aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr/thread
Commit message (Collapse)AuthorAgeFilesLines
* MFC r346158:Konstantin Belousov2019-04-191-2/+3
| | | | | | | | | Do not access mutex memory after unlock. PR: 237195 Notes: svn path=/stable/11/; revision=346372
* MFC r345703:Konstantin Belousov2019-04-122-0/+35
| | | | | | | Fix initial exec TLS mode for dynamically loaded shared objects. Notes: svn path=/stable/11/; revision=346156
* MFC r337992, r338125:Pedro F. Giffuni2018-09-1711-44/+61
| | | | | | | | | | | | | | | | POSIX compliance improvements in the pthread(3) functions. This basically adds makes use of the C99 restrict keyword, and also adds some 'const's to four threading functions: pthread_mutexattr_gettype(), pthread_mutexattr_getprioceiling(), pthread_mutexattr_getprotocol(), and pthread_mutex_getprioceiling. The changes are in accordance to POSIX/SUSv4-2018. Hinted by: DragonFlyBSD Relnotes: yes Notes: svn path=/stable/11/; revision=338707
* MFC r337983, r338044:Konstantin Belousov2018-08-313-11/+58
| | | | | | | Add pthread_get_name_np(3). Notes: svn path=/stable/11/; revision=338405
* MFC 331324: Ensure thread library is initialized in pthread_testcancel().John Baldwin2018-04-161-1/+3
| | | | | | | | | | | | | | | Call _thr_check_init() before reading curthread in pthread_testcancel(). If a constructor in a library creates a semaphore via sem_init() and then waits for it via sem_wait(), the program can core dump in _pthread_testcancel() called from sem_wait(). This is because the semaphore implementation lives in libc, so the library's constructors can be run before libthr's constructors. Sponsored by: DARPA / AFRL Notes: svn path=/stable/11/; revision=332633
* Revert r330897:Eitan Adler2018-03-2955-160/+49
| | | | | | | | | | | | | | | | | | | | This was intended to be a non-functional change. It wasn't. The commit message was thus wrong. In addition it broke arm, and merged crypto related code. Revert with prejudice. This revert skips files touched in r316370 since that commit was since MFCed. This revert also skips files that require $FreeBSD$ property changes. Thank you to those who helped me get out of this mess including but not limited to gonzo, kevans, rgrimes. Requested by: gjb (re) Notes: svn path=/stable/11/; revision=331722
* Partial merge of the SPDX changesEitan Adler2018-03-1455-49/+160
| | | | | | | | | | These changes are incomplete but are making it difficult to determine what other changes can/should be merged. No objections from: pfg Notes: svn path=/stable/11/; revision=330897
* MFC r320990, r321011:Pedro F. Giffuni2017-08-011-1/+1
| | | | | | | | | libthr: Avoid checking for negative values in usigned count. Check for overflow instead. Notes: svn path=/stable/11/; revision=321832
* MFC r318582Eric van Gyzen2017-06-012-7/+6
| | | | | | | | | | | | | | Remove old spinlock_debug code from libc This no longer seems useful. Remove it. This was prompted by a "cast discards volatile qualifier" warning in libthr when WARNS=6. Sponsored by: Dell EMC Notes: svn path=/stable/11/; revision=319442
* MFC r318539 r318580 r318581 r318584 r318749 r318952 r318953 r318955Eric van Gyzen2017-06-0111-58/+96
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | libthr: fix warnings at WARNS=6 Fix warnings about the following when WARNS=6 (which I will commit soon): - casting away const - no previous 'extern' declaration for non-static variable - others as explained by #pragmas and comments - unused parameters libthr: disable thread-safety warnings These warnings don't make sense for code that implements the locking primitives. libthr: change CHECK_AND_INIT_RWLOCK to an inline function This was prompted by a compiler warning about 'ret' shadowing a local variable in the callers of the macro. libthr: Use CLI flags instead of pragmas to disable warnings People tweaking the build system or compilers tend to look into the Makefile and not into the source. Having some warning controls in the Makefile and some in the source code is surprising. Pragmas have the advantage that they leave the warnings enabled for more code, but that advantage isn't very relevant in these cases. libthr: fix warnings from GCC when WARNS=6 Fix warnings about: - redundant declarations - a local variable shadowing a global function (dlinfo) - an old-style function definition (with an empty parameter list) - a variable that is possibly used uninitialized libthr: prevent setcontext() from masking SIGTHR __thr_setcontext() mistakenly tested for the presence of SIGCANCEL in its local ucontext_t instead of the parameter. Therefore, if a thread calls setcontext() with a context whose signal mask contains SIGTHR (a.k.a. SIGCANCEL), that signal will be blocked, preventing the thread from being cancelled or suspended. Sponsored by: Dell EMC Notes: svn path=/stable/11/; revision=319430
* MFC r318254:Jason Evans2017-05-141-1/+1
| | | | | | | | | Fix __pthread_mutex_trylock() to call THR_CRITICAL_LEAVE() on failure rather than on success. This regression was introduced by r300043 (Add implementation of robust mutexes...). Notes: svn path=/stable/11/; revision=318277
* MFC r315526Eric van Gyzen2017-05-012-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | Add clock_nanosleep() Add a clock_nanosleep() syscall, as specified by POSIX. Make nanosleep() a wrapper around it. Attach the clock_nanosleep test from NetBSD. Adjust it for the FreeBSD behavior of updating rmtp only when interrupted by a signal. I believe this to be POSIX-compliant, since POSIX mentions the rmtp parameter only in the paragraph about EINTR. This is also what Linux does. (NetBSD updates rmtp unconditionally.) Copy the whole nanosleep.2 man page from NetBSD because it is complete and closely resembles the POSIX description. Edit, polish, and reword it a bit, being sure to keep any relevant text from the FreeBSD page. Regenerate syscall files. Relnotes: yes Sponsored by: Dell EMC Notes: svn path=/stable/11/; revision=317618
* MFC r312934:Pedro F. Giffuni2017-03-141-5/+7
| | | | | | | | | | | | | | | | | | Make use of clang nullability attributes in C headers. Replace uses of the GCC __nonnull__ attribute with the clang nullability qualifiers. These are starting to get use in clang's static analyzer. Replacement should be transparent for developers using clang. GCC ports from older FreeBSD versions may need updating if the compiler was built before r312860 (Jan-27-2017). Hinted by: Apple's Libc-1158.20.4, Bionic libc Relnotes: yes Notes: svn path=/stable/11/; revision=315282
* MFC r309630:Konstantin Belousov2016-12-131-2/+12
| | | | | | | Do not leak curthread->inact_mtx when cancelling in pthread_cond_wait(3). Notes: svn path=/stable/11/; revision=310016
* MFC r304209:Konstantin Belousov2016-08-291-0/+15
| | | | | | | The fdatasync(2) call must be cancellation point. Notes: svn path=/stable/11/; revision=304980
* MFC r303795:Konstantin Belousov2016-08-201-1/+8
| | | | | | | Add __cxa_thread_atexit(3) API implementation. Notes: svn path=/stable/11/; revision=304524
* MFC r303393:Konstantin Belousov2016-08-033-7/+0
| | | | | | | | | Remove empty initializer for the once facility. Approved by: re (gjb) Notes: svn path=/stable/11/; revision=303708
* Revert r302194, there are issues with some applications after changingKonstantin Belousov2016-06-251-4/+1
| | | | | | | | | | | | the return value, in particular console-kit-daemon. Reported by: Ivan Klymenko <fidaj@ukr.net> Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Approved by: re (gjb) Notes: svn path=/head/; revision=302201
* For pthread_mutex_trylock() call on owned error-check or non-portableKonstantin Belousov2016-06-251-2/+5
| | | | | | | | | | | | | adaptive mutex, return EDEADLK as required by POSIX. The pthread_mutex_lock() is already compliant. Tested by: Guy Yur <guyyur@gmail.com> Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Approved by: re (gjb) Notes: svn path=/head/; revision=302194
* libthr: Use formatted PANIC()Conrad Meyer2016-06-013-24/+10
| | | | | | | | | | | | No functional change, although _thread_printf() may be slightly less functional or render some values differently from libc snprintf(3). No ABI change. Reviewed by: kib Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D6672 Notes: svn path=/head/; revision=301136
* libthr: _thread_vprintf: Enhance support for %p, %#xConrad Meyer2016-06-011-1/+8
| | | | | | | | | | | No functional change. No ABI change. Reviewed by: kib Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D6672 Notes: svn path=/head/; revision=301135
* libthr: Add vprintf variant of _thread_printf, formatted PANIC()Conrad Meyer2016-06-013-11/+34
| | | | | | | | | | | No ABI change. Reviewed by: kib Sponsored by: EMC / Isilon Storage Division Differential Revision: https://reviews.freebsd.org/D6672 Notes: svn path=/head/; revision=301134
* Stop inlining the struct ucond definition into struct pthread_cond.Konstantin Belousov2016-05-292-15/+11
| | | | | | | | | | | | | | | | | | | | This avoids unneccessary casts and make the calls to _thr_ucond_*() functions less questionable. The c_spare field was not included into struct pthread_cond, so the change modifies libthr ABI for shared condvars. But since an off-page does not legitimately contains any other data past the struct pthread_cond, the change keeps shared condvars from pre- and post- changed libthr compatible. Also note that the whole struct ucond was never copied in or out by kernel. For private condvars, the privately allocated memory was never exposed outside libthr. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=300971
* Add implementation of robust mutexes, hopefully close enough to theKonstantin Belousov2016-05-177-298/+612
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | intention of the POSIX IEEE Std 1003.1TM-2008/Cor 1-2013. A robust mutex is guaranteed to be cleared by the system upon either thread or process owner termination while the mutex is held. The next mutex locker is then notified about inconsistent mutex state and can execute (or abandon) corrective actions. The patch mostly consists of small changes here and there, adding neccessary checks for the inconsistent and abandoned conditions into existing paths. Additionally, the thread exit handler was extended to iterate over the userspace-maintained list of owned robust mutexes, unlocking and marking as terminated each of them. The list of owned robust mutexes cannot be maintained atomically synchronous with the mutex lock state (it is possible in kernel, but is too expensive). Instead, for the duration of lock or unlock operation, the current mutex is remembered in a special slot that is also checked by the kernel at thread termination. Kernel must be aware about the per-thread location of the heads of robust mutex lists and the current active mutex slot. When a thread touches a robust mutex for the first time, a new umtx op syscall is issued which informs about location of lists heads. The umtx sleep queues for PP and PI mutexes are split between non-robust and robust. Somewhat unrelated changes in the patch: 1. Style. 2. The fix for proper tdfind() call use in umtxq_sleep_pi() for shared pi mutexes. 3. Removal of the userspace struct pthread_mutex m_owner field. 4. The sysctl kern.ipc.umtx_vnode_persistent is added, which controls the lifetime of the shared mutex associated with a vnode' page. Reviewed by: jilles (previous version, supposedly the objection was fixed) Discussed with: brooks, Martin Simmons <martin@lispworks.com> (some aspects) Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=300043
* Do not leak THR_FLAGS_SUSPENDED from the previous suspend/resumeKonstantin Belousov2016-05-052-4/+2
| | | | | | | | | | | | | | | | | cycle. The flag currently is cleared by the resumed thread. If next suspend request comes before the thread was able to clean the flag, in which case suspender skip the thread. Instead, clear the THR_FLAGS_SUSPEND flag in resume_common(), we do not care how much code was executed in the resumed thread when the pthread_resume_*np(s) functions returned. PR: 209233 Reported by: Lawrence Esswood <le277@cam.ac.uk> MFC after: 1 week Notes: svn path=/head/; revision=299114
* If off-page lookup failed, there is no memory to performKonstantin Belousov2016-04-121-1/+2
| | | | | | | | | shared_mutex_init() upon. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297853
* Use __FBSDID() for .c files from lib/libthr/thread.Konstantin Belousov2016-04-0852-112/+158
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297706
* Use ANSI C function definitions, fix spelling in a comment.Konstantin Belousov2016-04-083-4/+5
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297704
* Assert that the lock objects put into the off-page, fit into the page.Konstantin Belousov2016-04-085-0/+15
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297701
* Remove unused variable. It was write-only before r297139.Konstantin Belousov2016-04-042-2/+0
| | | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=297535
* Apparently there are some popular programs around which assume that itKonstantin Belousov2016-03-222-2/+61
| | | | | | | | | | | | | | | | | | | | is safe to call pthread_mutex_init() on the same shared mutex several times. POSIX claims that the behaviour in this case is undefined. Make this working by only allowing one caller to initialize the mutex. Other callers either see already completed initialization and do nothing, or busy-loop yielding while designated initializer finishes. Also make the API requirements loose by initializing mutexes on other pthread_mutex*() calls if they see uninitialized shared mutex. Only mutexes provide the hack for now, but it could be also implemented for other process shared primitives from libthr. Reported and tested by: "Oleg V. Nauman" <oleg@opentransfer.com> Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297185
* Lock pshared_lock shared around fork, to ensure that the COW snapshotKonstantin Belousov2016-03-214-2/+22
| | | | | | | | | | of the pshared hash in child is consistent and can be safely used. Reported and tested by: "Oleg V. Nauman" <oleg@opentransfer.com> Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297141
* Provide more information on failing checks in mutex_assert_is_owned()Konstantin Belousov2016-03-211-4/+16
| | | | | | | | | | and mutex_assert_not_owned(). snprintf() use in this context should be safe. Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297140
* From libthr, remove special and strange code to set up session andKonstantin Belousov2016-03-212-22/+2
| | | | | | | | | | | | | | | control terminal, activated when running with pid 1. It is application duty to handle this, and unsuspecting init replacements which are linked with libthr would be broken by this. The pre-resolving of getpid() is restored, just in case. Reviewed by: jilles Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=297139
* Implement process-shared spinlocks.Konstantin Belousov2016-03-211-47/+58
| | | | | | | Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=297138
* Add two comments explaining the fine points of the hashKonstantin Belousov2016-03-011-0/+31
| | | | | | | | | | | implementation. Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D5490 Notes: svn path=/head/; revision=296268
* Implement process-shared locks support for libthr.so.3, withoutKonstantin Belousov2016-02-2813-304/+785
| | | | | | | | | | | | | | | breaking the ABI. Special value is stored in the lock pointer to indicate shared lock, and offline page in the shared memory is allocated to store the actual lock. Reviewed by: vangyzen (previous version) Discussed with: deischen, emaste, jhb, rwatson, Martin Simmons <martin@lispworks.com> Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=296162
* If libthr.so is dlopened without RTLD_GLOBAL flag, the libthr symbolsKonstantin Belousov2016-02-083-2/+4
| | | | | | | | | | | | | | | | | | | | | | | | | do not participate in the global symbols namespace, but rtld locks are still replaced and functions are interposed. In particular, __pthread_map_stacks_exec is resolved to the libc version. If a library is loaded later, which requires adjustment of the stack protection mode, rtld calls into libc __pthread_map_stacks_exec due to the symbols scope. The libc version might recurse into binder and recursively acquire rtld bind lock, causing the hang. Make libc __pthread_map_stacks_exec() interposed, which synchronizes rtld locks and version of the stack exec hook when libthr loaded, regardless of the symbol scope control or symbol resolution order. The __pthread_map_stacks_exec() symbol is removed from the private version in libthr since libc symbol now operates correctly in presence of libthr. Reported and tested by: markj Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=295407
* libthr: const-ify two variablesEric van Gyzen2016-01-131-2/+3
| | | | | | | | | | | Make the default umutex and urwlock initializers const, because they can be, and as a microoptimization. MFC after: 5 days Sponsored by: Dell Inc. Notes: svn path=/head/; revision=293858
* Typo.Konstantin Belousov2015-12-271-1/+1
| | | | Notes: svn path=/head/; revision=292763
* libthr: Don't use both __sys_open() and __sys_openat().Jilles Tjoelker2015-12-202-2/+1
| | | | Notes: svn path=/head/; revision=292516
* Style. Use ANSI definition, wrap long lines, no initialization inKonstantin Belousov2015-09-081-8/+15
| | | | | | | | | | declaration for locals. Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=287557
* In the pthread_once(), if the initializer has already run, then theKonstantin Belousov2015-09-081-3/+5
| | | | | | | | | | | | | | | | | | | | calling thread is supposed to see accesses issued by the initializer. This means that the read of the once_control->state variable should have an acquire semantic. Use atomic_thread_fence_acq() when the value read is ONCE_DONE, instead of straightforward atomic_load_acq(), to only put a barrier when needed (*). On the other hand, the updates of the once_control->state with the intermediate progress state do not need to synchronize with other state accesses, remove _acq suffix. Reviewed by: alc (previous version) Suggested by: alc (*) Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=287556
* Pre-resolve symbols required for the deferred signal processing. ThisKonstantin Belousov2015-08-102-1/+9
| | | | | | | | | | | | | | | | avoids recursion into rtld when leaving libthr critical section for the deferred signal delivery. For the same reason, use syscall(2) instead of referencing __sys_sigreturn(2). Syscall() is already pre-resolved for fork() interceptor. Tested by: Andre Meiser <ortadur@web.de> Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=286582
* cosmetic: whitespaces-tab before EOLPedro F. Giffuni2015-07-081-1/+1
| | | | | | | Obtained from: cpi-llvm project Notes: svn path=/head/; revision=285278
* Fix typo in comment.Konstantin Belousov2015-06-141-2/+2
| | | | | | | MFC after: 3 days Notes: svn path=/head/; revision=284385
* Some third-party malloc(3) implementations use pthread_setspecific(3)Konstantin Belousov2015-05-151-110/+91
| | | | | | | | | | | | | | | | | | | | | | | | | | | | to handle per-thread information. Since our pthread_setspecific() implementation calls calloc(3) to allocate per-thread specific data storage, things get complicated. Switch the allocator to use bare mmap(2). There is some loss of the allocated page, since e.g. on amd64, PTHREAD_KEYS_MAX * sizeof(struct pthread_specific_elem) is 3K (it actually spans whole page due to padding), but I believe it is more acceptable than additional code for specialized allocator(). The alternatives would either to make the specific data array be part of the struct thread, or use internal bindings to call the libc malloc, avoiding interposing. Also do the style pass over the thr_spec.c, esp. simplify the conditionals nesting by returning early when an error detected. Remove trivial comments. Found by: yuri@rawbw.com PR: 200138 Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=282948
* _pthread_cleanup_push: fix allocator sizeof operand mismatchPedro F. Giffuni2015-04-221-1/+1
| | | | | | | | | | Same fix appears to be in DragonFly's libthread_xu. Found by: Clang Static Analyzer MFC after: 1 week Notes: svn path=/head/; revision=281857
* The lseek(2), mmap(2), truncate(2), ftruncate(2), pread(2), andKonstantin Belousov2015-04-181-12/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | pwrite(2) syscalls are wrapped to provide compatibility with pre-7.x kernels which required padding before the off_t parameter. The fcntl(2) contains compatibility code to handle kernels before the struct flock was changed during the 8.x CURRENT development. The shims were reasonable to allow easier revert to the older kernel at that time. Now, two or three major releases later, shims do not serve any purpose. Such old kernels cannot handle current libc, so revert the compatibility code. Make padded syscalls support conditional under the COMPAT6 config option. For COMPAT32, the syscalls were under COMPAT6 already. Remove WITHOUT_SYSCALL_COMPAT build option, which only purpose was to (partially) disable the removed shims. Reviewed by: jhb, imp (previous versions) Discussed with: peter Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=281714
* Make wait6(2), waitid(3) and ppoll(2) cancellation points. TheKonstantin Belousov2015-04-181-0/+41
| | | | | | | | | | | | waitid() function is required to be cancellable by the standard. The wait6() and ppoll() follow the other syscalls in their groups. Reviewed by: jhb, jilles (previous versions) Sponsored by: The FreeBSD Foundation MFC after: 1 week Notes: svn path=/head/; revision=281712