1 /* $NetBSD: netbsd32_select.c,v 1.15 2008/05/29 14:51:26 mrg 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.15 2008/05/29 14:51:26 mrg Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/malloc.h> 35 #include <sys/mount.h> 36 #include <sys/time.h> 37 #include <sys/vnode.h> 38 #include <sys/file.h> 39 #include <sys/filedesc.h> 40 #include <sys/poll.h> 41 #include <sys/select.h> 42 #include <sys/dirent.h> 43 44 #include <sys/proc.h> 45 46 #include <net/if.h> 47 48 #include <compat/netbsd32/netbsd32.h> 49 #include <compat/netbsd32/netbsd32_syscall.h> 50 #include <compat/netbsd32/netbsd32_syscallargs.h> 51 #include <compat/netbsd32/netbsd32_conv.h> 52 53 int 54 netbsd32_select(struct lwp *l, const struct netbsd32_select_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 timeval atv, *tv = 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 netbsd32_to_timeval(&tv32, &atv); 72 tv = &atv; 73 } 74 75 return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in), 76 SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, NULL); 77 } 78 79 int 80 netbsd32_pselect(struct lwp *l, const struct netbsd32_pselect_args *uap, register_t *retval) 81 { 82 /* { 83 syscallarg(int) nd; 84 syscallarg(netbsd32_fd_setp_t) in; 85 syscallarg(netbsd32_fd_setp_t) ou; 86 syscallarg(netbsd32_fd_setp_t) ex; 87 syscallarg(const netbsd32_timespecp_t) ts; 88 syscallarg(const netbsd32_sigsetp_t) mask; 89 } */ 90 int error; 91 struct netbsd32_timespec ts32; 92 struct timespec ts; 93 struct timeval atv, *tv = NULL; 94 sigset_t amask, *mask = NULL; 95 96 if (SCARG_P32(uap, ts)) { 97 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32)); 98 if (error != 0) 99 return error; 100 netbsd32_to_timespec(&ts32, &ts); 101 atv.tv_sec = ts.tv_sec; 102 atv.tv_usec = ts.tv_nsec / 1000; 103 tv = &atv; 104 } 105 if (SCARG_P32(uap, mask)) { 106 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask)); 107 if (error != 0) 108 return error; 109 mask = &amask; 110 } 111 112 return selcommon(l, retval, SCARG(uap, nd), SCARG_P32(uap, in), 113 SCARG_P32(uap, ou), SCARG_P32(uap, ex), tv, mask); 114 } 115 116 int 117 netbsd32_pollts(struct lwp *l, const struct netbsd32_pollts_args *uap, register_t *retval) 118 { 119 /* { 120 syscallarg(struct netbsd32_pollfdp_t) fds; 121 syscallarg(u_int) nfds; 122 syscallarg(const netbsd32_timespecp_t) ts; 123 syscallarg(const netbsd32_sigsetp_t) mask; 124 } */ 125 int error; 126 struct netbsd32_timespec ts32; 127 struct timespec ts; 128 struct timeval atv, *tv = NULL; 129 sigset_t amask, *mask = NULL; 130 131 if (SCARG_P32(uap, ts)) { 132 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof(ts32)); 133 if (error != 0) 134 return error; 135 netbsd32_to_timespec(&ts32, &ts); 136 atv.tv_sec = ts.tv_sec; 137 atv.tv_usec = ts.tv_nsec / 1000; 138 tv = &atv; 139 } 140 if (NETBSD32PTR64( SCARG(uap, mask))) { 141 error = copyin(SCARG_P32(uap, mask), &amask, sizeof(amask)); 142 if (error != 0) 143 return error; 144 mask = &amask; 145 } 146 147 return pollcommon(l, retval, SCARG_P32(uap, fds), 148 SCARG(uap, nfds), tv, mask); 149 } 150