Ver código fonte

[Pal/Linux-SGX] Do not try to munmap not-mmapped stack of main thread

In Linux-SGX PAL, the main thread's stack is provided by host Linux, unlike
child threads which stacks are mmapped by the PAL. Therefore, the main
thread's stack must not be munmapped, unlike child threads' stacks.
Previously, PAL tried to munmap stack of even the main thread, leading to
spurious segfaults in e.g. `abort_multithread` test.
Dmitrii Kuvaiskii 5 anos atrás
pai
commit
7301453940
1 arquivos alterados com 4 adições e 1 exclusões
  1. 4 1
      Pal/src/host/Linux-SGX/sgx_thread.c

+ 4 - 1
Pal/src/host/Linux-SGX/sgx_thread.c

@@ -157,7 +157,10 @@ noreturn void thread_exit(int status) {
 
     /* free the thread stack (via munmap) and exit; note that exit() needs a "status" arg
      * but it could be allocated on a stack, so we must put it in register and do asm */
-    __asm__ volatile("syscall \n\t"            /* all args are already prepared, call munmap */
+    __asm__ volatile("cmpq $0, %%rdi \n\t"     /* check if tcb->stack != NULL */
+                     "je 1f \n\t"
+                     "syscall \n\t"            /* all args are already prepared, call munmap */
+                     "1: \n\t"
                      "movq %%rdx, %%rax \n\t"  /* prepare for exit: rax = __NR_exit */
                      "movq %%rbx, %%rdi \n\t"  /* prepare for exit: rdi = status    */
                      "syscall \n\t"            /* all args are prepared, call exit  */