From 18b5c73b618f43680b9ca6b366525cdbd86da946 Mon Sep 17 00:00:00 2001 From: 4lDO2 <4lDO2@protonmail.com> Date: Mon, 24 Jun 2024 12:29:44 +0200 Subject: [PATCH] Compile on the other arches. --- redox-rt/src/arch/aarch64.rs | 46 ++++++++++++++++----------- redox-rt/src/arch/{x86.rs => i686.rs} | 19 ++++++++--- redox-rt/src/arch/mod.rs | 4 +-- redox-rt/src/lib.rs | 4 +-- redox-rt/src/signal.rs | 4 +-- src/platform/redox/signal.rs | 2 +- 6 files changed, 48 insertions(+), 31 deletions(-) rename redox-rt/src/arch/{x86.rs => i686.rs} (86%) diff --git a/redox-rt/src/arch/aarch64.rs b/redox-rt/src/arch/aarch64.rs index 26d62a50..be9afcc0 100644 --- a/redox-rt/src/arch/aarch64.rs +++ b/redox-rt/src/arch/aarch64.rs @@ -1,11 +1,21 @@ use syscall::error::*; -use crate::{fork_inner, FdGuard}; +use crate::proc::{fork_inner, FdGuard}; +use crate::signal::inner_c; // Setup a stack starting from the very end of the address space, and then growing downwards. pub(crate) const STACK_TOP: usize = 1 << 47; pub(crate) const STACK_SIZE: usize = 1024 * 1024; +#[derive(Debug, Default)] +pub struct SigArea { + pub altstack_top: usize, + pub altstack_bottom: usize, + pub tmp: usize, + pub onstack: u64, + pub disable_signals_depth: u64, +} + /// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS /// is already initialized as if it was a thread. pub unsafe fn deactivate_tcb(open_via_dup: usize) -> Result<()> { @@ -33,18 +43,16 @@ pub fn copy_env_regs(cur_pid_fd: usize, new_pid_fd: usize) -> Result<()> { Ok(()) } -#[no_mangle] -unsafe extern "C" fn __relibc_internal_fork_impl(initial_rsp: *mut usize) -> usize { +unsafe extern "C" fn fork_impl(initial_rsp: *mut usize) -> usize { Error::mux(fork_inner(initial_rsp)) } -#[no_mangle] -unsafe extern "C" fn __relibc_internal_fork_hook(cur_filetable_fd: usize, new_pid_fd: usize) { +unsafe extern "C" fn child_hook(cur_filetable_fd: usize, new_pid_fd: usize) { let _ = syscall::close(cur_filetable_fd); let _ = syscall::close(new_pid_fd); } -asmfunction!(__relibc_internal_fork_wrapper: [" +asmfunction!(__relibc_internal_fork_wrapper -> usize: [" stp x29, x30, [sp, #-16]! stp x27, x28, [sp, #-16]! stp x25, x26, [sp, #-16]! @@ -57,20 +65,20 @@ asmfunction!(__relibc_internal_fork_wrapper: [" //TODO: store floating point regs mov x0, sp - bl __relibc_internal_fork_impl - b 2f -"]); + bl {fork_impl} + + add sp, sp, #128 + ret +"] <= [fork_impl = sym fork_impl]); -asmfunction!(__relibc_internal_fork_hook: [" +asmfunction!(__relibc_internal_fork_ret: [" ldp x0, x1, [sp] - bl __relibc_internal_fork_hook + bl {child_hook} //TODO: load floating point regs mov x0, xzr - .p2align 4 -2: add sp, sp, #32 ldp x19, x20, [sp], #16 ldp x21, x22, [sp], #16 @@ -80,17 +88,17 @@ asmfunction!(__relibc_internal_fork_hook: [" ldp x29, x30, [sp], #16 ret -"]); +"] <= [child_hook = sym child_hook]); asmfunction!(__relibc_internal_sigentry: [" mov x0, sp bl {inner} - mov x8, {SYS_SIGRETURN} - svc 0 -"] <= [inner = sym inner_c, SYS_SIGRETURN = const SYS_SIGRETURN]); + // FIXME + b . +"] <= [inner = sym inner_c]); -asmfunction!(__relibc_internal_rlct_clone_ret -> usize: [" +asmfunction!(__relibc_internal_rlct_clone_ret: [" # Load registers ldp x8, x0, [sp], #16 ldp x1, x2, [sp], #16 @@ -100,4 +108,4 @@ asmfunction!(__relibc_internal_rlct_clone_ret -> usize: [" blr x8 ret -"]); +"] <= []); diff --git a/redox-rt/src/arch/x86.rs b/redox-rt/src/arch/i686.rs similarity index 86% rename from redox-rt/src/arch/x86.rs rename to redox-rt/src/arch/i686.rs index eb33fc44..bab929a1 100644 --- a/redox-rt/src/arch/x86.rs +++ b/redox-rt/src/arch/i686.rs @@ -1,11 +1,21 @@ use syscall::error::*; -use crate::{fork_inner, FdGuard}; +use crate::proc::{fork_inner, FdGuard}; +use crate::signal::{inner_fastcall, RtSigarea}; // Setup a stack starting from the very end of the address space, and then growing downwards. pub(crate) const STACK_TOP: usize = 1 << 31; pub(crate) const STACK_SIZE: usize = 1024 * 1024; +#[derive(Debug, Default)] +pub struct SigArea { + pub altstack_top: usize, + pub altstack_bottom: usize, + pub tmp: usize, + pub onstack: u64, + pub disable_signals_depth: u64, +} + /// Deactive TLS, used before exec() on Redox to not trick target executable into thinking TLS /// is already initialized as if it was a thread. pub unsafe fn deactivate_tcb(open_via_dup: usize) -> Result<()> { @@ -45,7 +55,7 @@ unsafe extern "cdecl" fn __relibc_internal_fork_hook(cur_filetable_fd: usize, ne let _ = syscall::close(new_pid_fd); } -asmfunction!(__relibc_internal_fork_wrapper: [" +asmfunction!(__relibc_internal_fork_wrapper -> usize: [" push ebp mov ebp, esp @@ -98,9 +108,8 @@ asmfunction!(__relibc_internal_sigentry: [" add esp, 512 fxrstor [esp] - mov eax, {SYS_SIGRETURN} - int 0x80 -"] <= [inner = sym inner_fastcall, SYS_SIGRETURN = const SYS_SIGRETURN]); + ud2 +"] <= [inner = sym inner_fastcall]); asmfunction!(__relibc_internal_rlct_clone_ret -> usize: [" # Load registers diff --git a/redox-rt/src/arch/mod.rs b/redox-rt/src/arch/mod.rs index 372b7802..efbef2b7 100644 --- a/redox-rt/src/arch/mod.rs +++ b/redox-rt/src/arch/mod.rs @@ -4,9 +4,9 @@ pub use self::aarch64::*; pub mod aarch64; #[cfg(target_arch = "x86")] -pub use self::x86::*; +pub use self::i686::*; #[cfg(target_arch = "x86")] -pub mod x86; +pub mod i686; #[cfg(target_arch = "x86_64")] pub use self::x86_64::*; diff --git a/redox-rt/src/lib.rs b/redox-rt/src/lib.rs index 2d06cc8e..a1f3189c 100644 --- a/redox-rt/src/lib.rs +++ b/redox-rt/src/lib.rs @@ -45,8 +45,8 @@ pub type Tcb = GenericTcb<RtSigarea>; pub unsafe fn tcb_activate(tls_end: usize, tls_len: usize) { // Uses ABI page let abi_ptr = tls_end - tls_len - 16; - ptr::write(abi_ptr as *mut usize, tls_end); - asm!( + core::ptr::write(abi_ptr as *mut usize, tls_end); + core::arch::asm!( "msr tpidr_el0, {}", in(reg) abi_ptr, ); diff --git a/redox-rt/src/signal.rs b/redox-rt/src/signal.rs index 368620ce..7b72dd5e 100644 --- a/redox-rt/src/signal.rs +++ b/redox-rt/src/signal.rs @@ -11,7 +11,7 @@ use crate::sync::Mutex; static CPUID_EAX1_ECX: core::sync::atomic::AtomicU32 = core::sync::atomic::AtomicU32::new(0); pub fn sighandler_function() -> usize { - #[cfg(target_arch = "x86_64")] + //#[cfg(target_arch = "x86_64")] // Check OSXSAVE bit // TODO: HWCAP? /*if CPUID_EAX1_ECX.load(core::sync::atomic::Ordering::Relaxed) & (1 << 27) != 0 { @@ -73,7 +73,7 @@ pub(crate) unsafe extern "C" fn inner_c(stack: usize) { inner(&mut *(stack as *mut SigStack)) } #[cfg(target_arch = "x86")] -unsafe extern "fastcall" fn inner_fastcall(stack: usize) { +pub(crate) unsafe extern "fastcall" fn inner_fastcall(stack: usize) { inner(&mut *(stack as *mut SigStack)) } diff --git a/src/platform/redox/signal.rs b/src/platform/redox/signal.rs index 50f8f48a..de8d1ee2 100644 --- a/src/platform/redox/signal.rs +++ b/src/platform/redox/signal.rs @@ -125,7 +125,7 @@ impl PalSignal for Sys { SigactionKind::Ignore } else { SigactionKind::Handled { - handler: if c_act.sa_flags & crate::header::signal::SA_SIGINFO as u64 != 0 { + handler: if c_act.sa_flags & crate::header::signal::SA_SIGINFO as c_ulong != 0 { SignalHandler { sigaction: unsafe { core::mem::transmute(c_act.sa_handler) }, } -- GitLab