OpenCore
1.0.4
OpenCore Bootloader
|
#include "BootCompatInternal.h"
#include <Guid/AppleVariable.h>
#include <Guid/OcVariable.h>
#include <IndustryStandard/AppleHibernate.h>
#include <IndustryStandard/AppleEfiBootRtInfo.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/DevicePathLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcLogAggregatorLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcDeviceMiscLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcOSInfoLib.h>
#include <Library/OcStringLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Protocol/OcFirmwareRuntime.h>
#include <Protocol/VMwareMac.h>
Go to the source code of this file.
Functions | |
STATIC VOID | FixRuntimeAttributes (IN BOOT_COMPAT_CONTEXT *BootCompat, IN UINT32 Type) |
STATIC EFI_STATUS | ForceExitBootServices (IN EFI_HANDLE ImageHandle, IN UINTN MapKey, IN EFI_EXIT_BOOT_SERVICES ExitBootServices OPTIONAL, IN EFI_GET_MEMORY_MAP GetMemoryMap OPTIONAL) |
STATIC VOID | ProtectMemoryRegions (IN UINTN MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize) |
STATIC VOID | DevirtualiseMmio (IN VOID *Context, IN UINTN MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, IN UINTN DescriptorSize) |
STATIC VOID | ApplyBooterPatch (IN OUT UINT8 *ImageBase, IN UINTN ImageSize, IN OC_BOOTER_PATCH *Patch) |
STATIC VOID | ApplyBooterPatches (IN EFI_HANDLE ImageHandle, IN BOOLEAN IsApple, IN OC_BOOTER_PATCH *Patches, IN UINT32 PatchCount) |
STATIC EFI_STATUS EFIAPI | OcAllocatePages (IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, IN OUT EFI_PHYSICAL_ADDRESS *Memory) |
STATIC EFI_STATUS EFIAPI | OcFreePages (IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN Pages) |
STATIC EFI_STATUS EFIAPI | OcGetMemoryMap (IN OUT UINTN *MemoryMapSize, IN OUT EFI_MEMORY_DESCRIPTOR *MemoryMap, OUT UINTN *MapKey, OUT UINTN *DescriptorSize, OUT UINT32 *DescriptorVersion) |
STATIC EFI_STATUS EFIAPI | OcAllocatePool (IN EFI_MEMORY_TYPE PoolType, IN UINTN Size, OUT VOID **Buffer) |
STATIC EFI_STATUS EFIAPI | OcFreePool (IN VOID *Buffer) |
STATIC BOOLEAN | InternalIsEfiBootRt (IN EFI_DEVICE_PATH_PROTOCOL *EfiBootRtDevicePath OPTIONAL, IN VOID *SourceBuffer OPTIONAL, IN UINTN SourceSize, IN EFI_LOADED_IMAGE_PROTOCOL *EfiBootLoadedImage) |
STATIC EFI_STATUS EFIAPI | OcLoadImage (IN BOOLEAN BootPolicy, IN EFI_HANDLE ParentImageHandle, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN VOID *SourceBuffer OPTIONAL, IN UINTN SourceSize, OUT EFI_HANDLE *ImageHandle) |
STATIC EFI_STATUS EFIAPI | OcStartImage (IN EFI_HANDLE ImageHandle, OUT UINTN *ExitDataSize, OUT CHAR16 **ExitData OPTIONAL) |
STATIC EFI_STATUS EFIAPI | OcExitBootServices (IN EFI_HANDLE ImageHandle, IN UINTN MapKey) |
STATIC EFI_STATUS EFIAPI | OcSetVirtualAddressMap (IN UINTN MemoryMapSize, IN UINTN DescriptorSize, IN UINT32 DescriptorVersion, IN EFI_MEMORY_DESCRIPTOR *MemoryMap) |
STATIC EFI_STATUS EFIAPI | OcGetVariable (IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, OUT UINT32 *Attributes OPTIONAL, IN OUT UINTN *DataSize, OUT VOID *Data) |
STATIC VOID EFIAPI | SetGetVariableHookHandler (IN EFI_EVENT Event, IN VOID *Context) |
VOID | InstallServiceOverrides (IN OUT BOOT_COMPAT_CONTEXT *BootCompat) |
Copyright (C) 2013, dmazar. All rights reserved. Copyright (C) 2017, vit9696. All rights reserved.
All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Definition in file ServiceOverrides.c.
STATIC VOID ApplyBooterPatch | ( | IN OUT UINT8 * | ImageBase, |
IN UINTN | ImageSize, | ||
IN OC_BOOTER_PATCH * | Patch ) |
Apply single booter patch.
[in,out] | ImageBase | Booter image to be patched. |
[in] | ImageSize | Size of booter image. |
[in] | Patch | Single patch to be applied to booter. |
Definition at line 334 of file ServiceOverrides.c.
STATIC VOID ApplyBooterPatches | ( | IN EFI_HANDLE | ImageHandle, |
IN BOOLEAN | IsApple, | ||
IN OC_BOOTER_PATCH * | Patches, | ||
IN UINT32 | PatchCount ) |
Iterate through user booter patches and apply them.
[in] | ImageHandle | Loaded image handle to patch. |
[in] | IsApple | Whether the booter is Apple-made. |
[in] | Patches | Array of patches to be applied. |
[in] | PatchesCount | Size of patches to be applied. |
Definition at line 392 of file ServiceOverrides.c.
STATIC VOID DevirtualiseMmio | ( | IN VOID * | Context, |
IN UINTN | MemoryMapSize, | ||
IN OUT EFI_MEMORY_DESCRIPTOR * | MemoryMap, | ||
IN UINTN | DescriptorSize ) |
Mark MMIO virtual memory regions as non-runtime to reduce the amount of virtual memory required by boot.efi.
[in] | Context | Boot compatibility context. |
[in,out] | MemoryMapSize | Memory map size in bytes, updated on devirtualisation. |
[in,out] | MemoryMap | Memory map to devirtualise. |
[in] | DescriptorSize | Memory map descriptor size in bytes. |
Definition at line 245 of file ServiceOverrides.c.
STATIC VOID FixRuntimeAttributes | ( | IN BOOT_COMPAT_CONTEXT * | BootCompat, |
IN UINT32 | Type ) |
Helper function to mark OpenRuntime as executable with proper permissions.
[in] | BootCompat | Boot compatibility context. |
Definition at line 51 of file ServiceOverrides.c.
STATIC EFI_STATUS ForceExitBootServices | ( | IN EFI_HANDLE | ImageHandle, |
IN UINTN | MapKey, | ||
IN EFI_EXIT_BOOT_SERVICES ExitBootServices | OPTIONAL, | ||
IN EFI_GET_MEMORY_MAP GetMemoryMap | OPTIONAL ) |
Helper function to call ExitBootServices that can handle outdated MapKey issues.
[in] | ExitBootServices | ExitBootServices function pointer, optional. |
[in] | GetMemoryMap | GetMemoryMap function pointer, optional. |
[in] | ImageHandle | Image handle to call ExitBootServices on. |
[in] | MapKey | MapKey to call ExitBootServices on. |
EFI_SUCCESS | on success. |
Definition at line 95 of file ServiceOverrides.c.
VOID InstallServiceOverrides | ( | IN OUT BOOT_COMPAT_CONTEXT * | BootCompat | ) |
Install UEFI services overrides as necessary.
[in,out] | BootCompat | Boot compatibility context. |
Definition at line 1626 of file ServiceOverrides.c.
STATIC BOOLEAN InternalIsEfiBootRt | ( | IN EFI_DEVICE_PATH_PROTOCOL *EfiBootRtDevicePath | OPTIONAL, |
IN VOID *SourceBuffer | OPTIONAL, | ||
IN UINTN | SourceSize, | ||
IN EFI_LOADED_IMAGE_PROTOCOL * | EfiBootLoadedImage ) |
Definition at line 764 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcAllocatePages | ( | IN EFI_ALLOCATE_TYPE | Type, |
IN EFI_MEMORY_TYPE | MemoryType, | ||
IN UINTN | NumberOfPages, | ||
IN OUT EFI_PHYSICAL_ADDRESS * | Memory ) |
UEFI Boot Services AllocatePages override. Returns pages from free memory block to boot.efi for kernel boot image.
Definition at line 451 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcAllocatePool | ( | IN EFI_MEMORY_TYPE | PoolType, |
IN UINTN | Size, | ||
OUT VOID ** | Buffer ) |
UEFI Boot Services AllocatePool override. Ensures synchronised memory attribute table.
Definition at line 701 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcExitBootServices | ( | IN EFI_HANDLE | ImageHandle, |
IN UINTN | MapKey ) |
UEFI Boot Services ExitBootServices override. Patches kernel entry point with jump to our KernelEntryPatchJumpBack().
Notes:
Definition at line 1380 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcFreePages | ( | IN EFI_PHYSICAL_ADDRESS | Memory, |
IN UINTN | Pages ) |
UEFI Boot Services FreePages override. Ensures synchronised memory attribute table.
Definition at line 553 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcFreePool | ( | IN VOID * | Buffer | ) |
UEFI Boot Services FreePool override. Ensures synchronised memory attribute table.
Definition at line 732 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcGetMemoryMap | ( | IN OUT UINTN * | MemoryMapSize, |
IN OUT EFI_MEMORY_DESCRIPTOR * | MemoryMap, | ||
OUT UINTN * | MapKey, | ||
OUT UINTN * | DescriptorSize, | ||
OUT UINT32 * | DescriptorVersion ) |
UEFI Boot Services GetMemoryMap override. Returns shrinked memory map as XNU can handle up to PMAP_MEMORY_REGIONS_SIZE (128) entries. Also applies any further memory map alterations as necessary.
Definition at line 583 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcGetVariable | ( | IN CHAR16 * | VariableName, |
IN EFI_GUID * | VendorGuid, | ||
OUT UINT32 *Attributes | OPTIONAL, | ||
IN OUT UINTN * | DataSize, | ||
OUT VOID * | Data ) |
UEFI Runtime Services GetVariable override. Used to return customised values for boot-args and csr-active-config variables.
Definition at line 1499 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcLoadImage | ( | IN BOOLEAN | BootPolicy, |
IN EFI_HANDLE | ParentImageHandle, | ||
IN EFI_DEVICE_PATH_PROTOCOL * | DevicePath, | ||
IN VOID *SourceBuffer | OPTIONAL, | ||
IN UINTN | SourceSize, | ||
OUT EFI_HANDLE * | ImageHandle ) |
UEFI Boot Services LoadImage override. Called to load an efi image. If this is bootrt.efi, then we patch its kernel call gate.
Definition at line 1030 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcSetVirtualAddressMap | ( | IN UINTN | MemoryMapSize, |
IN UINTN | DescriptorSize, | ||
IN UINT32 | DescriptorVersion, | ||
IN EFI_MEMORY_DESCRIPTOR * | MemoryMap ) |
UEFI Runtime Services SetVirtualAddressMap override. Fixes virtualizing of RT services.
Definition at line 1467 of file ServiceOverrides.c.
STATIC EFI_STATUS EFIAPI OcStartImage | ( | IN EFI_HANDLE | ImageHandle, |
OUT UINTN * | ExitDataSize, | ||
OUT CHAR16 **ExitData | OPTIONAL ) |
UEFI Boot Services StartImage override. Called to start an efi image. If this is boot.efi, then our overrides are enabled.
Definition at line 1167 of file ServiceOverrides.c.
STATIC VOID ProtectMemoryRegions | ( | IN UINTN | MemoryMapSize, |
IN OUT EFI_MEMORY_DESCRIPTOR * | MemoryMap, | ||
IN UINTN | DescriptorSize ) |
Protect regions in memory map.
[in,out] | MemoryMapSize | Memory map size in bytes, updated on shrink. |
[in,out] | MemoryMap | Memory map to shrink. |
[in] | DescriptorSize | Memory map descriptor size in bytes. |
Definition at line 168 of file ServiceOverrides.c.
STATIC VOID EFIAPI SetGetVariableHookHandler | ( | IN EFI_EVENT | Event, |
IN VOID * | Context ) |
UEFI Runtime Services GetVariable override event handler. We do not override GetVariable ourselves but let our runtime do that.
[in] | Event | Event handle. |
[in] | Context | Apple boot compatibility context. |
Definition at line 1562 of file ServiceOverrides.c.