summaryrefslogtreecommitdiffstats
path: root/lib/librthread/rthread.c (follow)
Commit message (Collapse)AuthorAgeFilesLines
* Revert recent changes to unbreak ports/net/sambajca2017-11-041-1/+31
| | | | | | | | 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@
* Prefer <elf.h> to the non portable <sys/exec_elf.h>.mpi2017-10-291-2/+2
| | | | ok jca@, deraadt@
* Change pthread_cleanup_{push,pop} to macros that store the cleanup infoguenther2017-10-281-31/+1
| | | | | | | | | | | | | | 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@
* Move mutex, condvar, and thread-specific data routes, pthread_once, andguenther2017-09-051-127/+46
| | | | | | | | 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@
* bad things can (and will) happen if a threaded program calls fork() andtedu2017-07-271-1/+7
| | | | | | 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.
* Get rid of ticket support, replace "struct _spinlock" with "_atomic_lock_t".akfaew2016-09-041-18/+16
| | | | ok tedu@
* Remove _USING_TICKETS, it's defined as 0. No functional change.akfaew2016-09-031-3/+2
| | | | ok tedu@ mpi@
* Less lock contention by using more pools for mult-threaded programs.otto2016-09-011-1/+4
| | | | tested by many (thanks!) ok tedu, guenther@
* Use a Thread Information Block in both single and multi-threaded programs.guenther2016-05-071-215/+155
| | | | | | | | | | | | | | | | | 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@
* Wrap <pthread.h> and <pthread_np.h> to eliminate PLT entries for internalguenther2016-04-021-1/+4
| | | | | | | references. Use _thread_pagesize for the semaphore mmap size instead of calling getpagesize() each time. ok beck@
* Eliminate the need to explicitly invoke syscalls via their _thread_sys_*guenther2016-04-021-5/+20
| | | | | | | aliases by using a macro REDIRECT_SYSCALL() to map the symbols. Apply that to getthrid(), sysctl(), and issetugid() as well. ok mpi@ beck@
* Prepare for future ld.so/libc bump: update <tib.h> with the definitionsguenther2016-03-201-18/+8
| | | | | that will be needed and make libpthread work when ld.so/libc.a provide an initial TIB.
* Split the intra-thread functionality from kill(2) into its own syscallguenther2015-11-101-37/+11
| | | | | | | | | | | | 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@
* delete old lint ARGSUSED commentsguenther2015-11-011-2/+1
|
* Merge the sigaction() and sigprocmask() overloads/wrappers from libpthreadguenther2015-10-231-4/+2
| | | | | | | | | 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@
* ld.so no longer needs or uses a bind lock, so stop setting it. Thisguenther2015-10-181-23/+1
| | | | | eliminates a chunk of complexity from the libpthread init and the fork wrapper, as it was the bind lock that needed prebinding before use.
* Instead of testing for __ELF__ and/or vax, leave out the bits for interfacingguenther2015-05-191-11/+6
| | | | | | | with ld.so locking whenever building NOPIC pointless use of __ELF__ noted by brad@ ok miod@
* In the child after fork, the dl lock has to be forced as its inner spinlockguenther2015-05-101-6/+9
| | | | | | may have been grabbed by another thread in the parent before the fork problem report from dcoppa@, ok kettenis@
* Delete the duplicated sched_{policy,param} members from the internal structguenther2015-04-291-1/+8
| | | | | | | | 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.
* Make pthread_atfork() track the DSO that called it like atexit() does,guenther2015-04-071-1/+3
| | | | | | | | | | 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@
* Don't restart syscalls on SIGTHR. When a cancellation happens, we need toguenther2014-11-161-2/+1
| | | | | | unroll to the cancellation check ok tedu@
* Use a flag on the pthread_t to indicate that the thread's stack wasguenther2014-07-011-4/+4
| | | | | | allocated by the kernel's execve bits. ok matthew@
* lint is dead (long live the lint!), so stop using it as a cpp conditionalguenther2014-03-161-5/+1
| | | | | | (namespace pollution!) or talking about its opinion on code. ok krw@
* Fix static linking of libpthread: have crt0 invoke __init_tcb() if it'sguenther2013-12-121-6/+29
| | | | | | defined and we don't think ld.so has already done the TCB setup. ok and much discussion miod@
* Don't try to reuse _initial_thread in the fork() wrapper, as theguenther2013-11-291-3/+4
| | | | | | | | | 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@
* In pthread_kill()/pthread_cancel(), hold the target thread's flagsguenther2013-10-231-5/+42
| | | | | | | lock across the kill, so that it can't exit (and its tid be reused!) before the kill() discussed with tedu@ marc@
* Stop overwriting the dying thread's struct thread as its tid member mayguenther2013-07-301-11/+5
| | | | | | | be concurrently updated by __threxit() prompted by a report from Alf Schlichting (a.schlichting (at) lemarit.com) ok kettenis@
* VAX ELF userland bits. Consists mostly of register prefix additions.miod2013-07-051-2/+2
|
* something's not quite right yet. ticket locks result in more CPU usagetedu2013-06-011-28/+6
| | | | | | and spinning in kernel. partially back out, but in a way that makes going forward again easy. seen by ajacoutot
* cleanup and consolidate the spinlock_lock (what a name!) code.tedu2013-06-011-15/+44
| | | | | | | | | | 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)
* fix race when exiting a detached thread. observed by and ok guenthertedu2013-04-061-4/+7
|
* Revert previous diff: sparc and sparc64 don't set the TCB to NULL in exec, yet,guenther2013-02-151-42/+7
| | | | | | and vax doesn't support symbols that are both weak and undefined (yet?). sparc issue diagnosed by kettenis@, vax problem found by todd@
* Make libpthread compatible with an ld.so that does TCB allocation:guenther2013-02-141-7/+42
| | | | | | | | 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@
* We want to check that the dynamic linker is available at run-time, somatthew2012-08-221-15/+21
| | | | | | | | 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
* Test for __PIC__ instead of PIC in preparation for eliminating -DPICmatthew2012-08-221-3/+3
| | | | | | from bsd.lib.mk for C source files. ok deraadt, pascal
* Oops, on a.out architectures __cerror() is called _cerror(). Fixmatthew2012-08-151-3/+9
| | | | | | accordingly so vax can build again. ok deraadt
* Add explicit references from rthread.o to all of the weak symbolmatthew2012-08-131-1/+71
| | | | | | | | | | | 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@;
* __tfork() needs to set the stack address of the new thread in the kernel,guenther2012-06-211-6/+4
| | | | | | | | | 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@
* pthread_setcanceltype() shouldn't be a cancelation pointguenther2012-04-101-2/+1
| | | | ok kurt@
* Remove pthread_suspend* and related functions. This is part of thekurt2012-03-221-2/+1
| | | | rthreads major library bump from last night. okay kettenis@
* Permit recursive locking in _rthread_dl_lock(), as an so's destructorguenther2012-03-201-2/+42
| | | | | | may need to call dlclose(). problem observed by Antti Harri (iku at openbsd.fi), ok kurt@
* Force sched_yield() to be resolved before calling dlctl(DL_SET*LCK) withguenther2012-03-141-1/+2
| | | | | | a function that can call sched_yield(), to avoid recursion ok kurt@ kettenis@
* Add sem_timewait() and fix sem_wait()'s handling of signals, soguenther2012-03-031-5/+6
| | | | | | | 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.
* for readability, put the label on it's own line.fgsch2012-03-021-2/+3
|
* sched_yield() is the standard name while pthread_yield() is theguenther2012-02-241-2/+2
| | | | non-standard alias, so prefer the former
* Use a form of designated initializer that works with gcc2guenther2012-02-191-2/+7
| | | | lint doesn't understand designated initializers, so hide them from it
* Fix previous commit: _rthread_init() was static.guenther2012-02-181-2/+2
| | | | Improve consistency of error naming
* Fix the handling of the stackaddr, stacksize, and guardsize attributes:guenther2012-02-181-8/+18
| | | | | | | | | | | 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@
* Set __isthreaded in pthread_create() instead of _rthread_init() such that itkettenis2012-02-161-3/+4
| | | | | | | | 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@
* Reimplement mutexes, condvars, and rwlocks to eliminate bugs,guenther2012-01-171-16/+43
| | | | | | | | | | | | | 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.