summaryrefslogtreecommitdiffstats
path: root/lib/libc/thread
AgeCommit message (Collapse)AuthorFilesLines
2021-01-06Fix two issues related to thread private data in asr.otto2-14/+18
- setting up asr in single thread mode and then starting threads using asr would lead to multiple threads sharing the same resolver. - destruction of a thread that has been using asr would leak data. Problem originally reported by Alexey Sokolov and Uli Schlachter. ok kettenis@
2020-10-12annoying whitespacederaadt1-2/+2
2020-07-06Add support for timeconting in userland.pirofti1-2/+2
This diff exposes parts of clock_gettime(2) and gettimeofday(2) to userland via libc eliberating processes from the need for a context switch everytime they want to count the passage of time. If a timecounter clock can be exposed to userland than it needs to set its tc_user member to a non-zero value. Tested with one or multiple counters per architecture. The timing data is shared through a pointer found in the new ELF auxiliary vector AUX_openbsd_timekeep containing timehands information that is frequently updated by the kernel. Timing differences between the last kernel update and the current time are adjusted in userland by the tc_get_timecount() function inside the MD usertc.c file. This permits a much more responsive environment, quite visible in browsers, office programs and gaming (apparently one is are able to fly in Minecraft now). Tested by robert@, sthen@, naddy@, kmos@, phessler@, and many others! OK from at least kettenis@, cheloha@, naddy@, sthen@
2020-02-06Instead of opting in to futexes on archs with atomics opt out on archsjsg1-8/+5
without atomics, a smaller list. ok mpi@ visa@
2019-10-21Kill unused _wait() function.mpi1-8/+1
ok visa@
2019-02-13KNF.mpi1-2/+2
Pointed out by pirofti@ while reviewing my rwlock impl. based on this one.
2019-01-29Remove unused <assert.h> header.mpi1-2/+1
2019-01-29There's no point in asserting that a pointer is not NULL beforempi1-3/+1
dereferencing it. ok kettenis@, visa@
2019-01-10Make the "not my pool" searching loop a tiny bit smarter, whileotto1-3/+59
making the number of pools variable. Do not document the malloc conf settings atm, don't know yet if they will stay. Thanks to all the testers. ok deraadt@
2018-10-21Switch alpha to futex(2) based condvars, mutexes and semaphores.visa1-5/+6
From Brad, tested by Miod, OK kettenis@
2018-10-15Switch powerpc to futex(2) based condvars, mutexes and semaphores.visa1-2/+2
From Brad, OK mpi@ kettenis@
2018-09-24enable futex(2) based mutexes on armv7 and use futex based semaphores injsg1-3/+3
librthread on armv7 as well from brad ok visa@ kettenis@ mpi@
2018-06-04Use process-private futexes. This avoids the overhead of calling into uvmkettenis1-6/+6
to look up the mapping for the futex address. ok visa@, mpi@
2018-05-19Switch sparc64 to futex(2) based mutexes and condvars.mpi1-2/+3
ok visa@
2018-05-13Enable futex(2)-based mutex on arm64.visa1-2/+3
OK mpi@, kettenis@
2018-05-13Add memory barriers to libc's _spinlock() to make the mechanismvisa1-2/+11
serialize memory accesses properly. _spinlock()'s backend, _atomic_lock(), already issues an entry barrier on some architectures, but that practice has not been consistent. This patch generalizes the barrier use. OK kettenis@, mpi@
2018-04-24Validate timespec and return ECANCELED when interrupted with SA_RESTART.pirofti1-3/+5
Discussing with mpi@ and guenther@, we decided to first fix the existing semaphore implementation with regards to SA_RESTART and POSIX compliant returns in the case where we deal with restartable signals. Currently we return EINTR everywhere which is mostly incorrect as the user can not know if she needs to recall the syscall or not. Return ECANCELED to signal that SA_RESTART was set and EINTR otherwise. Regression tests pass and so does the posixsuite. Timespec validation bits are needed to pass the later. OK mpi@, guenther@
2017-12-05Implement __cxa_thread_atexit to support C++11 thread_local scope. Thekettenis1-1/+2
interface is also made available as __cxa_thread_atexit_impl to satisfy the needs of GNU libstdc++. ok guenther@, millert@
2017-11-04Revert recent changes to unbreak ports/net/sambajca4-101/+10
While it is not clear (to me) why that ports ends up with corrupted shared libs, reverting those changes fixes the issue and should allow us to close p2k17 more smoothly. Discussed with a bunch, ok ajacoutot@ guenther@
2017-10-28If the init_routine used with pthread_once() is canceled, then we need toguenther1-1/+11
unlock the mutex inside the pthread_once_t. Push a cleanup wrapper for that. Diff from Scott Cheloha <scottcheloha@gmail.com> ok mpi@
2017-10-28Change pthread_cleanup_{push,pop} to macros that store the cleanup infoguenther3-9/+90
on the stack instead of mallocing the list and move the APIs from libpthread to libc so that they can be used inside libc. Note: the standard was explicitly written to permit/support this "macro with unmatched brace" style and it's what basically everyone else already does. We xor the info with random cookies with a random magic to detect/trip-up overwrites. Major bump to both libc and libpthread due to the API move. ok mpi@
2017-09-05Move mutex, condvar, and thread-specific data routes, pthread_once, andguenther12-863/+161
pthread_exit from libpthread to libc, along with low-level bits to support them. Major bump to both libc and libpthread. Requested by libressl team. Ports testing by naddy@ ok kettenis@
2017-08-15s/DEF_STD/DEF_STRONG/ to match namespace.h differences between librthreadguenther5-29/+29
and libc
2017-08-15Sort headers per style(9)guenther10-34/+31
2017-08-15Copy files from ../librthread in preparation for moving functionalityguenther13-0/+3158
from libpthread to libc. No changes to the build yet, just making it easier to review the substantive diffs. ok beck@ kettenis@ tedu@
2016-09-02fix format stringchl1-2/+2
ok guenther@
2016-05-07Use a Thread Information Block in both single and multi-threaded programs.guenther4-137/+22
This stores errno, the cancelation flags, and related bits for each thread and is allocated by ld.so or libc.a. This is an ABI break from 5.9-stable! Make libpthread dlopen'able by moving the cancelation wrappers into libc and doing locking and fork/errno handling via callbacks that libpthread registers when it first initializes. 'errno' *must* be declared via <errno.h> now! Clean up libpthread's symbol exports like libc. On powerpc, offset the TIB/TCB/TLS data from the register per the ELF spec. Testing by various, particularly sthen@ and patrick@ ok kettenis@
2015-11-10libc.so can't be unloaded, so move the hidden atexit() and pthread_atfork()guenther1-1/+18
stubs for the executable from crtbegin.o into libc, which lets them be excluded from static links that don't use them. For this, drop the normal crt{begin,end}S.o from libc.so: the .init and .fini sections for libc aren't called at the right times anyway, so it's good that they're unused. libc.so just needs __guard_local and the .note.openbsd.ident section, so add them to stack_protector.c for now (this will be improved) "good time" deraadt@
2015-04-07Make pthread_atfork() track the DSO that called it like atexit() does,guenther3-3/+77
unregistering callbacks if the DSO is unloaded. Move the callback handling from libpthread to libc, though libpthread still overrides the inner call to handle locking and thread-library reinitialization. Major version bump for both libc and libpthread. verification that this fixes various ports ajacoutot@ asm assistance miod@; ok millert@ deraadt@
2014-07-16zap trailing newlines; "go for it" deraadtokan1-2/+1
2008-06-13remove _MALLOC_LOCK_INIT; major bump; ok deraadt@otto1-9/+1
2008-01-01- make arc4random*() functions thread safe. Use a custom spinlock functionkurt1-1/+19
instead of the generic pthread macros since free(3) uses __arc4_getbyte() when freeing small sized allocations and the generic pthread macros call malloc(3). - eliminate passing pointers to a static variable with global scope (rs) for additional code clarity and reduction. - shlib minor bumps for libc and libpthread due to new functions. From andreas@ with some bits from me. okay tedu@ marc@ w/some spot checking from millert@
2007-11-19remove unused zero length file.kurt1-0/+0
2007-06-05_FD_LOCK/UNLOCK() is libpthread specific and not needed for librthread, sokurt3-24/+51
isolate its usage to libpthread only and replace with generic non-static mutex support in the one place it is needed: - remove _FD_LOCK/UNLOCK from lseek and ftruncate in libc and make the functions weak so that libpthread can override with its own new versions that do the locking. - remove _thread_fd_lock/unlock() weak functions from libc and adjust libpthread for the change. - add generic _thread_mutex_lock/unlock/destroy() weak functions in libc to support non-static mutexes in libc and add libpthread and librthread implementations for them. libc can utilize non-static mutexes via the new _MUTEX_LOCK/UNLOCK/DESTROY() macros. Actually these new macros can support both static and non-static mutexes but currently only using them for non-static. - make opendir/closedir/readdir/readdir_r/seekdir/telldir() thread-safe for both thread libraries by using a non-static mutex in the struct _dirdesc (typedef DIR), utilizing it in the *dir functions and remove remaining and incorrect _FD_LOCK/UNLOCK() use in libc. - add comments to both thread libraries to indicate libc depends on the current implementation of static mutex initialization. suggested by marc@ - major bump libc and libpthread due to function removal, structure change and weak symbol conversions. okay marc@, tedu@
2006-02-22Avouid a race in atexit() handling by introducing a lock. Problemotto1-1/+19
originally reported by Gergely Kovacs; help from dhartmei@; ok tedu@ millert@
2004-06-07major bump to libc and libpthread to break the dependency of amarc5-51/+39
particular implementation of libpthread for libc. libc no longer needs pthread.h to compile. OK millert@, brad@, tedu@
2002-11-05thread safe libc -- 2nd try. OK miod@, millert@marc3-37/+20
Thanks to miod@ for m68k and vax fixes
2002-11-03back out previous patch.. there are still some vax/m68k issuesmarc3-20/+37
2002-11-03libc changes for thread safety. Tested on:marc3-37/+20
alpha (millert@), i386 (marc@), m68k (millert@ and miod@), powerpc (drahn@ and dhartmei@), sparc (millert@ and marc@), sparc64 (marc@), and vax (millert@ and miod@). Thanks to millert@, miod@, and mickey@ for fixes along the way.
2001-09-04put changes back, this time ALL the files.fgsch1-3/+3
2001-08-30Back out fgsch@'s tree breaking commits.todd1-3/+3
Test next time, ok?
2001-08-30fix some const warningsfgsch1-3/+3
2000-01-14malloc lock helpersd1-0/+21
2000-01-06rename thread_storage to unithread_storage to avoid object name conflictd2-3/+3
2000-01-06thread specific storage and fd locking for single-threaded libc (ie, no-ops)d3-0/+98