summaryrefslogtreecommitdiffstats
path: root/lib/libthr/thread
Commit message (Collapse)AuthorAgeFilesLines
* If off-page lookup failed, there is no memory to performkib2016-04-121-1/+2
| | | | | | shared_mutex_init() upon. Sponsored by: The FreeBSD Foundation
* Use __FBSDID() for .c files from lib/libthr/thread.kib2016-04-0852-112/+158
| | | | Sponsored by: The FreeBSD Foundation
* Use ANSI C function definitions, fix spelling in a comment.kib2016-04-083-4/+5
| | | | Sponsored by: The FreeBSD Foundation
* Assert that the lock objects put into the off-page, fit into the page.kib2016-04-085-0/+15
| | | | Sponsored by: The FreeBSD Foundation
* Remove unused variable. It was write-only before r297139.kib2016-04-042-2/+0
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Apparently there are some popular programs around which assume that itkib2016-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
* Lock pshared_lock shared around fork, to ensure that the COW snapshotkib2016-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
* Provide more information on failing checks in mutex_assert_is_owned()kib2016-03-211-4/+16
| | | | | | | and mutex_assert_not_owned(). snprintf() use in this context should be safe. Sponsored by: The FreeBSD Foundation
* From libthr, remove special and strange code to set up session andkib2016-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
* Implement process-shared spinlocks.kib2016-03-211-48/+59
| | | | Sponsored by: The FreeBSD Foundation
* Add two comments explaining the fine points of the hashkib2016-03-011-0/+31
| | | | | | | | implementation. Reviewed by: emaste Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D5490
* Implement process-shared locks support for libthr.so.3, withoutkib2016-02-2813-307/+788
| | | | | | | | | | | | 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
* If libthr.so is dlopened without RTLD_GLOBAL flag, the libthr symbolskib2016-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
* libthr: const-ify two variablesvangyzen2016-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.
* Typo.kib2015-12-271-1/+1
|
* libthr: Don't use both __sys_open() and __sys_openat().jilles2015-12-202-2/+1
|
* Style. Use ANSI definition, wrap long lines, no initialization inkib2015-09-081-8/+15
| | | | | | | declaration for locals. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* In the pthread_once(), if the initializer has already run, then thekib2015-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
* Pre-resolve symbols required for the deferred signal processing. Thiskib2015-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
* cosmetic: whitespaces-tab before EOLpfg2015-07-081-1/+1
| | | | Obtained from: cpi-llvm project
* Fix typo in comment.kib2015-06-141-2/+2
| | | | MFC after: 3 days
* Some third-party malloc(3) implementations use pthread_setspecific(3)kib2015-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
* _pthread_cleanup_push: fix allocator sizeof operand mismatchpfg2015-04-221-1/+1
| | | | | | | Same fix appears to be in DragonFly's libthread_xu. Found by: Clang Static Analyzer MFC after: 1 week
* The lseek(2), mmap(2), truncate(2), ftruncate(2), pread(2), andkib2015-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
* Make wait6(2), waitid(3) and ppoll(2) cancellation points. Thekib2015-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
* Make kevent(2) a cancellation point.kib2015-03-291-0/+24
| | | | | | | | | | | | | | | | | | | | | Note that to cancel blocked kevent(2) call, changelist must be empty, since we cannot cancel a call which already made changes to the process state. And in reverse, call which only makes changes to the kqueue state, without waiting for an event, is not cancellable. This makes a natural usage model to migrate kqueue loop to support cancellation, where existing single kevent(2) call must be split into two: first uncancellable update of kqueue, then cancellable wait for events. Note that this is ABI-incompatible change, but it is believed that there is no cancel-safe code that relies on kevent(2) not being a cancellation point. Option to preserve the ABI would be to keep kevent(2) as is, but add new call with flags to specify cancellation behaviour, which only value seems to add complications. Suggested and reviewed by: jilles Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* Fix a typo in comment and explain the reason.jkim2015-03-091-1/+1
|
* Propagate errors from _thr_umutex_unlock2 through mutex_unlock_common.kib2015-02-251-3/+4
| | | | | | | | | | | | Errors from _thr_umutex_unlock2 should "never happen" in normal circumstances. If they do, however, return them to the application so it can fail early and loudly. Hiding the errors will only delay the inevitable failure, making it harder to find and diagnose. Submitted by: Eric van Gyzen <eric_van_gyzen@dell.com> Obtained from: Dell Inc. PR: 198914 MFC after: 1 week
* Properly interpose libc spinlocks, was missed in r276630. Inkib2015-02-143-8/+8
| | | | | | | | particular, stdio locking was affected. Reported and tested by: "Matthew D. Fuller" <fullermd@over-yonder.net> Sponsored by: The FreeBSD Foundation MFC after: 3 days
* Fully initialize allocated memory for the new barrier. Thekib2015-02-061-4/+1
| | | | | | | | | | b_destroying member was left uninitialized, which caused spurious EBUSY. PR: 197365 Noted by: Florent Guiliani <fguiliani@verisign.com> Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Merge all the copies of _tcb_ctor and _tcb_dtor.andrew2015-01-213-0/+60
| | | | | | | | | | | | | | | | | | | | | | | | | The amd64, i386, and sparc64 versions were identical, with the one difference where the former two used inline asm instead of _tcb_get. I have compared the function before and after replacing the asm with _tcb_get and found the object files to be identical. The arm, mips, and powerpc versions were almost identical. The only difference was the powerpc version used an alignment of 1 where arm and mips used 16. As this is an increase in alignment is will be safe. Along with this arm, mips, and powerpc all passed, when initial was true, the value returned from _tcb_get as the first argument to _rtld_allocate_tls. This would then return this pointer back to the caller. We can remove these extra calls by checking if initial is set and setting the thread control block directly. As this is what the sparc64 code does we can use it directly. As after these observations all the architectures can now have identical code we can merge them into a common file. Differential Revision: https://reviews.freebsd.org/D1556 Reviewed by: kib Sponsored by: The FreeBSD Foundation
* Fix bug in r276630. Do not allow pthread_sigmask() to block SIGCANCEL.kib2015-01-211-1/+2
| | | | | | Reported and tested by: royger Sponsored by: The FreeBSD Foundation MFC after: 3 days
* Reduce the size of the interposing table and amount ofkib2015-01-113-160/+0
| | | | | | | | | | | | | | | | | cancellation-handling code in the libthr. Translate some syscalls into their more generic counterpart, and remove translated syscalls from the table. List of the affected syscalls: creat, open -> openat raise -> thr_kill sleep, usleep -> nanosleep pause -> sigsuspend wait, wait3, waitpid -> wait4 Suggested and reviewed by: jilles (previous version) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Avoid calling internal libc function through PLT or accessing datakib2015-01-052-2/+2
| | | | | | | | | though GOT, by staticizing and hiding. Add setter for __error_selector to hide it as well. Suggested and reviewed by: jilles Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Fix known issues which blow up the process after dlopen("libthr.so")kib2015-01-037-351/+358
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | (or loading a dso linked to libthr.so into process which was not linked against threading library). - Remove libthr interposers of the libc functions, including __error(). Instead, functions calls are indirected through the interposing table, similar to how pthread stubs in libc are already done. Libc by default points either to syscall trampolines or to existing libc implementations. On libthr load, libthr rewrites the pointers to the cancellable implementations already in libthr. The interposition table is separate from pthreads stubs indirection table to not pull pthreads stubs into static binaries. - Postpone the malloc(3) internal mutexes initialization until libthr is loaded. This avoids recursion between calloc(3) and static pthread_mutex_t initialization. - Reinstall signal handlers with wrapper on libthr load. The _rtld_is_dlopened(3) is used to avoid useless calls to sigaction(2) when libthr is statically referenced from the main binary. In the process, fix openat(2), swapcontext(2) and setcontext(2) interposing. The libc symbols were exported at different versions than libthr interposers. Export both libc and libthr versions from libc now, with default set to the higher version from libthr. Remove unused and disconnected swapcontext(3) userspace implementation from libc/gen. No objections from: deischen Tested by: pho, antoine (exp-run) (previous versions) Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Revert r274772: it is not valid on MIPSemaste2014-11-252-6/+6
| | | | Reported by: sbruno
* Use canonical __PIC__ flagemaste2014-11-212-6/+6
| | | | | | | | It is automatically set when -fPIC is passed to the compiler. Reviewed by: dim, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D1179
* Switch the defaults to not split the RLIMIT_STACK-sized initial threadkib2014-09-241-3/+4
| | | | | | | | stack into the stacks of the created threads. Add knob LIBPTHREAD_SPLITSTACK_MAIN to restore the older behaviour. Sponsored by: The FreeBSD Foundation MFC after: 3 weeks
* Fix typo in a comment.rpaulo2014-09-021-1/+1
|
* Add a knob LIBPTHREAD_BIGSTACK_MAIN, which instructs libthr to leavekib2014-08-132-1/+12
| | | | | | | | | | | | | | | | | the whole RLIMIT_STACK-sized region of the kernel-allocated stack as the stack of main thread. By default, the main thread stack is clamped at 2MB (4MB on 64bit ABIs) and the rest is used for other threads stack allocation. Since there is no programmatic way to adjust the size of the main thread stack, pthread_attr_setstacksize() is too late, the knob allows user to manage the main stack size both for single-threaded and multi-threaded processes with the rlimit. Reported by: "Ivan A. Kosarev" <ivan@ivan-labs.com> Tested by: dim Sponsored by: The FreeBSD Foundation MFC after: 3 days
* Style.kib2014-08-131-1/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 3 days
* Right now, the rtld prefork hook locks the rtld bind lock in the readkib2014-05-242-4/+30
| | | | | | | | | | | | | | | | | | mode. This allows the binder to be functional in the child after the fork (assuming no lazy loading of a filter is needed), but other rtld services which require write lock on rtld_bind_lock cause deadlock, if called by child. Change the _rtld_atfork() to lock the bind lock in write mode, making the rtld fully functional after the fork. Pre-resolve the symbols which are called by the libthr' fork() interposer, since dynamic resolution causes deadlock due to the rtld_bind_lock already owned in the write mode. Reported and tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* In _pthread_kill(), if passed pthread is current thread, do not sendkib2014-02-011-5/+8
| | | | | | | | | | | the signal second time, by adding the missed else before if statement. While there, postpone initializing local curthread variable until passed signal number is checked for validity. Submitted by: John Wolfe <jlw@xinuos.com> PR: threads/186309 MFC after: 1 week
* If check_deferred_signal() execution needs binding of PLT symbol,kib2013-11-232-2/+10
| | | | | | | | | | | | | | | | | | | | | | | unlocking the rtld bind lock results in the processing of ast and recursing into the check_deferred_signal(). Nested execution of check_deferred_signal() delivers the signal to user code and clears si_signo. On return, top-level check_deferred_signal() frame continues delivering the same signal one more time, but now with zero si_signo. Fix this by adding a flag to indicate that deferred delivery is running, so check_deferred_signal() should avoid doing anything. Since user signal handler is allowed to modify the passed machine context to make return from the signal handler to cause arbitrary jump, or do longjmp(). For this case, also clear the flag in thr_sighandler(), since kernel signal delivery means that nested delivery code should not run right now. Reported by: Vitaly Magerya <vmagerya@gmail.com> Reviewed by: davidxu, jilles Tested by: pho Sponsored by: The FreeBSD Foundation MFC after: 1 week
* The SUSv4tc1 requires that pthread_setcancelstate() shall be not akib2013-06-191-1/+2
| | | | | | | | | cancellation point. When enabling the cancellation, only process the pending cancellation for asynchronous mode. Reported and reviewed by: Kohji Okuno <okuno.kohji@jp.panasonic.com> Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Since the cause of the problems with the __fillcontextx() waskib2013-06-031-15/+7
| | | | | | | | | identified, unify the code of check_deferred_signal() for all architectures, making the variant under #ifdef x86 common. Tested by: marius (sparc64) Sponsored by: The FreeBSD Foundation MFC after: 2 weeks
* The getcontext() from the __fillcontextx() call in thekib2013-05-281-2/+7
| | | | | | | | | | | | | | | | | | | | | | | | | check_deferred_signal() returns twice, since handle_signal() emulates the return from the normal signal handler by sigreturn(2)ing the passed context. Second return is performed on the destroyed stack frame, because __fillcontextx() has already returned. This causes undefined and bad behaviour, usually the victim thread gets SIGSEGV. Avoid nested frame and the need to return from it by doing direct call to getcontext() in the check_deferred_signal() and using a new private libc helper __fillcontextx2() to complement the context with the extended CPU state if the deferred signal is still present. The __fillcontextx() is now unused, but is kept to allow older libthr.so to be used with the new libc. Mark __fillcontextx() as returning twice [1]. Reported by: pgj Pointy hat to: kib Discussed with: dim Tested by: pgj, dim Suggested by: jilles [1] MFC after: 1 week
* Partially apply the capitalization of the heading word of the sequencekib2013-05-271-3/+3
| | | | | | | and fix typo. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* Return one-based key so that user can check if the key is ever allocateddavidxu2013-05-161-4/+7
| | | | | | in the first place. Initial patch submitted by: phk
* Fix return value for setcontext and swapcontext.davidxu2013-05-091-4/+8
|
OpenPOWER on IntegriCloud