#include "ntvdm.h"
#include <debug.h>
#include "emulator.h"
#include "bios/umamgr.h"
#include "dos.h"
#include "dos/dem.h"
#include "memory.h"
#include "process.h"
#include "himem.h"
Go to the source code of this file.
◆ DosMemValidate
◆ FIRST_MCB_SEGMENT
◆ NDEBUG
◆ USER_MEMORY_SIZE
◆ DosAllocateMemory()
Definition at line 136 of file memory.c.
137{
141
142 DPRINT(
"DosAllocateMemory: Size 0x%04X\n",
Size);
143
145
148 {
149
152 }
153
155 {
156
158
159
161 {
162 DPRINT1(
"The DOS memory arena is corrupted!\n");
164 return 0;
165 }
166
167
168 if (CurrentMcb->
OwnerPsp != 0)
goto Next;
169
170
172
173
174 if (CurrentMcb->
Size > MaxSize) MaxSize = CurrentMcb->
Size;
175
176
177 if (CurrentMcb->
Size <
Size)
goto Next;
178
180 {
182 {
183
185 goto Done;
186 }
187
189 {
190
192 {
194 }
195
196 break;
197 }
198
200 {
201
203 break;
204 }
205 }
206
207Next:
208
210 {
211
213 {
214
217 continue;
218 }
219
220 break;
221 }
222
223
225 }
226
227Done:
229
230
232 {
233 DPRINT(
"DosAllocateMemory FAILED. Maximum available: 0x%04X\n", MaxSize);
235 if (MaxAvailable) *MaxAvailable = MaxSize;
236 return 0;
237 }
238
239
241
242
244 {
245
247 {
249
250
254
255
258 }
259 else
260 {
261
263
264
267
268
272
273
276 }
277 }
278
279
282
284
285
287}
#define ERROR_NOT_ENOUGH_MEMORY
static VOID DosCombineFreeBlocks(WORD StartBlock)
static BOOLEAN ValidateMcb(PDOS_MCB Mcb)
#define DOS_ALLOC_HIGH_LOW
#define SEGMENT_TO_MCB(seg)
#define RtlCopyMemory(Destination, Source, Length)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
#define ERROR_ARENA_TRASHED
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Referenced by DosCopyEnvironmentBlock(), DosCountryInitialize(), DosCreateDeviceEx(), DosInt21h(), DosLoadDriver(), DosLoadExecutableInternal(), DosMouseInitialize(), and DosResizeHandleTable().
◆ DosChangeMemoryOwner()
◆ DosCombineFreeBlocks()
static VOID DosCombineFreeBlocks |
( |
WORD |
StartBlock | ) |
|
|
static |
Definition at line 85 of file memory.c.
86{
87
88
90
91
92 if (CurrentMcb->
OwnerPsp != 0)
return;
93
94
95
96
97
98
99
100
101
102
103
104
106 {
107
109
110
112 {
113 DPRINT1(
"The DOS memory arena is corrupted!\n");
115 return;
116 }
117
118
119 if (NextMcb->OwnerPsp == 0)
120 {
121
122 CurrentMcb->
Size += NextMcb->Size + 1;
123 CurrentMcb->
BlockType = NextMcb->BlockType;
124 NextMcb->BlockType = 'I';
125 }
126 else
127 {
128
129 break;
130 }
131 }
132}
Referenced by DosAllocateMemory(), and DosResizeMemory().
◆ DosFreeMemory()
◆ DosGetPreviousUmb()
WORD DosGetPreviousUmb |
( |
WORD |
UmbSegment | ) |
|
Definition at line 544 of file memory.c.
545{
548
550 return 0;
551
552
555 {
556
558
559
561 {
562 DPRINT1(
"The UMB DOS memory arena is corrupted!\n");
564 return 0;
565 }
566
567
568 if (
Segment >= UmbSegment)
break;
569
571
572
574
575
577 }
578
579 return PrevSegment;
580}
Referenced by DosInitializeUmb().
◆ DosInitializeMemory()
Definition at line 665 of file memory.c.
666{
668
669
671
672
676
678
679
680 Mcb->BlockType =
'Z';
683}
#define FIRST_MCB_SEGMENT
Referenced by DosKRNLInitialize().
◆ DosInitializeUmb()
Definition at line 582 of file memory.c.
583{
585 USHORT UmbSegment = 0x0000, PrevSegment;
588
590
591
592
593
595 {
596
599
600
602 break;
603
604
606
607
610
611
613 {
614
615
616
617
619 Mcb->BlockType =
'Z';
623
624#if 0
625
628#endif
629
630
631
632
634 }
635
636
637
638
641
642
644
646 Mcb->Size = PrevMcb->
Size - (UmbSegment +
Size - PrevSegment) + 1;
649
650
652 PrevMcb->
Size = UmbSegment - PrevSegment - 1;
653
654
656 Mcb->BlockType =
'M';
659
661
662 }
663}
WORD DosGetPreviousUmb(WORD UmbSegment)
BOOLEAN UmaDescReserve(IN OUT PUSHORT Segment, IN OUT PUSHORT Size)
Referenced by DosKRNLInitialize().
◆ DosLinkUmb()
Definition at line 446 of file memory.c.
447{
450
452
453
456
458
459
460 while (Segment < SysVars->UmbChainStart)
461 {
462
464
465
467 {
468 DPRINT1(
"The DOS memory arena is corrupted!\n");
471 }
472
473
474 if (
Mcb->BlockType ==
'Z')
break;
475
476
478 }
479
480
481 if (
Mcb->BlockType !=
'Z')
return FALSE;
482
483
484 Mcb->BlockType =
'M';
485
487
490}
Referenced by DosInt21h().
◆ DosResizeMemory()
Definition at line 289 of file memory.c.
290{
292 WORD Segment = BlockData - 1, ReturnSize = 0, NextSegment;
294
295 DPRINT(
"DosResizeMemory: BlockData 0x%04X, NewSize 0x%04X\n",
297
299
300
302 {
305 goto Done;
306 }
307
308 ReturnSize =
Mcb->Size;
309
310
312 {
313
314 if (
Mcb->BlockType ==
'Z')
315 {
316 DPRINT(
"Cannot expand memory block 0x%04X: this is the last block (size 0x%04X)!\n",
Segment,
Mcb->Size);
319 goto Done;
320 }
321
322
325
326
328 {
329 DPRINT1(
"The DOS memory arena is corrupted!\n");
332 }
333
334
335 if (NextMcb->OwnerPsp != 0)
336 {
337 DPRINT(
"Cannot expand memory block 0x%04X: next segment is not free!\n",
Segment);
340 goto Done;
341 }
342
343
345
346
347 ReturnSize += NextMcb->Size + 1;
348
350 {
351 DPRINT(
"Cannot expand memory block 0x%04X: insufficient free segments available!\n",
Segment);
354 goto Done;
355 }
356
357
358 Mcb->Size = ReturnSize;
359 Mcb->BlockType = NextMcb->BlockType;
360
361
362 NextMcb->BlockType = 'I';
363
364
366 {
367 DPRINT(
"Block too large, reducing size from 0x%04X to 0x%04X\n",
369
370
372
373
374 NextMcb->BlockType =
Mcb->BlockType;
376 NextMcb->OwnerPsp = 0;
377
378
379 Mcb->BlockType =
'M';
381 }
382 }
383 else if (NewSize < Mcb->
Size)
384 {
385 DPRINT(
"Shrinking block from 0x%04X to 0x%04X\n",
387
388
391 NextMcb->BlockType =
Mcb->BlockType;
393 NextMcb->OwnerPsp = 0;
394
395
396 Mcb->BlockType =
'M';
398
399
401 }
402
403Done:
404
406 {
407 DPRINT(
"DosResizeMemory FAILED. Maximum available: 0x%04X\n", ReturnSize);
408
409
410 if (MaxAvailable) *MaxAvailable = ReturnSize;
411 }
412
414
416}
_Must_inspect_result_ _In_ USHORT NewSize
Referenced by DosInt21h(), DosResizeHandleTable(), and DosTerminateProcess().
◆ DosUnlinkUmb()
Definition at line 492 of file memory.c.
493{
496
497 DPRINT(
"Unlinking UMB\n");
498
499
502
504
505
506 while (Segment < SysVars->UmbChainStart)
507 {
508
510
511
513 {
514 DPRINT1(
"The DOS memory arena is corrupted!\n");
517 }
518
519
521 }
522
523
524 Mcb->BlockType =
'Z';
525
527
530}
Referenced by DosInt21h().
◆ ValidateMcb()