diff options
author | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-01-17 02:52:40 +0000 |
---|---|---|
committer | Philip Guenthe <guenther@cvs.openbsd.org> | 2012-01-17 02:52:40 +0000 |
commit | 9e94c2e5c369147584d18cdcf4bd233b1ed1d740 (patch) | |
tree | b1483337570fc6beec1a272403cd1338e5a257b0 /lib | |
parent | d067ea68812d54b3dd88ad4cd7cd71553a590003 (diff) |
Make openat(), pread(), preadv(), pwrite(), and pwritev() cancellation
points.
ok fgsch@
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libpthread/shlib_version | 2 | ||||
-rw-r--r-- | lib/libpthread/uthread/Makefile.inc | 9 | ||||
-rw-r--r-- | lib/libpthread/uthread/pthread_private.h | 11 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_init.c | 5 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_openat.c | 81 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_pread.c | 60 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_preadv.c | 61 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_pwrite.c | 61 | ||||
-rw-r--r-- | lib/libpthread/uthread/uthread_pwritev.c | 63 |
9 files changed, 346 insertions, 7 deletions
diff --git a/lib/libpthread/shlib_version b/lib/libpthread/shlib_version index b91c32ce7c8..b2253c1458b 100644 --- a/lib/libpthread/shlib_version +++ b/lib/libpthread/shlib_version @@ -1,2 +1,2 @@ major=13 -minor=1 +minor=2 diff --git a/lib/libpthread/uthread/Makefile.inc b/lib/libpthread/uthread/Makefile.inc index 7b457350353..573a5c64417 100644 --- a/lib/libpthread/uthread/Makefile.inc +++ b/lib/libpthread/uthread/Makefile.inc @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile.inc,v 1.23 2010/11/07 13:29:21 fgsch Exp $ +# $OpenBSD: Makefile.inc,v 1.24 2012/01/17 02:52:39 guenther Exp $ # $FreeBSD: Makefile.inc,v 1.19 1999/08/28 00:03:19 peter Exp $ # uthread sources @@ -76,8 +76,8 @@ SRCS+= \ uthread_join.c \ uthread_kern.c \ uthread_kevent.c \ - uthread_kqueue.c \ uthread_kill.c \ + uthread_kqueue.c \ uthread_listen.c \ uthread_lseek.c \ uthread_main_np.c \ @@ -92,9 +92,14 @@ SRCS+= \ uthread_nanosleep.c \ uthread_once.c \ uthread_open.c \ + uthread_openat.c \ uthread_pipe.c \ uthread_poll.c \ + uthread_pread.c \ + uthread_preadv.c \ uthread_priority_queue.c \ + uthread_pwrite.c \ + uthread_pwritev.c \ uthread_read.c \ uthread_readv.c \ uthread_recvfrom.c \ diff --git a/lib/libpthread/uthread/pthread_private.h b/lib/libpthread/uthread/pthread_private.h index 78b5754f5a1..457de4247e0 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.78 2011/10/07 08:59:42 fgsch Exp $ */ +/* $OpenBSD: pthread_private.h,v 1.79 2012/01/17 02:52:39 guenther Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>. * All rights reserved. @@ -1323,6 +1323,8 @@ int _thread_sys_ftruncate(int, off_t); long _thread_sys_fpathconf(int, int); pid_t _thread_sys_getpid(void); int _thread_sys_pipe(int *); +ssize_t _thread_sys_pread(int, void *, size_t, off_t); +ssize_t _thread_sys_pwrite(int, const void *, size_t, off_t); int _thread_sys_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); off_t _thread_sys_lseek(int, off_t, int); pid_t _thread_sys_fork(void); @@ -1339,6 +1341,7 @@ int _thread_sys_creat(const char *, mode_t); int _thread_sys_fcntl(int, int, ...); int _thread_sys_flock(int, int); int _thread_sys_open(const char *, int, ...); +int _thread_sys_openat(int, const char *, int, ...); #endif /* #include <sys/ioctl.h> */ @@ -1363,8 +1366,10 @@ void _thread_sys_seekdir(DIR *, long); /* #include <sys/uio.h> */ #ifdef _SYS_UIO_H_ -ssize_t _thread_sys_readv(int, const struct iovec *, int); -ssize_t _thread_sys_writev(int, const struct iovec *, int); +ssize_t _thread_sys_preadv(int, const struct iovec *, int, off_t); +ssize_t _thread_sys_pwritev(int, const struct iovec *, int, off_t); +ssize_t _thread_sys_readv(int, const struct iovec *, int); +ssize_t _thread_sys_writev(int, const struct iovec *, int); #endif /* #include <sys/wait.h> */ diff --git a/lib/libpthread/uthread/uthread_init.c b/lib/libpthread/uthread/uthread_init.c index 05078d5fb3f..436cd73fcb1 100644 --- a/lib/libpthread/uthread/uthread_init.c +++ b/lib/libpthread/uthread/uthread_init.c @@ -1,4 +1,4 @@ -/* $OpenBSD: uthread_init.c,v 1.46 2011/09/28 18:52:47 fgsch Exp $ */ +/* $OpenBSD: uthread_init.c,v 1.47 2012/01/17 02:52:39 guenther Exp $ */ /* * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> * All rights reserved. @@ -39,6 +39,7 @@ #include <sys/types.h> #include <sys/param.h> +#include <sys/event.h> #include <sys/ioctl.h> #include <sys/mman.h> #include <sys/mount.h> @@ -109,6 +110,8 @@ static void *references[] __used = { &open, &pipe, &poll, + &pread, + &pwrite, &read, &readv, &recvfrom, diff --git a/lib/libpthread/uthread/uthread_openat.c b/lib/libpthread/uthread/uthread_openat.c new file mode 100644 index 00000000000..8b68c7d0026 --- /dev/null +++ b/lib/libpthread/uthread/uthread_openat.c @@ -0,0 +1,81 @@ +/* $OpenBSD: uthread_openat.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ +/* + * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: uthread_open.c,v 1.6 1999/08/28 00:03:42 peter Exp $ + * + */ +#include <stdarg.h> +#include <unistd.h> +#include <fcntl.h> +#include <dirent.h> +#include <errno.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +int +openat(int atfd, const char *path, int flags,...) +{ + int fd; + int mode = 0; + va_list ap; + + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + + /* Check if the file is being created: */ + if (flags & O_CREAT) { + /* Get the creation mode: */ + va_start(ap, flags); + mode = va_arg(ap, int); + va_end(ap); + } + + /* Open the file: */ + if ((fd = _thread_sys_openat(atfd, path, flags, mode)) < 0) { + } + /* Initialise the file descriptor table entry: */ + else if (_thread_fd_table_init(fd, FD_INIT_NEW, NULL) != 0) { + /* Quietly close the file: */ + _thread_sys_close(fd); + + /* Reset the file descriptor: */ + fd = -1; + } + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + + /* Return the file descriptor or -1 on error: */ + return (fd); +} +#endif diff --git a/lib/libpthread/uthread/uthread_pread.c b/lib/libpthread/uthread/uthread_pread.c new file mode 100644 index 00000000000..5fd305b6e33 --- /dev/null +++ b/lib/libpthread/uthread/uthread_pread.c @@ -0,0 +1,60 @@ +/* $OpenBSD: uthread_pread.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ +/* + * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: uthread_read.c,v 1.8 1999/08/28 00:03:43 peter Exp $ + * + */ +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/uio.h> +#include <errno.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +ssize_t +pread(int fd, void *buf, size_t nbytes, off_t offset) +{ + ssize_t ret; + + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + + ret = _thread_sys_pread(fd, buf, nbytes, offset); + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + + return (ret); +} +#endif diff --git a/lib/libpthread/uthread/uthread_preadv.c b/lib/libpthread/uthread/uthread_preadv.c new file mode 100644 index 00000000000..934e1d84a77 --- /dev/null +++ b/lib/libpthread/uthread/uthread_preadv.c @@ -0,0 +1,61 @@ +/* $OpenBSD: uthread_preadv.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ +/* + * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: uthread_readv.c,v 1.8 1999/08/28 00:03:43 peter Exp $ + * + */ +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/uio.h> +#include <errno.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +ssize_t +preadv(int fd, const struct iovec * iov, int iovcnt, off_t offset) +{ + ssize_t ret; + int type; + + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + + ret = _thread_sys_preadv(fd, iov, iovcnt, offset); + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + + return (ret); +} +#endif diff --git a/lib/libpthread/uthread/uthread_pwrite.c b/lib/libpthread/uthread/uthread_pwrite.c new file mode 100644 index 00000000000..6e780ea4800 --- /dev/null +++ b/lib/libpthread/uthread/uthread_pwrite.c @@ -0,0 +1,61 @@ +/* $OpenBSD: uthread_pwrite.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ +/* + * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: uthread_write.c,v 1.12 1999/08/28 00:03:54 peter Exp $ + * + */ +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/uio.h> +#include <errno.h> +#include <stddef.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +ssize_t +pwrite(int fd, const void *buf, size_t nbytes, off_t offset) +{ + ssize_t ret; + + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + + ret = _thread_sys_pwrite(fd, buf, nbytes, offset); + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + + return (ret); +} +#endif diff --git a/lib/libpthread/uthread/uthread_pwritev.c b/lib/libpthread/uthread/uthread_pwritev.c new file mode 100644 index 00000000000..090eeb8928d --- /dev/null +++ b/lib/libpthread/uthread/uthread_pwritev.c @@ -0,0 +1,63 @@ +/* $OpenBSD: uthread_pwritev.c,v 1.1 2012/01/17 02:52:39 guenther Exp $ */ +/* + * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by John Birrell. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY JOHN BIRRELL AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: uthread_writev.c,v 1.12 1999/08/28 00:03:55 peter Exp $ + * + */ +#include <sys/types.h> +#include <sys/fcntl.h> +#include <sys/uio.h> +#include <errno.h> +#include <stddef.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> +#ifdef _THREAD_SAFE +#include <pthread.h> +#include "pthread_private.h" + +ssize_t +pwritev(int fd, const struct iovec * iov, int iovcnt, off_t offset) +{ + ssize_t ret; + + /* This is a cancellation point: */ + _thread_enter_cancellation_point(); + + ret = _thread_sys_pwritev(fd, iov, iovcnt, offset); + + /* No longer in a cancellation point: */ + _thread_leave_cancellation_point(); + + return (ret); +} +#endif |