From 3a3ff5345dd22dc06550061b42a40051551443b2 Mon Sep 17 00:00:00 2001 From: Evian-Zhang Date: Fri, 26 Jul 2024 12:41:54 +0800 Subject: [PATCH] Add ugly workaround for rust-lang/rust#128177 --- src/lib.rs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0ea393b..95bb79c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -68,6 +68,7 @@ impl JumpEntry { } /// Create a dummy jump entry + #[allow(unused)] const fn dummy() -> Self { Self { code: 0, @@ -335,6 +336,8 @@ unsafe fn jump_entry_update(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 { @@ -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; @@ -354,6 +367,17 @@ 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 { @@ -361,6 +385,7 @@ macro_rules! static_key_init_nop_with_given_branch_likely { }, sym $key, const $branch as usize, + options(att_syntax), ); // This branch will be adjcent to the NOP/JMP instruction