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