Browse Source

Fixes for redox-exec on aarch64

Jeremy Soller 2 years ago
parent
commit
adbdf1d73d
1 changed files with 12 additions and 5 deletions
  1. 12 5
      src/platform/redox/redox-exec/src/arch/aarch64.rs

+ 12 - 5
src/platform/redox/redox-exec/src/arch/aarch64.rs

@@ -9,13 +9,18 @@ pub(crate) const STACK_SIZE: usize = 1024 * 1024;
 /// 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<()> {
-    //TODO: aarch64
-    Err(Error::new(ENOSYS))
+    let mut env = syscall::EnvRegisters::default();
+
+    let file = FdGuard::new(syscall::dup(open_via_dup, b"regs/env")?);
+
+    env.tpidr_el0 = 0;
+
+    let _ = syscall::write(*file, &mut env)?;
+    Ok(())
 }
 
 pub fn copy_env_regs(cur_pid_fd: usize, new_pid_fd: usize) -> Result<()> {
     // Copy environment registers.
-    /*TODO
     {
         let cur_env_regs_fd = FdGuard::new(syscall::dup(cur_pid_fd, b"regs/env")?);
         let new_env_regs_fd = FdGuard::new(syscall::dup(new_pid_fd, b"regs/env")?);
@@ -24,7 +29,6 @@ pub fn copy_env_regs(cur_pid_fd: usize, new_pid_fd: usize) -> Result<()> {
         let _ = syscall::read(*cur_env_regs_fd, &mut env_regs)?;
         let _ = syscall::write(*new_env_regs_fd, &env_regs)?;
     }
-    */
 
     Ok(())
 }
@@ -58,6 +62,8 @@ __relibc_internal_fork_wrapper:
     str x29, [sp, #-8]!
     str x30, [sp, #-8]!
 
+    sub sp, sp, #32
+
     //TODO: store floating point regs
 
     mov x0, sp
@@ -71,7 +77,7 @@ __relibc_internal_fork_wrapper:
     .type __relibc_internal_fork_ret, @function
 __relibc_internal_fork_ret:
     ldr x0, [sp]
-    ldr x1, [sp], #8
+    ldr x1, [sp, #8]
     bl __relibc_internal_fork_hook
 
     //TODO: load floating point regs
@@ -80,6 +86,7 @@ __relibc_internal_fork_ret:
 
     .p2align 4
 2:
+    add sp, sp, #32
     ldr x30, [sp], #8
     ldr x29, [sp], #8
     ldr x28, [sp], #8