-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Add i686 target; Fix dummy jump entry eliminated by linker
1 parent
1c3d9ab
commit 5f1127d
Showing
5 changed files
with
214 additions
and
89 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
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,11 @@ | ||
//! Arch-specific implementations | ||
#[cfg(target_arch = "x86_64")] | ||
mod x86_64; | ||
#[cfg(target_arch = "x86_64")] | ||
pub use x86_64::*; | ||
|
||
#[cfg(target_arch = "x86")] | ||
mod x86; | ||
#[cfg(target_arch = "x86")] | ||
pub use x86::*; |
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,81 @@ | ||
//! x86 arch-sepcific implementations | ||
use crate::{JumpEntry, JumpLabelType}; | ||
|
||
/// Length of jump instruction to be replaced | ||
pub const ARCH_JUMP_INS_LENGTH: usize = 5; | ||
|
||
/// 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 => { | ||
let relative_addr = | ||
(jump_entry.target_addr() - (jump_entry.code_addr() + ARCH_JUMP_INS_LENGTH)) as u32; | ||
let [a, b, c, d] = relative_addr.to_ne_bytes(); | ||
[0xe9, a, b, c, d] | ||
} | ||
JumpLabelType::Nop => [0x3e, 0x8d, 0x74, 0x26, 0x00], | ||
} | ||
} | ||
|
||
/// With given branch as likely branch, initialize the instruction here as a 5-byte NOP instruction | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_nop_with_given_branch_likely { | ||
($key:path, $branch:expr) => {'my_label: { | ||
::core::arch::asm!( | ||
r#" | ||
2: | ||
.byte 0x3e,0x8d,0x74,0x26,0x00 | ||
.pushsection __static_keys, "awR" | ||
.balign 4 | ||
.long 2b - . | ||
.long {0} - . | ||
.long {1} + {2} - . | ||
.popsection | ||
"#, | ||
label { | ||
break 'my_label !$branch; | ||
}, | ||
sym $key, | ||
const $branch as usize, | ||
); | ||
|
||
// This branch will be adjcent to the NOP/JMP instruction | ||
break 'my_label $branch; | ||
}}; | ||
} | ||
|
||
// The `0x8d,0x76,0x00` is a 3-byte NOP, which is to make sure the `jmp {0}` is at least 5 bytes long. | ||
/// With given branch as likely branch, initialize the instruction here as JMP instruction | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_jmp_with_given_branch_likely { | ||
($key:path, $branch:expr) => {'my_label: { | ||
::core::arch::asm!( | ||
r#" | ||
2: | ||
jmp {0} | ||
.byte 0x8d,0x76,0x00 | ||
.pushsection __static_keys, "awR" | ||
.balign 4 | ||
.long 2b - . | ||
.long {0} - . | ||
.long {1} + {2} - . | ||
.popsection | ||
"#, | ||
label { | ||
break 'my_label !$branch; | ||
}, | ||
sym $key, | ||
const $branch as usize, | ||
); | ||
|
||
// This branch will be adjcent to the NOP/JMP instruction | ||
break 'my_label $branch; | ||
}}; | ||
} |
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,81 @@ | ||
//! x86_64 arch-sepcific implementations | ||
use crate::{JumpEntry, JumpLabelType}; | ||
|
||
/// Length of jump instruction to be replaced | ||
pub const ARCH_JUMP_INS_LENGTH: usize = 5; | ||
|
||
/// 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 => { | ||
let relative_addr = | ||
(jump_entry.target_addr() - (jump_entry.code_addr() + ARCH_JUMP_INS_LENGTH)) as u32; | ||
let [a, b, c, d] = relative_addr.to_ne_bytes(); | ||
[0xe9, a, b, c, d] | ||
} | ||
JumpLabelType::Nop => [0x0f, 0x1f, 0x44, 0x00, 0x00], | ||
} | ||
} | ||
|
||
/// With given branch as likely branch, initialize the instruction here as a 5-byte NOP instruction | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_nop_with_given_branch_likely { | ||
($key:path, $branch:expr) => {'my_label: { | ||
::core::arch::asm!( | ||
r#" | ||
2: | ||
.byte 0x0f,0x1f,0x44,0x00,0x00 | ||
.pushsection __static_keys, "awR" | ||
.balign 8 | ||
.quad 2b - . | ||
.quad {0} - . | ||
.quad {1} + {2} - . | ||
.popsection | ||
"#, | ||
label { | ||
break 'my_label !$branch; | ||
}, | ||
sym $key, | ||
const $branch as usize, | ||
); | ||
|
||
// This branch will be adjcent to the NOP/JMP instruction | ||
break 'my_label $branch; | ||
}}; | ||
} | ||
|
||
// The `0x0f,0x1f,0x00` is a 3-byte NOP, which is to make sure the `jmp {0}` is at least 5 bytes long. | ||
/// With given branch as likely branch, initialize the instruction here as JMP instruction | ||
#[doc(hidden)] | ||
#[macro_export] | ||
macro_rules! arch_static_key_init_jmp_with_given_branch_likely { | ||
($key:path, $branch:expr) => {'my_label: { | ||
::core::arch::asm!( | ||
r#" | ||
2: | ||
jmp {0} | ||
.byte 0x0f,0x1f,0x00 | ||
.pushsection __static_keys, "awR" | ||
.balign 8 | ||
.quad 2b - . | ||
.quad {0} - . | ||
.quad {1} + {2} - . | ||
.popsection | ||
"#, | ||
label { | ||
break 'my_label !$branch; | ||
}, | ||
sym $key, | ||
const $branch as usize, | ||
); | ||
|
||
// This branch will be adjcent to the NOP/JMP instruction | ||
break 'my_label $branch; | ||
}}; | ||
} |
Oops, something went wrong.