summaryrefslogtreecommitdiff
path: root/lib/librthread
AgeCommit message (Collapse)Author
2022-09-09Add libc wrappers for the new sendmmsg and recvmmsg system calls.Moritz Buhl
Feedback tb@, miod@, jca@ OK jca@
2022-05-14librthread: validate timespec inputs with timespecisvalid(3)Scott Soule Cheloha
ok millert@
2021-09-17these files do not need sys/param.hTheo de Raadt
2021-06-13Save and restore errno around FUTEX_WAIT futex(2) operations. While thereMark Kettenis
remove the unused _wait() function in librthread such that we don't have to add the save/restore sequence there. Fixed building Python as a race with another thread unlocking a futex(2) would make futex(2) set errno to EAGAIN which would confuse Python in beleiving that readdir(2) failed instead of reaching the end of the directory. Spotted and tested by tb@ ok bluhm@
2021-05-21The implementation of the FUTEX_WAIT option in futex(2) is subtly broken.Mark Kettenis
Unfortunately libc and libpthread rely on the broken behaviour. Adjust the code in those libraries such that it works with both the old and the proposed new behaviour. The kernel changes that fix the issue will be committed in a week or so to give those who do their own builds a chance to update these libraries before we make the change. ok mpi@, deraadt@
2020-10-12make fixed-sized fixed-value mib[] arrays be constTheo de Raadt
ok guenther tb millert
2020-04-06Update my email address.Paul Irofti
2020-02-06Instead of opting in to futexes on archs with atomics opt out on archsJonathan Gray
without atomics, a smaller list. ok mpi@ visa@
2019-11-01Remove duplicated header.Martin Pieuchot
2019-10-24Backout previous synch.h commit (r1.5, "Use process-private futexes to avoidStuart Henderson
the uvm_map lookup overhead"). This causes hangs with Python, seen easily by trying to build ports/graphics/py-Pillow.
2019-10-21Use process-private futexes to avoid the uvm_map lookup overhead.Martin Pieuchot
While here kill unused _wait() function. ok visa@
2019-03-03Wake all waiters when unlocking an rwlock. This fixes a hangVisa Hankala
that could happen if there was more than one writer waiting for a read-locked rwlock. Problem found by semarie@. OK semarie@ tedu@
2019-02-13New futex(2) based rwlock implementation based on the mutex code.Martin Pieuchot
This implementation reduces contention because threads no longer need to spin calling sched_yield(2) before going to sleep. Tested by many, thanks! ok visa@, pirofti@
2019-02-13Import the existing rwlock implementation for architectures that cannotMartin Pieuchot
use the futex(2)-based one due to missing atomic primitives.
2019-02-04add a pthread_get_name_np to match pthread_set_name_np.Ted Unangst
could be useful in ports. initial diff by David Carlier some time ago. ok jca
2019-01-29Rename 1-letter variables to be coherent with others futex(2) basedMartin Pieuchot
implementations. ok pirofti@
2019-01-12Move sigwait(3) from libpthread to libcJeremie Courreges-Anglas
POSIX wants it in libc, that's where the function can be found on other systems. Reported by naddy@, input from naddy@ and guenther@. "looks ok" guenther@, ok deraadt@ Note: riding the libc/libpthread major cranks earlier today.
2019-01-11mincore() is a relic from the past, exposing physical machine informationTheo de Raadt
about shared resources which no program should see. only a few pieces of software use it, generally poorly thought out. they are being fixed, so mincore() can be deleted. ok guenther tedu jca sthen, others
2018-10-21Switch alpha to futex(2) based condvars, mutexes and semaphores.Visa Hankala
From Brad, tested by Miod, OK kettenis@
2018-10-15Switch powerpc to futex(2) based condvars, mutexes and semaphores.Visa Hankala
From Brad, OK mpi@ kettenis@
2018-09-24enable futex(2) based mutexes on armv7 and use futex based semaphores inJonathan Gray
librthread on armv7 as well from brad ok visa@ kettenis@ mpi@
2018-07-06Return EINVAL if pthread_barrier_init is called with count=0.Paul Irofti
OK kettenis@, guenther@
2018-06-08New semaphore implementation making sem_post async-safe.Paul Irofti
POSIX dictates that sem_post() needs to be async-safe here[0] and is thus included in the list of safe functions to call from within a signal handler here[1]. The old semaphore implementation is using spinlocks and __thrsleep to synchronize between threads. Let's say there are two threads: T0 and T1 and the semaphore has V=0. T1 calls sem_wait() and it will now sleep (spinlock) until someone else sem_post()'s. Let's say T0 sends a signal to T1 and exits. The signal handler calls sem_post() which is meant to unblock T1 by incrementing V. With the old semaphore implementation we we are now in a deadlock as sem_post spinlocks on the same lock. The new implementation does not suffer from this defect as it uses futexes to resolve locking and thus sem_post does not need to spin. Besides fixing this defect and making us POSIX compliant, this should also improve performance as there should be less context switching and thus less time spent in the kernel. For architectures that do not provied futexes and atomic operations, the old implementation will be used and it is now being renamed to rthread_sem_compat as discussed with mpi@. [0] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_post.html [1] -- http://pubs.opengroup.org/onlinepubs/9699919799/functions/V2_chap02.html OK visa@, mpi@, guenther@
2018-05-02syslog_r() expects a priority, not a faciliy. Use LOG_ERR for theAlexander Bluhm
pthread_attr_setstack() error message. OK deraadt@
2018-04-27pthread_join() must not return EINTRPhilip Guenther
Simplify sem_trywait() ok pirofti@ mpi@
2018-04-24Validate timespec and return ECANCELED when interrupted with SA_RESTART.Paul Irofti
Discussing with mpi@ and guenther@, we decided to first fix the existing semaphore implementation with regards to SA_RESTART and POSIX compliant returns in the case where we deal with restartable signals. Currently we return EINTR everywhere which is mostly incorrect as the user can not know if she needs to recall the syscall or not. Return ECANCELED to signal that SA_RESTART was set and EINTR otherwise. Regression tests pass and so does the posixsuite. Timespec validation bits are needed to pass the later. OK mpi@, guenther@
2018-04-12(file missed from previous commit)Theo de Raadt
Implement MAP_STACK option for mmap(). Synchronous faults (pagefault and syscall) confirm the stack register points at MAP_STACK memory, otherwise SIGSEGV is delivered. sigaltstack() and pthread_attr_setstack() are modified to create a MAP_STACK sub-region which satisfies alignment requirements. Observe that MAP_STACK can only be set/cleared by mmap(), which zeroes the contents of the region -- there is no mprotect() equivalent operation, so there is no MAP_STACK-adding gadget. This opportunistic software-emulation of a stack protection bit makes stack-pivot operations during ROPchain fragile (kind of like removing a tool from the toolbox). original discussion with tedu, uvm work by stefan, testing by mortimer
2018-02-11Start mapping thread stacks with MAP_STACK. mmap() currently ignoresTheo de Raadt
the flag, but some problem identification can begin.
2018-02-10Shift top-of-stack down so that the random==0 case doesn't leave stackTheo de Raadt
pointer beyond the space. ok stefan, tedu
2017-11-04Revert recent changes to unbreak ports/net/sambaJeremie Courreges-Anglas
While it is not clear (to me) why that ports ends up with corrupted shared libs, reverting those changes fixes the issue and should allow us to close p2k17 more smoothly. Discussed with a bunch, ok ajacoutot@ guenther@
2017-10-29Prefer <elf.h> to the non portable <sys/exec_elf.h>.Martin Pieuchot
ok jca@, deraadt@
2017-10-28Change pthread_cleanup_{push,pop} to macros that store the cleanup infoPhilip Guenther
on the stack instead of mallocing the list and move the APIs from libpthread to libc so that they can be used inside libc. Note: the standard was explicitly written to permit/support this "macro with unmatched brace" style and it's what basically everyone else already does. We xor the info with random cookies with a random magic to detect/trip-up overwrites. Major bump to both libc and libpthread due to the API move. ok mpi@
2017-10-15Move the thread-related .h files to /usr/src/include/, since thePhilip Guenther
implementation is now spread between libc and librthread. No changes to the content ok mpi@
2017-09-05Move mutex, condvar, and thread-specific data routes, pthread_once, andPhilip Guenther
pthread_exit from libpthread to libc, along with low-level bits to support them. Major bump to both libc and libpthread. Requested by libressl team. Ports testing by naddy@ ok kettenis@
2017-08-01Use "volatile unsigned int" instead of _atomic_lock_t. The _atomic_lock_tMark Kettenis
isn't the same size on all our architectures and should only be used for spin locks. ok visa@, mpi@
2017-07-30disable post fork checks for now, too much turbulence in the airTed Unangst
2017-07-29not all the world is an i386. Back out breakage.Theo de Raadt
2017-07-29Use memory barriers to prevent pointer use before initialization.Paul Irofti
This work was sparked by the topic posted on hn by wuch. I am still not sure that this fixes the defect he claims to have observed because I was not able to create a proper regress test for it to manifest. To that end, a proof of concept is more than welcomed! Thank you for the report! Discussed with and OK kettenis@, tedu@.
2017-07-27bad things can (and will) happen if a threaded program calls fork() andTed Unangst
then strays off the path to exec(). one common manifestation of this problem occurs in pthread_join(), so we can add a little check there. first person to hit this in real life gets to change the error message.
2017-07-04Enable the use of futex(2) in librthread on mips64.Visa Hankala
OK mpi@, deraadt@
2017-06-01Re-enabled futex based condvar & mutexes, they are not the cause ofMartin Pieuchot
vmd(8)'s regression.
2017-06-01New condvar introduced a regression with vmd(8), revert until it is found.Martin Pieuchot
Reported by Gregor Best.
2017-05-29Enable futex-based mutex and condvar.Martin Pieuchot
ok everybody
2017-05-29SPINLOCK_SPIN_HOOK is no more, define our own set of macros.Martin Pieuchot
Prodded by kettenis@ and tedu@
2017-05-28Use membar_enter_after_atomic() and membar_exit_before_atomic().Martin Pieuchot
2017-05-27New mutex and condvar implementations based on futex(2).Martin Pieuchot
Not enabled yet, it needs some SPINLOCK_SPIN_HOOK love and some bumps. Tested by many including sthen@ in a bulk. ok visa@, sthen@, kettenis@, tedu@
2017-02-27RELRO means the __{got,plt}_{start,end} symbols are superfluousPhilip Guenther
ok kettenis@
2017-01-11Add support for AArch64.Patrick Wildt
2017-01-05Now that all non-ARMv7 platforms are gone, tedu the legacy atomicPatrick Wildt
locking code. ok kettenis@
2016-09-04Get rid of ticket support, replace "struct _spinlock" with "_atomic_lock_t".Michal Mazurek
ok tedu@