[libc-commits] [libc] 3383ec5 - [libc] Ensure the result of the clone syscall is not on stack in thrd_create.
Siva Chandra Reddy via libc-commits
libc-commits at lists.llvm.org
Sun Aug 29 21:36:58 PDT 2021
Author: Siva Chandra Reddy
Date: 2021-08-30T04:35:40Z
New Revision: 3383ec5fdd04be095678e0bd8bd1ce341f4f9294
URL: https://github.com/llvm/llvm-project/commit/3383ec5fdd04be095678e0bd8bd1ce341f4f9294
DIFF: https://github.com/llvm/llvm-project/commit/3383ec5fdd04be095678e0bd8bd1ce341f4f9294.diff
LOG: [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.
Added:
Modified:
libc/src/threads/linux/CMakeLists.txt
libc/src/threads/linux/thrd_create.cpp
Removed:
################################################################################
diff --git a/libc/src/threads/linux/CMakeLists.txt b/libc/src/threads/linux/CMakeLists.txt
index 6e8b212612ef..730314cefe52 100644
--- a/libc/src/threads/linux/CMakeLists.txt
+++ b/libc/src/threads/linux/CMakeLists.txt
@@ -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.
)
diff --git a/libc/src/threads/linux/thrd_create.cpp b/libc/src/threads/linux/thrd_create.cpp
index 5a6bc114e241..59d260da46df 100644
--- a/libc/src/threads/linux/thrd_create.cpp
+++ b/libc/src/threads/linux/thrd_create.cpp
@@ -82,13 +82,15 @@ LLVM_LIBC_FUNCTION(int, thrd_create,
// but it might
diff er 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;
}
More information about the libc-commits
mailing list