OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
ImageLoader.c File Reference
#include "BootManagementInternal.h"
#include <Protocol/DevicePath.h>
#include <Protocol/LoadedImage.h>
#include <Protocol/SimpleFileSystem.h>
#include <Guid/AppleVariable.h>
#include <Guid/FileInfo.h>
#include <Guid/GlobalVariable.h>
#include <Guid/OcVariable.h>
#include <AppleMacEfi/AppleMacEfiSpec.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/DevicePathLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/MemoryAllocationLibEx.h>
#include <Library/OcAppleSecureBootLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDevicePathLib.h>
#include <Library/OcFileLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcPeCoffExtLib.h>
#include <Library/OcStringLib.h>
#include <Library/UefiImageLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/PrintLib.h>

Go to the source code of this file.

Data Structures

struct  OC_LOADED_IMAGE_PROTOCOL
 
struct  OC_IMAGE_LOADER_CAPS_PROTOCOL
 

Functions

STATIC VOID PreserveGrubShimHooks (VOID)
 
STATIC VOID RestoreGrubShimHooks (IN CONST CHAR8 *Caller)
 
STATIC EFI_STATUS InternalEfiLoadImageFile (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, OUT UINTN *FileSize, OUT VOID **FileBuffer)
 
STATIC EFI_STATUS InternalEfiLoadImageProtocol (IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, IN BOOLEAN UseLoadImage2, OUT UINTN *FileSize, OUT VOID **FileBuffer)
 
STATIC EFI_STATUS InternalUpdateLoadedImage (IN EFI_HANDLE ImageHandle, IN EFI_DEVICE_PATH_PROTOCOL *DevicePath)
 
EFI_STATUS EFIAPI OcImageLoaderLoad (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 InternalDirectUnloadImage (IN OC_LOADED_IMAGE_PROTOCOL *OcLoadedImage, IN EFI_HANDLE ImageHandle)
 
STATIC EFI_STATUS InternalDirectExit (IN OC_LOADED_IMAGE_PROTOCOL *OcLoadedImage, IN EFI_HANDLE ImageHandle, IN EFI_STATUS ExitStatus, IN UINTN ExitDataSize, IN CHAR16 *ExitData OPTIONAL)
 
STATIC EFI_STATUS InternalDirectStartImage (IN OC_LOADED_IMAGE_PROTOCOL *OcLoadedImage, IN EFI_HANDLE ImageHandle, OUT UINTN *ExitDataSize, OUT CHAR16 **ExitData OPTIONAL)
 
STATIC UINT32 DetectCapabilities (IN VOID *SourceBuffer, IN UINT32 SourceSize)
 
STATIC EFI_STATUS EFIAPI InternalEfiLoadImage (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 InternalEfiStartImage (IN EFI_HANDLE ImageHandle, OUT UINTN *ExitDataSize, OUT CHAR16 **ExitData OPTIONAL)
 
STATIC EFI_STATUS EFIAPI InternalEfiUnloadImage (IN EFI_HANDLE ImageHandle)
 
STATIC EFI_STATUS EFIAPI InternalEfiExit (IN EFI_HANDLE ImageHandle, IN EFI_STATUS ExitStatus, IN UINTN ExitDataSize, IN CHAR16 *ExitData OPTIONAL)
 
VOID OcImageLoaderInit (IN CONST BOOLEAN ProtectUefiServices, IN CONST BOOLEAN FixupAppleEfiImages)
 
VOID OcImageLoaderActivate (VOID)
 
VOID OcImageLoaderRegisterPatch (IN OC_IMAGE_LOADER_PATCH Patch OPTIONAL)
 
VOID OcImageLoaderRegisterConfigure (IN OC_IMAGE_LOADER_CONFIGURE Configure OPTIONAL)
 

Variables

STATIC EFI_GUID mOcLoadedImageProtocolGuid
 
STATIC EFI_GUID mOcImageLoaderCapsProtocolGuid
 
STATIC EFI_IMAGE_LOAD mOriginalEfiLoadImage
 
STATIC EFI_IMAGE_START mOriginalEfiStartImage
 
STATIC EFI_IMAGE_UNLOAD mOriginalEfiUnloadImage
 
STATIC EFI_EXIT mOriginalEfiExit
 
STATIC EFI_HANDLE mCurrentImageHandle
 
STATIC OC_IMAGE_LOADER_PATCH mImageLoaderPatch
 
STATIC OC_IMAGE_LOADER_CONFIGURE mImageLoaderConfigure
 
STATIC BOOLEAN mImageLoaderEnabled
 
STATIC BOOLEAN mProtectUefiServices
 
STATIC BOOLEAN mFixupAppleEfiImages
 
STATIC EFI_IMAGE_LOAD mPreservedLoadImage
 
STATIC EFI_IMAGE_START mPreservedStartImage
 
STATIC EFI_EXIT_BOOT_SERVICES mPreservedExitBootServices
 
STATIC EFI_EXIT mPreservedExit
 

Detailed Description

Copyright (C) 2019, 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 ImageLoader.c.

Function Documentation

◆ DetectCapabilities()

STATIC UINT32 DetectCapabilities ( IN VOID * SourceBuffer,
IN UINT32 SourceSize )

Detect kernel capabilities from EfiBoot image.

Parameters
[in]SourceBufferBuffer containing EfiBoot.
[in]SourceSizeSize of EfiBoot buffer.
Returns
OC_KERN_CAPABILITY bitmask.

Definition at line 702 of file ImageLoader.c.

◆ InternalDirectExit()

STATIC EFI_STATUS InternalDirectExit ( IN OC_LOADED_IMAGE_PROTOCOL * OcLoadedImage,
IN EFI_HANDLE ImageHandle,
IN EFI_STATUS ExitStatus,
IN UINTN ExitDataSize,
IN CHAR16 *ExitData OPTIONAL )

Unload image routine for OcImageLoaderLoad.

Parameters
[in]OcLoadedImageOur loaded image instance.
[in]ImageHandleHandle that identifies the image to be unloaded.
[in]ExitStatusThe image's exit code.
[in]ExitDataSizeThe size, in bytes, of ExitData. Ignored if ExitStatus is EFI_SUCCESS.
[in]ExitDataThe pointer to a data buffer that includes a Null-terminated string, optionally followed by additional binary data. The string is a description that the caller may use to further indicate the reason for the image's exit. ExitData is only valid if ExitStatus is something other than EFI_SUCCESS. The ExitData buffer must be allocated by calling AllocatePool().
Return values
EFI_SUCCESSThe image has been unloaded.

Definition at line 501 of file ImageLoader.c.

◆ InternalDirectStartImage()

STATIC EFI_STATUS InternalDirectStartImage ( IN OC_LOADED_IMAGE_PROTOCOL * OcLoadedImage,
IN EFI_HANDLE ImageHandle,
OUT UINTN * ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL )

Simplified start image routine for OcImageLoaderLoad.

Parameters
[in]OcLoadedImageOur loaded image instance.
[in]ImageHandleHandle of image to be started.
[out]ExitDataSizeThe pointer to the size, in bytes, of ExitData.
[out]ExitDataThe pointer to a pointer to a data buffer that includes a Null-terminated string, optionally followed by additional binary data.
Return values
EFI_SUCCESSon success.

Definition at line 589 of file ImageLoader.c.

◆ InternalDirectUnloadImage()

STATIC EFI_STATUS InternalDirectUnloadImage ( IN OC_LOADED_IMAGE_PROTOCOL * OcLoadedImage,
IN EFI_HANDLE ImageHandle )

Unload image routine for OcImageLoaderLoad.

Parameters
[in]OcLoadedImageOur loaded image instance.
[in]ImageHandleHandle that identifies the image to be unloaded.
Return values
EFI_SUCCESSThe image has been unloaded.

Definition at line 440 of file ImageLoader.c.

◆ InternalEfiExit()

STATIC EFI_STATUS EFIAPI InternalEfiExit ( IN EFI_HANDLE ImageHandle,
IN EFI_STATUS ExitStatus,
IN UINTN ExitDataSize,
IN CHAR16 *ExitData OPTIONAL )

Definition at line 1180 of file ImageLoader.c.

◆ InternalEfiLoadImage()

STATIC EFI_STATUS EFIAPI InternalEfiLoadImage ( IN BOOLEAN BootPolicy,
IN EFI_HANDLE ParentImageHandle,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN VOID *SourceBuffer OPTIONAL,
IN UINTN SourceSize,
OUT EFI_HANDLE * ImageHandle )

Definition at line 774 of file ImageLoader.c.

◆ InternalEfiLoadImageFile()

STATIC EFI_STATUS InternalEfiLoadImageFile ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
OUT UINTN * FileSize,
OUT VOID ** FileBuffer )

Definition at line 154 of file ImageLoader.c.

◆ InternalEfiLoadImageProtocol()

STATIC EFI_STATUS InternalEfiLoadImageProtocol ( IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN BOOLEAN UseLoadImage2,
OUT UINTN * FileSize,
OUT VOID ** FileBuffer )

Definition at line 209 of file ImageLoader.c.

◆ InternalEfiStartImage()

STATIC EFI_STATUS EFIAPI InternalEfiStartImage ( IN EFI_HANDLE ImageHandle,
OUT UINTN * ExitDataSize,
OUT CHAR16 **ExitData OPTIONAL )

Definition at line 1045 of file ImageLoader.c.

◆ InternalEfiUnloadImage()

STATIC EFI_STATUS EFIAPI InternalEfiUnloadImage ( IN EFI_HANDLE ImageHandle)

Definition at line 1129 of file ImageLoader.c.

◆ InternalUpdateLoadedImage()

STATIC EFI_STATUS InternalUpdateLoadedImage ( IN EFI_HANDLE ImageHandle,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath )

Definition at line 224 of file ImageLoader.c.

◆ OcImageLoaderActivate()

VOID OcImageLoaderActivate ( VOID )

Make DirectImageLoader the default for Apple Secure Boot.

Definition at line 1242 of file ImageLoader.c.

◆ OcImageLoaderInit()

VOID OcImageLoaderInit ( IN CONST BOOLEAN ProtectUefiServices,
IN CONST BOOLEAN FixupAppleEfiImages )

Initialises custom Boot Services overrides to support direct images.

Definition at line 1219 of file ImageLoader.c.

◆ OcImageLoaderLoad()

EFI_STATUS EFIAPI OcImageLoaderLoad ( IN BOOLEAN BootPolicy,
IN EFI_HANDLE ParentImageHandle,
IN EFI_DEVICE_PATH_PROTOCOL * DevicePath,
IN VOID *SourceBuffer OPTIONAL,
IN UINTN SourceSize,
OUT EFI_HANDLE * ImageHandle )

Simplified load image routine, which bypasses UEFI and loads the image directly.

Parameters
[in]BootPolicyIgnored.
[in]ParentImageHandleThe caller's image handle.
[in]DevicePathIgnored.
[in]SourceBufferPointer to the memory location containing image to be loaded.
[in]SourceSizeThe size in bytes of SourceBuffer.
[out]ImageHandleThe pointer to the returned image handle created on success.
Return values
EFI_SUCCESSon success.

Definition at line 262 of file ImageLoader.c.

◆ OcImageLoaderRegisterConfigure()

VOID OcImageLoaderRegisterConfigure ( IN OC_IMAGE_LOADER_CONFIGURE Configure OPTIONAL)

Register image start callback.

Parameters
[in]ConfigureCallback function to call on image start.

Definition at line 1258 of file ImageLoader.c.

◆ OcImageLoaderRegisterPatch()

VOID OcImageLoaderRegisterPatch ( IN OC_IMAGE_LOADER_PATCH Patch OPTIONAL)

Register image loading callback.

Parameters
[in]PatchCallback function to call on image load.

Definition at line 1250 of file ImageLoader.c.

◆ PreserveGrubShimHooks()

STATIC VOID PreserveGrubShimHooks ( VOID )

Definition at line 103 of file ImageLoader.c.

◆ RestoreGrubShimHooks()

STATIC VOID RestoreGrubShimHooks ( IN CONST CHAR8 * Caller)

Definition at line 122 of file ImageLoader.c.

Variable Documentation

◆ mCurrentImageHandle

STATIC EFI_HANDLE mCurrentImageHandle

Definition at line 87 of file ImageLoader.c.

◆ mFixupAppleEfiImages

STATIC BOOLEAN mFixupAppleEfiImages

Definition at line 94 of file ImageLoader.c.

◆ mImageLoaderConfigure

STATIC OC_IMAGE_LOADER_CONFIGURE mImageLoaderConfigure

Definition at line 90 of file ImageLoader.c.

◆ mImageLoaderEnabled

STATIC BOOLEAN mImageLoaderEnabled

Definition at line 91 of file ImageLoader.c.

◆ mImageLoaderPatch

STATIC OC_IMAGE_LOADER_PATCH mImageLoaderPatch

Definition at line 89 of file ImageLoader.c.

◆ mOcImageLoaderCapsProtocolGuid

STATIC EFI_GUID mOcImageLoaderCapsProtocolGuid
Initial value:
= {
0xf5bbca36, 0x0f99, 0x4e7b, { 0x86, 0x0f, 0x92, 0x06, 0xa9, 0x3b, 0x52, 0xd0 }
}

Definition at line 61 of file ImageLoader.c.

◆ mOcLoadedImageProtocolGuid

STATIC EFI_GUID mOcLoadedImageProtocolGuid
Initial value:
= {
0x1f3c963d, 0xf9dc, 0x4537, { 0xbb, 0x06, 0xd8, 0x08, 0x46, 0x4a, 0x85, 0x2e }
}

Definition at line 57 of file ImageLoader.c.

◆ mOriginalEfiExit

STATIC EFI_EXIT mOriginalEfiExit

Definition at line 86 of file ImageLoader.c.

◆ mOriginalEfiLoadImage

STATIC EFI_IMAGE_LOAD mOriginalEfiLoadImage

Definition at line 83 of file ImageLoader.c.

◆ mOriginalEfiStartImage

STATIC EFI_IMAGE_START mOriginalEfiStartImage

Definition at line 84 of file ImageLoader.c.

◆ mOriginalEfiUnloadImage

STATIC EFI_IMAGE_UNLOAD mOriginalEfiUnloadImage

Definition at line 85 of file ImageLoader.c.

◆ mPreservedExit

STATIC EFI_EXIT mPreservedExit

Definition at line 99 of file ImageLoader.c.

◆ mPreservedExitBootServices

STATIC EFI_EXIT_BOOT_SERVICES mPreservedExitBootServices

Definition at line 98 of file ImageLoader.c.

◆ mPreservedLoadImage

STATIC EFI_IMAGE_LOAD mPreservedLoadImage

Definition at line 96 of file ImageLoader.c.

◆ mPreservedStartImage

STATIC EFI_IMAGE_START mPreservedStartImage

Definition at line 97 of file ImageLoader.c.

◆ mProtectUefiServices

STATIC BOOLEAN mProtectUefiServices

Definition at line 93 of file ImageLoader.c.