1 /* $NetBSD: netbsd32_select.c,v 1.20 2019/09/20 15:16:41 kamil Exp $ */ 2 3 /* 4 * Copyright (c) 1998, 2001 Matthew R. Green 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED 23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: netbsd32_select.c,v 1.20 2019/09/20 15:16:41 kamil Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/mount.h> 35 #include <sys/time.h> 36 #include <sys/vnode.h> 37 #include <sys/file.h> 38 #include <sys/filedesc.h> 39 #include <sys/poll.h> 40 #include <sys/select.h> 41 #include <sys/dirent.h> 42 43 #include <sys/proc.h> 44 45 #include <net/if.h> 46 47 #include <compat/netbsd32/netbsd32.h> 48 #include <compat/netbsd32/netbsd32_syscall.h> 49 #include <compat/netbsd32/netbsd32_syscallargs.h> 50 #include <compat/netbsd32/netbsd32_conv.h> 51 52 int 53 netbsd32___select50(struct lwp *l, 54 const struct netbsd32___select50_args *uap, register_t *retval) 55 { 56 /* { 57 syscallarg(int) nd; 58 syscallarg(netbsd32_fd_setp_t) in; 59 syscallarg(netbsd32_fd_setp_t) ou; 60 syscallarg(netbsd32_fd_setp_t) ex; 61 syscallarg(netbsd32_timevalp_t) tv; 62 } */ 63 int error; 64 struct netbsd32_timeval tv32; 65 struct timespec ats, *ts = NULL; 66 67 if (SCARG_P32(uap, tv)) { 68 error = copyin(SCARG_P32(uap, tv), &tv32, sizeof(tv32)); 69 if (error != 0) 70 return error; 71 72 if (tv32.tv_usec < 0 || tv32.tv_usec >= 1000000) 73 return EINVAL; 74 75 ats.tv_sec = tv32.tv_sec; 76 ats.tv_nsec = tv32.tv_usec * 1000; 77 ts = &ats; 78 } 79 80 return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in), 81 SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, NULL); 82 } 83 84 int 85 netbsd32___pselect50(struct lwp *l, 86 const struct netbsd32___pselect50_args *uap, register_t *retval) 87 { 88 /* { 89 syscallarg(int) nd; 90 syscallarg(netbsd32_fd_setp_t) in; 91 syscallarg(netbsd32_fd_setp_t) ou; 92 syscallarg(netbsd32_fd_setp_t) ex; 93 syscallarg(const netbsd32_timespecp_t) ts; 94 syscallarg(const netbsd32_sigsetp_t) mask; 95 } */ 96 int error; 97 struct netbsd32_timespec ts32; 98 struct timespec ats, *ts = NULL; 99 sigset_t amask, *mask = NULL; 100 101 if (SCARG_P32(uap, ts)) { 102 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32)); 103 if (error != 0) 104 return error; 105 netbsd32_to_timespec(&ts32, &ats); 106 ts = &ats; 107 } 108 if (SCARG_P32(uap, mask)) { 109 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask)); 110 if (error != 0) 111 return error; 112 mask = &amask; 113 } 114 115 return selcommon(retval, SCARG(uap, nd), SCARG_P32(uap, in), 116 SCARG_P32(uap, ou), SCARG_P32(uap, ex), ts, mask); 117 } 118 119 int 120 netbsd32___pollts50(struct lwp *l, const struct netbsd32___pollts50_args *uap, 121 register_t *retval) 122 { 123 /* { 124 syscallarg(struct netbsd32_pollfdp_t) fds; 125 syscallarg(u_int) nfds; 126 syscallarg(const netbsd32_timespecp_t) ts; 127 syscallarg(const netbsd32_sigsetp_t) mask; 128 } */ 129 int error; 130 struct netbsd32_timespec ts32; 131 struct timespec ats, *ts = NULL; 132 sigset_t amask, *mask = NULL; 133 134 if (SCARG_P32(uap, ts)) { 135 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32)); 136 if (error != 0) 137 return error; 138 netbsd32_to_timespec(&ts32, &ats); 139 ts = &ats; 140 } 141 if (NETBSD32PTR64( SCARG(uap, mask))) { 142 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask)); 143 if (error != 0) 144 return error; 145 mask = &amask; 146 } 147 148 return pollcommon(retval, SCARG_P32(uap, fds), 149 SCARG(uap, nfds), ts, mask); 150 } 151