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