summaryrefslogtreecommitdiff
path: root/lib/libpthread/pthread_int.h
AgeCommit message (Collapse)Author
2020-06-10- Make pthread_condvar and pthread_mutex work on the stack rather than inad
pthread_t, so there's less chance of bad things happening if someone calls (for example) pthread_cond_broadcast() from a signal handler. - Remove all the deferred waiter handling except for the one case that really matters which is transferring waiters from condvar -> mutex on wakeup, and do that by splicing the condvar's waiters onto the mutex. - Remove the mutex waiters bit as it's another complication that's not strictly needed.
2020-06-02Pass down errno when calling pthread__errorfunc after a system call.joerg
Allow format arguments for that reason and use (v)snprintf_ss in pthread_errorfunc to avoid race conditions and the like.
2020-06-01In the interests of reliability simplify waiter handling more and redoad
condvars to manage the list of waiters with atomic ops.
2020-05-16- Try to eliminate a hang in "parked" I've been seeing while stress testing.ad
Centralise wakeup of deferred waiters in pthread__clear_waiters() and use throughout libpthread. Make fewer assumptions. Be more conservative in pthread_mutex when dealing with pending waiters. - Remove the "hint" argument everywhere since the kernel doesn't use it any more.
2020-02-16Revert "Enhance the pthread(3) + malloc(3) init model"kamil
It is reported to hand on aarch64 with gzip.
2020-02-15Enhance the pthread(3) + malloc(3) init modelkamil
Separate the pthread_atfork(3) call from pthread_tsd_init() and move it into a distinct function. Call inside pthread__init() late TSD initialization route, just after "pthread_atfork(NULL, NULL, pthread__fork_callback);". Document that malloc(3) initialization is now controlled again and called during the first pthread_atfork(3) call. Remove #if 0 code from pthread_mutex.c as we no longer initialize malloc prematurely.
2020-02-05Retire ifdef ERRORCHECK in pthread(3)kamil
It is enabled unconditionally since 2003 and used only for rwlocks and spinlocks. LLVM sanitizers make assumptions that these checks are enabled always.
2020-01-28- A bit more alignment in __pthread_st especially for the rbtree node.ad
- Use COHERENCY_UNIT from sys/param.h.
2020-01-27pthread_detach(), pthread_join(): go back to using _lwp_detach() andad
_lwp_wait(), rather than doing it all in userspace. There's less to go wrong. Doesn't seem to be a performance penalty.
2020-01-13Rip out some very ambitious optimisations around pthread_mutex that aread
don't buy much. This stuff is hard enough to get right in the kernel let alone userspace, and I don't trust that it's right.
2019-12-18Bump PTHREAD__UNPARK_MAX to 128 as bandaid for locking related hangs.joerg
2019-12-16G/c unused rwlock owner macros copy-pasted from the kernel.uwe
They were brought along with the rwlock flags but never used and never even adapted to the new home (the struct member name is different here). I looked at adapting and using them, but they don't really help readability that much and there are cases where we need to deal with "fused" owner values anyway and so can't use them.
2019-03-05Transfer all the keys that were created in the libc stub implementationchristos
to the pthread tsd implementation when the main thread is created. This corrects a problem where a process created keys before libpthread was loaded (either from the libc constructor or because libpthread was dlopened later). This fixes a problem with jemalloc which creates keys in the constructor.
2017-07-02Export the guard size of the main thread via vm.guard_size. Add ajoerg
complementary writable sysctl for the initial guard size of threads created via pthread_create. Let the existing attribut accessors do the right thing. Raise the default guard size for threads to 64KB.
2017-02-08libpthread_dbg(3) deletion from the base distributionkamil
libpthread_dbg(3) is a remnant library from the M:N thread model (pre-NetBSD-5.0) API to introspect threads within a process and for use of debuggers. Currently in the 1:1 model it's not used in GDB neither in LLDB and it's not either planned to be used. It's current function to read pthread_t structures is realizable within a regular debugger capable to instrospect objects within a tracee (GDB, LLDB...). Remaining users of this API can still use this library from pkgsrc/devel/libpthread_dbg. Sponsored by <The NetBSD Foundation>
2015-05-29Fix previous: Can't use calloc/malloc before we complete initializationchristos
of the thread library, because malloc uses pthread_foo_specific, and it will end up initializing itself incorrectly.
2015-05-29Make PTHREAD_KEYS_MAX dynamically adjustablemanu
NetBSD's PTHREAD_KEYS_MAX is set to 256, which is low compared to other systems like Linux (1024) or MacOS X (512). As a result some setups tested on Linux will exhibit problems on NetBSD because of pthread_keys usage beyond the limit. This happens for instance on Apache with various module loaded, and in this case no particular developper can be blamed for going beyond the limit, since several modules from different sources contribute to the problem. This patch makes the limit conigurable through the PTHREAD_KEYS_MAX environement variable. If undefined, the default remains unchanged (256). In any case, the value cannot be lowered below POSIX-mandated _POSIX_THREAD_KEYS_MAX (128). While there: - use EXIT_FAILURE instead of 1 when calling err(3) in libpthread. - Reset _POSIX_THREAD_KEYS_MAX to POSIX mandated 128, instead of 256.
2014-12-16Allow for arbitrary MI scheduler implementations.pooka
A concrete result is enabling unpatched libpthread to run on the rumprun stacks (e.g. Xen and bare metal) with a non-NetBSD scheduler. Those schedulers hook into the existing _lwp_frobnitz() NetBSD syscall interfaces (well, "syscall" interfaces in that scenario ;) More specifically about the change itself: 1) instead of calling _lwp_makecontext() followed by _lwp_create() and passing the entry point in ucontext_t (MD) through the calls, roll the calls into pthread__makelwp() and allow alternate implementations for that MI interface. 2) allow compile-time overriding of __lwp_gettcb_fast() or __lwp_getprivate_fast, which are inline and leak MD scheduler/thread details into libpthread Additionally, two small nits: I) define LIB=pthread before including mk.conf so that it's possible to test for LIB==pthread in mk.conf II) make it possible to leave out pthread_cancelstub.c. This is required by the current implementation of rumprun-posix (i.e. rumprun on POSIX hosts) due to symbol collisions. It needs to be fixed properly some day, but for now allows an almost-correct libpthread to run. I am sure @justin will be happy to explain the details ;) no change to NetBSD tested: anita+atf
2013-03-21- Allow libpthread to be dlopened again, by providing libc stubs to libpthread.christos
- Fail if the dlopened libpthread does pthread_create(). From manu@ - Discussed at length in the mailing lists; approved by core@ - This was chosen as the least intrusive patch that will provide the necessary functionality. XXX: pullup to 6
2012-11-21Replace the simple implementation of pthread_key_{create,destroy}christos
and pthread_{g,s}etspecific functions, to one that invalidates values of keys in other threads when pthread_key_delete() is called. This fixes chromium, which expects pthread_key_delete() to do cleanup in all threads.
2012-11-03libpthread: replace the use of obsolete sys/tree.h interface with rbtree(9).rmind
2012-08-16Add a pthread__smt_wake and add support for it on arm along withmatt
pthread__smt_pause. These are implemented using the ARM instructions SEV (wake) and WFE (pause). These are treated as NOPs on ARM CPUs that don't support them.
2012-05-04Simplify check for TLS definition to not hide code. Drop it in anotherjoerg
place as it is redundant.
2012-03-12Keep track of the size of the guard area, in case we want to make itjoerg
modifiable later. Only reuse the stack if it was allocated by libpthread and if the expected thread size matches the current stack size.
2012-03-02Separate pthread_t from thread stack. Drop additional alignmentjoerg
restrictions on the thread stack. Remove remaining parts of stackid.
2012-01-17Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.joerg
Require __HAVE_TLS_VARIANT_I or __HAVE_TLS_VARIANT_II as well as __lwp_getprivate_fast / __lwp_gettcb_fast to exist for libpthread. Define VAX as going to use TLS variant I, if it is ever implemented.
2011-10-06Include limits.h to get PTHREAD_KEYS_MAX, and move its definition there.christos
2011-09-16Use __deadjoerg
2011-08-05fix spello in commentlukem
2011-03-17Add __HAVE___LWP_GETTCB_FAST support (for mips and powerpc).matt
2011-03-16If TLS support is present, use it for pthread__self(). Thejoerg
initialisation order is correct in this case as _lwp_setprivate has been called already by ld.elf_so for dynamic programs or _libc_init for statically linked ones.
2011-03-09Add TLS support infrastructure. For dynamic binaries, ld.elf_so exportsjoerg
_rtld_tls_allocate and _rtld_tls_free. libpthread uses this functions to setup the thread private area of all new threads. ld.elf_so is responsible for setting up the private area for the initial thread. Similar functions are called from _libc_init for static binaries, using dl_iterate_phdr to access the ELF Program Header. Add test cases to exercise the different TLS storage models. Test cases are compiled and installed on all platforms, but are skipped on platforms not marked for TLS support. This material is based upon work partially supported by The NetBSD Foundation under a contract with Joerg Sonnenberger. It is inspired by the TLS support in FreeBSD by Doug Rabson and the clean ups of the DragonFly port of the original FreeBSD modifications.
2011-02-25Back out using the thread register (if present) for now.joerg
libgcc_s's __register_frame_info gets called from libc's CSU code before the libc constructors are run. __register_frame_info in turn calls pthread_mutex_lock. libpthread is not initialised at this point and therefore pthread__self() traps when deferencing the thread register. This worked before because the garbage from pthread__self() is effectively ignored.
2011-02-24Allow storing and receiving the LWP private pointer via ucontext_tjoerg
on all platforms except VAX and IA64. Add fast access via register for AMD64, i386 and SH3 ports. Use this fast access in libpthread to replace the stack based pthread_self(). Implement skeleton support for Alpha, HPPA, PowerPC, SPARC and SPARC64, but leave it disabled. Ports that support this feature provide __HAVE____LWP_GETPRIVATE_FAST in machine/types.h and a corresponding __lwp_getprivate_fast in machine/mcontext.h. This material is based upon work partially supported by The NetBSD Foundation under a contract with Joerg Sonnenberger.
2010-12-18I've had this patch in my tree for a while and since it only improveschristos
the situation, I decided to commit it. There is an inherent problem with ASLR and the way the pthread library is using the thread stack. Our pthread library chooses that stack for each thread strategically so that it can locate the location of the pthread struct for each thread by masking the stack pointer and looking just below the red zone it creates. Unfortunately with ASLR you get many random values for the initial stack, and there are situations where the masked stack base ends up below the base of the stack. (this happens on x86 when the stack base happens to be 0x???02000 for example and your mask is stackmask is 0xffe00000). To fix this, we detect the pathological cases (this happens only in the main thread), allocate more stack, and mprotect it appropriately. Then we stash the main base and the main struct, so that when we look for the pthread struct in pthread__id, we can special case the main thread. Another way to work around the problem is unlimiting stacksize, but the proper way is to use TLS to find the thread structure and not to play games with the thread stacks.
2009-05-17- Convert from makecontext() -> _lwp_makecontext().ad
- Rely on _lwp_makecontext() to set up the thread identity register. This is not currently done (a bug), nor does libpthread use the threadreg yet. I'm doing this so it the code can be used by the person working on TLS to verify that their threadreg code is working.
2009-05-16Remove unused code that's confusing when using cscope/opengrok.ad
2008-06-28Now that we have all the scheduling gunk, make these do something useful:ad
pthread_attr_get_np pthread_attr_setschedparam pthread_attr_getschedparam pthread_attr_setschedpolicy pthread_attr_getschedpolicy
2008-05-25PR lib/38741 priority inversion in libpthread breaks apps that usead
SCHED_FIFO threads - Change condvar sync so that we never take the condvar's spinlock without first holding the caller-provided mutex. Previously, the spinlock was only taken without the mutex in an error path, but it was enough to trigger the problem described in the PR. - Even with this change, applications calling pthread_cond_signal/broadcast without holding the interlocking mutex are still subject to the problem described in the PR. POSIX discourages this saying that it leads to undefined scheduling behaviour, which seems good enough for the time being. - Elsewhere, use a hash of mutexes instead of per-object spinlocks to synchronize entry/exit from sleep queues. - Simplify how sleep queues are maintained.
2008-04-28Remove clause 3 and 4 from TNF licensesmartin
2008-02-14Adjust mutex/rwlock definitions to match reality now that there is onlyad
one implementation of each. PR lib/38030.
2008-02-10- Remove libpthread's atomic ops.ad
- Remove the old spinlock-based mutex and rwlock implementations. - Use the atomic ops from libc.
2008-01-08add missing static decls.christos
2007-12-24- Use pthread__cancelled() in more places.ad
- pthread_join(): assert that pthread_cond_wait() returns zero.
2007-12-24- Fix pthread_rwlock_trywrlock() which was broken.ad
- Add new functions: pthread_mutex_held_np, mutex_owner_np, rwlock_held_np, rwlock_wrheld_np, rwlock_rdheld_np. These match the kernel's locking primitives and can be used when porting kernel code to userspace. - Always create LWPs detached. Do join/exit sync mostly in userland. When looped on a dual core box this seems ~30% quicker than using lwp_wait(). Reduce number of lock acquire/release ops during thread exit.
2007-11-19Remove the debuglog stuff. ktrace is more useful now.ad
2007-11-13Mutexes:ad
- Play scrooge again and chop more cycles off acquire/release. - Spin while the lock holder is running on another CPU (adaptive mutexes). - Do non-atomic release. Threadreg: - Add the necessary hooks to use a thread register. - Add the code for i386, using %gs. - Leave i386 code disabled until xen and COMPAT_NETBSD32 have the changes.
2007-11-13For PR bin/37347:ad
- Override __libc_thr_init() instead of using our own constructor. - Add pthread__getenv() and use instead of getenv(). This is used before we are up and running and unfortunatley getenv() takes locks. Other changes: - Cache the spinlock vectors in pthread__st. Internal spinlock operations now take 1 function call instead of 3 (i386). - Use pthread__self() internally, not pthread_self(). - Use __attribute__ ((visibility("hidden"))) in some places. - Kill PTHREAD_MAIN_DEBUG.
2007-10-16Note that libpthread_dbg needs to be checked after making changes toad
libpthread.
2007-10-16... but preserve the linked list, for the debugger only.ad