diff --git a/src/header/signal/sigsetjmp/aarch64/sigsetjmp.s b/src/header/setjmp/impl/aarch64/sigsetjmp.s similarity index 100% rename from src/header/signal/sigsetjmp/aarch64/sigsetjmp.s rename to src/header/setjmp/impl/aarch64/sigsetjmp.s diff --git a/src/header/setjmp/impl/i386/sigsetjmp.s b/src/header/setjmp/impl/i386/sigsetjmp.s new file mode 100644 index 0000000000..0ef1e1b4ec --- /dev/null +++ b/src/header/setjmp/impl/i386/sigsetjmp.s @@ -0,0 +1,26 @@ +.global sigsetjmp +.global __sigsetjmp +.type sigsetjmp,@function +.type __sigsetjmp,@function +sigsetjmp: +__sigsetjmp: + mov ecx, dword ptr [esp + 8] + jecxz 1f + + mov eax, dword ptr [esp + 4] + pop [eax + 24] + mov dword ptr [eax * 8 + 28], ebx + mov ebx, eax + +.hidden ___setjmp + call ___setjmp + + push [ebx + 24] + mov dword ptr [esp + 4], ebx + mov dword ptr [esp + 4], eax + mov ebx, dword ptr [ebx * 8 + 28] + +.hidden __sigsetjmp_tail + jmp __sigsetjmp_tail + +1: jmp ___setjmp diff --git a/src/header/signal/sigsetjmp/riscv64/sigsetjmp.s b/src/header/setjmp/impl/riscv64/sigsetjmp.S similarity index 100% rename from src/header/signal/sigsetjmp/riscv64/sigsetjmp.s rename to src/header/setjmp/impl/riscv64/sigsetjmp.S diff --git a/src/header/signal/sigsetjmp/x86_64/sigsetjmp.s b/src/header/setjmp/impl/x86_64/sigsetjmp.s similarity index 55% rename from src/header/signal/sigsetjmp/x86_64/sigsetjmp.s rename to src/header/setjmp/impl/x86_64/sigsetjmp.s index d354d6802a..ab19b2b2d9 100644 --- a/src/header/signal/sigsetjmp/x86_64/sigsetjmp.s +++ b/src/header/setjmp/impl/x86_64/sigsetjmp.s @@ -4,19 +4,19 @@ .type __sigsetjmp,@function sigsetjmp: __sigsetjmp: - test %esi,%esi + test esi, esi jz 1f - popq 64(%rdi) - mov %rbx,72+8(%rdi) - mov %rdi,%rbx + pop [rdi + 64] + mov qword ptr [rdi * 8 + 72], rbx + mov rbx, rdi call setjmp - pushq 64(%rbx) - mov %rbx,%rdi - mov %eax,%esi - mov 72+8(%rbx),%rbx + push [rbx + 64] + mov rdi, rbx + mov esi, eax + mov rbx, qword ptr [rbx * 8 + 72] .hidden __sigsetjmp_tail jmp __sigsetjmp_tail diff --git a/src/header/setjmp/mod.rs b/src/header/setjmp/mod.rs index e7a70cd527..3ec61d2b0b 100644 --- a/src/header/setjmp/mod.rs +++ b/src/header/setjmp/mod.rs @@ -4,18 +4,14 @@ use core::arch::global_asm; -#[cfg(target_arch = "aarch64")] -use core::ffi::c_int; - -#[cfg(target_arch = "aarch64")] -use crate::header::signal::sigsetjmp; - macro_rules! platform_specific { ($($rust_arch:expr,$c_arch:expr,$ext:expr;)+) => { $( #[cfg(target_arch = $rust_arch)] global_asm!(include_str!(concat!("impl/", $c_arch, "/setjmp.", $ext))); #[cfg(target_arch = $rust_arch)] + global_asm!(include_str!(concat!("impl/", $c_arch, "/sigsetjmp.", $ext))); + #[cfg(target_arch = $rust_arch)] global_asm!(include_str!(concat!("impl/", $c_arch, "/longjmp.", $ext))); )+ } @@ -35,15 +31,3 @@ unsafe extern "C" { /// See . pub fn longjmp(jb: *mut u64, ret: i32); } - -#[cfg(target_arch = "aarch64")] -#[unsafe(no_mangle)] -pub unsafe extern "C" fn __relibc_unused_but_exist_to_avoid_linker_error_on_setjmp(arg: c_int) { - // Workaround to https://www.openwall.com/lists/musl/2023/09/07/2 - // By keeping setjmp close to sigsetjmp in link time - let jb: *mut u64 = core::ptr::null_mut(); - unsafe { - setjmp(jb); - sigsetjmp(jb, arg); - } -} diff --git a/src/header/signal/mod.rs b/src/header/signal/mod.rs index 79aff1952f..29f4529b14 100644 --- a/src/header/signal/mod.rs +++ b/src/header/signal/mod.rs @@ -2,7 +2,7 @@ //! //! See . -use core::{arch::global_asm, mem, ptr}; +use core::{mem, ptr}; use cbitset::BitSet; @@ -111,24 +111,6 @@ pub type siginfo_t = siginfo; /// See pub type stack_t = sigaltstack; -#[cfg(target_arch = "aarch64")] -global_asm!(include_str!("sigsetjmp/aarch64/sigsetjmp.s")); - -#[cfg(target_arch = "riscv64")] -global_asm!(include_str!("sigsetjmp/riscv64/sigsetjmp.s")); - -#[cfg(target_arch = "x86")] -global_asm!( - include_str!("sigsetjmp/i386/sigsetjmp.s"), - options(att_syntax) -); - -#[cfg(target_arch = "x86_64")] -global_asm!( - include_str!("sigsetjmp/x86_64/sigsetjmp.s"), - options(att_syntax) -); - unsafe extern "C" { pub fn sigsetjmp(jb: *mut u64, savemask: i32) -> i32; } diff --git a/src/header/signal/sigsetjmp/README.md b/src/header/signal/sigsetjmp/README.md deleted file mode 100644 index b41a4e552c..0000000000 --- a/src/header/signal/sigsetjmp/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# implementation of sigsetjmp - -All code found in the subdirectories of this directory belong to [musl libc](https://musl.libc.org/). They own it. All rights go to them. -Currently only x86_64 is supported, because I don't have access to non-x86 devices to test it properly. -Converted to Intel assembly syntax, according to setjmp and longjmp found in setjmp header. diff --git a/src/header/signal/sigsetjmp/i386/sigsetjmp.s b/src/header/signal/sigsetjmp/i386/sigsetjmp.s deleted file mode 100644 index 690b251c4c..0000000000 --- a/src/header/signal/sigsetjmp/i386/sigsetjmp.s +++ /dev/null @@ -1,26 +0,0 @@ -.global sigsetjmp -.global __sigsetjmp -.type sigsetjmp,@function -.type __sigsetjmp,@function -sigsetjmp: -__sigsetjmp: - mov 8(%esp),%ecx - jecxz 1f - - mov 4(%esp),%eax - popl 24(%eax) - mov %ebx,28+8(%eax) - mov %eax,%ebx - -.hidden ___setjmp - call ___setjmp - - pushl 24(%ebx) - mov %ebx,4(%esp) - mov %eax,8(%esp) - mov 28+8(%ebx),%ebx - -.hidden __sigsetjmp_tail - jmp __sigsetjmp_tail - -1: jmp ___setjmp