diff --git a/src/arch/aarch64.rs b/src/arch/aarch64.rs index c8f2b8b..e08d0fc 100644 --- a/src/arch/aarch64.rs +++ b/src/arch/aarch64.rs @@ -10,7 +10,6 @@ use core::arch::asm; use linux_raw_sys::elf::Elf_Ehdr; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] -#[cfg(test)] use linux_raw_sys::general::__NR_rt_sigreturn; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] @@ -275,14 +274,13 @@ pub(super) const TLS_OFFSET: usize = 0; #[cfg(feature = "thread")] #[inline] pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! { - assert_eq!(__NR_exit, 93); // TODO: obviate this asm!( "svc 0", "mov x0, xzr", - "mov x8, 93", // TODO: use {__NR_exit} + "mov x8, {__NR_exit}", "svc 0", "udf #16", - //__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized. + __NR_exit = const __NR_exit, in("x8") __NR_munmap, in("x0") map_addr, in("x1") map_len, @@ -304,16 +302,11 @@ naked_fn!( "; pub(super) fn return_from_signal_handler() -> (); - "mov x8, 139", // TODO: use {__NR_rt_sigreturn} + "mov x8, {__NR_rt_sigreturn}", "svc 0", "udf #16"; - //__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_rt_sigreturn = const __NR_rt_sigreturn ); -#[cfg(feature = "take-charge")] -#[test] // TODO: obviate this -fn test_rt_sigreturn() { - assert_eq!(__NR_rt_sigreturn, 139); -} /// Invoke the appropriate system call to return control from a signal /// handler that does not use `SA_SIGINFO`. On aarch64, this uses the same diff --git a/src/arch/arm.rs b/src/arch/arm.rs index 381b4cb..231c899 100644 --- a/src/arch/arm.rs +++ b/src/arch/arm.rs @@ -13,7 +13,6 @@ use linux_raw_sys::elf::Elf_Ehdr; use linux_raw_sys::general::{__NR_mprotect, PROT_READ}; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] -#[cfg(test)] use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn}; #[cfg(feature = "take-charge")] #[cfg(feature = "thread")] @@ -289,14 +288,13 @@ pub(super) const TLS_OFFSET: usize = 0; #[cfg(feature = "thread")] #[inline] pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! { - assert_eq!(__NR_exit, 1); // TODO: obviate this asm!( "svc 0", "mov r0, #0", - "mov r7, #1", // TODO: use {__NR_exit} + "mov r7, {__NR_exit}", "svc 0", "udf #16", - //__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized. + __NR_exit = const __NR_exit, in("r7") __NR_munmap, in("r0") map_addr, in("r1") map_len, @@ -318,16 +316,11 @@ naked_fn!( "; pub(super) fn return_from_signal_handler() -> (); - "mov r7, 173", // TODO: use {__NR_rt_sigreturn} + "mov r7, {__NR_rt_sigreturn}", "swi 0", "udf #16"; - //__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_rt_sigreturn = const __NR_rt_sigreturn ); -#[cfg(feature = "take-charge")] -#[test] // TODO: obviate this -fn test_rt_sigreturn() { - assert_eq!(__NR_rt_sigreturn, 173); -} #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] @@ -343,13 +336,8 @@ naked_fn!( "; pub(super) fn return_from_signal_handler_noinfo() -> (); - "mov r7, 119", // TODO: use {__NR_sigreturn} + "mov r7, {__NR_sigreturn}", "swi 0", "udf #16"; - //__NR_sigreturn = const __NR_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_sigreturn = const __NR_sigreturn ); -#[cfg(feature = "take-charge")] -#[test] // TODO: obviate this -fn test_sigreturn() { - assert_eq!(__NR_sigreturn, 119); -} diff --git a/src/arch/riscv64.rs b/src/arch/riscv64.rs index 9861042..5e53b36 100644 --- a/src/arch/riscv64.rs +++ b/src/arch/riscv64.rs @@ -293,14 +293,13 @@ pub(super) const TLS_OFFSET: usize = 0x800; #[cfg(feature = "thread")] #[inline] pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! { - assert_eq!(__NR_exit, 93); // TODO: obviate this asm!( "ecall", "mv a0, zero", - "li a7, 93", // TODO: use {__NR_exit} + "li a7, {__NR_exit}", "ecall", "unimp", - //__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized. + __NR_exit = const __NR_exit, in("a7") __NR_munmap, in("a0") map_addr, in("a1") map_len, diff --git a/src/arch/x86.rs b/src/arch/x86.rs index ca87456..ba96e6f 100644 --- a/src/arch/x86.rs +++ b/src/arch/x86.rs @@ -16,7 +16,6 @@ use linux_raw_sys::elf::Elf_Ehdr; use linux_raw_sys::general::{__NR_mprotect, PROT_READ}; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] -#[cfg(test)] use linux_raw_sys::general::{__NR_rt_sigreturn, __NR_sigreturn}; #[cfg(feature = "take-charge")] #[cfg(feature = "thread")] @@ -371,16 +370,15 @@ pub(super) const TLS_OFFSET: usize = 0; #[cfg(feature = "thread")] #[inline] pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! { - assert_eq!(__NR_exit, 1); // TODO: obviate this asm!( // Use `int 0x80` instead of vsyscall, since vsyscall would attempt to // touch the stack after we `munmap` it. "int 0x80", "xor ebx, ebx", - "mov eax, 1", // TODO: use {__NR_exit} + "mov eax, {__NR_exit}", "int 0x80", "ud2", - //__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized. + __NR_exit = const __NR_exit, in("eax") __NR_munmap, in("ebx") map_addr, in("ecx") map_len, @@ -402,17 +400,11 @@ naked_fn!( "; pub(super) fn return_from_signal_handler() -> (); - "mov eax, 173", // TODO: use {__NR_rt_sigreturn} + "mov eax, {__NR_rt_sigreturn}", "int 0x80", "ud2"; - //__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_rt_sigreturn = const __NR_rt_sigreturn ); -#[cfg(feature = "take-charge")] -#[cfg(feature = "signal")] -#[test] // TODO: obviate this -fn test_rt_sigreturn() { - assert_eq!(__NR_rt_sigreturn, 173); -} #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] @@ -429,14 +421,8 @@ naked_fn!( pub(super) fn return_from_signal_handler_noinfo() -> (); "pop eax", - "mov eax, 119", // TODO: use {__NR_sigreturn} + "mov eax, {__NR_sigreturn}", "int 0x80", "ud2"; - //__NR_sigreturn = const __NR_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_sigreturn = const __NR_sigreturn ); -#[cfg(feature = "take-charge")] -#[cfg(feature = "signal")] -#[test] // TODO: obviate this -fn test_sigreturn() { - assert_eq!(__NR_sigreturn, 119); -} diff --git a/src/arch/x86_64.rs b/src/arch/x86_64.rs index 9845450..8a6edca 100644 --- a/src/arch/x86_64.rs +++ b/src/arch/x86_64.rs @@ -10,7 +10,6 @@ use core::arch::asm; use linux_raw_sys::elf::Elf_Ehdr; #[cfg(feature = "take-charge")] #[cfg(feature = "signal")] -#[cfg(test)] use linux_raw_sys::general::__NR_rt_sigreturn; #[cfg(all(feature = "experimental-relocate", feature = "origin-start"))] #[cfg(relocation_model = "pic")] @@ -283,14 +282,13 @@ pub(super) const TLS_OFFSET: usize = 0; #[cfg(feature = "thread")] #[inline] pub(super) unsafe fn munmap_and_exit_thread(map_addr: *mut c_void, map_len: usize) -> ! { - assert_eq!(__NR_exit, 60); // TODO: obviate this asm!( "syscall", "xor edi, edi", - "mov eax, 60", // TODO: use {__NR_exit} + "mov eax, {__NR_exit}", "syscall", "ud2", - //__NR_exit = const __NR_exit, // TODO: Use this when `asm_const` is stabilized. + __NR_exit = const __NR_exit, in("rax") __NR_munmap, in("rdi") map_addr, in("rsi") map_len, @@ -312,16 +310,11 @@ naked_fn!( "; pub(super) fn return_from_signal_handler() -> (); - "mov rax, 15", // TODO: use {__NR_rt_sigreturn} + "mov rax, {__NR_rt_sigreturn}", "syscall", "ud2"; - //__NR_rt_sigreturn = const __NR_rt_sigreturn // TODO: Use this when `asm_const` is stabilized. + __NR_rt_sigreturn = const __NR_rt_sigreturn ); -#[cfg(feature = "take-charge")] -#[test] // TODO: obviate this -fn test_rt_sigreturn() { - assert_eq!(__NR_rt_sigreturn, 15); -} /// Invoke the appropriate system call to return control from a signal /// handler that does not use `SA_SIGINFO`. On x86-64, this uses the same diff --git a/tests/abi.rs b/tests/abi.rs deleted file mode 100644 index 66dd9a5..0000000 --- a/tests/abi.rs +++ /dev/null @@ -1,45 +0,0 @@ -//! Test that workarounds for missing `asm_const` have the right values.. -//! -//! Due to `asm_const` not being stable yet, src/arch/* currently have to -//! hard-code these ABI magic numbers. Test that the hard-coded numbers -//! match the upstream numbers. -//! -//! Keep these in sync with the code in src/arch/*. -//! -//! TODO: When `asm_const` is stable, obviate these tests. - -#[cfg(target_arch = "x86")] -#[test] -fn test_rt_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_rt_sigreturn, 173); -} - -#[cfg(target_arch = "x86")] -#[test] -fn test_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_sigreturn, 119); -} - -#[cfg(target_arch = "aarch64")] -#[test] -fn test_rt_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_rt_sigreturn, 139); -} - -#[cfg(target_arch = "arm")] -#[test] -fn test_rt_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_rt_sigreturn, 173); -} - -#[cfg(target_arch = "arm")] -#[test] -fn test_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_sigreturn, 119); -} - -#[cfg(target_arch = "x86_64")] -#[test] -fn test_rt_sigreturn() { - assert_eq!(linux_raw_sys::general::__NR_rt_sigreturn, 15); -}