aboutsummaryrefslogtreecommitdiff
path: root/lib/libthr/thread/thr_sig.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libthr/thread/thr_sig.c')
-rw-r--r--lib/libthr/thread/thr_sig.c66
1 files changed, 36 insertions, 30 deletions
diff --git a/lib/libthr/thread/thr_sig.c b/lib/libthr/thread/thr_sig.c
index 20f62dad99c9..4bff5497a804 100644
--- a/lib/libthr/thread/thr_sig.c
+++ b/lib/libthr/thread/thr_sig.c
@@ -1,5 +1,5 @@
/*-
- * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
+ * SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2005, David Xu <davidxu@freebsd.org>
* All rights reserved.
@@ -26,9 +26,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/cdefs.h>
-__FBSDID("$FreeBSD$");
-
#include "namespace.h"
#include <sys/param.h>
#include <sys/auxv.h>
@@ -40,6 +37,7 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <pthread.h>
+#include <pthread_np.h>
#include "un-namespace.h"
#include "libc_private.h"
@@ -166,6 +164,24 @@ _thr_signal_block_setup(struct pthread *curthread)
__sys_sigfastblock(SIGFASTBLOCK_SETPTR, &curthread->fsigblock);
}
+void
+pthread_signals_block_np(void)
+{
+ struct pthread *curthread;
+
+ curthread = _get_curthread();
+ _thr_signal_block(curthread);
+}
+
+void
+pthread_signals_unblock_np(void)
+{
+ struct pthread *curthread;
+
+ curthread = _get_curthread();
+ _thr_signal_unblock(curthread);
+}
+
int
_thr_send_sig(struct pthread *thread, int sig)
{
@@ -188,8 +204,7 @@ thr_remove_thr_signals(const sigset_t *set, sigset_t *newset)
}
static void
-sigcancel_handler(int sig __unused,
- siginfo_t *info __unused, ucontext_t *ucp)
+sigcancel_handler(int sig __unused, siginfo_t *info __unused, ucontext_t *ucp)
{
struct pthread *curthread = _get_curthread();
int err;
@@ -250,7 +265,6 @@ static void
handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
{
struct pthread *curthread = _get_curthread();
- ucontext_t uc2;
__siginfohandler_t *sigfunc;
int cancel_point;
int cancel_async;
@@ -310,13 +324,11 @@ handle_signal(struct sigaction *actp, int sig, siginfo_t *info, ucontext_t *ucp)
curthread->cancel_point = cancel_point;
curthread->cancel_enable = cancel_enable;
- memcpy(&uc2, ucp, sizeof(uc2));
- SIGDELSET(uc2.uc_sigmask, SIGCANCEL);
+ SIGDELSET(ucp->uc_sigmask, SIGCANCEL);
/* reschedule cancellation */
- check_cancel(curthread, &uc2);
+ check_cancel(curthread, ucp);
errno = err;
- syscall(SYS_sigreturn, &uc2);
}
void
@@ -360,9 +372,11 @@ check_cancel(struct pthread *curthread, ucontext_t *ucp)
* on getting a signal before it agrees to return.
*/
if (curthread->cancel_point) {
- if (curthread->in_sigsuspend && ucp) {
- SIGADDSET(ucp->uc_sigmask, SIGCANCEL);
- curthread->unblock_sigcancel = 1;
+ if (curthread->in_sigsuspend) {
+ if (ucp != NULL) {
+ SIGADDSET(ucp->uc_sigmask, SIGCANCEL);
+ curthread->unblock_sigcancel = 1;
+ }
_thr_send_sig(curthread, SIGCANCEL);
} else
thr_wake(curthread->tid);
@@ -371,8 +385,8 @@ check_cancel(struct pthread *curthread, ucontext_t *ucp)
* asynchronous cancellation mode, act upon
* immediately.
*/
- _pthread_exit_mask(PTHREAD_CANCELED,
- ucp? &ucp->uc_sigmask : NULL);
+ _pthread_exit_mask(PTHREAD_CANCELED, ucp != NULL ?
+ &ucp->uc_sigmask : NULL);
}
}
@@ -403,6 +417,7 @@ check_deferred_signal(struct pthread *curthread)
/* remove signal */
curthread->deferred_siginfo.si_signo = 0;
handle_signal(&act, info.si_signo, &info, uc);
+ syscall(SYS_sigreturn, uc);
}
static void
@@ -410,9 +425,8 @@ check_suspend(struct pthread *curthread)
{
uint32_t cycle;
- if (__predict_true((curthread->flags &
- (THR_FLAGS_NEED_SUSPEND | THR_FLAGS_SUSPENDED))
- != THR_FLAGS_NEED_SUSPEND))
+ if (__predict_true((curthread->flags & (THR_FLAGS_NEED_SUSPEND |
+ THR_FLAGS_SUSPENDED)) != THR_FLAGS_NEED_SUSPEND))
return;
if (curthread == _single_thread)
return;
@@ -669,15 +683,7 @@ _thr_sigmask(int how, const sigset_t *set, sigset_t *oset)
}
int
-_sigsuspend(const sigset_t * set)
-{
- sigset_t newset;
-
- return (__sys_sigsuspend(thr_remove_thr_signals(set, &newset)));
-}
-
-int
-__thr_sigsuspend(const sigset_t * set)
+__thr_sigsuspend(const sigset_t *set)
{
struct pthread *curthread;
sigset_t newset;
@@ -703,7 +709,7 @@ __thr_sigsuspend(const sigset_t * set)
int
_sigtimedwait(const sigset_t *set, siginfo_t *info,
- const struct timespec * timeout)
+ const struct timespec *timeout)
{
sigset_t newset;
@@ -718,7 +724,7 @@ _sigtimedwait(const sigset_t *set, siginfo_t *info,
*/
int
__thr_sigtimedwait(const sigset_t *set, siginfo_t *info,
- const struct timespec * timeout)
+ const struct timespec *timeout)
{
struct pthread *curthread = _get_curthread();
sigset_t newset;