Skip to content

Commit

Permalink
Force 5-byte JMP in x86 and x86-64
Browse files Browse the repository at this point in the history
  • Loading branch information
Evian-Zhang committed Aug 9, 2024
1 parent 11068d6 commit 5b06d7f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/arch/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@ macro_rules! arch_static_key_init_nop_asm_template {
};
}

// The `0x90,0x90,0x90` are three NOPs, which is to make sure the `jmp {0}` is at least 5 bytes long.
// Here we do not use `jmp {0}` because it may be compiled into a 3-byte jmp instead of 5 byte.
// See https://stackoverflow.com/q/74771372/10005095
#[doc(hidden)]
#[macro_export]
macro_rules! arch_static_key_init_jmp_asm_template {
() => {
::core::concat!(
r#"
2:
jmp {0}
.byte 0x90,0x90,0x90
.byte 0xe9
.long ({0} - 4) - .
.pushsection "#,
$crate::os_static_key_sec_name_attr!(),
r#"
Expand Down
3 changes: 2 additions & 1 deletion src/arch/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ macro_rules! arch_static_key_init_nop_asm_template {
};
}

// The `0x90,0x90,0x90` are three NOPs, which is to make sure the `jmp {0}` is at least 5 bytes long.
// Here we do not use `jmp {0}` because it may be compiled into a 3-byte jmp instead of 5 byte.
// See https://stackoverflow.com/q/74771372/10005095
#[doc(hidden)]
#[macro_export]
macro_rules! arch_static_key_init_jmp_asm_template {
Expand Down

0 comments on commit 5b06d7f

Please sign in to comment.