summaryrefslogtreecommitdiff
path: root/libc/src/__support/threads/linux/thread.cpp
AgeCommit message (Collapse)Author
2025-10-09[libc] fix sysconf test for rv32 (#162685)Schrodinger ZHU Yifan
2025-07-23[libc][NFC] Add stdint.h proxy header to fix dependency issue with ↵lntue
<stdint.h> includes. (#150303) https://github.com/llvm/llvm-project/issues/149993
2025-06-11[libc] Move libc_errno.h to libc/src/__support and make ↵lntue
LIBC_ERRNO_MODE_SYSTEM to be header-only. (#143187) This is the first step in preparation for: https://discourse.llvm.org/t/rfc-make-clang-builtin-math-functions-constexpr-with-llvm-libc-to-support-c-23-constexpr-math-functions/86450
2024-10-28[libc] remove #include <fcntl.h> and add proxy or type (#113836)Job Henandez Lara
2024-08-08[libc] Implement 'getenv' on the GPU target (#102376)Joseph Huber
Summary: This patch implements 'getenv'. I was torn on how to implement this, since realistically we only have access to this environment pointer in the "loader" interface. An alternative would be to use an RPC call every time, but I think that's overkill for what this will be used for. A better solution is just to emit a common `DataEnvironment` that contains all of the host visible resources to initialize. Right now this is the `env_ptr`, `clock_freq`, and `rpc_client`. I did this by making the `app.h` interface that Linux uses more general, could possibly move that into a separate patch, but I figured it's easier to see with the usage.
2024-07-27revert all tid changes (#100915)Schrodinger ZHU Yifan
2024-07-20reland "[libc] implement cached process/thread identity (#98989)" (#99765)Schrodinger ZHU Yifan
2024-07-18Revert "[libc] implement cached process/thread identity" (#99559)Schrodinger ZHU Yifan
Reverts llvm/llvm-project#98989
2024-07-18[libc] implement cached process/thread identity (#98989)Schrodinger ZHU Yifan
migrated from https://github.com/llvm/llvm-project/pull/95965 due to corrupted git history
2024-07-12[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98597)Petr Hosek
This is a part of #97655.
2024-07-12Revert "[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace ↵Mehdi Amini
declaration" (#98593) Reverts llvm/llvm-project#98075 bots are broken
2024-07-11[libc] Migrate to using LIBC_NAMESPACE_DECL for namespace declaration (#98075)Petr Hosek
This is a part of #97655.
2024-05-07[libc] clean up futex usage (#91163)Schrodinger ZHU Yifan
# Motivation Futex syscalls are widely used in our codebase as synchronization mechanism. Hence, it may be worthy to abstract out the most common routines (wait and wake). On the other hand, C++20 also provides `std::atomic_notify_one/std::atomic_wait/std::atomic_notify_all` which align with such functionalities. This PR introduces `Futex` as a subtype of `cpp::Atomic<FutexWordType>` with additional `notify_one/notify_all/wait` operations. Providing such wrappers also make future porting easier. For example, FreeBSD's `_umtx_op` and Darwin's `ulock` can be wrapped in a similar manner. ### Similar Examples 1. [bionic futex](https://android.googlesource.com/platform/bionic/+/refs/heads/main/libc/bionic/bionic_futex.cpp) 2. [futex in Rust's std](https://github.com/rust-lang/rust/blob/8cef37dbb67e9c80702925f19cf298c4203991e4/library/std/src/sys/pal/unix/futex.rs#L21)
2023-12-05[libc] remove spurious LIBC_INLINE (#74505)Nick Desaulniers
This function is marked noinline; the inline keyword (or whatever LIBC_INLINE resolves to) will have no effect.
2023-09-26[libc] Start to refactor riscv platform abstraction to support both 32 and ↵Mikhail R. Gadelha
64 bits versions This patch enables the compilation of libc for rv32 by unifying the current rv64 and rv32 implementation into a single rv implementation. We updated the cmake file to match the new riscv32 arch and force LIBC_TARGET_ARCHITECTURE to be "riscv" whenever we find "riscv32" or "riscv64". This is required as LIBC_TARGET_ARCHITECTURE is used in the path for several platform specific implementations. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148797
2023-09-26[libc] Mass replace enclosing namespace (#67032)Guillaume Chatelet
This is step 4 of https://discourse.llvm.org/t/rfc-customizable-namespace-to-allow-testing-the-libc-when-the-system-libc-is-also-llvms-libc/73079
2023-08-09[libc] Better IntegerToString APIGuillaume Chatelet
This patch is an alternative to D155902. It provides the following benefits: - No buffer manual allocation and error handling for the general case - More flexible API : width specifier, sign and prefix handling - Simpler code The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString. Reviewed By: michaelrj, jhuber6 Differential Revision: https://reviews.llvm.org/D156981
2023-08-08Revert "[libc] Better IntegerToString API"Guillaume Chatelet
This reverts commit 910cc05aae85a6b31e2a2ed87d3dd46db46fce04.
2023-08-08[libc] Better IntegerToString APIGuillaume Chatelet
This patch is an alternative to D155902. It provides the following benefits: - No buffer manual allocation and error handling for the general case - More flexible API : width specifier, sign and prefix handling - Simpler code The more flexible API removes the need for manually tweaking the buffer afterwards, and so prevents relying on implementation details of IntegerToString. Reviewed By: michaelrj, jhuber6 Differential Revision: https://reviews.llvm.org/D156981
2023-08-07[libc][cleanup] Fix most conversion warningsMichael Jones
This patch is large, but is almost entirely just adding casts to calls to syscall_impl. Much of the work was done programatically, with human checking when the syntax or types got confusing. Reviewed By: mcgrathr Differential Revision: https://reviews.llvm.org/D156950
2023-08-03[libc] Add support to compile some syscalls on 32 bit platformMikhail R. Gadelha
This patch adds a bunch of ifdefs to handle the 32 bit versions of some syscalls, which often only append a 64 to the name of the syscall (with exception of SYS_lseek -> SYS_llseek and SYS_futex -> SYS_futex_time64) This patch also tries to handle cases where wait4 is not available (as in riscv32): to implement wait, wait4 and waitpid when wait4 is not available, we check for alternative wait calls and ultimately rely on waitid to implement them all. In riscv32, only waitid is available, so we need it to support this platform. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D148371
2023-06-30[libc] Fix more inline definitionsRoland McGrath
Fix a bunch more instances of incorrect use of the `static` keyword and missing use of LIBC_INLINE and LIBC_INLINE_VAR macros. Note that even forward declarations and generic template declarations must follow the prescribed patterns for libc code so that they match every definition, all template specializations. Reviewed By: Caslyn Differential Revision: https://reviews.llvm.org/D154260
2023-05-22Cleanup code in `thread_exit`Noah Goldstein
1) Avoid proper function calls and referencing local variables after the stack has been deallocated. A proper function call/return or local variable reference that may have spilled will cause invalid memory reads after the stack has been deallocated. 2) Mark the function as [[noreturn]] and place `__builtin_unreachable()` after the `SYS_exit` syscalls. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D151142
2023-05-22Support custom attributes in pthread_createNoah Goldstein
Only functional for stack growsdown (same as before), but custom `stack`, `stacksize`, `guardsize`, and `detachstate` all should be working. Differential Revision: https://reviews.llvm.org/D148290
2023-04-21[libc] Another fix to add a null-terminator to the pthread name.Siva Chandra Reddy
This fix is similar to the one done in https://reviews.llvm.org/D148844. This miss was caught by the risv64 builder. Differential Revision: https://reviews.llvm.org/D148871
2023-04-20[libc] Add null-terminator to the thread name obtained from the syscall.Siva Chandra Reddy
This bug was caught by the aarch64 full build builder. Differential Revision: https://reviews.llvm.org/D148844
2023-04-17[libc][NFC] Standardize missing syscalls error messages.Mikhail R. Gadelha
This patch standardizes the error messages when a syscall is not available to be in the format: "ABC and DEF syscalls are not available." Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D148373
2023-03-13[libc] Special case sniffing of thread start args for riscv.Siva Chandra
2023-03-09[libc] Extend the linux thread implementation for riscv64.Siva Chandra
Also, added riscv64 startup code for static linking which is used by the integration tests. Functions from the C standard threads library have been enabled. Reviewed By: mikhail.ramalho Differential Revision: https://reviews.llvm.org/D145670
2023-03-03[libc] move stdlib and stdio to new errno patternMichael Jones
Fixes https://github.com/llvm/llvm-project/issues/61071 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D145191
2023-02-20[libc][AArch64] Fix fullbuild when using G++/GCCDavid Spickett
The libc uses some functions that GCC does not currently implement, that come from Arm's ACLE header usually. These are: ``` __arm_wsr64 __arm_rsr64 __arm_wsr __arm_rsr ``` This issue was reported to us (https://github.com/llvm/llvm-project/issues/60473) and I've then reported that back to GCC (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108642). Even if these functions are added, clang has some non standard extensions to them that gcc may not take. So we're looking at a fix in gcc 13 at best, and that may not be enough for what we're doing with them. So I've added ifdefs to use alternatives with gcc. For handling the stack pointer, inline assembly is unfortunately the only option. I have verified that the single mov is essentially what __arm_rsr64 generates. For fpsr and fpcr the gcc devs suggested using https://gcc.gnu.org/onlinedocs/gcc-12.2.0/gcc/AArch64-Built-in-Functions.html#AArch64-Built-in-Functions. Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D143261
2023-02-07[libc][NFC] Rename macrosGuillaume Chatelet
2023-02-07[libc][NFC] Rename architecture macros and move to macros folderGuillaume Chatelet
2023-01-20[libc][NFC] Replace static inline and inline annotations with LIBC_INLINE.Siva Chandra Reddy
This is first of a few patches which will do similar mechanical changes. LIBC_INLINE is a simple macro which is default defined as just `inline`. The idea is that, different downstream contexts can define the macro as suitable to their use case and context. For example, one can choose to define LIBC_INLINE as `[[clang::internal_linkage]] inline`. Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D142154
2022-12-12[libc] move errno out of file internalsMichael Jones
Now errno is only set by the terminal entrypoints, and not the internal implementations. This patch is part of the larger effort to not set errno in libc internal code: https://github.com/llvm/llvm-project/issues/59278 Reviewed By: sivachandra Differential Revision: https://reviews.llvm.org/D139576
2022-09-30[libc] add syscall functionMichael Jones
Add the syscall wrapper function and tests. It's implemented using a macro to guarantee the minimum number of arguments. Reviewed By: sivachandra, lntue Differential Revision: https://reviews.llvm.org/D134919
2022-08-22[libc][NFC] Use STL case for string_viewGuillaume Chatelet
2022-08-17[libc][NFC] Make IntegerToString simpler to use at call-sites.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D131943
2022-08-10[libc] Add implementation of pthread_exit and thrd_exit.Siva Chandra Reddy
Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D131451
2022-08-02[libc] Add GNU extension functions pthread_setname_np and pthread_getname_np.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D130872
2022-07-14[libc] Add implementations of pthread_equal and pthread_self.Siva Chandra Reddy
Reviewed By: michaelrj, lntue Differential Revision: https://reviews.llvm.org/D129729
2022-07-13[libc] Linux threads - Setup TLS area of a new thread and cleanup at exit.Siva Chandra Reddy
Reviewed By: lntue Differential Revision: https://reviews.llvm.org/D129543
2022-07-13[libc][NFC] Move thread platform data pointer to thread attributes.Siva Chandra Reddy
Along the way, added constexpr constructors to the Thread data structures.
2022-07-11[libc] Linux threads - Set CLEAR_TID addr to 0 when exiting a detached thread.Siva Chandra Reddy
A detached thread cleans itself up at completion. So, the CLEAR_TID memory is also gone by the time the kernel tries to signal potential waiters. By nulling the CLEAR_TID address, we prevent the kernel from signalling at a non-existent futex location.
2022-07-10[libc] Linux threads - store a ptr to the thread attribs in the start args.Siva Chandra Reddy
Previosly, a pointer to the thread data structure was stored in the start args. However, the thread data structure need not have the lifetime of the thread. On the the other hand, thread attributes are stored on the thread stack so they live as long as the thread lives.
2022-06-27[libc][NFC] Make the support thread library an object library.Siva Chandra Reddy
It was previously a header library. Making it an object library will allow us to declare thread local variables which can used to setup a thread's self object.