Home | History | Annotate | only in /src/lib/libc/thread-stub
History log of /src/lib/libc/thread-stub
RevisionDateAuthorComments
 1.4 05-Apr-2013  christos split init and errno to a separate file. No point in growing rtld 10K.
 1.3 18-Jan-2003  thorpej branches: 1.3.56; 1.3.62;
Merge the nathanw_sa branch.
 1.2 03-Dec-1999  explorer branches: 1.2.2; 1.2.8;
add. This holds the global __isthreaded variable, to indicate that threading
is (or is not) present.
 1.1 14-Nov-1999  explorer add stub thread functions. These are not (yet) used, and always return
success. They are weak-aliased, so if linked with a real pthreads library
the correct magic will happen.
 1.2.8.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.2.8.2 02-May-2002  nathanw Adapt to new dispatch-vector thread interface.
 1.2.8.1 16-Nov-2001  thorpej Add __indr_reference stubs so that an a.out libc works on its
own (a.out doesn't support __weak_alias).
 1.2.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.62.1 23-Jun-2013  tls resync from head
 1.3.56.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.3 01-Dec-2009  explorer Assign copyright to TNF
 1.2 12-Jun-2005  lukem branches: 1.2.26; 1.2.34;
Add missing __RCSID()
 1.1 03-Dec-1999  explorer branches: 1.1.2;
add. This holds the global __isthreaded variable, to indicate that threading
is (or is not) present.
 1.1.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.2.34.1 21-Apr-2010  matt sync to netbsd-5
 1.2.26.1 01-Dec-2009  explorer Assign copyright to TNF
 1.1 16-Nov-2001  thorpej branches: 1.1.2;
file pthread-indr.c was initially added on branch nathanw_sa.
 1.1.2.4 02-May-2002  nathanw Adapt to new dispatch-vector thread interface.
 1.1.2.3 25-Mar-2002  nathanw Bind libc's pthread desires to _libc_pthread_*, rather than pthread_*, to
prevent accidental use of pthread libraries that aren't actually integrated
with libc.
 1.1.2.2 01-Jan-2002  nathanw Weak/indirect references for pthread__errno().
 1.1.2.1 16-Nov-2001  thorpej Add __indr_reference stubs so that an a.out libc works on its
own (a.out doesn't support __weak_alias).
 1.4 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.3 22-Jan-2000  mycroft branches: 1.3.6;
Delint.
Remove trailing ; from uses of __weak_alias(). The macro inserts this if
needed.
 1.2 03-Dec-1999  explorer branches: 1.2.2;
typo
 1.1 14-Nov-1999  explorer add stub thread functions. These are not (yet) used, and always return
success. They are weak-aliased, so if linked with a real pthreads library
the correct magic will happen.
 1.2.2.1 27-Dec-1999  wrstuden Pull up to last week's -current.
 1.3.6.12 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.3.6.11 02-May-2002  nathanw Adapt to new dispatch-vector thread interface.
 1.3.6.10 25-Mar-2002  nathanw Bind libc's pthread desires to _libc_pthread_*, rather than pthread_*, to
prevent accidental use of pthread libraries that aren't actually integrated
with libc.
 1.3.6.9 11-Mar-2002  nathanw Remove spinlock stubs.
 1.3.6.8 23-Feb-2002  gmcgarry Prototype _pthread__errno().
 1.3.6.7 06-Feb-2002  nathanw All flockfile() stuff has moved to stdio/flockfile.c.
 1.3.6.6 01-Jan-2002  nathanw Weak/indirect references for pthread__errno().
 1.3.6.5 01-Jan-2002  wdk pt_spin_t has been renamed to pthread_spin_t
 1.3.6.4 18-Dec-2001  nathanw Delint (ugly).
 1.3.6.3 16-Nov-2001  thorpej Add __indr_reference stubs so that an a.out libc works on its
own (a.out doesn't support __weak_alias).
 1.3.6.2 16-Nov-2001  thorpej - Add return value to pthread_set_specific().
- Add a stub for ftrylockfile().
 1.3.6.1 08-Aug-2001  nathanw Add weak aliases and stub implementations for pthread_once,
pthread_cond*, pthread_key_create, pthread_{get,set}specific,
pthread_self.

Disable the pthread_rwlock stubs pending the creation of
pthread_rwlock_t and pthread_rwlockattr_t.
 1.2 19-Aug-2013  matt branches: 1.2.4;
Put the startup code in .text.startup
 1.1 05-Apr-2013  christos branches: 1.1.2;
split init and errno to a separate file. No point in growing rtld 10K.
 1.1.2.3 20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.1.2.2 23-Jun-2013  tls resync from head
 1.1.2.1 05-Apr-2013  tls file thread-stub-init.c was added on branch tls-maxphys on 2013-06-23 06:21:06 +0000
 1.2.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.2.4.1 19-Aug-2013  yamt file thread-stub-init.c was added on branch yamt-pagecache on 2014-05-22 11:36:54 +0000
 1.34 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.33 23-Sep-2024  christos Add weak aliases for methods used by the new jemalloc. Co-opt the mutex
catchall for now for it.
 1.32 19-Apr-2022  rillig branches: 1.32.4;
lib: remove CONSTCOND comment

Since 2021-01-31, lint doesn't need it anymore for the common pattern of
'do ... while (0)'.
 1.31 06-Feb-2021  jdolecek change libc sched_yield() stub to actually still call the syscall
instead of doing nothing when app is not linked with pthread; this matches
other systems

suggested by Mateusz Guzik in:
http://mail-index.netbsd.org/tech-kern/2020/07/19/msg026620.html
 1.30 14-Jan-2020  kamil Adjust the error return value of pthread_sigmask for !libpthread usage

Instead of returning -1, return errno on error.

Catch up after the fix in libpthread by Andrew Doran in 2008
in lib/libpthread/pthread_misc.c r.1.9.

It's an open question whether this function shall be used without linked
in the POSIX thread library.

Detected by Bruno Haible (GNU) and documented in gnulib in commit
"pthread_sigmask: Avoid test failure on NetBSD 8.0. " r. 4d16a83b0c1fcb6c.
 1.29 05-Mar-2019  christos branches: 1.29.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.28 31-Oct-2016  kamil branches: 1.28.14;
Add CHECK_NOT_THREADED() in __libc_mutexattr_settype_stub()

This makes this function consistent with __libc_mutex_catchall_stub()
and others in the same group.

Approved by <christos>.
 1.27 28-May-2013  christos branches: 1.27.10;
mark __libc_thr_exit_stub dead here too
 1.26 27-Apr-2013  joerg Provide stubs for pthread_detach/pthread_join.
 1.25 12-Apr-2013  joerg Weak alias directly to the catchall stub and don't strong alias twice.
 1.24 05-Apr-2013  christos split init and errno to a separate file. No point in growing rtld 10K.
 1.23 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.22 16-Sep-2011  joerg branches: 1.22.2; 1.22.4; 1.22.8;
Use __dead
 1.21 30-Jan-2009  ad Make threaded programs die correctly:

kill(getpid(), SIGFOO) -> raise(SIGFOO)
 1.20 28-Apr-2008  martin branches: 1.20.6; 1.20.8;
Remove clause 3 and 4 from TNF licenses
 1.19 14-Dec-2007  christos branches: 1.19.4;
add fw decl.
 1.18 14-Dec-2007  christos fix obvious bogon [can't alias symbol to itself]
 1.17 27-Nov-2007  ad Add thr_curcpu(), pthread_curcpu_np().
 1.16 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.15 13-Nov-2007  ad - stack_protector.c doesn't really belong under sys/. Add a new directory
for misc support routines and put it there.
- Add a libc constructor. Use this to initialize threading and the
stack protector stuff. libpthread cannot be initialized safely using
its own constructor because libc and libpthread are deeply intertwined.
PR bin/37347
 1.14 29-Nov-2005  christos branches: 1.14.10;
WARNS=4
 1.13 12-Jun-2005  lukem Add missing __RCSID()
 1.12 14-Dec-2004  nathanw Fix the __libc_thr_yield_stub() signature.
 1.11 13-Dec-2004  nathanw The __libc_thr_yield_stub() for scched_yield() should return int (and
a 0), not void.
 1.10 06-Dec-2004  nathanw Implement __libc_thr_sigsetmask_stub() in terms of sigprocmask(),
instead of having a dummy function.
 1.9 18-Jul-2003  nathanw Add a stub for setcancelstate().
 1.8 01-Mar-2003  matt Add #include <stdlib.h> for exit definition.
 1.7 20-Jan-2003  thorpej Simple TSD implementation, since some thread-safe libraries want
to use it.
 1.6 20-Jan-2003  thorpej Make thr_self() not return NULL.
 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  thorpej Add mutexattr_init(), mutexattr_destroy(), and mutexattr_settype() (recursive
mutexes are used by the X libraries).
 1.3 19-Jan-2003  thorpej Make the libc thr_once() stub functional.
 1.2 18-Jan-2003  thorpej Merge the nathanw_sa branch.
 1.1 08-Jan-2003  thorpej branches: 1.1.2;
file thread-stub.c was initially added on branch nathanw_sa.
 1.1.2.2 09-Jan-2003  nathanw __weak_alias() declarations don't compile with a semicolon at the
end.
 1.1.2.1 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.14.10.1 09-Jan-2008  matt sync with HEAD
 1.19.4.1 18-May-2008  yamt sync with head.
 1.20.8.2 28-Apr-2008  martin Remove clause 3 and 4 from TNF licenses
 1.20.8.1 28-Apr-2008  martin file thread-stub.c was added on branch christos-time_t on 2008-04-28 20:23:02 +0000
 1.20.6.1 02-Feb-2009  snj Pull up following revision(s) (requested by ad in ticket #399):
lib/libc/misc/stack_protector.c: revision 1.3
lib/libc/stdlib/abort.c: revision 1.13
lib/libc/thread-stub/thread-stub.c: revision 1.21
Make threaded programs die correctly:
kill(getpid(), SIGFOO) -> raise(SIGFOO)
 1.22.8.1 23-Jun-2013  tls resync from head
 1.22.4.2 29-Apr-2013  riz Pull up following revision(s) (requested by joerg in ticket #869):

Needed to fix build on alpha:

lib/libc/thread-stub/thread-stub.c: revision 1.25
Weak alias directly to the catchall stub and don't strong alias twice.
 1.22.4.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.22.2.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.27.10.1 04-Nov-2016  pgoyette Sync with HEAD
 1.28.14.2 08-Apr-2020  martin Merge changes from current as of 20200406
 1.28.14.1 10-Jun-2019  christos Sync with HEAD
 1.29.2.2 04-Feb-2023  martin Pull up following revision(s) (requested by uwe in ticket #1584):

lib/libc/thread-stub/thread-stub.c: revision 1.31

change libc sched_yield() stub to actually still call the syscall
instead of doing nothing when app is not linked with pthread; this matches
other systems

suggested by Mateusz Guzik in:
http://mail-index.netbsd.org/tech-kern/2020/07/19/msg026620.html
 1.29.2.1 04-Feb-2023  martin Pull up following revision(s) (requested by uwe in ticket #1583):

lib/libc/thread-stub/thread-stub.c: revision 1.30

Adjust the error return value of pthread_sigmask for !libpthread usage

Instead of returning -1, return errno on error.
Catch up after the fix in libpthread by Andrew Doran in 2008
in lib/libpthread/pthread_misc.c r.1.9.

It's an open question whether this function shall be used without linked
in the POSIX thread library.

Detected by Bruno Haible (GNU) and documented in gnulib in commit
"pthread_sigmask: Avoid test failure on NetBSD 8.0. " r. 4d16a83b0c1fcb6c.
 1.32.4.1 02-Aug-2025  perseant Sync with HEAD

RSS XML Feed