summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorfgsch <fgsch@openbsd.org>2011-09-13 23:56:00 +0000
committerfgsch <fgsch@openbsd.org>2011-09-13 23:56:00 +0000
commit65d75b8a6cd00042e7ebd92f510cafae1b641d3b (patch)
tree91b75b078d049539c3adc7ef400843989ba3166d
parentfirst round of tests to check system calls restarting with pthreads. (diff)
downloadwireguard-openbsd-65d75b8a6cd00042e7ebd92f510cafae1b641d3b.tar.xz
wireguard-openbsd-65d75b8a6cd00042e7ebd92f510cafae1b641d3b.zip
For threads in PS_FDR_WAIT state, check SA_RESTART before marking it as
interrupted, thus simulating the system call restart behaviour in the non-pthreads case. Add a state for kevent since it shouldn't be restarted regardless of SA_RESTART being present. guenther@ ok.
-rw-r--r--lib/libpthread/uthread/pthread_private.h3
-rw-r--r--lib/libpthread/uthread/uthread_cancel.c3
-rw-r--r--lib/libpthread/uthread/uthread_info_openbsd.c4
-rw-r--r--lib/libpthread/uthread/uthread_kern.c5
-rw-r--r--lib/libpthread/uthread/uthread_kevent.c4
-rw-r--r--lib/libpthread/uthread/uthread_sig.c11
-rw-r--r--lib/libpthread/uthread/uthread_suspend_np.c3
7 files changed, 24 insertions, 9 deletions
diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h
index 7e79622073f..106a03317f1 100644
--- a/lib/libpthread/uthread/pthread_private.h
+++ b/lib/libpthread/uthread/pthread_private.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: pthread_private.h,v 1.76 2010/10/28 15:02:41 millert Exp $ */
+/* $OpenBSD: pthread_private.h,v 1.77 2011/09/13 23:56:00 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -486,6 +486,7 @@ enum pthread_state {
PS_SUSPENDED,
PS_DEAD,
PS_DEADLOCK,
+ PS_KEVENT_WAIT,
PS_STATE_MAX
};
diff --git a/lib/libpthread/uthread/uthread_cancel.c b/lib/libpthread/uthread/uthread_cancel.c
index 859cc2bf8e7..b2079e24a55 100644
--- a/lib/libpthread/uthread/uthread_cancel.c
+++ b/lib/libpthread/uthread/uthread_cancel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_cancel.c,v 1.16 2007/04/27 19:44:48 kurt Exp $ */
+/* $OpenBSD: uthread_cancel.c,v 1.17 2011/09/13 23:56:00 fgsch Exp $ */
/*
* David Leonard <d@openbsd.org>, 1999. Public domain.
*/
@@ -41,6 +41,7 @@ pthread_cancel(pthread_t pthread)
case PS_SPINBLOCK:
case PS_FDR_WAIT:
case PS_FDW_WAIT:
+ case PS_KEVENT_WAIT:
case PS_POLL_WAIT:
case PS_SELECT_WAIT:
/* Remove these threads from the work queue: */
diff --git a/lib/libpthread/uthread/uthread_info_openbsd.c b/lib/libpthread/uthread/uthread_info_openbsd.c
index b33378f5707..bbaa4ba5168 100644
--- a/lib/libpthread/uthread/uthread_info_openbsd.c
+++ b/lib/libpthread/uthread/uthread_info_openbsd.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_info_openbsd.c,v 1.15 2007/05/21 16:50:36 kurt Exp $ */
+/* $OpenBSD: uthread_info_openbsd.c,v 1.16 2011/09/13 23:56:00 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
@@ -62,6 +62,7 @@ static const struct s_thread_info thread_info[] = {
{PS_FDR_WAIT , "fdr_wait"},
{PS_FDW_WAIT , "fdw_wait"},
{PS_FILE_WAIT , "file_wait"},
+ {PS_KEVENT_WAIT , "kevent_wait"},
{PS_POLL_WAIT , "poll_wait"},
{PS_SELECT_WAIT , "select_wait"},
{PS_SLEEP_WAIT , "sleep_wait"},
@@ -177,6 +178,7 @@ _thread_dump_entry(pthread_t pthread, int fd, int verbose)
case PS_FDLW_WAIT:
case PS_FDR_WAIT:
case PS_FDW_WAIT:
+ case PS_KEVENT_WAIT:
/* Write the lock details: */
snprintf(s, sizeof(s), "%s fd %d [%s:%d]\n",
info_lead,
diff --git a/lib/libpthread/uthread/uthread_kern.c b/lib/libpthread/uthread/uthread_kern.c
index 80b873ee633..a7ea95e295d 100644
--- a/lib/libpthread/uthread/uthread_kern.c
+++ b/lib/libpthread/uthread/uthread_kern.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kern.c,v 1.39 2011/09/05 21:24:24 guenther Exp $ */
+/* $OpenBSD: uthread_kern.c,v 1.40 2011/09/13 23:56:00 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -227,6 +227,7 @@ _thread_kern_sched(struct sigcontext * scp)
/* FALLTHROUGH */
case PS_FDR_WAIT:
case PS_FDW_WAIT:
+ case PS_KEVENT_WAIT:
case PS_POLL_WAIT:
case PS_SELECT_WAIT:
/* Restart the time slice: */
@@ -714,6 +715,7 @@ _thread_kern_poll(int wait_reqd)
/* File descriptor read wait: */
case PS_FDR_WAIT:
+ case PS_KEVENT_WAIT:
/* if fd is closing then reschedule this thread */
if (_thread_fd_table[pthread->data.fd.fd]->state == FD_ENTRY_CLOSING) {
pthread->closing_fd = 1;
@@ -844,6 +846,7 @@ _thread_kern_poll(int wait_reqd)
/* File descriptor read wait: */
case PS_FDR_WAIT:
+ case PS_KEVENT_WAIT:
if ((nfds < _thread_max_pfdtsize) &&
(_thread_pfd_table[nfds].revents
& (POLLRDNORM|POLLERR|POLLHUP|POLLNVAL))
diff --git a/lib/libpthread/uthread/uthread_kevent.c b/lib/libpthread/uthread/uthread_kevent.c
index e810900418a..7530e5e4184 100644
--- a/lib/libpthread/uthread/uthread_kevent.c
+++ b/lib/libpthread/uthread/uthread_kevent.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_kevent.c,v 1.5 2006/10/03 02:59:36 kurt Exp $ */
+/* $OpenBSD: uthread_kevent.c,v 1.6 2011/09/13 23:56:00 fgsch Exp $ */
/*-
* Copyright (c) 2000 Jonathan Lemon <jlemon@flugsvamp.com>
@@ -63,7 +63,7 @@ kevent(int kq, const struct kevent *changelist, int nchanges,
curthread->closing_fd = 0;
curthread->timeout = 0;
- _thread_kern_sched_state(PS_FDR_WAIT,
+ _thread_kern_sched_state(PS_KEVENT_WAIT,
__FILE__, __LINE__);
if (curthread->interrupted) {
diff --git a/lib/libpthread/uthread/uthread_sig.c b/lib/libpthread/uthread/uthread_sig.c
index 16754dcfa16..2a1a791fcc7 100644
--- a/lib/libpthread/uthread/uthread_sig.c
+++ b/lib/libpthread/uthread/uthread_sig.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_sig.c,v 1.26 2010/07/13 03:10:29 guenther Exp $ */
+/* $OpenBSD: uthread_sig.c,v 1.27 2011/09/13 23:56:00 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
* All rights reserved.
@@ -272,6 +272,8 @@ _thread_sig_handle(int sig, struct sigcontext * scp)
void
_thread_signal(pthread_t pthread, int sig)
{
+ int interrupted = 1;
+
/* Flag the signal as pending. It may be dispatched later. */
sigaddset(&pthread->sigpend,sig);
@@ -326,14 +328,19 @@ _thread_signal(pthread_t pthread, int sig)
* other than the scheduling alarm:
*/
case PS_FDR_WAIT:
+ if (_thread_sigact[sig - 1].sa_flags & SA_RESTART)
+ interrupted = 0;
+ /* FALLTHROUGH */
+
case PS_FDW_WAIT:
+ case PS_KEVENT_WAIT:
case PS_POLL_WAIT:
case PS_SLEEP_WAIT:
case PS_SELECT_WAIT:
if (sig != SIGCHLD ||
_thread_sigact[sig - 1].sa_handler != SIG_DFL) {
/* Flag the operation as interrupted: */
- pthread->interrupted = 1;
+ pthread->interrupted = interrupted;
if (pthread->flags & PTHREAD_FLAGS_IN_WORKQ)
PTHREAD_WORKQ_REMOVE(pthread);
diff --git a/lib/libpthread/uthread/uthread_suspend_np.c b/lib/libpthread/uthread/uthread_suspend_np.c
index 8f3fa261232..500cdd12420 100644
--- a/lib/libpthread/uthread/uthread_suspend_np.c
+++ b/lib/libpthread/uthread/uthread_suspend_np.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: uthread_suspend_np.c,v 1.10 2007/04/27 19:40:08 kurt Exp $ */
+/* $OpenBSD: uthread_suspend_np.c,v 1.11 2011/09/13 23:56:00 fgsch Exp $ */
/*
* Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>.
* All rights reserved.
@@ -108,6 +108,7 @@ suspend_common(struct pthread *thread)
case PS_FDR_WAIT:
case PS_FDW_WAIT:
+ case PS_KEVENT_WAIT:
/*
* Remove these threads from the work queue
* and set the state to suspended: