summaryrefslogtreecommitdiff
path: root/lib/librthread
AgeCommit message (Collapse)Author
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@
2016-09-03Remove _USING_TICKETS, it's defined as 0. No functional change.Michal Mazurek
ok tedu@ mpi@
2016-09-01delete wrong cvs $ tagsTheo de Raadt
2016-09-01bumpOtto Moerbeek
2016-09-01Less lock contention by using more pools for mult-threaded programs.Otto Moerbeek
tested by many (thanks!) ok tedu, guenther@
2016-09-01retire sparcTed Unangst
2016-06-01implicit function declaration is the error we really want, not theTed Unangst
annoying strict prototypes
2016-05-20Delete the _SDA_BASE and _SDA2_BASE symbols: they're unnecessary inPhilip Guenther
shared libraries...and I misspelled them anyway
2016-05-11remove hppa64 port, which we never got going beyond broken single users.Theo de Raadt
hppa reverse-stack gives us a valuable test case, but most developers don't have a 2nd one to proceed further with this. ok kettenis
2016-05-07Use a Thread Information Block in both single and multi-threaded programs.Philip Guenther
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
2016-04-15Document PROTO_NORMAL requires matching DEF_{,NON}STDPhilip Guenther
2016-04-15PROTO_NORMAL(pthread_cond_signal) requires DEF_STD(pthread_cond_signal)Philip Guenther
2016-04-15make pthread_barrier_wait behave more like it does on other platforms.Ted Unangst
from Kari Tristan Helgason
2016-04-09replace 0xf57ff05f with dmb syJonathan Gray
spotted by guenther
2016-04-02Wrap <pthread.h> and <pthread_np.h> to eliminate PLT entries for internalPhilip Guenther
references. Use _thread_pagesize for the semaphore mmap size instead of calling getpagesize() each time. ok beck@
2016-04-02Eliminate the need to explicitly invoke syscalls via their _thread_sys_*Philip Guenther
aliases by using a macro REDIRECT_SYSCALL() to map the symbols. Apply that to getthrid(), sysctl(), and issetugid() as well. ok mpi@ beck@
2016-03-21Rename the system call sendsyslog2 to sendsyslog. Keep the old oneAlexander Bluhm
as osendsyslog for a while. The three argument variant is the only one that will stay. input kettenis@; OK deraadt@
2016-03-20Prepare for future ld.so/libc bump: update <tib.h> with the definitionsPhilip Guenther
that will be needed and make libpthread work when ld.so/libc.a provide an initial TIB.
2016-03-10No point in keeping the threading support for vax, I guessPhilip Guenther
2016-01-27Replace the malloc spinlock with a mutex. This lock is held over system callsMark Kettenis
which run for many cycles and may even sleep. This leads to other threads spinning for a long time waiting on the lock. Using a mutex means those threads go to sleep and get woken up when the lock is released, which results in a lot less CPU usage. More work is needed to improve the performance of threaded code that suffers from malloc lock contention, but this diff makes ports like Firefox significantly more usable. Tested by many. ok mpi@, guenther@, tedu@, jca@
2015-12-10use geteuid to allow root to communicate with others.Ted Unangst
report from Jeunder Yu
2015-11-10Split the intra-thread functionality from kill(2) into its own syscallPhilip Guenther
thrkill(2), rolling the kill(2) syscall number with the ABI change to avoid breaking binaries during during the transition. thrkill(2) includes a 'tcb' argument that eliminates the need for locking in pthread_kill() and simplifies pthread_cancel(). Switch __stack_smash_handler() to use thrkill(2) and explicitly unblock SIGABRT. Minor bump to both libc and libpthread: make sure you install a new kernel! ok semarie@