-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9de0815
commit 6b31886
Showing
7 changed files
with
113 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
//! AArch64 arch-sepcific implementations | ||
use crate::{JumpEntry, JumpLabelType}; | ||
|
||
/// Length of jump instruction to be replaced | ||
pub const ARCH_JUMP_INS_LENGTH: usize = 4; | ||
|
||
/// New instruction generated according to jump label type and jump entry | ||
#[inline(always)] | ||
pub fn arch_jump_entry_instruction( | ||
jump_label_type: JumpLabelType, | ||
jump_entry: &JumpEntry, | ||
) -> [u8; ARCH_JUMP_INS_LENGTH] { | ||
match jump_label_type { | ||
JumpLabelType::Jmp => { | ||
// Note that aarch64 only supports relative address within +/-128MB. | ||
// In current implementation, this assumption is always hold. | ||
let relative_addr = | ||
(jump_entry.target_addr() - (jump_entry.code_addr() + ARCH_JUMP_INS_LENGTH)) as u32; | ||
let [a, b, c, d] = (relative_addr / 4).to_ne_bytes(); | ||
[a, b, c, d | 0b00010100] | ||
} | ||
JumpLabelType::Nop => [0x1f, 0x20, 0x03, 0xd5], | ||
} | ||
} | ||
|
||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_nop_asm_template { | ||
() => { | ||
::core::concat!( | ||
r#" | ||
2: | ||
nop | ||
.pushsection "#, | ||
$crate::os_static_key_sec_name_attr!(), | ||
r#" | ||
.balign 8 | ||
.quad 2b - . | ||
.quad {0} - . | ||
.quad {1} + {2} - . | ||
.popsection | ||
"# | ||
) | ||
}; | ||
} | ||
|
||
// The `0x90,0x90,0x90` are three NOPs, which is to make sure the `jmp {0}` is at least 5 bytes long. | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_jmp_asm_template { | ||
() => { | ||
::core::concat!( | ||
r#" | ||
2: | ||
b {0} | ||
.pushsection "#, | ||
$crate::os_static_key_sec_name_attr!(), | ||
r#" | ||
.balign 8 | ||
.quad 2b - . | ||
.quad {0} - . | ||
.quad {1} + {2} - . | ||
.popsection | ||
"# | ||
) | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
//! macOS-specific implementations | ||
use crate::JumpEntry; | ||
|
||
// See https://developer.apple.com/library/archive/documentation/DeveloperTools/Reference/Assembler/040-Assembler_Directives/asm_directives.html#//apple_ref/doc/uid/TP30000823-CJBIFBJG | ||
/// Name and attribute of section storing jump entries | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! os_static_key_sec_name_attr { | ||
() => { | ||
"__DATA,__static_keys,regular,no_dead_strip" | ||
}; | ||
} | ||
|
||
// See https://stackoverflow.com/q/17669593/10005095 and https://github.com/apple-opensource-mirror/ld64/blob/master/unit-tests/test-cases/section-labels/main.c | ||
extern "Rust" { | ||
/// Address of this static is the start address of __static_keys section | ||
#[link_name = "\x01section$start$__DATA$__static_keys"] | ||
pub static mut JUMP_ENTRY_START: JumpEntry; | ||
/// Address of this static is the end address of __static_keys section (excluded) | ||
#[link_name = "\x01section$end$__DATA$__static_keys"] | ||
pub static mut JUMP_ENTRY_STOP: JumpEntry; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters