diff options
author | 2003-12-23 19:31:05 +0000 | |
---|---|---|
committer | 2003-12-23 19:31:05 +0000 | |
commit | d5e6f81f8f8be5333e2b48e6ada6ad7302e5942b (patch) | |
tree | e4d719469d3c4f391618b10b35060e304927190b /lib/libpthread | |
parent | spacing (diff) | |
download | wireguard-openbsd-d5e6f81f8f8be5333e2b48e6ada6ad7302e5942b.tar.xz wireguard-openbsd-d5e6f81f8f8be5333e2b48e6ada6ad7302e5942b.zip |
Make accept(), connect(), recvfrom(), recvmsg(), sendmsg(),
and sendto() cancellation points, as required by POSIX.1-2001.
From: FreeBSD' libc_r
ok marc@
Diffstat (limited to 'lib/libpthread')
-rw-r--r-- | lib/libpthread/uthread/uthread_accept.c | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_cond.c | 10 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_connect.c | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_recvfrom.c | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_recvmsg.c | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_sendmsg.c | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_sendto.c | 9 |
7 files changed, 57 insertions, 7 deletions
diff --git a/lib/libpthread/uthread/uthread_accept.c b/lib/libpthread/uthread/uthread_accept.c index a3f424084fc..eb88a166753 100644 --- a/lib/libpthread/uthread/uthread_accept.c +++ b/lib/libpthread/uthread/uthread_accept.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_accept.c,v 1.7 2002/11/12 20:12:45 marc Exp $ */ +/* $OpenBSD: uthread_accept.c,v 1.8 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -47,6 +47,9 @@ accept(int fd, struct sockaddr * name, socklen_t *namelen) struct pthread *curthread = _get_curthread(); int ret; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + /* Lock the file descriptor: */ if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { /* Enter a loop to wait for a connection request: */ @@ -101,6 +104,10 @@ accept(int fd, struct sockaddr * name, socklen_t *namelen) /* Unlock the file descriptor: */ _FD_UNLOCK(fd, FD_RDWR); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + /* Return the socket file descriptor or -1 on error: */ return (ret); } diff --git a/lib/libpthread/uthread/uthread_cond.c b/lib/libpthread/uthread/uthread_cond.c index dc46e26127d..a8cc4923c36 100644 --- a/lib/libpthread/uthread/uthread_cond.c +++ b/lib/libpthread/uthread/uthread_cond.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_cond.c,v 1.13 2002/06/04 00:09:07 deraadt Exp $ */ +/* $OpenBSD: uthread_cond.c,v 1.14 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1995 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -166,9 +166,11 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) int interrupted = 0; int seqno; + /* This is a cancellation point: */ _thread_enter_cancellation_point(); if (cond == NULL) { + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); return (EINVAL); } @@ -179,6 +181,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) */ if (*cond == NULL && (rval = pthread_cond_init(cond, NULL)) != 0) { + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); return (rval); } @@ -314,6 +317,7 @@ pthread_cond_wait(pthread_cond_t * cond, pthread_mutex_t * mutex) curthread->continuation((void *) curthread); } while ((done == 0) && (rval == 0)); + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); /* Return the completion status: */ @@ -330,11 +334,13 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, int interrupted = 0; int seqno; + /* This is a cancellation point: */ _thread_enter_cancellation_point(); if (cond == NULL || abstime == NULL || abstime->tv_sec < 0 || abstime->tv_nsec < 0 || abstime->tv_nsec >= 1000000000) { + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); return (EINVAL); } @@ -343,6 +349,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, * initialization. */ if (*cond == NULL && (rval = pthread_cond_init(cond, NULL)) != 0) { + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); return (rval); } @@ -490,6 +497,7 @@ pthread_cond_timedwait(pthread_cond_t * cond, pthread_mutex_t * mutex, curthread->continuation((void *) curthread); } while ((done == 0) && (rval == 0)); + /* No longer in a cancellation point: */ _thread_leave_cancellation_point(); /* Return the completion status: */ diff --git a/lib/libpthread/uthread/uthread_connect.c b/lib/libpthread/uthread/uthread_connect.c index ad0a6ea8921..85e344f2975 100644 --- a/lib/libpthread/uthread/uthread_connect.c +++ b/lib/libpthread/uthread/uthread_connect.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_connect.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_connect.c,v 1.5 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -47,6 +47,9 @@ connect(int fd, const struct sockaddr * name, socklen_t namelen) struct sockaddr tmpname; int errnolen, ret, tmpnamelen; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if ((ret = _FD_LOCK(fd, FD_RDWR, NULL)) == 0) { if ((ret = _thread_sys_connect(fd, name, namelen)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && @@ -75,6 +78,10 @@ connect(int fd, const struct sockaddr * name, socklen_t namelen) } _FD_UNLOCK(fd, FD_RDWR); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + return (ret); } #endif diff --git a/lib/libpthread/uthread/uthread_recvfrom.c b/lib/libpthread/uthread/uthread_recvfrom.c index fee722f0b68..5817832a43c 100644 --- a/lib/libpthread/uthread/uthread_recvfrom.c +++ b/lib/libpthread/uthread/uthread_recvfrom.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_recvfrom.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_recvfrom.c,v 1.6 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,6 +46,9 @@ recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, sockl struct pthread *curthread = _get_curthread(); int ret; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { while ((ret = _thread_sys_recvfrom(fd, buf, len, flags, from, from_len)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { @@ -70,6 +73,10 @@ recvfrom(int fd, void *buf, size_t len, int flags, struct sockaddr * from, sockl } _FD_UNLOCK(fd, FD_READ); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + return (ret); } #endif diff --git a/lib/libpthread/uthread/uthread_recvmsg.c b/lib/libpthread/uthread/uthread_recvmsg.c index 73fa874b123..6c1f9668c5e 100644 --- a/lib/libpthread/uthread/uthread_recvmsg.c +++ b/lib/libpthread/uthread/uthread_recvmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_recvmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_recvmsg.c,v 1.5 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,6 +46,9 @@ recvmsg(int fd, struct msghdr *msg, int flags) struct pthread *curthread = _get_curthread(); int ret; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if ((ret = _FD_LOCK(fd, FD_READ, NULL)) == 0) { while ((ret = _thread_sys_recvmsg(fd, msg, flags)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { @@ -70,6 +73,10 @@ recvmsg(int fd, struct msghdr *msg, int flags) } _FD_UNLOCK(fd, FD_READ); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + return (ret); } #endif diff --git a/lib/libpthread/uthread/uthread_sendmsg.c b/lib/libpthread/uthread/uthread_sendmsg.c index 11d91d85c5c..5910e7b04cc 100644 --- a/lib/libpthread/uthread/uthread_sendmsg.c +++ b/lib/libpthread/uthread/uthread_sendmsg.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_sendmsg.c,v 1.4 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_sendmsg.c,v 1.5 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,6 +46,9 @@ sendmsg(int fd, const struct msghdr *msg, int flags) struct pthread *curthread = _get_curthread(); int ret; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { while ((ret = _thread_sys_sendmsg(fd, msg, flags)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { @@ -69,6 +72,10 @@ sendmsg(int fd, const struct msghdr *msg, int flags) } _FD_UNLOCK(fd, FD_WRITE); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + return (ret); } #endif diff --git a/lib/libpthread/uthread/uthread_sendto.c b/lib/libpthread/uthread/uthread_sendto.c index 062d11e77ac..c2ad04b0e2a 100644 --- a/lib/libpthread/uthread/uthread_sendto.c +++ b/lib/libpthread/uthread/uthread_sendto.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_sendto.c,v 1.5 2001/08/21 19:24:53 fgsch Exp $ */ +/* $OpenBSD: uthread_sendto.c,v 1.6 2003/12/23 19:31:05 brad Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -46,6 +46,9 @@ sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * t struct pthread *curthread = _get_curthread(); int ret; + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + if ((ret = _FD_LOCK(fd, FD_WRITE, NULL)) == 0) { while ((ret = _thread_sys_sendto(fd, msg, len, flags, to, to_len)) < 0) { if (!(_thread_fd_table[fd]->flags & O_NONBLOCK) && ((errno == EWOULDBLOCK) || (errno == EAGAIN))) { @@ -69,6 +72,10 @@ sendto(int fd, const void *msg, size_t len, int flags, const struct sockaddr * t } _FD_UNLOCK(fd, FD_WRITE); } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + return (ret); } #endif |