28#define FIRST_MCB_SEGMENT (SYSTEM_ENV_BLOCK + 0x200)
29#define USER_MEMORY_SIZE (0x9FFE - FIRST_MCB_SEGMENT)
46 return (
Mcb->BlockType ==
'M' ||
Mcb->BlockType ==
'Z');
68 DPRINT1(
"The DOS memory arena is corrupted! (CurrentMcb = 0x%04X; PreviousMcb = 0x%04X)\n",
Segment, PrevSegment);
82#define DosMemValidate()
92 if (CurrentMcb->
OwnerPsp != 0)
return;
113 DPRINT1(
"The DOS memory arena is corrupted!\n");
119 if (NextMcb->OwnerPsp == 0)
122 CurrentMcb->
Size += NextMcb->Size + 1;
123 CurrentMcb->
BlockType = NextMcb->BlockType;
124 NextMcb->BlockType =
'I';
142 DPRINT(
"DosAllocateMemory: Size 0x%04X\n",
Size);
162 DPRINT1(
"The DOS memory arena is corrupted!\n");
168 if (CurrentMcb->
OwnerPsp != 0)
goto Next;
174 if (CurrentMcb->
Size > MaxSize) MaxSize = CurrentMcb->
Size;
177 if (CurrentMcb->
Size <
Size)
goto Next;
233 DPRINT(
"DosAllocateMemory FAILED. Maximum available: 0x%04X\n", MaxSize);
235 if (MaxAvailable) *MaxAvailable = MaxSize;
292 WORD Segment = BlockData - 1, ReturnSize = 0, NextSegment;
295 DPRINT(
"DosResizeMemory: BlockData 0x%04X, NewSize 0x%04X\n",
308 ReturnSize =
Mcb->Size;
314 if (
Mcb->BlockType ==
'Z')
316 DPRINT(
"Cannot expand memory block 0x%04X: this is the last block (size 0x%04X)!\n",
Segment,
Mcb->Size);
329 DPRINT1(
"The DOS memory arena is corrupted!\n");
335 if (NextMcb->OwnerPsp != 0)
337 DPRINT(
"Cannot expand memory block 0x%04X: next segment is not free!\n",
Segment);
347 ReturnSize += NextMcb->Size + 1;
351 DPRINT(
"Cannot expand memory block 0x%04X: insufficient free segments available!\n",
Segment);
358 Mcb->Size = ReturnSize;
359 Mcb->BlockType = NextMcb->BlockType;
362 NextMcb->BlockType =
'I';
367 DPRINT(
"Block too large, reducing size from 0x%04X to 0x%04X\n",
374 NextMcb->BlockType =
Mcb->BlockType;
376 NextMcb->OwnerPsp = 0;
379 Mcb->BlockType =
'M';
383 else if (NewSize < Mcb->
Size)
385 DPRINT(
"Shrinking block from 0x%04X to 0x%04X\n",
391 NextMcb->BlockType =
Mcb->BlockType;
393 NextMcb->OwnerPsp = 0;
396 Mcb->BlockType =
'M';
407 DPRINT(
"DosResizeMemory FAILED. Maximum available: 0x%04X\n", ReturnSize);
410 if (MaxAvailable) *MaxAvailable = ReturnSize;
422 DPRINT(
"DosFreeMemory: BlockData 0x%04X\n", BlockData);
435 DPRINT(
"MCB block type '%c' not valid!\n",
Mcb->BlockType);
460 while (Segment < SysVars->UmbChainStart)
468 DPRINT1(
"The DOS memory arena is corrupted!\n");
474 if (
Mcb->BlockType ==
'Z')
break;
481 if (
Mcb->BlockType !=
'Z')
return FALSE;
484 Mcb->BlockType =
'M';
497 DPRINT(
"Unlinking UMB\n");
506 while (Segment < SysVars->UmbChainStart)
514 DPRINT1(
"The DOS memory arena is corrupted!\n");
524 Mcb->BlockType =
'Z';
535 Mcb->OwnerPsp = NewOwner;
562 DPRINT1(
"The UMB DOS memory arena is corrupted!\n");
568 if (
Segment >= UmbSegment)
break;
585 USHORT UmbSegment = 0x0000, PrevSegment;
619 Mcb->BlockType =
'Z';
646 Mcb->Size = PrevMcb->
Size - (UmbSegment +
Size - PrevSegment) + 1;
652 PrevMcb->
Size = UmbSegment - PrevSegment - 1;
656 Mcb->BlockType =
'M';
680 Mcb->BlockType =
'Z';
#define ERROR_NOT_ENOUGH_MEMORY
IN PVCB IN ULONG IN OUT PULONG IN BOOLEAN OUT PLARGE_MCB Mcb
_Must_inspect_result_ _In_ USHORT NewSize
BOOLEAN DosResizeMemory(WORD BlockData, WORD NewSize, WORD *MaxAvailable)
WORD DosAllocateMemory(WORD Size, WORD *MaxAvailable)
VOID DosInitializeUmb(VOID)
BOOLEAN DosUnlinkUmb(VOID)
VOID DosInitializeMemory(VOID)
#define FIRST_MCB_SEGMENT
WORD DosGetPreviousUmb(WORD UmbSegment)
VOID DosChangeMemoryOwner(WORD Segment, WORD NewOwner)
static VOID DosCombineFreeBlocks(WORD StartBlock)
BOOLEAN DosFreeMemory(WORD BlockData)
static BOOLEAN ValidateMcb(PDOS_MCB Mcb)
#define DOS_ALLOC_HIGH_LOW
#define SEGMENT_TO_MCB(seg)
#define RtlCopyMemory(Destination, Source, Length)
BOOLEAN UmaDescReserve(IN OUT PUSHORT Segment, IN OUT PUSHORT Size)
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
#define ERROR_INVALID_BLOCK
#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