[BOOT] Execution contexts and more refactoring

This commit is contained in:
2024-10-05 15:44:25 -04:00
parent 7c3dafc051
commit 24a31cab26
13 changed files with 317 additions and 118 deletions

View File

@@ -62,15 +62,32 @@ Return Value:
--*/
{
return EfiGetNtStatusCode(
EfiBS->GetMemoryMap(
MemoryMapSize,
MemoryMap,
MapKey,
DescriptorSize,
DescriptorVersion
)
EXECUTION_CONTEXT_TYPE ContextType;
EFI_STATUS EfiStatus;
ContextType = CurrentExecutionContext->Type;
if (ContextType != ExecutionContextFirmware) {
//
// TODO: Translate addresses here.
// Need MmArchTranslateVirtualAddress().
//
BlpArchSwitchContext(ExecutionContextFirmware);
}
EfiStatus = EfiBS->GetMemoryMap(
MemoryMapSize,
MemoryMap,
MapKey,
DescriptorSize,
DescriptorVersion
);
if (ContextType != ExecutionContextFirmware) {
BlpArchSwitchContext(ContextType);
}
return EfiGetNtStatusCode(EfiStatus);
}
NTSTATUS
@@ -106,14 +123,26 @@ Return Value:
--*/
{
return EfiGetNtStatusCode(
EfiBS->AllocatePages(
Type,
MemoryType,
Pages,
Memory
)
EXECUTION_CONTEXT_TYPE ContextType;
EFI_STATUS EfiStatus;
ContextType = CurrentExecutionContext->Type;
if (ContextType != ExecutionContextFirmware) {
BlpArchSwitchContext(ExecutionContextFirmware);
}
EfiStatus = EfiBS->AllocatePages(
Type,
MemoryType,
Pages,
Memory
);
if (ContextType != ExecutionContextFirmware) {
BlpArchSwitchContext(ContextType);
}
return EfiGetNtStatusCode(EfiStatus);
}
NTSTATUS
@@ -143,12 +172,24 @@ Return Value:
--*/
{
return EfiGetNtStatusCode(
EfiBS->FreePages(
Memory,
Pages
)
EXECUTION_CONTEXT_TYPE ContextType;
EFI_STATUS EfiStatus;
ContextType = CurrentExecutionContext->Type;
if (ContextType != ExecutionContextFirmware) {
BlpArchSwitchContext(ExecutionContextFirmware);
}
EfiStatus = EfiBS->FreePages(
Memory,
Pages
);
if (ContextType != ExecutionContextFirmware) {
BlpArchSwitchContext(ContextType);
}
return EfiGetNtStatusCode(EfiStatus);
}
MEMORY_TYPE
@@ -616,7 +657,7 @@ Return Value:
//
// Remove the current descriptor.
//
Status = MmMdRemoveRegionFromMdlEx(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL, NULL);
Status = MmMdRemoveRegionFromMdl(Mdl, NtStartPage, NtPageCount, MDL_OPERATION_FLAGS_PHYSICAL);
if (!NT_SUCCESS(Status)) {
MmMdFreeDescriptor(NtDescriptor);
goto exit;