[libc] Ensure the result of the clone syscall is not on stack in thrd_create.
Also, added a call to munmap on error in thrd_create.
This commit is contained in:
parent
3bdd850d0c
commit
3383ec5fdd
|
@ -50,6 +50,7 @@ add_entrypoint_object(
|
|||
libc.src.errno.__errno_location
|
||||
libc.src.sys.mman.mmap
|
||||
COMPILE_OPTIONS
|
||||
-O3
|
||||
-fno-omit-frame-pointer # This allows us to sniff out the thread args from
|
||||
# the new thread's stack reliably.
|
||||
)
|
||||
|
|
|
@ -82,13 +82,15 @@ LLVM_LIBC_FUNCTION(int, thrd_create,
|
|||
// but it might differ for other architectures. So, make this call
|
||||
// architecture independent. May be implement a glibc like wrapper for clone
|
||||
// and use it here.
|
||||
long clone_result =
|
||||
long register clone_result asm("rax");
|
||||
clone_result =
|
||||
__llvm_libc::syscall(SYS_clone, clone_flags, adjusted_stack,
|
||||
&thread->__tid, clear_tid_address, 0);
|
||||
|
||||
if (clone_result == 0) {
|
||||
start_thread();
|
||||
} else if (clone_result < 0) {
|
||||
__llvm_libc::munmap(thread->__stack, thread->__stack_size);
|
||||
int error_val = -clone_result;
|
||||
return error_val == ENOMEM ? thrd_nomem : thrd_error;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue