diff --git a/libc/arch-aarch64/bionic/_exit_with_stack_teardown.S b/libc/arch-aarch64/bionic/_exit_with_stack_teardown.S index 083bcb699..d910821ce 100644 --- a/libc/arch-aarch64/bionic/_exit_with_stack_teardown.S +++ b/libc/arch-aarch64/bionic/_exit_with_stack_teardown.S @@ -26,18 +26,16 @@ * SUCH DAMAGE. */ -#include -#include +#include -// void _exit_with_stack_teardown(void* stackBase, size_t stackSize, int status) +// void _exit_with_stack_teardown(void* stackBase, size_t stackSize) ENTRY(_exit_with_stack_teardown) - mov w28, w2 - mov w8, __NR_munmap - svc #0 + mov w8, __NR_munmap + svc #0 // If munmap failed, we ignore the failure and exit anyway. - sxtw x0, w28 - mov w8, __NR_exit - svc #0 + mov x0, #0 + mov w8, __NR_exit + svc #0 // The exit syscall does not return. END(_exit_with_stack_teardown) diff --git a/libc/arch-arm/bionic/_exit_with_stack_teardown.S b/libc/arch-arm/bionic/_exit_with_stack_teardown.S index 0d97f0613..6fa950e30 100644 --- a/libc/arch-arm/bionic/_exit_with_stack_teardown.S +++ b/libc/arch-arm/bionic/_exit_with_stack_teardown.S @@ -26,18 +26,16 @@ * SUCH DAMAGE. */ -#include -#include +#include -// void _exit_with_stack_teardown(void* stackBase, size_t stackSize, int status) +// void _exit_with_stack_teardown(void* stackBase, size_t stackSize) ENTRY(_exit_with_stack_teardown) - mov lr, r2 - ldr r7, =__NR_munmap - swi #0 - // If munmap failed, we ignore the failure and exit anyway. + ldr r7, =__NR_munmap + swi #0 + // If munmap failed, we ignore the failure and exit anyway. - mov r0, lr - ldr r7, =__NR_exit - swi #0 - // The exit syscall does not return. + mov r0, #0 + ldr r7, =__NR_exit + swi #0 + // The exit syscall does not return. END(_exit_with_stack_teardown) diff --git a/libc/arch-mips/bionic/_exit_with_stack_teardown.S b/libc/arch-mips/bionic/_exit_with_stack_teardown.S index 9cab52b27..ce05ab889 100644 --- a/libc/arch-mips/bionic/_exit_with_stack_teardown.S +++ b/libc/arch-mips/bionic/_exit_with_stack_teardown.S @@ -30,21 +30,19 @@ .text -// void _exit_with_stack_teardown(void* stackBase, size_t stackSize, int status) +// void _exit_with_stack_teardown(void* stackBase, size_t stackSize) .type _exit_with_stack_teardown, @function .global _exit_with_stack_teardown .align 4 .ent _exit_with_stack_teardown _exit_with_stack_teardown: - move $s0,$a2 /* preserve status for exit() call */ - - li $v0,__NR_munmap + li $v0, __NR_munmap syscall // If munmap failed, we ignore the failure and exit anyway. - move $a0,$s0 - li $v0,__NR_exit + move $a0, 0 + li $v0, __NR_exit syscall // The exit syscall does not return. .end _exit_with_stack_teardown diff --git a/libc/arch-x86/bionic/_exit_with_stack_teardown.S b/libc/arch-x86/bionic/_exit_with_stack_teardown.S index 03a4be02b..e94ae90d8 100644 --- a/libc/arch-x86/bionic/_exit_with_stack_teardown.S +++ b/libc/arch-x86/bionic/_exit_with_stack_teardown.S @@ -1,21 +1,16 @@ -#include -#include +#include -// void _exit_with_stack_teardown(void* stackBase, size_t stackSize, int status) +// void _exit_with_stack_teardown(void* stackBase, size_t stackSize) ENTRY(_exit_with_stack_teardown) - // We can trash registers because this function never returns. - // We can also take advantage of the fact that the linux syscall trap - // handler saves all the registers, so we don't need a stack to keep - // the status argument for exit while doing the munmap. - mov 4(%esp), %ebx // stackBase - mov 8(%esp), %ecx // stackSize - mov 12(%esp), %edx // Also copy 'status' off the stack we're about to unmap. - mov $__NR_munmap, %eax - int $0x80 - // If munmap failed, we ignore the failure and exit anyway. + // We can trash registers because this function never returns. + mov 4(%esp), %ebx // stackBase + mov 8(%esp), %ecx // stackSize + mov $__NR_munmap, %eax + int $0x80 + // If munmap failed, we ignore the failure and exit anyway. - mov %edx, %ebx // status - movl $__NR_exit, %eax - int $0x80 - // The exit syscall does not return. + mov $0, %ebx // status + movl $__NR_exit, %eax + int $0x80 + // The exit syscall does not return. END(_exit_with_stack_teardown) diff --git a/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S b/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S index eca3b68f9..f7bc96290 100644 --- a/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S +++ b/libc/arch-x86_64/bionic/_exit_with_stack_teardown.S @@ -26,20 +26,16 @@ * SUCH DAMAGE. */ -#include -#include +#include -// void _exit_with_stack_teardown(void* stackBase, size_t stackSize, int status) +// void _exit_with_stack_teardown(void* stackBase, size_t stackSize) ENTRY(_exit_with_stack_teardown) - // We take advantage of the fact that the linux syscall trap - // handler saves all the registers, so we don't need to save - // the status argument for exit(2) while doing the munmap(2). - mov $__NR_munmap, %eax - syscall - // If munmap failed, we ignore the failure and exit anyway. + mov $__NR_munmap, %eax + syscall + // If munmap failed, we ignore the failure and exit anyway. - mov %rdx, %rdi // status - mov $__NR_exit, %eax - syscall - // The exit syscall does not return. + mov $0, %rdi + mov $__NR_exit, %eax + syscall + // The exit syscall does not return. END(_exit_with_stack_teardown) diff --git a/libc/bionic/pthread_exit.cpp b/libc/bionic/pthread_exit.cpp index e6e636f42..269276233 100644 --- a/libc/bionic/pthread_exit.cpp +++ b/libc/bionic/pthread_exit.cpp @@ -34,7 +34,7 @@ #include "pthread_internal.h" -extern "C" void _exit_with_stack_teardown(void*, size_t, int); +extern "C" void _exit_with_stack_teardown(void*, size_t); extern "C" void __exit(int); extern "C" int __set_tid_address(int*); @@ -125,7 +125,7 @@ void pthread_exit(void* return_value) { sigfillset(&mask); sigprocmask(SIG_SETMASK, &mask, NULL); - _exit_with_stack_teardown(stack_base, stack_size, 0); + _exit_with_stack_teardown(stack_base, stack_size); } // NOTREACHED, but we told the compiler this function is noreturn, and it doesn't believe us.