Home | History | Annotate | Download | only in libpthread
History log of /src/lib/libpthread/pthread.c
RevisionDateAuthorComments
 1.187  02-Apr-2025  riastradh pthread_cancel(3): Use _Atomic consistently with C11 atomics.

Should fix clang build:

/home/source/ab/HEAD-llvm/src/lib/libpthread/pthread.c:1264:8: error: address argument to atomic operation must be a pointer to _Atomic type ('volatile unsigned int *' invalid)
(atomic_load_relaxed(&self->pt_cancel) &
^ ~~~~~~~~~~~~~~~~
/home/source/ab/HEAD-llvm/src/lib/libpthread/pthread.c:74:2: note: expanded from macro 'atomic_load_relaxed'
atomic_load_explicit(p, memory_order_relaxed)
^ ~
/home/builds/ab/HEAD-llvm/amd64/202504020240Z-dest/usr/include/clang-13.0/stdatomic.h:121:30: note: expanded from macro 'atomic_load_explicit'
#define atomic_load_explicit __c11_atomic_load

PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
 1.186  31-Mar-2025  riastradh pthread_cancel(3): Rework.

Make pthread_setcancelstate(3) async-signal-safe. (As a side effect,
this also makes pthread_setcanceltype(3) async-signal-safe, although
that is not required.)

PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe
 1.185  08-Jun-2024  hannken Fix resource leak in pthread_create(). Pthread field "pt_lwpctl"
must not be accessed after _lwp_exit() as the kernel may free
it, attach it to another thread and change its "lc_curcpu".

The "pthread__deadqueue" will fill up with pthreads with
an invalid "pt_lwpctl" and allocated stack that never get
reused.

Replace the test "lc_curcpu == LWPCTL_CPU_EXITED" with
test "_lwp_kill(newthread->pt_lid, 0) == -1 && errno == ESRCH"
to make sure this thread has finished its _lwp_exit().

PR lib/57831 "Memory leaks in libpthread/libc"
 1.184  28-Nov-2023  riastradh pthread: Don't adjust user-allocated stack addresses by guardsize.

PR lib/57721

XXX pullup-10
XXX pullup-9
XXX pullup-8
 1.183  07-Sep-2023  ad raise() has understood threads for a long time, don't reimplment it.
 1.182  24-Mar-2023  joerg Use snprintf_ss in pthread__assertfunc and update comment in
pthread__errorfunc. snprintf can use locks in some code paths and we
only care about the restricted subset here.
 1.181  31-May-2022  riastradh branches: 1.181.2;
libpthread(3): Fix a marvellous interaction with rtld.

Patch from chs@. Comment explaining the story by me. This patch may
not be optimal -- maybe it would be better in pthread__init, or
better for rtld to call _lwp_unpark after _lwp_park in the contened
case -- but we've tested this version and it's annoying to reproduce,
so let's take this version and worry about testing improvements
later.
 1.180  12-Feb-2022  riastradh libpthread: Move namespacing include to top of .c files.

Stuff like libc's namespace.h, or atomic_op_namespace.h, which does
namespacing tricks like `#define atomic_cas_uint _atomic_cas_uint',
has to go at the top of each .c file. If it goes in the middle, it
might be too late to affect the declarations, and result in compile
errors.

I tripped over this by including <sys/atomic.h> in mips
<machine/lock.h>.

(Maybe we should create a new pthread_namespace.h file for the
purpose, but this'll do for now.)
 1.179  13-Apr-2021  mrg fake-use alloca()'s return value to quieten -Werror=unused-result
 1.178  22-Jul-2020  msaitoh s/reseting/resetting/
 1.177  14-Jun-2020  ad Don't need to ignore ESRCH from _lwp_park() any more.
 1.176  11-Jun-2020  ad Drop self->pt_lock before clearing TSD / malloc TSD.
 1.175  10-Jun-2020  ad - Make pthread_condvar and pthread_mutex work on the stack rather than in
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.
 1.174  04-Jun-2020  joerg If _malloc_thread_cleanup is implement, call it from libpthread.
Provide the hook from modern jemalloc to avoid using TSD for the thread
destruction cleanup as it can result in reentrancy crashes if fork is
called from a thread that never called malloc as it will result in a
late malloc from the pre-fork synchronisation handler.
 1.173  03-Jun-2020  ad Deal with a couple of problems with threads being awoken early due to
timeouts or cancellation where:

- The restarting thread calls _lwp_exit() before another thread gets around
to waking it with _lwp_unpark(), leading to ESRCH (observed by joerg@).
(I may have removed a similar check mistakenly over the weekend.)

- The restarting thread considers itself gone off the sleep queue but
at the same time another thread is part way through waking it, and hasn't
fully completed that operation yet by setting thread->pt_mutexwait = 0.
I think that could have potentially lead to the list of waiters getting
messed up given the right circumstances.
 1.172  02-Jun-2020  joerg Pass down errno when calling pthread__errorfunc after a system call.
Allow format arguments for that reason and use (v)snprintf_ss in
pthread_errorfunc to avoid race conditions and the like.
 1.171  01-Jun-2020  ad In the interests of reliability simplify waiter handling more and redo
condvars to manage the list of waiters with atomic ops.
 1.170  16-May-2020  ad - Try to eliminate a hang in "parked" I've been seeing while stress testing.
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.
 1.169  15-May-2020  joerg Lock/unlock/reinit pthread__deadqueue_lock over fork.
 1.168  14-Apr-2020  joerg Drop most of the logic associated with pthread__started.

The pthread_cond logic is a questionable optimisation at best and the
post-fork logic is plainly broken.
 1.167  16-Feb-2020  kamil Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.
 1.166  16-Feb-2020  kamil Set __isthreaded before bootstrapping malloc(3)

jemalloc depends on the __isthreaded dynamic state logic.

Reported by <wiz> for mpv and by <tih> for gzip.
 1.165  15-Feb-2020  kamil Enhance the pthread(3) + malloc(3) init model

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.
 1.164  08-Feb-2020  kamil Change the behavior of pthread_equal()

On error when not aborting, do not return EINVAL as it has a side effect
of being interpreted as matching threads. For invalid threads return
unmatched.

Check pthreads for NULL, before accessing pt_magic field. This avoids
faults on comparision with a NULL pointer.

This behavior is in the scope of UB, but should be easier to deal with
buggy software.
 1.163  05-Feb-2020  ryoon Remove trailing whiteapaces and tab
 1.162  29-Jan-2020  ad - pthread_join(): remove temporary hack now kernel returns correct errno.

- kill(getpid(), SIGABRT) -> _lwp_kill(_lwp_self(), SIGABRT)
 1.161  29-Jan-2020  kamil Chack thread->pt_magic with PT_MAGIC promptly

Rearrange some checks to avoid verifying pthread_t after using it.
 1.160  29-Jan-2020  kamil Revert previous

Two assignments are correct.
 1.159  29-Jan-2020  kamil Do not set stackbase2 twice for !__MACHINE_STACK_GROWS_UP
 1.158  28-Jan-2020  ad pthread_join(): add a temporary hack to make lib/libpthread/t_detach pass.
The correct fix is to do this in kernel (I have that change, but it's part
of the wider change to index LWPs in a tree).
 1.157  27-Jan-2020  ad pthread_detach(), pthread_join(): go back to using _lwp_detach() and
_lwp_wait(), rather than doing it all in userspace. There's less to go
wrong. Doesn't seem to be a performance penalty.
 1.156  25-Jan-2020  ad pthread_exit(): it looks there there is at least one path through which
a thread can exit with waiters still hanging off it (cancellation when
waiting on a condvar) so deal with all/any crappy failure like that and
make sure there are never any waiters left before exiting. Maybe of help
for:

PR: bin/50350: rump/rumpkern/t_sp/stress_{long,short} fail on Core 2
 1.155  25-Jan-2020  ad - Fix a race between the kernel and libpthread, where a new thread can start
life without its self->pt_lid being filled in.

- Fix an error path in _lwp_create(). If the new LID can't be copied out,
then get rid of the new LWP (i.e. either succeed or fail, not both).

- Mark l_dopreempt and l_nopreempt volatile in struct lwp.
 1.154  13-Jan-2020  ad Rip out some very ambitious optimisations around pthread_mutex that are
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.
 1.153  05-Mar-2019  christos branches: 1.153.2;
Transfer all the keys that were created in the libc stub implementation
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.
 1.152  19-Aug-2018  kamil Drop a duplicate instruction line

No functional change intended.
 1.151  08-Dec-2017  kre branches: 1.151.2; 1.151.4;

Deal with more lwp_park() timestamp unconsting
 1.150  11-Jul-2017  joerg Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.

If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.

Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
 1.149  02-Jul-2017  joerg Do not look at environmental variables for suid/guid binaries.
 1.148  02-Jul-2017  joerg Export the guard size of the main thread via vm.guard_size. Add a
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.
 1.147  29-May-2015  christos branches: 1.147.8;
Fix previous: Can't use calloc/malloc before we complete initialization
of the thread library, because malloc uses pthread_foo_specific, and it will
end up initializing itself incorrectly.
 1.146  29-May-2015  manu Make PTHREAD_KEYS_MAX dynamically adjustable

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.
 1.145  16-Dec-2014  pooka Allow for arbitrary MI scheduler implementations.

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
 1.144  31-Jan-2014  christos branches: 1.144.4;
remove compatibility code for handling CLOCK_MONOTONIC and handle it in the
syscall directly.
 1.143  21-Mar-2013  christos - Allow libpthread to be dlopened again, by providing libc stubs to libpthread.
- 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
 1.142  01-Jan-2013  dsl Don't rely on sys/lwp.h includeing sys/resource.h for us.
 1.141  14-Nov-2012  christos add argsused
 1.140  06-Nov-2012  apb Remove duplicate "const" modifier found by clang -Wduplicate-decl-specifier
 1.139  03-Nov-2012  rmind libpthread: replace the use of obsolete sys/tree.h interface with rbtree(9).
 1.138  03-Nov-2012  christos cast return of sysconf
 1.137  15-Aug-2012  drochner branches: 1.137.2;
return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
 1.136  02-Aug-2012  joerg Prefer sysconf to obtain number of CPUs.
 1.135  04-May-2012  joerg Simplify check for TLS definition to not hide code. Drop it in another
place as it is redundant.
 1.134  26-Apr-2012  enami Store allocated lwpctl state in the thread actually forked,
which is the only thread lives in the child process.

The problem originally reported here:
https://bugs.ruby-lang.org/issues/6341
 1.133  22-Mar-2012  drochner don't reuse a dynamically allocated stack if a fixed one is requested
 1.132  12-Mar-2012  joerg Keep track of the size of the guard area, in case we want to make it
modifiable later. Only reuse the stack if it was allocated by libpthread
and if the expected thread size matches the current stack size.
 1.131  12-Mar-2012  joerg Further refine stack allocation. If the stack was provided by the user,
don't bother with setting up a guard page. Otherwise, round up the size
to page size. Point stack inside the guarded area, without the guard
page. Fix size when mprotect failed.
 1.130  10-Mar-2012  joerg Use correct size.
 1.129  09-Mar-2012  drochner -fix initial stacksize rounding
-minor indentation fix
 1.128  08-Mar-2012  joerg Actually use the stack thread attributes when creating a new thread.
 1.127  08-Mar-2012  joerg Fix the stack base pointer for the initial thread on !HPPA.
AT_STACKBASE is pointing to the start of the stack, which is the
upper limit on platforms where the stack grows down.
 1.126  02-Mar-2012  joerg Separate pthread_t from thread stack. Drop additional alignment
restrictions on the thread stack. Remove remaining parts of stackid.
 1.125  02-Oct-2011  christos branches: 1.125.2; 1.125.4;
put back pthread__dbg variable; this is set to no zero by td_open() when
debugging to avoid multiple td_open() mess.
 1.124  16-Sep-2011  joerg Use __dead
 1.123  30-Mar-2011  joerg Rework TLS initialisation:
- Update TCB for the initial thread in pthread__initthread, not
pthread__init to get it valid as soon as possible.
- Don't overwrite the pt_tls field in pthread__initthread.
- Don't deallocate pt_tls in pthread__scrubthread. This worked more by
chance than by design.
- Handle freeing the TLS area in pthread_create after removing the
thread instance from the dead queue.
 1.122  12-Mar-2011  matt Use __lwp_gettcb_fast if present.
 1.121  09-Mar-2011  joerg Add TLS support infrastructure. For dynamic binaries, ld.elf_so exports
_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.
 1.120  22-Dec-2010  christos use pthread__stacksize since size has not been initialized yet.
 1.119  22-Dec-2010  christos only mprotect base if we moved it.
 1.118  18-Dec-2010  christos I've had this patch in my tree for a while and since it only improves
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.
 1.117  14-Nov-2010  tron Don't use internal libc function __findenv().
 1.116  08-Jul-2010  rmind pthread_create: simplify error path slightly.
 1.115  25-Mar-2010  explorer fix the pthread pt_lid in the fork callback function that runs in the child instead of a function that may be going away. KNFify
 1.114  24-Mar-2010  explorer Correctly set pt_lid in the child, after a fork
 1.113  03-Oct-2009  christos Don't just look only at the first element in the deadqueue to find lwp's
to reuse, because if we lose the race with the kernel we are never going
to reuse any elements. Look in the whole list instead.
XXX: should be pulled up to 5.x
 1.112  02-Jul-2009  joerg Restore use of _lwp_makecontext, the AMD64 bug has been fixed.
 1.111  25-Jun-2009  joerg Partially revert 1.110: Use makecontext again until the problems with
_lwp_makecontext are solved.
 1.110  17-May-2009  ad - Convert from makecontext() -> _lwp_makecontext().

- 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.
 1.109  01-Apr-2009  drochner Fix the comparision function used by the red-black tree global thread list
implementation:
-don't return a difference, this can overflow
-don't try to substract typed pointers which don't belong to the
same object, this gives undefined results

This fixes instabilities of programs which use more than a handful
of threads, eg spuriously failing pthread_join().
 1.108  30-Mar-2009  ad Revert the _lwp_ctl which is causing problem. I did test this locally,
I guess not well enough.
 1.107  29-Mar-2009  ad - Make the threadreg code use _lwp_setprivate() instead of MD hooks.

XXX This must not be enabled by default because the LWP private mechanism
is reserved for TLS. It is provided only as a test/demo.

XXX Since ucontext_t does not contain the thread private variable, for a
short time after threads are created their thread specific data is unset.
If a signal arrives during that time we are screwed.

- No longer need pthread__osrev.

- Rearrange _lwp_ctl() calls slightly.
 1.106  08-Oct-2008  ad branches: 1.106.2; 1.106.4; 1.106.6;
Disable diagnostic assertions by default and just return error codes like
other systems. Allows poorly written applications to appear working. If you
are developing pthread apps please turn it on manually by setting the
environment variable.
 1.105  02-Aug-2008  matt Change some type to eliminate some lint warnings.
 1.104  28-Jun-2008  ad Minor correction to previous.
 1.103  28-Jun-2008  ad Now that we have all the scheduling gunk, make these do something useful:

pthread_attr_get_np
pthread_attr_setschedparam
pthread_attr_getschedparam
pthread_attr_setschedpolicy
pthread_attr_getschedpolicy
 1.102  25-Jun-2008  ad pthread_join: explicitly test for cancellation.
 1.101  25-May-2008  ad PR lib/38741 priority inversion in libpthread breaks apps that use
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.
 1.100  28-Apr-2008  martin branches: 1.100.2;
Remove clause 3 and 4 from TNF licenses
 1.99  22-Mar-2008  ad branches: 1.99.2;
Back out previous. It seems to expose another bug in libpthread/libc,
potentially errno being used before threading is up and running.
 1.98  21-Mar-2008  ad Move pthread__errno() into pthread_specific.c so it gets the "no stack
frame" treatment.
 1.97  08-Mar-2008  ad Complain if _lwp_ctl() fails.
 1.96  08-Jan-2008  christos branches: 1.96.2;
add missing static decls.
 1.95  24-Dec-2007  ad - Use pthread__cancelled() in more places.
- pthread_join(): assert that pthread_cond_wait() returns zero.
 1.94  24-Dec-2007  ad - Fix pthread_rwlock_trywrlock() which was broken.

- 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.
 1.93  11-Dec-2007  ad Remove test of pthread__osrev that is no longer needed.
 1.92  04-Dec-2007  yamt remove unnecessary assignments.
 1.91  01-Dec-2007  ad - On 64-bit platforms 1/2 the default tsd values were garbage. Fix it.
- The lwpctl block is now needed on uniprocessors, for pthread_curcpu_np().
 1.90  19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.89  14-Nov-2007  drochner Add pthread_equal() to libc stubs; this makes a lot of sense for
threadsafe libraries implementing own locking functions.
Ride on yesterday's minor version bumps.
 1.88  13-Nov-2007  ad Mutexes:

- 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.
 1.87  13-Nov-2007  ad For PR bin/37347:

- 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.
 1.86  07-Nov-2007  ad Use _lwp_setname() to pass thread names to the kernel.
 1.85  16-Oct-2007  ad ... but preserve the linked list, for the debugger only.
 1.84  16-Oct-2007  ad Replace the global thread list with a red-black tree. From joerg@.
 1.83  11-Sep-2007  ad Put new threads on the tail of pthread__allqueue, for the debugger.
 1.82  08-Sep-2007  ad - Get rid of self->pt_mutexhint and use pthread__mutex_owned() instead.
- Update some comments and fix minor bugs. Minor cosmetic changes.
- Replace some spinlocks with mutexes and rwlocks.
- Change the process private semaphores to use mutexes and condition
variables instead of doing the synchronization directly. Spinlocks
are no longer used by the semaphore code.
 1.81  07-Sep-2007  ad - Don't take the mutex's spinlock (ptr_interlock) in pthread_cond_wait().
Instead, make the deferred wakeup list a per-thread array and pass down
the lwpid_t's that way.

- In pthread_cond_wait(), take the mutex before dealing with early wakeup.
In this way there should never be contention on the CV's spinlock if
the app follows POSIX rules (there should only be contention on the
user-provided mutex).

- Add a port of the kernel's rwlocks. The rwlock's spinlock is only taken if
there is contention. This is enabled where atomic ops are available. Right
now that is only i386 and amd64 because I don't have other hardware to
test with. It's trivial to add stubs for other architectures as long as
they have compare-and-swap. When we have proper atomic ops the old rwlock
code can be removed.

- Add a new mutex implementation that's similar to the kernel's mutexes, but
uses compare-and-swap to maintain the waiters list, so no spinlocks are
involved. Same caveats apply as for the rwlocks.
 1.80  23-Aug-2007  ad branches: 1.80.2;
Acquire the correct lock in pthread_detach(). Spotted by Jan Kryl.
 1.79  17-Aug-2007  ad pthread_suspend_np, pthread_resume_np, pthread_detach: return correct code
on error.
 1.78  16-Aug-2007  ad Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.77  16-Aug-2007  ad - Reinitialize the absolute minimum when recycling user thread state.
Chops another ~10% off create/join in a loop on i386.
- Disable low level debugging as this is stable. Improves benchmarks
across the board by a small percentage. Uncontested mutex acquire
and release in a loop becomes about 8% quicker.
- Minor cleanup.
 1.76  16-Aug-2007  ad Remove PT_FIXEDSTACKSIZE_LG.
 1.75  16-Aug-2007  ad Cache thread context for creation instead of setting it up every time.
Speeds create/join loop by about 10-15% on i386.
 1.74  15-Aug-2007  ad Simplify pthread_join(). Knocks about 5% off pthread_create/join in a loop.
 1.73  07-Aug-2007  ad Missed variable rename..
 1.72  07-Aug-2007  ad Change the signature of _lwp_park() to accept an lwpid_t and second
hint pointer, but do so in a way that remains compatible with older
pthread libraries. This can be used to wake another thread before the
calling thread goes asleep, saving at least one syscall + involuntary
context switch. This turns out to be a fairly large win on the condvar
benchmarks that I have tried.
 1.71  04-Aug-2007  ad branches: 1.71.2;
Make libpthread_dbg build again.
 1.70  04-Aug-2007  ad Fix error in previous.
 1.69  04-Aug-2007  ad Some significant performance improvements, and a fix for a race with pthread
detach/join.

- Make mutex acquire spin for a short time, as done with spinlocks.
- Make the number of spins controllable with the env var PTHREAD_NSPINS.
- Reduce the amount of time that libpthread internal spinlocks are held.
- Rely more on the barrier effects of park/unpark to avoid taking spinlocks.
- Simplify the locking around pthreads and the global queues.
- Align per-thread sync data on a 128 byte boundary.
- Offset thread stacks by a small amount to try and reduce cache thrash.
 1.68  24-Mar-2007  ad branches: 1.68.2;
- Test+branch is usually cheaper than making an indirect function call,
so avoid making them.
- When parking an LWP on a condition variable, point the hint argument at
the mutex's waiters queue. Chances are we will be awoken from that later.
 1.67  14-Mar-2007  ad - pthread__park: always check for cancellation.
- pthread__unpark: cosmetic changes.
 1.66  05-Mar-2007  ad - Simplify the interface to pthread__park() and friends slightly.
- If sysctl() fails, complain.
 1.65  02-Mar-2007  ad Silence a gcc/lint warning.
 1.64  02-Mar-2007  ad Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.63  02-Mar-2007  ad pthread_detach: acquire the join lock before changing pt_flags.
 1.62  21-Feb-2007  ad - Put detached & exiting threads on the tail of the deadqueue, not head.
- Don't forget to set PT_FLAG_DETACHED.
 1.61  21-Feb-2007  ad Minor optimisation to previous: only check for continued existence of
the thread if it was detached.
 1.60  15-Feb-2007  yamt fix a race between pthread_exit and pthread_create.
inefficient, but better than crashing.
 1.59  09-Feb-2007  ad Cast the return value of _lwp_unpark_all(), just in case.
 1.58  31-Jan-2007  christos use __func__ instead of __FUNCTION__ which is a gcc extension.
 1.57  20-Jan-2007  ad pthread_create(): clear newthread->pt_sleeponq before calling _lwp_create().
 1.56  20-Jan-2007  christos add a missing volatile.
 1.55  16-Jan-2007  ad Fix a race between pthread_exit() and pthread_join().
 1.54  16-Jan-2007  ad Fix a race between pthread_create() and pthread_exit() in the 1:1 case.
 1.53  16-Jan-2007  ad Pass in the 'hint' argument when parking/unparking LWPs.
 1.52  24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.51  23-Dec-2006  ad Add another comment.
 1.50  23-Dec-2006  ad Add a comment.
 1.49  23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.48  24-Apr-2006  drochner branches: 1.48.4; 1.48.6;
There is no point in using the internal sigprocmask() to initialize
the process' signal mask -- this ends up in a no-op.
Use the system call directly instead.
(This might be done in pthread_sig.c, but for now I wanted a simple
patch which is easily tested and pulled up.)
 1.47  12-Feb-2006  yamt - do PTHREAD_MLOCK_KLUDGE in pthread__stackid_setup, rather than callers,
so that the main thread is not different from others.
as a side effect, fix memory leak in pthread_create on error.
- make pthread__stackid_setup return a error rather than calling err(2).
 1.46  19-Oct-2005  chs if mlock() fails in pthread_create(), return EAGAIN instead of
failing an assertion.
 1.45  19-Oct-2005  chs starting the pthread library (ie. calling pthread__start()) before
any threads are created turned out to be not such a good idea.
there are stronger requirements on what has to work in a forked child
while a process is still single-threaded. so take all that stuff
back out and fix the problems with single-threaded programs that
are linked with libpthread differently, by checking if the library
has been started and doing completely different stuff if it hasn't been:
- for pthread_rwlock_timedrdlock(), just fail with EDEADLK immediately.
- for sem_wait(), the only thing that can unlock the semaphore is a
signal handler, so use sigsuspend() to wait for a signal.
- for pthread_mutex_lock_slow(), just go into an infinite loop
waiting for signals.

I also noticed that there's a "sem2" test that has never worked in its
single-threaded form. the problem there is that a signal handler tries
to take a sem_t interlock which is already held when the signal is received.
fix this too, by adding a single-threaded case for sig_trywait() that
blocks signals instead of using the userland interlock.
 1.44  16-Oct-2005  chs in pthread_kill() and pthread_suspend_np(), return without doing anything
if the target thread is a zombie.

in all the functions that didn't do so already, verify a pthread_t before
dereferencing it (under #ifdef ERRORCHECK, since these checks are not
mandated by the standard).

clean up some debugging stuff.
 1.43  16-Oct-2005  chs in pthread_mutex_lock_slow(), pthread_rwlock_timedrdlock() and sem_wait(),
call pthread__start() if it hasn't already been called. this avoids
an internal assertion from the library if these routines are used
before any threads are created and they need to sleep.
fixes PR 20256, PR 24241, PR 25722, PR 26096.
 1.42  01-Jul-2005  yamt make this compile without PTHREAD_MLOCK_KLUDGE.
 1.41  26-Feb-2005  nathanw branches: 1.41.2;
Keep the kernel updated with signal action signal masks (act.sa_mask) until
threads are started, since before that the traditional signal invocation
method will be used. Fixes regress/lib/libpthread/sigmask2.
 1.40  10-Feb-2005  christos Default back pthread__concurrency to 1 until we fix the regression test
related to pthread_kill().
 1.39  10-Feb-2005  christos If $PTHREAD_CONCURRENCY is not set, set it to ncpu
 1.38  03-Feb-2005  christos Add charles' mlock fixes, protected with PTHREAD_MLOCK_KLUDGE and enabled
by default, until we come up with a real fix.
 1.37  06-Jan-2005  mycroft Add some additional assertions and debugging printf()s.
 1.36  12-Aug-2004  yamt - fix pthread_detach with an already exit'ed thread.
namely, put the thread to deadqueue rather than just leaking it.
- fix a race between pthread_detach/join and pthread_exit,
which also causes dead thread leaks.
 1.35  18-Jul-2004  chs enhance MI pthreads code to support hppa:
- statically initialize all global spin locks. on hppa, 0 means
the lock is held, so leaving them with the default value doesn't work.
- compare functions pointers using a function-pointer type rather than
an integral type. on hppa, function pointers may be indirect,
so we need to trigger gcc to emit calls to the function-pointer
canonicalization routines in the millicode.
- on hppa the stack grows up, so handle that using the STACK_* macros.
 1.34  25-Jun-2004  drochner const'ify the arguments to pthread__assertfunc and _errorfunc;
needed because the __func__ pseudo-var is strictly "const*" in gcc-3.4
 1.33  14-Mar-2004  cl branches: 1.33.2;
add libpthread part of concurrency support for SA on MP systems
- enable concurrency according to environment variable PTHREAD_CONCURRENCY
- add idle VP wakeup if there are additional jobs and idle VPs
- make reidlequeue per VP
- enable spinning for locks
- fix race condition in alarm processing
- fix race condition in mutex locking
- make debugging output line buffered and add VP prefix to debug lines
 1.32  31-Dec-2003  cl Handle block/unblock for threads in critical section without
sa_unblockyield.

XXX g/c sa_unblockyield in kernel later
 1.31  18-Dec-2003  christos PR/23791: Patrick Latify: Fix memory leak on thread creation failure.
 1.30  09-Nov-2003  christos Add:

int pthread_attr_setcreatesuspend_np(pthread_attr_t *);
int pthread_suspend_np(pthread_t);
int pthread_resume_np(pthread_t);

needed for java. Approved and fixed by cl.
 1.29  13-Aug-2003  nathanw Split out pthread_{set,get}specific() into a separate file and arrange
for that file to not be built with profiling. This makes it reasonable to
use pthread_{set,get}specific() to implement thread-safe profiline call counts.
 1.28  21-Jul-2003  nathanw Lock accesses to pt_flags and pt_cancel.

When disabling cancellation, clear the pt_cancel flag if it was set
and note the cancellation request with PT_FLAG_CS_PENDING. This avoids
a problem where a cancellation request entered but not acted upon before
pthread_setcanclstate(PTHREAD_CANCEL_DISABLE) is called would still be
aceted upon before cancellation was re-enabled.
 1.27  21-Jul-2003  nathanw Use _sys_write() instead of write() in the assertion and error
functions, to avoid invoking the cancellation machinery in the middle
of trying to print an assertion or error message.
 1.26  21-Jul-2003  nathanw Move initialization of variable 'nthreads' so that pthread_exit() from
the main thread, with no other threads created, exits cleanly instead
of triggering an assertion in pthread_next().
 1.25  18-Jul-2003  nathanw pthread.c was getting a bit unwieldly. Move pthread_attr stuff out
into a new file, and put the shared private structure definition in
pthread_int.h.
 1.24  18-Jul-2003  nathanw Implement a bunch of pthread_attr_() functions, which genuinely set and examine
pthread_attr_t objects, although most of the properties being set don't really
affect threads yet:

pthread_attr_{get,set}guardsize()
pthread_attr_{get,set}inheritsched()
pthread_attr_{get,set}scope()
pthread_attr_{get,set}stack()
pthread_attr_setstack{size,addr}()

Remove some useless assertions and error checks in the existing pthread_attr()
routines.

Implement pthread_attr_get_np(), to examine the attributes of an existing
thread. Idea and interface from FreeBSD.

Change PTHREAD_ERRORMODE environment variable to PTHREAD_DIAGASSERT, and
make it behave like libc's LIBC_DIAGASSERT. The way to disable error-checking
and aborting is now "PTHREAD_DIAGASSERT=AEL", rather than
"PTHREAD_ERRORMODE=ignore".
 1.23  18-Jul-2003  nathanw Add strong alias for setcancelstate.
 1.22  26-Jun-2003  nathanw Initialize pt_trapuc in pthread__initthread().
 1.21  06-Jun-2003  nathanw Tiny bit of infrastructure for ABI-supported thread-ID storage.
 1.20  02-Jun-2003  christos Add pthread_attr_getstack{,size,addr} needed by jdk
 1.19  27-May-2003  christos pass lint:
1. add new pthread__abort() and change pthread_assert(0) to it.
2. put constcond in the right place (in the macro).
3. no space after pthread__assert macro.
 1.18  28-Apr-2003  nathanw Move call to pthread__alarm_init() from pthread_init() (called at load
time) to pthread__start() (called on the first call of
pthread_create()), so that there's no opportunity for a fork() to
clear the per-process timer.

Problem pointed out by a test program from Mihai CHELARU on
current-users.
 1.17  23-Apr-2003  nathanw Introduce a pthread__error() macro, for detected application errors as
opposed to internal errors. The setting of the PTHREAD_ERRORMODE
environment variable determines the runtime behavior. Valid settings
are "ignore", "abort", and "print". The default is currently "abort".
 1.16  07-Apr-2003  nathanw When threads are started, register an atfork callback to clear
pthread__started in the child process. This lets sleep() work in the
child, as required by POSIX.
 1.15  10-Mar-2003  nathanw Re-enable nanosleep(); kernel bug is squished (kern_time.c:1.67).
 1.14  08-Mar-2003  lukem add __RCSID()
 1.13  28-Feb-2003  nathanw Disable userlevel nanosleep() until I find the timer/alarm bug that it
is tickling.
 1.12  26-Feb-2003  nathanw In pthread_create(), rearrange name-setting code so that name is set
to NULL when the attribute structure does not have a private field
allocated.
 1.11  26-Feb-2003  thorpej Add support for naming a thread, using an API compatible with Tru64 Unix:
* pthread_attr_getname_np()
* pthread_attr_setname_np()
* pthread_getname_np()
* pthread_setname_np()

In addition to being query'able by the application (for log messages, etc.),
it is intended that these names can show up in the debugger.

Reviewed by nathanw.
 1.10  22-Feb-2003  nathanw In pthread_exit(), clear pt_canceled in addition to setting
PT_FLAG_CS_DISABLED in pt_flags.

Prevents cancellation cleanup handlers from thinking that they've been
canceled and exiting mid-handler. Problem spotted by Matt Thomas.
 1.9  15-Feb-2003  nathanw Define a pthread-specific assert function, pthread__assert(), that
bails out without trying to flush stdio buffers.
 1.8  31-Jan-2003  nathanw Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.
 1.7  29-Jan-2003  drochner cosmetics
 1.6  25-Jan-2003  nathanw Make pthread_join() accomodate spurious wakeups from pthread__block().
 1.5  19-Jan-2003  thorpej Add some threadlib stubs that are used by X:
* thr_create() (stub in libc aborts)
* thr_exit() (stub in libc calls exit())
* thr_yield() (stub in libc does nothing)

Also make the libc thr_self() stub not abort.

XXX Should we add thrattr_*() stubs for setting the detach-state?
 1.4  19-Jan-2003  christos - constify the get functions
- remove argument variable names since they pollute the namespace
- add mock implementation of the missing stack functions
XXX: we need to do this right [i.e. actually get and set sizes and addresses]
but the current stack setup makes this a bit complicated.
 1.3  18-Jan-2003  christos de-lint
 1.2  18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1  05-Mar-2001  nathanw branches: 1.1.2;
file pthread.c was initially added on branch nathanw_sa.
 1.1.2.44  11-Jan-2003  nathanw Add some debug logging to pthread__idle(). Be more agressive about the
assertion if we return from sa_yield() by creating an artifical
lock-count, so it doesn't get reclaimed mid-assert.
 1.1.2.43  09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.42  08-Jan-2003  thorpej Rewrite the way libpthread provides thread primitives to libc, using
strong and weak aliases (the way cancelation points are handled).

Work around lame Unix static library semantics which could cause
the wrong thread primitives or cancelation point functions to be
included in a statically-linked program.

THIS IS AN ABI CHANGE. People running the nathanw_sa branch should
ensure that their libc and libpthread are in sync after updating.
 1.1.2.41  03-Jan-2003  nathanw Silent failures are annoying.
Sprinkle some assert(0) after NOTREACHED points.
 1.1.2.40  02-Jan-2003  nathanw Oops, left a few too many extern declarations around. (Save buffers
*before* commiting!)
 1.1.2.39  02-Jan-2003  nathanw Clean up the namespace a bit; make a few more things static, and make sure
all private globals are prefixed with pthread__.
 1.1.2.38  02-Jan-2003  nathanw Newline police.
 1.1.2.37  30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.36  20-Dec-2002  nathanw Set the type of an idle thread to PT_THREAD_IDLE only when it is created,
not every time it's scheduled (left over from vestigal any-thread-can-be-idle
code).
 1.1.2.35  18-Dec-2002  nathanw Start debugging subsystem later, after the main() thread has been
created, so that lockcounts (called back by mutexes locked by libc)
aren't referencing garbage.
 1.1.2.34  16-Dec-2002  nathanw More debugging hooks.
 1.1.2.33  18-Nov-2002  skrll Typo in comment.
 1.1.2.32  28-Oct-2002  nathanw Implement sched_yield().

Clean up trailing whitespace.
 1.1.2.31  28-Oct-2002  nathanw As pointed out recently on comp.programming.threads, POSIX requires
that pthread_detach() and pthread_join() must return ESRCH, not invoke
undefined behavior, even if handed completely nonsensical pthread_t values.
So, search through the list of threads to see if the pthread_t value is
valid.
 1.1.2.30  27-Oct-2002  thorpej Cosmetic changes.
 1.1.2.29  22-Oct-2002  nathanw Use _INITCONTEXT_U() instead of _getucontext_u() to prime a fresh context.
 1.1.2.28  07-Oct-2002  nathanw Rename started to pthread__started and make it avaliable to other
files.
 1.1.2.27  07-Oct-2002  nathanw Comment formatting.
 1.1.2.26  14-Aug-2002  nathanw Infrastructure for machine-dependent init code.
 1.1.2.25  20-May-2002  nathanw Many signal improvements:

- Implement sigsuspend()
- Take pending signals that are unblocked in pthread_sigmask().
- Tweak the signal mask passed by sigaction() to permit us to manage
our own thread-specific signal masks.
- Don't try to deliver signals to zombie threads.
- Prevent a race between deciding a thread can take a signal and actually
taking it.
- Don't put threads that are blocked in a syscall on the run queue.
- Add debug logging.
 1.1.2.24  02-May-2002  nathanw Different way of integrating with libc: Create a vector type for pthread
operations; libc will have a pointer to such a vector. When the pthread
library is loaded, set libc's pointer to a vector of real operations.
This removes the reliance on weak symbol magic, which didn't work
for static binaries, and as an aesthetic side effect, we don't have to
export a bunch of ugly _libc_pthread_* wrappers.
 1.1.2.23  28-Apr-2002  nathanw Explicitly set the state of the first thread to RUNNING.
 1.1.2.22  26-Apr-2002  nathanw Track the object (and queue and lock!) when sleeping to join a thread.
 1.1.2.21  24-Apr-2002  nathanw Create pthread IDs.
 1.1.2.20  11-Apr-2002  nathanw Revert weak aliases.

Recycle the thread structures and stacks of threads that have been put on
on the dead queue, so that pthread_create() ... pthread_join() isn't a
resource leak.
 1.1.2.19  25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.18  01-Mar-2002  nathanw Loop-hoist a comment.
 1.1.2.17  21-Feb-2002  nathanw Block signals in idle threads.
 1.1.2.16  19-Feb-2002  nathanw Move alarm initialization into pthread_alarms.c.
 1.1.2.15  06-Feb-2002  nathanw Move a couple of debugging declarations to pthread_debug.c, where they belong.

Add a debug routine to print the pthread event counters if the environment
variable PTHREAD_DEBUGCOUNTERS is set.
 1.1.2.14  28-Jan-2002  nathanw Cancellation support.
This includes implementing pthread_cancel() and pthread_testcancel(),
making pthread_join() and pthread_cond_wait() cancellation points,
introducing new states to distinguish waiting on a sleep queue
from waiting in the kernel, and introducing a locking protocol around
changing a thread's run state.
 1.1.2.13  30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
Implement basic cancellation functions.
Implement pthread__errno().
 1.1.2.12  25-Sep-2001  nathanw Use getcontext() instead of _getcontext() before initializing the
new thread state with makecontext(), since the callee-save registers saved
by _getcontext() may not include the registers needed by makecontext().

Unfortunately, this implies a syscall for every new thread creation.
 1.1.2.11  04-Sep-2001  nathanw #include <string.h> for memset prototype.
 1.1.2.10  08-Aug-2001  nathanw pthread_malloc() and pthread_free() are superfluous.
 1.1.2.9  08-Aug-2001  nathanw Keep track of the total number of normal threads, and exit() from
pthread_exit() if the count goes to 0.
 1.1.2.8  08-Aug-2001  nathanw Split pthread__start() into pthread__start() and pthread__init();
pthread__init() is the code that needs to run whenever the thread
library is linked in and usable; pthread__start() doesn't run until
the first new thread is created.
 1.1.2.7  01-Aug-2001  nathanw Initialize pt_sleepuc and pt_switchto (!).
 1.1.2.6  24-Jul-2001  nathanw Unlock the correct spinlock (Ye gods).
 1.1.2.5  17-Jul-2001  nathanw Add a mechanisim for debugging that is less likely to change scheduling
behaviour than using printf (writing to a shared memory segment), and a
simple tool for dumping the buffer. Partly inspired by the kernel msgbuf
code.
 1.1.2.4  17-Jul-2001  nathanw Create more idle threads. In the current system, we need one for every level
of preemption nesting.
 1.1.2.3  13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2  13-Jul-2001  nathanw Convert to new queue type.

Remove a level of indirection in the pthread_attr_t type.
 1.1.2.1  05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.33.2.1  30-Aug-2004  tron Pull up revision 1.36 (requested by yamt in ticket #801):
- fix pthread_detach with an already exit'ed thread.
namely, put the thread to deadqueue rather than just leaking it.
- fix a race between pthread_detach/join and pthread_exit,
which also causes dead thread leaks.
 1.41.2.2  13-May-2006  tron Pull up following revision(s) (requested by drochner in ticket #1314):
lib/libpthread/pthread.c: revision 1.48
There is no point in using the internal sigprocmask() to initialize
the process' signal mask -- this ends up in a no-op.
Use the system call directly instead.
(This might be done in pthread_sig.c, but for now I wanted a simple
patch which is easily tested and pulled up.)
 1.41.2.1  01-Nov-2005  jmc Pullup revs 1.43-1.46 (requested by chs in ticket #926)
In pthread_mutex_lock_slow(), pthread_rwlock_timedrdlock() and sem_wait(),
call pthread__start() if it hasn't already been called. this avoids
an internal assertion from the library if these routines are used
before any threads are created and they need to sleep.
PR#20256, PR#24241, PR#25722, PR#26096

Fix the interaction between sigtimedwait() and pthread_kill(),
both waking up a sleeping thread and avoiding going to sleep if
a signal is already pending. PR#30348

In pthread_kill() and pthread_suspend_np(), return without doing anything
f the target thread is a zombie.
In all the functions that didn't do so already, verify a pthread_t before
dereferencing it (under #ifdef ERRORCHECK, since these checks are not
mandated by the standard).

Starting the pthread library (ie. calling pthread__start()) before
any threads are created turned out to be not such a good idea.
there are stronger requirements on what has to work in a forked child
while a process is still single-threaded. so take all that stuff
back out and fix the problems with single-threaded programs that
are linked with libpthread differently, by checking if the library
has been started and doing completely different stuff if it hasn't been:
- for pthread_rwlock_timedrdlock(), just fail with EDEADLK immediately.
- for sem_wait(), the only thing that can unlock the semaphore is a
signal handler, so use sigsuspend() to wait for a signal.
- for pthread_mutex_lock_slow(), just go into an infinite loop
waiting for signals.

If mlock() fails in pthread_create(), return EAGAIN instead of
failing an assertion.
 1.48.6.4  04-Nov-2007  wrstuden Check in changes to locking behavior.

pthread__sched() now takes a parameter indicating if the run queue is
already locked. Useful in cases where we already hold pthread__runqueue_lock.

pthread__suspend() now requires callers explicitly lock pthread__runqueue_lock
so we avoid issues with locking order regarding pt_statelock.

Adjsut our lock hierarchy. pthread__runqueue_lock is now above
pt_statelock, triggering the above adjustments. Adjust a lot of routines
as a result. Also move pt_siglock way up in the hierarchy, making
pthread__kill() not violate locking. Add a few extra locks to the list.

Adjust a botch in how pthread_join() used pthread-spintrylock().

pthread_cancel() now correctly walks up the locks with thread->pt_sleeplock.
We can't just lock it, as it points to a lock in the top locking rung. So
try locking, and if it fails, unlock and re-lock. Add code to cope with
the target thread not being in the expected state (which was on a
blocked queue) after we get all the locks.

Add comments to describe what's going on in places that I got confused.

Now that pt_statelock is lower in the locking order than
pthread__runqueue_lock, we can explicitly lock a thread's state before
we take it off the run queue. Adjust sched_yield() accordingly and
add some locking calls that were commented out before (as they'd have
been locking violations).

pthread_next(): now that we can lock the state lock while holding the run
queue lock, do so. Set a thread's state to PT_STATE_RUNNING before we
pull it off the run queue. Since we always are going to switch to it,
set pt_vpid and pt_lastlwp while setting the state. pthread_next
callers now _don't_ set these values.

pthread__kill(): grab pthread__runqueue_lock before target->pt_statelock.
If we want to target a thread that is on a blocked queue, do the
pthread_spintrylock() dance. Unlock all three locks we're running around
with, lock target->pt_sleeplock, then re-lock them all. After we lock,
make sure that the thread's still on a blocked queue before proceeding. If
it's not, either exit (if we wanted to wake out of sigtimedwait())
or start it all over. If the thread has gone live, it may have blocked
our signal and it'd be quite weird to get a signal you'd disabled, just
because the signaller had been running before you blocked it.
 1.48.6.3  19-Oct-2007  wrstuden Work on cleaning up lock ordering. Turns out that there's not too
much to do, other than fixing an issue in join and one I introduced.

Add volumous comment in pthread_int.h describing how I understand the
current locking to work.

pthread_join() considered pt_flaglock to be a higher-priority lock
than pt_join_lock. Life makes more sense if we flip that.

To not make a lot of routines messy, pthread__runqueue_lock has to be
lower in the lock ordering than pt_statelock. Adapt the changes I made
to sched_yield() to this ordering.

There still is a wart regarding setting the state of a thread
we are taking off of the run (or idle) queue. We can't lock
its pt_statelock as we have the runqueue lock held. For now,
go back to what the old code did which was just write over the info.
This isn't that bad as the only things that should be changing
the state of this thread should be run-queue savy. I need to check
this though....
 1.48.6.2  25-Sep-2007  wrstuden Rename pt_blockedlwp to pt_lastlwp, and set it whenever we switch
to a new pthread. This way we always know on what lwp a given
thread is running.
 1.48.6.1  10-Sep-2007  wrstuden Check in first step towards having pthread_kill() kill a thread running
on another CPU.

This change adds initial support for deferred signal handling. Just before
we go to sleep and while we hold &self->pt_statelock, check to see if we
have any deferred signals (blocked signals) pending. These are signals
that are not masked in our mask and which have been sent to us. We
were running when they came in. Further, since they are being handled
this way, there's a signal handler defined for them.

So unlock, run the signal handler(s), then carry on.

For condition variables, we consider this a spurious wakeup, so we just
return 0, having not unlocked the mutex. We run the handler with
the mutex held. This shouldn't matter, as you aren't supposed to play
with mutexes in signal handlers. :-)

For nanosleep(), we just process signals, then go to sleep.

For all other cases, we are in a loop with some external predicate. So
we process the signal then roll around the loop to see if it still applies.

In sched_yield(), spin until all deferred signals are gone. Since we hold
self->pt_statelock and that lock has to be held before sending a deferred
signal, no new deferred signals will come in until we're asleep.

While here, be more careful about locking while changing pt_state
to PT_STATE_RUNNING. Grab pt_statelock while doing it, and also set
next->pt_vpid to self->pt_vpid holding the same lock. Will make
the test to determine how to deliver a signal work right (since
a thread's vpid will soon matter in the general case). No longer
set next->pt_vpid in pthread__next().
 1.48.4.1  16-Sep-2008  bouyer Sync with the following revisions (requested by skrll in ticket #1196):
gnu/dist/gdb removed
gnu/usr.bin/gdb53 removed
distrib/cats/instkernel/Makefile 1.14.6.1
gnu/dist/gdb6/bfd/config.bfd 1.3.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.c 1.1.1.2.6.1
gnu/dist/gdb6/bfd/elfxx-sparc.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/Makefile.in 1.2.2.1.2.2
gnu/dist/gdb6/gdb/alpha-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alpha-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/alphabsd-nat.h 1.1.2.1
gnu/dist/gdb6/gdb/alphabsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphabsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/alphanbsd-nat.c 1.1.2.1
gnu/dist/gdb6/gdb/alphanbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/amd64nbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/amd64nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/arm-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/armbsd-tdep.c 1.1.2.1
gnu/dist/gdb6/gdb/armnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/armnbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure 1.1.1.2.6.1
gnu/dist/gdb6/gdb/configure.ac 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386bsd-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/i386nbsd-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/m68kbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/mipsnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/nbsd-thread.c 1.1.2.3
gnu/dist/gdb6/gdb/ppcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/ppcnbsd-tdep.c 1.3.6.1
gnu/dist/gdb6/gdb/sh-tdep.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/shnbsd-nat.c 1.1.1.2.6.3
gnu/dist/gdb6/gdb/shnbsd-tdep.c 1.1.1.2.6.4
gnu/dist/gdb6/gdb/shnbsd-tdep.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc-nat.c 1.1.1.2.6.1
gnu/dist/gdb6/gdb/sparc64nbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/sparcnbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/tramp-frame.h 1.1.1.2.6.1
gnu/dist/gdb6/gdb/vaxbsd-nat.c 1.1.1.2.6.2
gnu/dist/gdb6/gdb/config/alpha/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/arm/nbsd.mt 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/arm/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/i386/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/m68k/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/mips/nbsd.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/powerpc/nbsd.mh 1.1.1.2.6.1
gnu/dist/gdb6/gdb/config/sh/nbsd.mh 1.1.1.1.6.2
gnu/dist/gdb6/gdb/config/sh/tm-nbsd.h 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsd64.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/sparc/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/gdb/config/vax/nbsdelf.mh 1.1.1.1.6.1
gnu/dist/gdb6/opcodes/configure 1.1.1.2.6.1
gnu/dist/gdb6/opcodes/configure.in 1.1.1.2.6.1
gnu/usr.bin/Makefile 1.126.4.1
gnu/usr.bin/gdb6/arch/alpha/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/alpha/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/init.c 1.2.6.1
gnu/usr.bin/gdb6/arch/alpha/nm.h 1.2.6.1
gnu/usr.bin/gdb6/arch/arm/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/arm/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/defs.mk 1.1.6.3
gnu/usr.bin/gdb6/arch/armeb/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/armeb/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/i386/defs.mk 1.4.4.1
gnu/usr.bin/gdb6/arch/i386/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/m68000/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/m68k/defs.mk 1.1.4.1
gnu/usr.bin/gdb6/arch/m68k/init.c 1.1.4.1
gnu/usr.bin/gdb6/arch/mipseb/config.h 1.3.4.1
gnu/usr.bin/gdb6/arch/mipseb/defs.mk 1.2.6.2
gnu/usr.bin/gdb6/arch/mipseb/init.c 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/config.h 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/defs.mk 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/init.c 1.2.6.3
gnu/usr.bin/gdb6/arch/mipsel/tm.h 1.2.6.2
gnu/usr.bin/gdb6/arch/mipsel/version.c 1.2.6.2
gnu/usr.bin/gdb6/arch/powerpc/defs.mk 1.3.6.1
gnu/usr.bin/gdb6/arch/powerpc/init.c 1.3.6.1
gnu/usr.bin/gdb6/arch/sh3eb/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3eb/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3eb/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3eb/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3eb/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/config.h 1.2.2.2
gnu/usr.bin/gdb6/arch/sh3el/defs.mk 1.2.8.3
gnu/usr.bin/gdb6/arch/sh3el/init.c 1.1.8.3
gnu/usr.bin/gdb6/arch/sh3el/nm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/tm.h 1.1.8.2
gnu/usr.bin/gdb6/arch/sh3el/version.c 1.1.8.2
gnu/usr.bin/gdb6/arch/sparc/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/sparc64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/sparc64/init.c 1.1.6.1
gnu/usr.bin/gdb6/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/init.c 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/tm.h 1.1.6.2
gnu/usr.bin/gdb6/arch/vax/version.c 1.1.6.2
gnu/usr.bin/gdb6/arch/x86_64/defs.mk 1.2.6.1
gnu/usr.bin/gdb6/arch/x86_64/init.c 1.1.6.1
gnu/usr.bin/gdb6/bfd/arch/armeb/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3eb/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfd.h 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/sh3el/bfdver.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/bfd/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/bfd/arch/vax/bfd.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/bfdver.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/bfd/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/gdb/Makefile 1.5.2.1.2.2
gnu/usr.bin/gdb6/gdbtui/Makefile 1.2.6.1
gnu/usr.bin/gdb6/libiberty/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/libiberty/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/libiberty/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3eb/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/opcodes/arch/sh3el/defs.mk 1.1.8.3
gnu/usr.bin/gdb6/opcodes/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/opcodes/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/armeb/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/m68000/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/mipsel/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3eb/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/config.h 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/sh3el/defs.mk 1.1.8.2
gnu/usr.bin/gdb6/readline/arch/vax/config.h 1.1.6.2
gnu/usr.bin/gdb6/readline/arch/vax/defs.mk 1.1.6.2
gnu/usr.bin/gdb6/sim/arch/mipseb/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipseb/defs.mk 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/cconfig.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/config.h 1.1.2.1
gnu/usr.bin/gdb6/sim/arch/mipsel/defs.mk 1.1.2.1
lib/libkvm/kvm_sparc64.c 1.10.18.2
lib/libpthread/pthread.c 1.48.6.4
lib/libpthread/pthread_barrier.c 1.6.18.1
lib/libpthread/pthread_cond.c 1.18.12.2
lib/libpthread/pthread_debug.h 1.8.18.1
lib/libpthread/pthread_int.h 1.34.4.5
lib/libpthread/pthread_lock.c 1.14.6.1
lib/libpthread/pthread_mutex.c 1.22.4.2
lib/libpthread/pthread_run.c 1.18.12.4
lib/libpthread/pthread_rwlock.c 1.13.6.2
lib/libpthread/pthread_sa.c 1.37.6.5
lib/libpthread/pthread_sig.c 1.47.4.8
lib/libpthread/pthread_sleep.c 1.7.6.2
lib/libpthread/sem.c 1.9.6.2
lib/libpthread/arch/sh3/pthread_md.h 1.3.6.1
regress/lib/libpthread/resolv/Makefile 1.1.12.1
regress/lib/libpthread/sigrunning/Makefile 1.1.2.1
regress/lib/libpthread/sigrunning/sigrunning.c 1.1.2.1
share/mk/bsd.own.mk 1.489.4.3
sys/arch/amd64/amd64/locore.S 1.18.14.1
sys/arch/amd64/amd64/machdep.c 1.44.2.3.2.1
sys/arch/amd64/conf/kern.ldscript 1.1.70.1
sys/arch/cats/conf/Makefile.cats.inc 1.17.30.1
sys/arch/shark/conf/Makefile.shark.inc 1.6.30.1
sys/arch/sparc64/conf/kern.ldscript 1.7.26.2
sys/arch/sparc64/conf/kern32.ldscript 1.6.26.2
sys/arch/sparc64/include/kcore.h 1.4.92.2
sys/arch/sparc64/sparc64/locore.s 1.232.4.4
sys/arch/sparc64/sparc64/machdep.c 1.193.4.3
sys/arch/sparc64/sparc64/pmap.c 1.184.2.1.2.4
sys/conf/newvers.sh 1.42.26.2
sys/kern/kern_sa.c 1.87.4.11
sys/kern/kern_synch.c 1.173.4.2
sys/sys/savar.h 1.20.10.2
tools/gdb/Makefile 1.9.4.1
tools/gdb/mknative-gdb 1.1.6.1

pullup the wrstuden-fixsa CVS branch to netbsd-4:
toolchain/35540 - GDB 6 support for pthreads.
port-sparc64/37534 - ktrace firefox gives
kernel trap 30: data access expection
GDB changes:
- delete gdb53
- enable gdb6 on all architectures
- add support for amd64 crash dumps
- add support for sparc64 crash dumps
- add support for /proc pid to executable filename for all archs
- enable thread support for all architectures
- add a note section to kernels to all platforms
- support detection/unwinding of signals for most architectures.
- Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT on sh3.
- Apply fix from binutils-current so that sparc gdb can be cross built
on a 64bit host.
SA/pthread changes:
Pre-allocate memory needed for event delivery. Eliminates dropped
interrupts under load.
Deliver intra-process signals to running threads
Eliminate some deadlock scenarios
Fix intra-process signal delivery when delivering to a thread waiting
for signals. Makes afs work again!
 1.68.2.3  10-Sep-2007  skrll Sync with HEAD.
 1.68.2.2  03-Sep-2007  skrll Sync with HEAD.
 1.68.2.1  15-Aug-2007  skrll Sync with HEAD.
 1.71.2.2  04-Aug-2007  ad Make libpthread_dbg build again.
 1.71.2.1  04-Aug-2007  ad file pthread.c was added on branch matt-mips64 on 2007-08-04 18:54:13 +0000
 1.80.2.3  23-Mar-2008  matt sync with HEAD
 1.80.2.2  09-Jan-2008  matt sync with HEAD
 1.80.2.1  06-Nov-2007  matt sync with HEAD
 1.96.2.1  24-Mar-2008  keiichi sync with head.
 1.99.2.2  04-Jun-2008  yamt sync with head
 1.99.2.1  18-May-2008  yamt sync with head.
 1.100.2.2  18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.100.2.1  23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.106.6.1  13-May-2009  jym Sync with HEAD.

Third (and last) commit. See http://mail-index.netbsd.org/source-changes/2009/05/13/msg221222.html
 1.106.4.2  08-Oct-2008  ad Disable diagnostic assertions by default and just return error codes like
other systems. Allows poorly written applications to appear working. If you
are developing pthread apps please turn it on manually by setting the
environment variable.
 1.106.4.1  08-Oct-2008  ad file pthread.c was added on branch christos-time_t on 2008-10-08 10:03:29 +0000
 1.106.2.5  20-Oct-2013  bouyer Pull up following revision(s) (requested by riastradh in ticket #1881):
lib/libpthread/pthread.c: revision 1.137 via patch
return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
 1.106.2.4  19-May-2012  riz Pull up following revision(s) (requested by enami in ticket #1753):
lib/libpthread/pthread.c: revision 1.134
Store allocated lwpctl state in the thread actually forked,
which is the only thread lives in the child process.
The problem originally reported here:
https://bugs.ruby-lang.org/issues/6341
 1.106.2.3  20-May-2010  snj Pull up following revision(s) (requested by explorer in ticket #1353):
lib/libpthread/pthread.c: revision 1.114, 1.115
Correctly set pt_lid in the child, after a fork
--
fix the pthread pt_lid in the fork callback function that runs in the
child instead of a function that may be going away. KNFify
 1.106.2.2  11-Jan-2010  snj Pull up following revision(s) (requested by christos in ticket #1235):
lib/libpthread/pthread.c: revision 1.113
Don't just look only at the first element in the deadqueue to find lwp's
to reuse, because if we lose the race with the kernel we are never going
to reuse any elements. Look in the whole list instead.
 1.106.2.1  03-Apr-2009  snj branches: 1.106.2.1.4;
Pull up following revision(s) (requested by drochner in ticket #648):
lib/libpthread/pthread.c: revision 1.109
Fix the comparision function used by the red-black tree global thread list
implementation:
-don't return a difference, this can overflow
-don't try to substract typed pointers which don't belong to the
same object, this gives undefined results
This fixes instabilities of programs which use more than a handful
of threads, eg spuriously failing pthread_join().
 1.106.2.1.4.2  20-May-2011  matt bring matt-nb5-mips64 up to date with netbsd-5-1-RELEASE (except compat).
 1.106.2.1.4.1  21-Apr-2010  matt sync to netbsd-5
 1.125.4.4  26-Sep-2013  riz Pull up following revision(s) (requested by riastradh in ticket #959):
lib/libpthread/pthread.c: revision 1.137
return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
 1.125.4.3  29-Apr-2013  riz branches: 1.125.4.3.2;
Pull up following revision(s) (requested by manu in ticket #869):
lib/libpthread/pthread_rwlock.c: revision 1.33
lib/libc/include/reentrant.h: revision 1.16
lib/libpthread/pthread_cond.c: revision 1.59
lib/libpthread/pthread_misc.c: revision 1.15
lib/libc/thread-stub/thread-stub.c: revision 1.23
lib/libpthread/pthread_cancelstub.c: revision 1.38
lib/libpthread/pthread_specific.c: revision 1.26
lib/libpthread/pthread_mutex.c: revision 1.56
lib/libpthread/pthread_tsd.c: revision 1.11
lib/libpthread/Makefile: revision 1.80
lib/libpthread/pthread.c: revision 1.143
lib/libpthread/pthread_int.h: revision 1.89
- Allow libpthread to be dlopened again, by providing libc stubs to
libpthread.
- 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
 1.125.4.2  03-Dec-2012  jdc Apply patch (requested by riastradh in ticket #735) to fix the unchecked
assumption that sizeof(struct __pthread_st) <= pagesize, as observed in
PR 47271.
 1.125.4.1  07-May-2012  riz branches: 1.125.4.1.4;
Pull up following revision(s) (requested by enami in ticket #209):
lib/libpthread/pthread.c: revision 1.134
Store allocated lwpctl state in the thread actually forked,
which is the only thread lives in the child process.
The problem originally reported here:
https://bugs.ruby-lang.org/issues/6341
 1.125.4.3.2.1  26-Sep-2013  riz Pull up following revision(s) (requested by riastradh in ticket #959):
lib/libpthread/pthread.c: revision 1.137
return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
 1.125.4.1.4.1  26-Sep-2013  riz Pull up following revision(s) (requested by riastradh in ticket #959):
lib/libpthread/pthread.c: revision 1.137
return errno if pthread_create hits the system limit, not just -1
(this is not entirely correct because it can return ENOMEM which is
not mentioned in the spec, but there are other places in pthread_create
whete ENOMEM is returned -- it at all, this should be fixed everywhere)
 1.125.2.6  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.125.2.5  23-Jan-2013  yamt sync with head
 1.125.2.4  16-Jan-2013  yamt sync with (a bit old) head
 1.125.2.3  30-Oct-2012  yamt sync with head
 1.125.2.2  23-May-2012  yamt sync with head.
 1.125.2.1  17-Apr-2012  yamt sync with head
 1.137.2.4  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.137.2.3  23-Jun-2013  tls resync from head
 1.137.2.2  25-Feb-2013  tls resync with head
 1.137.2.1  20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.144.4.1  24-Nov-2015  martin Pull up following revision(s) (requested by manu in ticket #829):
lib/libpthread_dbg/pthread_dbg.c: revision 1.43 (via patch)
lib/libpthread/pthread_int.h: revision 1.91-1.92 (via patch)
lib/libc/stdlib/jemalloc.c: revision 1.37-1.38
lib/libpthread/pthread_tsd.c: revision 1.12-1.14 (via patch)
include/limits.h: revision 1.34 (via patch)
lib/libpthread/pthread.c: revision 1.146-1.147 (via patch)
lib/libpthread/pthread_key_create.3: revision 1.7 (via patch)

libpthread:

Make PTHREAD_KEYS_MAX dynamically adjustable
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.

Fix previous: Can't use calloc/malloc before we complete initialization
of the thread library, because malloc uses pthread_foo_specific, and it will
end up initializing itself incorrectly.

Thanks rump for not letting us use even mmap during initialization.

libc/jemalloc:

Fix non _REENTRANT build.
Defer using pthread keys until we are threaded.
From Christos, fixes PR port-arm/50087 by allowing malloc calls prior
to libpthread initialization.
 1.147.8.4  09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1924):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.147.8.3  31-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #234):
sys/arch/amd64/include/vmparam.h: revision 1.43
sys/kern/exec_subr.c: revision 1.79
lib/libpthread/pthread_int.h: revision 1.94
sys/arch/mips/include/vmparam.h: revision 1.58
sys/arch/mips/include/vmparam.h: revision 1.59
lib/libpthread/TODO: revision 1.19
sys/arch/powerpc/include/vmparam.h: revision 1.20
sys/arch/riscv/include/vmparam.h: revision 1.2
sys/arch/riscv/include/vmparam.h: revision 1.3
sys/arch/i386/include/vmparam.h: revision 1.85
tests/lib/libpthread/t_join.c: revision 1.9
sys/uvm/uvm_meter.c: revision 1.66
sys/uvm/uvm_param.h: revision 1.36
sys/kern/exec_subr.c: revision 1.80
sys/uvm/uvm_param.h: revision 1.37
sys/kern/exec_subr.c: revision 1.81
sys/kern/exec_subr.c: revision 1.82
lib/libpthread/pthread_attr_getguardsize.3: revision 1.4
lib/libpthread/pthread.c: revision 1.148
lib/libpthread/pthread_attr.c: revision 1.17
sys/arch/amd64/include/vmparam.h: revision 1.42
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Revert for the moment, creates problems on i386.
Recommit exec_subr.c revision 1.79:
Always include a 1MB guard area beyond the end of stack. While ASLR will
normally create a guard area as well, this provides a deterministic area
for all binaries.
Mitigates the rest of CVE-2017-1000374 and CVE-2017-1000375 from
Qualys.
Additionally, change VM_DEFAULT_ADDRESS_TOPDOWN to include
user_stack_guard_size in the size reservation.
Update VM_DEFAULT_ADDRESS32_TOPDOWN to include guard area.
Export the guard size of the main thread via vm.guard_size. Add a
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.
 1.147.8.2  31-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #232):
lib/libpthread/pthread.c: revision 1.149
Do not look at environmental variables for suid/guid binaries.
 1.147.8.1  29-Aug-2017  bouyer Pull up following revision(s) (requested by joerg in ticket #127):
tests/libexec/ld.elf_so/h_thread_local_dtor.c: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmeb/c++config.h: revision 1.17
lib/libc/stdlib/atexit.h: file removal
lib/libc/stdlib/exit.c: revision 1.16
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc64/c++config.h: revision 1.8
lib/libc/stdlib/exit.c: revision 1.17
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.178
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3el/c++config.h: revision 1.21
distrib/sets/lists/debug/shl.mi: revision 1.179
distrib/sets/lists/debug/mi: revision 1.219
lib/libpthread/pthread.c: revision 1.150
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7/c++config.h: revision 1.14
libexec/ld.elf_so/symbols.map: revision 1.2
include/dlfcn.h: revision 1.25
external/gpl3/gcc/lib/libstdc++-v3/arch/arm/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/x86_64/c++config.h: revision 1.23
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64el/c++config.h: revision 1.18
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earm/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/mipsel/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/ia64/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6eb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhf/c++config.h: revision 1.17
distrib/sets/lists/tests/mi: revision 1.755
external/gpl3/gcc/lib/libstdc++-v3/arch/mips64eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/i386/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/vax/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/armeb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc/c++config.h: revision 1.20
lib/libc/dlfcn/dlfcn_elf.c: revision 1.14
tests/libexec/ld.elf_so/t_thread_local_dtor.sh: revision 1.1
tests/lib/libpthread/t_thread_local_dtor.sh: revision 1.1
lib/libc/stdlib/Makefile.inc: revision 1.93
lib/libc/include/atexit.h: revision 1.1
lib/libc/include/atexit.h: revision 1.2
external/gpl3/gcc/lib/libstdc++-v3/arch/m68k/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hf/c++config.h: revision 1.14
distrib/sets/lists/debug/shl.mi: revision 1.180
external/gpl3/gcc/lib/libstdc++-v3/arch/sparc64/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv6hfeb/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/hppa/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7hfeb/c++config.h: revision 1.14
lib/libc/stdlib/cxa_thread_atexit.c: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/h_helper_dso3.cpp: revision 1.1
tests/libexec/ld.elf_so/helper_dso3/Makefile: revision 1.1
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv64/c++config.h: revision 1.5
libexec/ld.elf_so/rtld.c: revision 1.185
external/gpl3/gcc/lib/libstdc++-v3/arch/sh3eb/c++config.h: revision 1.19
external/gpl3/gcc/lib/libstdc++-v3/arch/riscv32/c++config.h: revision 1.5
external/gpl3/gcc/lib/libstdc++-v3/arch/m68000/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/mipseb/c++config.h: revision 1.21
external/gpl3/gcc/lib/libstdc++-v3/arch/coldfire/c++config.h: revision 1.12
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv4/c++config.h: revision 1.14
external/gpl3/gcc/lib/libstdc++-v3/arch/earmhfeb/c++config.h: revision 1.15
external/gpl3/gcc/lib/libstdc++-v3/arch/alpha/c++config.h: revision 1.19
tests/libexec/ld.elf_so/Makefile: revision 1.9
external/gpl3/gcc/lib/libstdc++-v3/arch/powerpc/c++config.h: revision 1.20
external/gpl3/gcc/lib/libstdc++-v3/arch/earmv7eb/c++config.h: revision 1.14
tests/lib/libpthread/h_thread_local_dtor.cpp: revision 1.1
distrib/sets/lists/tests/shl.mi: revision 1.11
tests/lib/libpthread/Makefile: revision 1.13
libexec/ld.elf_so/rtld.h: revision 1.129
external/gpl3/gcc/lib/libstdc++-v3/arch/or1k/c++config.h: revision 1.6
Implement __cxa_thread_atexit and __cxa_thread_atexit_impl. This
functions are used for destructors of thread_local objects.
If a pending destructor exists, prevent unloading of shared objects.
Introduce __dl_cxa_refcount interface for this purpose. When the last
reference is gone and the object has been dlclose'd before, the
unloading is finalized.
Ideally, __cxa_thread_atexit_impl wouldn't exist, but libstdc++ insists
on providing __cxa_thread_atexit as direct wrapper without further
patching.
Fix filename of new debug file
Add misising DEBUGLIB file
Avoid common declaration.
Drop TLS variant checks, emutls is enough for VAX and Sun2.
 1.151.4.3  21-Apr-2020  martin Sync with HEAD
 1.151.4.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.151.4.1  10-Jun-2019  christos Sync with HEAD
 1.151.2.1  06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.153.2.3  09-Dec-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1775):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721
 1.153.2.2  08-Aug-2022  martin Apply patch, requested by riastradh in ticket #1498:

lib/libpthread/pthread.c 1.181 (via patch)

libpthread(3): Fix a marvellous interaction with rtld.

Patch from chs@. Comment explaining the story by me. This patch may
not be optimal -- maybe it would be better in pthread__init, or
better for rtld to call _lwp_unpark after _lwp_park in the contened
case -- but we've tested this version and it's annoying to reproduce,
so let's take this version and worry about testing improvements
later.
 1.153.2.1  26-Jan-2020  martin Pull up following revision(s) (requested by ad in ticket #647):

lib/libpthread/pthread_rwlock.c: revision 1.37 (patch)
lib/libpthread/pthread_misc.c: revision 1.16
lib/libpthread/pthread.c: revision 1.154
lib/libpthread/pthread_int.h: revision 1.98
lib/libpthread/pthread_cond.c: revision 1.66
lib/libpthread/pthread_mutex.c: revision 1.66

Rip out some very ambitious optimisations around pthread_mutex that are
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.
 1.181.2.3  20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #757):

lib/libpthread/pthread.c: revision 1.182

Use snprintf_ss in pthread__assertfunc and update comment in
pthread__errorfunc. snprintf can use locks in some code paths and we
only care about the restricted subset here.
 1.181.2.2  20-Jun-2024  martin Pull up following revision(s) (requested by hannken in ticket #711):

lib/libpthread/pthread.c: revision 1.185

Fix resource leak in pthread_create(). Pthread field "pt_lwpctl"
must not be accessed after _lwp_exit() as the kernel may free
it, attach it to another thread and change its "lc_curcpu".

The "pthread__deadqueue" will fill up with pthreads with
an invalid "pt_lwpctl" and allocated stack that never get
reused.

Replace the test "lc_curcpu == LWPCTL_CPU_EXITED" with
test "_lwp_kill(newthread->pt_lid, 0) == -1 && errno == ESRCH"
to make sure this thread has finished its _lwp_exit().

PR lib/57831 "Memory leaks in libpthread/libc"
 1.181.2.1  28-Nov-2023  martin Pull up following revision(s) (requested by riastradh in ticket #478):

tests/lib/libpthread/Makefile: revision 1.16
lib/libpthread/pthread.c: revision 1.184
distrib/sets/lists/debug/mi: revision 1.424
distrib/sets/lists/tests/mi: revision 1.1297
tests/lib/libpthread/t_stack.c: revision 1.1
tests/lib/libpthread/t_stack.c: revision 1.2
tests/lib/libpthread/t_stack.c: revision 1.3
tests/lib/libpthread/t_stack.c: revision 1.4
tests/lib/libpthread/t_stack.c: revision 1.5
tests/lib/libpthread/t_stack.c: revision 1.6

pthread: Add tests for pthread user stack allocation.
PR lib/57721

libpthread/t_stack: Make this more robust to the guard size bug.
Make sure to allocate enough space for the thread's stack for a guard
even though there shouldn't be one, so that when we run the thread,
it doesn't start with the stack pointer pointing into someone else's
allocation (like malloc) causing stack frames to trash another data
structure -- or causing the user of that data structure to trash the
stack frames.
PR lib/57721

libpthread/t_stack: Omit needless cast in previous.
Arose from an earlier draft of the change.
PR lib/57721

libpthread/t_stack: Appease gcc12 maybe-uninitialized warning.
The jmp_buf is not, in fact, uninitialized at the point of use, but
it doesn't hurt to narrow the scope a bit to between when the jmp_buf
is initialized by setjmp, and when the signal handler might be called
after sigaction.
Noted by prlw1.
PR lib/57721

libpthread/t_stack: Fix format string for size_t.
Tested this on i386 since that had been crashing before, but i386
doesn't see %zu for unsigned int as a problem.
PR lib/57721

pthread: Don't adjust user-allocated stack addresses by guardsize.
PR lib/57721

RSS XML Feed