summaryrefslogtreecommitdiff
path: root/Userland/Libraries/LibPthread
AgeCommit message (Collapse)Author
2021-07-09LibPthread+Kernel: Add pthread_kill() and the thread_kill syscallAli Mohammad Pur
2021-07-07LibC+LibPthread: Use FUTEX_PRIVATE_FLAG in more placesSergey Bugaev
Performance go brrrrr
2021-07-06LibPthread: Fix some assertionsSergey Bugaev
2021-07-06LibPthread: Fix orderingSergey Bugaev
It would be enough to use relaxed ordering here if it weren't for the mutex, which we also need to store and retrieve. To ensure the pthread_cond_broadcast() call sees the store, use release and acquire as appropriate. Thankfully, both of these are on the slow paths.
2021-07-05LibC+LibPthread: Add PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NPAndreas Kling
This is a common but non-standard way of initializing a pthread_mutex_t in recursive mode.
2021-07-05LibPthread: Reimplement semaphoresSergey Bugaev
This implementation does not use locking or condition variables internally; it's purely based on atomics and futexes. Notably, concurrent sem_wait() and sem_post() calls can run *completely in parallel* without slowing each other down, as long as there are empty slots for them all to succeed without blocking. Additionally, sem_wait() never executes an atomic operation with release ordering, and sem_post() never executes an atomic operation with acquire ordering (unless you count the syscall). This means the compiler and the hardware are free to reorder code *into* the critical section.
2021-07-05LibPthread: Reimplement condition variablesSergey Bugaev
This implementation features a fast path for pthread_cond_signal() and pthread_cond_broadcast() for the case there's no thread waiting, and does not exhibit the "thundering herd" issue in pthread_cond_broadcast(). Fixes https://github.com/SerenityOS/serenity/issues/8432
2021-07-05LibC: Add futex_wait() and futex_wake() helpersSergey Bugaev
These are convinient wrappers over the most used futex operations. futex_wait() also does some smarts for timeout and clock handling. Use the new futex_wait() instead of a similar private helper in LibPthread.
2021-07-04Toolchain+Userland: Enable TLS for x86_64Gunnar Beutner
This is not technically a toolchain change, but it does require rebuilding the toolchain for x86_64 (and just that).
2021-07-01Kernel+LibPthread: Add support for usermode threads on x86_64Gunnar Beutner
2021-07-01Kernel+LibPthread: Remove m_ prefix for public membersGunnar Beutner
2021-06-30Kernel: Disable __thread and TLS on x86_64 for nowGunnar Beutner
They're not yet properly supported.
2021-06-30LibPthread: Remove redundant return statementGunnar Beutner
The pthread_exit() function doesn't return and is marked as such.
2021-06-24Userland: Add more TODO()s for arch-specific codeGunnar Beutner
This enables building more of the userspace applications for x86_64.
2021-06-01LibPthread: Correct error check in `sem_post` and `sem_wait`Jelle Raaijmakers
2021-05-29Kernel: Make sure we free the thread stack on thread exitGunnar Beutner
This adds two new arguments to the thread_exit system call which let a thread unmap an arbitrary VM range on thread exit. LibPthread uses this functionality to unmap the thread stack. Fixes #7267.
2021-05-29LibPthread: Make some variables staticGunnar Beutner
2021-05-21Revert "Userland: static vs non-static constexpr variables"Linus Groh
This reverts commit 800ea8ea969835297dc7e7da345a45b9dc5e751a. Booting the system no longer worked after these changes.
2021-05-21Userland: static vs non-static constexpr variablesLenny Maiorani
Problem: - `static` variables consume memory and sometimes are less optimizable. - `static const` variables can be `constexpr`, usually. - `static` function-local variables require an initialization check every time the function is run. Solution: - If a global `static` variable is only used in a single function then move it into the function and make it non-`static` and `constexpr`. - Make all global `static` variables `constexpr` instead of `const`. - Change function-local `static const[expr]` variables to be just `constexpr`.
2021-05-17Everywhere: Fix a bunch of typosLinus Groh
2021-05-14LibC: Do not include errno.h inside unistd.hJean-Baptiste Boric
POSIX does not mandate this, therefore let's not do it.
2021-05-10LibC: Partially implement pthread_setcancel{state,type}()Gunnar Beutner
With those partially implemented I can start to clone the SerenityOS git repository via HTTPS. The download still fails half-way through because SSL_read returns an error for reasons I haven't investigated yet.
2021-05-08LibPthread: Add implementation for pthread_mutexattr_gettypeGunnar Beutner
2021-05-02LibPthread: Implement pthread_spinlock_t API.Brian Gianforcaro
This change implements the pthread user space spinlock API. The stress-ng Port requires a functioning version to work correctly. To facilitate the requirements of the posix specification for the API we implement the spinlock so that the owning tid is the value stored in the spinlock. This gives us the proper ownership semantics needed to implement the proper error handling.
2021-04-27LibPthread: Use realtime clock for futex_wait()Jelle Raaijmakers
If we get an absolute time passed to one of the pthread_*wait methods, this is not an absolute monotonic time but rather an absolute wall time. This means that we also need to pass FUTEX_CLOCK_REALTIME to the futex syscall to ensure we're not using the monotonic clock.
2021-04-25LibC: Move the __pthread_mutex_trylock function to LibCGunnar Beutner
Let's move this to LibC because the dynamic loader depends on this function.
2021-04-22Everything: Move to SPDX license identifiers in all files.Brian Gianforcaro
SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
2021-04-21LibPthread: Add non functional pthread_attr_[set|get]scope stubsBrian Gianforcaro
Standard: https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_attr_getscope.html Needed for https://fio.readthedocs.io
2021-04-20LibPthread: Add stubs for pthread_spin_* functionsGunnar Beutner
The stress-ng port depends on these now that it detects we have thread support.
2021-04-20LibC+LibPthread: Implement function forwarding for libpthreadGunnar Beutner
GCC will insert various calls to pthread functions when compiling C++ code with static initializers, even when the user doesn't link their program against libpthread explicitly. This is used to make static initializers thread-safe, e.g. when building a library that does not itself use thread functionality and thus does not link against libpthread - but is intended to be used with other code that does use libpthread explicitly. This makes these symbols available in libc.
2021-04-19Pthread: Add stubs for pthread_cleanup_{push,pop}Gunnar Beutner
The stubs are necessary to make the xz port properly detect pthread support. The two functions are only used in the configure script and nowhere else.
2021-04-18LibC+LibPthread: Make sure TLS keys are destroyed after everything elseGunnar Beutner
This ensures that __thread variables can be used when global destructors are being invoked.
2021-04-15LibPthread: Implement sem_getvalue()Gunnar Beutner
2021-04-15LibPthread: Don't hold sem->mtx after sem_wait()/sem_trywait()Gunnar Beutner
Semaphores with values greater than one didn't work because whoever called sem_wait() first held the semaphore's mutex until a matching sem_post() call. Other callers then wouldn't be able to acquire the semaphore even if the semaphore's value was still greater than zero at that point.
2021-04-15LibPthread: Improve error handling for the semaphore functionsGunnar Beutner
This patch makes sure we're propagating errors to the caller.
2021-04-15LibPthread: Ensure we're not overflowing the semaphore's valueGunnar Beutner
2021-04-14LibPthread: Implement semaphore functionsGunnar Beutner
2021-02-23Everywhere: Rename ASSERT => VERIFYAndreas Kling
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED) Since all of these checks are done in release builds as well, let's rename them to VERIFY to prevent confusion, as everyone is used to assertions being compiled out in release. We can introduce a new ASSERT macro that is specifically for debug checks, but I'm doing this wholesale conversion first since we've accumulated thousands of these already, and it's not immediately obvious which ones are suitable for ASSERT.
2021-02-17LibPthread: Convert dbgprintf() => dbgln_if()Andreas Kling
2021-02-15LibC+LibPthread: Permit partial pthread_atforkBen Wiederhake
POSIX explicitly allows providing nullptr's, and our __pthread_*() implementation stores and calls the provided functions as-is, without checking for nullptr.
2021-02-15LibC+LibPthread: Implement pthread_atfork()AnotherTest
This required a bit of rearchitecture, as pthread_atfork() required a mutex, and duplicating a mutex impl for it was silly. As such, this patch moves some standalone bits of pthread into LibC and uses those to implement atfork(). It should be noted that for programs that don't use atfork(), this mechanism only costs two atomic loads (as opposed to the normal mutex lock+unlock) :^)
2021-02-15LibC+LibPthread: Implement pthread_rwlock_*AnotherTest
This implementation is pretty damn dumb, and probably has more bugs than features. But for the time being, it seems to work. however, we should definitely replace it with a good implementation sometime very soon :^)
2021-02-15LibPthread: Stub out `pthread_atfork()`AnotherTest
2021-02-15LibC+LibPthread: Stub out pthread_rwlock_* functionsAnotherTest
2021-02-05Userland: Add LibSystem and funnel all syscalls through itAndreas Kling
This achieves two things: - Programs can now intentionally perform arbitrary syscalls by calling syscall(). This allows us to work on things like syscall fuzzing. - It restricts the ability of userspace to make syscalls to a single 4KB page of code. In order to call the kernel directly, an attacker must now locate this page and call through it.
2021-01-25Everywhere: Hook up remaining debug macros to Debug.h.asynts
2021-01-25Everywhere: Remove unnecessary debug comments.asynts
It would be tempting to uncomment these statements, but that won't work with the new changes. This was done with the following commands: find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/#define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/#define/ { toggle = 1 }' {} \; find . \( -name '*.cpp' -o -name '*.h' -o -name '*.in' \) -not -path './Toolchain/*' -not -path './Build/*' -exec awk -i inplace '$0 !~ /\/\/ #define/ { if (!toggle) { print; } else { toggle = !toggle } } ; $0 ~/\/\/ #define/ { toggle = 1 }' {} \;
2021-01-22LibPthread: Fix asserting futex return valueTom
FUTEX_WAIT returns the number of threads woken (if any). Fixes #5032
2021-01-17Kernel: Some futex improvementsTom
This adds support for FUTEX_WAKE_OP, FUTEX_WAIT_BITSET, FUTEX_WAKE_BITSET, FUTEX_REQUEUE, and FUTEX_CMP_REQUEUE, as well well as global and private futex and absolute/relative timeouts against the appropriate clock. This also changes the implementation so that kernel resources are only used when a thread is blocked on a futex. Global futexes are implemented as offsets in VMObjects, so that different processes can share a futex against the same VMObject despite potentially being mapped at different virtual addresses.
2021-01-12LibPthread: Add pthread_equal()Andreas Kling