Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
btwise
OpenCorePKG_MOD
提交
a27fe27f
O
OpenCorePKG_MOD
项目概览
btwise
/
OpenCorePKG_MOD
通知
26
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
OpenCorePKG_MOD
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
a27fe27f
编写于
4月 16, 2024
作者:
草原企鹅
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of
https://github.com/acidanthera/OpenCorePkg
上级
e4091726
9ede6067
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
484 addition
and
191 deletion
+484
-191
Changelog.md
Changelog.md
+4
-1
Docs/Configuration.md5
Docs/Configuration.md5
+1
-1
Docs/Configuration.pdf
Docs/Configuration.pdf
+0
-0
Docs/Configuration.tex
Docs/Configuration.tex
+2
-2
Docs/Differences/Differences.pdf
Docs/Differences/Differences.pdf
+0
-0
Docs/Differences/Differences.tex
Docs/Differences/Differences.tex
+6
-4
Docs/Errata/Errata.pdf
Docs/Errata/Errata.pdf
+0
-0
Library/OcAfterBootCompatLib/BootCompatInternal.h
Library/OcAfterBootCompatLib/BootCompatInternal.h
+62
-4
Library/OcAfterBootCompatLib/Ia32/KernelSupport32.c
Library/OcAfterBootCompatLib/Ia32/KernelSupport32.c
+152
-0
Library/OcAfterBootCompatLib/Ia32/KernelTrampoline.nasm
Library/OcAfterBootCompatLib/Ia32/KernelTrampoline.nasm
+41
-0
Library/OcAfterBootCompatLib/KernelSupport.c
Library/OcAfterBootCompatLib/KernelSupport.c
+0
-147
Library/OcAfterBootCompatLib/OcAfterBootCompatLib.inf
Library/OcAfterBootCompatLib/OcAfterBootCompatLib.inf
+7
-0
Library/OcAfterBootCompatLib/RelocationBlock.c
Library/OcAfterBootCompatLib/RelocationBlock.c
+1
-1
Library/OcAfterBootCompatLib/ServiceOverrides.c
Library/OcAfterBootCompatLib/ServiceOverrides.c
+27
-11
Library/OcAfterBootCompatLib/X64/KernelSupport64.c
Library/OcAfterBootCompatLib/X64/KernelSupport64.c
+165
-0
User/Makefile
User/Makefile
+2
-7
Utilities/BaseTools/Makefile
Utilities/BaseTools/Makefile
+1
-1
Utilities/RsaTool/Makefile
Utilities/RsaTool/Makefile
+10
-2
Utilities/RsaTool/build_libressl.sh
Utilities/RsaTool/build_libressl.sh
+3
-10
未找到文件。
Changelog.md
浏览文件 @
a27fe27f
...
...
@@ -2,7 +2,10 @@ OpenCore Changelog
==================
#### v1.0.0
-
Updated builtin firmware versions for SMBIOS and the rest
-
Use Apple silicon GitHub runner for CI, thx @Goooler
-
Switched to Apple silicon GitHub runner for CI, thx @Goooler
-
Added Apple Silicon support in all provided utilities
-
Utilities now require macOS 10.9+ (OpenCore itself still supports macOS 10.4+)
-
Added
`AllowRelocationBlock`
support for 32-bit version
#### v0.9.9
-
Fixed incorrect warning in ocvalidate
...
...
Docs/Configuration.md5
浏览文件 @
a27fe27f
1a71d1870e336326d90153724e52def0
e8b51b8b5d7acdef262b61a3aed6bf05
Docs/Configuration.pdf
浏览文件 @
a27fe27f
无法预览此类型文件
Docs/Configuration.tex
浏览文件 @
a27fe27f
...
...
@@ -1487,8 +1487,8 @@ To view their current state, use the \texttt{pmset -g} command in Terminal.
\item
KASLR (slide) is unsupported (this is Mac OS X 10.7 or older)
\end{itemize}
This quirk
requires
\texttt
{
ProvideCustomSlide
}
to be enabled
and
typically also requires enabling
\texttt
{
AvoidRuntimeDefrag
}
to function
This quirk
typically requires
\texttt
{
ProvideCustomSlide
}
and
\texttt
{
AvoidRuntimeDefrag
}
to be enabled
to function
correctly. Hibernation is not supported when booting with a relocation
block, which will only be used if required when the quirk is enabled.
...
...
Docs/Differences/Differences.pdf
浏览文件 @
a27fe27f
无法预览此类型文件
Docs/Differences/Differences.tex
浏览文件 @
a27fe27f
\documentclass
[]
{
article
}
%DIF LATEXDIFF DIFFERENCE FILE
%DIF DEL PreviousConfiguration.tex
Tue Mar 12 23:19:24
2024
%DIF ADD ../Configuration.tex
Wed Mar 13 00:03:04
2024
%DIF DEL PreviousConfiguration.tex
Sun Apr 7 20:10:19
2024
%DIF ADD ../Configuration.tex
Mon Apr 8 11:31:07
2024
\usepackage
{
lmodern
}
\usepackage
{
amssymb,amsmath
}
...
...
@@ -1547,8 +1547,10 @@ To view their current state, use the \texttt{pmset -g} command in Terminal.
\item
KASLR (slide) is unsupported (this is
\DIFdelbegin
\DIFdel
{
macOS
}
\DIFdelend
\DIFaddbegin
\DIFadd
{
Mac OS X
}
\DIFaddend
10.7 or older)
\end{itemize}
This quirk requires
\texttt
{
ProvideCustomSlide
}
to be enabled and
typically also requires enabling
\texttt
{
AvoidRuntimeDefrag
}
to function
This quirk
\DIFaddbegin
\DIFadd
{
typically
}
\DIFaddend
requires
\texttt
{
ProvideCustomSlide
}
\DIFaddbegin
\DIFadd
{
and
}
\texttt
{
\DIFadd
{
AvoidRuntimeDefrag
}}
\DIFaddend
to be enabled
\DIFdelbegin
\DIFdel
{
and
typically also requires enabling
}
\texttt
{
\DIFdel
{
AvoidRuntimeDefrag
}}
%DIFAUXCMD
\DIFdelend
to function
correctly. Hibernation is not supported when booting with a relocation
block, which will only be used if required when the quirk is enabled.
...
...
Docs/Errata/Errata.pdf
浏览文件 @
a27fe27f
无法预览此类型文件
Library/OcAfterBootCompatLib/BootCompatInternal.h
浏览文件 @
a27fe27f
...
...
@@ -502,6 +502,16 @@ AppleMapPrepareBooterState (
IN
EFI_GET_MEMORY_MAP
GetMemoryMap
OPTIONAL
);
/**
Patch kernel entry point with KernelJump to later land in AppleMapPrepareKernelState.
@param[in,out] BootCompat Boot compatibility context.
**/
VOID
AppleMapPrepareKernelJump32
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
);
/**
Patch kernel entry point with KernelJump to later land in AppleMapPrepareKernelState.
...
...
@@ -511,12 +521,36 @@ AppleMapPrepareBooterState (
entering the kernel call gate.
**/
VOID
AppleMapPrepareKernelJump
(
AppleMapPrepareKernelJump
64
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
EFI_PHYSICAL_ADDRESS
CallGate
,
IN
UINTN
HookAddress
);
/**
Prepare environment for normal booting. Called when boot.efi jumps to kernel.
@param[in,out] BootCompat Boot compatibility context.
@param[in,out] BootArgs Apple kernel boot arguments.
**/
VOID
AppleMapPrepareForBooting
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
OUT
VOID
*
BootArgs
);
/**
Prepare environment for hibernate wake. Called when boot.efi jumps to kernel.
@param[in,out] BootCompat Boot compatibility context.
@param[in,out] ImageHeaderPage Apple hibernate image page number.
**/
VOID
AppleMapPrepareForHibernateWake
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
UINTN
ImageHeaderPage
);
/**
Prepare memory state and perform virtual address translation.
...
...
@@ -535,6 +569,30 @@ AppleMapPrepareMemState (
IN
EFI_MEMORY_DESCRIPTOR
*
MemoryMap
);
/**
Assembly wrapper for AppleMapPrepareKernelState32.
Used to convert calling conventions and fixup registers.
**/
VOID
AsmAppleMapPrepareKernelState32
(
VOID
);
/**
Prepare environment for Apple kernel bootloader in boot or wake cases.
This callback arrives when boot.efi jumps to kernel entry point.
Should transfer control to restored kernel entry point with the same arguments.
@param[in] Args Case-specific kernel argument handle.
@returns Case-specific value if any.
**/
UINTN
EFIAPI
AppleMapPrepareKernelState32
(
IN
UINTN
Args
);
/**
Prepare environment for Apple kernel bootloader in boot or wake cases.
This callback arrives when boot.efi jumps to kernel call gate.
...
...
@@ -553,7 +611,7 @@ AppleMapPrepareMemState (
**/
EFI_STATUS
EFIAPI
AppleMapPrepareKernelStateNew
(
AppleMapPrepareKernelStateNew
64
(
IN
UINTN
SystemTable
,
IN
OUT
APPLE_EFI_BOOT_RT_KCG_ARGS
*
KcgArguments
,
IN
KERNEL_CALL_GATE
CallGate
...
...
@@ -575,7 +633,7 @@ AppleMapPrepareKernelStateNew (
**/
UINTN
EFIAPI
AppleMapPrepareKernelStateOld
(
AppleMapPrepareKernelStateOld
64
(
IN
UINTN
Args
,
IN
UINTN
EntryPoint
,
IN
KERNEL_CALL_GATE
CallGate
...
...
@@ -724,7 +782,7 @@ AppleRelocationRebase (
@param[in] KcgArg2 Second kernel call gate argument.
**/
VOID
AppleRelocationCallGate
(
AppleRelocationCallGate
64
(
IN
OUT
UINTN
*
Args
,
IN
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
KERNEL_CALL_GATE
CallGate
,
...
...
Library/OcAfterBootCompatLib/Ia32/KernelSupport32.c
0 → 100644
浏览文件 @
a27fe27f
/** @file
Copyright (C) 2019-2024, 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.
**/
#include "../BootCompatInternal.h"
#include <Guid/OcVariable.h>
#include <IndustryStandard/AppleHibernate.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDeviceTreeLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcStringLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
VOID
AppleMapPrepareKernelJump32
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
)
{
UINT8
*
KernelEntry
;
UINT32
Offset
;
BOOLEAN
Found
;
//
// There is no reason to patch the kernel when we do not need it.
//
if
(
!
BootCompat
->
Settings
.
AvoidRuntimeDefrag
&&
!
BootCompat
->
Settings
.
DiscardHibernateMap
&&
!
BootCompat
->
Settings
.
AllowRelocationBlock
&&
!
BootCompat
->
Settings
.
DisableSingleUser
&&
!
BootCompat
->
Settings
.
ForceBooterSignature
)
{
return
;
}
//
// TODO: Add support for 32-bit hibernation some day.
//
if
(
BootCompat
->
ServiceState
.
AppleHibernateWake
)
{
RUNTIME_DEBUG
((
DEBUG_ERROR
,
"OCABC: Cannot patch 32-bit kernel in hibernate wake!
\n
"
));
CpuDeadLoop
();
}
//
// There are no call gates in 32-bit mode.
//
ASSERT
(
BootCompat
->
ServiceState
.
OldKernelCallGate
==
0
);
//
// Search for kernel entry point.
// This sequence seems to be relatively stable for 10.4 ~ 10.6.
//
STATIC
CONST
UINT8
mEntryBytes
[]
=
{
0x66
,
0x8C
,
0xDB
,
///< mov bx, ds
0x8E
,
0xC3
,
///< mov es, ebx
0x89
,
0xC5
,
///< mov ebp, eax
};
Offset
=
0
;
if
(
BootCompat
->
KernelState
.
RelocationBlock
!=
0
)
{
Found
=
FindPattern
(
mEntryBytes
,
NULL
,
sizeof
(
mEntryBytes
),
(
VOID
*
)(
UINTN
)
BootCompat
->
KernelState
.
RelocationBlock
,
BootCompat
->
KernelState
.
RelocationBlockUsed
,
&
Offset
);
}
else
{
Found
=
FindPattern
(
mEntryBytes
,
NULL
,
sizeof
(
mEntryBytes
),
(
VOID
*
)(
UINTN
)
KERNEL_BASE_PADDR
,
BASE_2MB
,
&
Offset
);
}
if
(
!
Found
)
{
RUNTIME_DEBUG
((
DEBUG_ERROR
,
"OCABC: No 32-bit kernel entry!
\n
"
));
CpuDeadLoop
();
}
KernelEntry
=
(
VOID
*
)(
UINTN
)(
KERNEL_BASE_PADDR
+
Offset
);
KernelEntry
[
0
]
=
0xE8
;
///< call
Offset
=
(
UINTN
)((
UINTN
)
AsmAppleMapPrepareKernelState32
-
(
UINTN
)
KernelEntry
-
5
);
CopyMem
(
&
KernelEntry
[
1
],
&
Offset
,
sizeof
(
UINT32
));
}
UINTN
EFIAPI
AppleMapPrepareKernelState32
(
IN
UINTN
Args
)
{
BOOT_COMPAT_CONTEXT
*
BootCompat
;
BootCompat
=
GetBootCompatContext
();
if
(
BootCompat
->
ServiceState
.
AppleHibernateWake
)
{
//
// TODO: This is not really implemented.
//
AppleMapPrepareForHibernateWake
(
BootCompat
,
Args
);
}
else
{
AppleMapPrepareForBooting
(
BootCompat
,
(
VOID
*
)
Args
);
}
if
(
BootCompat
->
KernelState
.
RelocationBlock
!=
0
)
{
Args
-=
(
UINTN
)(
BootCompat
->
KernelState
.
RelocationBlock
-
KERNEL_BASE_PADDR
);
//
// FIXME: This should be done via trampoline as we may overwrite ourselves.
// See RelocationCallGate.nasm for more details.
//
CopyMem
(
(
VOID
*
)(
UINTN
)
KERNEL_BASE_PADDR
,
(
VOID
*
)(
UINTN
)
BootCompat
->
KernelState
.
RelocationBlock
,
BootCompat
->
KernelState
.
RelocationBlockUsed
);
}
return
Args
;
}
Library/OcAfterBootCompatLib/Ia32/KernelTrampoline.nasm
0 → 100644
浏览文件 @
a27fe27f
;------------------------------------------------------------------------------
; @file
; Copyright (C) 2024, 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.
;------------------------------------------------------------------------------
BITS 32
DEFAULT REL
SECTION .text
extern ASM_PFX(AppleMapPrepareKernelState32)
align 8
global ASM_PFX(AsmAppleMapPrepareKernelState32)
ASM_PFX(AsmAppleMapPrepareKernelState32):
; Pass kernel arguments as an argument.
; EDK II does not seem to align stack by more than 4 bytes.
push eax
; Call our C wrapper.
call ASM_PFX(AppleMapPrepareKernelState32)
; Restore stack pointer for ret function.
; We might have updated eax via return for relocation block.
add esp, 4
; Execute overwritten instructions by a jump to our asm handler.
mov bx, ds
mov es, ebx
; Return to kernel.
ret
Library/OcAfterBootCompatLib/KernelSupport.c
浏览文件 @
a27fe27f
...
...
@@ -321,13 +321,6 @@ RestoreProtectedRtMemoryTypes (
}
}
/**
Prepare environment for normal booting. Called when boot.efi jumps to kernel.
@param[in,out] BootCompat Boot compatibility context.
@param[in,out] BootArgs Apple kernel boot arguments.
**/
STATIC
VOID
AppleMapPrepareForBooting
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
...
...
@@ -439,13 +432,6 @@ AppleMapPrepareForBooting (
}
}
/**
Prepare environment for hibernate wake. Called when boot.efi jumps to kernel.
@param[in,out] BootCompat Boot compatibility context.
@param[in,out] ImageHeaderPage Apple hibernate image page number.
**/
STATIC
VOID
AppleMapPrepareForHibernateWake
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
...
...
@@ -618,66 +604,6 @@ AppleMapPrepareBooterState (
}
}
VOID
AppleMapPrepareKernelJump
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
EFI_PHYSICAL_ADDRESS
CallGate
,
IN
UINTN
HookAddress
)
{
CALL_GATE_JUMP
*
CallGateJump
;
//
// There is no reason to patch the kernel when we do not need it.
//
if
(
!
BootCompat
->
Settings
.
AvoidRuntimeDefrag
&&
!
BootCompat
->
Settings
.
DiscardHibernateMap
&&
!
BootCompat
->
Settings
.
AllowRelocationBlock
&&
!
BootCompat
->
Settings
.
DisableSingleUser
&&
!
BootCompat
->
Settings
.
ForceBooterSignature
)
{
return
;
}
#ifndef MDE_CPU_X64
RUNTIME_DEBUG
((
DEBUG_ERROR
,
"OCABC: Kernel trampolines are unsupported for non-X64
\n
"
));
CpuDeadLoop
();
#endif
//
// Check whether we have address and abort if not.
//
if
(
CallGate
==
0
)
{
RUNTIME_DEBUG
((
DEBUG_ERROR
,
"OCABC: Failed to find call gate address
\n
"
));
return
;
}
CallGateJump
=
(
VOID
*
)(
UINTN
)
CallGate
;
//
// Move call gate jump bytes front.
// Performing this on the EfiBootRt KCG may bork the binary, but right now
// only corrupts an unused string.
//
CopyMem
(
CallGateJump
+
1
,
CallGateJump
,
ESTIMATED_CALL_GATE_SIZE
);
//
// lea r8, [rip+XXX]
// Passes KCG as third argument to be relocatable. macOS 13 Developer Beta 1
// copies the KCG into a separately allocated buffer.
//
CallGateJump
->
LeaRip
.
Command
[
0
]
=
0x4C
;
CallGateJump
->
LeaRip
.
Command
[
1
]
=
0x8D
;
CallGateJump
->
LeaRip
.
Command
[
2
]
=
0x05
;
CallGateJump
->
LeaRip
.
Argument
=
sizeof
(
*
CallGateJump
)
-
sizeof
(
CallGateJump
->
LeaRip
);
CallGateJump
->
Jmp
.
Command
=
0x25FF
;
CallGateJump
->
Jmp
.
Argument
=
0x0
;
CallGateJump
->
Jmp
.
Address
=
HookAddress
;
}
EFI_STATUS
AppleMapPrepareMemState
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
...
...
@@ -758,76 +684,3 @@ AppleMapPrepareMemState (
return
Status
;
}
UINTN
EFIAPI
AppleMapPrepareKernelStateWorker
(
IN
UINTN
*
Args
,
IN
UINTN
EntryPoint
,
IN
KERNEL_CALL_GATE
CallGate
,
IN
UINTN
*
Arg1
,
IN
UINTN
Arg2
)
{
BOOT_COMPAT_CONTEXT
*
BootCompatContext
;
BootCompatContext
=
GetBootCompatContext
();
if
(
BootCompatContext
->
ServiceState
.
AppleHibernateWake
)
{
AppleMapPrepareForHibernateWake
(
BootCompatContext
,
*
Args
);
}
else
{
AppleMapPrepareForBooting
(
BootCompatContext
,
(
VOID
*
)
*
Args
);
}
if
(
BootCompatContext
->
KernelState
.
RelocationBlock
!=
0
)
{
AppleRelocationCallGate
(
Args
,
BootCompatContext
,
CallGate
,
Arg1
,
Arg2
);
}
return
CallGate
(
*
Arg1
,
Arg2
);
}
EFI_STATUS
EFIAPI
AppleMapPrepareKernelStateNew
(
IN
UINTN
SystemTable
,
IN
OUT
APPLE_EFI_BOOT_RT_KCG_ARGS
*
KcgArguments
,
IN
KERNEL_CALL_GATE
CallGate
)
{
return
AppleMapPrepareKernelStateWorker
(
&
KcgArguments
->
Args
,
KcgArguments
->
EntryPoint
,
CallGate
,
&
SystemTable
,
(
UINTN
)
KcgArguments
);
}
UINTN
EFIAPI
AppleMapPrepareKernelStateOld
(
IN
UINTN
Args
,
IN
UINTN
EntryPoint
,
IN
KERNEL_CALL_GATE
CallGate
)
{
return
AppleMapPrepareKernelStateWorker
(
&
Args
,
EntryPoint
,
CallGate
,
&
Args
,
EntryPoint
);
}
Library/OcAfterBootCompatLib/OcAfterBootCompatLib.inf
浏览文件 @
a27fe27f
...
...
@@ -39,6 +39,13 @@
RelocationCallGate.h
ServiceOverrides.c
[Sources.Ia32]
Ia32/KernelSupport32.c
Ia32/KernelTrampoline.nasm
[Sources.X64]
X64/KernelSupport64.c
[Packages]
MdePkg/MdePkg.dec
OpenCorePkg/OpenCorePkg.dec
...
...
Library/OcAfterBootCompatLib/RelocationBlock.c
浏览文件 @
a27fe27f
...
...
@@ -375,7 +375,7 @@ AppleRelocationRebase (
}
VOID
AppleRelocationCallGate
(
AppleRelocationCallGate
64
(
IN
OUT
UINTN
*
Args
,
IN
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
KERNEL_CALL_GATE
CallGate
,
...
...
Library/OcAfterBootCompatLib/ServiceOverrides.c
浏览文件 @
a27fe27f
...
...
@@ -906,6 +906,8 @@ InternalIsEfiBootRt (
return
TRUE
;
}
#ifdef MDE_CPU_X64
/*
Retrieves the offset of the kernel call gate in EfiBootRt.
...
...
@@ -1016,6 +1018,8 @@ InternalEfiBootRtGetKcgOffset (
return
KcgOffset
;
}
#endif
/**
UEFI Boot Services LoadImage override. Called to load an efi image.
If this is bootrt.efi, then we patch its kernel call gate.
...
...
@@ -1032,13 +1036,8 @@ OcLoadImage (
OUT
EFI_HANDLE
*
ImageHandle
)
{
EFI_STATUS
LoadImageStatus
;
EFI_STATUS
Status
;
BOOLEAN
IsEfiBootRt
;
BOOT_COMPAT_CONTEXT
*
BootCompat
;
EFI_LOADED_IMAGE_PROTOCOL
*
LoadedImage
;
UINTN
KcgOffset
;
UINTN
KcgSize
;
BOOLEAN
IsEfiBootRt
;
BOOT_COMPAT_CONTEXT
*
BootCompat
;
BootCompat
=
GetBootCompatContext
();
...
...
@@ -1084,6 +1083,13 @@ OcLoadImage (
);
}
#if defined (MDE_CPU_X64)
EFI_STATUS
LoadImageStatus
;
EFI_STATUS
Status
;
EFI_LOADED_IMAGE_PROTOCOL
*
LoadedImage
;
UINTN
KcgOffset
;
UINTN
KcgSize
;
LoadImageStatus
=
OcImageLoaderLoad
(
BootPolicy
,
ParentImageHandle
,
...
...
@@ -1130,10 +1136,10 @@ OcLoadImage (
//
// Patch the EfiBootRt kernel call gate.
//
AppleMapPrepareKernelJump
(
AppleMapPrepareKernelJump
64
(
BootCompat
,
(
UINTN
)
LoadedImage
->
ImageBase
+
KcgOffset
,
(
UINTN
)
AppleMapPrepareKernelStateNew
(
UINTN
)
AppleMapPrepareKernelStateNew
64
);
DEBUG
((
...
...
@@ -1143,6 +1149,12 @@ OcLoadImage (
));
return
LoadImageStatus
;
#elif defined (MDE_CPU_IA32)
//
// Something is completely borked if we are here in 32-bit mode.
//
return
EFI_INVALID_PARAMETER
;
#endif
}
/**
...
...
@@ -1430,11 +1442,15 @@ OcExitBootServices (
return
Status
;
}
AppleMapPrepareKernelJump
(
#ifdef MDE_CPU_IA32
AppleMapPrepareKernelJump32
(
BootCompat
);
#elif defined (MDE_CPU_X64)
AppleMapPrepareKernelJump64
(
BootCompat
,
(
UINTN
)
BootCompat
->
ServiceState
.
OldKernelCallGate
,
(
UINTN
)
AppleMapPrepareKernelStateOld
(
UINTN
)
AppleMapPrepareKernelStateOld
64
);
#endif
return
Status
;
}
...
...
Library/OcAfterBootCompatLib/X64/KernelSupport64.c
0 → 100644
浏览文件 @
a27fe27f
/** @file
Copyright (C) 2019-2024, 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.
**/
#include "../BootCompatInternal.h"
#include <Guid/OcVariable.h>
#include <IndustryStandard/AppleHibernate.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/OcBootManagementLib.h>
#include <Library/OcDebugLogLib.h>
#include <Library/OcDeviceTreeLib.h>
#include <Library/OcMachoLib.h>
#include <Library/OcMemoryLib.h>
#include <Library/OcMiscLib.h>
#include <Library/OcStringLib.h>
#include <Library/PrintLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
VOID
AppleMapPrepareKernelJump64
(
IN
OUT
BOOT_COMPAT_CONTEXT
*
BootCompat
,
IN
EFI_PHYSICAL_ADDRESS
CallGate
,
IN
UINTN
HookAddress
)
{
CALL_GATE_JUMP
*
CallGateJump
;
//
// There is no reason to patch the kernel when we do not need it.
//
if
(
!
BootCompat
->
Settings
.
AvoidRuntimeDefrag
&&
!
BootCompat
->
Settings
.
DiscardHibernateMap
&&
!
BootCompat
->
Settings
.
AllowRelocationBlock
&&
!
BootCompat
->
Settings
.
DisableSingleUser
&&
!
BootCompat
->
Settings
.
ForceBooterSignature
)
{
return
;
}
//
// Check whether we have address and abort if not.
//
if
(
CallGate
==
0
)
{
RUNTIME_DEBUG
((
DEBUG_ERROR
,
"OCABC: Failed to find call gate address
\n
"
));
return
;
}
CallGateJump
=
(
VOID
*
)(
UINTN
)
CallGate
;
//
// Move call gate jump bytes front.
// Performing this on the EfiBootRt KCG may bork the binary, but right now
// only corrupts an unused string.
//
CopyMem
(
CallGateJump
+
1
,
CallGateJump
,
ESTIMATED_CALL_GATE_SIZE
);
//
// lea r8, [rip+XXX]
// Passes KCG as third argument to be relocatable. macOS 13 Developer Beta 1
// copies the KCG into a separately allocated buffer.
//
CallGateJump
->
LeaRip
.
Command
[
0
]
=
0x4C
;
CallGateJump
->
LeaRip
.
Command
[
1
]
=
0x8D
;
CallGateJump
->
LeaRip
.
Command
[
2
]
=
0x05
;
CallGateJump
->
LeaRip
.
Argument
=
sizeof
(
*
CallGateJump
)
-
sizeof
(
CallGateJump
->
LeaRip
);
CallGateJump
->
Jmp
.
Command
=
0x25FF
;
CallGateJump
->
Jmp
.
Argument
=
0x0
;
CallGateJump
->
Jmp
.
Address
=
HookAddress
;
}
STATIC
UINTN
EFIAPI
AppleMapPrepareKernelStateWorker64
(
IN
UINTN
*
Args
,
IN
UINTN
EntryPoint
,
IN
KERNEL_CALL_GATE
CallGate
,
IN
UINTN
*
Arg1
,
IN
UINTN
Arg2
)
{
BOOT_COMPAT_CONTEXT
*
BootCompatContext
;
BootCompatContext
=
GetBootCompatContext
();
if
(
BootCompatContext
->
ServiceState
.
AppleHibernateWake
)
{
AppleMapPrepareForHibernateWake
(
BootCompatContext
,
*
Args
);
}
else
{
AppleMapPrepareForBooting
(
BootCompatContext
,
(
VOID
*
)
*
Args
);
}
if
(
BootCompatContext
->
KernelState
.
RelocationBlock
!=
0
)
{
//
// Does not return.
//
AppleRelocationCallGate64
(
Args
,
BootCompatContext
,
CallGate
,
Arg1
,
Arg2
);
}
return
CallGate
(
*
Arg1
,
Arg2
);
}
EFI_STATUS
EFIAPI
AppleMapPrepareKernelStateNew64
(
IN
UINTN
SystemTable
,
IN
OUT
APPLE_EFI_BOOT_RT_KCG_ARGS
*
KcgArguments
,
IN
KERNEL_CALL_GATE
CallGate
)
{
return
AppleMapPrepareKernelStateWorker64
(
&
KcgArguments
->
Args
,
KcgArguments
->
EntryPoint
,
CallGate
,
&
SystemTable
,
(
UINTN
)
KcgArguments
);
}
UINTN
EFIAPI
AppleMapPrepareKernelStateOld64
(
IN
UINTN
Args
,
IN
UINTN
EntryPoint
,
IN
KERNEL_CALL_GATE
CallGate
)
{
return
AppleMapPrepareKernelStateWorker64
(
&
Args
,
EntryPoint
,
CallGate
,
&
Args
,
EntryPoint
);
}
User/Makefile
浏览文件 @
a27fe27f
...
...
@@ -80,13 +80,8 @@ endif
ifeq
($(DIST),Darwin)
ifneq
($(FUZZ),1)
ifeq
($(UDK_ARCH),Ia32)
CFLAGS
+=
-mmacosx-version-min
=
10.6
--target
=
i386-apple-darwin
LDFLAGS
+=
-mmacosx-version-min
=
10.6
--target
=
i386-apple-darwin
else
CFLAGS
+=
-mmacosx-version-min
=
10.6
--target
=
x86_64-apple-darwin
LDFLAGS
+=
-mmacosx-version-min
=
10.6
--target
=
x86_64-apple-darwin
endif
CFLAGS
+=
-mmacosx-version-min
=
10.9
-arch
x86_64
-arch
arm64
LDFLAGS
+=
-mmacosx-version-min
=
10.9
-arch
x86_64
-arch
arm64
endif
endif
...
...
Utilities/BaseTools/Makefile
浏览文件 @
a27fe27f
...
...
@@ -5,7 +5,7 @@ RM ?= /bin/rm
DIST
?=
$(
shell
uname
)
ifeq
($(DIST),Darwin)
CFLAGS
+=
-mmacosx-version-min
=
10.6
CFLAGS
+=
-arch
x86_64
-arch
arm64
-mmacosx-version-min
=
10.9
endif
BINDIR
=
bin.
$(DIST)
...
...
Utilities/RsaTool/Makefile
浏览文件 @
a27fe27f
...
...
@@ -16,6 +16,14 @@ libressl/lib/libcrypto.a:
$(OUT_DIR)/$(PROJECT).o
:
libressl/lib/libcrypto.a
endif
CFLAGS
+=
-Ilibressl
/include
-I
/usr/local/opt/openssl/include
-I
/opt/local/include
-Wno-deprecated-declarations
LDFLAGS
+=
-Llibressl
/lib
-L
/usr/local/opt/openssl/lib
-L
/opt/local/lib
ifeq
($(DIST),Darwin)
ifeq
($(shell uname -p),arm)
OPENSSL_PATH
=
/opt/homebrew/opt/openssl
else
OPENSSL_PATH
=
/usr/local/opt/openssl
endif
endif
CFLAGS
+=
-Ilibressl
/include
-I
$(OPENSSL_PATH)
/include
-I
/opt/local/include
-Wno-deprecated-declarations
LDFLAGS
+=
-Llibressl
/lib
-L
$(OPENSSL_PATH)
/lib
-L
/opt/local/lib
LDLIBS
+=
-lcrypto
Utilities/RsaTool/build_libressl.sh
浏览文件 @
a27fe27f
...
...
@@ -11,8 +11,8 @@ cd "$SRC_DIR" || exit 1
OUTPUT_PATH
=
"
$(
pwd
)
/libressl"
BUILD_DIR
=
"
$(
pwd
)
/tmp/
${
LIBRESSL_NAME
}
/build"
export
CFLAGS
=
"-
mmacosx-version-min=10.6
-Wno-unguarded-availability-new"
export
LDFLAGS
=
"-
mmacosx-version-min=10.6
"
export
CFLAGS
=
"-
arch x86_64 -arch arm64 -mmacosx-version-min=10.9
-Wno-unguarded-availability-new"
export
LDFLAGS
=
"-
arch x86_64 -arch arm64 -mmacosx-version-min=10.9
"
abort
()
{
echo
"ERROR:
$1
!"
...
...
@@ -69,14 +69,7 @@ echo "Downloading LibreSSL ${LIBRESSL_VERSION}..."
cd
"
${
LIBRESSL_NAME
}
"
||
abort
"Failed to cd to
${
LIBRESSL_NAME
}
with code
$?
"
if
[
"
$(
${
ARCH
}
)
"
=
"arm64"
]
;
then
# If we are building on arm64 (Apple Silicon), these extra options are required to ensure x86_64 builds.
EXTRA_OPTS
=(
--host
=
arm-apple-darwin
--build
=
x86_64-apple-darwin
)
CFLAGS+
=
" --target=x86_64-apple-darwin"
LDFLAGS+
=
" --target=x86_64-apple-darwin"
else
EXTRA_OPTS
=()
fi
EXTRA_OPTS
=()
# Monkeypatch to disable strtonum for <11.0 support
"
${
SED
}
"
-i
''
-E
's/strsep strtonum/strsep/g'
configure
||
abort
"Failed to monkeypatch strtonum in LibreSSL with code
$?
"
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录