OpenCore
1.0.4
OpenCore Bootloader
|
#include <Base.h>
#include <IndustryStandard/AppleKmodInfo.h>
#include <IndustryStandard/AppleMachoImage.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/BaseOverflowLib.h>
#include <Library/DebugLib.h>
#include <Library/OcAppleKernelLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcFileLib.h>
#include "PrelinkedInternal.h"
Go to the source code of this file.
Macros | |
#define | TEXT_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_EXECUTE) |
#define | DATA_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_WRITE) |
#define | MATCH(X) |
Functions | |
STATIC CONST PRELINKED_KEXT_SYMBOL * | InternalOcGetSymbolWorkerName (IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *LookupValue, IN UINT32 LookupValueLength, IN OC_GET_SYMBOL_LEVEL SymbolLevel) |
STATIC CONST PRELINKED_KEXT_SYMBOL * | InternalOcGetSymbolWorkerValue (IN PRELINKED_KEXT *Kext, IN UINT64 LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel) |
CONST PRELINKED_KEXT_SYMBOL * | InternalOcGetSymbolName (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel) |
CONST PRELINKED_KEXT_SYMBOL * | InternalOcGetSymbolValue (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LookupValue, IN OC_GET_SYMBOL_LEVEL SymbolLevel) |
VOID | InternalSolveSymbolValue (IN BOOLEAN Is32Bit, IN UINT64 Value, OUT MACH_NLIST_ANY *Symbol) |
STATIC BOOLEAN | InternalSolveSymbolNonWeak (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *Name, IN OUT MACH_NLIST_ANY *Symbol) |
STATIC BOOLEAN | InternalSolveSymbol (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN CONST CHAR8 *Name, IN OUT MACH_NLIST_ANY *Symbol, IN OUT UINT64 *WeakTestValue, IN CONST MACH_NLIST_ANY *UndefinedSymbols, IN UINT32 NumUndefinedSymbols) |
STATIC BOOLEAN | InternalCalculateDisplacementIntel64 (IN UINT64 Target, IN UINT64 Adjustment, IN OUT INT32 *Instruction) |
STATIC BOOLEAN | InternalCalculateTargets (IN PRELINKED_CONTEXT *Context, IN OUT PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN CONST MACH_RELOCATION_INFO *Relocation, IN CONST MACH_RELOCATION_INFO *NextRelocation OPTIONAL, OUT UINT64 *Target, OUT UINT64 *PairTarget, OUT CONST PRELINKED_VTABLE **Vtable OPTIONAL) |
STATIC BOOLEAN | InternalIsDirectPureVirtualCall (IN BOOLEAN Is32Bit, IN CONST PRELINKED_VTABLE *Vtable, IN UINT64 Offset) |
STATIC UINTN | InternalRelocateRelocation (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 RelocationBase, IN CONST MACH_RELOCATION_INFO *Relocation, IN CONST MACH_RELOCATION_INFO *NextRelocation OPTIONAL) |
STATIC BOOLEAN | InternalRelocateAndCopyRelocations (IN PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 RelocationBase, IN CONST MACH_RELOCATION_INFO *SourceRelocations, IN OUT UINT32 *NumRelocations, OUT MACH_RELOCATION_INFO *TargetRelocations) |
STATIC BOOLEAN | InternalRelocateSymbol (IN OC_MACHO_CONTEXT *MachoContext, IN UINT64 LoadAddress, IN OUT MACH_NLIST_ANY *Symbol, IN OUT UINT32 *KmodInfoOffset) |
STATIC BOOLEAN | InternalRelocateSymbols (IN OC_MACHO_CONTEXT *MachoContext, IN UINT64 LoadAddress, IN UINT32 NumSymbols, IN OUT MACH_NLIST_ANY *Symbols, OUT UINT32 *KmodInfoOffset) |
STATIC BOOLEAN | InternalProcessSymbolPointers (IN OC_MACHO_CONTEXT *MachoContext, IN CONST MACH_DYSYMTAB_COMMAND *DySymtab, IN UINT64 LoadAddress) |
EFI_STATUS | InternalPrelinkKext (IN OUT PRELINKED_CONTEXT *Context, IN PRELINKED_KEXT *Kext, IN UINT64 LoadAddress, IN UINT64 FileOffset) |
Library handling KEXT prelinking.
Copyright (c) 2018, Download-Fritz. 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 Link.c.
#define DATA_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_WRITE) |
#define MATCH | ( | X | ) |
#define TEXT_SEG_PROT (MACH_SEGMENT_VM_PROT_READ | MACH_SEGMENT_VM_PROT_EXECUTE) |
STATIC BOOLEAN InternalCalculateDisplacementIntel64 | ( | IN UINT64 | Target, |
IN UINT64 | Adjustment, | ||
IN OUT INT32 * | Instruction ) |
Calculate the target address' displacement for the Intel 64 platform. Instruction will be patched with the resulting address. Logically matches XNU's calculate_displacement_x86_64.
[in] | Target | The target address. |
[in] | Adjustment | Adjustment to be subtracted from the displacement. |
[in,out] | Instruction | Pointer to the instruction to be patched. |
Returned | is whether the target instruction has been patched. |
STATIC BOOLEAN InternalCalculateTargets | ( | IN PRELINKED_CONTEXT * | Context, |
IN OUT PRELINKED_KEXT * | Kext, | ||
IN UINT64 | LoadAddress, | ||
IN CONST MACH_RELOCATION_INFO * | Relocation, | ||
IN CONST MACH_RELOCATION_INFO *NextRelocation | OPTIONAL, | ||
OUT UINT64 * | Target, | ||
OUT UINT64 * | PairTarget, | ||
OUT CONST PRELINKED_VTABLE **Vtable | OPTIONAL ) |
Calculate the target addresses for Relocation and NextRelocation. Logically matches XNU's calculate_targets.
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | LoadAddress | The address to be linked against. |
[in] | Relocation | The Relocation to be resolved. |
[in] | NextRelocation | The Relocation following Relocation. |
[out] | Target | Relocation's target address. |
[out] | PairTarget | NextRelocation's target address. |
[out] | Vtable | The VTable described by the symbol referenced by Relocation. NULL, if there is none. |
STATIC BOOLEAN InternalIsDirectPureVirtualCall | ( | IN BOOLEAN | Is32Bit, |
IN CONST PRELINKED_VTABLE * | Vtable, | ||
IN UINT64 | Offset ) |
CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolName | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN CONST CHAR8 * | LookupValue, | ||
IN OC_GET_SYMBOL_LEVEL | SymbolLevel ) |
CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolValue | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN UINT64 | LookupValue, | ||
IN OC_GET_SYMBOL_LEVEL | SymbolLevel ) |
STATIC CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolWorkerName | ( | IN PRELINKED_KEXT * | Kext, |
IN CONST CHAR8 * | LookupValue, | ||
IN UINT32 | LookupValueLength, | ||
IN OC_GET_SYMBOL_LEVEL | SymbolLevel ) |
STATIC CONST PRELINKED_KEXT_SYMBOL * InternalOcGetSymbolWorkerValue | ( | IN PRELINKED_KEXT * | Kext, |
IN UINT64 | LookupValue, | ||
IN OC_GET_SYMBOL_LEVEL | SymbolLevel ) |
EFI_STATUS InternalPrelinkKext | ( | IN OUT PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN UINT64 | LoadAddress, | ||
IN UINT64 | FileOffset ) |
Prelinks the specified KEXT against the specified LoadAddress and the data of its dependencies.
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | LoadAddress | The address this KEXT shall be linked against. |
[in] | FileOffset | The file offset of the first segment. |
Returned | is whether the prelinking process has been successful. The state of the KEXT is undefined in case this routine fails. |
STATIC BOOLEAN InternalProcessSymbolPointers | ( | IN OC_MACHO_CONTEXT * | MachoContext, |
IN CONST MACH_DYSYMTAB_COMMAND * | DySymtab, | ||
IN UINT64 | LoadAddress ) |
STATIC BOOLEAN InternalRelocateAndCopyRelocations | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN UINT64 | LoadAddress, | ||
IN UINT64 | RelocationBase, | ||
IN CONST MACH_RELOCATION_INFO * | SourceRelocations, | ||
IN OUT UINT32 * | NumRelocations, | ||
OUT MACH_RELOCATION_INFO * | TargetRelocations ) |
Relocates all Mach-O Relocations and copies the ones to be preserved after prelinking to TargetRelocations.
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | LoadAddress | The address to be linked against. dependencies. |
[in] | RelocationBase | The Relocations base address. |
[in] | SourceRelocations | The Relocations source buffer. |
[in] | NumRelocations | On input, the number of source Relocations. On output, the number of Relocations to preserve. |
[out] | TargetRelocations | The Relocations destination buffer. |
Returned | is the number of preserved Relocations. |
STATIC UINTN InternalRelocateRelocation | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN UINT64 | LoadAddress, | ||
IN UINT64 | RelocationBase, | ||
IN CONST MACH_RELOCATION_INFO * | Relocation, | ||
IN CONST MACH_RELOCATION_INFO *NextRelocation | OPTIONAL ) |
Relocates Relocation against the specified Symtab's Symbol Table and LoadAddress. This logically matches KXLD's generic_process_reloc (for 32-bit) and x86_64_process_reloc (for 64-bit).
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | LoadAddress | The address to be linked against. |
[in] | RelocationBase | The Relocations base address. |
[in] | Relocation | The Relocation to be processed. |
[in] | NextRelocation | The Relocation following Relocation. |
0 | The Relocation does not need to be preseved. |
1 | The Relocation must be preseved. |
0 | | BIT31 The Relocation does not need to be preseved. The next Relocation shall be skipped. |
1 | | BIT31 The Relocation must be preseved. The next Relocation shall be skipped. |
MAX_UINTN | The Relocation's target cannot be determined or it is a direct pure virtual call. |
STATIC BOOLEAN InternalRelocateSymbol | ( | IN OC_MACHO_CONTEXT * | MachoContext, |
IN UINT64 | LoadAddress, | ||
IN OUT MACH_NLIST_ANY * | Symbol, | ||
IN OUT UINT32 * | KmodInfoOffset ) |
STATIC BOOLEAN InternalRelocateSymbols | ( | IN OC_MACHO_CONTEXT * | MachoContext, |
IN UINT64 | LoadAddress, | ||
IN UINT32 | NumSymbols, | ||
IN OUT MACH_NLIST_ANY * | Symbols, | ||
OUT UINT32 * | KmodInfoOffset ) |
STATIC BOOLEAN InternalSolveSymbol | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN CONST CHAR8 * | Name, | ||
IN OUT MACH_NLIST_ANY * | Symbol, | ||
IN OUT UINT64 * | WeakTestValue, | ||
IN CONST MACH_NLIST_ANY * | UndefinedSymbols, | ||
IN UINT32 | NumUndefinedSymbols ) |
Solves Symbol against the specified DefinedSymbols.
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | Name | The name of the symbol to resolve against. |
[in,out] | Symbol | The symbol to be resolved. |
[in,out] | WeakTestValue | Points to the value of the Weak test symbol. If it is 0 on input, it will get assigned the value on the first resolution of a weak symbol. |
[in] | UndefinedSymbols | Array of the Mach-O'S undefined symbols. |
[in] | NumUndefinedSymbols | Number of symbols in UndefinedSymbols. |
Returned | is whether the symbol was solved successfully. For weak symbols, this includes solving with _gOSKextUnresolved. |
STATIC BOOLEAN InternalSolveSymbolNonWeak | ( | IN PRELINKED_CONTEXT * | Context, |
IN PRELINKED_KEXT * | Kext, | ||
IN CONST CHAR8 * | Name, | ||
IN OUT MACH_NLIST_ANY * | Symbol ) |
Worker function to solve Symbol against the specified DefinedSymbols. It does not consider Symbol might be a weak reference.
[in,out] | Context | Prelinking context. |
[in] | Kext | KEXT prelinking context. |
[in] | Name | The name of the symbol to resolve against. |
[in,out] | Symbol | The symbol to be resolved. |
Returned | is whether the symbol was solved successfully. |
VOID InternalSolveSymbolValue | ( | IN BOOLEAN | Is32Bit, |
IN UINT64 | Value, | ||
OUT MACH_NLIST_ANY * | Symbol ) |