Skip to content

Commit

Permalink
Add ugly workaround for rust-lang/rust#128177
Browse files Browse the repository at this point in the history
  • Loading branch information
Evian-Zhang committed Jul 26, 2024
1 parent 5a31d86 commit 3a3ff53
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ impl JumpEntry {
}

/// Create a dummy jump entry
#[allow(unused)]
const fn dummy() -> Self {
Self {
code: 0,
Expand Down Expand Up @@ -335,6 +336,8 @@ unsafe fn jump_entry_update<M: CodeManipulator>(jump_entry: &JumpEntry, enabled:
#[macro_export]
macro_rules! static_key_init_jmp_with_given_branch_likely {
($key:path, $branch:expr) => {'my_label: {
// This is an ugly workaround for https://github.com/rust-lang/rust/issues/128177
#[cfg(not(all(target_os = "windows", any(target_arch = "x86", target_arch = "x86_64"))))]
::core::arch::asm!(
$crate::arch_static_key_init_jmp_asm_template!(),
label {
Expand All @@ -343,6 +346,16 @@ macro_rules! static_key_init_jmp_with_given_branch_likely {
sym $key,
const $branch as usize,
);
#[cfg(all(target_os = "windows", any(target_arch = "x86", target_arch = "x86_64")))]
::core::arch::asm!(
$crate::arch_static_key_init_jmp_asm_template!(),
label {
break 'my_label !$branch;
},
sym $key,
const $branch as usize,
options(att_syntax),
);

// This branch will be adjcent to the NOP/JMP instruction
break 'my_label $branch;
Expand All @@ -354,13 +367,25 @@ macro_rules! static_key_init_jmp_with_given_branch_likely {
#[macro_export]
macro_rules! static_key_init_nop_with_given_branch_likely {
($key:path, $branch:expr) => {'my_label: {
// This is an ugly workaround for https://github.com/rust-lang/rust/issues/128177
#[cfg(not(all(target_os = "windows", any(target_arch = "x86", target_arch = "x86_64"))))]
::core::arch::asm!(
$crate::arch_static_key_init_nop_asm_template!(),
label {
break 'my_label !$branch;
},
sym $key,
const $branch as usize,
);
#[cfg(all(target_os = "windows", any(target_arch = "x86", target_arch = "x86_64")))]
::core::arch::asm!(
$crate::arch_static_key_init_nop_asm_template!(),
label {
break 'my_label !$branch;
},
sym $key,
const $branch as usize,
options(att_syntax),
);

// This branch will be adjcent to the NOP/JMP instruction
Expand Down

0 comments on commit 3a3ff53

Please sign in to comment.