summaryrefslogtreecommitdiff
path: root/libc/src/__support/threads/linux/callonce.cpp
AgeCommit message (Collapse)Author
2025-10-08[libc] Refactor AUXV handling with new auxv.h header library (#162326)Schrodinger ZHU Yifan
Closes https://github.com/llvm/llvm-project/issues/153666 This patch introduces a new centralized AUXV (auxiliary vector) handling mechanism for LLVM libc on Linux, replacing the previous scattered implementation across multiple files. ## Key Changes: ### New Files: - **libc/src/__support/OSUtil/linux/auxv.h**: New header library providing a clean interface for AUXV access with: - `auxv::Entry` struct for AUXV entries (type and value) - `auxv::Vector` class with iterator support for traversing AUXV - `auxv::get()` function for retrieving specific AUXV values - Thread-safe initialization with fallback mechanisms (prctl and /proc/self/auxv) ### Modified Files: 1. **libc/src/__support/OSUtil/linux/CMakeLists.txt**: - Added `auxv` header library declaration with proper dependencies: - libc.hdr.fcntl_macros - libc.src.__support.OSUtil.osutil - libc.src.__support.common - libc.src.__support.CPP.optional - libc.src.__support.threads.callonce 2. **libc/config/linux/app.h**: - Removed `AuxEntry` struct (moved to auxv.h as `auxv::Entry`) - Removed `auxv_ptr` from `AppProperties` struct - Simplified application properties structure 3. **libc/src/sys/auxv/linux/getauxval.cpp**: - Completely refactored to use new auxv.h interface - Removed ~200 lines of complex initialization code - Simplified to just call `auxv::get()` function - Removed dependencies to external symbols (mman, prctl, fcntl, read, close, open) 4. **libc/src/sys/auxv/linux/CMakeLists.txt**: - Updated dependencies to use new auxv header library - Removed dependencies to external symbols (prctl, mman, fcntl, unistd, etc.) 5. **libc/startup/linux/do_start.cpp**: - Updated to use new `auxv::Vector` interface - Changed from pointer-based to iterator-based AUXV traversal - Updated field names (`aux_entry->id` → `aux_entry.type`, `aux_entry->value` → `aux_entry.val`) - Added call to `auxv::Vector::initialize_unsafe()` for early AUXV setup 6. **libc/startup/linux/CMakeLists.txt**: - Added dependency on `libc.src.__support.OSUtil.linux.auxv`
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-06-27[libc] inline fast path of callonce (#96226)Schrodinger ZHU Yifan
Split from #91572 --------- Co-authored-by: Nick Desaulniers (paternity leave) <nickdesaulniers@users.noreply.github.com>
2024-05-10[libc] avoid cmpxchg on the fastpath of callonce (#91748)Schrodinger ZHU Yifan
Avoid `cmpxchg` operation if the function has already been called. The destination operand of `cmpxchg` may receive a write cycle without regard to the result of the comparison
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)
2024-01-24[libc] Add C23 limits.h header. (#78887)lntue
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-29[libc] Fix the remaining old style includesPetr Hosek
These were omitted from previous cleanup changes. Differential Revision: https://reviews.llvm.org/D159066
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
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-09-28[libc] Add implementation of pthread_once.Siva Chandra Reddy
The existing thrd_once function has been refactored so that the implementation can be shared between thrd_once and pthread_once functions. Reviewed By: michaelrj Differential Revision: https://reviews.llvm.org/D134716