Compare commits

..

No commits in common. "2a19fd42de4f9d2f79814fef6bffcabe984c9d17" and "471beb81300706f7176017a95cfbf71d6ec3dd72" have entirely different histories.

5 changed files with 85 additions and 203 deletions

View File

@ -20,7 +20,6 @@ Abstract:
#define MDL_OPERATION_FLAGS_TRUNCATE 0x00000002
#define MDL_OPERATION_FLAGS_PHYSICAL 0x40000000
#define MDL_OPERATION_FLAGS_VIRTUAL 0x80000000
NTSTATUS
MmFwGetMemoryMap (

View File

@ -421,7 +421,6 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -457,7 +456,6 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -488,7 +486,6 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
}
@ -510,7 +507,6 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
@ -572,7 +568,6 @@ Return Value:
Status = MmMdAddDescriptorToList(Mdl, NtDescriptor, MDL_OPERATION_FLAGS_TRUNCATE);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;
}
}
@ -616,7 +611,7 @@ Return Value:
//
// Remove the current descriptor.
//
Status = MmMdRemoveRegionFromMdlEx(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL);
Status = MmMdRemoveRegionFromMdlEx(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL, 0);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;

View File

@ -152,7 +152,6 @@ Return Value:
--*/
{
NTSTATUS Status;
PMEMORY_DESCRIPTOR PrevDescriptor, NextDescriptor, NewDescriptor;
ULONGLONG DescriptorEnd, PrevDescriptorEnd, NextDescriptorEnd;
ULONGLONG MappedFirstPage;
@ -187,10 +186,7 @@ Return Value:
PrevDescriptor->Type
);
if (NewDescriptor != NULL) {
Status = MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
}
MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
}
}
@ -246,10 +242,7 @@ Return Value:
Descriptor->Type
);
if (NewDescriptor != NULL) {
Status = MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
}
MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
}
}
@ -317,7 +310,6 @@ Return Value:
PMEMORY_DESCRIPTOR CurrentDescriptor;
if (Mdl == NULL || Descriptor == NULL) {
DebugPrint(L"MmMdAddDescriptorToList(): Mdl and/or Descriptor are NULL\r\n");
return STATUS_INVALID_PARAMETER;
}
@ -462,61 +454,9 @@ Return Value:
{
BOOLEAN Mapped;
PMEMORY_DESCRIPTOR Descriptor;
PLIST_ENTRY ListEntry;
ULONGLONG FirstPage;
Mapped = FALSE;
if (Flags & MDL_OPERATION_FLAGS_VIRTUAL) {
if (Mdl->Type == MDL_TYPE_PHYSICAL) {
Mapped = TRUE;
}
} else {
//
// If the MDL is virtual, the
// virtual flag must be set.
//
if (Mdl->Type == MDL_TYPE_VIRTUAL) {
DebugPrint(L"MmMdFindDescriptorFromMdl(): Flags is invalid\r\n");
return NULL;
}
}
//
// Check if the cached descriptor is in range.
// TODO: Implement this routine.
//
if (!Mapped && Mdl->Current != NULL) {
Descriptor = (PMEMORY_DESCRIPTOR)Mdl->Current;
if (Page < Descriptor->FirstPage) {
ListEntry = Mdl->Head->Flink;
} else {
ListEntry = Mdl->Current;
}
} else {
ListEntry = Mdl->Head->Flink;
}
while (ListEntry != Mdl->Head) {
Descriptor = (PMEMORY_DESCRIPTOR)ListEntry;
if (Mapped) {
FirstPage = Descriptor->MappedFirstPage;
} else {
FirstPage = Descriptor->FirstPage;
}
//
// Check if this descriptor contains Page.
//
if ((!Mapped || FirstPage)
&& Page >= FirstPage
&& Page < FirstPage + Descriptor->PageCount) {
return Descriptor;
}
ListEntry = ListEntry->Flink;
}
return NULL;
}
@ -524,7 +464,7 @@ Return Value:
NTSTATUS
MmMdRemoveRegionFromMdlEx (
IN PMEMORY_DESCRIPTOR_LIST Mdl,
IN ULONGLONG RemoveStart,
IN ULONGLONG FirstPage,
IN ULONGLONG PageCount,
IN ULONG Flags,
OUT PMEMORY_DESCRIPTOR_LIST Unused
@ -540,154 +480,46 @@ Arguments:
Mdl - MDL to remove the region from.
RemoveStart - The first page in the region.
FirstPage - The first page in the region.
PageCount - The number of pages in the region.
Flags - MDL_OPERATION_FLAGS_*.
MDL_OPERATION_FLAGS_PHYSICAL if the region is physical.
MDL_OPERATION_FLAGS_VIRTUAL if the region is virtual.
Unused - Unused.
Return Value:
STATUS_SUCCESS if successful,
STATUS_INVALID_PARAMETER if Flags value is invalid.
None.
--*/
{
NTSTATUS Status;
ULONG Offset;
BOOLEAN Mapped;
ULONGLONG RemoveEnd;
PLIST_ENTRY ListEntry;
ULONGLONG DescriptorStart, DescriptorEnd;
PMEMORY_DESCRIPTOR Descriptor, NewDescriptor;
ULONGLONG RemoveEnd, DescriptorEnd;
PLIST_ENTRY Entry;
PMEMORY_DESCRIPTOR Descriptor;
MEMORY_DESCRIPTOR RemovedDescriptor;
(VOID)Flags;
(VOID)Unused;
Mapped = FALSE;
if (Flags & MDL_OPERATION_FLAGS_VIRTUAL) {
if (Mdl->Type == MDL_TYPE_PHYSICAL) {
Mapped = TRUE;
}
} else {
//
// If the MDL is virtual, the
// virtual flag must be set.
//
if (Mdl->Type == MDL_TYPE_VIRTUAL) {
DebugPrint(L"MmMdRemoveRegionFromMdlEx(): Flags is invalid\r\n");
return STATUS_INVALID_PARAMETER;
}
RemoveEnd = FirstPage + PageCount;
Entry = Mdl->Head->Flink;
while (Entry != Mdl->Head) {
Descriptor = (PMEMORY_DESCRIPTOR)Entry;
DescriptorEnd = Descriptor->FirstPage + Descriptor->PageCount;
RtlCopyMemory(&RemovedDescriptor, Descriptor, sizeof(MEMORY_DESCRIPTOR));
// if (FirstPage <= Descriptor->FirstPage && Descriptor->FirstPage < RemoveEnd) {
// }
}
RemoveEnd = RemoveStart + PageCount;
ListEntry = Mdl->Head->Flink;
while (ListEntry != Mdl->Head) {
Descriptor = (PMEMORY_DESCRIPTOR)ListEntry;
//
// TODO: Implement the rest of this routine.
//
if (Mapped) {
DescriptorStart = Descriptor->MappedFirstPage;
} else {
DescriptorStart = Descriptor->FirstPage;
}
DescriptorEnd = DescriptorStart + Descriptor->PageCount;
//
// Check if the region to be removed
// is inside the current descriptor.
//
if (RemoveStart <= DescriptorStart && RemoveEnd > DescriptorStart) {
//
// The region is around the start of the descriptor, or
// they have identical locations and sizes.
// | RemoveStart | DescriptorStart | RemoveEnd | DescriptorEnd |
// | Lower address ............................ Higher address |
//
if (RemoveEnd < DescriptorEnd) {
Offset = RemoveEnd - DescriptorStart;
} else {
Offset = DescriptorEnd - DescriptorStart;
}
//
// Shrink the descriptor.
//
Descriptor->FirstPage += Offset;
Descriptor->PageCount -= Offset;
if (Descriptor->MappedFirstPage) {
Descriptor->MappedFirstPage += Offset;
}
//
// Remove descriptor if now empty.
//
if (Descriptor->PageCount == 0) {
MmMdRemoveDescriptorFromList(Mdl, Descriptor);
MmMdFreeDescriptor(Descriptor);
}
} else if (RemoveStart < DescriptorEnd && RemoveEnd >= DescriptorEnd) {
//
// The region is around the end of the descriptor.
// | DescriptorStart | RemoveStart | DescriptorEnd | RemoveEnd |
// | Lower address ............................ Higher address |
//
//
// Simply shrink the descriptor.
//
Descriptor->PageCount -= DescriptorEnd - RemoveStart;
} else if (RemoveStart > DescriptorStart && RemoveEnd < DescriptorEnd) {
//
// The region is completely inside the descriptor.
// In this case, the descriptor must be split in two.
// | DescriptorStart | RemoveStart | RemoveEnd | DescriptorEnd |
// | Lower address ............................ Higher address |
//
//
// Create a new descriptor before the removed region.
//
NewDescriptor = MmMdInitDescriptor(
Descriptor->FirstPage,
Descriptor->MappedFirstPage,
RemoveStart - DescriptorStart,
Descriptor->Attributes,
Descriptor->Type
);
//
// Shrink and move the current descriptor.
//
Offset = NewDescriptor->PageCount + PageCount;
Descriptor->FirstPage += Offset;
Descriptor->PageCount -= Offset;
if (Descriptor->MappedFirstPage) {
Descriptor->MappedFirstPage += Offset;
}
//
// Now check if MmMdInitDescriptor() actually worked.
//
if (NewDescriptor == NULL) {
return STATUS_NO_MEMORY;
}
Status = MmMdAddDescriptorToList(Mdl, NewDescriptor, Flags);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
return Status;
}
}
ListEntry = ListEntry->Flink;
}
return Status;
return STATUS_SUCCESS;
}
NTSTATUS
@ -735,7 +567,7 @@ Return Value:
// Free the descriptor from the heap.
// TODO: Use BlMmFreeHeap().
//
ConsolePrint(L"MmMdFreeDescriptor(): Heap not available\r\n");
ConsolePrint(L"MmMdFreeDescriptor(): need BlMmFreeHeap() to free descriptor\r\n");
return STATUS_NOT_IMPLEMENTED;
// return BlMmFreeHeap(Descriptor);
}

View File

@ -139,9 +139,8 @@ Return Value:
return STATUS_NO_MEMORY;
}
Status = MmMdAddDescriptorToList(&MmMdlReservedAllocated, NewDescriptor, 0);
Status = MmMdAddDescriptorToList(&MmMdlReservedAllocated, NewDescriptor, 0x00);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NewDescriptor);
return Status;
}

View File

@ -105,6 +105,63 @@ Return Value:
return Status;
}
//
// Print debug information.
// TODO: Remove this once the project is more stable?
//
#ifdef _DEBUG
DebugPrint(L"Boot device type: ");
switch (BlpBootDevice->Type) {
case BOOT_DEVICE_TYPE_PARTITION:
DebugPrint(L"partition\r\n");
BlockDevice = &BlpBootDevice->Partition.Parent;
break;
case BOOT_DEVICE_TYPE_PARTITION_EX:
DebugPrint(L"partition\r\n");
BlockDevice = &BlpBootDevice->PartitionEx.Parent;
break;
default:
DebugPrint(L"generic block device\r\n");
BlockDevice = &BlpBootDevice->Block;
break;
}
DebugPrint(L"Boot device parent type: ");
switch (BlockDevice->Type) {
case BOOT_BLOCK_DEVICE_TYPE_HARDDRIVE:
DebugPrint(L"hard drive\r\n");
break;
case BOOT_BLOCK_DEVICE_TYPE_CDROM:
DebugPrint(L"CD-ROM\r\n");
break;
case BOOT_BLOCK_DEVICE_TYPE_RAMDISK:
DebugPrint(L"RAM disk\r\n");
break;
default:
DebugPrint(L"generic block device\r\n");
break;
}
Option = &ApplicationEntry->Options;
for (ULONG Index = 0; !Option->IsInvalid; Index++) {
DebugPrintf(L"Boot entry option %x: ", Index);
if (Option->Type == BCDE_DATA_TYPE_APPLICATION_PATH) {
DebugPrint(L"application path \"");
DebugPrint((PWSTR)((PUCHAR)Option + Option->DataOffset));
DebugPrint(L"\"\r\n");
} else {
DebugPrintf(L"type %x, data size %x\r\n", Option->Type, Option->DataSize);
}
if (Option->NextOptionOffset == 0) {
break;
}
Option = (PBOOT_APPLICATION_OPTION)((PUCHAR)Option + Option->NextOptionOffset);
}
#endif
return STATUS_SUCCESS;
}