Home | History | Annotate | only in /src/lib/libpthread
History log of /src/lib/libpthread
RevisionDateAuthorComments
 1.2 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.1 20-Dec-1993  proven Copyrights added to each file.
 1.100 07-Apr-2025  rillig libpthread: fix lint build
 1.99 22-Nov-2024  riastradh libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.98 14-Sep-2023  rin branches: 1.98.2;
libpthread/Makefile: trailing whitespace
 1.97 14-Jul-2023  lukem fix rump URLs

Link to https://github.com/rumpkernel/ instead of
a site now taken over by an SEO squatter.

Per discussion on github.com/rumpkernel issues with pooka.

PR misc/57501
 1.96 11-Nov-2019  joerg branches: 1.96.8;
Update LLVM to 10.0.0git (01f3a59fb3e2542fce74c768718f594d0debd0da)
 1.95 22-Sep-2019  brad Add USE_SHLIBDIR=yes to a number of Makefiles for the libraries used
by /sbin/{zfs,zpool,mount_zfs}. The general effect is to move them
from /usr/lib to /lib. Compatibility links are installed in /usr/lib
and nothing that is installed, say in /usr/pkg, appears to break.

With this, it is possible to have a /var and /usr mount using ZFS
legacy mounting early on in the boot process.

Run tested on amd64 and i386 and compile tested on evbarm.
 1.94 07-May-2019  maya branches: 1.94.2;
Make CLEANFILES actually work. .TARGET is not defined when not in a target
rule.

Thanks xtos for the heads up.
 1.93 07-May-2019  maya Replace the link command for libpthread.a so that we create a single section
with all the libpthread symbols in it.
This makes -lpthread behave like to -Wl,--whole-archive -lpthread.

This avoids a situation where threaded static binaries use some libc thread
stubs, which are racy.

Fixes PR lib/54001: call_once2_32, call_once2_static test cases failing on
amd64 since gcc7 import.

Suggested by Jonathan Wakely, thanks!
 1.92 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.91 03-Feb-2019  thorpej Implement support for "pshared" POSIX semaphores.

Fixes lib/53273 (and Firefox's multi-process tab feature).
 1.90 09-Jun-2018  christos branches: 1.90.2;
But set NOSANITIZER
 1.89 09-Jun-2018  christos We can't build those three with MKSANITIZER, they are used too early.
 1.88 25-Feb-2018  chs branches: 1.88.2;
remove hard-coded -fomit-frame-pointer for pthread stuff,
let these use the same setting as the rest of the tree.
the performance difference is marginal and this allows
dtrace ustack() to work better.
 1.87 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.86 23-Apr-2016  christos Add pthread_getcpuclockid(3)
 1.85 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.84 10-Aug-2014  matt MKCOMPAT fixes for when compat MACHINE_CPU != normal MACHINE_CPU
 1.83 09-Oct-2013  matt Use MACHINE_CPU for m68k. Use similar logic for both tests.
 1.82 15-Aug-2013  matt Add support for an optional ARCHSUBDIR/Makefile.inc
 1.81 12-Aug-2013  joerg Some architectures can't create unwind tables without the frame pointer,
so don't use -fomit-frame-pointer on those.
 1.80 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.79 25-Feb-2013  apb Explain what PTHREAD__COMPAT is for. This comment in
src/libpthread/Makefile is adated from a comment in
src/doc/CHANGES.prev.
 1.78 31-Jan-2013  riastradh Add pthread_condattr_setclock(3) man page link.
 1.77 04-Aug-2012  matt branches: 1.77.2;
-Wfoo goes into CWARNFLAGS
 1.76 04-Apr-2012  joerg Disable new -Wstring-plus-int warning where needed for now.
Adjust various places that add GCC-only options to check for the active
compiler first.
 1.75 21-Mar-2012  matt These directories default to WARNS?=5
 1.74 12-Mar-2012  joerg Move pthread_once implementation into a separate file, it doesn't depend
on the mutex implementation in any way.
 1.73 10-Nov-2011  yamt branches: 1.73.2;
document pthread_curcpu_np
 1.72 16-Aug-2011  christos branches: 1.72.2;
document non-literal format strings
 1.71 24-Dec-2010  skrll Add support for DF_1_BIND_NOW, DF_1_NODELETE and DF_1_NOOPEN marked
objects, and the RTLD_NODELETE and RTLD_NOLOAD flags to dlopen(3).

Mark libpthread as DF_1_NOOPEN and use it to test the functionality.

Somewhat taken from FreeBSD.

Fixes PR 42029.

OK from christos and joerg.
 1.70 06-Aug-2010  christos document pthread_getattr_np
 1.69 09-Jul-2010  jruoho Rationalize by moving

pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
 1.68 09-Jul-2010  jruoho Rationalize by moving

pthread_attr_setname_np(3) to pthread_attr_getname_np(3); and
pthread_setname_np(3) to pthread_getname_np(3).
 1.67 08-Jul-2010  jruoho Group also pthread_attr_getschedparam(3) and pthread_attr_getschedpolicy(3),
as these two pages fit well together.
 1.66 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.65 07-Jul-2010  jruoho Finally, split pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy()
to their own page.
 1.64 07-Jul-2010  jruoho Split pthread_attr_getschedparam() and pthread_attr_setschedparam() to a
separate page.
 1.63 07-Jul-2010  jruoho Split pthread_attr_getinheritsched() and pthread_attr_setinheritsched() to a
separate page, and actually document these.
 1.62 07-Jul-2010  jruoho Move pthread_attr_getguardsize() and pthread_attr_setguardsize() to a
separate page, and actually document these.
 1.61 07-Jul-2010  jruoho Move the thread stack attribute functions to a separate page. In addition,
document pthread_attr_getstack() and pthread_attr_setstack(). Try to also
document these a little better (in particular, note some items in the long
list of caveats and questions related to application-controlled thread stack).
 1.60 07-Jul-2010  jruoho Split pthread_attr_getdetachstate(3) and pthread_attr_setdetachstate(3) to a
separate page. Once ready, the main page, pthread_attr(3), will contain a
summary of the various thread attribute functions.
 1.59 07-Jul-2010  jruoho Move pthread_attr_{g,s}etscope() to a separate page and try to document
these better. Should fix PR lib/41831 from Wolfgang Stukenbrock.

XXX: Please proofread.
 1.58 06-Jul-2010  jruoho Document pthread_attr_get_np(). Fixes PR lib/39289 from ahoka@.
 1.57 19-May-2010  jruoho Build links for rest of the pthread_attr(3) functions.
Hopefully I got all of them right in the setlist...
 1.56 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.55 26-Oct-2008  mrg branches: 1.55.4;
check for ${PTHREAD_MACHINE_ARCH} before ${MACHINE_ARCH} or ${MACHINE_CPU}
 1.54 08-Oct-2008  ad Adjust the compat stuff slightly so that the changes are mostly self
contained (Makefile, pthread_compat.c).
 1.53 29-Sep-2008  ad make PTHREAD__COMPAT=1

Builds a libpthread that can be dropped into a NetBSD 2/3/4 chroot.

This makes threading work in the chroot when using a NetBSD 5 kernel, no
other modifications required.
 1.52 16-Jun-2008  rmind - Add affinity(3) manual page, which describes thread affinity,
pthread_setaffinity_np(3) and pthread_getaffinity_np(3) functions,
provides simple code example.
- Add cpuset(3) manual page, which describes API of CPU-sets.

Thanks <wiz> for many improvements!
 1.51 10-Mar-2008  rmind branches: 1.51.2; 1.51.4;
Add sched(3) manual page, and appropriate links.
Thanks <wiz> for review and fixes!
 1.50 10-Feb-2008  ad branches: 1.50.2;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.49 15-Jan-2008  rmind Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
 1.48 14-Dec-2007  yamt document following functions.
pthread_attr_getname_np
pthread_attr_setname_np
pthread_getname_np
pthread_setname_np
 1.47 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.46 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.45 13-Oct-2007  jnemeth SSP doesn't like alloca...
 1.44 04-Oct-2007  ad Compile pthread_getspecific / pthread_setspecific with -fomit-frame-pointer
-falign-functions=32, since these two really get hammered on. To make them
faster needs a threadreg or TLS, unless there is a way to tell gcc that a
library-local (pthread__threadmask) variable does not need to be PIC.
 1.43 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.42 16-Aug-2007  ad branches: 1.42.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.41 16-Aug-2007  ad Remove PT_FIXEDSTACKSIZE_LG.
 1.40 02-Mar-2007  ad branches: 1.40.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.39 09-Feb-2007  ad Sync with kernel changes introduced by merging the newlock2 branch.
 1.38 20-Jan-2007  christos set warns to 4
 1.37 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.36 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.35 13-Dec-2005  christos include libc after our own files to fix ports that have 2 assym.h's. One
in pthread and one in libc.
 1.34 13-Sep-2005  christos XXX: Work around libpthread's "intimate" connection with libc.
 1.33 17-Jun-2005  peter Create links for pthread_attr_setschedparam.3
and pthread_attr_getschedparam.3 to pthread_attr.3.

From Igor Sobrado in PR/29997.
 1.32 17-Jun-2005  peter Don't create links to pthread_barierattr_init.3 and
pthread_barierattr_destroy.3 but to pthread_barrierattr_init.3
and pthread_barrierattr_destroy.3 (note the 2 rs in barrier).
 1.31 30-May-2005  thorpej Use TOOL_GENASSYM. Part of PR toolchain/30350
 1.30 03-Feb-2005  christos branches: 1.30.2;
Add charles' mlock fixes, protected with PTHREAD_MLOCK_KLUDGE and enabled
by default, until we come up with a real fix.
 1.29 14-Dec-2004  yamt document sched_yield.
 1.28 10-Dec-2004  nathanw Use CPP macros to cause many libpthread functions used by applications
to be transformed into the do-nothing-when-libpthread-isn't-linked libc
stub names. This will permit library code that uses <pthread.h> and pthread
functions "defensively" to not need to link against libpthread and not need
to be patched to the threadlib.h API.
 1.27 02-Jun-2004  pooka pthread_spin_lock.3 also describes pthread_spin_trylock(),
so link them together
 1.26 21-May-2004  christos add pool code for res state.
XXX: could be more efficient.
 1.25 02-Jan-2004  lukem branches: 1.25.4;
Add dependencies to assym.h on:
pthread.h pthread_int.h pthread_md.h
Should help prevent the problem I raised in [kern/23946], based on
a hint from Christian Limpach.

Add MAKEVERBOSE support.
 1.24 27-Nov-2003  cl Set default stack size to the current limit on the stack size as set
with the shell's command to change limits. Make the PTHREAD_STACKSIZE
environment variable override the default stack size. The old fixed
stack size behaviour can be enable with PT_FIXEDSTACKSIZE_LG when building
libpthread.
 1.23 12-Nov-2003  christos Document pthread_attr_setcreatesuspend_np, pthread_suspend_np, pthread_resume_np
 1.22 26-Oct-2003  lukem Use ${HOST_SH} instead of `sh'.

If necessary, pull in <bsd.sys.mk> to get the definition of HOST_SH;
Makefiles that pull in one of (most of) <bsd.*.mk> will get this anyway.
 1.21 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.20 01-Aug-2003  lukem Rework how dependency generation is performed:

* DPSRCS contains extra dependencies, but is _NOT_ added to CLEANFILES.
This is a change of behaviour. If a Makefile wants the clean semantics
it must specifically append to CLEANFILES.
Resolves PR toolchain/5204.

* To recap: .d (depend) files are generated for all files in SRCS and DPSRCS
that have a suffix of: .c .m .s .S .C .cc .cpp .cxx

* If YHEADER is set, automatically add the .y->.h to DPSRCS & CLEANFILES

* Ensure that ${OBJS} ${POBJS} ${LOBJS} ${SOBJS} *.d depend upon ${DPSRCS}

* Deprecate the (short lived) DEPENDSRCS


Update the various Makefiles to these new semantics; generally either
adding to CLEANFILES (because DPSRCS doesn't do that anymore), or replacing
specific .o dependencies with DPSRCS entries.

Tested with "make -j 8 distribution" and "make distribution".
 1.19 24-Jul-2003  wiz Add pthread(3), based on one by Hubert Feyrer, improved by yours truly,
reviewed by Nathan J. Williams.
 1.18 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.17 03-Jun-2003  nathanw Make infrastructure for man pages.
 1.16 10-Mar-2003  nathanw Re-enable nanosleep(); kernel bug is squished (kern_time.c:1.67).
 1.15 28-Feb-2003  nathanw Disable userlevel nanosleep() until I find the timer/alarm bug that it
is tickling.
 1.14 15-Feb-2003  nathanw Implement nanosleep() at userlevel. Threaded applications seem to like
to sleep a lot, and there's no need for each such thread to consume kernel
resources.

(accidentally checked the pthread.c part of this in yesterday; no reason
not to finish the job)
 1.13 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.12 21-Jan-2003  christos add manual pages.
 1.11 20-Jan-2003  christos add support for p1003.1b semaphores. From FreeBSD
 1.10 19-Jan-2003  thorpej Always allow includes to be installed. This makes it easier for
people to get straggling ports bootstrapped (pthread.h is required
in order to build libc).
 1.9 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.8 08-Oct-1997  scottr branches: 1.8.2;
This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.7 07-Feb-1994  proven The latest pthread library.
 1.6 22-Nov-1993  proven Fix for older shells that can't handle then;
 1.5 16-Nov-1993  proven Added NOPIC flag.
 1.4 15-Nov-1993  cgd correct my bad advice
 1.3 15-Nov-1993  proven OK one more try at getting it right ...
 1.2 15-Nov-1993  proven Makefile needed a preall to make a few links before compiling sources.
CVS doesn't check in symlinks.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.8.2.21 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.8.2.20 07-Jan-2003  thorpej Implement the pthread_barrier API.
 1.8.2.19 28-Oct-2002  nathanw Implement POSIX read-write locks.
 1.8.2.18 07-Oct-2002  thorpej Slight adjustment to last -- Only bring in <bsd.lib.mk> if LIB is
defined, and bring in <bsd.man.mk> otherwise.
 1.8.2.17 07-Oct-2002  thorpej Issue a warning, but to not error out (just skip it) if we don't
yet have pthread support for the platform we're building on.
 1.8.2.16 14-Aug-2002  nathanw Infrastructure for machine-dependent init code.
 1.8.2.15 03-May-2002  nathanw Remove accidentally committed variables.
 1.8.2.14 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.8.2.13 11-Apr-2002  thorpej This file is exactly the same as include/sched.h; don't bother with
the second copy.
 1.8.2.12 11-Apr-2002  nathanw Add "hard" stubs for libc interface. Weak aliases didn't work so well.
 1.8.2.11 04-Apr-2002  nathanw Remove an unnecessary bit of variable indirection.
 1.8.2.10 28-Jan-2002  nathanw Add new files.
 1.8.2.9 16-Nov-2001  thorpej Need bsd.own.mk early due to variable expansion rules and the use
of .if exists...
 1.8.2.8 06-Sep-2001  nathanw Add dependancies on assym.h, so that "make depend" is not strictly necessary.
 1.8.2.7 08-Aug-2001  nathanw Implement thread-specific data.
 1.8.2.6 25-Jul-2001  nathanw WARNS=2
 1.8.2.5 25-Jul-2001  nathanw Implement most of condition variables
(pthread_cond_timedwait() is not yet done).
 1.8.2.4 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.8.2.3 13-Jul-2001  nathanw Make userlevel-only *context functions part of libpthread rather than libc.
 1.8.2.2 13-Jul-2001  nathanw Add the new headers.
 1.8.2.1 08-Mar-2001  nathanw Forgot this file, somehow.
 1.25.4.1 21-Jun-2005  riz Pull up revision 1.32 (requested by peter in ticket #2002):
Don't create links to pthread_barierattr_init.3 and
pthread_barierattr_destroy.3 but to pthread_barrierattr_init.3
and pthread_barrierattr_destroy.3 (note the 2 rs in barrier).
 1.30.2.2 18-Jun-2005  tron Pull up revision 1.33 (requested by peter in ticket #473):
Create links for pthread_attr_setschedparam.3
and pthread_attr_getschedparam.3 to pthread_attr.3.
From Igor Sobrado in PR/29997.
 1.30.2.1 18-Jun-2005  tron Pull up revision 1.32 (requested by peter in ticket #473):
Don't create links to pthread_barierattr_init.3 and
pthread_barierattr_destroy.3 but to pthread_barrierattr_init.3
and pthread_barrierattr_destroy.3 (note the 2 rs in barrier).
 1.40.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.40.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.42.2.3 23-Mar-2008  matt sync with HEAD
 1.42.2.2 09-Jan-2008  matt sync with HEAD
 1.42.2.1 06-Nov-2007  matt sync with HEAD
 1.50.2.1 24-Mar-2008  keiichi sync with head.
 1.51.4.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.51.2.1 17-Jun-2008  yamt sync with head.
 1.55.4.2 26-Oct-2008  mrg check for ${PTHREAD_MACHINE_ARCH} before ${MACHINE_ARCH} or ${MACHINE_CPU}
 1.55.4.1 26-Oct-2008  mrg file Makefile was added on branch christos-time_t on 2008-10-26 00:00:28 +0000
 1.72.2.3 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.72.2.2 30-Oct-2012  yamt sync with head
 1.72.2.1 17-Apr-2012  yamt sync with head
 1.73.2.1 29-Apr-2013  riz 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.77.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.77.2.2 23-Jun-2013  tls resync from head
 1.77.2.1 25-Feb-2013  tls resync with head
 1.88.2.1 25-Jun-2018  pgoyette Sync with HEAD
 1.90.2.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.90.2.1 10-Jun-2019  christos Sync with HEAD
 1.94.2.1 27-Sep-2019  martin Pull up following revision(s) (requested by brad in ticket #252):

external/cddl/osnet/lib/libzpool/Makefile: revision 1.13
lib/libpthread/Makefile: revision 1.95
external/cddl/osnet/lib/libuutil/Makefile: revision 1.6
distrib/sets/lists/base/shl.mi: revision 1.871
external/cddl/osnet/lib/libzfs_core/Makefile: revision 1.2
external/cddl/osnet/lib/libnvpair/Makefile: revision 1.11
external/cddl/osnet/lib/libzfs/Makefile: revision 1.10
external/cddl/osnet/lib/libavl/Makefile: revision 1.6
distrib/sets/lists/debug/shl.mi: revision 1.230
external/cddl/osnet/lib/libumem/Makefile: revision 1.7

Add USE_SHLIBDIR=yes to a number of Makefiles for the libraries used
by /sbin/{zfs,zpool,mount_zfs}. The general effect is to move them
from /usr/lib to /lib. Compatibility links are installed in /usr/lib
and nothing that is installed, say in /usr/pkg, appears to break.

With this, it is possible to have a /var and /usr mount using ZFS
legacy mounting early on in the boot process.
Run tested on amd64 and i386 and compile tested on evbarm.

Fix MKDEBUG distrib sets
Add libpthread, libnvpair and ZFS libs to dynamicroot.
 1.96.8.1 20-Sep-2024  martin Pull up following revision(s) (requested by rin in ticket #889):

lib/librumpuser/configure.ac: revision 1.6
lib/librumpuser/rumpuser_port.h: revision 1.53
lib/libpthread/Makefile: revision 1.97
sys/rump/share/man/man3/rumpuser.3: revision 1.4
sys/rump/share/man/man7/rumpkernel.7: revision 1.4
sys/rump/share/man/man7/rumpkernel.7: revision 1.5

fix rump URLs in man pages

Link to https://github.com/rumpkernel/wiki/wiki instead of
a site now taken over by an SEO squatter.
Per discussion on github.com/rumpkernel issues
with pooka.
PR misc/57501

fix rump URLs
Link to https://github.com/rumpkernel/ instead of
a site now taken over by an SEO squatter.
Per discussion on github.com/rumpkernel issues with pooka.
PR misc/57501

use rumpkernel.github.io as the entry point
 1.98.2.1 02-Aug-2025  perseant Sync with HEAD
 1.7 08-Feb-2017  kamil libpthread_dbg(3) deletion from the base distribution

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>
 1.6 16-Apr-2009  wiz branches: 1.6.28; 1.6.32;
Add CAVEATS section:
Due to limitations in the current pthread implementation, makecontext(3)
and sigaltstack(2) should not be used in programs which link against
libpthread (whether threads are used or not).

Wording from drochner@ and ad@

Bump date for man pages.

Add note in libpthread/README so it's not forgotten to update the man
pages when the problem is fixed.
 1.5 16-Oct-2007  ad branches: 1.5.2; 1.5.18;
Note that libpthread_dbg needs to be checked after making changes to
libpthread.
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 07-Feb-1994  proven The latest pthread library.
 1.2 15-Nov-1993  proven Makefile needed a preall to make a few links before compiling sources.
CVS doesn't check in symlinks.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.5.18.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.5.2.2 06-Nov-2007  matt sync with HEAD
 1.5.2.1 16-Oct-2007  matt file README was added on branch matt-armv6 on 2007-11-06 23:11:38 +0000
 1.6.32.1 21-Apr-2017  bouyer Sync with HEAD
 1.6.28.1 20-Mar-2017  pgoyette Sync with HEAD
 1.19 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.18 08-Feb-2017  kamil branches: 1.18.4;
libpthread_dbg(3) deletion from the base distribution

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>
 1.17 03-Feb-2012  joerg branches: 1.17.22; 1.17.26;
ld.elf_so is reentrant.
 1.16 09-Jul-2010  jruoho branches: 1.16.6;
As per (now closed) PR lib/43581, add a note about unsupported modifications
to the red zone size.
 1.15 24-Jan-2009  wiz Fix typo.
 1.14 10-Feb-2008  ad We've got the priority/class stuff now.
 1.13 24-Dec-2007  ad Update.
 1.12 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.11 08-Sep-2007  ad Update.
 1.10 23-Aug-2007  ad branches: 1.10.2;
Update.
 1.9 04-Aug-2007  ad branches: 1.9.2;
Update.
 1.8 02-Mar-2007  ad branches: 1.8.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.7 02-Mar-2007  ad Don't grab the state lock to check for cancellation around condition
variables, as _lwp_wakeup/lwp_park provide the necessary barrier.
 1.6 15-Feb-2007  yamt fix a race between pthread_exit and pthread_create.
inefficient, but better than crashing.
 1.5 25-Dec-2006  ad Add some items for 1:1 threads.
 1.4 25-Nov-2003  christos Update list of items.
 1.3 06-Feb-2003  jdolecek pthread_kill() was implemented, remove from list
pthread_cond_timedwait() now works even before SA initialization, but some
other routines do not; update the paragraph for this
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file TODO was initially added on branch nathanw_sa.
 1.1.2.19 13-Jan-2003  thorpej Implement recursive and errorcheck mutexes.
 1.1.2.18 07-Jan-2003  thorpej In the "ideas to play with" section, make a note about registers
reserved by the ABI for thread-specific data.
 1.1.2.17 30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.16 30-Oct-2002  skrll Nathan added pthread_rwlock.c
 1.1.2.15 02-Oct-2002  thorpej One more signal-reliated item.
 1.1.2.14 02-Oct-2002  thorpej libc:
Internally rename __sigaction14 to __libc_sigaction14. Provide a
weak alias of __sigaction14 -> __libc_sigaction14.

libpthread:
Use __libc_sigaction14 to actually register the signal handler, rather
than using __sigaction_sigtramp() directly with a hard-coded trampoline
version. While we don't actually use the libc trampoline, we want to
avoid depending on any COMPAT_* kernel options down the road (this is
already the case for the VAX port).

Be explicit about which version of the signal interface we're interposing
(...14), and build pthread_sig.c with __LIBC12_SOURCE__ (required to get
the libc-internal interfaces).
 1.1.2.13 02-Oct-2002  thorpej ...and another.
 1.1.2.12 02-Oct-2002  thorpej Add another item to the "bugs to fix" list.
 1.1.2.11 02-Oct-2002  thorpej Add some TODO items.
 1.1.2.10 25-Mar-2002  nathanw Remove a couple of fixed items.
 1.1.2.9 28-Jan-2002  nathanw Update a bit.
 1.1.2.8 16-Nov-2001  thorpej Note that real flockfile()/funclockfile()/ftrylockfile() routines
need to be written.
 1.1.2.7 08-Aug-2001  nathanw pthread_malloc() and pthread_free() are superfluous.
 1.1.2.6 08-Aug-2001  nathanw Fixed one.
 1.1.2.5 08-Aug-2001  nathanw Another open issue.
 1.1.2.4 07-Aug-2001  nathanw Add a bug I don't feel like fixing tonight.
 1.1.2.3 06-Aug-2001  nathanw Update and reorganize.
 1.1.2.2 08-Mar-2001  nathanw Couple more things.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.8.2.3 10-Sep-2007  skrll Sync with HEAD.
 1.8.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.8.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.9.2.2 04-Aug-2007  ad Update.
 1.9.2.1 04-Aug-2007  ad file TODO was added on branch matt-mips64 on 2007-08-04 13:46:05 +0000
 1.10.2.3 23-Mar-2008  matt sync with HEAD
 1.10.2.2 09-Jan-2008  matt sync with HEAD
 1.10.2.1 06-Nov-2007  matt sync with HEAD
 1.16.6.1 17-Apr-2012  yamt sync with head
 1.17.26.1 21-Apr-2017  bouyer Sync with HEAD
 1.17.22.1 20-Mar-2017  pgoyette Sync with HEAD
 1.18.4.1 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.1 31-Mar-2013  agc branches: 1.1.2;
file Version.map was initially added on branch agc-symver.
 1.1.2.1 31-Mar-2013  agc add symbol versioning information for libpthread
 1.10 25-Feb-2025  riastradh libpthread/affinity.3: Fix error reporting in example.

pthread_setaffinity_np does not set errno, so err(...) is wrong.
Instead, it returns the error number, which requires either
errc(..., error, ...) or errno = error; err(...).
 1.9 21-Feb-2025  wiz slightly expand example
 1.8 05-Dec-2011  wiz branches: 1.8.52;
Do not xref to itself.
 1.7 04-Dec-2011  jym Improvements in secmodel(9). Document secmodel_register(9), _deregister(9)
and _eval(9).

Add secmodel_extensions(9), and indicate the new sysctl(7) to let
ordinary users control the CPU affinity (user_set_cpu_affinity).
 1.6 09-Jul-2010  wiz branches: 1.6.6;
Sort sections.
 1.5 09-Jul-2010  jruoho Add a compatibility note. Also some minor improvements.
 1.4 20-Jan-2009  rmind - Make thread-affinity and processor-set interfaces mutually exlusive.
- pset_assign: when CPU is assigned, migrate out all LWPs from it.
 1.3 18-Oct-2008  rmind branches: 1.3.2; 1.3.4;
Do not recommend to mix affinity(3) with pset(3).
 1.2 12-Sep-2008  rmind Arguments were swapped for cpuset_set(), cpuset_clr(), cpuset_isset()
functions, but man pages were not updated (hi Christos!).
 1.1 16-Jun-2008  rmind branches: 1.1.2; 1.1.4;
- Add affinity(3) manual page, which describes thread affinity,
pthread_setaffinity_np(3) and pthread_getaffinity_np(3) functions,
provides simple code example.
- Add cpuset(3) manual page, which describes API of CPU-sets.

Thanks <wiz> for many improvements!
 1.1.4.3 24-Sep-2008  wrstuden Merge in changes between wrstuden-revivesa-base-2 and
wrstuden-revivesa-base-3.
 1.1.4.2 23-Jun-2008  wrstuden Add files to branch that were added on -current.

After this, all that's left of update is to merge some changes
that had conflicts.
 1.1.4.1 16-Jun-2008  wrstuden file affinity.3 was added on branch wrstuden-revivesa on 2008-06-23 05:02:11 +0000
 1.1.2.2 17-Jun-2008  yamt sync with head.
 1.1.2.1 16-Jun-2008  yamt file affinity.3 was added on branch yamt-pf42 on 2008-06-17 09:13:39 +0000
 1.3.4.2 18-Oct-2008  rmind Do not recommend to mix affinity(3) with pset(3).
 1.3.4.1 18-Oct-2008  rmind file affinity.3 was added on branch christos-time_t on 2008-10-18 03:37:42 +0000
 1.3.2.1 22-Jan-2009  snj Pull up following revision(s) (requested by rmind in ticket #291):
lib/libpthread/affinity.3: revision 1.4
lib/librt/pset.3: revision 1.8
sys/kern/sys_pset.c: revision 1.10
sys/kern/sys_sched.c: revision 1.32
- Make thread-affinity and processor-set interfaces mutually exlusive.
- pset_assign: when CPU is assigned, migrate out all LWPs from it.
 1.6.6.1 17-Apr-2012  yamt sync with head
 1.8.52.1 02-Aug-2025  perseant Sync with HEAD
 1.2 27-Apr-2019  wiz branches: 1.2.2;
Fix some typos, improve wording.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 27-Apr-2019  christos file call_once.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.2 24-Apr-2019  kamil branches: 1.2.2;
Drop error path from C11 call_once

The original implementation of C11 threads(3) contained check for error
paths, but it was stripped in the calls that are documented to return
no status from an operation. Do the same in call_once(3).
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 24-Apr-2019  christos file call_once.c was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.3 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.2 27-Apr-2019  wiz branches: 1.2.2; 1.2.14;
Fix some typos, improve wording.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.14.1 02-Aug-2025  perseant Sync with HEAD
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 27-Apr-2019  christos file cnd.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file cnd.c was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.8 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.7 02-Mar-2007  ad branches: 1.7.6;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 14-Dec-2006  ad Set _IOLBF on stdout.
 1.5 20-Aug-2003  martin Include <stdlib.h> for exit() prototype.
 1.4 25-Jun-2003  nathanw More printf format size tweaks.
 1.3 27-Jan-2003  nathanw printf format fixes.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 17-Jul-2001  nathanw branches: 1.1.2;
file debuglog.c was initially added on branch nathanw_sa.
 1.1.2.4 20-May-2002  nathanw Add a way to dump the raw debuglog.

Use fwrite() instead of printf() so that we get the entire log if,
somehow, there is a NUL in the log.

Add a flag to keep the log and not update the read pointer.
 1.1.2.3 31-Jul-2001  nathanw Use the new "force" argument to pthread__debuglog_init(), and remove the
copy of the buffer-initialization code.
 1.1.2.2 24-Jul-2001  nathanw Instead of always doing the equivalent of tail -f on the log, add a -f
option to do that and make the default simply to display the log.
Add a -i option to initialize (clear) the log.
Oh, and add getopt framework and usage().
 1.1.2.1 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.7.6.1 09-Jan-2008  matt sync with HEAD
 1.4 30-May-2005  thorpej Use TOOL_GENASSYM. Part of PR toolchain/30350
 1.3 15-Dec-2003  jmc Clean up tmp files on exit. Fixes PR#23723
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file genassym.sh was initially added on branch nathanw_sa.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.3 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.2 27-Apr-2019  wiz branches: 1.2.2; 1.2.14;
Fix some typos, improve wording.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.14.1 02-Aug-2025  perseant Sync with HEAD
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 27-Apr-2019  christos file mtx.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file mtx.c was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.18 23-Oct-2017  wiz Remove superfluous Tn.
 1.17 08-Feb-2017  kamil libpthread_dbg(3) deletion from the base distribution

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>
 1.16 24-Nov-2016  wiz branches: 1.16.2;
Bump date for previous.
 1.15 22-Nov-2016  kamil Add reference in SEE ALSO to pthread_dbg(3)

Sponsored by <The NetBSD Foundation>
 1.14 16-May-2010  jruoho branches: 1.14.28;
Add the Butenhof's book to SEE ALSO. (It was decent enough when I read it
years ago, but if there are better ones, please feel free to add those.)
 1.13 16-May-2010  jruoho Enumerate the functions in a table instead of a big SEE ALSO.
Also some stylistic changes.
 1.12 05-Oct-2009  rmind pthread(3): mention that we use 1:1 threading model; remove descriptions
of no longer used environment variables.
 1.11 16-Apr-2009  wiz Add CAVEATS section:
Due to limitations in the current pthread implementation, makecontext(3)
and sigaltstack(2) should not be used in programs which link against
libpthread (whether threads are used or not).

Wording from drochner@ and ad@

Bump date for man pages.

Add note in libpthread/README so it's not forgotten to update the man
pages when the problem is fixed.
 1.10 11-Apr-2009  wiz Remove trailing whitespace.
 1.9 08-Oct-2008  ad branches: 1.9.2; 1.9.4; 1.9.6;
Clarifications for PTHREAD_DIAGASSERT.
 1.8 09-May-2008  wiz Assign to TNF. Make 2-clause instead of 3.

Ok: co-copyright owner hubertf@.
 1.7 19-Nov-2007  ad branches: 1.7.6; 1.7.8;
Sync with reality, and note that programs must link against the dynamic
libpthread in order to remain compatible with future releases of NetBSD.
 1.6 19-May-2007  wiz branches: 1.6.6;
Remove scheduler activations references. Bump date.
 1.5 05-Mar-2007  ad - Sync with reality.
- Minor cosmetic changes.
 1.4 01-Feb-2005  daniel Document PTHREAD_CONCURRENCY, ack by wiz@.
 1.3 27-Nov-2003  cl branches: 1.3.2; 1.3.4;
Set default stack size to the current limit on the stack size as set
with the shell's command to change limits. Make the PTHREAD_STACKSIZE
environment variable override the default stack size. The old fixed
stack size behaviour can be enable with PT_FIXEDSTACKSIZE_LG when building
libpthread.
 1.2 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.1 24-Jul-2003  wiz Add pthread(3), based on one by Hubert Feyrer, improved by yours truly,
reviewed by Nathan J. Williams.
 1.3.4.1 17-Mar-2005  tron Pull up revision 1.4 (requested by daniel in ticket #1166):
Document PTHREAD_CONCURRENCY, ack by wiz@.
 1.3.2.1 17-Mar-2005  tron Pull up revision 1.4 (requested by daniel in ticket #1166):
Document PTHREAD_CONCURRENCY, ack by wiz@.
 1.6.6.1 09-Jan-2008  matt sync with HEAD
 1.7.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.6.1 18-May-2008  yamt sync with head.
 1.9.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.9.4.2 08-Oct-2008  ad Clarifications for PTHREAD_DIAGASSERT.
 1.9.4.1 08-Oct-2008  ad file pthread.3 was added on branch christos-time_t on 2008-10-08 10:11:12 +0000
 1.9.2.1 25-Apr-2009  snj Pull up following revision(s) (requested by rmind in ticket #727):
lib/libc/gen/makecontext.3: revision 1.6
lib/libc/sys/sigaltstack.2: revision 1.22
lib/libpthread/pthread.3: revision 1.11
Add CAVEATS section:
Due to limitations in the current pthread implementation, makecontext(3)
and sigaltstack(2) should not be used in programs which link against
libpthread (whether threads are used or not).
Wording from drochner@ and ad@
Bump date for man pages.
 1.14.28.2 20-Mar-2017  pgoyette Sync with HEAD
 1.14.28.1 07-Jan-2017  pgoyette Sync with HEAD. (Note that most of these changes are simply $NetBSD$
tag issues.)
 1.16.2.1 21-Apr-2017  bouyer Sync with HEAD
 1.188 06-Oct-2025  riastradh libc: Expose some more pthread stubs.

Additionally, provide the option for pthread.h to expose
pthread_create so that libc can provide a weak stub for it, if you
define _NETBSD_PTHREAD_CREATE_WEAK.

This allows libraries to use the functions without linking against
libpthread for applications that don't need threads. For example,
with OpenSSL's libcrypto, as long as you don't try to raise
OSSL_set_max_threads above 0, it won't ever try pthread_create.

New pthread.h macros defined:

pthread_attr_destroy __libc_thr_attr_destroy
pthread_attr_init __libc_thr_attr_init
pthread_attr_setdetachstate __libc_thr_attr_setdetachstate
pthread_detach __libc_thr_detach
pthread_join __libc_thr_join

New pthread.h macros defined if _NETBSD_PTHREAD_CREATE_WEAK is
defined first:

pthread_create __libc_thr_create

New symbols defined by libc as weak aliases for stubs that always
fail but can be overridden by libpthread:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that libc already defined __libc_thr_create.

New internal stubs, not for overriding:

__libc_thr_detach_stub
__libc_thr_join_stub

These were formerly called __libc_pthread_detach and
__libc_pthread_join, respectively, and libc has defined weak aliases
pthread_detach and pthread_join for them since 2013. I retained all
four of those symbols, but defined new ones in the __ namespace that
match the pattern for other thread stubs to avoid raising questions
about why the pattern seems to be broken. I left a comment noting
this fact too.

New pthread strong aliases to override the libc symbols:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that pthread already defined a strong __libc_thr_create alias
for the real pthread_create, so there is no need to add a new one.

PR lib/59685: libcrypto should not depend on libpthread
 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 branches: 1.185.2;
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
 1.185.2.1 02-Aug-2025  perseant Sync with HEAD
 1.2 22-Nov-2024  riastradh libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1 21-Nov-2024  riastradh libpthread: Add expected symbols list.

PR lib/58838: shared libraries in base should all have expsym lists
 1.42 06-Oct-2025  riastradh libc: Expose some more pthread stubs.

Additionally, provide the option for pthread.h to expose
pthread_create so that libc can provide a weak stub for it, if you
define _NETBSD_PTHREAD_CREATE_WEAK.

This allows libraries to use the functions without linking against
libpthread for applications that don't need threads. For example,
with OpenSSL's libcrypto, as long as you don't try to raise
OSSL_set_max_threads above 0, it won't ever try pthread_create.

New pthread.h macros defined:

pthread_attr_destroy __libc_thr_attr_destroy
pthread_attr_init __libc_thr_attr_init
pthread_attr_setdetachstate __libc_thr_attr_setdetachstate
pthread_detach __libc_thr_detach
pthread_join __libc_thr_join

New pthread.h macros defined if _NETBSD_PTHREAD_CREATE_WEAK is
defined first:

pthread_create __libc_thr_create

New symbols defined by libc as weak aliases for stubs that always
fail but can be overridden by libpthread:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that libc already defined __libc_thr_create.

New internal stubs, not for overriding:

__libc_thr_detach_stub
__libc_thr_join_stub

These were formerly called __libc_pthread_detach and
__libc_pthread_join, respectively, and libc has defined weak aliases
pthread_detach and pthread_join for them since 2013. I retained all
four of those symbols, but defined new ones in the __ namespace that
match the pattern for other thread stubs to avoid raising questions
about why the pattern seems to be broken. I left a comment noting
this fact too.

New pthread strong aliases to override the libc symbols:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that pthread already defined a strong __libc_thr_create alias
for the real pthread_create, so there is no need to add a new one.

PR lib/59685: libcrypto should not depend on libpthread
 1.41 20-Feb-2018  kamil Remove namespace restriction from pthread_condattr_{g,s}etclock(3)

These functions were marked as _NETBSD_SOURCE when introduced to the
sources. In fact they are regular POSIX threading functions available
since the 2001 standard. There is an older mention about alignment with
"IEEE Std 1003.1j-2000".

This corrects usage of these functions when a source code is compiled
with a POSIX namespace option.
 1.40 06-Feb-2018  christos fix duplicate declaration of pthread_atfork in unistd.h
 1.39 26-Dec-2017  christos Needs to be protected since it has a timespec argument. Found by lint(1)
 1.38 30-Oct-2016  kamil branches: 1.38.6;
POSIX harder the pthread_mutex_timedlock(3) prototype

Add missing __restrict keyword to the first pointer parameter.

It was already used for the second argument, should not be a functional
change and generated code should be the same.

This new form is now aligned with POSIX.
 1.37 03-Jul-2016  christos branches: 1.37.2;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.36 23-Apr-2016  christos Add pthread_getcpuclockid(3)
 1.35 03-Nov-2012  christos add pthread_condattr_setclock(3)
 1.34 06-Aug-2010  christos branches: 1.34.6; 1.34.8; 1.34.12;
Add pthread_getattr_np()
 1.33 11-Jan-2009  christos merge christos-time_t
 1.32 18-Jul-2008  pooka branches: 1.32.6;
add pthread_cond_has_waiters_np()
 1.31 05-Jun-2008  ad Back out previous because it breaks the build.
 1.30 05-Jun-2008  ad glibc compatibile PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, requested by
rafal@.
 1.29 28-Apr-2008  martin branches: 1.29.2;
Remove clause 3 and 4 from TNF licenses
 1.28 26-Jan-2008  rmind branches: 1.28.4;
sched_setparam: fix the case when incorrect (according to the class)
in-kernel priority is used. Reported by <drochner>.

Minor fixes for scheduling calls to conform the POSIX:
- If pid is equal to zero, use the calling process;
- In case of permission problem, return EPERM instead of EACESS;
- sched_setscheduler() should return previously used policy;
- pthread_* calls should return the error code or zero;

Should fix the namespace problems (and builds of some packages):
- Move cpuset_t defintion from pset.h to sched.h;
- Remove the #include of pset.h in pthread.h;
 1.27 19-Jan-2008  christos s/set/test/
 1.26 19-Jan-2008  christos only include <sys/pset.h> if _NETBSD_SOURCE
 1.25 15-Jan-2008  rmind Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
 1.24 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.23 27-Nov-2007  ad Add thr_curcpu(), pthread_curcpu_np().
 1.22 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.21 21-Mar-2005  kleink branches: 1.21.12;
Add restrict qualifiers to <pthread.h> function arguments.
 1.20 29-Dec-2004  nathanw branches: 1.20.2;
Implement pthread_attr_{set,get}schedpolicy() at the same level as the other
scheduling stuff: only handle SCHED_OTHER. Like the rest of the scheduling
stuff, this is for the benefit of code that can't be bothered to test against
_POSIX_THREAD_PRIORITY_SCHEDULING.
 1.19 15-Dec-2004  wiz Fix typo in comment.
 1.18 13-Dec-2004  nathanw Add #defines to make use of libc stubs for pthread_cond_wait() and
pthread_cond_timedwait().

XXX as noted in the comments, in the situations where these are
useful, they should never be called in a single-threaded
process. Perhaps they should die rather than return 0.

Addresses xsrc/28630.
 1.17 10-Dec-2004  nathanw Use CPP macros to cause many libpthread functions used by applications
to be transformed into the do-nothing-when-libpthread-isn't-linked libc
stub names. This will permit library code that uses <pthread.h> and pthread
functions "defensively" to not need to link against libpthread and not need
to be patched to the threadlib.h API.
 1.16 07-Dec-2003  christos Add pthread_{g,s}etschedparam, that do nothing.
 1.15 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.14 18-Jul-2003  nathanw Add prototypes and necessary symbols for a bunch of pthread_attr_*() functions,
including (interface borrowed from FreeBSD) pthread_attr_get_np().

Remove a few limit-indicating symbols that don't actually need to be defined
(and if they did need to be defined, it would be in limits.h, not here).
 1.13 18-Jul-2003  lukem #include <pthread_types.h> instead of "pthread_types.h"
 1.12 17-Jul-2003  nathanw Define PTHREAD_* structure initializers from _PTHREAD_* macros from
pthread_types.h.
 1.11 16-Jul-2003  nathanw pthread_kill() prototype moved to <signal.h>.
 1.10 02-Jun-2003  christos Add pthread_attr_getstack{,size,addr} needed by jdk
 1.9 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.8 13-Feb-2003  nathanw Implement pthread_atfork() (in libc, because the required threadlib
stub behavior is exactly the same as the usual behavior).
 1.7 19-Jan-2003  thorpej Remove the dummy stack attr routines -- best to catch broken applications
and fix them to use the proper feature test instead (as has already been
done with the openldap package).
 1.6 19-Jan-2003  skrll Move _POSIX_THREADS to the right place and define a few other symbolic
constants for the features we gained with the merge of the nathanw_sa
branch.

Ok'd by thorpej.

Closes my PR 19930.
 1.5 19-Jan-2003  wiz Remove another variable name.
 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 19-Jan-2003  jdolecek 'destructor' is a bit too generic; use 'destruct' instead for
pthread_key_create() prototype
this fixes compilation of Python 2.2 with thread support
XXX perhaps should drop all variable names from prototypes?
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread.h was initially added on branch nathanw_sa.
 1.1.2.21 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.20 13-Jan-2003  thorpej Implement recursive and errorcheck mutexes.
 1.1.2.19 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.18 07-Jan-2003  thorpej Implement the pthread_barrier API.
 1.1.2.17 03-Nov-2002  skrll Whitespace in comments
 1.1.2.16 01-Nov-2002  thorpej * Default to a 100mS round-robin timer; there are a great many
applications that assume concurrency even on a uniprocessor.
(These applications are, of course, broken, but there's not
much we can do about it.)
* Add pthread_getrrtimer_np() and pthread_setrrtimer_np() functions
which provide access to the round-robin timer to application programs.
Setting the rrtimer to 0 will disable timeslicing.

Per discussion with Loren Rittle (on libstdc++@gcc.gnu.org) and
Nathan Williams (privately). The 100mS default interval is chosen
because timeslicing is largely for user-visible parallelism, and
the 100mS interval results in less overhead while still providing
a reasonable amount of user-visible parallelism.
 1.1.2.15 28-Oct-2002  nathanw Implement POSIX read-write locks.
 1.1.2.14 27-Oct-2002  thorpej Remove duplicate <sched.h>
 1.1.2.13 27-Oct-2002  thorpej Cosmetic changes.
 1.1.2.12 24-Jun-2002  nathanw C++ protection.
From Nick Hudson.
 1.1.2.11 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.10 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.9 01-Mar-2002  nathanw Declare POSIX spinlock interfaces: pthread_spin_*() and pthread_spinlock_t.
Move the internal spinlock interface declarations back to the internal header.
 1.1.2.8 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.7 30-Dec-2001  nathanw Declare cancellation routines and define cancellation constants.
Define pthread_cleanup_push() and pthread_cleanup_pop().
Rename pt_spin_t to pthread_spin_t.
Add pthread__errno() interface, for use by libc.
 1.1.2.6 08-Aug-2001  nathanw Add the __noreturn__ attribute to pthread_exit().

Add pthread_once and thread-specific data functions.

Expose pthread spinlock functions.
 1.1.2.5 06-Aug-2001  nathanw broadacst->broadcast
(Regression tests can also catch spelling errors!)
 1.1.2.4 25-Jul-2001  nathanw Remove obsolete PTHREAD_COND_INITIALIZER definition.
Add pthread_mutexattr_{init,destroy}().
Remove optional pthread_condattr functions.
 1.1.2.3 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2 13-Jul-2001  nathanw Move some of the more internal types to another file, to improve
readability.

C sucks, or I'd take them out of the application visibility completely.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.20.2.1 22-Mar-2005  tron Pull up revision 1.21 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.21.12.2 23-Mar-2008  matt sync with HEAD
 1.21.12.1 09-Jan-2008  matt sync with HEAD
 1.28.4.1 18-May-2008  yamt sync with head.
 1.29.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.32.6.2 05-Jan-2009  christos protect functions that use timespec, but don't bother defining compat versions
since we are going to bump. Fixes lint issues in libc.
 1.32.6.1 18-Jul-2008  christos file pthread.h was added on branch christos-time_t on 2009-01-05 01:28:26 +0000
 1.34.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.34.8.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #722):
lib/libpthread/pthread_cond.c: revision 1.58
lib/libpthread/pthread_condattr.3: revision 1.8
lib/libpthread/pthread.h: revision 1.35
add pthread_condattr_setclock(3)
 1.34.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.37.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.38.6.1 25-Feb-2018  snj Pull up following revision(s) (requested by kamil in ticket #562):
lib/libpthread/pthread.h: 1.41
Remove namespace restriction from pthread_condattr_{g,s}etclock(3)
These functions were marked as _NETBSD_SOURCE when introduced to the
sources. In fact they are regular POSIX threading functions available
since the 2001 standard. There is an older mention about alignment with
"IEEE Std 1003.1j-2000".
This corrects usage of these functions when a source code is compiled
with a POSIX namespace option.
 1.15 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.14 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.13 19-Mar-2006  christos Coverity CID 882: Avoid NULL deref.
 1.12 06-Jan-2005  mycroft gettimeofday();TIMEVAL_TO_TIMESPEC(); is exactly equivalent to
clock_gettime(CLOCK_REALTIME), except the latter may have more preicison
some day. So, use that.
 1.11 29-Dec-2004  nathanw Avoid passing zero-valued timespecs to timer_settime() when we want to set
a timer, as that will clear the timer instead. Pass in a safely in-the-past
value instead.
Addresses PR lib/28700.

(XXX passing in values between 0 and 1000 nanoseconds will still fail, but
that bug needs to be fixed in timer_settime(), not here)
 1.10 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.9 14-Mar-2004  cl branches: 1.9.4;
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.8 07-Apr-2003  nathanw Consistently use pthread__assert() rather than err() to assert that
timer_settime() worked, and don't bother calling err() after a
pthread__assert() call.
 1.7 11-Mar-2003  nathanw Remove debugging code accidentally committed.
 1.6 11-Mar-2003  nathanw * Use a <= comparison rather than a < comparison when searching for
alarms to process.

* Remove a redundant assignment.

* Make a debug message more consistent with the others.
 1.5 08-Mar-2003  lukem add __RCSID()
 1.4 15-Feb-2003  nathanw Adapt to pthread__assert() and remove local debug toggle.
 1.3 18-Jan-2003  christos de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Jan-2002  nathanw branches: 1.1.2;
file pthread_alarms.c was initially added on branch nathanw_sa.
 1.1.2.8 11-Jan-2003  skrll Improve error checking.

OK'd by Nathan.
 1.1.2.7 16-Dec-2002  nathanw Adjust the locking protocol for alarms to prevent deletion of running alarms.
 1.1.2.6 22-Oct-2002  nathanw In pthread__alarm_process(), initialize "next" to the same value as "iterator",
so that the timer *always* gets reset, even if the current time is before
the first timer on the list.

XXX the situation that this avoids shouldn't happen and should be looked into
XXX more closely.
 1.1.2.5 16-Jul-2002  nathanw Make the caller of the alarm functions supply the alarm data structure,
instead of malloc'ing() it.

"malloc() inside spinlocks considered harmful." Duh.
 1.1.2.4 20-May-2002  nathanw Add a bunch of debug logging and assertions.

In pthread__alarm_process(), reset the timer to the next alarm in the queue.
 1.1.2.3 19-Feb-2002  nathanw Move alarm initialization into pthread_alarms.c.
 1.1.2.2 30-Jan-2002  nathanw Initialize the temporary queue.
 1.1.2.1 28-Jan-2002  nathanw Add an alarm-queue and callback system. Currently useful for
pthread_cond_timedwait(); will also be useful for pthread_mutex_timedlock().
 1.9.4.1 08-Apr-2005  tron Pull up revision 1.11 (requested by nathanw in ticket #1064):
Avoid passing zero-valued timespecs to timer_settime() when we want to set
a timer, as that will clear the timer instead. Pass in a safely in-the-past
value instead.
Addresses PR lib/28700.
(XXX passing in values between 0 and 1000 nanoseconds will still fail, but
that bug needs to be fixed in timer_settime(), not here)
 1.22 10-Nov-2012  uwe Each get function "has" a set counterpart, it doesn't "contain" it.
 1.21 09-Jul-2010  jruoho branches: 1.21.6; 1.21.12;
Update conformance to the 2001 revision.
 1.20 08-Jul-2010  wiz Add missing word.
 1.19 08-Jul-2010  jruoho Rewrite and include a short summary.
 1.18 07-Jul-2010  jruoho Finally, split pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy()
to their own page.
 1.17 07-Jul-2010  jruoho Split pthread_attr_getschedparam() and pthread_attr_setschedparam() to a
separate page.
 1.16 07-Jul-2010  jruoho Split pthread_attr_getinheritsched() and pthread_attr_setinheritsched() to a
separate page, and actually document these.
 1.15 07-Jul-2010  jruoho Move pthread_attr_getguardsize() and pthread_attr_setguardsize() to a
separate page, and actually document these.
 1.14 07-Jul-2010  jruoho Move the thread stack attribute functions to a separate page. In addition,
document pthread_attr_getstack() and pthread_attr_setstack(). Try to also
document these a little better (in particular, note some items in the long
list of caveats and questions related to application-controlled thread stack).
 1.13 07-Jul-2010  jruoho Split pthread_attr_getdetachstate(3) and pthread_attr_setdetachstate(3) to a
separate page. Once ready, the main page, pthread_attr(3), will contain a
summary of the various thread attribute functions.
 1.12 07-Jul-2010  jruoho Remove pthread_attr_getscope() and pthread_attr_setscope().
 1.11 05-Oct-2009  rmind pthread_attr(3): sync with reality i.e. uncomment descriptions about
various functions we support. Fix license style.
 1.10 11-Apr-2009  wiz Avoid duplicate .Pp.
 1.9 11-Apr-2009  joerg .\" are comments, not ./"
 1.8 19-Oct-2008  snj branches: 1.8.4; 1.8.6;
s/explicitely/explicitly/
 1.7 04-May-2008  martin Move TNF licenses to 2 clause form
 1.6 01-Dec-2007  wiz branches: 1.6.6;
Use more markup. New sentence, new line.
 1.5 21-Mar-2007  ad branches: 1.5.6;
PR lib/34931: PTHREAD_ATTR(3) doesn't document PTHREAD_CREATE_JOINABLE and
PTHREAD_CREATE_DETACHED macros. From Matthew Mondor.
 1.4 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.3 26-Jun-2003  wiz branches: 1.3.6;
Remove trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.6.1 22-Mar-2005  tron Pull up revision 1.4 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.5.6.1 09-Jan-2008  matt sync with HEAD
 1.6.6.1 18-May-2008  yamt sync with head.
 1.8.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.8.4.2 19-Oct-2008  snj s/explicitely/explicitly/
 1.8.4.1 19-Oct-2008  snj file pthread_attr.3 was added on branch christos-time_t on 2008-10-19 21:27:47 +0000
 1.21.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.21.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.22 06-Oct-2025  riastradh libc: Expose some more pthread stubs.

Additionally, provide the option for pthread.h to expose
pthread_create so that libc can provide a weak stub for it, if you
define _NETBSD_PTHREAD_CREATE_WEAK.

This allows libraries to use the functions without linking against
libpthread for applications that don't need threads. For example,
with OpenSSL's libcrypto, as long as you don't try to raise
OSSL_set_max_threads above 0, it won't ever try pthread_create.

New pthread.h macros defined:

pthread_attr_destroy __libc_thr_attr_destroy
pthread_attr_init __libc_thr_attr_init
pthread_attr_setdetachstate __libc_thr_attr_setdetachstate
pthread_detach __libc_thr_detach
pthread_join __libc_thr_join

New pthread.h macros defined if _NETBSD_PTHREAD_CREATE_WEAK is
defined first:

pthread_create __libc_thr_create

New symbols defined by libc as weak aliases for stubs that always
fail but can be overridden by libpthread:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that libc already defined __libc_thr_create.

New internal stubs, not for overriding:

__libc_thr_detach_stub
__libc_thr_join_stub

These were formerly called __libc_pthread_detach and
__libc_pthread_join, respectively, and libc has defined weak aliases
pthread_detach and pthread_join for them since 2013. I retained all
four of those symbols, but defined new ones in the __ namespace that
match the pattern for other thread stubs to avoid raising questions
about why the pattern seems to be broken. I left a comment noting
this fact too.

New pthread strong aliases to override the libc symbols:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that pthread already defined a strong __libc_thr_create alias
for the real pthread_create, so there is no need to add a new one.

PR lib/59685: libcrypto should not depend on libpthread
 1.21 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.20 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.19 29-Jan-2020  kamil Use the pta_magic field in pthread attribute

Set PT_ATTR_DEAD on pthread_attr_destroy().
Check pta_magic before using pthread_attr_t in a bunch of other functions.
 1.18 01-Aug-2017  martin branches: 1.18.4;
pthread__attr_init_private:
malloc+memset -> calloc. Also initialize all values to the proper
defaults.
This fixes the "rustc panic" discussed on pkgsrc-users.
OK: joerg
 1.17 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.16 02-Mar-2012  joerg branches: 1.16.24;
Separate pthread_t from thread stack. Drop additional alignment
restrictions on the thread stack. Remove remaining parts of stackid.
 1.15 06-Aug-2010  christos branches: 1.15.6;
move namespace protection before inclusion.
 1.14 06-Aug-2010  christos Add a weak alias for pthread_attr_get_np. Noted my Matthias Drochner.
 1.13 06-Aug-2010  christos Add pthread_getattr_np()
 1.12 18-Jan-2009  lukem fix -Wsign-compare issues
 1.11 10-Oct-2008  ad branches: 1.11.4;
pthread_attr_getschedparam: allow without preceding setparam on the
attr structure.
 1.10 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.9 25-Jun-2008  ad pthread_attr_setstacksize: EINVAL if the requested size is less than
sysconf(_SC_THREAD_STACK_MIN).
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 08-Jan-2008  christos branches: 1.7.4;
add missing static decls.
 1.6 16-Aug-2007  ad branches: 1.6.2;
Remove PT_FIXEDSTACKSIZE_LG.
 1.5 21-Sep-2005  tv branches: 1.5.8;
pthread_attr_getschedpolicy() wasn't setting the return buffer at all.
SCHED_OTHER happens to be 0, so this assignment to "int *" succeeds,
and becomes a no-op.

Fix by dereferencing "policy" to do the assignment, thus filling the
return buffer with 0.
 1.4 29-Dec-2004  nathanw branches: 1.4.2;
Implement pthread_attr_{set,get}schedpolicy() at the same level as the other
scheduling stuff: only handle SCHED_OTHER. Like the rest of the scheduling
stuff, this is for the benefit of code that can't be bothered to test against
_POSIX_THREAD_PRIORITY_SCHEDULING.
 1.3 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.2 11-Sep-2003  christos sprinkle ARGSUSED for good cheer.
 1.1 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.4.2.1 27-Sep-2005  tron Pull up following revision(s) (requested by tv in ticket #818):
lib/libpthread/pthread_attr.c: revision 1.5
pthread_attr_getschedpolicy() wasn't setting the return buffer at all.
SCHED_OTHER happens to be 0, so this assignment to "int *" succeeds,
and becomes a no-op.
Fix by dereferencing "policy" to do the assignment, thus filling the
return buffer with 0.
 1.5.8.1 03-Sep-2007  skrll Sync with HEAD.
 1.6.2.1 23-Mar-2008  matt sync with HEAD
 1.7.4.1 18-May-2008  yamt sync with head.
 1.8.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.11.4.2 10-Oct-2008  ad pthread_attr_getschedparam: allow without preceding setparam on the
attr structure.
 1.11.4.1 10-Oct-2008  ad file pthread_attr.c was added on branch christos-time_t on 2008-10-10 09:13:21 +0000
 1.15.6.1 17-Apr-2012  yamt sync with head
 1.16.24.2 01-Oct-2017  snj Pull up following revision(s) (requested by martin in ticket #295):
lib/libpthread/pthread_attr.c: revision 1.18
pthread__attr_init_private:
malloc+memset -> calloc. Also initialize all values to the proper
defaults.
This fixes the "rustc panic" discussed on pkgsrc-users.
OK: joerg
 1.16.24.1 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.18.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5 22-Oct-2017  abhinav Add pthread_getattr_np to the NAME section
 1.4 06-Aug-2010  christos document pthread_getattr_np
 1.3 07-Jul-2010  wiz Sort sections.
 1.2 06-Jul-2010  njoly Add missing list end.
 1.1 06-Jul-2010  jruoho Document pthread_attr_get_np(). Fixes PR lib/39289 from ahoka@.
 1.4 23-Oct-2017  wiz Remove superfluous Tn.
 1.3 22-Oct-2017  abhinav Add pthread_attr_setdetachstate to NAME section
 1.2 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.1 07-Jul-2010  jruoho Split pthread_attr_getdetachstate(3) and pthread_attr_setdetachstate(3) to a
separate page. Once ready, the main page, pthread_attr(3), will contain a
summary of the various thread attribute functions.
 1.6 07-Dec-2023  riastradh pthread: Document the setstack vs setguardsize bug.

Suggest the safe, compatible workaround.
 1.5 22-Oct-2017  abhinav branches: 1.5.14;
Add missing function names in the NAME section for rest of the man pages in libpthread
 1.4 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.3 07-Apr-2016  dholland branches: 1.3.8;
_SC_PAGESIZE is not the page size; it's a symbolic code for retrieving
the page size.
 1.2 08-Jul-2010  wiz Whitespace nit.
 1.1 07-Jul-2010  jruoho Move pthread_attr_getguardsize() and pthread_attr_setguardsize() to a
separate page, and actually document these.
 1.3.8.1 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.5.14.1 20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #758):

lib/libpthread/pthread_attr_getstack.3: revision 1.9
lib/libpthread/pthread_attr_getguardsize.3: revision 1.6

pthread: Document the setstack vs setguardsize bug.
Suggest the safe, compatible workaround.
 1.5 27-Feb-2025  andvar s/tread/thread/
 1.4 22-Oct-2017  abhinav branches: 1.4.16;
Add missing function names in the NAME section for rest of the man pages in libpthread
 1.3 10-May-2013  christos s/inherited/inherit/
 1.2 08-Jul-2010  wiz branches: 1.2.6; 1.2.12;
Sort sections.
 1.1 07-Jul-2010  jruoho Split pthread_attr_getinheritsched() and pthread_attr_setinheritsched() to a
separate page, and actually document these.
 1.2.12.1 23-Jun-2013  tls resync from head
 1.2.6.1 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.4.16.1 02-Aug-2025  perseant Sync with HEAD
 1.7 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.6 09-Jul-2010  jruoho Add missing prototypes. Noted by wiz@ -- thanks.
 1.5 09-Jul-2010  wiz Sort errors.
 1.4 09-Jul-2010  jruoho Rationalize by moving

pthread_attr_setname_np(3) to pthread_attr_getname_np(3); and
pthread_setname_np(3) to pthread_getname_np(3).
 1.3 07-Jul-2010  wiz Sort sections.
 1.2 06-Jul-2010  jruoho Same here; fix LIBRARY, add COMPATIBILITY/ERRORS, etc.
 1.1 14-Dec-2007  yamt branches: 1.1.2;
document following functions.
pthread_attr_getname_np
pthread_attr_setname_np
pthread_getname_np
pthread_setname_np
 1.1.2.2 09-Jan-2008  matt sync with HEAD
 1.1.2.1 14-Dec-2007  matt file pthread_attr_getname_np.3 was added on branch matt-armv6 on 2008-01-09 01:36:32 +0000
 1.3 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.2 08-Jul-2010  jruoho Group also pthread_attr_getschedparam(3) and pthread_attr_getschedpolicy(3),
as these two pages fit well together.
 1.1 07-Jul-2010  jruoho Split pthread_attr_getschedparam() and pthread_attr_setschedparam() to a
separate page.
 1.2 08-Jul-2010  jruoho Group also pthread_attr_getschedparam(3) and pthread_attr_getschedpolicy(3),
as these two pages fit well together.
 1.1 07-Jul-2010  jruoho Finally, split pthread_attr_getschedpolicy() and pthread_attr_setschedpolicy()
to their own page.
 1.4 23-Oct-2017  wiz Remove superfluous Tn.
 1.3 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.2 07-Jul-2010  njoly Add missing list end.
 1.1 07-Jul-2010  jruoho Move pthread_attr_{g,s}etscope() to a separate page and try to document
these better. Should fix PR lib/41831 from Wolfgang Stukenbrock.

XXX: Please proofread.
 1.9 07-Dec-2023  riastradh pthread: Document the setstack vs setguardsize bug.

Suggest the safe, compatible workaround.
 1.8 23-Oct-2017  wiz branches: 1.8.14;
Remove superfluous Tn.
 1.7 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.6 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.5 09-Jul-2010  jruoho Note also alignment via mmap(2), as done in NetBSD.
 1.4 09-Jul-2010  jruoho Use .Ss for non-standard subtitle.
 1.3 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.2 07-Jul-2010  jruoho Fix some minor errors/typos and clarify.
 1.1 07-Jul-2010  jruoho Move the thread stack attribute functions to a separate page. In addition,
document pthread_attr_getstack() and pthread_attr_setstack(). Try to also
document these a little better (in particular, note some items in the long
list of caveats and questions related to application-controlled thread stack).
 1.8.14.1 20-Jul-2024  martin Pull up following revision(s) (requested by rin in ticket #758):

lib/libpthread/pthread_attr_getstack.3: revision 1.9
lib/libpthread/pthread_attr_getguardsize.3: revision 1.6

pthread: Document the setstack vs setguardsize bug.
Suggest the safe, compatible workaround.
 1.4 09-Jul-2010  jruoho Add the last compatibility note for the NetBSD extensions.
 1.3 30-Apr-2008  martin branches: 1.3.8;
Convert TNF licenses to new 2 clause variant
 1.2 12-Nov-2003  wiz branches: 1.2.32;
Various fixes.
 1.1 12-Nov-2003  christos Document pthread_attr_setcreatesuspend_np, pthread_suspend_np, pthread_resume_np
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.3.8.1 30-Apr-2008  martin file pthread_attr_setcreatesuspend_np.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.5 09-Jul-2010  jruoho Rationalize by moving

pthread_attr_setname_np(3) to pthread_attr_getname_np(3); and
pthread_setname_np(3) to pthread_getname_np(3).
 1.4 07-Jul-2010  wiz Sort sections.
 1.3 06-Jul-2010  jruoho Same here; fix LIBRARY, add COMPATIBILITY/ERRORS, etc.
 1.2 26-May-2008  wiz branches: 1.2.6;
Remove trailing whitespace.
 1.1 14-Dec-2007  yamt branches: 1.1.2; 1.1.6; 1.1.8;
document following functions.
pthread_attr_getname_np
pthread_attr_setname_np
pthread_getname_np
pthread_setname_np
 1.1.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1.6.1 04-Jun-2008  yamt sync with head
 1.1.2.2 09-Jan-2008  matt sync with HEAD
 1.1.2.1 14-Dec-2007  matt file pthread_attr_setname_np.3 was added on branch matt-armv6 on 2008-01-09 01:36:33 +0000
 1.2.6.2 26-May-2008  wiz Remove trailing whitespace.
 1.2.6.1 26-May-2008  wiz file pthread_attr_setname_np.3 was added on branch christos-time_t on 2008-05-26 08:41:43 +0000
 1.8 22-Oct-2017  abhinav Remove description of pthread_barrierattr_getpshared and pthread_barrierattr_setpshared

These functions are described in pthread_barrierattr(3) man page
 1.7 22-Oct-2017  abhinav Add rest of the pthread_barrier functions in the NAME section
 1.6 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.5 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.4 09-Jul-2010  jruoho Update ERRORS, tidy SEE ALSO.
 1.3 08-Jul-2010  wiz Add comma in enumeration, sort errors.
 1.2 08-Jul-2010  jruoho Split long lines, .Dv NULL, note pthread_barrierattr_init(3).
 1.1 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.23 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.22 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.21 29-Jan-2020  kamil Use pthread_barrierattr_t and pthread_barrier_t magic fields

Set respectively _PT_BARRIER_DEAD for pthread_barrier_destroy() and
_PT_BARRIERATTR_DEAD for pthread_barrierattr_destroy().

Validate _PT_BARRIER_MAGIC in pthread_barrier_t and _PT_BARRIERATTR_MAGIC
in pthread_barrierattr_t accordingly.
 1.20 03-Jul-2016  christos branches: 1.20.16;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.19 29-Jan-2009  ad pthread_barrier: Fix numerous stupid bugs. Surprising that nobody
complained yet.
 1.18 25-May-2008  ad branches: 1.18.4; 1.18.6;
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.17 28-Apr-2008  martin branches: 1.17.2;
Remove clause 3 and 4 from TNF licenses
 1.16 19-Nov-2007  ad branches: 1.16.6;
Remove the debuglog stuff. ktrace is more useful now.
 1.15 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.14 16-Aug-2007  ad branches: 1.14.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.13 04-Aug-2007  ad branches: 1.13.2;
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.12 24-Mar-2007  ad branches: 1.12.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.11 05-Mar-2007  ad Update to match changed pthread__park() interface.
 1.10 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.9 17-Jan-2007  hubertf Remove more duplicate #includes, and a few spurious whitespaces at EOL
From Slava Semushin <slava.semushin@gmail.com>
 1.8 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.7 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.6 08-Mar-2003  lukem branches: 1.6.16; 1.6.18;
add __RCSID()
 1.5 15-Feb-2003  nathanw Remove unnecessary inclusion of <assert.h>.
 1.4 31-Jan-2003  nathanw Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.
 1.3 25-Jan-2003  nathanw Make pthread_barrier_wait() handle spurious wakeups from pthread__block()
by adding a generation number to the barrier structure and incrementing it
when the barrier fires.

XXX this is an ABI change for anything using barriers, but the library is
new enough and nothing in the tree uses barriers so I'm going to let it
slide. Using the private data pointer for a field that will always be present
would be excessive.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 07-Jan-2003  thorpej branches: 1.1.2;
file pthread_barrier.c was initially added on branch nathanw_sa.
 1.1.2.1 07-Jan-2003  thorpej Implement the pthread_barrier API.
 1.6.18.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.6.16.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.12.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.12.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.13.2.2 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.13.2.1 04-Aug-2007  ad file pthread_barrier.c was added on branch matt-mips64 on 2007-08-04 13:37:50 +0000
 1.14.2.1 09-Jan-2008  matt sync with HEAD
 1.16.6.2 04-Jun-2008  yamt sync with head
 1.16.6.1 18-May-2008  yamt sync with head.
 1.17.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.18.6.2 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.18.6.1 25-May-2008  ad file pthread_barrier.c was added on branch christos-time_t on 2008-05-25 17:05:29 +0000
 1.18.4.1 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #379):
lib/libpthread/pthread_barrier.c: revision 1.19
pthread_barrier: Fix numerous stupid bugs. Surprising that nobody
complained yet.
 1.20.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.8 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.7 26-May-2008  wiz branches: 1.7.6;
Sort ERRORS.
 1.6 30-Apr-2008  martin branches: 1.6.2;
Convert TNF licenses to new 2 clause variant
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.3 04-Jul-2003  wiz branches: 1.3.4; 1.3.6;
Fix SEE ALSO.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.3.6.1 18-Jun-2005  tron Pull up revision 1.4 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.3.4.1 21-Jun-2005  riz Pull up revision 1.4 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.5.20.2 04-Jun-2008  yamt sync with head
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.6.2 26-May-2008  wiz Sort ERRORS.
 1.7.6.1 26-May-2008  wiz file pthread_barrier_destroy.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.10 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.9 26-May-2008  wiz branches: 1.9.6;
Sort ERRORS.
 1.8 30-Apr-2008  martin branches: 1.8.2;
Convert TNF licenses to new 2 clause variant
 1.7 17-Jun-2005  peter branches: 1.7.20;
Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.6 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.5 04-Jul-2003  wiz branches: 1.5.4; 1.5.6;
Fix SEE ALSO.
 1.4 04-Jul-2003  wiz Drop trailing whitespace.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.5.6.2 18-Jun-2005  tron Pull up revision 1.7 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.5.6.1 22-Mar-2005  tron Pull up revision 1.6 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.5.4.1 21-Jun-2005  riz Pull up revision 1.7 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.7.20.2 04-Jun-2008  yamt sync with head
 1.7.20.1 18-May-2008  yamt sync with head.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.6.2 26-May-2008  wiz Sort ERRORS.
 1.9.6.1 26-May-2008  wiz file pthread_barrier_init.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.8 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.7 30-Apr-2008  martin branches: 1.7.8;
Convert TNF licenses to new 2 clause variant
 1.6 17-Jun-2005  wiz branches: 1.6.20;
New sentence, new line.
Break much too long line.
 1.5 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.4 04-Jul-2003  wiz branches: 1.4.4; 1.4.6;
Fix SEE ALSO.
 1.3 04-Jul-2003  wiz Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.4.6.2 18-Jun-2005  tron Pull up revision 1.6 (requested by peter in ticket #473):
New sentence, new line.
Break much too long line.
 1.4.6.1 18-Jun-2005  tron Pull up revision 1.5 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.4.4.1 21-Jun-2005  riz Pull up revision 1.5 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.6.20.1 18-May-2008  yamt sync with head.
 1.7.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.7.8.1 30-Apr-2008  martin file pthread_barrier_wait.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.14 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.13 22-Oct-2017  abhinav branches: 1.13.16;
All the four functions described in the man page conform to POSIX.1
 1.12 22-Oct-2017  abhinav Add missing word in the sentence
 1.11 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.10 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.9 09-Jul-2010  wiz Add missing word.
 1.8 08-Jul-2010  jruoho Ups. pthread_barrierattr_destroy(3) may fail with EINVAL.
 1.7 08-Jul-2010  jruoho Cleanup errors; no error returns are defined in NetBSD. (The error codes
should be audited, and tested, for all pthread functions. Also the used
separation between "shall fail" and "may fail" should probably be removed.)
 1.6 30-Apr-2008  martin branches: 1.6.8;
Convert TNF licenses to new 2 clause variant
 1.5 17-Jun-2005  peter branches: 1.5.20;
Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.4 02-Nov-2003  wiz branches: 1.4.4; 1.4.6;
Typo; from Jared Yanovich via jmc@openbsd.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.4.6.1 18-Jun-2005  tron Pull up revision 1.5 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.4.4.1 21-Jun-2005  riz Pull up revision 1.5 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.6.8.1 30-Apr-2008  martin file pthread_barrierattr.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.13.16.1 02-Aug-2025  perseant Sync with HEAD
 1.6 12-Mar-2014  dholland typo
 1.5 09-Jul-2010  jruoho branches: 1.5.6; 1.5.12;
Rewrite this for clarity. Also remove AUTHORS; someone was proud enough to
put himself as the author, even though the page was directly cut-and-pasted
from the Open Group's specification.
 1.4 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.3 30-Apr-2008  martin branches: 1.3.8;
Convert TNF licenses to new 2 clause variant
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.3.8.1 30-Apr-2008  martin file pthread_cancel.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.5.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.5.6.1 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.51 04-Apr-2025  riastradh pthread_cancelstub.c: Use restrict, not __restrict.

Only reason to use __restrict is to make header files safe for
pre-C99 clients, but we have built this code as C99 for many years
(and we build it as C11 now anyway).

No functional change intended.

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.50 04-Apr-2025  riastradh libpthread: Sort cancelstub definitions.

No functional change intended.

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.49 04-Apr-2025  riastradh libpthread: Use typeof rather than copying signatures of cancelstubs.

This would have caught my previous mistake with paccept.

Omit needless declarations that are already covered by the
compat/*/*.h header files.

No functional change intended. This is purely an improvement to
build-time error detection.

PR lib/59134: POSIX-1.2024: pthread_setcancelstate must be
async-signal-safe

PR lib/59247: pthread_cancelstub.c is inadequately tested
 1.48 02-Apr-2025  riastradh libpthread: Fix signature of _sys_paccept symbol for paccept(2).

This is not, in fact, an alias for accept4(2): it has an extra
argument for a signal mask to restore while sleeping.

It would be nice if we had a .h file which could check the signature
in both definition and use, but that might be tricky to arrange.

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.47 31-Mar-2025  riastradh libpthread(3): Add missing cancellation points.

- accept4
- tcdrain

XXX Should our nonstandard alias paccept(2) also be a cancellation
point?

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.46 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.45 19-Jan-2024  christos branches: 1.45.2;
Add missing headers
 1.44 28-Jul-2023  christos Add epoll(2) from Theodore Preduta as part of GSoC 2023
 1.43 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.42 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.41 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.40 01-Oct-2021  christos remove parameter names from decls.
 1.39 01-Oct-2021  christos PR/56424: Clay Mayers: recvfrom() is not a cancelation point as documented
in pthread_setcanceltype.3
 1.38 21-Mar-2013  christos branches: 1.38.32;
- 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.37 04-Apr-2012  christos branches: 1.37.2;
trailing whitespace police.
 1.36 04-Apr-2012  agc Add a pthread cancel stub for sigwait, following Onno van der Linden's
analysis in PR 45131. Kindly tested by Hisashi T Fujinaka (using csup
as the test case) with a successful outcome.

OK martin@
 1.35 22-Apr-2011  joerg branches: 1.35.4; 1.35.6;
Don't kill the read(2) stub, just the magic around it.
 1.34 21-Apr-2011  joerg Disable Fortification for pthread and rump stubs.
 1.33 21-Apr-2011  martin Backout previous, it causes lots of test failures (tests/fs/nfs for
example).
 1.32 12-Apr-2011  christos Fix SSP builds (Vladimir Kirillov)
 1.31 26-Jan-2011  christos make the code more re-usable
 1.30 26-Jan-2011  christos Moving the ssp check inside the source code does not work properly because
the compiler loses information about the size of the object. So instead of
the hacky #define mess we did before, add a way to inject our function between
the user call and the system call.
 1.29 25-Jan-2011  christos Fix SSP build.
XXX: This is gross.
 1.28 06-Aug-2010  christos branches: 1.28.2;
make kevent(2) a cancelation point, and document properly all the cancelation
points we currently support.
 1.27 12-Aug-2009  enami Make nanosleep cancelable again.
 1.26 13-Jan-2009  christos fix __sigtimedwait50
 1.25 11-Jan-2009  christos merge christos-time_t
 1.24 29-Dec-2008  christos branches: 1.24.2;
revert previous. It was meant for the branch
 1.23 28-Dec-2008  christos adjust for time_t 64
 1.22 08-Oct-2008  ad branches: 1.22.2; 1.22.6;
Adjust the compat stuff slightly so that the changes are mostly self
contained (Makefile, pthread_compat.c).
 1.21 29-Sep-2008  ad make PTHREAD__COMPAT=1

Builds a libpthread that can be dropped into a NetBSD 2/3/4 chroot.

This makes threading work in the chroot when using a NetBSD 5 kernel, no
other modifications required.
 1.20 28-Jun-2008  ad Shut lint up.
 1.19 28-Apr-2008  martin branches: 1.19.2;
Remove clause 3 and 4 from TNF licenses
 1.18 02-Feb-2008  christos branches: 1.18.4;
PR/37932: Yakovetsky Vladimir: build distribution with USE_FORT fails
Avoid read redefinition
 1.17 24-Dec-2007  ad - Use pthread__cancelled() in more places.
- pthread_join(): assert that pthread_cond_wait() returns zero.
 1.16 19-Nov-2007  ad int -> ssize_t in a couple of places.
 1.15 09-Oct-2007  rmind Add cancellation stubs in libpthread for POSIX messages queues and
asynchronous I/O.

OK by <ad>.
 1.14 04-Mar-2007  ad branches: 1.14.6;
Add __sigsuspend14, sigtimedwait as cancellation points.
 1.13 13-Sep-2005  christos XXX: Work around libpthread's "intimate" connection with libc.
 1.12 21-Mar-2005  kleink Include <sys/select.h> explicitly rather than relying on other headers
to do it.
 1.11 18-Mar-2005  kleink Interpose cancellation points in pollts() and pselect(), bringing us
to libc.so.12.127 and libpthread.so.0.6.
 1.10 10-Mar-2005  kleink branches: 1.10.2;
Move up the definition of __LIBC12_SOURCE__; since <poll.h> now includes
<sys/sigtypes.h> this is needed earlier.
 1.9 21-May-2004  kleink IEEE Std 1003.1-2001/Cor 2-2004, item XSH/TC2/D6/5: fdatasync() shall
have cancellation points.

Note: we ride today's resolver-related version bumps.
 1.8 24-Nov-2003  cl add CONSTCOND in constant condition.
 1.7 21-Nov-2003  nathanw Manually inline pthread__testcancel in these routines; two function
calls' worth of overhead per cancellable syscall is overkill.
 1.6 18-Nov-2003  thorpej Userland portion of fsync_range(2), written by Bill Studenmund, and
contributed by Wasabi Systems, Inc.
 1.5 08-Mar-2003  lukem add __RCSID()
 1.4 15-Feb-2003  nathanw Implement nanosleep() at userlevel. Threaded applications seem to like
to sleep a lot, and there's no need for each such thread to consume kernel
resources.

(accidentally checked the pthread.c part of this in yesterday; no reason
not to finish the job)
 1.3 27-Jan-2003  nathanw Add cancellation stubs for accept() and connect().
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Jan-2002  nathanw branches: 1.1.2;
file pthread_cancelstub.c was initially added on branch nathanw_sa.
 1.1.2.6 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.5 03-Nov-2002  skrll Whitespace.
 1.1.2.4 14-Aug-2002  nathanw Oops, re-add nanosleep stub, which had been accidentally deleted.
 1.1.2.3 02-Aug-2002  nathanw Adapt to new syscall stub names. Create strong aliases for override functions.
 1.1.2.2 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.1 28-Jan-2002  nathanw Add cancellation-wrapped syscall stubs that override the weak symbols
in libsyscall.
 1.10.2.2 21-Mar-2005  tron Pull up revision 1.12 (requested by kleink in ticket #38):
Include <sys/select.h> explicitly rather than relying on other headers
to do it.
 1.10.2.1 20-Mar-2005  tron Pull up revision 1.11 (requested by kleink in ticket #27):
Interpose cancellation points in pollts() and pselect(), bringing us
to libc.so.12.127 and libpthread.so.0.6.
 1.14.6.3 23-Mar-2008  matt sync with HEAD
 1.14.6.2 09-Jan-2008  matt sync with HEAD
 1.14.6.1 06-Nov-2007  matt sync with HEAD
 1.18.4.1 18-May-2008  yamt sync with head.
 1.19.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.22.6.1 21-Apr-2010  matt sync to netbsd-5
 1.22.2.1 05-Sep-2009  bouyer Pull up following revision(s) (requested by enami in ticket #921):
lib/libpthread/pthread_misc.c: revision 1.14 via patch
lib/libpthread/pthread_cancelstub.c: revision 1.27 via patch
Make nanosleep cancelable again.
 1.24.2.3 10-Jan-2009  christos use the proper sigtimedwait.
 1.24.2.2 29-Dec-2008  christos commit changes to the right branch.
 1.24.2.1 29-Dec-2008  christos file pthread_cancelstub.c was added on branch christos-time_t on 2008-12-29 15:10:58 +0000
 1.28.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.35.6.2 29-Apr-2013  riz 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.35.6.1 09-Apr-2012  riz Pull up following revision(s) (requested by agc in ticket #174):
lib/libpthread/pthread_cancelstub.c: revision 1.36
Add a pthread cancel stub for sigwait, following Onno van der Linden's
analysis in PR 45131. Kindly tested by Hisashi T Fujinaka (using csup
as the test case) with a successful outcome.
OK martin@
 1.35.4.2 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.35.4.1 17-Apr-2012  yamt sync with head
 1.37.2.1 23-Jun-2013  tls resync from head
 1.38.32.1 05-Oct-2021  martin Pull up following revision(s) (requested by christos in ticket #1355):

lib/libpthread/pthread_cancelstub.c: revision 1.39
lib/libc/sys/Makefile.inc: revision 1.247
lib/libpthread/pthread_cancelstub.c: revision 1.40

PR/56424: Clay Mayers: recvfrom() is not a cancelation point as documented
in pthread_setcanceltype.3

remove parameter names from decls.
 1.45.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.5 04-May-2008  martin branches: 1.5.8;
Move TNF licenses to 2 clause form
 1.4 04-Jul-2003  wiz branches: 1.4.32;
.Pp fixes.
 1.3 04-Jul-2003  wiz Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.4.32.1 18-May-2008  yamt sync with head.
 1.5.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.5.8.1 04-May-2008  martin file pthread_cleanup_push.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.7 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.6 08-Dec-2017  kre Revert last 2 updates - these are, of course, not needed at all...
 1.5 08-Dec-2017  kre This time do _lwp_park() timeout unconsting correctly not just compilably.
 1.4 08-Dec-2017  kre Deal with more lwp_park() timestamp unconsting
 1.3 31-Jan-2014  christos remove compatibility code for handling CLOCK_MONOTONIC and handle it in the
syscall directly.
 1.2 08-Oct-2008  ad branches: 1.2.4; 1.2.20; 1.2.26;
Adjust the compat stuff slightly so that the changes are mostly self
contained (Makefile, pthread_compat.c).
 1.1 29-Sep-2008  ad make PTHREAD__COMPAT=1

Builds a libpthread that can be dropped into a NetBSD 2/3/4 chroot.

This makes threading work in the chroot when using a NetBSD 5 kernel, no
other modifications required.
 1.2.26.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.2.20.1 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.2.4.2 08-Oct-2008  ad Adjust the compat stuff slightly so that the changes are mostly self
contained (Makefile, pthread_compat.c).
 1.2.4.1 08-Oct-2008  ad file pthread_compat.c was added on branch christos-time_t on 2008-10-08 08:27:08 +0000
 1.9 28-Jul-2018  kre PR lib/53477 (rudolf at eq.cz) - correct an obvious mistake.
 1.8 22-Oct-2017  abhinav branches: 1.8.2; 1.8.4;
Add missing function names in the NAME section for rest of the man pages in libpthread
 1.7 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.6 12-Nov-2012  uwe Use

.Vt type var No = Dv INITIALIZER;

to provide examples of static initialization in SYNOPSIS section.
.Va macro does the wrong thing (check groff PostScript output) and the
need for .Pp kludge (now dropped) should have been an indication too.

While here move static initialization example to be right after the
declaration of *_init().
 1.5 09-Jul-2010  wiz branches: 1.5.6; 1.5.12;
Fix typo.
 1.4 09-Jul-2010  jruoho Rearrange, reword, clarify. Remove duplicate paragraphs and recurring
sentences. Update the ERRORS to reflect reality in NetBSD.
 1.3 09-Jul-2010  wiz Mark up NULL.
 1.2 08-Jul-2010  wiz Sort errors.
 1.1 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.5.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.8.4.1 10-Jun-2019  christos Sync with HEAD
 1.8.2.1 06-Sep-2018  pgoyette Sync with HEAD

Resolve a couple of conflicts (result of the uimin/uimax changes)
 1.78 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.77 12-Feb-2022  riastradh branches: 1.77.4;
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.76 14-Jun-2020  ad Another bug. The CAS loop in pthread_cond_signal() could race against the
thread it is trying to awake. The thread could exit the condvar and then
reinsert itself at the head of the list with a new waiter behind it. It's
likely possible to fix this in a way that's wait-free but for now just fix
the bug.
 1.75 13-Jun-2020  riastradh Nix trailing whitespace.
 1.74 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.73 06-Jun-2020  ad Adjust previous. In the condvar case the wakeup might already have been
eaten.
 1.72 04-Jun-2020  riastradh Nix trailing whitespace. NFCI.
 1.71 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.70 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.69 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.68 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.67 29-Jan-2020  kamil Use pthread_condattr_t and pthread_cond_t magic fields

Validate _PT_CONDATTR_MAGIC and _PT_COND_MAGIC respectively.
 1.66 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.65 08-Dec-2017  christos branches: 1.65.4; 1.65.6;
unconst the timestamp
 1.64 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.63 31-Jan-2014  christos remove compatibility code for handling CLOCK_MONOTONIC and handle it in the
syscall directly.
 1.62 31-Jan-2014  christos PR/44756: Sad Clouds: Prevent leakage of errno = ESRCH from _lwp_park. This
has two parts:
- in pthread_cond_timedwait() if the thread we are trying to unpark
exited, retry the the _lwp_park call without it.
- pthread_mutex() was affecting errno since it is calling _lwp_park()
from pthread_mutex_lock_slow(). preserve the original errno.
Note that the example problem still causes an occassional deadlock on machines
with many CPUs and it is the same deadlock we observe with named.
 1.61 01-Apr-2013  christos for safety, declare mono on the outermost block it is used.
 1.60 28-Mar-2013  christos PR/47703: Yasushi Oshima: pthread_cond_timedwait() does not wait
after call pthread_condattr_setclock(CLOCK_MONOTONIC)

_lwp_park(2) expects a realtime clock, and it gets passed a monotonic
one. Since monotonic < real, it never sleeps. This patch adjusts
the monotonic clock to be a real one before it passes is to
_lwp_park(2). This is the minimal hacky fix and it will be fixed
properly in _lwp_park(2) in the future.

XXX: pullup to 6.
 1.59 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.58 03-Nov-2012  christos add pthread_condattr_setclock(3)
 1.57 15-Jun-2012  joerg branches: 1.57.2;
Do not mark pthread_cond_timedwait explicitly as inlineable, since it
calls pthread__self, which is static.
 1.56 02-Nov-2010  skrll branches: 1.56.6; 1.56.8;
Spell immediately correctly.
 1.55 23-Mar-2010  drochner catch up with the __RENAME of nanosleep(2) a while ago, otherwise we
get the compatibility function which assumes a different struct timespec
 1.54 18-Jan-2009  lukem fix -Wsign-compare issues
 1.53 25-Oct-2008  yamt branches: 1.53.2; 1.53.4;
remove ; after __weak_alias()
 1.52 02-Aug-2008  matt Change some type to eliminate some lint warnings.
 1.51 18-Jul-2008  pooka add pthread_cond_has_waiters_np()
 1.50 28-Jun-2008  ad Avoid spurious assertion failure.
 1.49 23-Jun-2008  ad Split cond_signal/cond_broadcast into inline and non-inline parts, like
the kernel.
 1.48 21-Jun-2008  ad PR lib/38948: libpthread, java: thread awakening itself
 1.47 26-May-2008  ad Add a comment describing some limitiations of this implementation.
 1.46 26-May-2008  ad - Eliminate one test+branch.
- Fix a comment.
- Fix a lock leak.
 1.45 25-May-2008  ad pthread_cond_timedwait: don't leak EINTR or EALREADY to the caller.
 1.44 25-May-2008  ad Fix error in previous.
 1.43 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.42 28-Apr-2008  martin branches: 1.42.2;
Remove clause 3 and 4 from TNF licenses
 1.41 14-Feb-2008  ad branches: 1.41.4;
Adjust mutex/rwlock definitions to match reality now that there is only
one implementation of each. PR lib/38030.
 1.40 24-Dec-2007  ad - Use pthread__cancelled() in more places.
- pthread_join(): assert that pthread_cond_wait() returns zero.
 1.39 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.38 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.37 13-Sep-2007  ad Add a per-mutex deferred wakeup flag so that threads doing something like
the following do not wake other threads early:

pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
foo = malloc(100); /* takes libc mutexes */
pthread_mutex_unlock(&mutex);
 1.36 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.35 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.34 16-Aug-2007  ad branches: 1.34.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.33 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.32 04-Aug-2007  ad branches: 1.32.2;
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.31 12-Apr-2007  ad branches: 1.31.2;
Mirror a fix made to the kernel's condvars:

After resuming execution, the thread must check to see if it
has been restarted as a result of pthread_cond_signal(). If it
has, but cannot take the wakeup (because of eg a pending Unix
signal or timeout) then try to ensure that another thread sees
it. This is necessary because there may be multiple waiters,
and at least one should take the wakeup if possible.
 1.30 24-Mar-2007  ad - 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.29 21-Mar-2007  ad Move PTHREADD_ADD(PTHREADD_COND_WOKEUP) back to the correct spot.
 1.28 20-Mar-2007  ad - When signalling waiters, try not to awaken them immediatley. If we hold
the mutex that the waiters are using to synchronise, then transfer them
to the mutex's waiters list so that the wakeup is deferred until release
of the mutex. Improves the timings for CV sleep/wakeup by between 30-100%
in tests conducted locally on a UP system. There can be a penalty for MP
systems when only one thread is being awoken, but in practice I think it
won't be be an issue.
- pthread_signal: search for a thread that does not have a pending wakeup.
Threads can have a pending wakeup and still be on the waiters list if we
clash with an earlier pthread_cond_broadcast().
 1.27 14-Mar-2007  ad Cosmetic changes.
 1.26 05-Mar-2007  ad - Update to match changed pthread__park() interface.
- Fix a bug where a thread could be "reentered" onto the waiters queue.
 1.25 05-Mar-2007  ad Undo previous, it matches IEEE 1003.1.
 1.24 05-Mar-2007  ad Drop the interlock if cancelled.
 1.23 02-Mar-2007  ad Fix a sleep/wakeup race with condvars.
 1.22 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.21 02-Mar-2007  ad Don't grab the state lock to check for cancellation around condition
variables, as _lwp_wakeup/lwp_park provide the necessary barrier.
 1.20 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.19 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.18 06-Jan-2005  mycroft branches: 1.18.10; 1.18.12;
gettimeofday();TIMEVAL_TO_TIMESPEC(); is exactly equivalent to
clock_gettime(CLOCK_REALTIME), except the latter may have more preicison
some day. So, use that.
 1.17 10-Dec-2004  nathanw Correctly return ETIMEDOUT when the absolute time is in the past, in
the nonthreaded case. Fixes, and fix from, PR lib/25961.
 1.16 27-Jul-2004  nathanw In cond_wait() and cond_timedwait(), do the ERRORCHECK testing of the
waiters list in all cases, not just on cancellation; there are other
sources of spurious wakeups, such as single-stepping in the debugger.

regress/lib/libpthread/conddestroy1 now passes.
 1.15 03-May-2004  kleink In the nothread version, don't return EINTR if select() was interrupted
since this value is explicitly ruled out by POSIX. Instead, return 0,
like a spurious wakeup. From YAMAMOTO Takashi in PR standards/24240.
 1.14 24-Nov-2003  cl branches: 1.14.2;
Update mutex/rwlock/sem code to match recent change in cond code.
 1.13 24-Nov-2003  nathanw Fix a race between timed wait callbacks and manual signal/broadcasting
accidentally introduced in rev. 1.5.

Noted by Christian Limpach.
 1.12 21-Nov-2003  nathanw Prevent ptc_mutex from remaining set if a CV sleep is woken by
cancellation:

* Arrange to not set ptc_mutex until after the pre-sleep cancellation
test.

* In the post-sleep cancellation test, check if there are no more
sleepers and clear ptc_mutex if so.

While here, sprinkle some __predict_false() around the cancellation
tests.
 1.11 23-Apr-2003  nathanw Use pthread__error() instead of pthread__abort().
 1.10 18-Apr-2003  nathanw More agressive assertions. Change a number of detected conditions, which
officially have undefined behavior, from returning an error code to raising
an assertion failure.
Also, don't bother to explicitly test for (illegal) null pointers and return
an error; they'll bomb out soon enough.
 1.9 16-Apr-2003  nathanw When a thread sleeps on a mutex or cv, have it put itself on the
front of the sleep queue rather than the back. This is more
cache-friendly behavior and within the (lack of) constraints on wakeup
ordering imposed on equal-priority threads.
 1.8 08-Mar-2003  lukem add __RCSID()
 1.7 15-Feb-2003  nathanw Remove debug toggle and add debug counter for signals and broadcasts
that actually wake another thread up.
 1.6 01-Feb-2003  nathanw Arrange to pause for a while if pthread_cond_wait() or
pthread_cond_timedwait() is called before any threads have been
created and the SA infrastructure is up and running.

Addresses PR lib/20139.

XXX probably need to do this for all of the pthread_*_timedlock()
functions, too.
 1.5 31-Jan-2003  nathanw Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.
 1.4 31-Jan-2003  nathanw Do a similar tuneup on pthread_cond_signal() and
pthread_cond_broadcast(): use double-checked locking to avoid
pthread__self() and pthread_spinlock() when signaling or broadcasting
on a condition variable with no waiters.
 1.3 27-Jan-2003  nathanw Add debug counters for mutex and condvar operations.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Jul-2001  nathanw branches: 1.1.2;
file pthread_cond.c was initially added on branch nathanw_sa.
 1.1.2.18 11-Jan-2003  skrll Improve error checking.

OK'd by Nathan.
 1.1.2.17 09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.16 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.15 16-Dec-2002  nathanw Ensure that only one of an alarm callback or a signal/broadcast wakeup can
remove a thread from a condition-variable sleep and schedule it.

Don't call pthread__alarm_fired() until after pthread__alarm_del().
 1.1.2.14 28-Oct-2002  nathanw A little whitespace cleanup, and use PTQ_INIT() rather than a
structure copy to clear the blocked queue in pthread_cond_broadcast().
 1.1.2.13 07-Oct-2002  nathanw Put all assigning and testing of ptc_mutex inside #ifdef ERRORCHECK.
 1.1.2.12 16-Jul-2002  nathanw Adapt to alarm changes.
 1.1.2.11 16-Jul-2002  nathanw Clear the ptc_mutex field in the pthread_cond_wait() callback if the
timed_wait was the last waiter.
 1.1.2.10 20-May-2002  nathanw Record the sleep object in pthread_cond_timedwait().

Add debug logging (disabled by default).
 1.1.2.9 26-Apr-2002  nathanw Track the synchronization object being slept on.
 1.1.2.8 11-Apr-2002  nathanw Revert weak aliases.
 1.1.2.7 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.6 28-Jan-2002  nathanw Implement pthread_cond_timedwait().
Cancellation support.
 1.1.2.5 30-Dec-2001  nathanw pt_queue_t -> pthread_queue_t.
 1.1.2.4 07-Aug-2001  nathanw Initialize the mutex in the condition variable structure in
pthread_cond_init().
 1.1.2.3 06-Aug-2001  nathanw broadacst->broadcast
(Regression tests can also catch spelling errors!)
 1.1.2.2 25-Jul-2001  nathanw Stadardize and clean up use of ERRORCHECK.
Implement pthread_{cond,mutex}attr_{init,destroy} and make the relevant
functions check for their validity.
(No non-default attribute values are supported, but these interfaces
are required anyway).
 1.1.2.1 25-Jul-2001  nathanw Implement most of condition variables
(pthread_cond_timedwait() is not yet done).
 1.14.2.2 04-Oct-2004  jmc branches: 1.14.2.2.2;
Pullup rev 1.16 (requested by oster in ticket #885)

In cond_wait() and cond_timedwait(), do the ERRORCHECK testing of the
waiters list in all cases, not just on cancellation; there are other
sources of spurious wakeups, such as single-stepping in the debugger.
 1.14.2.1 06-May-2004  jmc Pullup rev 1.15 (requested by kleink in ticket #255)

In the nothread version, don't return EINTR if select() was interrupted
since this value is explicitly ruled out by POSIX. Instead, return 0,
like a spurious wakeup. PR#24240.
 1.14.2.2.2.1 08-Apr-2005  tron Pull up revision 1.17 (requested by nathanw in ticket #1065):
Correctly return ETIMEDOUT when the absolute time is in the past, in
the nonthreaded case. Fixes, and fix from, PR lib/25961.
 1.18.12.2 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.18.12.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.18.10.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.31.2.5 10-Sep-2007  skrll Reduce diff to HEAD.
 1.31.2.4 10-Sep-2007  skrll Sync with HEAD.
 1.31.2.3 03-Sep-2007  skrll Sync with HEAD.
 1.31.2.2 15-Aug-2007  skrll Sync with HEAD.
 1.31.2.1 18-Jul-2007  skrll Initial work on provided correctly aligned __cpu_simple_lock_t for hppa
and first attempt at adapting i386 to the changes.

More to come.
 1.32.2.2 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.32.2.1 04-Aug-2007  ad file pthread_cond.c was added on branch matt-mips64 on 2007-08-04 13:37:50 +0000
 1.34.2.3 23-Mar-2008  matt sync with HEAD
 1.34.2.2 09-Jan-2008  matt sync with HEAD
 1.34.2.1 06-Nov-2007  matt sync with HEAD
 1.41.4.2 04-Jun-2008  yamt sync with head
 1.41.4.1 18-May-2008  yamt sync with head.
 1.42.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.42.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.53.4.2 25-Oct-2008  yamt remove ; after __weak_alias()
 1.53.4.1 25-Oct-2008  yamt file pthread_cond.c was added on branch christos-time_t on 2008-10-25 14:14:12 +0000
 1.53.2.1 20-Feb-2014  sborrill Pull up the following revisions(s) (requested by prlw1 in ticket #1898):
lib/libpthread/pthread_cond.c: revision 1.62
lib/libpthread/pthread_mutex.c: revision 1.57,1.59

Partial fix for thread deadlock commonly observed with named.
Also address PR/44756.
 1.56.8.4 20-Feb-2014  sborrill Pull up the following revisions(s) (requested by prlw1 in ticket #1029):
lib/libpthread/pthread_cond.c: revision 1.62
lib/libpthread/pthread_mutex.c: revision 1.57,1.59

Partial fix for thread deadlock commonly observed with named.
Also address PR/44756.
 1.56.8.3 29-Apr-2013  riz 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.56.8.2 20-Apr-2013  bouyer Pull up following revision(s) (requested by christos in ticket #862):
lib/libpthread/pthread_cond.c: revision 1.60
lib/libpthread/pthread_cond.c: revision 1.61
PR/47703: Yasushi Oshima: pthread_cond_timedwait() does not wait
after call pthread_condattr_setclock(CLOCK_MONOTONIC)
_lwp_park(2) expects a realtime clock, and it gets passed a monotonic
one. Since monotonic < real, it never sleeps. This patch adjusts
the monotonic clock to be a real one before it passes is to
_lwp_park(2). This is the minimal hacky fix and it will be fixed
properly in _lwp_park(2) in the future.
XXX: pullup to 6.
for safety, declare mono on the outermost block it is used.
 1.56.8.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #722):
lib/libpthread/pthread_cond.c: revision 1.58
lib/libpthread/pthread_condattr.3: revision 1.8
lib/libpthread/pthread.h: revision 1.35
add pthread_condattr_setclock(3)
 1.56.6.3 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.56.6.2 16-Jan-2013  yamt sync with (a bit old) head
 1.56.6.1 30-Oct-2012  yamt sync with head
 1.57.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.57.2.2 23-Jun-2013  tls resync from head
 1.57.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.65.6.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.65.4.2 21-Apr-2020  martin Sync with HEAD
 1.65.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.77.4.1 02-Aug-2025  perseant Sync with HEAD
 1.8 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.7 26-May-2008  wiz branches: 1.7.6;
Remove trailing whitespace.
 1.6 26-May-2008  ad Note that when calling pthread_cond_broadcast/signal, the same mutex as
passed to wait/timedwait must be held.
 1.5 04-May-2008  martin branches: 1.5.2;
Move TNF licenses to 2 clause form
 1.4 17-Jun-2005  peter branches: 1.4.20;
Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.3 04-Jul-2003  wiz branches: 1.3.4; 1.3.6;
Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.6.1 18-Jun-2005  tron Pull up revision 1.4 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.3.4.1 21-Jun-2005  riz Pull up revision 1.4 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.4.20.2 04-Jun-2008  yamt sync with head
 1.4.20.1 18-May-2008  yamt sync with head.
 1.5.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.7.6.2 26-May-2008  wiz Remove trailing whitespace.
 1.7.6.1 26-May-2008  wiz file pthread_cond_broadcast.3 was added on branch christos-time_t on 2008-05-26 08:42:21 +0000
 1.5 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.4 26-May-2008  wiz branches: 1.4.6;
Sort ERRORS.
 1.3 04-May-2008  martin branches: 1.3.2;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.2 04-Jun-2008  yamt sync with head
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.4.6.2 26-May-2008  wiz Sort ERRORS.
 1.4.6.1 26-May-2008  wiz file pthread_cond_destroy.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.11 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.10 20-May-2010  jruoho Note the initializer macros.
 1.9 26-May-2008  wiz branches: 1.9.6;
Sort ERRORS.
 1.8 04-May-2008  martin branches: 1.8.2;
Move TNF licenses to 2 clause form
 1.7 17-Jun-2005  wiz branches: 1.7.20;
New sentence, new line.
 1.6 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.5 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.4 04-Jul-2003  wiz branches: 1.4.4; 1.4.6;
Fix typo.
 1.3 04-Jul-2003  wiz Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.4.6.2 18-Jun-2005  tron Pull up revision 1.6 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.4.6.1 22-Mar-2005  tron Pull up revision 1.5 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.4.4.1 21-Jun-2005  riz Pull up revision 1.6 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.7.20.2 04-Jun-2008  yamt sync with head
 1.7.20.1 18-May-2008  yamt sync with head.
 1.8.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.6.2 26-May-2008  wiz Sort ERRORS.
 1.9.6.1 26-May-2008  wiz file pthread_cond_init.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.16 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.15 20-May-2010  jruoho .Fa -> .Fn.
 1.14 18-May-2010  jruoho Xref timespec(3).
 1.13 02-Jul-2009  rumble "unblocks the mutex" -> "unlocks the mutex"
 1.12 11-Jan-2009  christos merge christos-time_t
 1.11 31-Dec-2008  wiz Bump date for previous.
 1.10 31-Dec-2008  christos mention that these may fail with EPERM. From Anon Ymous
 1.9 26-May-2008  wiz branches: 1.9.6;
Remove duplicate (pasto?) RETURN VALUES section.
 1.8 26-May-2008  ad More blurb about the mutex and limitations.
 1.7 04-May-2008  martin branches: 1.7.2;
Move TNF licenses to 2 clause form
 1.6 21-Mar-2005  kleink branches: 1.6.20;
Add restrict qualifiers to <pthread.h> function arguments.
 1.5 04-Jul-2003  wiz branches: 1.5.6;
New sentence, new line.
 1.4 04-Jul-2003  wiz Fix SEE ALSO.
 1.3 04-Jul-2003  wiz Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.5.6.1 22-Mar-2005  tron Pull up revision 1.6 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.6.20.2 04-Jun-2008  yamt sync with head
 1.6.20.1 18-May-2008  yamt sync with head.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.9.6.2 11-Jan-2009  christos merge with head.
 1.9.6.1 26-May-2008  christos file pthread_cond_wait.3 was added on branch christos-time_t on 2009-01-11 01:21:59 +0000
 1.13 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.12 28-Mar-2017  maya branches: 1.12.24;
Remove outdated CAVEATS.

Not sure everything is standards compliant, but I've been told non-default
values are supported and pshared exists.
 1.11 05-Jul-2016  wiz branches: 1.11.2; 1.11.4;
Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.10 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.9 03-Nov-2012  wiz Fix pasto.
 1.8 03-Nov-2012  christos add pthread_condattr_setclock(3)
 1.7 09-Jul-2010  jruoho branches: 1.7.6; 1.7.8; 1.7.12;
Re-add EINVAL for pthread_condattr_destroy(3) (misread the pthread__error()).
 1.6 09-Jul-2010  jruoho Remove error conditions. Add CAVEATS to note the questionable value of the
functions in NetBSD, which does not support additional condition attributes.
Note that these do not conform to SUSv4, where two additional attributes are
mandated.
 1.5 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.4 04-May-2008  martin branches: 1.4.8;
Move TNF licenses to 2 clause form
 1.3 17-Jun-2005  peter branches: 1.3.20;
Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.2 08-Jun-2003  thorpej branches: 1.2.4; 1.2.6;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.6.1 18-Jun-2005  tron Pull up revision 1.3 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.2.4.1 21-Jun-2005  riz Pull up revision 1.3 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.3.20.1 18-May-2008  yamt sync with head.
 1.4.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.4.8.1 04-May-2008  martin file pthread_condattr.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.7.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.7.8.2 29-Apr-2013  riz Pull up following revision(s) (requested by enami in ticket #877):
lib/libpthread/pthread_condattr.3: revision 1.9
Fix pasto.
 1.7.8.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #722):
lib/libpthread/pthread_cond.c: revision 1.58
lib/libpthread/pthread_condattr.3: revision 1.8
lib/libpthread/pthread.h: revision 1.35
add pthread_condattr_setclock(3)
 1.7.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.11.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.11.2.1 26-Apr-2017  pgoyette Sync with HEAD
 1.12.24.1 02-Aug-2025  perseant Sync with HEAD
 1.9 29-Apr-2023  uwe pthread_create(3): minor markup tweaks
 1.8 29-Apr-2023  jschauma delete spurious space
 1.7 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.6 07-Jun-2010  dholland Improve wording describing the behavior of the attributes argument, and
add reference to pthread_attr(3), as requested in PR 42871. The text
added is different from but based on a suggestion by Matthew Mondor.
 1.5 02-May-2008  martin branches: 1.5.8;
Move TNF licenses to 2 clause form
 1.4 21-Mar-2005  kleink branches: 1.4.20;
Add restrict qualifiers to <pthread.h> function arguments.
 1.3 04-Jul-2003  wiz branches: 1.3.6;
Mark up a defined value.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.6.1 22-Mar-2005  tron Pull up revision 1.4 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.4.20.1 18-May-2008  yamt sync with head.
 1.5.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.5.8.1 02-May-2008  martin file pthread_create.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.2 10-Nov-2011  wiz branches: 1.2.4;
Fix typo.
 1.1 10-Nov-2011  yamt document pthread_curcpu_np
 1.2.4.2 17-Apr-2012  yamt sync with head
 1.2.4.1 10-Nov-2011  yamt file pthread_curcpu_np.3 was added on branch yamt-pagecache on 2012-04-17 00:05:31 +0000
 1.15 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.14 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.13 16-Aug-2007  ad branches: 1.13.2;
- 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.12 02-Mar-2007  ad branches: 1.12.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.11 20-Jan-2007  christos remove unused variable/code.
 1.10 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.9 14-Dec-2006  ad pthread__debuglog_printf(): check for linebuf == NULL.
 1.8 14-Mar-2004  cl 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.7 02-Jan-2004  cl logging/debugging changes:
- add PTHREAD_PID_DEBUG which prints the pid before each debuglog line
- output thread returned in pthread__next
- add asserts in pthread__sched akin to asserts in pthread__sched_bulk:
check if scheduled thread is at front/end of queue
- pthread__upcall: output event/interrupted LWP count instead of LWPid
of the first event/interrupted LWP (since unblock upcalls can have
multiple event LWPs).
- pthread__find_interrupted: output LWPid here
 1.6 16-Jun-2003  nathanw Dodge a potential race condition in pthread__debuglog_printf(). It's
still possible for multiple threads to write into the same space, but
they shouldn't be able to corrupt the write pointer in the process.

Also, check for pointer-lapping a bit more carefully in the wrap
vs. non-wrap case.
 1.5 16-Apr-2003  nathanw Fix a fencepost error in writing to the debug buffer.
 1.4 08-Mar-2003  lukem add __RCSID()
 1.3 18-Jan-2003  christos de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 17-Jul-2001  nathanw branches: 1.1.2;
file pthread_debug.c was initially added on branch nathanw_sa.
 1.1.2.12 13-Jan-2003  nathanw Textual names for event counters.
 1.1.2.11 22-Oct-2002  nathanw Copy the debug counters before printing anything out, to avoid
observing the effect of printing them.
 1.1.2.10 20-May-2002  nathanw The temporary sprintf buffer doesn't need to be static.
 1.1.2.9 24-Apr-2002  nathanw Add a variable that tracks whether the process is being debugged.
 1.1.2.8 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.7 28-Jan-2002  nathanw Create the debug log with wider permissions.
Clean up a couple of error messages.
 1.1.2.6 30-Dec-2001  nathanw Only do debug logging if the environment variable PTHREAD_DEBUGLOG is
set.
 1.1.2.5 31-Jul-2001  nathanw Add a "force" argument to pthread__debuglog_init(), to reset buffer
parameters even when the magic value seems okay.
 1.1.2.4 27-Jul-2001  nathanw Account for the size of the header structure when computing the usable
debug buffer size.
 1.1.2.3 25-Jul-2001  nathanw Fix printf-style varargs to err(); add some includes.
 1.1.2.2 24-Jul-2001  nathanw Log the PID as well as the program name when starting up.
 1.1.2.1 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.12.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.13.2.1 09-Jan-2008  matt sync with HEAD
 1.13 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.12 24-Sep-2007  ad Kill PTHREAD_SPIN_DEBUG - it's not must use with 1:1.
 1.11 16-Aug-2007  ad branches: 1.11.2;
- 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.10 01-Aug-2007  ad branches: 1.10.2;
Remove unused counters.
 1.9 02-Mar-2007  ad branches: 1.9.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.8 14-Mar-2004  cl branches: 1.8.16; 1.8.18;
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.7 02-Jan-2004  cl logging/debugging changes:
- add PTHREAD_PID_DEBUG which prints the pid before each debuglog line
- output thread returned in pthread__next
- add asserts in pthread__sched akin to asserts in pthread__sched_bulk:
check if scheduled thread is at front/end of queue
- pthread__upcall: output event/interrupted LWP count instead of LWPid
of the first event/interrupted LWP (since unblock upcalls can have
multiple event LWPs).
- pthread__find_interrupted: output LWPid here
 1.6 04-Jul-2003  skrll Typos in comments.
 1.5 15-Feb-2003  nathanw Move module-specific debugging definitions here.
 1.4 27-Jan-2003  nathanw Add debug counters for mutex and condvar operations.
 1.3 18-Jan-2003  christos de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Jan-2003  nathanw branches: 1.1.2;
file pthread_debug.h was initially added on branch nathanw_sa.
 1.1.2.2 13-Jan-2003  nathanw Textual names for event counters.
 1.1.2.1 13-Jan-2003  nathanw Move debug-only stuff into its own header.
 1.8.18.1 25-Sep-2007  wrstuden In preparation for sending ourselves upcalls, keep track of them
(give them a counter) and don't consider receiving one of them
an error.
 1.8.16.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.9.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.9.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.10.2.2 01-Aug-2007  ad Remove unused counters.
 1.10.2.1 01-Aug-2007  ad file pthread_debug.h was added on branch matt-mips64 on 2007-08-01 21:48:20 +0000
 1.11.2.2 09-Jan-2008  matt sync with HEAD
 1.11.2.1 06-Nov-2007  matt sync with HEAD
 1.4 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_detach.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.4 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_equal.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.5 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.4 02-May-2008  martin branches: 1.4.8;
Move TNF licenses to 2 clause form
 1.3 04-Jul-2003  wiz branches: 1.3.32;
New sentence, new line.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.32.1 18-May-2008  yamt sync with head.
 1.4.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.4.8.1 02-May-2008  martin file pthread_exit.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.5 05-Mar-2017  njoly Fix man page ERRORS section for (clock,pthread}_getcpuclockid to match
reality.
 1.4 04-Mar-2017  njoly Fix {clock,pthread}_getcpuclockid to return an error number on
failure, to match OpenGroup specifications.
 1.3 24-Apr-2016  wiz branches: 1.3.2; 1.3.4;
Formatting, typos, whitespace fixes.
 1.2 24-Apr-2016  christos commit the right file.
 1.1 23-Apr-2016  christos Add pthread_getcpuclockid(3)
 1.3.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.3.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.4 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.3 29-Jan-2020  kamil Chack thread->pt_magic with PT_MAGIC promptly

Rearrange some checks to avoid verifying pthread_t after using it.
 1.2 04-Mar-2017  njoly branches: 1.2.12;
Fix {clock,pthread}_getcpuclockid to return an error number on
failure, to match OpenGroup specifications.
 1.1 23-Apr-2016  christos branches: 1.1.2; 1.1.4;
Add pthread_getcpuclockid(3)
 1.1.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.1.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.2.12.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.5 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.4 09-Jul-2010  jruoho Rationalize by moving

pthread_attr_setname_np(3) to pthread_attr_getname_np(3); and
pthread_setname_np(3) to pthread_getname_np(3).
 1.3 07-Jul-2010  wiz Sort sections.
 1.2 06-Jul-2010  jruoho Fix LIBRARY. Add ERRORS and COMPATIBILITY. And some small improvements.
 1.1 14-Dec-2007  yamt branches: 1.1.2;
document following functions.
pthread_attr_getname_np
pthread_attr_setname_np
pthread_getname_np
pthread_setname_np
 1.1.2.2 09-Jan-2008  matt sync with HEAD
 1.1.2.1 14-Dec-2007  matt file pthread_getname_np.3 was added on branch matt-armv6 on 2008-01-09 01:36:35 +0000
 1.6 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.5 09-Jul-2010  wiz Mark up NULL, remove double space.
 1.4 09-Jul-2010  jruoho Rationalize by moving

pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_getspecific.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.114 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.113 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.112 30-Nov-2024  christos Create a new header lwp_private.h to contain _lwp_getprivate_fast,
_lwp_gettcb_fast, _lwp_settcb and remove them from mcontext.h, so that:
1. we don't need special hacks to hide them
2. we can include <lwp.h> where needed to get the necessary prototypes
without redefining them locally.
 1.111 25-May-2023  riastradh branches: 1.111.2;
libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.110 25-May-2023  riastradh libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

XXX pullup-10
 1.109 19-Apr-2022  rillig branches: 1.109.2;
lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.108 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.107 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.106 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.105 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.104 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.103 16-Feb-2020  kamil Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.
 1.102 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.101 05-Feb-2020  kamil Retire ifdef ERRORCHECK in pthread(3)

It is enabled unconditionally since 2003 and used only for rwlocks and
spinlocks.

LLVM sanitizers make assumptions that these checks are enabled always.
 1.100 28-Jan-2020  ad - A bit more alignment in __pthread_st especially for the rbtree node.
- Use COHERENCY_UNIT from sys/param.h.
 1.99 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.98 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.97 18-Dec-2019  joerg Bump PTHREAD__UNPARK_MAX to 128 as bandaid for locking related hangs.
 1.96 16-Dec-2019  uwe G/c unused rwlock owner macros copy-pasted from the kernel.

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.
 1.95 05-Mar-2019  christos branches: 1.95.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.94 02-Jul-2017  joerg branches: 1.94.6;
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.93 08-Feb-2017  kamil branches: 1.93.4;
libpthread_dbg(3) deletion from the base distribution

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>
 1.92 29-May-2015  christos branches: 1.92.2; 1.92.4;
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.91 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.90 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.89 21-Mar-2013  christos branches: 1.89.8;
- 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.88 21-Nov-2012  christos Replace the simple implementation of pthread_key_{create,destroy}
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.
 1.87 03-Nov-2012  rmind libpthread: replace the use of obsolete sys/tree.h interface with rbtree(9).
 1.86 16-Aug-2012  matt branches: 1.86.2;
Add a pthread__smt_wake and add support for it on arm along with
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.
 1.85 04-May-2012  joerg Simplify check for TLS definition to not hide code. Drop it in another
place as it is redundant.
 1.84 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.83 02-Mar-2012  joerg Separate pthread_t from thread stack. Drop additional alignment
restrictions on the thread stack. Remove remaining parts of stackid.
 1.82 17-Jan-2012  joerg branches: 1.82.2;
Introduce __HAVE_NO___THREAD for sun2 and vax to disable the TLS usage.
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.
 1.81 06-Oct-2011  christos branches: 1.81.2;
Include limits.h to get PTHREAD_KEYS_MAX, and move its definition there.
 1.80 16-Sep-2011  joerg Use __dead
 1.79 05-Aug-2011  lukem fix spello in comment
 1.78 17-Mar-2011  matt Add __HAVE___LWP_GETTCB_FAST support (for mips and powerpc).
 1.77 16-Mar-2011  joerg If TLS support is present, use it for pthread__self(). The
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.
 1.76 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.75 25-Feb-2011  joerg Back out using the thread register (if present) for now.

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.
 1.74 24-Feb-2011  joerg Allow storing and receiving the LWP private pointer via ucontext_t
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.
 1.73 18-Dec-2010  christos branches: 1.73.2;
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.72 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.71 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.70 28-Jun-2008  ad branches: 1.70.6;
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.69 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.68 28-Apr-2008  martin branches: 1.68.2;
Remove clause 3 and 4 from TNF licenses
 1.67 14-Feb-2008  ad branches: 1.67.4;
Adjust mutex/rwlock definitions to match reality now that there is only
one implementation of each. PR lib/38030.
 1.66 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.65 08-Jan-2008  christos add missing static decls.
 1.64 24-Dec-2007  ad - Use pthread__cancelled() in more places.
- pthread_join(): assert that pthread_cond_wait() returns zero.
 1.63 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.62 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.61 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.60 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.59 16-Oct-2007  ad Note that libpthread_dbg needs to be checked after making changes to
libpthread.
 1.58 16-Oct-2007  ad ... but preserve the linked list, for the debugger only.
 1.57 16-Oct-2007  ad Replace the global thread list with a red-black tree. From joerg@.
 1.56 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.55 13-Sep-2007  ad Add a per-mutex deferred wakeup flag so that threads doing something like
the following do not wake other threads early:

pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
foo = malloc(100); /* takes libc mutexes */
pthread_mutex_unlock(&mutex);
 1.54 11-Sep-2007  ad Make the new mutexes faster:

- Eliminate mutexattr_private and just set a bit in ptm_owner if the mutex
is recursive. This forces the slow path to be taken for recursive mutexes.
Overload an unused field in pthread_mutex_t to record whether or not it's
an errorcheck mutex.
- Streamline pthread_mutex_lock / pthread_mutex_unlock a bit more. As a
side effect makes it possible to have assembly stubs for them.
 1.53 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.52 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.51 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.50 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.49 16-Aug-2007  ad branches: 1.49.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.48 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.47 16-Aug-2007  ad Remove PT_FIXEDSTACKSIZE_LG.
 1.46 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.45 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.44 04-Aug-2007  ad branches: 1.44.2;
Make libpthread_dbg build again.
 1.43 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.42 12-Apr-2007  ad branches: 1.42.2;
Mirror a fix made to the kernel's condvars:

After resuming execution, the thread must check to see if it
has been restarted as a result of pthread_cond_signal(). If it
has, but cannot take the wakeup (because of eg a pending Unix
signal or timeout) then try to ensure that another thread sees
it. This is necessary because there may be multiple waiters,
and at least one should take the wakeup if possible.
 1.41 24-Mar-2007  ad - 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.40 20-Mar-2007  ad - Maintain a per-thread pointer to the last mutex acquired by the app, to
be used only as as a hint. Clear the pointer when releasing the mutex.
- When releasing a mutex, wake all waiters. Makes it possible to tranfer
waiters from another object to a mutex.
 1.39 05-Mar-2007  ad - Simplify the interface to pthread__park() and friends slightly.
- If sysctl() fails, complain.
 1.38 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.37 06-Feb-2007  ad Build without sys/sa.h present.
 1.36 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.35 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.34 03-Oct-2006  yamt branches: 1.34.2; 1.34.4;
remove unused IDLESPINS.
 1.33 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.32 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.31 26-Feb-2005  nathanw 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.30 12-Oct-2004  mycroft Remove pt_blockuc. If the debugger attempts to muck with the state of a
blocked thread, return an error; this should be done through ptrace(2).
 1.29 24-Aug-2004  nathanw Local whitespace police.
 1.28 24-Aug-2004  nathanw Add a flag that indicates that a thread took a signal.
 1.27 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.26 14-Mar-2004  cl 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.25 02-Feb-2004  nathanw Rename pt_stacksize, pt_stacksize_lg, and pt_stackmask to pthread_*. External
symbols can't start with pt_, as that is in the application namespace.
 1.24 02-Jan-2004  cl userland part of no-syscall upcall stack return

- add pt_stackinfo to struct __pthread_st
- add pthread__stackinfo_offset returning the offset from ss_sp to
pt_stackinfo
- pass stackinfo_offset to sa_register and set SA_FLAG_STACKINFO to
make the kernel use it
- call pthread__sa_recycle in pthread__resolve_locks; g/c recycleq and
pthread__recycle_bulk
- return stack in pthread__sa_recycle by incrementing sasi_stackgen
- make pthread__sa_recycle debugging output formatting conditional on
pthread__debug_newline
 1.23 31-Dec-2003  cl Handle block/unblock for threads in critical section without
sa_unblockyield.

XXX g/c sa_unblockyield in kernel later
 1.22 27-Nov-2003  cl Set default stack size to the current limit on the stack size as set
with the shell's command to change limits. Make the PTHREAD_STACKSIZE
environment variable override the default stack size. The old fixed
stack size behaviour can be enable with PT_FIXEDSTACKSIZE_LG when building
libpthread.
 1.21 25-Nov-2003  christos GC sigcontext<->mcontext code and __HAVE_SIGINFO. All supported archs have
siginfo implemented.
 1.20 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.19 12-Sep-2003  christos convert to use siginfo/ucontext style of signal delivery instead of
sigcontext. Approved by nathanw.
 1.18 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.17 21-Jul-2003  nathanw Add a lock on the pt_flags field.
 1.16 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.15 17-Jul-2003  nathanw Adapt to internal structure name changes.

Add a couple of useful flags and symbols.
 1.14 26-Jun-2003  nathanw Introduce a new pointer, pt_trapuc, that stores thread context captured
by the kernel. Separating this from pt_uc makes it possible to avoid a race
condition in pt_uc management near the STACK_SWITCH part of pthread__switch()
and pthread__locked_switch().

Remove pt_sleepuc pointer, which was made obsolete by the previous round of
UC juggling but still present in the assembler files.
 1.13 06-Jun-2003  nathanw Tiny bit of infrastructure for ABI-supported thread-ID storage.
 1.12 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.11 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.10 18-Apr-2003  nathanw Use a __predict_true() in the definition of pthread__assert().
 1.9 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.8 15-Feb-2003  jdolecek interposition sigtimedwait() with a thread-aware version, which uses
single proxy thread to do the actual syscall, and blocks other threads
in userland
 1.7 15-Feb-2003  nathanw Define a pthread-specific assert function, pthread__assert(), that
bails out without trying to flush stdio buffers.
 1.6 04-Feb-2003  jdolecek minor whitespace changes
 1.5 31-Jan-2003  nathanw Add a new internal function, pthread__sched_sleepers(), which iterates
over a sleep queue and puts everything on the run queue. This permits
the iteration to be inside the acquisition of the run queue spinlock,
avoiding repetitive acquire/release cycles.
 1.4 25-Jan-2003  nathanw More signal rearranging:

- Signal handlers now simply continue executing the current thread,
rather than trying to put themselves back on the queue that they came
from, which was rather fragile. As a result, all callers of
pthread__block() must be prepared to handle spurious wakeups.

- When a signal arrives for a thread that is blocked in the kernel,
note this in another field in pthread_st and set a flag. Process the
signal and set up the trampoline for the handler *after* the thread
unblocks, so that both the trampoline and the returned state from
the kernel are preserved.

- Factor out some code into a pthread__deliver_signal() routine;
the signal-taking code in pthread_sigmask() should be able to use this
soon.

This is still gross, and there are still some terrible MP issues lurking here,
but progress crawls along.
 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_int.h was initially added on branch nathanw_sa.
 1.1.2.41 16-Jan-2003  thorpej Back out previous, and fix the problem by only providing the
ucontext prototypes if the names are not already #define'd.
 1.1.2.40 16-Jan-2003  skrll Put the #include "pthread_md.h" back where it was so the #define stuff
in i386/pthread_md.h works again.
 1.1.2.39 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.38 13-Jan-2003  nathanw Move debug-only stuff into its own header.
 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 16-Dec-2002  nathanw Add a lock to the alarm structure, and adjust the alarm__fired()
function to take a properly typed pointer.
 1.1.2.35 03-Nov-2002  skrll Whitespace.
 1.1.2.34 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.33 28-Oct-2002  nathanw Compact timer magic slightly.
 1.1.2.32 22-Oct-2002  nathanw Define a new macro _INITCONTEXT_U() which initializes a ucontext_t to "blank"
values cheaply. Include _INITCONTEXT_U_MD() for setting machine-specific
registers that must be set to have a valid context.
 1.1.2.31 21-Oct-2002  nathanw Implement a somewhat crude forced round-robin scheduling option,
enabled by setting PTHREAD_RRTIME to the number of milliseconds between
timer events. Makes use of CLOCK_VIRTUAL POSIX timers.
 1.1.2.30 02-Oct-2002  thorpej Fix a typo in a comment.
 1.1.2.29 14-Aug-2002  nathanw Infrastructure for machine-dependent init code.
 1.1.2.28 12-Aug-2002  nathanw Move inclusion of pthread_md.h down to just where it's needed.
 1.1.2.27 02-Aug-2002  nathanw Add a flag indicating that the thread should be woken up on a signal.
 1.1.2.26 16-Jul-2002  nathanw Make the caller of the alarm functions supply the alarm data structure,
instead of malloc'ing() it.

"malloc() inside spinlocks considered harmful." Duh.
 1.1.2.25 20-May-2002  nathanw Increase the thread stack size from 64k to 256k. This is necessary for
some stack-hogging apps like Apache, and for systems with page sizes
larger than 16k.
 1.1.2.24 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.23 26-Apr-2002  nathanw Track the object being slept on.
 1.1.2.22 24-Apr-2002  nathanw Add a numeric ID to the pthread structure.
Add a "Running" state, distinct from "Runnable".
 1.1.2.21 07-Mar-2002  nathanw Oops. It's slightly less confusing if PT_ALARMTIMER_MAGIC and
_PT_MUTEX_MAGIC have different values.
 1.1.2.20 01-Mar-2002  nathanw Declare POSIX spinlock interfaces: pthread_spin_*() and pthread_spinlock_t.
Move the internal spinlock interface declarations back to the internal header.
 1.1.2.19 19-Feb-2002  nathanw Move alarm initialization into pthread_alarms.c.
 1.1.2.18 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.17 30-Dec-2001  nathanw Rename pt_spin_t to pthread_spin_t for namespace cleanliness.

Define cleanup data structures: cleanup queue, cancel state.
 1.1.2.16 04-Sep-2001  nathanw Define a "_UC_USER" flag to b eused in ucontext.uc_flags to indicate
that only "user" (callee-save) state is stored.
 1.1.2.15 08-Aug-2001  nathanw pthread_malloc() and pthread_free() are superfluous.
 1.1.2.14 08-Aug-2001  nathanw Add thread-specific data area to thread structure.

Declare pthread_init() startup function.
Declare pthread__destroy_tsd() utility function.

Move spinlock functions to pthread.h.
 1.1.2.13 01-Aug-2001  nathanw Oops, that's old_preempt, not new_preempt.
 1.1.2.12 01-Aug-2001  nathanw Add a field to the pthread structure to hold the "real" ucontext
pointer for threads preempted in the early stage of locked_switch.
 1.1.2.11 31-Jul-2001  nathanw Prototype "force" argument to pthread__debuglog_init().
 1.1.2.10 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.9 25-Jul-2001  nathanw Enable ERRORCHECK.
Standardize MAGIC/DEAD values.
 1.1.2.8 24-Jul-2001  nathanw Some whitespace cleanup.
 1.1.2.7 20-Jul-2001  nathanw The _*context_u functions are now in the pthread library.
 1.1.2.6 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.5 17-Jul-2001  nathanw Create more idle threads. In the current system, we need one for every level
of preemption nesting.
 1.1.2.4 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.3 13-Jul-2001  nathanw Shrink the per-thread stack to a more reasonable size.
 1.1.2.2 13-Jul-2001  nathanw Use the new queue type and type headers.

Prototype pthread_lockinit().

A little whitespace cleanup.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.34.4.5 04-Jan-2008  wrstuden Fix comment.
 1.34.4.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.34.4.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.34.4.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.34.4.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.34.2.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.42.2.3 10-Sep-2007  skrll Sync with HEAD.
 1.42.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.42.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.44.2.2 04-Aug-2007  ad Make libpthread_dbg build again.
 1.44.2.1 04-Aug-2007  ad file pthread_int.h was added on branch matt-mips64 on 2007-08-04 18:54:14 +0000
 1.49.2.3 23-Mar-2008  matt sync with HEAD
 1.49.2.2 09-Jan-2008  matt sync with HEAD
 1.49.2.1 06-Nov-2007  matt sync with HEAD
 1.67.4.2 04-Jun-2008  yamt sync with head
 1.67.4.1 18-May-2008  yamt sync with head.
 1.68.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.68.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.70.6.2 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.70.6.1 28-Jun-2008  ad file pthread_int.h was added on branch christos-time_t on 2008-06-28 10:29:38 +0000
 1.73.2.1 05-Mar-2011  bouyer Sync with HEAD
 1.81.2.5 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.81.2.4 16-Jan-2013  yamt sync with (a bit old) head
 1.81.2.3 30-Oct-2012  yamt sync with head
 1.81.2.2 23-May-2012  yamt sync with head.
 1.81.2.1 17-Apr-2012  yamt sync with head
 1.82.2.3 29-Apr-2013  riz 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.82.2.2 02-Dec-2012  riz Back out ticket #724 (libpthread changes) until they can be better
understood, as they broke threaded programs on (at least) i386 and amd64.
 1.82.2.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #724):
lib/libpthread/pthread_specific.c: revision 1.24
lib/libpthread/pthread_tsd.c: revision 1.10
lib/libpthread/pthread_tsd.c: revision 1.9
lib/libpthread/pthread_int.h: revision 1.88
Replace the simple implementation of pthread_key_{create,destroy}
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.
Don't call the destructor in pthread_key_delete() following the standard.
 1.86.2.3 23-Jun-2013  tls resync from head
 1.86.2.2 25-Feb-2013  tls resync with head
 1.86.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.89.8.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.92.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.92.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.93.4.2 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.93.4.1 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.94.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.94.6.1 10-Jun-2019  christos Sync with HEAD
 1.95.2.3 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.95.2.2 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.95.2.1 18-Dec-2019  martin Pull up following revision(s) (requested by joerg in ticket #571):

lib/libpthread/pthread_int.h: revision 1.97

Bump PTHREAD__UNPARK_MAX to 128 as bandaid for locking related hangs.
 1.109.2.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.111.2.1 02-Aug-2025  perseant Sync with HEAD
 1.6 09-Jul-2010  wiz Mark up NULL.
 1.5 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.4 02-May-2008  martin branches: 1.4.8;
Move TNF licenses to 2 clause form
 1.3 04-Jul-2003  wiz branches: 1.3.32;
Mark up a defined value.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.32.1 18-May-2008  yamt sync with head.
 1.4.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.4.8.1 02-May-2008  martin file pthread_join.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.9 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.8 29-May-2015  wiz Bump date for previous.
New sentence, new line.
 1.7 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.6 09-Jul-2010  wiz branches: 1.6.24;
Mark up NULL.
 1.5 09-Jul-2010  jruoho Rationalize by moving

pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
 1.4 02-May-2008  martin branches: 1.4.8;
Move TNF licenses to 2 clause form
 1.3 04-Jul-2003  wiz branches: 1.3.32;
Mark up a defined value.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.32.1 18-May-2008  yamt sync with head.
 1.4.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.4.8.1 02-May-2008  martin file pthread_key_create.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.6.24.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.7 09-Jul-2010  jruoho Rationalize by moving

pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
 1.6 02-May-2008  martin branches: 1.6.8;
Move TNF licenses to 2 clause form
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 04-Jul-2003  wiz Sort sections.
 1.3 04-Jul-2003  wiz .Pp fixes.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.6.8.1 02-May-2008  martin file pthread_key_delete.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.9 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.8 26-May-2008  wiz branches: 1.8.6;
Sort ERRORS.
 1.7 04-May-2008  martin branches: 1.7.2;
Move TNF licenses to 2 clause form
 1.6 30-Oct-2003  wiz branches: 1.6.32;
sigwait(2), not (3).
 1.5 30-Oct-2003  jdolecek bump date too
 1.4 30-Oct-2003  jdolecek xref sigwait(3)
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.6.32.2 04-Jun-2008  yamt sync with head
 1.6.32.1 18-May-2008  yamt sync with head.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 26-May-2008  wiz Sort ERRORS.
 1.8.6.1 26-May-2008  wiz file pthread_kill.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.1 11-Apr-2002  nathanw branches: 1.1.2;
file pthread_libcstubs.c was initially added on branch nathanw_sa.
 1.1.2.2 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.1 11-Apr-2002  nathanw Add "hard" stubs for libc interface. Weak aliases didn't work so well.
 1.36 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.35 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.34 28-Apr-2008  martin branches: 1.34.8;
Remove clause 3 and 4 from TNF licenses
 1.33 05-Jan-2008  ad branches: 1.33.4;
machine/lock.h, not sys/lock.h
 1.32 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.31 04-Oct-2007  ad Drop PTHREAD__NSPINS back from 1000 to 64. Setting the waiters bits and
preparing to sleep on a mutex are slow in relative terms, so this allows
us to recover from short lock holds without blocking, while not wasting
too much time on longer holds.
 1.30 24-Sep-2007  ad Kill PTHREAD_SPIN_DEBUG - it's not must use with 1:1.
 1.29 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.28 17-Sep-2007  skrll Mostly fix the restartable atomic sequences by reversing the sense of the
lock check and test for return value.

At least alpha looks broken me and some are sub-optimal.

"Looks good to me" from ad.
 1.27 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.26 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.25 07-Sep-2007  ad If a libpthread internal spinlock is held, nanosleep() for a tick instead of
yielding. This is a nasty band-aid but with many threads, looping over
sched_yield() wastes a huge amount of CPU time. It would be nice to have a
way to temporarily disable preemption, but it turns out that's yet another
no-brain concept that has been patented and the patent holder seems to be
suing people lately. Another alternative is probably to have kernel-assisted
spinlocks.
 1.24 16-Aug-2007  ad branches: 1.24.2;
Minor correction for debug code and a cosmetic change.
 1.23 16-Aug-2007  ad Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.22 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.21 04-Aug-2007  ad branches: 1.21.2;
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.20 24-Mar-2007  ad branches: 1.20.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.19 05-Mar-2007  ad Cosmetic and minor debugging changes.
 1.18 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.17 02-Mar-2007  ad On x86, issue the pause instruction while spinning.
 1.16 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.15 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.14 17-Mar-2005  jwise branches: 1.14.4; 1.14.6;
Lint warning police -- don't use `//' for comments in C code.
 1.13 06-Jan-2005  mycroft Add some additional assertions and debugging printf()s.
 1.12 14-Mar-2004  he It appears that <sys/lock.h> requires <sys/types.h>, so include that as well.
 1.11 14-Mar-2004  cl 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.10 03-Mar-2004  thorpej Use the new RAS_*() macros.
 1.9 13-Feb-2004  wiz Uppercase CPU, plural is CPUs.
 1.8 19-Jan-2004  kleink ; may be a comment character in assembly, use \n as a separator instead.
This instance spotted by Martin Husemann.
 1.7 16-May-2003  scw Both pthread__lock_ras_start and pthread__lock_ras_end need to be
explicitly declared global in the asm() statements for the benefit of
SH5 binutils. Otherwise, the assembler/linker (I haven't figured out
which) botches the SHmedia bit when generating GOT references for
these symbols in the shared version of the library.

Ok'd by Nathan.
 1.6 08-Mar-2003  lukem add __RCSID()
 1.5 15-Feb-2003  nathanw Adapt to pthread__assert() and remove local debug toggle.
 1.4 22-Jan-2003  scw pthread__lock_ras_start and pthread__lock_ras_end need to be declared
as function pointers, not character arrays, for the benefit of
platforms (e.g. SH5) where the two types are quite distinct.
 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_lock.c was initially added on branch nathanw_sa.
 1.1.2.14 30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.13 18-Dec-2002  nathanw Log lock counts in debug messages.
 1.1.2.12 14-Nov-2002  nathanw Use PTHREAD_SPIN_DEBUG here instead of PTHREAD_SA_DEBUG.

Add some checks, conditional on PTHREAD_SPIN_DEBUG, that the spinlock
count is positive. Bail out manually instead of calling abort(),
because abort() will call signal functions, which will try to use
spinlocks....
 1.1.2.11 03-Nov-2002  skrll Whitespace.
 1.1.2.10 22-Oct-2002  nathanw Revert 1.1.2.7 (don't switch if we're an upcall) and the assertion in
1.1.2.6 that encountering a locked spinlock is a bug.

Since upcalls can hold spinlocks (signal system, recycle lock, alarm
queue, condition variable interlocks via alarm queue callbacks) it is
possible that an upcall that has itself been preempted will try to
acquire a spinlock that is held by another thread in the
lock-resolution code. In this case, the proper thing to do is to
transfer control via the preempted-while-spinning code, rather than
raising an assertion failure. This will permit the other thread to
make forward progress in its critical region, after which this upcall
will run again and can aquire the spinlock
 1.1.2.9 16-Oct-2002  nathanw Whitespace.
 1.1.2.8 01-Mar-2002  nathanw Implement POSIX spinlock functions.
 1.1.2.7 08-Feb-2002  nathanw Efficency tweak: don't take preemption-jumps out of switch routines if
we're an upcall; the handler will just continue us at the same point
anyway until we finish our business.
 1.1.2.6 30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
Add some debug logging and assertions.
 1.1.2.5 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.4 20-Jul-2001  nathanw Reduce excessive header inclusion.
 1.1.2.3 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2 13-Jul-2001  nathanw Add pthread_lockinit().
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.14.6.1 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.14.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.20.2.4 03-Sep-2007  skrll Sync with HEAD.
 1.20.2.3 15-Aug-2007  skrll Sync with HEAD.
 1.20.2.2 15-Aug-2007  skrll Simplify the pthread__simple_lock_try RAS.
 1.20.2.1 18-Jul-2007  skrll Initial work on provided correctly aligned __cpu_simple_lock_t for hppa
and first attempt at adapting i386 to the changes.

More to come.
 1.21.2.2 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.21.2.1 04-Aug-2007  ad file pthread_lock.c was added on branch matt-mips64 on 2007-08-04 13:37:50 +0000
 1.24.2.2 09-Jan-2008  matt sync with HEAD
 1.24.2.1 06-Nov-2007  matt sync with HEAD
 1.33.4.1 18-May-2008  yamt sync with head.
 1.34.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.34.8.1 28-Apr-2008  martin file pthread_lock.c was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.1 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.3 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.2 17-Dec-2014  pooka include correct header for "last minute just-in-case defensive addition
that's too trivial to check"
 1.1 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.3 06-Oct-2025  riastradh libc: Expose some more pthread stubs.

Additionally, provide the option for pthread.h to expose
pthread_create so that libc can provide a weak stub for it, if you
define _NETBSD_PTHREAD_CREATE_WEAK.

This allows libraries to use the functions without linking against
libpthread for applications that don't need threads. For example,
with OpenSSL's libcrypto, as long as you don't try to raise
OSSL_set_max_threads above 0, it won't ever try pthread_create.

New pthread.h macros defined:

pthread_attr_destroy __libc_thr_attr_destroy
pthread_attr_init __libc_thr_attr_init
pthread_attr_setdetachstate __libc_thr_attr_setdetachstate
pthread_detach __libc_thr_detach
pthread_join __libc_thr_join

New pthread.h macros defined if _NETBSD_PTHREAD_CREATE_WEAK is
defined first:

pthread_create __libc_thr_create

New symbols defined by libc as weak aliases for stubs that always
fail but can be overridden by libpthread:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that libc already defined __libc_thr_create.

New internal stubs, not for overriding:

__libc_thr_detach_stub
__libc_thr_join_stub

These were formerly called __libc_pthread_detach and
__libc_pthread_join, respectively, and libc has defined weak aliases
pthread_detach and pthread_join for them since 2013. I retained all
four of those symbols, but defined new ones in the __ namespace that
match the pattern for other thread stubs to avoid raising questions
about why the pattern seems to be broken. I left a comment noting
this fact too.

New pthread strong aliases to override the libc symbols:

__libc_thr_attr_destroy
__libc_thr_attr_init
__libc_thr_attr_setdetachstate
__libc_thr_detach
__libc_thr_join

Note that pthread already defined a strong __libc_thr_create alias
for the real pthread_create, so there is no need to add a new one.

PR lib/59685: libcrypto should not depend on libpthread
 1.2 31-Mar-2025  riastradh branches: 1.2.4;
libpthread(3): Add missing cancellation points.

- accept4
- tcdrain

XXX Should our nonstandard alias paccept(2) also be a cancellation
point?

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.1 22-Nov-2024  riastradh libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.2.4.2 02-Aug-2025  perseant Sync with HEAD
 1.2.4.1 31-Mar-2025  perseant file pthread_mi.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:55 +0000
 1.19 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.18 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.17 29-Jan-2020  kamil Check thread->pt_magic with PT_MAGIC promptly
 1.16 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.15 21-Mar-2013  christos branches: 1.15.30; 1.15.32;
- 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.14 12-Aug-2009  enami branches: 1.14.6; 1.14.8; 1.14.12;
Make nanosleep cancelable again.
 1.13 11-Jan-2009  christos merge christos-time_t
 1.12 29-Dec-2008  christos branches: 1.12.2;
revert previous. It was meant for the branch
 1.11 28-Dec-2008  christos adjust for time_t 64
 1.10 28-Jun-2008  ad branches: 1.10.4; 1.10.8;
Shut lint up.
 1.9 24-Jun-2008  ad pthread_kill, pthread_sigmask: return errno, not the return from the system
call. Found by VSTHlite.
 1.8 28-Apr-2008  martin branches: 1.8.2;
Remove clause 3 and 4 from TNF licenses
 1.7 10-Feb-2008  ad branches: 1.7.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.6 09-Feb-2008  yamt update for _sched_{get,set}param changes. from rmind@.
 1.5 26-Jan-2008  rmind sched_setparam: fix the case when incorrect (according to the class)
in-kernel priority is used. Reported by <drochner>.

Minor fixes for scheduling calls to conform the POSIX:
- If pid is equal to zero, use the calling process;
- In case of permission problem, return EPERM instead of EACESS;
- sched_setscheduler() should return previously used policy;
- pthread_* calls should return the error code or zero;

Should fix the namespace problems (and builds of some packages):
- Move cpuset_t defintion from pset.h to sched.h;
- Remove the #include of pset.h in pthread.h;
 1.4 15-Jan-2008  rmind Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
 1.3 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.2 16-Aug-2007  ad branches: 1.2.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.1 02-Mar-2007  ad branches: 1.1.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.1.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.2.2.2 23-Mar-2008  matt sync with HEAD
 1.2.2.1 09-Jan-2008  matt sync with HEAD
 1.7.4.1 18-May-2008  yamt sync with head.
 1.8.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.10.8.1 21-Apr-2010  matt sync to netbsd-5
 1.10.4.1 05-Sep-2009  bouyer Pull up following revision(s) (requested by enami in ticket #921):
lib/libpthread/pthread_misc.c: revision 1.14 via patch
lib/libpthread/pthread_cancelstub.c: revision 1.27 via patch
Make nanosleep cancelable again.
 1.12.2.2 29-Dec-2008  christos commit changes to the right branch.
 1.12.2.1 29-Dec-2008  christos file pthread_misc.c was added on branch christos-time_t on 2008-12-29 15:10:58 +0000
 1.14.12.1 23-Jun-2013  tls resync from head
 1.14.8.1 29-Apr-2013  riz 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.14.6.1 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.15.32.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.15.30.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.12 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.11 27-Dec-2019  msaitoh branches: 1.11.10;
s/sucess/success/ in comment.
 1.10 22-Oct-2017  abhinav branches: 1.10.4;
Add missing function names in the NAME section for rest of the man pages in libpthread
 1.9 30-Oct-2016  kamil POSIX harder the pthread_mutex_timedlock(3) prototype

Add missing __restrict keyword to the first pointer parameter.

It was already used for the second argument, should not be a functional
change and generated code should be the same.

This new form is now aligned with POSIX.
 1.8 05-Jul-2016  wiz branches: 1.8.2;
Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.7 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.6 12-Nov-2012  uwe Use

.Vt type var No = Dv INITIALIZER;

to provide examples of static initialization in SYNOPSIS section.
.Va macro does the wrong thing (check groff PostScript output) and the
need for .Pp kludge (now dropped) should have been an indication too.

While here move static initialization example to be right after the
declaration of *_init().
 1.5 09-Jul-2010  wiz branches: 1.5.6; 1.5.12;
Mark up NULL.
 1.4 08-Jul-2010  wiz Add comma in enumeration, sort errors.
 1.3 08-Jul-2010  jruoho Add missing word.
 1.2 08-Jul-2010  jruoho Continue the discussion with few remarks and rearrange slightly.
 1.1 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.5.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.5.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.8.2.1 04-Nov-2016  pgoyette Sync with HEAD
 1.10.4.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11.10.1 02-Aug-2025  perseant Sync with HEAD
 1.83 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.82 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.81 11-Jun-2020  ad Adjust memory barriers.
 1.80 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.79 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.78 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.77 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.76 16-Feb-2020  kamil Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.
 1.75 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.74 01-Feb-2020  kamil Revert previous

'git grep' breaks now.
 1.73 01-Feb-2020  kamil Remove 'ifdef 0' hacks

It is no longer needed as the proper fix avoiding premature malloc()
landed the sources.
 1.72 31-Jan-2020  kamil Refactor libpthread checks for invalid arguments

Switch from manual functions to pthread__error().
 1.71 31-Jan-2020  christos In the same spirit as the previous pthread_mutex_init change for jemalloc,
make pthread_mutexattr_init do always a full initialization, so that the
attribute that will be used later when we become threaded is properly
initialized.
 1.70 29-Jan-2020  kamil Use pthread_mutexattr_t and pthread_mutex_t magic fields

Validate _PT_MUTEX_MAGIC in pthread_mutex_t and _PT_MUTEXATTR_MAGIC
in pthread_mutexattr_t accordingly.
 1.69 29-Jan-2020  kamil Mark destroyed pthread_mutexattr_t as dead
 1.68 25-Jan-2020  ad Adjustment to previous: don't call _lwp_unpark_all() with nwaiters == 0.
 1.67 25-Jan-2020  ad pthread__mutex_unlock_slow(): ignore the DEFERRED bit. It's only purpose
is to get the thread to go through the slow path. If there are waiters,
process them there and then. Should not affect well behaved apps. Maybe
of help for:

PR bin/50350: rump/rumpkern/t_sp/stress_{long,short} fail on Core 2 Quad
 1.66 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.65 05-Mar-2019  christos branches: 1.65.2;
Jemalloc initializes mutexes before we become threaded and expects to use
them later.
 1.64 08-Dec-2017  kre branches: 1.64.4;

Deal with more lwp_park() timestamp unconsting
 1.63 31-Oct-2016  christos Don't spin if we already own the mutex, otherwise we will get stuck spinning
forever, fixes timemutex{1,2} tests.
 1.62 17-Jul-2016  skrll Use anonymous union for ptm_ceiling and old __pthread_spin_t field to
maintain backward compatibility and fix hppa build. hppa has an non-
integer type __pthread_spin_t
 1.61 16-Jul-2016  skrll KNF
 1.60 03-Jul-2016  christos branches: 1.60.2;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.59 03-Feb-2014  rmind pthread__mutex_lock_slow: fix the handling of a potential race with the
non-interlocked CAS in the fast unlock path -- it is unsafe to test for
the waiters-bit while the owner thread is running, we have to spin for
the owner or its state change to be sure about the presence of the bit.
Split off the logic into the pthread__mutex_setwaiters() routine.

This is a partial fix to the named lockup problem (also see PR/44756).
It seems there is another race which can be reproduced on faster CPUs.
 1.58 31-Jan-2014  christos remove compatibility code for handling CLOCK_MONOTONIC and handle it in the
syscall directly.
 1.57 31-Jan-2014  christos PR/44756: Sad Clouds: Prevent leakage of errno = ESRCH from _lwp_park. This
has two parts:
- in pthread_cond_timedwait() if the thread we are trying to unpark
exited, retry the the _lwp_park call without it.
- pthread_mutex() was affecting errno since it is calling _lwp_park()
from pthread_mutex_lock_slow(). preserve the original errno.
Note that the example problem still causes an occassional deadlock on machines
with many CPUs and it is the same deadlock we observe with named.
 1.56 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.55 06-Mar-2013  yamt add comments
whitespace
 1.54 16-Aug-2012  matt branches: 1.54.2;
Add a pthread__smt_wake and add support for it on arm along with
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.
 1.53 13-Mar-2012  joerg Move the pthread_once alias where it belongs.
 1.52 12-Mar-2012  joerg Move pthread_once implementation into a separate file, it doesn't depend
on the mutex implementation in any way.
 1.51 02-Aug-2008  matt branches: 1.51.2; 1.51.4; 1.51.6; 1.51.22;
Change pthread_mutex_t to use the amount of space as and be congruent to
the version used in the SA version of pthreads. This preserves binary
compatibility between both versions of the library.
 1.50 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.49 25-May-2008  ad Add some general comments about the mutex implementation.
 1.48 28-Apr-2008  martin branches: 1.48.2;
Remove clause 3 and 4 from TNF licenses
 1.47 07-Mar-2008  ad branches: 1.47.2;
pthread__mutex_lock_slow:

- don't stop spinning if there are already waiters on the mutex, there is
no point.
- cosmetic change.
 1.46 23-Feb-2008  ad Fix pthread_mutex_trylock() for recursive mutexes. PR lib/38087.
Based on a patch provided by rafal@.
 1.45 14-Feb-2008  ad branches: 1.45.2;
Adjust mutex/rwlock definitions to match reality now that there is only
one implementation of each. PR lib/38030.
 1.44 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.43 25-Jan-2008  rafal Make this compile after Andrew's fix (remove now-unused variables)
 1.42 25-Jan-2008  ad pthread_mutex_lock_slow: remove "deliberate deadlock" code that's not
needed with 1:1. PR lib/37524.
 1.41 08-Jan-2008  christos add missing static decls.
 1.40 05-Jan-2008  ad machine/lock.h, not sys/lock.h
 1.39 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.38 19-Nov-2007  ad Remove the debuglog stuff. ktrace is more useful now.
 1.37 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.36 13-Sep-2007  ad Add a per-mutex deferred wakeup flag so that threads doing something like
the following do not wake other threads early:

pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
foo = malloc(100); /* takes libc mutexes */
pthread_mutex_unlock(&mutex);
 1.35 11-Sep-2007  ad Fix inverted test after merge of nick-csl-alignment.
 1.34 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.33 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.32 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.31 16-Aug-2007  ad branches: 1.31.2;
One more micro-optimization..
 1.30 16-Aug-2007  ad Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.29 04-Aug-2007  ad branches: 1.29.2;
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.28 24-Mar-2007  ad branches: 1.28.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.27 20-Mar-2007  ad - Maintain a per-thread pointer to the last mutex acquired by the app, to
be used only as as a hint. Clear the pointer when releasing the mutex.
- When releasing a mutex, wake all waiters. Makes it possible to tranfer
waiters from another object to a mutex.
 1.26 05-Mar-2007  ad Update to match changed pthread__park() interface.
 1.25 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.24 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.23 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.22 22-Aug-2006  wrstuden branches: 1.22.2; 1.22.4;
Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.

Reviewed by myself and Christos.

Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.
 1.21 19-Oct-2005  chs branches: 1.21.2;
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.20 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.19 16-Jul-2005  nathanw Add cancellation protection to pthread_once() as per the standard; if
the once routine is cancelled, the effect on once_control is as if
pthread_once() was never called.

Bug report and fix from PR lib/30734.
 1.18 14-Mar-2004  cl branches: 1.18.6;
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.17 24-Nov-2003  cl Update mutex/rwlock/sem code to match recent change in cond code.
 1.16 27-May-2003  christos add missing notreached lint comment.
 1.15 16-May-2003  nathanw Separately report unlocking an unlocked mutex and unlocking a mutex
owned by another thread.
 1.14 23-Apr-2003  nathanw Use pthread__error() instead of pthread__abort().
 1.13 18-Apr-2003  nathanw More agressive assertions. Change a number of detected conditions, which
officially have undefined behavior, from returning an error code to raising
an assertion failure.
Also, don't bother to explicitly test for (illegal) null pointers and return
an error; they'll bomb out soon enough.
 1.12 16-Apr-2003  nathanw pthread_mutex_trylock(): It's not an error to call trylock() on a
mutex already locked by the calling thread, even for non-recursive
mutexes.
 1.11 16-Apr-2003  nathanw When a thread sleeps on a mutex or cv, have it put itself on the
front of the sleep queue rather than the back. This is more
cache-friendly behavior and within the (lack of) constraints on wakeup
ordering imposed on equal-priority threads.
 1.10 08-Mar-2003  lukem add __RCSID()
 1.9 15-Feb-2003  nathanw Remove unnecessary inclusion of <assert.h>.
 1.8 31-Jan-2003  nathanw Mutex tuneup.

* Use a double-checked locking technique to avoid taking
the interlock in pthread_mutex_unlock().

* In pthread_mutex_lock() and pthread_mutex_trylock(), only store the
stack pointer, not the thread ID, in ptm_owner. Do the translation
to a thread ID in the slow-lock, errorcheck, and recursive mutex
cases rather than in the common path.

* Juggle where pthread__self() is called, to move it out of the fast path.

Overall, this means that neither pthread_self() nor
pthread_spin[un]lock() are used in the course of locking and unlocking
an uncontested mutex. Speeds up the fast path by 40-50%, and
eliminates about 98% of spinlocks used by a couple of large threaded
applications.

(Still a GET_MUTEX_PRIVATE() in the fast path... perhaps the type
should be in the main body of the mutex).
 1.7 27-Jan-2003  nathanw Add debug counters for mutex and condvar operations.
 1.6 22-Jan-2003  scw Need to include <string.h> for memcmp() prototype.
 1.5 19-Jan-2003  thorpej Fix typo.
 1.4 19-Jan-2003  thorpej Add mutexattr_init(), mutexattr_destroy(), and mutexattr_settype() (recursive
mutexes are used by the X libraries).
 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_mutex.c was initially added on branch nathanw_sa.
 1.1.2.20 14-Jan-2003  thorpej Move a comment to a more logical location.
 1.1.2.19 13-Jan-2003  thorpej Implement recursive and errorcheck mutexes.
 1.1.2.18 09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.17 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.16 30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.15 26-Oct-2002  nathanw Whitespace in comments.
 1.1.2.14 23-Oct-2002  nathanw Revert previous. There's still a race condition whose avoidance requires
checking the blocked queue with the interlock held.
 1.1.2.13 22-Oct-2002  nathanw Speed up pthread_mutex_unlock() similarly to what was done to
pthread_mutex_lock(): heavily optimize for the case of a mutex with no
waiters, and defer the waiter case to a separate function.

Uncontested mutexes now no longer use library spin locks.
 1.1.2.12 04-Oct-2002  nathanw Tweak pthread_mutex_lock(): Move the "slow" code to another function
and only call pthread_self() inside that function.

Don't use pthread_self() to track ownership; just stash the stack
pointer. Translation to thread IDs can be done post-mortem if
necessary (Thanks to Greg Hudson for pointing this out).
 1.1.2.11 26-Apr-2002  nathanw Track the synchronization object being slept on.
 1.1.2.10 11-Apr-2002  nathanw Revert weak aliases.
 1.1.2.9 25-Mar-2002  nathanw Oops, that function is pthread_once(), not pthread_mutex_once().
 1.1.2.8 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.7 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.6 08-Aug-2001  nathanw Implement pthread_once().
 1.1.2.5 25-Jul-2001  nathanw Stadardize and clean up use of ERRORCHECK.
Implement pthread_{cond,mutex}attr_{init,destroy} and make the relevant
functions check for their validity.
(No non-default attribute values are supported, but these interfaces
are required anyway).
 1.1.2.4 24-Jul-2001  nathanw Remove some unnecessary includes.
Prefix some application-visible preprocessor symbols with an underscore.

Modify pthread_mutex_unlock() to only wake up one waiter.
 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 definition and use of
pthread_mutex_t.

Add a note about Pthreads memory visibility rules.

Use an optimistic simple-lock approach for locking mutexes. Should be
faster in the common case.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.18.6.2 25-Aug-2006  ghen Pull up following revision(s) (requested by wrstuden in ticket #1474):
lib/libpthread/pthread_mutex.c: revision 1.22
Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.
Reviewed by myself and Christos.
Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.
 1.18.6.1 01-Nov-2005  jmc branches: 1.18.6.1.2;
Pullup revs 1.20-1.21 (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.18.6.1.2.1 25-Aug-2006  ghen Pull up following revision(s) (requested by wrstuden in ticket #1474):
lib/libpthread/pthread_mutex.c: revision 1.22
Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.
Reviewed by myself and Christos.
Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.
 1.21.2.1 25-Aug-2006  ghen Pull up following revision(s) (requested by wrstuden in ticket #52):
lib/libpthread/pthread_mutex.c: revision 1.22
Close a window in which we can not notice a recently-slept-on-our
mutex thread, thus leaving a thread sleeping on an unlocked mutex.
Reviewed by myself and Christos.
Problem reported by Arne H. Juul, arnej at pvv dot ntnu dot no,
in PR 26208. This fix represents option 1 presented in the PR.
 1.22.4.2 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.22.4.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.22.2.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.28.2.4 10-Sep-2007  skrll Sync with HEAD.
 1.28.2.3 03-Sep-2007  skrll Sync with HEAD.
 1.28.2.2 15-Aug-2007  skrll Sync with HEAD.
 1.28.2.1 18-Jul-2007  skrll Initial work on provided correctly aligned __cpu_simple_lock_t for hppa
and first attempt at adapting i386 to the changes.

More to come.
 1.29.2.2 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.29.2.1 04-Aug-2007  ad file pthread_mutex.c was added on branch matt-mips64 on 2007-08-04 13:37:50 +0000
 1.31.2.3 23-Mar-2008  matt sync with HEAD
 1.31.2.2 09-Jan-2008  matt sync with HEAD
 1.31.2.1 06-Nov-2007  matt sync with HEAD
 1.45.2.1 24-Mar-2008  keiichi sync with head.
 1.47.2.2 04-Jun-2008  yamt sync with head
 1.47.2.1 18-May-2008  yamt sync with head.
 1.48.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.48.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.51.22.2 20-Feb-2014  sborrill Pull up the following revisions(s) (requested by prlw1 in ticket #1029):
lib/libpthread/pthread_cond.c: revision 1.62
lib/libpthread/pthread_mutex.c: revision 1.57,1.59

Partial fix for thread deadlock commonly observed with named.
Also address PR/44756.
 1.51.22.1 29-Apr-2013  riz 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.51.6.2 02-Aug-2008  matt Change pthread_mutex_t to use the amount of space as and be congruent to
the version used in the SA version of pthreads. This preserves binary
compatibility between both versions of the library.
 1.51.6.1 02-Aug-2008  matt file pthread_mutex.c was added on branch christos-time_t on 2008-08-02 19:46:31 +0000
 1.51.4.1 20-Feb-2014  sborrill Pull up the following revisions(s) (requested by prlw1 in ticket #1898):
lib/libpthread/pthread_cond.c: revision 1.62
lib/libpthread/pthread_mutex.c: revision 1.57,1.59

Partial fix for thread deadlock commonly observed with named.
Also address PR/44756.
 1.51.2.3 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.51.2.2 30-Oct-2012  yamt sync with head
 1.51.2.1 17-Apr-2012  yamt sync with head
 1.54.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.54.2.1 23-Jun-2013  tls resync from head
 1.60.2.2 04-Nov-2016  pgoyette Sync with HEAD
 1.60.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.64.4.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.64.4.1 10-Jun-2019  christos Sync with HEAD
 1.65.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.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread_mutex.h was initially added on branch nathanw_sa.
 1.1.2.2 13-Jul-2001  nathanw Contents have moved to other headers.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.18 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.17 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.16 07-Dec-2007  ad pthread__mutex_lock_slow: avoid entering the waiters list if a race to
acquire the mutex is lost. Removing the current thread from the waiters
list requires at least one syscall.
 1.15 04-Dec-2007  yamt pthread__mutex_wakeup: ignore ESRCH from _lwp_unpark.
once we clear pt_sleeponq, the target thread can proceed further
and even do pthread_exit.
 1.14 04-Dec-2007  yamt remove unnecessary assignments.
 1.13 27-Nov-2007  ad Fix a warning with _LP64.
 1.12 14-Nov-2007  ad Don't try to block if there are already waiters; it doesn't make sense.
 1.11 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.10 04-Oct-2007  ad branches: 1.10.2;
Fix a thinko.
 1.9 21-Sep-2007  ad Adjust previous for clarity.
 1.8 21-Sep-2007  ad pthread__mutex_unlock_slow: always catch up with deferred wakeups, because
pthread_mutex_unlock clears the per-mutex indicator.
 1.7 13-Sep-2007  ad Add a per-mutex deferred wakeup flag so that threads doing something like
the following do not wake other threads early:

pthread_mutex_lock(&mutex);
pthread_cond_broadcast(&cond);
foo = malloc(100); /* takes libc mutexes */
pthread_mutex_unlock(&mutex);
 1.6 11-Sep-2007  ad Make the new mutexes faster:

- Eliminate mutexattr_private and just set a bit in ptm_owner if the mutex
is recursive. This forces the slow path to be taken for recursive mutexes.
Overload an unused field in pthread_mutex_t to record whether or not it's
an errorcheck mutex.
- Streamline pthread_mutex_lock / pthread_mutex_unlock a bit more. As a
side effect makes it possible to have assembly stubs for them.
 1.5 11-Sep-2007  ad Fix broken pthread_mutex_trylock().
 1.4 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.3 09-Sep-2007  ad branches: 1.3.2;
Fix recursive mutexes to work again in non-threaded applications.
 1.2 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.1 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.3.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.3.2.1 09-Sep-2007  skrll file pthread_mutex2.c was added on branch nick-csl-alignment on 2007-09-10 10:54:06 +0000
 1.10.2.4 23-Mar-2008  matt sync with HEAD
 1.10.2.3 09-Jan-2008  matt sync with HEAD
 1.10.2.2 06-Nov-2007  matt sync with HEAD
 1.10.2.1 04-Oct-2007  matt file pthread_mutex2.c was added on branch matt-armv6 on 2007-11-06 23:11:43 +0000
 1.5 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.4 26-May-2008  wiz branches: 1.4.6;
Sort ERRORS.
 1.3 04-May-2008  martin branches: 1.3.2;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.2 04-Jun-2008  yamt sync with head
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.4.6.2 26-May-2008  wiz Sort ERRORS.
 1.4.6.1 26-May-2008  wiz file pthread_mutex_destroy.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.7 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.6 20-May-2010  jruoho Note the initializer macros.
 1.5 26-May-2008  wiz branches: 1.5.6;
Sort ERRORS.
 1.4 04-May-2008  martin branches: 1.4.2;
Move TNF licenses to 2 clause form
 1.3 21-Mar-2005  kleink branches: 1.3.20;
Add restrict qualifiers to <pthread.h> function arguments.
 1.2 08-Jun-2003  thorpej branches: 1.2.6;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.6.1 22-Mar-2005  tron Pull up revision 1.3 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.3.20.2 04-Jun-2008  yamt sync with head
 1.3.20.1 18-May-2008  yamt sync with head.
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.6.2 26-May-2008  wiz Sort ERRORS.
 1.5.6.1 26-May-2008  wiz file pthread_mutex_init.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.7 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.6 26-May-2008  wiz branches: 1.6.6;
Sort ERRORS.
 1.5 04-May-2008  martin branches: 1.5.2;
Move TNF licenses to 2 clause form
 1.4 04-Jul-2003  wiz branches: 1.4.32;
Drop trailing whitespace.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.4.32.2 04-Jun-2008  yamt sync with head
 1.4.32.1 18-May-2008  yamt sync with head.
 1.5.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.6.6.2 26-May-2008  wiz Sort ERRORS.
 1.6.6.1 26-May-2008  wiz file pthread_mutex_lock.3 was added on branch christos-time_t on 2008-05-26 08:43:58 +0000
 1.4 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.3 04-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 04-May-2008  martin file pthread_mutex_unlock.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.15 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.14 02-Feb-2017  njoly branches: 1.14.24;
Fix a typo : pthread_mutexaddr_init -> pthread_mutexattr_init.
 1.13 05-Jul-2016  wiz branches: 1.13.2; 1.13.4;
Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.12 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.11 08-Jul-2010  jruoho .Xr instaed of .Fn for pthread_mutex_init(3), update the error codes,
cleanup STANDARDS, etc.
 1.10 20-May-2010  jruoho Use a list with the mutex type. Note, from the standard, that recursive
mutexes should be avoided when condition variables are used.
 1.9 11-Apr-2009  wiz Avoid duplicate .Pp.
 1.8 04-May-2008  martin branches: 1.8.8; 1.8.10;
Move TNF licenses to 2 clause form
 1.7 17-Apr-2007  heinz branches: 1.7.12;
Fixed spelling error.
 1.6 17-Jun-2005  wiz New sentence, new line.
 1.5 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.4 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.3 04-Jul-2003  wiz branches: 1.3.4; 1.3.6;
Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.6.2 18-Jun-2005  tron Pull up revision 1.5 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.3.6.1 22-Mar-2005  tron Pull up revision 1.4 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.3.4.1 21-Jun-2005  riz Pull up revision 1.5 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.7.12.1 18-May-2008  yamt sync with head.
 1.8.10.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.8.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.8.8.1 04-May-2008  martin file pthread_mutexattr.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.13.4.1 21-Apr-2017  bouyer Sync with HEAD
 1.13.2.1 20-Mar-2017  pgoyette Sync with HEAD
 1.14.24.1 02-Aug-2025  perseant Sync with HEAD
 1.10 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.9 12-Nov-2012  uwe Refer to init_routine in the DESCRIPTION section with .Fa instead of .Fn
 1.8 12-Nov-2012  uwe Use

.Vt type var No = Dv INITIALIZER;

to provide examples of static initialization in SYNOPSIS section.
.Va macro does the wrong thing (check groff PostScript output) and the
need for .Pp kludge (now dropped) should have been an indication too.

While here move static initialization example to be right after the
declaration of *_init().
 1.7 09-Jul-2010  jruoho branches: 1.7.6; 1.7.12;
Update conformance to the 2001 revision.
 1.6 20-May-2010  jruoho Use similar markup than in pthread_mutex_init(3) etc. with the initializer
macro. Improve wording slightly.
 1.5 16-May-2010  jruoho .Dv.
 1.4 22-Mar-2010  joerg Use .In instead of .Ar Pa
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_once.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.7.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.7.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.5 04-Mar-2025  riastradh pthread_once(3): Add missing memory barriers.

PR lib/59126: pthread_once(3): missing memory ordering
 1.4 12-Feb-2022  riastradh branches: 1.4.4;
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.3 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.2 13-Mar-2012  joerg branches: 1.2.2; 1.2.4;
Move the pthread_once alias where it belongs.
 1.1 12-Mar-2012  joerg Move pthread_once implementation into a separate file, it doesn't depend
on the mutex implementation in any way.
 1.2.4.1 23-Jun-2013  tls resync from head
 1.2.2.3 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.2.2.2 17-Apr-2012  yamt sync with head
 1.2.2.1 13-Mar-2012  yamt file pthread_once.c was added on branch yamt-pagecache on 2012-04-17 00:05:31 +0000
 1.4.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7 19-Apr-2022  rillig lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.6 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.5 05-Oct-2009  rmind Add check to avoid multiple inclusions and redefinitions.
KNF while here.
 1.4 28-Apr-2008  martin branches: 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 18-Jan-2003  christos branches: 1.3.32;
de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Jul-2001  nathanw branches: 1.1.2;
file pthread_queue.h was initially added on branch nathanw_sa.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 13-Jul-2001  nathanw A statically-initializable tail queue, necessary for various pthread
structures.
 1.3.32.1 18-May-2008  yamt sync with head.
 1.4.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4.8.1 28-Apr-2008  martin file pthread_queue.h was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.1 22-Nov-2024  riastradh branches: 1.1.4;
libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Nov-2024  perseant file pthread_ras.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:55 +0000
 1.24 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.23 20-Jan-2007  christos sprinkle volatile.
 1.22 16-Jan-2007  ad For 1:1 threads: __strong_alias(__libc_thr_yield,_sys_sched_yield)
 1.21 08-Jan-2007  drochner bring sched_yield() back which got lost recently
 1.20 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.19 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.18 06-Jan-2005  mycroft branches: 1.18.10; 1.18.12;
Replace the even-odd test for incrementing unblockgen with a simple
blockgen!=unblockgen. I'm not sure this is 100% correct, but it partly
alleviates a problem with multiple unblocks for the same thread getting
stacked up.
 1.17 14-Mar-2004  cl 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.16 16-Jan-2004  cl - delay making a thread unblocked until it's put on the runqueue.
- simplify handling of blocked idle threads.

This should fix the ``assertion "target->pt_state != PT_STATE_RUNNING
|| target->pt_blockgen != target->pt_unblockgen" failed'' problem
reported by Marc Recht and Steve Bellovin on current-users.

Also g/c unused pthread__sched_bulk call left over from pthread_sa.c
rev. 1.22 change.
 1.15 02-Jan-2004  cl logging/debugging changes:
- add PTHREAD_PID_DEBUG which prints the pid before each debuglog line
- output thread returned in pthread__next
- add asserts in pthread__sched akin to asserts in pthread__sched_bulk:
check if scheduled thread is at front/end of queue
- pthread__upcall: output event/interrupted LWP count instead of LWPid
of the first event/interrupted LWP (since unblock upcalls can have
multiple event LWPs).
- pthread__find_interrupted: output LWPid here
 1.14 07-Dec-2003  christos Add pthread_{g,s}etschedparam, that do nothing.
 1.13 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.12 16-Sep-2003  cl fix SA/pthread pagefault failure:
- prevent BLOCKED upcalls on double page faults and during upcalls
- make libpthread handle blocked threads which hold locks
- prevent UNBLOCKED upcalls from overtaking their BLOCKED upcall
this adds a new syscall sa_unblockyield
see also http://mail-index.netbsd.org/tech-kern/2003/09/15/0020.html
 1.11 26-Jun-2003  nathanw Clear pt_trapuc when idling threads.
 1.10 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.9 04-Apr-2003  nathanw Don't call pthread__locked_switch() to switch to ourself. Bad stack
mangling results.

Fixes regression in test yield2, dating to 2003/1/2 when
pthread__locked_switch() was changed to not store the saved-context
pointer until after switching stacks.

Note to self: regression tests exist to be run.
 1.8 08-Mar-2003  lukem add __RCSID()
 1.7 15-Feb-2003  nathanw Adapt to pthread__assert() and remove local debug toggle.
 1.6 31-Jan-2003  tron Add a missing bracket to make this compile.
 1.5 31-Jan-2003  nathanw Add a new internal function, pthread__sched_sleepers(), which iterates
over a sleep queue and puts everything on the run queue. This permits
the iteration to be inside the acquisition of the run queue spinlock,
avoiding repetitive acquire/release cycles.
 1.4 30-Jan-2003  nathanw Set a thread's state to RUNNABLE when yielding.
 1.3 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.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread_run.c was initially added on branch nathanw_sa.
 1.1.2.20 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.19 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.18 16-Dec-2002  nathanw Don't let pthread__sched_idle2 operate on a thread that's part of a
interrupted chain (pt_next != NULL). Clear pt_next when removing an idle
thread from the chain.
 1.1.2.17 14-Nov-2002  nathanw Couple of spinlocks == 0 assertions.
 1.1.2.16 28-Oct-2002  nathanw Implement sched_yield().

Clean up trailing whitespace.
 1.1.2.15 22-Oct-2002  nathanw Use _INITCONTEXT_U() instead of _getucontext_u() to prime a fresh context.
 1.1.2.14 14-Oct-2002  nathanw Oops, correct typos in previous.
 1.1.2.13 14-Oct-2002  nathanw Explicitly clear the UC_USER bit from uc_flags after calling _getcontext_u()
if we're going to call makecontext(), because makecontext() needs to affect
registers other than the caller-save regs.
 1.1.2.12 24-Apr-2002  nathanw Track "Running" state.
 1.1.2.11 08-Feb-2002  nathanw Remove a redundant set of #defines for SDPRINTF.

Wrap per-thread debugging counters in #ifdef PTHREAD__DEBUG.
 1.1.2.10 30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
Add debug logging and assertions.
 1.1.2.9 01-Aug-2001  nathanw Whitespace style.
 1.1.2.8 31-Jul-2001  nathanw No, it turns out we can't have a C pthread__switch().
 1.1.2.7 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.6 25-Jul-2001  nathanw Re-add a necessary include file (should have read those lint errors more
carefully).
 1.1.2.5 20-Jul-2001  nathanw Reduce excessive header inclusion.
 1.1.2.4 17-Jul-2001  nathanw Clean up the state of used idle threads more carefully.
 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.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.18.12.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.18.12.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.18.12.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.18.12.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.18.10.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.7 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.6 05-Jul-2016  wiz Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.5 12-Nov-2012  uwe Mark up (unsupported) PTHREAD_PROCESS_SHARED with .Dv macro.
 1.4 12-Nov-2012  uwe Use

.Vt type var No = Dv INITIALIZER;

to provide examples of static initialization in SYNOPSIS section.
.Va macro does the wrong thing (check groff PostScript output) and the
need for .Pp kludge (now dropped) should have been an indication too.

While here move static initialization example to be right after the
declaration of *_init().
 1.3 09-Jul-2010  wiz branches: 1.3.6; 1.3.12;
Mark up NULL.
 1.2 08-Jul-2010  wiz Add comma in enumeration, sort errors.
 1.1 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.3.12.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.3.6.1 16-Jan-2013  yamt sync with (a bit old) head
 1.44 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.43 11-Feb-2022  riastradh libpthread: Fix membars around rwlocks.

1. After loading self->pt_rwlocked, membar_enter() must not be
conditional on PTHREAD__ATOMIC_IS_MEMBAR because there is no
atomic r/m/w operation here which could imply the acquire barrier.

(This should maybe just be a load-acquire operation, but we don't
have atomic_load_acquire in userland at the moment -- TBD.)

2. Before storing thread->pt_rwlocked, must issue membar_exit() so
that this is a store-release operation -- except if we had just
done an atomic r/m/w and PTHREAD__ATOMIC_IS_MEMBAR is set, in
which case it can be elided.

The second membar_exit() added here might be safely hoisted out of
the loop but I'm not sure -- needs more analysis to prove that
would be safe.
 1.42 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.41 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.40 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.39 05-Feb-2020  kamil Retire ifdef ERRORCHECK in pthread(3)

It is enabled unconditionally since 2003 and used only for rwlocks and
spinlocks.

LLVM sanitizers make assumptions that these checks are enabled always.
 1.38 31-Jan-2020  kamil Refactor libpthread checks for invalid arguments

Switch from manual functions to pthread__error().
 1.37 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.36 16-Dec-2019  uwe pthread__rwlock_spin - clarify the test.

It's more pedantically correct to check RW_WRITE_LOCKED before
obtaining the thread id of the owner. And since there must be an
owner annotate the guard NULL check as unlinkely.

No functional change intended. Ok ad@.
 1.35 15-Dec-2019  uwe _DIAGASSERT that RW_FLAGMASK bits are not set in a thread pointer.

rwlock uses lower bits of a thread pointer for flags in the lock owner
field. Assert that the pointer is properly aligned and those bits are
actually free to use. This may not be the case when a program uses
its own allocator that can return less aligned pointers.
 1.34 03-Jul-2016  christos branches: 1.34.16; 1.34.18;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.33 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.32 25-Oct-2008  yamt branches: 1.32.4; 1.32.20; 1.32.22; 1.32.26;
remove ; after __weak_alias()
 1.31 23-Jun-2008  ad Move call to pthread__self() later.
 1.30 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.29 28-Apr-2008  martin branches: 1.29.2;
Remove clause 3 and 4 from TNF licenses
 1.28 08-Mar-2008  ad branches: 1.28.2;
_pthread_rwlock_held_np: if write locked, only return true if held by
the current thread.
 1.27 10-Feb-2008  ad branches: 1.27.2;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.26 31-Jan-2008  ad pthread_rwlock_wrheld_np: return true only if locked by the calling thread.
 1.25 31-Jan-2008  mlelstv use the correct symbols
 1.24 08-Jan-2008  christos no semis after weak alias.
 1.23 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.22 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.21 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.20 16-Aug-2007  ad branches: 1.20.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.19 04-Aug-2007  ad branches: 1.19.2;
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.18 24-Mar-2007  ad branches: 1.18.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.17 05-Mar-2007  ad Update to match changed pthread__park() interface.
 1.16 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.15 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.14 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.13 19-Oct-2005  chs branches: 1.13.4; 1.13.6;
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.12 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.11 09-Jan-2005  nathanw branches: 1.11.2;
pthread_rwlock_timedrdlock() and pthread_rwlock_timedwrlock():
After exiting the try-again loop, make one more test of the lock
conditions, in case it was released while a signal handler kept the
thread busy past the alarm expiration.
 1.10 09-Jan-2005  nathanw pthread_rwlock_timedrdlock() and pthread_rwlock_timedwrlock():
Expand the test for valid values of abs_timeout to check for negative
values of tv_sec and tv_nsec.
 1.9 03-Aug-2004  yamt pthread_rwlock_timedrdlock/pthread_rwlock_timedwrlock:
fix lock/unlock inversions in ERRORCHECK.
 1.8 03-Aug-2004  yamt pthread_rwlock_timedwrlock: return ETIMEDOUT appropriately.
 1.7 09-Jan-2004  cl branches: 1.7.2;
- add deadlock check to pthread_rwlock_wrlock and pthread_rwlock_timedwrlock
- return EPERM when unlocking a lock which isn't held
=> prevent the failure in PR 24023, where the citrus code had a deadlocking
code path

- remove deadlock check in pthread_rwlock_tryrdlock, return EBUSY instead
=> makes pthread_rwlock_tryrdlock standards compliant
 1.6 24-Nov-2003  cl Update mutex/rwlock/sem code to match recent change in cond code.
 1.5 08-Mar-2003  lukem add __RCSID()
 1.4 15-Feb-2003  nathanw Remove unnecessary inclusion of <assert.h>.
 1.3 31-Jan-2003  nathanw Use pthread__sched_sleepers() instead of iterating over sleep queues
ourself.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Oct-2002  nathanw branches: 1.1.2;
file pthread_rwlock.c was initially added on branch nathanw_sa.
 1.1.2.5 11-Jan-2003  skrll Improve error checking.

OK'd by Nathan.
 1.1.2.4 09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.3 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.2 18-Dec-2002  nathanw Analagous to the fixes in pthread_cond.c, ensure that only one of an
alarm callback or an unlock can remove a thread from a timed lock
sleep and schedule it.

Don't call pthread__alarm_fired() until after pthread__alarm_del().
 1.1.2.1 28-Oct-2002  nathanw Implement POSIX read-write locks.
 1.7.2.2 12-Aug-2004  jmc Pullup rev 1.9 (requested by yamt in ticket #751)

pthread_rwlock_timedrdlock/pthread_rwlock_timedwrlock:
fix lock/unlock inversions in ERRORCHECK.
 1.7.2.1 12-Aug-2004  jmc Pullup rev 1.8 (requested by yamt in ticket #749)

pthread_rwlock_timedwrlock: return ETIMEDOUT appropriately.
 1.11.2.1 01-Nov-2005  jmc Pullup revs 1.12-1.13 (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.13.6.2 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.13.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.13.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.18.2.3 10-Sep-2007  skrll Sync with HEAD.
 1.18.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.18.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.19.2.2 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.19.2.1 04-Aug-2007  ad file pthread_rwlock.c was added on branch matt-mips64 on 2007-08-04 13:37:51 +0000
 1.20.2.3 23-Mar-2008  matt sync with HEAD
 1.20.2.2 09-Jan-2008  matt sync with HEAD
 1.20.2.1 06-Nov-2007  matt sync with HEAD
 1.27.2.1 24-Mar-2008  keiichi sync with head.
 1.28.2.2 04-Jun-2008  yamt sync with head
 1.28.2.1 18-May-2008  yamt sync with head.
 1.29.2.2 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.29.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.32.26.1 23-Jun-2013  tls resync from head
 1.32.22.1 29-Apr-2013  riz 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.32.20.1 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.32.4.2 25-Oct-2008  yamt remove ; after __weak_alias()
 1.32.4.1 25-Oct-2008  yamt file pthread_rwlock.c was added on branch christos-time_t on 2008-10-25 14:14:12 +0000
 1.34.18.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.34.16.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.10 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.9 31-Jan-2008  ad pthread_rwlock_wrheld_np: return true only if locked by the calling thread.
 1.8 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.7 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.6 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.5 21-Sep-2007  ad branches: 1.5.2;
pthread_rwlock_unlock: return EPERM if the caller tries to release a
rwlock that is write held, but not by the caller.
 1.4 21-Sep-2007  ad pthread_rwlock_unlock

- Allow callers to try and release an unheld rwlock. Just return EPERM
as mandated by IEEE Std 1003.1.
- Use pthread__atomic_swap_ptr() to set in the new lock value. At this
point the lock word can't have changed.

pthread__rwlock_wrlock, pthread__rwlock_rdlock:

- Mask out the waiter bits in the lock word before checking to see if
the current thread is about to lock against itself.
 1.3 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.2 08-Sep-2007  ad branches: 1.2.2;
- 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.1 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.2.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.2.2.1 08-Sep-2007  skrll file pthread_rwlock2.c was added on branch nick-csl-alignment on 2007-09-10 10:54:08 +0000
 1.5.2.4 23-Mar-2008  matt sync with HEAD
 1.5.2.3 09-Jan-2008  matt sync with HEAD
 1.5.2.2 06-Nov-2007  matt sync with HEAD
 1.5.2.1 21-Sep-2007  matt file pthread_rwlock2.c was added on branch matt-armv6 on 2007-11-06 23:11:44 +0000
 1.7 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.6 04-May-2008  martin branches: 1.6.8;
Move TNF licenses to 2 clause form
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 04-Jul-2003  wiz Fix SEE ALSO.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.6.8.1 04-May-2008  martin file pthread_rwlock_destroy.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.10 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.9 20-May-2010  jruoho Note the initializer macros.
 1.8 04-May-2008  martin branches: 1.8.8;
Move TNF licenses to 2 clause form
 1.7 17-Jun-2005  wiz branches: 1.7.20;
New sentence, new line.
 1.6 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.5 04-Jul-2003  wiz branches: 1.5.6;
Fix typo.
 1.4 04-Jul-2003  wiz Sort sections.
 1.3 04-Jul-2003  wiz Fix SEE ALSO.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.5.6.1 22-Mar-2005  tron Pull up revision 1.6 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.7.20.1 18-May-2008  yamt sync with head.
 1.8.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.8.8.1 04-May-2008  martin file pthread_rwlock_init.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.11 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.10 04-May-2008  martin branches: 1.10.8;
Move TNF licenses to 2 clause form
 1.9 17-Jun-2005  wiz branches: 1.9.20;
New sentence, new line.
 1.8 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.7 04-Jul-2003  wiz branches: 1.7.6;
Add comma.
 1.6 04-Jul-2003  wiz Remove superfluous word.
 1.5 04-Jul-2003  wiz Fix SEE ALSO.
 1.4 04-Jul-2003  wiz Drop trailing whitespace.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.7.6.1 22-Mar-2005  tron Pull up revision 1.8 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.9.20.1 18-May-2008  yamt sync with head.
 1.10.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.10.8.1 04-May-2008  martin file pthread_rwlock_rdlock.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.8 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.7 04-May-2008  martin branches: 1.7.8;
Move TNF licenses to 2 clause form
 1.6 17-Jun-2005  wiz branches: 1.6.20;
New sentence, new line.
 1.5 04-Jul-2003  wiz Fix SEE ALSO.
 1.4 04-Jul-2003  wiz Drop trailing whitespace.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.6.20.1 18-May-2008  yamt sync with head.
 1.7.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.7.8.1 04-May-2008  martin file pthread_rwlock_unlock.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.9 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.8 04-May-2008  martin branches: 1.8.8;
Move TNF licenses to 2 clause form
 1.7 17-Jun-2005  wiz branches: 1.7.20;
New sentence, new line.
 1.6 21-Mar-2005  kleink Add restrict qualifiers to <pthread.h> function arguments.
 1.5 04-Jul-2003  wiz branches: 1.5.6;
Remove superfluous word.
 1.4 04-Jul-2003  wiz Fix SEE ALSO.
 1.3 04-Jul-2003  wiz Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.5.6.1 22-Mar-2005  tron Pull up revision 1.6 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.7.20.1 18-May-2008  yamt sync with head.
 1.8.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.8.8.1 04-May-2008  martin file pthread_rwlock_wrlock.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.11 10-Feb-2025  riastradh libpthread: Say `restrict', not `__restrict', in man pages.

The private macro __restrict exists only to make .h files work with
legacy C/C++ versions without support for the `restrict' keyword.
It's only distracting to use in a man page.
 1.10 05-Jul-2016  wiz branches: 1.10.28;
Fix some lint.

Too much or too little whitespace;
improve macro usage;
add missing .El;
merge error sections for same error code.
 1.9 03-Jul-2016  christos GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.8 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.7 04-May-2008  martin branches: 1.7.8;
Move TNF licenses to 2 clause form
 1.6 17-Jun-2005  wiz branches: 1.6.20;
New sentence, new line.
 1.5 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.4 04-Jul-2003  wiz branches: 1.4.4; 1.4.6;
Drop trailing whitespace.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.4.6.1 18-Jun-2005  tron Pull up revision 1.5 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.4.4.1 21-Jun-2005  riz Pull up revision 1.5 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.6.20.1 18-May-2008  yamt sync with head.
 1.7.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.7.8.1 04-May-2008  martin file pthread_rwlockattr.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.10.28.1 02-Aug-2025  perseant Sync with HEAD
 1.40 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.39 06-Feb-2007  ad Build without sys/sa.h present.
 1.38 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.37 17-Mar-2005  jwise branches: 1.37.4; 1.37.6;
Lint warning police -- don't use `//' for comments in C code.
 1.36 06-Jan-2005  mycroft Fix a pasto.
 1.35 06-Jan-2005  mycroft Add some additional assertions and debugging printf()s.
 1.34 06-Jan-2005  mycroft Use TIMER_RELTIME rather than the constant 0 in one place.
 1.33 12-Oct-2004  mycroft Remove pt_blockuc. If the debugger attempts to muck with the state of a
blocked thread, return an error; this should be done through ptrace(2).
 1.32 20-Jul-2004  he Cast result of pthread__uc_pc() via intptr_t before using as a pointer.
Fixes compile problem for evbsh5.
 1.31 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.30 14-Mar-2004  cl 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.29 24-Feb-2004  wiz Spell interrupt with two rs. From Peter Postma.
 1.28 24-Feb-2004  wiz occured -> occurred. From Peter Postma.
 1.27 16-Jan-2004  cl - delay making a thread unblocked until it's put on the runqueue.
- simplify handling of blocked idle threads.

This should fix the ``assertion "target->pt_state != PT_STATE_RUNNING
|| target->pt_blockgen != target->pt_unblockgen" failed'' problem
reported by Marc Recht and Steve Bellovin on current-users.

Also g/c unused pthread__sched_bulk call left over from pthread_sa.c
rev. 1.22 change.
 1.26 02-Jan-2004  cl userland part of no-syscall upcall stack return

- add pt_stackinfo to struct __pthread_st
- add pthread__stackinfo_offset returning the offset from ss_sp to
pt_stackinfo
- pass stackinfo_offset to sa_register and set SA_FLAG_STACKINFO to
make the kernel use it
- call pthread__sa_recycle in pthread__resolve_locks; g/c recycleq and
pthread__recycle_bulk
- return stack in pthread__sa_recycle by incrementing sasi_stackgen
- make pthread__sa_recycle debugging output formatting conditional on
pthread__debug_newline
 1.25 02-Jan-2004  cl - libc.so.12.109 and libpthread.so.0.4
- add ssize_t stackinfo_offset argument to sa_register syscall
- remove sa_unblockyield syscall
- make __sigprocmask14 syscall weak
- in pthread__sa_start: catch up with 4-argument sa_register syscall
 1.24 02-Jan-2004  cl pthread__upcall: output LWPid in SA_UPCALL_BLOCKED case
 1.23 02-Jan-2004  cl logging/debugging changes:
- add PTHREAD_PID_DEBUG which prints the pid before each debuglog line
- output thread returned in pthread__next
- add asserts in pthread__sched akin to asserts in pthread__sched_bulk:
check if scheduled thread is at front/end of queue
- pthread__upcall: output event/interrupted LWP count instead of LWPid
of the first event/interrupted LWP (since unblock upcalls can have
multiple event LWPs).
- pthread__find_interrupted: output LWPid here
 1.22 31-Dec-2003  cl Handle block/unblock for threads in critical section without
sa_unblockyield.

XXX g/c sa_unblockyield in kernel later
 1.21 17-Nov-2003  cl - delay processing unblocked threads until after locks are resolved:
without the blocked/unblocked upcall ordering, an interrupted blocked
upcall might put the blocked thread on the intqueue because it needs
to be continued. With the delayed processing, we avoid putting such a
thread twice on the runqueue.
- fix putting a thread on the intqueue when it needs to be continued
after it blocked.

Also check return value when returning a single stack.
 1.20 12-Nov-2003  cl check deferred signals for all unblocked threads
 1.19 29-Oct-2003  cl remove incorrect assert:
regular threads can block in the kernel while holding (libpthread) locks
and have to be continued

XXX if the blocked upcall is preempted, the blocked threads syscall
XXX return value can get lost
 1.18 24-Oct-2003  yamt update a comment.
 1.17 29-Sep-2003  wiz available, not avaliable. From miod@openbsd.
 1.16 16-Sep-2003  cl fix SA/pthread pagefault failure:
- prevent BLOCKED upcalls on double page faults and during upcalls
- make libpthread handle blocked threads which hold locks
- prevent UNBLOCKED upcalls from overtaking their BLOCKED upcall
this adds a new syscall sa_unblockyield
see also http://mail-index.netbsd.org/tech-kern/2003/09/15/0020.html
 1.15 12-Sep-2003  christos convert to use siginfo/ucontext style of signal delivery instead of
sigcontext. Approved by nathanw.
 1.14 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.13 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.12 26-Jun-2003  nathanw Adapt to pt_trapuc: Store context obtained from upcalls there, clear it
in switchto targets and vitims, and print it in debug messages (including
indication of whether a context is trap or user context).

Remove obsolete pt_sleepuc handling.
 1.11 25-Jun-2003  nathanw Complain clearly if SA syscalls aren't avaliable.
 1.10 12-Jun-2003  nathanw In pthread__resolve_locks(), change the conditions for removing a normal
thread from the continuation chain: Not only must it have released all
spinlocks, but it must have signaled completion by finishing pthread__switch
or by having stored into pt_switchto.

Together with the previous pthread_switch.S changes, this fixes a couple of
crasehes caused by race conditions in the examination and use of pt_next,
and by switching to empty pt_switchtouc's.
 1.9 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.8 26-May-2003  nathanw * Recycle upcall stacks as soon as possible rather than waiting to
accumulate half of the total number. There are too many ways for
the SA subsystem to deadlock waiting for stacks that userland has no
reason to recycle.

* Consolidate switchto handling in pthread_resolve_locks().

* Add code to re-chain the preempting parents of switchtos.

* Tweak debuglog output in a couple of cases.
 1.7 08-Mar-2003  lukem add __RCSID()
 1.6 15-Feb-2003  nathanw Adapt to pthread__assert() and remove local debug toggle.
 1.5 30-Jan-2003  nathanw Simplify pthread__upcall() a bit by moving lock resolution before the big
switch statement, and moving upcall-type-specific code into that switch.
Beneficial side effect: don't manipulate a statelock before lock resolution
occurs.
 1.4 25-Jan-2003  nathanw More signal rearranging:

- Signal handlers now simply continue executing the current thread,
rather than trying to put themselves back on the queue that they came
from, which was rather fragile. As a result, all callers of
pthread__block() must be prepared to handle spurious wakeups.

- When a signal arrives for a thread that is blocked in the kernel,
note this in another field in pthread_st and set a flag. Process the
signal and set up the trampoline for the handler *after* the thread
unblocks, so that both the trampoline and the returned state from
the kernel are preserved.

- Factor out some code into a pthread__deliver_signal() routine;
the signal-taking code in pthread_sigmask() should be able to use this
soon.

This is still gross, and there are still some terrible MP issues lurking here,
but progress crawls along.
 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_sa.c was initially added on branch nathanw_sa.
 1.1.2.37 14-Jan-2003  nathanw Clear _UC_SIGMASK from a thread's ucontext; the pthread library has no
desire to reset the sigmask in a setcontext() call.
 1.1.2.36 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.35 30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.34 16-Dec-2002  nathanw Don't let pthread__sched_idle2 operate on a thread that's part of a
interrupted chain (pt_next != NULL). Clear pt_next when removing an idle
thread from the chain.
 1.1.2.33 11-Dec-2002  martin Adapt to siginfo changes - hope this is right, someone please sanit check
it!
 1.1.2.32 01-Nov-2002  thorpej * Default to a 100mS round-robin timer; there are a great many
applications that assume concurrency even on a uniprocessor.
(These applications are, of course, broken, but there's not
much we can do about it.)
* Add pthread_getrrtimer_np() and pthread_setrrtimer_np() functions
which provide access to the round-robin timer to application programs.
Setting the rrtimer to 0 will disable timeslicing.

Per discussion with Loren Rittle (on libstdc++@gcc.gnu.org) and
Nathan Williams (privately). The 100mS default interval is chosen
because timeslicing is largely for user-visible parallelism, and
the 100mS interval results in less overhead while still providing
a reasonable amount of user-visible parallelism.
 1.1.2.31 29-Oct-2002  nathanw Add a note about why PT_RRTIMER_MAGIC doesn't need explicit handling
in sa_upcall().

Fix a couple of err() calls that should be errx().
 1.1.2.30 22-Oct-2002  nathanw Run the alarm queue *after* spinlock resolution, since alarm handling
uses locks.
 1.1.2.29 21-Oct-2002  nathanw Debug-count sigev upcalls.

A little whitespace fiddling.
 1.1.2.28 21-Oct-2002  nathanw Implement a somewhat crude forced round-robin scheduling option,
enabled by setting PTHREAD_RRTIME to the number of milliseconds between
timer events. Makes use of CLOCK_VIRTUAL POSIX timers.
 1.1.2.27 16-Oct-2002  nathanw Track the largest LWP we've seen, to aid debuggers.

(XXX probably better handled with a ptrace query, but that will
require more careful consideration)
 1.1.2.26 31-Aug-2002  nathanw Adapt to the flag argument for sa_register. If the environment
variable PTHREAD_PREEMPT (possiboly a poor choice if name) is set,
then set the flag that requests upcalls whenever a kernel preempt()
event happens. Defaults to off, as this can lead to upcall stack
exhaustion in some pathalogical cases.
 1.1.2.25 20-May-2002  nathanw Set upcall thread state to running upon entering the upcall handler.

Paranoia: remove an upcall from the normal queue before putting it
on the recycle queue.

Reset the next/parent/state fields of an upcall in pthread__sa_recycle().

Lots of whitespace and comment tweaks.
 1.1.2.24 24-Apr-2002  nathanw Track "Running" state.
Help create thread IDs.
Stash the context pointer of blocked threads so that a debugger can
backtrace it.
 1.1.2.23 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.22 19-Feb-2002  nathanw Only run the alarm queue when the siginfo_t has the right magic number.

Run signals after putting resolved threads back on their queues so
that signal handling doesn't have to deal with threads that aren't on
any queue at all.
 1.1.2.21 13-Feb-2002  nathanw In pthread__find_interrupted(), keep idle threads that have set PT_FLAG_IDLED
and that don't need lock resolution off of the resumption queue.
Prevents mangling of the idle queue and losing threads in certain situations.
 1.1.2.20 13-Feb-2002  nathanw Change resumecount to just resume, and don't bother counting threads
that need resumption handling, just whether or not there are any.
 1.1.2.19 08-Feb-2002  nathanw Properly handle idle threads in pthread__resolve_locks().

As always, add some more debugging.
 1.1.2.18 08-Feb-2002  nathanw pthread__resolve_locks(): Make sure that upcalls on the interrupted
queue update the next pointer, so that they're on the queue for the
next pass if there are non-upcalls later in the queue.
 1.1.2.17 08-Feb-2002  nathanw Make pthread__upcall() non-static; it didn't really serve any purpose
for it to be static, and made debugging more annoying.

Wrap counters in #ifdef PTHREAD__DEBUG, so that libpthread builds
when that's not defined.

Add a little bit of debugging information.
 1.1.2.16 28-Jan-2002  nathanw Add SA_SIGEV handling for the alarm queue.

Adjust for cancellation-oriented thread state management.
 1.1.2.15 02-Jan-2002  nathanw Work around the fact that the sa_enable() syscall doesn't really
return from the kernel, but is continued by being jumped to from an
upcall, which can result in stuffing a bogus value into errno.

Fixes errno1 test on i386, and possibly elsewhere.
 1.1.2.14 30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
pt_queue_t -> pthread_queue_t.
 1.1.2.13 17-Nov-2001  nathanw Update for new signal interface.
 1.1.2.12 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.11 25-Sep-2001  nathanw A few more asserts and debuglog entries.
 1.1.2.10 01-Aug-2001  nathanw Add some debugging framework I've been using a lot (can easily be
compiled out).

Bugfix 1: In the new_preempt case, it is possible for victim and
switchto to point to the same thing. Don't but one thread on the
runqueue twice when this happens.

Bugfix 2 (along with changes to pthread_switch.S and pthread_int.h):
Restore the useful ucontext of a thread that is preempted on the
original stack in pthread__locked_switch().
 1.1.2.9 31-Jul-2001  nathanw Clear pt_next and pt_parent for threads that had been making locked
switches.
 1.1.2.8 31-Jul-2001  nathanw It is no longer necessary that a switchto's pt_next and pt_parent be
NULL. In fact, they will often not be null: a thread that hits a
new_preempt case in pthread__locked_switch() or
pthread__upcall_switch() will have itself as its switchto victim.
 1.1.2.7 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.6 24-Jul-2001  nathanw Add an assert() after a /* NOTREACHED */.
 1.1.2.5 19-Jul-2001  nathanw Make an effort to recycle idle threads on every upcall.
Remove some obsolete debugging code.
 1.1.2.4 13-Jul-2001  nathanw Remove obsolete debugging code.
 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.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.37.6.5 04-Jan-2008  wrstuden Add preliminary support for a SA_UPCALL_USER to notice
pending signals. Not fully tested yet as we don't send them.
 1.37.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.37.6.3 25-Sep-2007  wrstuden In preparation for sending ourselves upcalls, keep track of them
(give them a counter) and don't consider receiving one of them
an error.
 1.37.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.37.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.37.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.8 03-Jul-2017  wiz Remove workaround for ancient HTML generation code.
 1.7 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.6 07-Jul-2010  jruoho Xref pthread_attr_getschedparam(3) and sched(3). Use a list for clarity.
 1.5 04-May-2008  martin branches: 1.5.8;
Move TNF licenses to 2 clause form
 1.4 21-Mar-2005  kleink branches: 1.4.20;
Add restrict qualifiers to <pthread.h> function arguments.
 1.3 04-Jul-2003  wiz branches: 1.3.6;
> -> \*[Gt]
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.6.1 22-Mar-2005  tron Pull up revision 1.4 (requested by kleink in ticket #46):
Add restrict qualifiers to <pthread.h> function arguments.
 1.4.20.1 18-May-2008  yamt sync with head.
 1.5.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.5.8.1 04-May-2008  martin file pthread_schedparam.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.5 23-Oct-2017  wiz Remove superfluous Tn.
 1.4 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_self.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.5 09-Jul-2010  jruoho Rationalize by moving

pthread_attr_setname_np(3) to pthread_attr_getname_np(3); and
pthread_setname_np(3) to pthread_getname_np(3).
 1.4 07-Jul-2010  wiz Sort sections.
 1.3 06-Jul-2010  jruoho Fix LIBRARY. Add ERRORS and COMPATIBILITY. And some small improvements.
 1.2 26-May-2008  wiz branches: 1.2.6;
Remove trailing whitespace.
 1.1 14-Dec-2007  yamt branches: 1.1.2; 1.1.6; 1.1.8;
document following functions.
pthread_attr_getname_np
pthread_attr_setname_np
pthread_getname_np
pthread_setname_np
 1.1.8.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.1.6.1 04-Jun-2008  yamt sync with head
 1.1.2.2 09-Jan-2008  matt sync with HEAD
 1.1.2.1 14-Dec-2007  matt file pthread_setname_np.3 was added on branch matt-armv6 on 2008-01-09 01:36:39 +0000
 1.2.6.2 26-May-2008  wiz Remove trailing whitespace.
 1.2.6.1 26-May-2008  wiz file pthread_setname_np.3 was added on branch christos-time_t on 2008-05-26 08:43:42 +0000
 1.4 09-Jul-2010  jruoho Rationalize by moving

pthread_key_delete(3) to pthread_key_create(3); and
pthread_setspecific(3) to pthread_getspecific(3)
 1.3 02-May-2008  martin branches: 1.3.8;
Move TNF licenses to 2 clause form
 1.2 08-Jun-2003  thorpej branches: 1.2.32;
$NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 02-May-2008  martin Move TNF licenses to 2 clause form
 1.3.8.1 02-May-2008  martin file pthread_setspecific.3 was added on branch christos-time_t on 2008-05-02 18:11:05 +0000
 1.50 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.49 22-Jan-2007  christos Add another volatile, mentioned in current-users from a cross-build on amd64.
 1.48 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.47 24-Nov-2006  christos branches: 1.47.2; 1.47.4;
fix spelling of accommodate; from Zapher.
 1.46 12-Jun-2006  chuck sigtimedwait: if we collect a queued signal via pt_siglist, do not
forget to clear it out of pt_siglist, otherwise we will keep getting
it over and over again. fixes a problem introduced in rev 1.43.

problem observed with mysqld where sending it a SIGHUP after it has
set an alarm (e.g. due to some package like rt3 using it) caused the
signal handler thread to go into a tight loop (collecting a SIGALRM
[via sigwait() in mysqld.cc] that would not go away due to the above
issue). mysqld appears to get a SIGHUP when /etc/rc exits, so it
can go into this tight loop after a reboot (but not if you restart
it by hand). the bad sequence is:
/etc/rc runs:
- starts mysqld
- starts web server with rt3 fastcgi starts
- fastcgi/rt3 talks to mysqld (causing it to set an alarm)
- /etc/rc exits, SIGHUP goes to mysqld
- mysqld catches SIGHUP, signal handler thread gets
stuck in loop (database continues to operate, slowly).

you can also trigger the problem by sending mysqld a SIGHUP by hand after
you've caused it to set an alarm by connecting to it.
 1.45 24-Apr-2006  snj It's "its."
 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 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. fixes PR 30348.
 1.42 13-Sep-2005  christos XXX: Work around libpthread's "intimate" connection with libc.
 1.41 26-Jul-2005  christos Revert part of previous; we need to merge acts.sa_mask into our pthread mask.
Thanks martin...
 1.40 26-Jul-2005  christos - removed bogus acts.sa_mask setting.
- unblock the signal we are currently delivering, because it might have
been blocked if we are woken up by another thread.
 1.39 27-Feb-2005  nathanw branches: 1.39.2;
Correct the order of arguments to __sigplusset() in two places to correct
the signal mask experienced by signal handlers in threaded programs.
Fixes regress/lib/libpthread/sigmask3.
 1.38 26-Feb-2005  nathanw 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.37 26-Feb-2005  nathanw Fetch the old signal mask for the signal action whether or not we're
setting a new signal action; this makes sigaction(sig, NULL, &oact)
return a sensible value in the signal mask instead of stack trash.

Addresses PR lib/29536.

XXX the mask seen by signal handlers in a program linked with
libpthread but not yet multithreaded will not reflect masks set here.
 1.36 24-Aug-2004  nathanw Mark when a thread has taken a signal.
 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 24-Mar-2004  lha Fix a problem where pthread_kill can set a signal while the process
have the signal blocked, this ends up making target thread getting
later stuck in a loop if it uses pthread_sigmask.

ok, cl and christos
 1.33 02-Jan-2004  cl make siglongjmp out of a signal handler work:
- strong alias __sigprocmask14 to pthread_sigmask
- call _sys___sigprocmask14 where appropriate
- make pthread_sigmask not set the signal mask lazily when pthreads
aren't started yet
 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 25-Nov-2003  cl Save the old mask in the old context, not in the new one.
 1.30 25-Nov-2003  cl Honor SA_NODEFER in pthread__deliver_signal(). This should help code which
makes a longjmp out of a signal handler.

Also add missing si_code argument to debugging printf in pthread__kill().
 1.29 25-Nov-2003  christos GC sigcontext<->mcontext code and __HAVE_SIGINFO. All supported archs have
siginfo implemented.
 1.28 25-Nov-2003  christos - don't store sigmask on the stack, we could store it in the right place
[in the context]
- this has the side effect of fixing the problem of the signal mask not
being preserved properly upon signal return, found and fixed by cl.
- add si_code to the tramp debugging output (requested by cl).
 1.27 20-Nov-2003  uwe Follow-up to previous. In pthread__signal_tramp() maskp is below
siginfo on the stack, so get it from there. ss_sp no longer points to
the the mask. Pointed out by cl@.
 1.26 20-Nov-2003  uwe Undo previous. In pthread__deliver_signal set uc->uc_stack.ss_sp = uc;
(as it used to be before 1.1.2.12) so that makecontext doesn't stomp
on the data we allocated on the stack. Correct the debugging printf
to print olduc instead of target->pt_uc (we have pt_trapuc now, and
olduc can be pt_trapuc).
 1.25 20-Nov-2003  yamt pthread__deliver_signal: swap oldmask and siginfo so that signal
handler's stack doesn't stomp siginfo.
this also fixes !__HAVE_SIGINFO, in that case
pthread__signal_tramp assumes uc->uc_stack.ss_sp points the old
signal mask.

pointed by uwe@.
 1.24 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.23 16-Oct-2003  yamt in pthread__deliver_signal(),
copy siginfo_t into the stack of the target thread
rather than relying on the luck that on-stack siginfo_t stay valid.
 1.22 13-Sep-2003  christos fix syntax; thanks aymeric
 1.21 13-Sep-2003  christos explicitly use a sigset_t * variable to recover the signal mask pointer.
 1.20 12-Sep-2003  drochner make it compile with PTHREAD_SIG_DEBUG again
 1.19 12-Sep-2003  kleink Fix pasto in previous.
 1.18 12-Sep-2003  christos convert to use siginfo/ucontext style of signal delivery instead of
sigcontext. Approved by nathanw.
 1.17 22-Aug-2003  nathanw In pthread__deliver_signal(), correctly use pt_trapuc or pt_uc as the
context-to-restore instead of always using pt_uc.

Fixes a problem with signal handlers for synchronous signals noted by
Matthias Drochner on current-users.
 1.16 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.15 17-Jul-2003  fvdl Take the normal return path in sigtimedwait when the current thread was
canceled as well. From Stephan Uphoff.
 1.14 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.13 20-Mar-2003  nathanw Use pthread__assert() instead of plain assert(), as the latter has
locking issues.
 1.12 14-Mar-2003  nathanw Add a wrapper for the execve() system call that arranges for the current
thread sigal mask to be propagated into the new process image.
 1.11 08-Mar-2003  lukem add __RCSID()
 1.10 28-Feb-2003  lha If pthreads hasn't started yet when calling sigsuspend, use the systemcall
 1.9 15-Feb-2003  jdolecek interposition sigtimedwait() with a thread-aware version, which uses
single proxy thread to do the actual syscall, and blocks other threads
in userland
 1.8 15-Feb-2003  nathanw Move debug toggle to pthread_debug.h.
 1.7 30-Jan-2003  nathanw More rototilling:

* Implement pthread_kill().

* Return the old thread mask, not the old process mask, in our
interpositioned sigaction call.

* Refer to _NSIG, not NSIG.

* Gut pthread_sigmask(). It was handling a lot of corner cases that
weren't legal anyway. Handle unblocked signals with a new
pthread__kill_self() routine (also used by pthread_kill()).

* Be more consistent with locking around pt_sigacts[].
 1.6 28-Jan-2003  jdolecek __sigaction14(): sanity check 'sig' before use, same way as sigaction1()
in kernel
 1.5 25-Jan-2003  nathanw More signal rearranging:

- Signal handlers now simply continue executing the current thread,
rather than trying to put themselves back on the queue that they came
from, which was rather fragile. As a result, all callers of
pthread__block() must be prepared to handle spurious wakeups.

- When a signal arrives for a thread that is blocked in the kernel,
note this in another field in pthread_st and set a flag. Process the
signal and set up the trampoline for the handler *after* the thread
unblocks, so that both the trampoline and the returned state from
the kernel are preserved.

- Factor out some code into a pthread__deliver_signal() routine;
the signal-taking code in pthread_sigmask() should be able to use this
soon.

This is still gross, and there are still some terrible MP issues lurking here,
but progress crawls along.
 1.4 24-Jan-2003  jdolecek unlock pt_statelock _after_ changing pt_state, not before
problem found and fix suggested by Nick Hudson
 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_sig.c was initially added on branch nathanw_sa.
 1.1.2.28 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.27 14-Jan-2003  nathanw Subtract off STACKSPACE *before* using space on the victim's
stack. Overwriting the contents of STACKSPACE with a signal mask has
bad side effects.
 1.1.2.26 09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.25 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.24 03-Jan-2003  nathanw Silent failures are annoying.
Sprinkle some assert(0) after NOTREACHED points.
 1.1.2.23 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.22 20-Dec-2002  thorpej Include <stdint.h> to ensure we have uintptr_t.
 1.1.2.21 19-Dec-2002  thorpej If _UC_UCONTEXT_ALIGN is defined, use it to align the ucontext_t
that is used to provide the signal delivery context.

(This is only needed because we're using our own userland versions
of the context routines; this is not needed if we use the kernel
versions of the routines...)
 1.1.2.20 02-Nov-2002  nathanw In pthread_sigmask(), be careful to only unlock the spinlocks that
were locked.
 1.1.2.19 27-Oct-2002  thorpej Cosmetic changes.
 1.1.2.18 22-Oct-2002  nathanw Use _INITCONTEXT_U() instead of _getucontext_u() to prime a fresh context.
 1.1.2.17 16-Oct-2002  nathanw In pthread__signal(), lock the pt_siglock of a directly-targeted
thread.
 1.1.2.16 14-Oct-2002  nathanw Oops, correct typos in previous.
 1.1.2.15 14-Oct-2002  nathanw Explicitly clear the UC_USER bit from uc_flags after calling _getcontext_u()
if we're going to call makecontext(), because makecontext() needs to affect
registers other than the caller-save regs.
 1.1.2.14 02-Oct-2002  thorpej libc:
Internally rename __sigaction14 to __libc_sigaction14. Provide a
weak alias of __sigaction14 -> __libc_sigaction14.

libpthread:
Use __libc_sigaction14 to actually register the signal handler, rather
than using __sigaction_sigtramp() directly with a hard-coded trampoline
version. While we don't actually use the libc trampoline, we want to
avoid depending on any COMPAT_* kernel options down the road (this is
already the case for the VAX port).

Be explicit about which version of the signal interface we're interposing
(...14), and build pthread_sig.c with __LIBC12_SOURCE__ (required to get
the libc-internal interfaces).
 1.1.2.13 02-Aug-2002  nathanw Adapt to new syscall stubs for sigaction override.
Use SIGCATCH flag instead of special-casing the sigsuspended queue.
 1.1.2.12 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.11 24-Apr-2002  nathanw Track "Running" state.
 1.1.2.10 11-Apr-2002  nathanw Revert weak aliases.
 1.1.2.9 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.8 19-Feb-2002  nathanw Carefully lock queues when manipulating threads taking signals.
Handle signals beling delivered to queie-locked threads.
 1.1.2.7 30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
 1.1.2.6 26-Nov-2001  nathanw Whitespace cleanup (including removal of some weird one-column
indents).
 1.1.2.5 17-Nov-2001  nathanw Clean up and update for new signal interface.
 1.1.2.4 25-Sep-2001  nathanw Comment more verbosely and correctly.
Set the size of the stack-adjust better.
 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.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.39.2.4 13-Jun-2006  tron Pull up following revision(s) (requested by chuck in ticket #1376):
lib/libpthread/pthread_sig.c: revision 1.46
sigtimedwait: if we collect a queued signal via pt_siglist, do not
forget to clear it out of pt_siglist, otherwise we will keep getting
it over and over again. fixes a problem introduced in rev 1.43.
problem observed with mysqld where sending it a SIGHUP after it has
set an alarm (e.g. due to some package like rt3 using it) caused the
signal handler thread to go into a tight loop (collecting a SIGALRM
[via sigwait() in mysqld.cc] that would not go away due to the above
issue). mysqld appears to get a SIGHUP when /etc/rc exits, so it
can go into this tight loop after a reboot (but not if you restart
it by hand). the bad sequence is:
/etc/rc runs:
- starts mysqld
- starts web server with rt3 fastcgi starts
- fastcgi/rt3 talks to mysqld (causing it to set an alarm)
- /etc/rc exits, SIGHUP goes to mysqld
- mysqld catches SIGHUP, signal handler thread gets
stuck in loop (database continues to operate, slowly).
you can also trigger the problem by sending mysqld a SIGHUP by hand after
you've caused it to set an alarm by connecting to it.
 1.39.2.3 01-Nov-2005  jmc branches: 1.39.2.3.2;
Pullup revs 1.43-1.44 (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.39.2.2 12-Aug-2005  snj Pull up revision 1.41 (requested by christos in ticket #642):
Revert part of previous; we need to merge acts.sa_mask into our pthread mask.
Thanks martin...
 1.39.2.1 12-Aug-2005  snj Pull up revision 1.40 (requested by christos in ticket #642):
- removed bogus acts.sa_mask setting.
- unblock the signal we are currently delivering, because it might have
been blocked if we are woken up by another thread.
 1.39.2.3.2.1 13-Jun-2006  tron Pull up following revision(s) (requested by chuck in ticket #1376):
lib/libpthread/pthread_sig.c: revision 1.46
sigtimedwait: if we collect a queued signal via pt_siglist, do not
forget to clear it out of pt_siglist, otherwise we will keep getting
it over and over again. fixes a problem introduced in rev 1.43.
problem observed with mysqld where sending it a SIGHUP after it has
set an alarm (e.g. due to some package like rt3 using it) caused the
signal handler thread to go into a tight loop (collecting a SIGALRM
[via sigwait() in mysqld.cc] that would not go away due to the above
issue). mysqld appears to get a SIGHUP when /etc/rc exits, so it
can go into this tight loop after a reboot (but not if you restart
it by hand). the bad sequence is:
/etc/rc runs:
- starts mysqld
- starts web server with rt3 fastcgi starts
- fastcgi/rt3 talks to mysqld (causing it to set an alarm)
- /etc/rc exits, SIGHUP goes to mysqld
- mysqld catches SIGHUP, signal handler thread gets
stuck in loop (database continues to operate, slowly).
you can also trigger the problem by sending mysqld a SIGHUP by hand after
you've caused it to set an alarm by connecting to it.
 1.47.4.8 03-May-2008  wrstuden pthread_kill() won't correctly deliver signals to a thread that is
in sigwait() waiting for them. Problem is we need to kick
the "master" waiter out of the kernel, and it has to correctly
handle this. It either has to realize we now have a signal we were
waiting for, or we have to ignore it (and keep waiting for other
signals).

Do it.

Fixes PR kern/30348 even though it's totally a library bug.
 1.47.4.7 04-Nov-2007  wrstuden Add an #ifdef PTHREAD__DEBUG variable, __pthread_running_kills. Incriment
it each time we kill a running thread. Will be used by a new regression test
to verify the defsig code.
 1.47.4.6 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.47.4.5 25-Sep-2007  wrstuden Add code to handle delivering a signal to a running thread. At present,
it only adds the signal to the blocked set for the thread. This
change does not add support for the kernel preempting the thread. A minor
detail is that the upcall handler doesn't handle it right yet. The main
reason is so that we can test to see if the signal catching code that
I recently sprinkled throught the library actually works right.
 1.47.4.4 25-Sep-2007  wrstuden Fix a comment about MP locking. Remove it and adapt the code
to close a race window. Only grab the target's state lock at most once;
don't lock it, release it, then lock it again. Remember if we locked it
early.
 1.47.4.3 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.47.4.2 11-Sep-2007  wrstuden While examining the target's state, grab the target's statelock,
not our own.
 1.47.4.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.47.2.3 10-Apr-2009  snj Apply patch (requested by dholland in ticket #1301):
In the pthreads wrapper for __sigaction14, return -1 and set errno
rather than returning an error number directly like many pthreads
functions do. Fixes a problem where sigaction(-1, ...) returns
EINVAL instead of failing with EINVAL, reported by Matteo Beccati
in PR lib/41085.
 1.47.2.2 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.47.2.1 25-Sep-2007  xtraeme Pull up following revision(s) (requested by wrstuden in ticket #892):
lib/libpthread/pthread_sig.c: revision 1.47.4.2

While examining the target's state, grab the target's statelock,
not our own.
 1.9 09-Jul-2010  wiz Mark up NULL.
 1.8 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.7 04-May-2008  martin branches: 1.7.8;
Move TNF licenses to 2 clause form
 1.6 07-Jan-2006  kleink branches: 1.6.20;
pthread_sigmask(): Add restrict qualifier to set, oset args.
 1.5 30-Oct-2003  wiz sigwait(2), not (3).
 1.4 30-Oct-2003  jdolecek bump date too
 1.3 30-Oct-2003  jdolecek xref sigwait(3)
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.6.20.1 18-May-2008  yamt sync with head.
 1.7.8.2 04-May-2008  martin Move TNF licenses to 2 clause form
 1.7.8.1 04-May-2008  martin file pthread_sigmask.3 was added on branch christos-time_t on 2008-05-04 19:43:06 +0000
 1.9 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.8 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.7 19-Apr-2005  nathanw branches: 1.7.4; 1.7.6;
Avoid passing along a timespec with a negative number of seconds if
the current time plus the caller-supplied time to sleep wraps the
time_t. Instead, sleep until INT_MAX.
 1.6 06-Jan-2005  mycroft branches: 1.6.2;
gettimeofday();TIMEVAL_TO_TIMESPEC(); is exactly equivalent to
clock_gettime(CLOCK_REALTIME), except the latter may have more preicison
some day. So, use that.
 1.5 24-Aug-2004  nathanw In nanosleep(), loop until the timer fires or a signal is taken; other
spurious wakeups (such as those caused by gdb) should not cause
nanosleep to return prematurely.
 1.4 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.3 24-Jun-2004  nathanw If the sleep sleeps for its full time and rmtp is non-NULL, clear it;
sleep(3) expects this, even though it's not a documented property of
nanosleep().

Fixes a problem where sleep() in a threaded program would return
nonzero even on success.
 1.2 08-Mar-2003  lukem branches: 1.2.4;
add __RCSID()
 1.1 15-Feb-2003  nathanw Implement nanosleep() at userlevel. Threaded applications seem to like
to sleep a lot, and there's no need for each such thread to consume kernel
resources.

(accidentally checked the pthread.c part of this in yesterday; no reason
not to finish the job)
 1.2.4.1 12-May-2005  riz Pull up revision 1.7 (requested by nathanw in ticket #1443):
Avoid passing along a timespec with a negative number of seconds if
the current time plus the caller-supplied time to sleep wraps the
time_t. Instead, sleep until INT_MAX.
 1.6.2.1 21-Apr-2005  tron Pull up revision 1.7 (requested by nathanw in ticket #181):
Avoid passing along a timespec with a negative number of seconds if
the current time plus the caller-supplied time to sleep wraps the
time_t. Instead, sleep until INT_MAX.
 1.7.6.2 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.7.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.7.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.28 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.27 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.26 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.25 06-Mar-2013  yamt add assertions
 1.24 21-Nov-2012  christos Replace the simple implementation of pthread_key_{create,destroy}
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.
 1.23 12-Sep-2012  matt Only copy the ucontext_t in pthread_setcontext if _UC_TLSBASE is set.
Conditionalize the test on _UC_TLSBASE being defined.
 1.22 12-Sep-2012  manu branches: 1.22.2;
setcontext() used to be incompatible with -lpthread since it affected
the TLS pointer, therefore wrecking the pthread environement.

Some ports had _UC_TLSBASE flag or equivalent (_UC_UNIQUE on alpha)
that controlled whether setcontext() would change the TLS pointer.
This change let libpthread override setcontext() with its own version
that unsets _UC_TLSBASE, enabling safe usage of setcontext() with
-lpthread.

We also have the following required changes here:
- rename alpha's _UC_UNIQUE into _UC_TLSBASE
- add _UC_TLSBASE definition in header file for all ports
(powerpc, sh3, sparc and sparc64 lack the implementation for now)
- introduce a libc stub that can be overriden for setcontext()
- modify MD libcs swapcontext() implementations so that they use the
setcontext() libc stub instead of doing a plain system call.

While we are there:
- document various MD _UC_* flags in header file
- add libc and libpthread tests for swapcontext() behavior
(hopefully helpful to spot MD problems introduced with this change)

Future work:
- Deciding whether kernel support or _UC_TLSBASE should be added for
powerpc, sh3, sparc and sparc64 is left to portmasters
sparc64

Approved by core@
 1.21 23-Jun-2008  ad branches: 1.21.2; 1.21.6; 1.21.22;
pthread_curcpu_np: remove hack for pthread_dummy_lwpctl.
 1.20 28-Apr-2008  martin branches: 1.20.2;
Remove clause 3 and 4 from TNF licenses
 1.19 22-Mar-2008  ad branches: 1.19.2;
Back out previous. It seems to expose another bug in libpthread/libc,
potentially errno being used before threading is up and running.
 1.18 21-Mar-2008  ad Move pthread__errno() into pthread_specific.c so it gets the "no stack
frame" treatment.
 1.17 08-Jan-2008  christos cast -1 to unsigned int.
 1.16 07-Jan-2008  yamt pthread_curcpu_np: map LWPCTL_CPU_NONE to 0 so that this works in the case
of _lwp_ctl failure.
 1.15 07-Dec-2007  ad Back out previous now that libc/libpthread are initialized first.
 1.14 01-Dec-2007  ad Hack around ld.so initializing pthread users before libpthread/libc.
 1.13 27-Nov-2007  ad Add thr_curcpu(), pthread_curcpu_np().
 1.12 13-Nov-2007  ad Cosmetic change.
 1.11 16-Aug-2007  ad branches: 1.11.2;
- 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.10 13-Aug-2003  nathanw branches: 1.10.20;
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.9 17-Jul-2003  nathanw Don't use PTHREAD_DESTRUCTOR_ITERATIONS; the constant is going away.
 1.8 15-May-2003  wiz Fix typo in comment.
 1.7 15-May-2003  nathanw Remove an unnecessary test in pthread_getspecific().
 1.6 08-Mar-2003  lukem add __RCSID()
 1.5 15-Feb-2003  nathanw Remove unused #include <assert.h>
 1.4 21-Jan-2003  nathanw Don't bother acquiring the tsd_lock and reading the destructor function
if the corresponding TSD entry is empty.

Cuts down lock/unlock pairs for this operation from 256 to the number
of active TSD entries; sicne this is done when every thread exits, it saves
many total lock/unlock pairs.
 1.3 18-Jan-2003  christos de-lint
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 08-Aug-2001  nathanw branches: 1.1.2;
file pthread_specific.c was initially added on branch nathanw_sa.
 1.1.2.9 09-Jan-2003  thorpej Remove trailing semicolon from __strong_alias().
 1.1.2.8 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.7 07-Oct-2002  nathanw Protect operations on the destructor array with mutexes.

Add a lot of verbiage about how broken the specification of
pthread_key_delete() is, and change the implementation to the
least-damaging option: clearing the destructor and not permitting key
reuse.
 1.1.2.6 26-Apr-2002  nathanw Make the names of the thread-specific data arrays visible.
 1.1.2.5 11-Apr-2002  nathanw Revert weak aliases.
 1.1.2.4 25-Mar-2002  nathanw Provide interfaces to libc.
 1.1.2.3 01-Mar-2002  nathanw Add a comment noting the dissent about what pthread_key_delete() should
really do.
 1.1.2.2 30-Dec-2001  nathanw pt_spin_t -> pthread_spin_t.
 1.1.2.1 08-Aug-2001  nathanw Implement thread-specific data.
 1.10.20.1 03-Sep-2007  skrll Sync with HEAD.
 1.11.2.2 23-Mar-2008  matt sync with HEAD
 1.11.2.1 09-Jan-2008  matt sync with HEAD
 1.19.2.1 18-May-2008  yamt sync with head.
 1.20.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.21.22.3 29-Apr-2013  riz 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.21.22.2 02-Dec-2012  riz Back out ticket #724 (libpthread changes) until they can be better
understood, as they broke threaded programs on (at least) i386 and amd64.
 1.21.22.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #724):
lib/libpthread/pthread_specific.c: revision 1.24
lib/libpthread/pthread_tsd.c: revision 1.10
lib/libpthread/pthread_tsd.c: revision 1.9
lib/libpthread/pthread_int.h: revision 1.88
Replace the simple implementation of pthread_key_{create,destroy}
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.
Don't call the destructor in pthread_key_delete() following the standard.
 1.21.6.2 23-Jun-2008  ad pthread_curcpu_np: remove hack for pthread_dummy_lwpctl.
 1.21.6.1 23-Jun-2008  ad file pthread_specific.c was added on branch christos-time_t on 2008-06-23 10:38:40 +0000
 1.21.2.3 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.21.2.2 16-Jan-2013  yamt sync with (a bit old) head
 1.21.2.1 30-Oct-2012  yamt sync with head
 1.22.2.3 23-Jun-2013  tls resync from head
 1.22.2.2 25-Feb-2013  tls resync with head
 1.22.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.6 22-Oct-2017  abhinav Add missing function names in the NAME section for rest of the man pages in libpthread
 1.5 09-Jul-2010  wiz Mark up NULL.
 1.4 09-Jul-2010  wiz Remove empty line.
 1.3 08-Jul-2010  jruoho Add some remarks and clarifications, simplify RETURN VALUES, grammar, etc.
 1.2 08-Jul-2010  wiz Add comma in enumeration, remove Xr to itself from SEE ALSO.
 1.1 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.11 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.10 10-Apr-2022  riastradh branches: 1.10.2;
pthread: Nix trailing whitespace.
 1.9 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.8 05-Feb-2020  kamil Retire ifdef ERRORCHECK in pthread(3)

It is enabled unconditionally since 2003 and used only for rwlocks and
spinlocks.

LLVM sanitizers make assumptions that these checks are enabled always.
 1.7 31-Jan-2020  kamil Refactor libpthread checks for invalid arguments

Switch from manual functions to pthread__error().
 1.6 16-Aug-2012  matt branches: 1.6.24; 1.6.32; 1.6.34;
Add a pthread__smt_wake and add support for it on arm along with
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.
 1.5 28-Apr-2008  martin branches: 1.5.4; 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 05-Jan-2008  ad branches: 1.4.4;
machine/lock.h, not sys/lock.h
 1.3 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.2 10-Sep-2007  skrll Merge nick-csl-alignment.
 1.1 16-Aug-2007  ad branches: 1.1.2; 1.1.4;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.1.4.3 10-Sep-2007  skrll Fix inverted test.
 1.1.4.2 03-Sep-2007  skrll Sync with HEAD.
 1.1.4.1 16-Aug-2007  skrll file pthread_spin.c was added on branch nick-csl-alignment on 2007-09-03 10:14:16 +0000
 1.1.2.2 09-Jan-2008  matt sync with HEAD
 1.1.2.1 06-Nov-2007  matt sync with HEAD
 1.4.4.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_spin.c was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.5.4.1 30-Oct-2012  yamt sync with head
 1.6.34.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.6.32.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.6.24.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.10.2.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.7 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.6 26-May-2008  wiz branches: 1.6.6;
Sort sections. Use more markup.
 1.5 26-May-2008  ad Note that apps with real-time threads shouldn't use spinlocks because of
the danger of deadlock, and note that in general spinlocks suck and mutexes
should be used instead!
 1.4 30-Apr-2008  martin branches: 1.4.2;
Convert TNF licenses to new 2 clause variant
 1.3 17-Jun-2005  wiz branches: 1.3.20;
New sentence, new line.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.3.20.2 04-Jun-2008  yamt sync with head
 1.3.20.1 18-May-2008  yamt sync with head.
 1.4.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.6.6.2 26-May-2008  wiz Sort sections. Use more markup.
 1.6.6.1 26-May-2008  wiz file pthread_spin_destroy.3 was added on branch christos-time_t on 2008-05-26 08:45:56 +0000
 1.9 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.8 26-May-2008  wiz branches: 1.8.6;
Sort sections. Use more markup.
 1.7 26-May-2008  ad Note that apps with real-time threads shouldn't use spinlocks because of
the danger of deadlock, and note that in general spinlocks suck and mutexes
should be used instead!
 1.6 30-Apr-2008  martin branches: 1.6.2;
Convert TNF licenses to new 2 clause variant
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 17-Jun-2005  peter Fix various spelling errors.

From Igor Sobrado in PR/29997.
 1.3 04-Jul-2003  wiz branches: 1.3.4; 1.3.6;
Drop trailing whitespace.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.3.6.1 18-Jun-2005  tron Pull up revision 1.4 (requested by peter in ticket #473):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.3.4.1 21-Jun-2005  riz Pull up revision 1.4 (requested by peter in ticket #2002):
Fix various spelling errors.
From Igor Sobrado in PR/29997.
 1.5.20.2 04-Jun-2008  yamt sync with head
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 26-May-2008  wiz Sort sections. Use more markup.
 1.8.6.1 26-May-2008  wiz file pthread_spin_init.3 was added on branch christos-time_t on 2008-05-26 08:45:56 +0000
 1.9 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.8 26-May-2008  wiz branches: 1.8.6;
Sort sections. Use more markup.
 1.7 26-May-2008  ad Note that apps with real-time threads shouldn't use spinlocks because of
the danger of deadlock, and note that in general spinlocks suck and mutexes
should be used instead!
 1.6 30-Apr-2008  martin branches: 1.6.2;
Convert TNF licenses to new 2 clause variant
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 04-Jul-2003  wiz New sentence, new line.
 1.3 04-Jul-2003  wiz Fix SEE ALSO.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.5.20.2 04-Jun-2008  yamt sync with head
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 26-May-2008  wiz Sort sections. Use more markup.
 1.8.6.1 26-May-2008  wiz file pthread_spin_lock.3 was added on branch christos-time_t on 2008-05-26 08:45:56 +0000
 1.9 08-Jul-2010  rmind Merge/group man pages:
- pthread_barrier_{init,destroy,wait} into pthread_barrier(3).
- pthread_cond_* into pthread_cond(3).
- pthread_mutex_* into pthread_mutex(3).
- pthread_rwlock_* into pthread_rwlock(3).
- pthread_spin_* into pthread_spin(3).
Cross-link amongst groups.
OK jruoho@
 1.8 26-May-2008  wiz branches: 1.8.6;
Sort sections. Use more markup.
 1.7 26-May-2008  ad Note that apps with real-time threads shouldn't use spinlocks because of
the danger of deadlock, and note that in general spinlocks suck and mutexes
should be used instead!
 1.6 30-Apr-2008  martin branches: 1.6.2;
Convert TNF licenses to new 2 clause variant
 1.5 17-Jun-2005  wiz branches: 1.5.20;
New sentence, new line.
 1.4 04-Jul-2003  wiz Fix SEE ALSO.
 1.3 01-Jul-2003  wiz We do not want empty lines in mdoc.
 1.2 08-Jun-2003  thorpej $NetBSD$, not $Header$.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, written by Stephen Degler.
 1.5.20.2 04-Jun-2008  yamt sync with head
 1.5.20.1 18-May-2008  yamt sync with head.
 1.6.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 26-May-2008  wiz Sort sections. Use more markup.
 1.8.6.1 26-May-2008  wiz file pthread_spin_unlock.3 was added on branch christos-time_t on 2008-05-26 08:45:56 +0000
 1.22 16-Aug-2007  ad Remove PT_FIXEDSTACKSIZE_LG.
 1.21 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.20 02-Mar-2007  ad branches: 1.20.2;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.19 20-Jan-2007  christos add casts to pacify lint.
 1.18 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.17 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.16 17-Aug-2004  chs redo the fix for PR 26392 differently: instead of changing the stack bounds
for the initial stack, just change the initial thread's pt_uc to point to
the opposite end of the stack (away from the argv, environment, etc).
 1.15 25-Jul-2004  chs in pthread__initmain(), don't reuse the part of the initial stack that
is occupied by the argv and environment (and MD stuff like the page-table
mapping on x86). fixes PR 26392.
 1.14 20-Jul-2004  chs fix some stack-pointer math in the previous revision.
 1.13 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.12 14-Mar-2004  cl branches: 1.12.2;
fix comment for recent pthread_stack* var rename
 1.11 02-Feb-2004  nathanw Rename pt_stacksize, pt_stacksize_lg, and pt_stackmask to pthread_*. External
symbols can't start with pt_, as that is in the application namespace.
 1.10 02-Jan-2004  cl userland part of no-syscall upcall stack return

- add pt_stackinfo to struct __pthread_st
- add pthread__stackinfo_offset returning the offset from ss_sp to
pt_stackinfo
- pass stackinfo_offset to sa_register and set SA_FLAG_STACKINFO to
make the kernel use it
- call pthread__sa_recycle in pthread__resolve_locks; g/c recycleq and
pthread__recycle_bulk
- return stack in pthread__sa_recycle by incrementing sasi_stackgen
- make pthread__sa_recycle debugging output formatting conditional on
pthread__debug_newline
 1.9 27-Nov-2003  cl Set default stack size to the current limit on the stack size as set
with the shell's command to change limits. Make the PTHREAD_STACKSIZE
environment variable override the default stack size. The old fixed
stack size behaviour can be enable with PT_FIXEDSTACKSIZE_LG when building
libpthread.
 1.8 17-Jul-2003  nathanw Simplify pthread__stackalloc() by using the newish aligned-mmap()
feature.
 1.7 08-Mar-2003  lukem add __RCSID()
 1.6 15-Feb-2003  nathanw Remove unnecessary inclusion of <assert.h>.
 1.5 19-Jan-2003  thorpej Remove the dummy stack attr routines -- best to catch broken applications
and fix them to use the proper feature test instead (as has already been
done with the openldap package).
 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_stack.c was initially added on branch nathanw_sa.
 1.1.2.9 20-Dec-2002  thorpej Include <stdint.h> to ensure we have uintptr_t.
 1.1.2.8 20-Dec-2002  nathanw Align space for new ucontext_t, if necessary.
 1.1.2.7 03-Nov-2002  skrll Remove trailing newlines.
 1.1.2.6 27-Oct-2002  thorpej Cosmetic changes.
 1.1.2.5 04-Sep-2002  nathanw Use mprotect(PROT_NONE) instead of munmap() to mark the thread stack
red zone.

Problem pointed out by Joel Schopp.
 1.1.2.4 25-Jul-2001  nathanw Remove an unused variable.
 1.1.2.3 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2 13-Jul-2001  nathanw Use munmap() to redzone-protect the end of the stack allocations.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.12.2.2 22-Aug-2004  tron Pull up revision 1.16 via patch (requested by chs in ticket #768):
redo the fix for PR 26392 differently: instead of changing the stack bounds
for the initial stack, just change the initial thread's pt_uc to point to
the opposite end of the stack (away from the argv, environment, etc).
 1.12.2.1 26-Jul-2004  tron Pull up revision 1.15 via patch (requested by chs in ticket #714):
in pthread__initmain(), don't reuse the part of the initial stack that
is occupied by the argv and environment (and MD stuff like the page-table
mapping on x86). fixes PR 26392.
 1.20.2.1 03-Sep-2007  skrll Sync with HEAD.
 1.5 09-Jul-2010  jruoho Fix the return values; pthread_resume_np() may fail with ESRCH. In addition,
some improvements to markup and wording.
 1.4 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.3 30-Apr-2008  martin branches: 1.3.8;
Convert TNF licenses to new 2 clause variant
 1.2 12-Nov-2003  wiz branches: 1.2.32;
Various fixes.
 1.1 12-Nov-2003  christos Document pthread_attr_setcreatesuspend_np, pthread_suspend_np, pthread_resume_np
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.3.8.1 30-Apr-2008  martin file pthread_suspend_np.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.10 05-Mar-2025  riastradh pthread_testcancel(3): Add a colon for clarity in man page.

`No punctual change intended.'
 1.9 18-Mar-2014  riastradh branches: 1.9.38;
Merge riastradh-drm2 to HEAD.
 1.8 20-Jul-2013  wiz Use Mt for email addresses.
 1.7 06-Aug-2010  wiz branches: 1.7.6; 1.7.12; 1.7.16;
Fix typo.
 1.6 06-Aug-2010  christos make kevent(2) a cancelation point, and document properly all the cancelation
points we currently support.
 1.5 09-Jul-2010  jruoho Update conformance to the 2001 revision.
 1.4 30-Apr-2008  martin branches: 1.4.8;
Convert TNF licenses to new 2 clause variant
 1.3 18-Nov-2003  thorpej branches: 1.3.32;
Userland portion of fsync_range(2), written by Bill Studenmund, and
contributed by Wasabi Systems, Inc.
 1.2 04-Jul-2003  wiz .Pp fixes.
 1.1 03-Jun-2003  nathanw Man pages for libpthread, adapted from FreeBSD by Stephen Degler.
 1.3.32.1 18-May-2008  yamt sync with head.
 1.4.8.2 30-Apr-2008  martin Convert TNF licenses to new 2 clause variant
 1.4.8.1 30-Apr-2008  martin file pthread_testcancel.3 was added on branch christos-time_t on 2008-04-30 13:10:53 +0000
 1.7.16.1 23-Jul-2013  riastradh sync with HEAD
 1.7.12.1 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.6.1 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.9.38.1 02-Aug-2025  perseant Sync with HEAD
 1.26 01-Mar-2025  christos Explain that the pthread_atfork() call will not call malloc from here.
 1.25 10-Apr-2022  riastradh branches: 1.25.4;
pthread: Nix trailing whitespace.
 1.24 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.23 11-Jun-2020  ad Drop self->pt_lock before clearing TSD / malloc TSD.
 1.22 19-Apr-2020  joerg Improve TSD behavior

Optimistically check whether the key has been used by this thread
already and avoid locking in that case. This avoids the atomic operation
in the hot path. When the value is set to non-NULL for the first time,
put the entry on the to-be-freed list and keep it their until
destruction or thread exit. Setting the key to NULL and back is common
enough and updating the list is more expensive than the extra check on
the final round.
 1.21 19-Apr-2020  joerg Reinit TSD mutex in the child to avoid issues with former waiters
 1.20 16-Feb-2020  kamil Revert "Enhance the pthread(3) + malloc(3) init model"

It is reported to hand on aarch64 with gzip.
 1.19 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.18 25-Dec-2019  joerg Since pthread_setspecific requires locks, ensure that they are acquired
before fork and dropped in both parent and child. At least Python
depends on TSD after fork, even though it is undefined behavior in
POSIX.
 1.17 05-Mar-2019  christos 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.16 09-Jul-2017  christos branches: 1.16.6;
PR/52386: Use the number of iterations we document.
 1.15 25-Aug-2015  pooka branches: 1.15.8;
Revert 1.14 now that the arduous task of fixing rumphijack to allow
mmap() in early init has been completed.
 1.14 30-May-2015  christos Thanks rump for not letting us use even mmap during initialization.
 1.13 29-May-2015  christos 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.12 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.11 21-Mar-2013  christos branches: 1.11.8;
- 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.10 22-Nov-2012  christos Don't call the destructor in pthread_key_delete() following the standard.
 1.9 21-Nov-2012  christos Replace the simple implementation of pthread_key_{create,destroy}
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.
 1.8 02-Mar-2012  joerg branches: 1.8.2;
Fix indentation.
 1.7 28-Apr-2008  martin branches: 1.7.4; 1.7.8; 1.7.24;
Remove clause 3 and 4 from TNF licenses
 1.6 08-Mar-2008  ad branches: 1.6.2;
Add a cast to make lint happy.
 1.5 07-Mar-2008  ad pthread_key_create: instead of using a simple 1/0 value to record a key
as allocated, use an array of pointers and save __builtin_return_address(0)
so keys can be identified when doing post-mortem debugging.
 1.4 24-Dec-2007  ad branches: 1.4.2;
- 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.3 16-Aug-2007  ad branches: 1.3.2;
- 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.2 29-Sep-2003  wiz branches: 1.2.20;
available, not avaliable. From miod@openbsd.
 1.1 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.2.20.1 03-Sep-2007  skrll Sync with HEAD.
 1.3.2.2 23-Mar-2008  matt sync with HEAD
 1.3.2.1 09-Jan-2008  matt sync with HEAD
 1.4.2.1 24-Mar-2008  keiichi sync with head.
 1.6.2.1 18-May-2008  yamt sync with head.
 1.7.24.3 29-Apr-2013  riz 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.7.24.2 02-Dec-2012  riz Back out ticket #724 (libpthread changes) until they can be better
understood, as they broke threaded programs on (at least) i386 and amd64.
 1.7.24.1 28-Nov-2012  riz Pull up following revision(s) (requested by christos in ticket #724):
lib/libpthread/pthread_specific.c: revision 1.24
lib/libpthread/pthread_tsd.c: revision 1.10
lib/libpthread/pthread_tsd.c: revision 1.9
lib/libpthread/pthread_int.h: revision 1.88
Replace the simple implementation of pthread_key_{create,destroy}
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.
Don't call the destructor in pthread_key_delete() following the standard.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file pthread_tsd.c was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.7.4.3 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.7.4.2 16-Jan-2013  yamt sync with (a bit old) head
 1.7.4.1 17-Apr-2012  yamt sync with head
 1.8.2.2 23-Jun-2013  tls resync from head
 1.8.2.1 25-Feb-2013  tls resync with head
 1.11.8.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.15.8.1 24-Jul-2017  snj Pull up following revision(s) (requested by kamil in ticket #119):
lib/libpthread/pthread_tsd.c: revision 1.16
PR/52386: Use the number of iterations we document.
 1.16.6.3 21-Apr-2020  martin Sync with HEAD
 1.16.6.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.16.6.1 10-Jun-2019  christos Sync with HEAD
 1.25.4.1 02-Aug-2025  perseant Sync with HEAD
 1.27 10-Apr-2022  riastradh pthread: Nix trailing whitespace.
 1.26 10-Mar-2021  christos Use __pthread_volatile for ptc_waiters (Greg A. Woods)
 1.25 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.24 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.23 09-Sep-2017  kamil Support <pthread_typs.h> on C89 compilers

Clang 5.0.0(svn) reports warnings on <pthread_types.h> for C99 constructs
when used with strict -std=c89.

Restrict designated initializers usage to C99 or newer code.
C89 and C++ will share the same code without extension of designated
initializers.

PR 52285
 1.22 20-Jul-2016  christos unnamed unions need special treatment since they need braced initializers
for old style initializations.
 1.21 20-Jul-2016  christos cplusplus does not like complex named initializers...
 1.20 20-Jul-2016  christos use named initializers
 1.19 17-Jul-2016  skrll Use anonymous union for ptm_ceiling and old __pthread_spin_t field to
maintain backward compatibility and fix hppa build. hppa has an non-
integer type __pthread_spin_t
 1.18 03-Jul-2016  christos branches: 1.18.2;
GSoC 2016 Charles Cui: Implement thread priority protection based on work
by Andy Doran. Also document the get/set pshared thread calls as not
implemented, and add a skeleton implementation that is disabled.
XXX: document _sched_protect(2).
 1.17 27-Aug-2015  pooka Fix PTHREAD_FOO_INITIALIZER for C++ by not using volatile in the relevant
pthread types in C++ builds, attempt 2.

The problem with attempt 1 was making assumptions of what the MD
__cpu_simple_lock_t (declared volatile) looks like. To get a same type
except non-volatile, we change the MD type to __cpu_simple_lock_nv_t
and typedef __cpu_simple_lock_t as a volatile __cpu_simple_lock_nv_t.
IMO, __cpu_simple_lock_t should not be volatile at all, but changing it
now is too risky.

Fixes at least Rumprun w/ gcc 5.1/5.2. Furthermore, the mpd application
(and possibly others) will no longer require NetBSD-specific patches.

Tested: build.sh for i386, Rumprun for x86_64 w/ gcc 5.2.

Based on the patch from Christos in lib/49989.
 1.16 26-Jun-2015  pooka Rev 1.14 was nice except it didn't work with _INITIALIZER, which
sort of negates the whole point ... so revert everything while in
drawing board mode.
 1.15 26-Jun-2015  pooka Don't depend on __CPU_SIMPLE_LOCK_PAD to determine the type of
__cpu_simple_lock_t (because it doesn't). Instead, use sizeof/alignof
with a struct { uchar[] }.

Fixes problem in previous commit, caught by Nick Hudson.
 1.14 26-Jun-2015  pooka C++ (namely libc++) expects to be using PTHREAD_FOO_INITIALIZER as a
member initializer. This does not work for volatile types. Since C++
does not touch the guts of those types, redefine them as non-volatile.

Fixes libc++ compilation with g++ 5.1, as reported in PR lib/49989.
 1.13 02-Aug-2008  matt branches: 1.13.6;
Change pthread_mutex_t to use the amount of space as and be congruent to
the version used in the SA version of pthreads. This preserves binary
compatibility between both versions of the library.
 1.12 05-Jun-2008  ad Back out previous because it breaks the build.
 1.11 05-Jun-2008  ad glibc compatibile PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP, requested by
rafal@.
 1.10 28-Apr-2008  martin branches: 1.10.2;
Remove clause 3 and 4 from TNF licenses
 1.9 14-Feb-2008  ad branches: 1.9.4;
Adjust mutex/rwlock definitions to match reality now that there is only
one implementation of each. PR lib/38030.
 1.8 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.7 04-Aug-2007  ad branches: 1.7.2; 1.7.4;
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.6 02-May-2007  ad branches: 1.6.2;
Remove obsolete comment.
 1.5 26-Sep-2003  nathanw Don't include <machine/lock.h> anymore; instead, we now get
__cpu_simple_lock_t and __SIMPLELOCK_{UN,}LOCKED from <sys/types.h>.
Should prevent the massive namespace pollution by way of dragging in
many MD headers that has been observed to break stuff.
 1.4 17-Jul-2003  nathanw Prepare for inclusion in sys/types.h by ensuring that all the symbols
defined end with _t or start with _[A-Z_].
 1.3 25-Jan-2003  nathanw Make pthread_barrier_wait() handle spurious wakeups from pthread__block()
by adding a generation number to the barrier structure and incrementing it
when the barrier fires.

XXX this is an ABI change for anything using barriers, but the library is
new enough and nothing in the tree uses barriers so I'm going to let it
slide. Using the private data pointer for a field that will always be present
would be excessive.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Jul-2001  nathanw branches: 1.1.2;
file pthread_types.h was initially added on branch nathanw_sa.
 1.1.2.12 07-Jan-2003  thorpej Implement the pthread_barrier API.
 1.1.2.11 06-Jan-2003  nathanw ABI change, while this is still on the branch: Add pointers to private
storage to major exposed data structures.
This should redudce the need for ABI changes with future expansion.
 1.1.2.10 30-Dec-2002  thorpej Add support for using RAS lock primitives on uniprocessors where
RAS is available.
 1.1.2.9 28-Oct-2002  nathanw Implement POSIX read-write locks.
 1.1.2.8 01-Mar-2002  nathanw Declare POSIX spinlock interfaces: pthread_spin_*() and pthread_spinlock_t.
Move the internal spinlock interface declarations back to the internal header.
 1.1.2.7 30-Dec-2001  nathanw Avoid including pthread_queue.h and thereby exposing the PTQ_* macros
to userland, by #defining a local _PTQ_HEAD, identical to PTQ_HEAD in
pthread_queue.h, and using {NULL, NULL} in place of
PTQ_HEAD_INITIALIZER.

Rename struct pt_queue_t to struct pthread_queue_t.
Rename pt_spin_t to pthread_spin_t.
 1.1.2.6 08-Aug-2001  nathanw Add pthread_once and thread-specific data types.
 1.1.2.5 25-Jul-2001  nathanw Standardize MAGIC/DEAD values.
Fix PTHREAD_MUTEX_INITIALIZER.
Create pthread_mutexattr_t and pthread_condattr_t types.
Creat PTHREAD_COND_INITIALIZER.
 1.1.2.4 25-Jul-2001  nathanw Implement most of condition variables
(pthread_cond_timedwait() is not yet done).
 1.1.2.3 24-Jul-2001  nathanw Prefix some application-visible symbols with an underscore.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 13-Jul-2001  nathanw Move some of the more internal types to another file, to improve
readability.

C sucks, or I'd take them out of the application visibility completely.
 1.6.2.2 10-Sep-2007  skrll Sync with HEAD.
 1.6.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.7.4.2 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.7.4.1 04-Aug-2007  ad file pthread_types.h was added on branch matt-mips64 on 2007-08-04 13:37:51 +0000
 1.7.2.2 23-Mar-2008  matt sync with HEAD
 1.7.2.1 06-Nov-2007  matt sync with HEAD
 1.9.4.1 18-May-2008  yamt sync with head.
 1.10.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.13.6.2 02-Aug-2008  matt Change pthread_mutex_t to use the amount of space as and be congruent to
the version used in the SA version of pthreads. This preserves binary
compatibility between both versions of the library.
 1.13.6.1 02-Aug-2008  matt file pthread_types.h was added on branch christos-time_t on 2008-08-02 19:46:31 +0000
 1.18.2.1 26-Jul-2016  pgoyette Sync with HEAD
 1.8 15-Dec-2024  riastradh libpthread: Zero-initialize res_state objects.

PR lib/58888
 1.7 12-Feb-2022  riastradh branches: 1.7.2; 1.7.4;
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.6 28-Apr-2008  martin branches: 1.6.8; 1.6.66;
Remove clause 3 and 4 from TNF licenses
 1.5 13-Nov-2007  ad branches: 1.5.6;
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.4 03-Jun-2004  christos branches: 1.4.18;
simplify and make more efficient (YAMAMOTO Takashi)
 1.3 24-May-2004  christos Oops, forgot to commit this.
 1.2 22-May-2004  christos Provide access to _res in the non-threaded case, and abort in the threaded
case.
 1.1 21-May-2004  christos add pool code for res state.
XXX: could be more efficient.
 1.4.18.1 09-Jan-2008  matt sync with HEAD
 1.5.6.1 18-May-2008  yamt sync with head.
 1.6.66.1 15-Dec-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1930):

lib/libpthread/res_state.c: revision 1.8

libpthread: Zero-initialize res_state objects.
PR lib/58888
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file res_state.c was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.4.1 02-Aug-2025  perseant Sync with HEAD
 1.7.2.1 15-Dec-2024  martin Pull up following revision(s) (requested by riastradh in ticket #1029):

lib/libpthread/res_state.c: revision 1.8

libpthread: Zero-initialize res_state objects.
PR lib/58888
 1.5 15-Jan-2008  rmind Implementation of processor-sets, affinity and POSIX real-time extensions.
Add schedctl(8) - a program to control scheduling of processes and threads.

Notes:
- This is supported only by SCHED_M2;
- Migration of LWP mechanism will be revisited;

Proposed on: <tech-kern>. Reviewed by: <ad>.
 1.4 09-Oct-2005  kleink branches: 1.4.12;
Change the sched_*() functions to return -1 and set errno to ENOSYS
(per the standard) instead of returning ENOSYS. Noted by Ian Zagorskih
in PR kern/30970.
 1.3 08-Mar-2003  lukem branches: 1.3.4; 1.3.6;
add __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file sched.c was initially added on branch nathanw_sa.
 1.1.2.4 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.3 27-Oct-2002  thorpej Cosmetic changes.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.3.6.1 10-Oct-2005  tron Pull up following revision(s) (requested by kleink in ticket #875):
include/sched.h: revision 1.8
lib/libpthread/sched.c: revision 1.4
Change the sched_*() functions to return -1 and set errno to ENOSYS
(per the standard) instead of returning ENOSYS. Noted by Ian Zagorskih
in PR kern/30970.
 1.3.4.1 28-Oct-2005  jmc Pullup from trunk 1.3->1.4
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file sched.h was initially added on branch nathanw_sa.
 1.1.2.6 11-Apr-2002  thorpej This file is exactly the same as include/sched.h; don't bother with
the second copy.
 1.1.2.5 30-Dec-2001  nathanw Make a comment more clear.
 1.1.2.4 17-Nov-2001  thorpej Whitespace nit.
 1.1.2.3 16-Nov-2001  thorpej Since this file goes in <sched.h>, add the things that are
in src/include/sched.h to this header file. We will deprecate
src/include/sched.h when this is pulled down onto the trunk.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.3 10-Mar-2008  rmind Add sched(3) manual page, and appropriate links.
Thanks <wiz> for review and fixes!
 1.2 15-Dec-2004  wiz branches: 1.2.18; 1.2.24;
Grammar improvements.
 1.1 14-Dec-2004  yamt document sched_yield.
 1.2.24.1 24-Mar-2008  keiichi sync with head.
 1.2.18.1 23-Mar-2008  matt sync with HEAD
 1.25 03-Feb-2019  thorpej Implement support for "pshared" POSIX semaphores.

Fixes lib/53273 (and Firefox's multi-process tab feature).
 1.24 10-Mar-2012  joerg branches: 1.24.32;
Fix error handling
 1.23 08-Mar-2012  joerg Implement sem_timedwait.
 1.22 07-Mar-2012  joerg Remove libpthread's semaphore implementation and always use the kernel
one. The implementation doesn't provide an async-safe sem_post and can't
without a lot of work on the pthread primitives.

Remove bogus time out requirement in test case, it should have been
a "known failure" if anything.
 1.21 14-Nov-2008  ad branches: 1.21.2; 1.21.10;
Replace semid_t with intptr_t. No function change. This is a libc/kernel
private interface and so the name change should not affect any third
party code.
 1.20 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.19 24-Dec-2007  ad branches: 1.19.4;
- Use pthread__cancelled() in more places.
- pthread_join(): assert that pthread_cond_wait() returns zero.
 1.18 14-Sep-2007  tnn sem_post(): pthread__self() is no longer used here.
 1.17 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.16 16-Aug-2007  ad branches: 1.16.2;
Trim fat off libpthread internal spinlock operations. Makes a mesurable
improvement across the board.
 1.15 04-Aug-2007  ad branches: 1.15.2;
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.14 24-Mar-2007  ad branches: 1.14.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.13 05-Mar-2007  ad - Update to match changed pthread__park() interface.
- Simplify the locking in sem_wait().
 1.12 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.11 24-Dec-2006  ad Fix bugs with and improve upon previous.
 1.10 23-Dec-2006  ad Conditionalised support for 1:1 threads. Needs associated kernel changes
and more work to be useful.
 1.9 19-Oct-2005  chs branches: 1.9.4; 1.9.6;
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.8 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.7 24-Nov-2003  cl branches: 1.7.6;
Update mutex/rwlock/sem code to match recent change in cond code.
 1.6 08-Mar-2003  lukem add __RCSID()
 1.5 24-Jan-2003  thorpej Correct omission in notice.
 1.4 22-Jan-2003  thorpej sem_init(): oops, only destroy the ksem on error if it is a ksem.
 1.3 22-Jan-2003  thorpej Rewrite to use our internal scheduling primitives.
 1.2 20-Jan-2003  christos more sem to _sem_st
 1.1 20-Jan-2003  christos add support for p1003.1b semaphores. From FreeBSD
 1.7.6.1 01-Nov-2005  jmc Pullup revs 1.8-1.9 (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.9.6.2 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.9.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.9.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.14.2.3 10-Sep-2007  skrll Sync with HEAD.
 1.14.2.2 03-Sep-2007  skrll Sync with HEAD.
 1.14.2.1 15-Aug-2007  skrll Sync with HEAD.
 1.15.2.2 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.15.2.1 04-Aug-2007  ad file sem.c was added on branch matt-mips64 on 2007-08-04 13:37:51 +0000
 1.16.2.2 09-Jan-2008  matt sync with HEAD
 1.16.2.1 06-Nov-2007  matt sync with HEAD
 1.19.4.1 18-May-2008  yamt sync with head.
 1.21.10.1 17-Apr-2012  yamt sync with head
 1.21.2.2 14-Nov-2008  ad Replace semid_t with intptr_t. No function change. This is a libc/kernel
private interface and so the name change should not affect any third
party code.
 1.21.2.1 14-Nov-2008  ad file sem.c was added on branch christos-time_t on 2008-11-14 15:49:21 +0000
 1.24.32.1 10-Jun-2019  christos Sync with HEAD
 1.3 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.2 21-Jan-2003  wiz Replace -1 with \-1.
 1.1 21-Jan-2003  christos add manual pages.
 1.3 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.2 21-Jan-2003  wiz New sentence, new line.
 1.1 21-Jan-2003  christos add manual pages.
 1.2 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.1 21-Jan-2003  christos add manual pages.
 1.3 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.2 21-Jan-2003  wiz Replace -1 with \-1.
 1.1 21-Jan-2003  christos add manual pages.
 1.2 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.1 21-Jan-2003  christos add manual pages.
 1.4 24-Jan-2003  thorpej p1003.1b semaphore manual pages have been moved to librt.
 1.3 21-Jan-2003  wiz New sentence, new line.
 1.2 21-Jan-2003  jdolecek .Rv needs a function name as parameter
 1.1 21-Jan-2003  christos add manual pages.
 1.20 31-Mar-2025  riastradh libpthread(3): Add missing cancellation points.

- accept4
- tcdrain

XXX Should our nonstandard alias paccept(2) also be a cancellation
point?

PR lib/59240: POSIX.1-2024: cancellation point audit
 1.19 24-Apr-2019  kamil branches: 1.19.12;
Bump the libpthread(3) minor number to 4

Added C11 Threading library support.
 1.18 09-Sep-2018  maya Add a todo item for a future major bump (rename many symbols)
 1.17 23-Apr-2016  christos branches: 1.17.14; 1.17.16;
bump
 1.16 03-Apr-2013  christos bump for pthread_cond_setclock
 1.15 08-Mar-2012  joerg branches: 1.15.2;
Implement sem_timedwait.
 1.14 11-Jan-2009  christos branches: 1.14.8; 1.14.10;
merge christos-time_t
 1.13 28-Dec-2008  ad branches: 1.13.2;
Some things to do on major bump.
 1.12 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.11 27-Nov-2007  ad Bump libc/libpthread minor for thr_curcpu()/pthread_curcpu_np().
 1.10 13-Nov-2007  ad Crank libpthread to 0.8. It now uses _lwp_ctl(), and it's handy to keep
0.7 hanging around for old kernels.
 1.9 09-Feb-2007  ad branches: 1.9.6;
Bump libpthread & libpthread_dbg minor versions so that an old SA copy
gets kept in the file system. Requested by pavel.
 1.8 18-Mar-2005  kleink Interpose cancellation points in pollts() and pselect(), bringing us
to libc.so.12.127 and libpthread.so.0.6.
 1.7 21-May-2004  christos branches: 1.7.2;
bump the version of this too.
 1.6 02-Jan-2004  cl - libc.so.12.109 and libpthread.so.0.4
- add ssize_t stackinfo_offset argument to sa_register syscall
- remove sa_unblockyield syscall
- make __sigprocmask14 syscall weak
- in pthread__sa_start: catch up with 4-argument sa_register syscall
 1.5 18-Nov-2003  thorpej Bump libc to 12.107 and libpthread to 0.3 for fsync_range(2).
 1.4 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.3 20-Jan-2003  christos add support for p1003.1b semaphores. From FreeBSD
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file shlib_version was initially added on branch nathanw_sa.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.7.2.1 20-Mar-2005  tron Pull up revision 1.8 (requested by kleink in ticket #27):
Interpose cancellation points in pollts() and pselect(), bringing us
to libc.so.12.127 and libpthread.so.0.6.
 1.9.6.1 09-Jan-2008  matt sync with HEAD
 1.13.2.2 28-Dec-2008  ad Some things to do on major bump.
 1.13.2.1 28-Dec-2008  ad file shlib_version was added on branch christos-time_t on 2008-12-28 11:01:59 +0000
 1.14.10.1 20-Apr-2013  bouyer Pull up following revision(s) (requested by christos in ticket #863) via patch:
distrib/sets/lists/base/ad.mips64eb: patch
distrib/sets/lists/base/ad.mips64el: patch
distrib/sets/lists/base/md.amd64: patch
distrib/sets/lists/base/md.sparc64: patch
distrib/sets/lists/base/shl.mi: patch
distrib/sets/lists/comp/ad.mips64eb: patch
distrib/sets/lists/comp/ad.mips64el: patch
distrib/sets/lists/comp/md.amd64: patch
distrib/sets/lists/comp/md.sparc64: patch
distrib/sets/lists/comp/shl.mi: patch
lib/libpthread/shlib_version: patch
bump libpthread minor for pthread_cond_setclock to libpthread.so.1.1.
Note that this is not the same as libpthread.so.1.1 from HEAD.
 1.14.8.2 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.14.8.1 17-Apr-2012  yamt sync with head
 1.15.2.1 23-Jun-2013  tls resync from head
 1.17.16.1 10-Jun-2019  christos Sync with HEAD
 1.17.14.1 30-Sep-2018  pgoyette Ssync with HEAD
 1.19.12.1 02-Aug-2025  perseant Sync with HEAD
 1.3 27-Apr-2019  wiz branches: 1.3.2;
Fix some typos, improve wording.
 1.2 24-Apr-2019  kamil Introduce minor changes to the C11 threading library

Switch tss_t type from int to pthread_key_t (no functional change as
pthread_key_t was already typedefed as int).

Noted by <enh from Google>.

Use C11 _Noreturn in thrd_exit(3) instead of NetBSD specific __dead.
The former is documented in the standard as an attribute of thrd_exit(3),
the latter is more portable to pre-C11 compilers, however C11 thread
support library needs C11 compiler for TLS anyway. __dead made a little bit
more point 3 years ago than today as 3 years ago pre-C11 compilers were
more common.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.3.2.2 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 27-Apr-2019  christos file thrd.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.4 10-Sep-2019  kamil Switch back _Noreturn to __dead in C11 threads

There is an ongoing discussion to unify unreturn attribute between C and
C++, making a compatible version, shared between languages. Instead of
picking C11-only approach here, switch back to __dead that wraps the
compiler extension for the same purpose.

This change makes this header more compatible with C++ and pre-C11.

Reference:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf
 1.3 29-Apr-2019  kamil branches: 1.3.2; 1.3.4;
Avoid incompatible function pointer casts in thrd_create(3)

Use an intermediate function trampoline to workaround different function
pointer prototypes.

While there, correct scenario returning thrd_nomem from thrd_create(3).
In practice ENOMEM is rarely returned from pthread(3).

Older code worked on tested ports, but was depending on unneeded UB.
 1.2 24-Apr-2019  kamil Introduce minor changes to the C11 threading library

Switch tss_t type from int to pthread_key_t (no functional change as
pthread_key_t was already typedefed as int).

Noted by <enh from Google>.

Use C11 _Noreturn in thrd_exit(3) instead of NetBSD specific __dead.
The former is documented in the standard as an attribute of thrd_exit(3),
the latter is more portable to pre-C11 compilers, however C11 thread
support library needs C11 compiler for TLS anyway. __dead made a little bit
more point 3 years ago than today as 3 years ago pre-C11 compilers were
more common.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.3.4.1 13-Sep-2019  martin Pull up following revision(s) (requested by kamil in ticket #198):

lib/libpthread/thrd.c: revision 1.4
lib/libpthread/threads.h: revision 1.3

Switch back _Noreturn to __dead in C11 threads

There is an ongoing discussion to unify unreturn attribute between C and
C++, making a compatible version, shared between languages. Instead of
picking C11-only approach here, switch back to __dead that wraps the
compiler extension for the same purpose.

This change makes this header more compatible with C++ and pre-C11.
Reference:

<a rel="nofollow" href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf</a>
 1.3.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.3.2.2 10-Jun-2019  christos Sync with HEAD
 1.3.2.1 29-Apr-2019  christos file thrd.c was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.2 27-Apr-2019  wiz branches: 1.2.2;
Fix some typos, improve wording.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 27-Apr-2019  christos file threads.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.3 10-Sep-2019  kamil Switch back _Noreturn to __dead in C11 threads

There is an ongoing discussion to unify unreturn attribute between C and
C++, making a compatible version, shared between languages. Instead of
picking C11-only approach here, switch back to __dead that wraps the
compiler extension for the same purpose.

This change makes this header more compatible with C++ and pre-C11.

Reference:

http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf
 1.2 24-Apr-2019  kamil branches: 1.2.2; 1.2.4;
Introduce minor changes to the C11 threading library

Switch tss_t type from int to pthread_key_t (no functional change as
pthread_key_t was already typedefed as int).

Noted by <enh from Google>.

Use C11 _Noreturn in thrd_exit(3) instead of NetBSD specific __dead.
The former is documented in the standard as an attribute of thrd_exit(3),
the latter is more portable to pre-C11 compilers, however C11 thread
support library needs C11 compiler for TLS anyway. __dead made a little bit
more point 3 years ago than today as 3 years ago pre-C11 compilers were
more common.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.4.1 13-Sep-2019  martin Pull up following revision(s) (requested by kamil in ticket #198):

lib/libpthread/thrd.c: revision 1.4
lib/libpthread/threads.h: revision 1.3

Switch back _Noreturn to __dead in C11 threads

There is an ongoing discussion to unify unreturn attribute between C and
C++, making a compatible version, shared between languages. Instead of
picking C11-only approach here, switch back to __dead that wraps the
compiler extension for the same purpose.

This change makes this header more compatible with C++ and pre-C11.
Reference:

<a rel="nofollow" href="http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf">http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2410.pdf</a>
 1.2.2.3 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 24-Apr-2019  christos file threads.h was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.2 27-Apr-2019  wiz branches: 1.2.2;
Fix some typos, improve wording.
 1.1 24-Apr-2019  kamil Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.2.2.2 10-Jun-2019  christos Sync with HEAD
 1.2.2.1 27-Apr-2019  christos file tss.3 was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.2 15-Dec-2019  uwe Drop bogus _DIAGASSERT that don't even compile.
 1.1 24-Apr-2019  kamil branches: 1.1.2;
Add a complete C11 threads(3) implementation

C11 Thread support library is a portable threading C API between OSs,
similar to std::threads in the C++ world.

The library is implemented as a thin shim over POSIX interfaces.

NetBSD implements the API as a part of the POSIX threading library
(libpthread(3)).

C11 threads(3) are in the process of making them an integral part
of the POSIX standard. The interface has been implemented in major
OSs and used with stopgap libraries for older versions of them.

C11 threading library is already used (with a stopgap implementation)
in the NetBSD distribution in MESA.

Original implementation by myself from 2016.

ATF tests are new and cover almost all interfaces.

Proposed on tech-userlevel@.
 1.1.2.3 08-Apr-2020  martin Merge changes from current as of 20200406
 1.1.2.2 10-Jun-2019  christos Sync with HEAD
 1.1.2.1 24-Apr-2019  christos file tss.c was added on branch phil-wifi on 2019-06-10 22:05:26 +0000
 1.2 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.1 10-Aug-2014  matt branches: 1.1.4; 1.1.18; 1.1.28; 1.1.36;
Preliminary files for AARCH64 (64-bit ARM) support.
Enough for a distribution build.
 1.1.36.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.1.28.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.1.18.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.1.4.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.4.1 10-Aug-2014  tls file pthread_md.h was added on branch tls-maxphys on 2014-08-20 00:02:20 +0000
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 28-Apr-2008  martin branches: 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 08-Oct-2007  skrll branches: 1.3.6;
Provide PTHREAD__ASM_RASOPS for alpha.

The gcc generated lock try RAS is broken as the store needs to be the last
instruction.
 1.2 18-Jan-2003  thorpej branches: 1.2.24;
Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Save and restore process-unique value.
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
Save and restore FP registers.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.2.24.1 06-Nov-2007  matt sync with HEAD
 1.3.6.1 18-May-2008  yamt sync with head.
 1.4.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Save and restore process-unique value.
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.1 18-May-2009  njoly Restore PTHREAD__ASM_RASOPS for alpha (from _context_u.S), that was
lost in previous cleanup.

ok by ad@.
 1.1 22-Nov-2024  riastradh branches: 1.1.4;
libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Nov-2024  perseant file pthread_md.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:56 +0000
 1.7 25-Jan-2011  christos make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 08-Oct-2007  skrll branches: 1.4.6;
Provide PTHREAD__ASM_RASOPS for alpha.

The gcc generated lock try RAS is broken as the store needs to be the last
instruction.
 1.3 24-Dec-2005  perry branches: 1.3.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.7 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.6 06-Dec-2002  nathanw ucontext/sigcontext glue.
 1.1.2.5 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set the status register to a reasonable value.
 1.1.2.4 06-Aug-2002  nathanw Add struct reg/mcontext conversion glue.
 1.1.2.3 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.2 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.3.12.1 06-Nov-2007  matt sync with HEAD
 1.4.6.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.6 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.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 25-Sep-2001  nathanw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 13-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch().
 1.1.2.2 17-Dec-2001  nathanw Update to work with Klaus's mcontext code.
 1.1.2.1 25-Sep-2001  nathanw Alpha MD files for the pthread lib.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 21-Aug-2004  rearnsha Use RET macro for returning.
 1.3 05-Apr-2003  bjh21 NetBSD/acorn26 has used APCS-32 for years, so unifdef -U__APCS_26__.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.8 27-Nov-2001  bjh21 In GETC(), rather than faking a CPSR, save the real one if we're can, and
zero otherwise (ie if we're on a 26-bit CPU). I suspect this isn't actually
necessary, but it's cheap, and it should make it easier for debuggers and
suchlike to work out what's going on.
 1.1.2.7 22-Nov-2001  bjh21 _UC_USER | _UC_CPU happens to be a valid ARM constant, so we can load
it in a single cycle.
 1.1.2.6 22-Nov-2001  thorpej In the GETC() macro, don't actually save r14 (lr) and r15 (pc).
r14 is caller-save, so we don't need to save it in the _REG_LR
slot. Instead, we save it in the _REG_PC slot so that when the
context is resumed, we end up at the insn after the call site.

Fixes the "cu6" test in Nathan's test suite. "cu1" - "cu5" also
function correctly (as they did before this change).
 1.1.2.5 21-Nov-2001  thorpej ome improvements, based on suggestions from Ben Harris:
* Don't need to save CPSR in GETC(), since it's a caller-saved
register. However, stuff a fake one (that indicates USR32 mode)
into the ucontext in case it is used later in a setcontext(2)
system call (as is done in one of Nathan's regression tests; this
last bit from me).
* Only restore CPSR if ! _UC_USER (i.e. context was created by
getcontext(2)).
* Determine at run-time if we're in USR26 or USR32 by forcing the Z
flag to be set and then comparing the PC portion of R15 to all of
R15 (if they're not equal, we're in 26-bit mode).
* Restore banked regs properly in 26-bit mode.

Plus one from me: Don't or _UC_USER | _UC_CPU into uc_flags; set uc_flags
to that value instead.
 1.1.2.4 20-Nov-2001  thorpej Clean up SAVE_FLAGS/RESTORE_FLAGS, and make sure to fetch the
flags from the correct place in the ucontext (not past the END
of the ucontext) in the SETC() macro.
 1.1.2.3 20-Nov-2001  thorpej Make sure to set _UC_CPU in _getcontext_u().
 1.1.2.2 18-Nov-2001  thorpej Note that we need to think about what to do regarding hard and
soft FP context.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 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.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 13-Mar-2003  thorpej Include <sys/types> before <sys/lock.h>, shuffle <ucontext.h>.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.2 22-Nov-2001  thorpej Move the _REG_PC definition up with the other _REG_* definitions.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.13 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.12 25-May-2023  riastradh libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

XXX pullup-10
 1.11 22-Nov-2018  skrll branches: 1.11.2; 1.11.10;
G/C __APCS_26__ support
 1.10 17-Jul-2017  skrll branches: 1.10.2; 1.10.4; 1.10.6;
Typo in comment
 1.9 15-Aug-2013  matt branches: 1.9.18;
Use the thumb1 versions of sev/wfe for thumb && armv6+.
if using armv5t don't do anything for thumb.
 1.8 19-Sep-2012  matt Use .inst instead of wfe/sev to shut up gas.
 1.7 16-Aug-2012  matt branches: 1.7.2;
Add a pthread__smt_wake and add support for it on arm along with
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.
 1.6 25-Jan-2011  christos branches: 1.6.4;
make pthread__sp unsigned long.
 1.5 16-May-2009  ad branches: 1.5.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.4 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 18-Jan-2003  christos add missing backslash
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.4 17-Jan-2003  nathanw Add _INITCONTEXT_U_MD() code that sets up the PC or CPSR.

Adjust PTHREAD_UCONTEXT_TO_REG() to set a plausable value in
reg->r_cpsr when _UC_USER is set in the ucontext; otherwise, GDB gets
very confused and thinks it's dealing with 26-bit ARM state.
 1.1.2.3 20-Dec-2002  thorpej Update for mcontext_t changes.
 1.1.2.2 06-Aug-2002  thorpej Add glue for libpthread_dbg.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.5.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.6.4.2 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.6.4.1 30-Oct-2012  yamt sync with head
 1.7.2.2 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.7.2.1 20-Nov-2012  tls Resync to 2012-11-19 00:00:00 UTC
 1.9.18.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.10.6.1 10-Jun-2019  christos Sync with HEAD
 1.10.4.1 26-Nov-2018  pgoyette Sync with HEAD, resolve a couple of conflicts
 1.10.2.2 17-Jul-2017  skrll 2167115
 1.10.2.1 17-Jul-2017  skrll file pthread_md.h was added on branch perseant-stdc-iso10646 on 2017-07-17 20:24:08 +0000
 1.11.10.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.11.2.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.9 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.8 21-Aug-2004  rearnsha Use RET macro for returning.
 1.7 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.6 24-Jul-2003  skrll Typo in comment.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 05-Apr-2003  bjh21 NetBSD/acorn26 has used APCS-32 for years, so unifdef -U__APCS_26__.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 14-Jan-2003  nathanw Rewrite pthread__switch() to avoid storing the new saved-context
pointer while still using the old stack. This avoids a race condition
with pthread__find_interrupted() where a thread could lose its old
state if it was interrupted in a certain window in pthread__switch().
 1.1.2.2 22-Nov-2001  bjh21 Correct a typo in STACK_SWITCH(), where it used the wrong register to
compute the stack pointer. This patch gets test "cond2" working on ARM.
 1.1.2.1 16-Nov-2001  thorpej First cut at machine-dependent pthread bits for ARM.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 11-Aug-2008  skrll branches: 1.4.6;
Remove unnecessary include.
 1.3 28-Apr-2008  martin branches: 1.3.2;
Remove clause 3 and 4 from TNF licenses
 1.2 24-Sep-2007  skrll branches: 1.2.6;
Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.1 19-Jul-2004  chs branches: 1.1.18;
add hppa MD libpthread bits. translated from MIPS.
 1.1.18.1 06-Nov-2007  matt sync with HEAD
 1.2.6.1 18-May-2008  yamt sync with head.
 1.3.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.4.6.2 11-Aug-2008  skrll Remove unnecessary include.
 1.4.6.1 11-Aug-2008  skrll file _context_u.S was added on branch christos-time_t on 2008-08-11 21:45:25 +0000
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 02-Mar-2007  ad branches: 1.2.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.2.12.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.2 19-May-2022  skrll Use RAS_{START,END}_ASM_HIDDEN
 1.1 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.1 22-Nov-2024  riastradh branches: 1.1.4;
libpthread: Fix expected symbols on alpha and hppa.

These have PTHREAD__ASM_RASOPS and define a different subset of
symbols which get exported. None of these pthread__ras_* and
pthread__lock_* symbols _should_ be exported but we can fix that in a
future revbump.

PR lib/58838: shared libraries in base should all have expsym lists
 1.1.4.2 02-Aug-2025  perseant Sync with HEAD
 1.1.4.1 22-Nov-2024  perseant file pthread_md.expsym was added on branch perseant-exfatfs on 2025-08-02 05:54:56 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.3 24-Dec-2005  perry branches: 1.3.12;
__asm__ -> __asm
 1.2 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.3.12.2 23-Mar-2008  matt sync with HEAD
 1.3.12.1 06-Nov-2007  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.2 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.1 19-Jul-2004  chs add hppa MD libpthread bits. translated from MIPS.
 1.3 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.2 07-Jan-1994  mycroft Delete special rules for syscall.S; they are not needed, and one of them
is wrong anyway.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.10 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.9 28-Apr-2008  martin branches: 1.9.8;
Remove clause 3 and 4 from TNF licenses
 1.8 10-Feb-2008  ad branches: 1.8.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.7 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.6 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.5 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.4 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.3 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.2 18-Jan-2003  thorpej branches: 1.2.20; 1.2.24;
Merge the nathanw_sa branch.
 1.1 13-Jul-2001  nathanw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.10 06-Sep-2002  nathanw In the xmm case, FPSAVE should be "fxsave", and FPLOAD should be "fxrstor",
not the other way around. Note to self: Lay off the crack.
 1.1.2.9 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.8 24-Apr-2002  nathanw Save FP state in user context switches.

XXX1: doing something clever about lazy-FP-switching would be good.
XXX2: coping with SSE/SSE2 regsisters would also be good.
 1.1.2.7 01-Mar-2002  nathanw Restore FP state if the kernel handed us any.
[xmms no longer sounds like it's playing Play-Skool LPs]
 1.1.2.6 11-Feb-2002  nathanw Implement _UC_USER for i386: only save callee-save registers, and set a
flag saying so; on restore, if that flag is set, only restore the callee-save
registers.

Speeds up the user-only version of these routines by 35-40% on a
Pentium MMX 233.
 1.1.2.5 04-Sep-2001  nathanw Generate and use symbolic constants for register offsets in mcontext_t,
instead of hand-coding offset numbers.
 1.1.2.4 02-Aug-2001  nathanw Don't bother even storing 0s into the fields for the caller-save
registers (eax, ecx, edx) and unused fields (esp, trapno, err).

Still need to deal more sanely with segment registers.
 1.1.2.3 02-Aug-2001  nathanw Adjust SETC (used by _setcontext_u and _getcontext_u) to not set the
new stack pointer until all the possibly-interesting data below the
new SP has been preserved. Unfortunately, it's about 3% slower.
 1.1.2.2 31-Jul-2001  nathanw Whitespace cleanup.
 1.1.2.1 13-Jul-2001  nathanw Make userlevel-only *context functions part of libpthread rather than libc.
 1.2.24.3 23-Mar-2008  matt sync with HEAD
 1.2.24.2 09-Jan-2008  matt sync with HEAD
 1.2.24.1 06-Nov-2007  matt sync with HEAD
 1.2.20.1 10-Sep-2007  skrll Sync with HEAD.
 1.8.4.1 18-May-2008  yamt sync with head.
 1.9.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.9.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 07-Jul-2008  gmcgarry branches: 1.8.6;
Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.7 28-Apr-2008  martin branches: 1.7.2;
Remove clause 3 and 4 from TNF licenses
 1.6 20-Jan-2007  christos branches: 1.6.12;
fix warning about indirect call without *
 1.5 30-Nov-2004  nathanw Punt to setcontext() system call if the PSL_T bit (single-step trap)
is set, so that the single-step trap happens in the thread's context
and not in the middle of _setcontext_u.

XXX might be able to do something here with iret, too, but it needs
more testing.
 1.4 10-Nov-2004  kent save&restore %fs and %gs registers for USER_LDT applications.
PR#26900
 1.3 30-Oct-2003  yamt branches: 1.3.2;
use explicit "l" suffixes. (eg. lea -> leal)
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 14-Aug-2002  nathanw branches: 1.1.2;
file _getsetc.S was initially added on branch nathanw_sa.
 1.1.2.4 22-Oct-2002  skrll RCSId police.
 1.1.2.3 04-Sep-2002  nathanw The _UC_USER_BIT case of SETC (currently) needs to load FP state.

Found by inspection.
 1.1.2.2 15-Aug-2002  nathanw Bit values are not the same as bit positions; fix the test for the
_UC_FPU flag.
 1.1.2.1 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.3.2.1 12-Nov-2004  jmc Pullup rev 1.4 (requested by kent in ticket #969)

save&restore %fs and %gs registers for USER_LDT applications. PR#26900
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.8.6.2 07-Jul-2008  gmcgarry Selector registers are 16-bit and binutils 2.18 insists that only 16-bit
accesses are permitted on them. Therefore, change movl to movw. No change to
machine code generated.
 1.8.6.1 07-Jul-2008  gmcgarry file _getsetc.S was added on branch christos-time_t on 2008-07-07 13:07:56 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.9 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.8 25-Mar-2002  nathanw Define a couple of constants for FP register use.
 1.1.2.7 11-Feb-2002  nathanw Implement _UC_USER for i386: only save callee-save registers, and set a
flag saying so; on restore, if that flag is set, only restore the callee-save
registers.

Speeds up the user-only version of these routines by 35-40% on a
Pentium MMX 233.
 1.1.2.6 04-Sep-2001  nathanw Generate and use symbolic constants for register offsets in mcontext_t,
instead of hand-coding offset numbers.
 1.1.2.5 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.4 01-Aug-2001  nathanw Create an offset for pt_sleepuc.
 1.1.2.3 31-Jul-2001  nathanw Create an asm symbol for the offset of EIP in the ucontext.
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 07-Feb-1994  proven More wrapper functions, and some hacks for machine independent sleep
mechanisms.
 1.2 20-Dec-1993  proven Copyrights added to each file.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 20-Dec-1993  proven Copyrights added to each file.
 1.2 15-Nov-1993  proven OK one more try at getting it right ...
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 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.5 28-Apr-2008  martin branches: 1.5.8; 1.5.10;
Remove clause 3 and 4 from TNF licenses
 1.4 13-Nov-2007  ad branches: 1.4.6;
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.3 08-Mar-2003  lukem branches: 1.3.24;
add __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 15-Aug-2002  nathanw branches: 1.1.2;
file pthread_md.c was initially added on branch nathanw_sa.
 1.1.2.1 15-Aug-2002  nathanw Actually add this file.
 1.3.24.1 09-Jan-2008  matt sync with HEAD
 1.4.6.1 18-May-2008  yamt sync with head.
 1.5.10.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.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.c was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.21 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.20 02-Mar-2012  joerg branches: 1.20.24; 1.20.34; 1.20.42;
Avoid getcontext() as it triggers clobbering warnings. Use inline
assembler to get the fields directly. Saves a system call as side
effect.
 1.19 24-Feb-2011  joerg branches: 1.19.4;
Allow storing and receiving the LWP private pointer via ucontext_t
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.
 1.18 25-Jan-2011  christos make pthread__sp unsigned long.
 1.17 16-May-2009  ad branches: 1.17.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.16 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.15 23-Jun-2008  ad branches: 1.15.6; 1.15.8;
pthread__threadreg_get: mark it const.
 1.14 28-Apr-2008  martin branches: 1.14.2;
Remove clause 3 and 4 from TNF licenses
 1.13 22-Mar-2008  ad branches: 1.13.2;
Cheat and add inlines for _atomic_cas_ptr() to work around gcc emitting
unneeded PIC stuff in mutex_lock() and mutex_unlock(), when a thread
register is used.
 1.12 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.11 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.10 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.9 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.8 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.7 29-Mar-2006  cube branches: 1.7.8; 1.7.12;
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.6 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 11-Feb-2004  nathanw branches: 1.5.4; 1.5.6;
Add ucontext conversion macros for an "extra" register set.
 1.4 18-Jan-2003  christos delint
 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_md.h was initially added on branch nathanw_sa.
 1.1.2.11 17-Jan-2003  thorpej Include <sys/ucontext.h> to get ucontext_t for prototypes.
 1.1.2.10 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.9 06-Dec-2002  nathanw Clear _UC_USER bit when converting from sigcontext to ucontext.
 1.1.2.8 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set segment registers and flag register
to sensible values.
 1.1.2.7 21-Oct-2002  nathanw Add some macros to convert between ucontext_t and struct sigcontext.
 1.1.2.6 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.5 24-Apr-2002  nathanw Add macros to convert between struct ucontext and struct reg/fpreg.
 1.1.2.4 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.3 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.2 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.5.6.1 19-Apr-2006  tron Pull up following revision(s) (requested by cube in ticket #1265):
lib/libpthread/arch/i386/pthread_md.h: revision 1.7
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.5.4.1 21-Apr-2006  tron Pull up following revision(s) (requested by cube in ticket #10448):
lib/libpthread/arch/i386/pthread_md.h: revision 1.7
Instead of using hard-coded values for various registers, get them from the
current context. Valid values can change depending on how the kernel is
setup. i386 and amd64 happen to be setup differently.
 1.7.12.3 23-Mar-2008  matt sync with HEAD
 1.7.12.2 09-Jan-2008  matt sync with HEAD
 1.7.12.1 06-Nov-2007  matt sync with HEAD
 1.7.8.1 10-Sep-2007  skrll Sync with HEAD.
 1.13.2.1 18-May-2008  yamt sync with head.
 1.14.2.1 18-Sep-2008  wrstuden Sync with wrstuden-revivesa-base-2.
 1.15.8.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.15.6.2 23-Jun-2008  ad pthread__threadreg_get: mark it const.
 1.15.6.1 23-Jun-2008  ad file pthread_md.h was added on branch christos-time_t on 2008-06-23 10:39:39 +0000
 1.17.2.2 05-Mar-2011  bouyer Sync with HEAD
 1.17.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.19.4.1 17-Apr-2012  yamt sync with head
 1.20.42.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.20.34.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.20.24.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.10 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.9 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.8 23-Apr-2004  simonb branches: 1.8.2;
s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.7 30-Oct-2003  yamt use explicit "l" suffixes. (eg. lea -> leal)
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 10-Feb-2003  fvdl Continue at the plain switch return point in pthread__switch, not the
locked one, in the !PIC case. From Tor Egge via Havard Eidnes.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 05-Mar-2001  nathanw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.18 02-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch() or pthread__locked_switch() (the
latter was never actually observed, but appeared possible).
 1.1.2.17 18-Dec-2002  nathanw Comment whitespace.
 1.1.2.16 18-Dec-2002  nathanw Tweak ucontext-alignment code so that it consumes at most 12 bytes of
stack space instead of 16, leaving 20 bytes avaliable.
 1.1.2.15 16-Sep-2002  skrll Fix typo in comment.
 1.1.2.14 06-Sep-2002  nathanw Ensure that stack regions allocated for storing ucontext_t's are
aligned to 16-byte boundaries; this ensures that the XMM save areas
are also 16-byte aligned, which is a requirement for use of the fxsave
and fxrstor instructions.
 1.1.2.13 14-Aug-2002  nathanw Define, initialize, and use function pointers for _{set,get,swap}context_u
routines, with different versions for saving FP state with fnsave or fxsave,
depending on the machdep.osfxsr sysctl.
 1.1.2.12 04-Sep-2001  nathanw Define STACKSPACE in pthread_md.h, not directly in pthread_switch.S
 1.1.2.11 01-Aug-2001  nathanw Rework the whole" ucontext vs. temporary crud on the bottom of the
stack" thing again, placing the burden of weirdness on STACK_SWITCH.

Add a lot of comments to explain why this is so tricky, and document
which functions are external.

In the old_preempt case of pthread__locked switch, save the thread's
real context so we don't try to switch back into the middle of this
code more than once.
 1.1.2.10 31-Jul-2001  nathanw Increase paranoia about keeping the ucontext on the bottom of the
stack: Find the location to put it, but don't move $esp there, so that
subsequent caller-save arguments and return addresses are above it
rather than below it.
 1.1.2.9 31-Jul-2001  nathanw Actually, we *do* need pthread__switch in assembler, in order that
the ucontext_t be the last thing on the stack. Otherwise, the switch
code will overwrite stack data, since it sets the stack to pt_uc.

Use the UT_EIP symbolic constant.

When performing a new_preempt, store into pt_switchto and
pt_switchtouc of the *new* thread, so that resolve_locks stands a
chance of finding the switchto victim.
 1.1.2.8 26-Jul-2001  nathanw pthread__switch() no longer needs to be implemeted in assembler,
and doesn't have a lock parameter.
 1.1.2.7 24-Jul-2001  nathanw Substantial rework:
- Make pthread__switch() just a plain switch, and move the
switch-to-next code to pthread__switch_away. Saves a stack switch,
test, and branch in the pthread_switch case, a _getcontext_u() and
associated stack frobbing in the switch_away case, and several
points of sanity.
- Remove a poorly-thought-out ucontext-dodge in STACK_SWITCH.
- Fill in PT_SWITCHTO and PT_SWITCHTOUC in the new_preempt path as
well as the old_preempt path in pthread__locked_switch() and
pthread__upcall_switch().
 1.1.2.6 23-Jul-2001  nathanw Pushing parameters on the stack is not the same as preserving their
values.
 1.1.2.5 20-Jul-2001  nathanw The %esi and %edi registers are callee-save, not caller-save.
 1.1.2.4 16-Jul-2001  nathanw Make pthread__switch() actually decrement fake spinlock counts when
told to do so by pthread__upcall_switch() or pthread__lock_switch().
 1.1.2.3 13-Jul-2001  nathanw Note copyright.
Standardize RCS IDs.
 1.1.2.2 29-Mar-2001  nathanw Don't frob pt_spinlocks in pthread__switch; we don't use it for
switching with locks held.
 1.1.2.1 05-Mar-2001  nathanw The beginnings of a scheduler activations-based pthread library.
 1.8.2.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.4 08-Oct-1997  scottr This incarnation of the pthreads library is ancient and not useful, and
should have been mothballed some time ago...
 1.3 07-Feb-1994  proven More wrapper functions, and some hacks for machine independent sleep
mechanisms.
 1.2 27-Jan-1994  mycroft Stylistic change.
 1.1 14-Nov-1993  proven branches: 1.1.1;
Initial revision
 1.1.1.1 14-Nov-1993  proven Initial release of the POSIX 1003.4a Draft 7 thread implementation.
 1.1 17-Apr-2015  martin Dummy ia64 support
 1.6 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 12-Oct-2003  chs branches: 1.4.32;
fix typo in previous.
 1.3 01-Mar-2003  scw Don't use FP instructions when building for m68010. Fixes broken sun2 build.
G/C some unused code.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.7 01-Dec-2001  scw Small cleanup of FP register context goo.
 1.1.2.6 25-Nov-2001  scw Checkpoint user-land context switch glue.

This code still needs some more thought, specifically for FPU context
save/restore. On m68k, it is not possible to completely save/restore
full FPU context from user-mode.
 1.1.2.5 21-Nov-2001  scw Don't bother stashing the CCR in the saved context; it's effectively a
caller saved register. Instead, clear the full 32-bit REG_PS value in
the context since the kernel's setcontext() call validates all 32-bits.

Also overwrite uc_flags with _UC_CPU instead of a logical OR.
 1.1.2.4 20-Nov-2001  scw Can't "rts" at the end of _getcontext_u() since we've already popped
the return address. Fortunately, it's in %a1 so just jmp to it.
 1.1.2.3 19-Nov-2001  scw Set the UC_CPU bit in UC_FLAGS for the GETC case.
Pointed out by Nathan Williams.
 1.1.2.2 19-Nov-2001  scw Tweak the context save/restore code; the first cut was a bit too simplistic.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4.32.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2001  scw Small cleanup of FP register context goo.
 1.1.2.3 25-Nov-2001  scw Add defines for FP registers and for some more uc_flags values.
Ditch CONTEXTSIZE in favour of RND_CTXSIZE which ensure the stack
is always longword aligned (and it brings m68k into line with most
other ports).
 1.1.2.2 19-Nov-2001  scw Tweak the context save/restore code; the first cut was a bit too simplistic.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6 25-Nov-2003  christos This is not needed anymore.
 1.5 22-Sep-2003  cl SA_SIGINFO support for m68k (libpthread)
 1.4 26-Jul-2003  mrg need <string.h>
 1.3 08-Mar-2003  lukem add __RCSID()
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 16-Jan-2003  thorpej branches: 1.1.2;
file pthread_md.c was initially added on branch nathanw_sa.
 1.1.2.1 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 25-Nov-2003  christos m68k does not sigcontext<->mcontext anymore.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.5 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.4 06-Aug-2002  nathanw struct reg/ucontext conversion glue.
 1.1.2.3 28-Jul-2002  gmcgarry _REG_SP -> _REG_A7 to match definition in mcontext.h.
 1.1.2.2 19-Nov-2001  scw The right value for STACKSPACE is 12, for 3 integer values in this
implementation. (Actually, we only need 10; 2 ints, 1 short, but best
to keep the stack long-word aligned).
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.8 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.7 23-Apr-2004  simonb s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.6 17-Sep-2003  cl fix pt_trapuc handling errors:
- movl to address register doesn't set flags (add explicit test)
- clr only clears a word (use clrl)
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 13-Jun-2003  scw Apply Nathan's switch-away fix and previous save-PT_UC from new stack fix.
Compile-tested only.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 18-Nov-2001  scw branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2001  scw G/C a superfluous assignment, and fix a PT_SWITCHTOUC bogon which
managed to creep in with the last change...
 1.1.2.3 25-Nov-2001  scw Cleanup of the thread switching MD glue.

With these changes, m68k now passes all Nathan's pthreads tests.
 1.1.2.2 20-Nov-2001  scw Fix a botched reference to a local label.
 1.1.2.1 18-Nov-2001  scw Initial cut of m68k-specific pthreads backend.
Compiles, but testing will have to wait until I've had some sleep.
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 07-Aug-2003  agc branches: 1.3.48;
Move UCB-licensed code from 4-clause to 3-clause licence.

Patches provided by Joel Baker in PR 22280, verified by myself.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file SYS.h was initially added on branch nathanw_sa.
 1.1.2.5 01-Dec-2002  wdk Remove nop
 1.1.2.4 24-Nov-2002  wdk Use __ABICALLS__
 1.1.2.3 23-Nov-2002  wdk PIC_CALL macros had a major side effect - last instruction has a jump
with an unfilled bdslot. Add nop instruction to ensure no side effect
and let the assembler try and remove it.
 1.1.2.2 20-Nov-2002  wdk Jump could not represent target in direct addressing mode.
Error discovered by current toolchain.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.3.48.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8; 1.3.14;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.34;
Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.3 01-Dec-2002  wdk - Use LEAF functions when nexted calls are not used.
- Reorder branch-delay slots and let teh assembler do the hard work.
 1.1.2.2 29-Nov-2001  wdk setcontext macro incorrectly used the RA (return address) as the target
PC to start the new context (RA == PC in getcontext so one may be lead
to believe it wouldn't matter).
Since the pthread__locked_switch() function updates the PC value we
must use the PC value in the context.

While we are the use T9 register for target PC value to maintain calling
conventions.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.2.34.1 18-May-2008  yamt sync with head.
 1.3.14.3 29-Apr-2011  matt Pull in fixes from -current.
 1.3.14.2 24-Aug-2009  matt Fix typo
 1.3.14.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8; 1.7.14;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.14;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 17-Jul-2003  nathanw Adapt to structure name changes.
 1.3 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.6.14.1 18-May-2008  yamt sync with head.
 1.7.14.1 16-Aug-2009  matt Make ABI agonstic (first pass).
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 25-Jan-2011  christos make pthread__sp unsigned long.
 1.8 16-May-2009  ad branches: 1.8.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.7 28-Apr-2008  martin branches: 1.7.8;
Remove clause 3 and 4 from TNF licenses
 1.6 24-Dec-2005  perry branches: 1.6.22;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.5 03-Jul-2004  simonb Catch up with changes to __fpregset_t.
In __longjmp14(), copy the FP CSR from the correct array and array slot.

Completes fix for PR port-mips/25942.
 1.4 26-Nov-2003  he branches: 1.4.2;
Hide the register number constants behind an _R_ prefix, and also
rename FPBASE to _FPBASE, so that we avoid polluting the user's
name space when e.g. <sys/ptrace.h> is included. Previously, the
PC symbol in mips/regnum.h would conflict with the declaration of
the external variable by the same name in termcap.h, as discovered
by the ``okheaders'' regression test.
 1.3 12-Jun-2003  nathanw STACKSPACE of 16 is too small, given the use of CALLFRAME_SIZ;
increase to match.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.5 20-Dec-2002  thorpej Update for mcontext_t changes.
 1.1.2.4 05-Dec-2002  thorpej Fix the reg <--> mcontext conversion macros. The reg structure is
equivalent to the frame structure, which has a slightly different
layout from the mcontext.
 1.1.2.3 01-Dec-2002  wdk Implement libpthread_dbg conversion macros.
 1.1.2.2 29-Nov-2001  wdk Drop STACKSPACE to 16 bytes
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.4.2.1 04-Jul-2004  he Pull up revision 1.5 (requested by simonb in ticket #591):
Changes fixing PR#25942:
o Catch up with changes to __fpregset_t. In __longjmp14(),
copy the FP CSR from the correct array and array slot.
 1.6.22.1 18-May-2008  yamt sync with head.
 1.7.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.7.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7 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.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.4 12-Jun-2003  nathanw Oops, that's switch_return_point, not locked_return_point. The perils
of cut-and-paste.
 1.3 12-Jun-2003  nathanw Apply switch-away fix and previous save-PT_UC from new stack fix.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 28-Nov-2001  wdk branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.4 01-Dec-2002  wdk Reorder branch-delay slot usage, and remove nop's

cond5 test with type 5 upcalls now work!!
 1.1.2.3 24-Nov-2002  wdk Use __ABICALLS__
 1.1.2.2 20-Nov-2002  wdk Use CALLFRAME_RA and CALLFRAME_SIZ instead of static contants.
 1.1.2.1 28-Nov-2001  wdk Initial pthread support for Mips processors.
 1.1 03-Sep-2014  matt New files for OR1K support
 1.6 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.5 10-Jul-2004  nathanw When _SOFT_FLOAT is defined, don't save or restore user FP context.
(note: still needs some mk rules tweaking for MKSOFTFLOAT=yes to pass
-msoft-float to asm builds).
 1.4 02-Jun-2004  nathanw Remove a comment made obsolete by the previous commit.
 1.3 12-Jun-2003  nathanw branches: 1.3.4;
Don't need to set the MSR field here; _INITCONTEXT_U_MD() takes care
of that where necessary.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.7 08-Aug-2002  nathanw Use register prefixes everywhere, now that asm.h no longer provides
the intermediate-format macros.
 1.1.2.6 21-Nov-2001  briggs Preserve LR and use CTR to hold new PC when setting new context.
 1.1.2.5 21-Nov-2001  briggs Save FP state as well as integer state.
Save reasonable constant in MSR (supervisor-only).
 1.1.2.4 20-Nov-2001  briggs Some cleanup.
 1.1.2.3 19-Nov-2001  briggs Use r prefixes for registers.
 1.1.2.2 17-Nov-2001  briggs Change SETC to use a fixed register (r4).
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.3.4.1 18-May-2005  riz Pull up revision 1.4 (requested by matt in ticket #1526):
Remove a comment made obsolete by the previous commit.
 1.8 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.7 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.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 20-Jan-2003  matt Add _REG_foo to ppc mcontext and use them instead of constants.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.2 21-Nov-2001  briggs Save FP state as well as integer state.
Save reasonable constant in MSR (supervisor-only).
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.9 11-Apr-2020  rin Revert previous:
http://mail-index.netbsd.org/source-changes/2020/02/20/msg114173.html

Comment turned out to be wrong, and KASSERT fires for oea.

XXX
Need to revisit shortly...
 1.8 20-Feb-2020  rin libpthread sets initial value of MSR for lwp's. However, appropriate
value differs b/w oea/booke/ibm4xx, and there's no way to obtain it
from userland. Therefore, this initial value should be corrected by
cpu_setmcontext().

- Comment this in libpthread
- Add KASSERT in cpu_mcontext_validate()
 1.7 25-Jan-2011  christos branches: 1.7.44; 1.7.46;
make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 24-Dec-2005  perry Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.4 11-Feb-2004  nathanw Add ucontext conversion macros for an "extra" register set.
 1.3 20-Jan-2003  matt Add _REG_foo to ppc mcontext and use them instead of constants.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.8 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.7 06-Dec-2002  nathanw sigcontext/ucontext glue.
 1.1.2.6 22-Oct-2002  nathanw Define _INITCONTEXT_U_MD() to set the MSR to a reasonable value.
 1.1.2.5 24-Apr-2002  nathanw Add macros to convert between struct ucontext and struct reg/fpreg.
 1.1.2.4 23-Mar-2002  nathanw Change operand constraint of "mr %0,1" from "=g" to "=r", since mr
really wants a register.

This fixes -g powerpc builds.
 1.1.2.3 20-Nov-2001  briggs Some cleanup.
 1.1.2.2 14-Nov-2001  briggs Add pthread__uc_pc() to pthread_md.h instead of making assumptions about
the contents of the m.d. mcontext.
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7.46.2 12-Apr-2020  martin Pull up following revision(s) (requested by rin in ticket #826):

lib/libpthread/arch/powerpc/pthread_md.h: revision 1.9
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.48

Revert previous:
http://mail-index.netbsd.org/source-changes/2020/02/20/msg114173.html
Comment turned out to be wrong, and KASSERT fires for oea.

XXX
Need to revisit shortly...
 1.7.46.1 27-Feb-2020  martin Pull up following revision(s) (requested by rin in ticket #736):

lib/libpthread/arch/powerpc/pthread_md.h: revision 1.8
sys/arch/powerpc/powerpc/sig_machdep.c: revision 1.47

libpthread sets initial value of MSR for lwp's. However, appropriate
value differs b/w oea/booke/ibm4xx, and there's no way to obtain it
from userland. Therefore, this initial value should be corrected by
cpu_setmcontext().

- Comment this in libpthread
- Add KASSERT in cpu_mcontext_validate()
 1.7.44.2 13-Apr-2020  martin Mostly merge changes from HEAD upto 20200411
 1.7.44.1 08-Apr-2020  martin Merge changes from current as of 20200406
 1.11 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.10 08-Jul-2006  ross remove unreferenced temporary label
 1.9 07-Jul-2004  nathanw Fix a comment to say "Edit" instead of "Exit".
 1.8 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.7 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.6 24-Jun-2003  nathanw Oops, reordering the PT_STATE/PT_SWITCHTOUC/PT_SWITCHTO assembly
killed a live value too soon. Fix by using a different register for
the PT_STATE immediate.
 1.5 23-Jun-2003  nathanw Update the switch_return point name in the static case.
 1.4 12-Jun-2003  nathanw Two fixes:
* In switch-away cases, write PT_SWITCHTO last (after PT_SWITCHTOUC), so
that pthread__resolve_locks() doesn't see an empty SWITCHTOUC value. This
also permits pthread__resolve_locks() to use the presence of PT_SWITCHTO
as a sign that the thread has done all of its necessary chain work.

* Make the return-point of pthread__switch global and visible, so that its
address can be compared to the PC of a thread, again as a sign that its
chain-work is done.

(other architectures in progress, after they get the *previous* asm fix...)
 1.3 06-Jun-2003  nathanw Fix typo in comment.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 13-Nov-2001  briggs branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.10 14-Jan-2003  nathanw Rewrite pthread__switch() and adjust pthread__locked_switch() to
avoid storing the new saved-context pointer while still using the old
stack. This avoids a race condition with pthread__find_interrupted()
where a thread could lose its old state if it was interrupted in a
certain window in pthread__switch().
 1.1.2.9 09-Nov-2002  nathanw Make pthread__locked_switch() work in a PIC world, now that the linker
is less lenient.

XXX the stack usage is probably overkill for the required alignment.
 1.1.2.8 08-Aug-2002  nathanw Use register prefixes everywhere, now that asm.h no longer provides
the intermediate-format macros.
 1.1.2.7 02-May-2002  nathanw Restore all three registers that are saved before the call to
pthread__sa_recycle. Fixes a problem where pt_switchtouc would end up
containing a small integer, rather than the ucontext pointer.
 1.1.2.6 26-Nov-2001  briggs Correct offset of ucontext on stack in pthread__switch().
Correct saved ucontext in PT_SLEEPUC in pthread__locked_switch().
 1.1.2.5 21-Nov-2001  briggs Update a couple of offsets I missed in earlier stack alignment.
 1.1.2.4 20-Nov-2001  briggs Some cleanup.
 1.1.2.3 19-Nov-2001  briggs Use r prefixes for registers.
 1.1.2.2 16-Nov-2001  briggs What crack was I on to use reg 0 in an addi instruction?
 1.1.2.1 13-Nov-2001  briggs Initial stab at pthread support for PPC.
 1.3 07-May-2023  skrll RISC-V support that works on QEMU with a single hart.

Thanks for Simon Burge for plic(4).
 1.2 31-Mar-2015  matt We have _REG_SP so use it.
 1.1 19-Sep-2014  matt New files for Userland support of UCB RISC-V (both 32-bit and 64-bit)
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 01-Jun-2008  uwe branches: 1.6.6;
Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.5 04-Jan-2006  uwe branches: 1.5.20; 1.5.22;
In PIC code call setcontext(2) via PLT to avoid text reloc in the
shared library.
 1.4 17-Nov-2003  uwe branches: 1.4.6;
Cause SIGTRAP if NOTREACHED code is reached.
 1.3 05-Jul-2003  uwe Not that the branch in SETC doens't have a delay slot, remove the
.empty comment as it's no longer pertinent.
 1.2 05-Jul-2003  marcus PIC patch from Valeriy E. Ushakov applied.
Also, removed bogus delay slot flag from branch instruction.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.4.6.1 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1095):
lib/libpthread/arch/sh3/_context_u.S: revision 1.5
In PIC code call setcontext(2) via PLT to avoid text reloc in the
shared library.
 1.5.22.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.5.20.1 04-Jun-2008  yamt sync with head
 1.6.6.2 01-Jun-2008  uwe Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.6.6.1 01-Jun-2008  uwe file _context_u.S was added on branch christos-time_t on 2008-06-01 23:07:21 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 01-Jun-2008  uwe branches: 1.8.6;
Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.7 28-Apr-2008  martin branches: 1.7.2;
Remove clause 3 and 4 from TNF licenses
 1.6 02-Mar-2007  ad branches: 1.6.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.5 18-Nov-2003  uwe Add necessary symbols.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 17-Jul-2003  nathanw Adapt to structure name changes.
 1.2 05-Jul-2003  marcus The field "pt_sleepuc" doesn't exist in struct pthread_st.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.6.12.2 04-Jun-2008  yamt sync with head
 1.6.12.1 18-May-2008  yamt sync with head.
 1.7.2.1 23-Jun-2008  wrstuden Sync w/ -current. 34 merge conflicts to follow.
 1.8.6.2 01-Jun-2008  uwe Recycle unused _REG_EXPEVT slot in mcontext for _REG_GBR.

As the size of mcontext is not changed, we avoid the hassle of
versioning all the calls that use it.

_REG_EXPEVT was never used by any code in the tree. Reporting EXPEVT
makes sense only for signals and in that case we pass it to userland
in ksi_trap already which is official MI way to get this (MD) information.

Old binaries running on new kernels will now have their GBR set from
new mcontext, but that's ok too, as GBR was not properly supported by
old kernels (not saved in trapframe), so old binaries couldn't have
possibly used it anyway.
 1.8.6.1 01-Jun-2008  uwe file genassym.cf was added on branch christos-time_t on 2008-06-01 23:07:21 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 27-Oct-2008  uwe branches: 1.6.4;
Fix typo in comment.
 1.5 27-Oct-2008  uwe Pull down revision 1.3.6.1 by skrll@ (adapted to include reg::r_gbr).

struct mcontext != struct reg on sh3.

Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT to deal with this.
 1.4 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.3 24-Dec-2005  perry branches: 1.3.4; 1.3.6; 1.3.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.2 20-Nov-2003  uwe Add _INITCONTEXT_U_MD, we need to clean _REG_SR.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.3.12.1 23-Mar-2008  matt sync with HEAD
 1.3.6.1 26-Feb-2008  skrll struct mcontext != struct reg on sh3.

Fix PTHREAD_UCONTEXT_TO_REG / PTHREAD_REG_TO_UCONTEXT to deal with this.
 1.3.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.6.4.2 27-Oct-2008  uwe Fix typo in comment.
 1.6.4.1 27-Oct-2008  uwe file pthread_md.h was added on branch christos-time_t on 2008-10-27 00:52:08 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.8 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.7 06-Jan-2006  uwe Use PLT for PIC calls to avoid text relocs in the shared library.
 1.6 31-Dec-2005  uwe Adapt to new PIC macros that are now in <machine/asm.h>. Same binary
code is generated (still with text relocs, but eliminating them is the
next step).
 1.5 28-May-2004  uwe branches: 1.5.2;
Fix typo in comment.
 1.4 20-Nov-2003  uwe Do not move incoming paramters to callee-save registers when not
necessary. Saves about a dozen of instructions.
 1.3 20-Nov-2003  uwe In pthread__locked_switch set self->pt_uc only when the context is inited.
In STACK_SWITCH subtract STACKSPACE, not add it (it's zero for now anyway).
 1.2 18-Nov-2003  uwe First cut at pthreads MD code for sh3. Based on m68k version.
Regression tests still failing: sem, sigalarm.
 1.1 23-Jun-2003  uwe First bits of SH3 support. Only _context_u.S is implemented (passess
cu[1-6] tests), the pthread_switch.S is stubbed out for now.

Code posted by Christian Groessler (cpg at aladdin dot de) to port-sh3.
 1.5.2.2 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1099):
lib/libpthread/arch/sh3/pthread_switch.S: revision 1.7
Use PLT for PIC calls to avoid text relocs in the shared library.
 1.5.2.1 11-Jan-2006  tron Pull up following revision(s) (requested by uwe in ticket #1094):
lib/libpthread/arch/sh3/pthread_switch.S: revision 1.6
Adapt to new PIC macros that are now in <machine/asm.h>. Same binary
code is generated (still with text relocs, but eliminating them is the
next step).
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.32;
Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.4 07-Jan-2003  thorpej UC_GREG -> UC_GREGS
 1.1.2.3 29-Nov-2002  uwe Add _UC_USER to genassym.cf and use it instead of hardcoded magic number.
 1.1.2.2 28-Nov-2002  uwe Save nPC in _getcontext_u() too, so that we can setcontext(2) it.
Cosmetic changes.
All context tests now work.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 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.7 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.6 29-Jul-2003  kleink Remove PT_SLEEPUC, which somehow wasn't.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 31-Jan-2003  pk Include <sys/types.h>
Remove v9 register defs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.3 18-Dec-2002  skrll Fix up after change to mcontext.h
 1.1.2.2 29-Nov-2002  uwe Add _UC_USER to genassym.cf and use it instead of hardcoded magic number.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 10-Nov-2003  martin All the ucontext <-> {fp}reg macros were slightly simplistic and untested
before (old gdb support on sparc did not use this).
Pointed out by Christian Limpach.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.2 18-Dec-2002  skrll Fix up after change to mcontext.h
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.9 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.8 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.7 07-Sep-2003  cl branches: 1.7.6;
Remove possible race condition in upcall recycling.
 1.6 07-Sep-2003  uwe Use delay slot in STACK_SWITCH (catching up with sparc64 changes).
 1.5 07-Sep-2003  uwe Use correct context to switch to.
From sparc64 fix by Andrey Petrov <petrov@netbsd>.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 17-Jun-2003  martin Catch up with Nathan's changes to other archs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 23-Nov-2002  martin branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.3 07-Jan-2003  thorpej UC_GREG -> UC_GREGS
 1.1.2.2 28-Nov-2002  uwe Remove few remaining sparc64'isms.
Some cosmetic changes.
 1.1.2.1 23-Nov-2002  martin Port of Andrey Petrovs sparc64 support to sparc. With input from
Valeriy E. Ushakov. Not yet tested.
 1.7.6.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.4 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.3 28-Apr-2008  martin branches: 1.3.8;
Remove clause 3 and 4 from TNF licenses
 1.2 18-Jan-2003  thorpej branches: 1.2.32;
Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file _context_u.S was initially added on branch nathanw_sa.
 1.1.2.5 23-Nov-2002  martin Minor style nits, express frame size by apropriate macro and reorder
one load sequence to avoid pipeline interlocks. From Valeriy E. Ushakov.
 1.1.2.4 19-Sep-2002  petrov PIC aware, remove debug cruft.
 1.1.2.3 21-May-2002  petrov STACK_SWITCH fix, added debug.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.2.32.1 18-May-2008  yamt sync with head.
 1.3.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.3.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 28-Apr-2008  martin branches: 1.8.8;
Remove clause 3 and 4 from TNF licenses
 1.7 02-Mar-2007  ad branches: 1.7.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 17-Jul-2003  nathanw Adapt to structure name changes.
 1.4 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.3 07-May-2003  petrov Add missing include and copyright.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file genassym.cf was initially added on branch nathanw_sa.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.7.12.1 18-May-2008  yamt sync with head.
 1.8.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7 25-Jan-2011  christos make pthread__sp unsigned long.
 1.6 16-May-2009  ad branches: 1.6.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.5 28-Apr-2008  martin branches: 1.5.8;
Remove clause 3 and 4 from TNF licenses
 1.4 24-Dec-2005  perry branches: 1.4.20;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 11-Nov-2003  martin Fix ucontext conversion macros. From Christian Limpach.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file pthread_md.h was initially added on branch nathanw_sa.
 1.1.2.4 16-Jan-2003  thorpej * Move the pthread_sigmask() prototype to <signal.h>.
* Don't include <signal.h> in <pthread.h>.
* Add code to the signal trampoline to convert from the ucontext
to a sigcontext, and back again (XXX though, only callee-save
regs for _UC_USER contexts).

This is necessary in order to support e.g. GCC's libjava, which depends
on the traditional Unix semantics of changes made to the sigcontext
being visible when the handler returns.
 1.1.2.3 10-Sep-2002  petrov regs/mcontext conversion macros.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Initial pthreads support
 1.4.20.1 18-May-2008  yamt sync with head.
 1.5.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.5.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.6.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.10 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.9 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.8 07-Sep-2003  cl branches: 1.8.6;
Remove possible race condition in upcall recycling.
 1.7 26-Aug-2003  petrov typo in previous commit, annul isn't good there,
noticed by Eduardo Horvath.
 1.6 25-Aug-2003  petrov Use branch-slot in STACK_SWITCH, suggested by Martin Husemann.
 1.5 25-Aug-2003  petrov Use correct context to switch to.
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 15-Jun-2003  martin Catch up with changes Nathan did to other archs.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 22-Feb-2002  petrov branches: 1.1.2;
file pthread_switch.S was initially added on branch nathanw_sa.
 1.1.2.6 20-Sep-2002  petrov minor clean-up.
 1.1.2.5 19-Sep-2002  petrov PIC aware, remove debug cruft.
 1.1.2.4 22-May-2002  petrov more fixes.
 1.1.2.3 21-May-2002  petrov STACK_SWITCH fix, added debug.
 1.1.2.2 26-Apr-2002  petrov round 2: simplify _get(set)context_u, add pthread__locked_switch.
 1.1.2.1 22-Feb-2002  petrov Implementation of pthread__switch only so far.
 1.8.6.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.
 1.5 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.4 28-Apr-2008  martin branches: 1.4.8;
Remove clause 3 and 4 from TNF licenses
 1.3 09-Apr-2005  matt branches: 1.3.20;
Rework and cleanup. Don't use REI, fake a call frame instead.
 1.2 19-Jan-2003  matt Set _UC_USER in ucontext. Call setcontext if _UC_USER is not in
_setcontext_u
 1.1 19-Jan-2003  matt VAX versions of _getcontext_u/_setcontext_u/_swapcontext_u
 1.3.20.1 18-May-2008  yamt sync with head.
 1.4.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.4.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.9 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.8 28-Apr-2008  martin branches: 1.8.8;
Remove clause 3 and 4 from TNF licenses
 1.7 02-Mar-2007  ad branches: 1.7.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.6 09-Apr-2005  matt Add STACKSPACE
 1.5 01-Dec-2004  skrll pt_sleepuc was removed a long time ago.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 25-Aug-2003  ragge Add PT_TRAPUC and pthread__switch_return_point.
Not tested (as most of the pthread stuff on vax) but at least
allow the system to compile.
 1.2 17-Jul-2003  nathanw Adapt to structure name changes.
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.7.12.1 18-May-2008  yamt sync with head.
 1.8.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.8.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.8 25-Jan-2011  christos make pthread__sp unsigned long.
 1.7 16-May-2009  ad branches: 1.7.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 10-Feb-2008  ad branches: 1.5.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.4 24-Dec-2005  perry branches: 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 20-Jan-2003  matt Define FPREG macros even though we don't have any.
 1.2 19-Jan-2003  matt Need to define STACKSIZE (even though we don't need any).
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.4.12.1 23-Mar-2008  matt sync with HEAD
 1.5.4.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.7 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.6 09-Apr-2005  matt Merge updates to algorithms from i386 switch code.
 1.5 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.4 25-Aug-2003  ragge Add PT_TRAPUC and pthread__switch_return_point.
Not tested (as most of the pthread stuff on vax) but at least
allow the system to compile.
 1.3 09-Jul-2003  matt Update to new world order. **not tested** But will allow builds to
finish.
 1.2 20-Jan-2003  matt Add myself to the authors list.
 1.1 19-Jan-2003  matt Add of pthread support for VAX.
 1.12 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.11 28-Apr-2008  martin branches: 1.11.8;
Remove clause 3 and 4 from TNF licenses
 1.10 10-Feb-2008  ad branches: 1.10.4;
- Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.9 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.8 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.7 11-Sep-2007  ad Fix a dodgy bit of assembly.
 1.6 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.5 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.4 21-Oct-2004  fvdl branches: 1.4.14; 1.4.18;
Fix thread context switching to take the stack ABI into account.
From Wolfgang Solfrank.
 1.3 08-Nov-2003  fvdl branches: 1.3.2;
Restore %rax correctly during a full context restore (oops).
 1.2 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.3.2.1 12-Nov-2004  jmc Pullup rev 1.4 (requested by fvdl in ticket #956)

Fix thread context switching to take the stack ABI into account.
 1.4.18.3 23-Mar-2008  matt sync with HEAD
 1.4.18.2 09-Jan-2008  matt sync with HEAD
 1.4.18.1 06-Nov-2007  matt sync with HEAD
 1.4.14.1 10-Sep-2007  skrll Sync with HEAD.
 1.10.4.1 18-May-2008  yamt sync with head.
 1.11.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.11.8.1 28-Apr-2008  martin file _context_u.S was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.7 16-May-2009  ad Remove unused code that's confusing when using cscope/opengrok.
 1.6 28-Apr-2008  martin branches: 1.6.8;
Remove clause 3 and 4 from TNF licenses
 1.5 02-Mar-2007  ad branches: 1.5.12;
Remove the PTHREAD_SA option. If M:N threads is reimplemented it's
better off done with a seperate library.
 1.4 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.3 17-Jul-2003  nathanw Adapt to structure name changes.
 1.2 26-Jun-2003  nathanw Remove PT_SLEEPUC and add PT_TRAPUC.
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.5.12.1 18-May-2008  yamt sync with head.
 1.6.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.6.8.1 28-Apr-2008  martin file genassym.cf was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.13 25-May-2023  riastradh libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:

- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register

- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437

XXX pullup-10
 1.12 25-Jan-2011  christos branches: 1.12.36; 1.12.46; 1.12.54;
make pthread__sp unsigned long.
 1.11 16-May-2009  ad branches: 1.11.2;
Remove unused code that's confusing when using cscope/opengrok.
 1.10 28-Apr-2008  martin branches: 1.10.8;
Remove clause 3 and 4 from TNF licenses
 1.9 22-Mar-2008  ad branches: 1.9.2;
Cheat and add inlines for _atomic_cas_ptr() to work around gcc emitting
unneeded PIC stuff in mutex_lock() and mutex_unlock(), when a thread
register is used.
 1.8 10-Feb-2008  ad - Remove libpthread's atomic ops.
- Remove the old spinlock-based mutex and rwlock implementations.
- Use the atomic ops from libc.
 1.7 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.6 24-Sep-2007  skrll Resurrect the function pointers for lock operations and allow each
architecture to provide asm versions of the RAS operations.

We do this because relying on the compiler to get the RAS right is not
sensible. (It gets alpha wrong and hppa is suboptimal)

Provide asm RAS ops for hppa.

(A slightly different version) reviewed by Andrew Doran.
 1.5 07-Sep-2007  ad Add: pthread__atomic_cas_ptr, pthread__atomic_swap_ptr, pthread__membar_full
This is a stopgap until the thorpej-atomic branch is complete.
 1.4 24-Dec-2005  perry branches: 1.4.8; 1.4.12;
Remove leading __ from __(const|inline|signed|volatile) -- it is obsolete.
 1.3 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.2 17-Apr-2003  fvdl Catch up with changed struct reg (same as gregs in mcontext now).
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.4.12.3 23-Mar-2008  matt sync with HEAD
 1.4.12.2 09-Jan-2008  matt sync with HEAD
 1.4.12.1 06-Nov-2007  matt sync with HEAD
 1.4.8.1 10-Sep-2007  skrll Sync with HEAD.
 1.9.2.1 18-May-2008  yamt sync with head.
 1.10.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.10.8.1 28-Apr-2008  martin file pthread_md.h was added on branch christos-time_t on 2008-04-28 20:23:03 +0000
 1.11.2.1 08-Feb-2011  bouyer Sync with HEAD
 1.12.54.1 01-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #296):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.

PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.

PR port-arm/57437
 1.12.46.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1700):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.12.36.1 04-Aug-2023  martin Pull up following revision(s) (requested by riastradh in ticket #1878):

lib/libpthread/arch/x86_64/pthread_md.h: revision 1.13
lib/libpthread/pthread_int.h: revision 1.110
lib/libpthread/pthread_int.h: revision 1.111
lib/libpthread/arch/i386/pthread_md.h: revision 1.21
lib/libpthread/arch/arm/pthread_md.h: revision 1.12
lib/libpthread/arch/arm/pthread_md.h: revision 1.13
lib/libpthread/pthread_spin.c: revision 1.11
lib/libpthread/arch/aarch64/pthread_md.h: revision 1.2

libpthread: Use __nothing, not /* nothing */, for empty macros.

No functional change intended -- just safer to do it this way in case
the macros are used in if branches or comma expressions.
PR port-arm/57437 (pthread__smt_pause/wake issue)

libpthread: New pthread__smt_wait to put CPU in low power for spin.

This is now distinct from pthread__smt_pause, which is for spin lock
backoff with no paired wakeup.

On Arm, there is a single-bit event register per CPU, and there are two
instructions to manage it:
- wfe, wait for event -- if event register is clear, enter low power
mode and wait until event register is set; then exit low power mode
and clear event register
- sev, signal event -- sets event register on all CPUs (other
circumstances like interrupts also set the event register and cause
wfe to wake)

These can be used to reduce the power consumption of spinning for a
lock, but only if they are actually paired -- if there's no sev, wfe
might hang indefinitely. Currently only pthread_spin(3) actually
pairs them; the other lock primitives (internal lock, mutex, rwlock)
do not -- they have spin lock backoff loops, but no corresponding
wakeup to cancel a wfe.

It may be worthwhile to teach the other lock primitives to pair
wfe/sev, but that requires some performance measurement to verify
it's actually worthwhile. So for now, we just make sure not to use
wfe when there's no sev, and keep everything else the same -- this
should fix severe performance degredation in libpthread on Arm
without hurting anything else.

No change in the generated code on amd64 and i386. No change in the
generated code for pthread_spin.c on arm and aarch64 -- changes only
the generated code for pthread_lock.c, pthread_mutex.c, and
pthread_rwlock.c, as intended.
PR port-arm/57437
 1.13 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.12 09-Jan-2006  skrll I was a bit over zealous with my last change so revert the
locked_return_point change.

Loading the instruction at locked_return_point as a return value didn't
work so well.

Thanks to uwe, cube, and dsl.
 1.11 04-Jan-2006  skrll A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:

- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.

Thanks to uwe@, dyoung@ and elad@ for help.

XXX sh3 is still to be done.
XXX vax does strange things.
 1.10 23-Apr-2004  simonb branches: 1.10.2;
s/the the/the/ (only in sources that aren't regularly imported from
elsewhere).
 1.9 08-Nov-2003  fvdl Make register usage more consistent, also in comparison with the i386
version, for easier maintenance.
 1.8 20-Oct-2003  fvdl Correct and simplify computing the return point; just use PC-relative
addressing.
 1.7 19-Oct-2003  fvdl Make sure the stack stays aligned.
 1.6 07-Sep-2003  cl Remove possible race condition in upcall recycling.
 1.5 26-Jul-2003  salo netbsd.org->NetBSD.org
 1.4 26-Jun-2003  nathanw Adapt to pt_trapuc: change STACK_SWITCH to check for a value in pt_trapuc
and use it preferentially to a value in pt_uc, clearing it once on the new
stack. Move stores into pt_uc back to before the stack switch; storing
after the stack switch opened a one-instruction race condition where an upcall
that had just started a chain could be preempted again, and would bomb when
restarted due to its pt_uc not yet having been updated. Now that pt_trapuc
is what the upcall code writes to, it is safe to store to pt_uc before
switching stacks.

Remove obsolete pt_sleepuc code.
 1.3 12-Jun-2003  fvdl Apply Nathan's switch-away fix.
 1.2 10-Feb-2003  fvdl Continue at the plain switch return point in pthread__switch, not the
locked one, in the !PIC case. From Tor Egge via Havard Eidnes.
 1.1 30-Jan-2003  fvdl libpthread support for x86_64.
 1.10.2.2 11-Jan-2006  tron Pull up following revision(s) (requested by skrll in ticket #1115):
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.12
I was a bit over zealous with my last change so revert the
locked_return_point change.
Loading the instruction at locked_return_point as a return value didn't
work so well.
Thanks to uwe, cube, and dsl.
 1.10.2.1 08-Jan-2006  riz Pull up following revision(s) (requested by skrll in ticket #1093):
lib/libpthread/arch/sparc/pthread_switch.S: revision 1.8
lib/libpthread/arch/x86_64/pthread_switch.S: revision 1.11
lib/libpthread/arch/sparc64/pthread_switch.S: revision 1.9
lib/libpthread/arch/i386/pthread_switch.S: revision 1.9
A couple of fixes to make libpthread really shared, i.e. not have text re-
locations:
- Don't declare pthread__switch_away global
- Do the PIC dance for pthread__switch_return_point and
pthread__locked_switch. Ideally these (and other) symbols would
be hidden.
Thanks to uwe@, dyoung@ and elad@ for help.
XXX sh3 is still to be done.
XXX vax does strange things.

RSS XML Feed