summaryrefslogtreecommitdiff
path: root/lib/librthread/rthread.c
AgeCommit message (Collapse)Author
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-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-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.
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-01Less lock contention by using more pools for mult-threaded programs.Otto Moerbeek
tested by many (thanks!) ok tedu, guenther@
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-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-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.
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@
2015-11-01delete old lint ARGSUSED commentsPhilip Guenther
2015-10-23Merge the sigaction() and sigprocmask() overloads/wrappers from libpthreadPhilip Guenther
into libc, and move pthread_sigmask() as well (just a trivial wrapper). This provides consistent handling of SIGTHR between single- and multi-threaded programs and is a step in the merge of all the libpthread overloads, providing some ASM and Makefile bits that the other wrappers will need. ok deraadt@ millert@
2015-10-18ld.so no longer needs or uses a bind lock, so stop setting it. ThisPhilip Guenther
eliminates a chunk of complexity from the libpthread init and the fork wrapper, as it was the bind lock that needed prebinding before use.
2015-05-19Instead of testing for __ELF__ and/or vax, leave out the bits for interfacingPhilip Guenther
with ld.so locking whenever building NOPIC pointless use of __ELF__ noted by brad@ ok miod@
2015-05-10In the child after fork, the dl lock has to be forced as its inner spinlockPhilip Guenther
may have been grabbed by another thread in the parent before the fork problem report from dcoppa@, ok kettenis@
2015-04-29Delete the duplicated sched_{policy,param} members from the internal structPhilip Guenther
pthread and instead use the values from the embedded struct pthread_attr. For bonus points, pay attention to the sched_inherit attribute and possibly set the values from the parent thread. Problem noted by natano of bitrig.
2015-04-07Make pthread_atfork() track the DSO that called it like atexit() does,Philip Guenther
unregistering callbacks if the DSO is unloaded. Move the callback handling from libpthread to libc, though libpthread still overrides the inner call to handle locking and thread-library reinitialization. Major version bump for both libc and libpthread. verification that this fixes various ports ajacoutot@ asm assistance miod@; ok millert@ deraadt@
2014-11-16Don't restart syscalls on SIGTHR. When a cancellation happens, we need toPhilip Guenther
unroll to the cancellation check ok tedu@
2014-07-01Use a flag on the pthread_t to indicate that the thread's stack wasPhilip Guenther
allocated by the kernel's execve bits. ok matthew@
2014-03-16lint is dead (long live the lint!), so stop using it as a cpp conditionalPhilip Guenther
(namespace pollution!) or talking about its opinion on code. ok krw@
2013-12-12Fix static linking of libpthread: have crt0 invoke __init_tcb() if it'sPhilip Guenther
defined and we don't think ld.so has already done the TCB setup. ok and much discussion miod@
2013-11-29Don't try to reuse _initial_thread in the fork() wrapper, as thePhilip Guenther
thread's existing handle must continue to be valid and it didn't fully 'change' the thread handle anyway. For pthread_main_np(), use a new flag, THREAD_ORIGINAL, to indicate that the flagged thread is the original thread for *this* process. Fixes some ConsoleKit failures according to aja@
2013-10-23In pthread_kill()/pthread_cancel(), hold the target thread's flagsPhilip Guenther
lock across the kill, so that it can't exit (and its tid be reused!) before the kill() discussed with tedu@ marc@
2013-07-30Stop overwriting the dying thread's struct thread as its tid member mayPhilip Guenther
be concurrently updated by __threxit() prompted by a report from Alf Schlichting (a.schlichting (at) lemarit.com) ok kettenis@
2013-07-05VAX ELF userland bits. Consists mostly of register prefix additions.Miod Vallat
2013-06-01something's not quite right yet. ticket locks result in more CPU usageTed Unangst
and spinning in kernel. partially back out, but in a way that makes going forward again easy. seen by ajacoutot
2013-06-01cleanup and consolidate the spinlock_lock (what a name!) code.Ted Unangst
it's now atomic_lock to better reflect its usage, and librthread now features a new spinlock that's really a ticket lock. thrlseep can handle both types of lock via a flag in the clock arg. (temp back compat hack) remove some old stuff that's accumulated along the way and no longer used. some feedback from dlg, who is concerned with all things ticket lock. (you need to boot a new kernel before installing librthread)
2013-04-06fix race when exiting a detached thread. observed by and ok guentherTed Unangst
2013-02-15Revert previous diff: sparc and sparc64 don't set the TCB to NULL in exec, yet,Philip Guenther
and vax doesn't support symbols that are both weak and undefined (yet?). sparc issue diagnosed by kettenis@, vax problem found by todd@
2013-02-14Make libpthread compatible with an ld.so that does TCB allocation:Philip Guenther
if the initial thread already has a TCB then don't override it, and if the _dl_allocate_tls() and _dl_free_tls() symbols exist then use them instead of malloc/free ok kettenis@
2012-08-22We want to check that the dynamic linker is available at run-time, soMatthew Dempsky
we should actually check for _DYNAMIC at run-time rather than checking for __PIC__ at compile time, since the two are actually independent. Problem and solution identified by guenther; minor tweaks by me. ok guenther
2012-08-22Test for __PIC__ instead of PIC in preparation for eliminating -DPICMatthew Dempsky
from bsd.lib.mk for C source files. ok deraadt, pascal
2012-08-15Oops, on a.out architectures __cerror() is called _cerror(). FixMatthew Dempsky
accordingly so vax can build again. ok deraadt
2012-08-13Add explicit references from rthread.o to all of the weak symbolMatthew Dempsky
overrides provided by libpthread.a. This ensures that statically linked threaded programs use (e.g.) __cerror() from libpthread.a instead of libc.a. (Same idea previously used by libuthread.) Thanks to fgsch@ for pointing out libuthread's solution to the static linking problem. ok guenther@, tedu@;
2012-06-21__tfork() needs to set the stack address of the new thread in the kernel,Philip Guenthe
so that it can't get a signal while still running on the parent thread's stack. Also, pass in sizeof(struct __tfork) to provide forward compat when more members are added. This is an ABI change, so switch syscall numbers and bump lib majors this time. ok deraadt@ matthew@
2012-04-10pthread_setcanceltype() shouldn't be a cancelation pointPhilip Guenthe
ok kurt@
2012-03-22Remove pthread_suspend* and related functions. This is part of theKurt Miller
rthreads major library bump from last night. okay kettenis@
2012-03-20Permit recursive locking in _rthread_dl_lock(), as an so's destructorPhilip Guenthe
may need to call dlclose(). problem observed by Antti Harri (iku at openbsd.fi), ok kurt@
2012-03-14Force sched_yield() to be resolved before calling dlctl(DL_SET*LCK) withPhilip Guenthe
a function that can call sched_yield(), to avoid recursion ok kurt@ kettenis@
2012-03-03Add sem_timewait() and fix sem_wait()'s handling of signals, soPhilip Guenthe
that it resumes waiting unless the thread was canceled. As part of this, change the internal _sem_wait() function to return zero on success and an errno value on failure instead of 1 on success and zero on failure.
2012-03-02for readability, put the label on it's own line.Federico G. Schwindt
2012-02-24sched_yield() is the standard name while pthread_yield() is thePhilip Guenthe
non-standard alias, so prefer the former
2012-02-19Use a form of designated initializer that works with gcc2Philip Guenthe
lint doesn't understand designated initializers, so hide them from it
2012-02-18Fix previous commit: _rthread_init() was static.Philip Guenthe
Improve consistency of error naming
2012-02-18Fix the handling of the stackaddr, stacksize, and guardsize attributes:Philip Guenthe
don't try to merge values, round the sizes separately, and don't try to unmap application-supplied stacks. Copy from uthread the caching of default-sized stacks. Have pthread_attr_init() and pthread_create() get the default attributes from staticly allocated pthread_attr_t. Cache the pagesize in _rthread_init() and provide a macro for rounding to it based on suggestions from kettenis@ and tedu@, ok kettenis@
2012-02-16Set __isthreaded in pthread_create() instead of _rthread_init() such that itMark Kettenis
properly represents whether a process is multi-threaded or not. This fixes a bug where if a forked child would create a new thread we would not set __isthreaded. ok guenther@
2012-01-17Reimplement mutexes, condvars, and rwlocks to eliminate bugs,Philip Guenthe
particularly the "consume the signal you just sent" hang, and putting the wait queues in userspace. Do cancellation handling in pthread_cond_*wait(), pthread_join(), and sem_wait(). Add __ prefix to thr{sleep,wakeup,exit,sigdivert}() syscalls; add 'abort" argument to thrsleep to close cancellation race; make thr{sleep,wakeup} return errno values via *retval to avoid touching userspace errno.