From ffb49563cd3abb85b63420f7e61e574034a87fef Mon Sep 17 00:00:00 2001 From: vit9696 Date: Fri, 3 Apr 2020 02:32:52 +0300 Subject: [PATCH] OcAppleBootCompatLib: Update attributes after every allocation --- .../OcAppleBootCompatLib/ServiceOverrides.c | 58 +++++++++++-------- 1 file changed, 35 insertions(+), 23 deletions(-) diff --git a/Library/OcAppleBootCompatLib/ServiceOverrides.c b/Library/OcAppleBootCompatLib/ServiceOverrides.c index fc0054fd..fcc3bf6f 100644 --- a/Library/OcAppleBootCompatLib/ServiceOverrides.c +++ b/Library/OcAppleBootCompatLib/ServiceOverrides.c @@ -275,6 +275,8 @@ OcAllocatePages ( { EFI_STATUS Status; BOOT_COMPAT_CONTEXT *BootCompat; + EFI_PHYSICAL_ADDRESS Address; + UINTN Pages; BOOLEAN IsPerfAlloc; BootCompat = GetBootCompatContext (); @@ -299,30 +301,40 @@ OcAllocatePages ( Memory ); - if (!EFI_ERROR (Status) && BootCompat->ServiceState.AppleBootNestedCount > 0) { - if (IsPerfAlloc) { - // - // Called from boot.efi. - // New perf data, it can be reallocated multiple times. - // - OcAppleDebugLogPerfAllocated ((VOID *)(UINTN) *Memory, EFI_PAGES_TO_SIZE (NumberOfPages)); - } else if (Type == AllocateAddress && MemoryType == EfiLoaderData) { - // - // Called from boot.efi. - // Store minimally allocated address to find kernel image start. - // - if (BootCompat->ServiceState.MinAllocatedAddr == 0 - || *Memory < BootCompat->ServiceState.MinAllocatedAddr) { - BootCompat->ServiceState.MinAllocatedAddr = *Memory; + if (!EFI_ERROR (Status)) { + if (BootCompat->Settings.SyncRuntimePermissions && BootCompat->ServiceState.FwRuntime != NULL) { + Status = BootCompat->ServiceState.FwRuntime->GetExecArea (&Address, &Pages); + + if (!EFI_ERROR (Status)) { + OcUpdateAttributes (Address, EfiRuntimeServicesCode, EFI_MEMORY_RO, EFI_MEMORY_XP); + } + } + + if (BootCompat->ServiceState.AppleBootNestedCount > 0) { + if (IsPerfAlloc) { + // + // Called from boot.efi. + // New perf data, it can be reallocated multiple times. + // + OcAppleDebugLogPerfAllocated ((VOID *)(UINTN) *Memory, EFI_PAGES_TO_SIZE (NumberOfPages)); + } else if (Type == AllocateAddress && MemoryType == EfiLoaderData) { + // + // Called from boot.efi. + // Store minimally allocated address to find kernel image start. + // + if (BootCompat->ServiceState.MinAllocatedAddr == 0 + || *Memory < BootCompat->ServiceState.MinAllocatedAddr) { + BootCompat->ServiceState.MinAllocatedAddr = *Memory; + } + } else if (BootCompat->ServiceState.AppleHibernateWake + && Type == AllocateAnyPages && MemoryType == EfiLoaderData + && BootCompat->ServiceState.HibernateImageAddress == 0) { + // + // Called from boot.efi during hibernate wake, + // first such allocation is for hibernate image + // + BootCompat->ServiceState.HibernateImageAddress = *Memory; } - } else if (BootCompat->ServiceState.AppleHibernateWake - && Type == AllocateAnyPages && MemoryType == EfiLoaderData - && BootCompat->ServiceState.HibernateImageAddress == 0) { - // - // Called from boot.efi during hibernate wake, - // first such allocation is for hibernate image - // - BootCompat->ServiceState.HibernateImageAddress = *Memory; } }