Home | History | Annotate | Line # | Download | only in netbsd32
netbsd32_sem.c revision 1.8
      1  1.8    ad /*	$NetBSD: netbsd32_sem.c,v 1.8 2008/11/14 15:49:20 ad Exp $	*/
      2  1.1  cube 
      3  1.1  cube /*
      4  1.1  cube  *  Copyright (c) 2006 The NetBSD Foundation.
      5  1.1  cube  *  All rights reserved.
      6  1.1  cube  *
      7  1.1  cube  *  Redistribution and use in source and binary forms, with or without
      8  1.1  cube  *  modification, are permitted provided that the following conditions
      9  1.1  cube  *  are met:
     10  1.1  cube  *  1. Redistributions of source code must retain the above copyright
     11  1.1  cube  *     notice, this list of conditions and the following disclaimer.
     12  1.1  cube  *  2. Redistributions in binary form must reproduce the above copyright
     13  1.1  cube  *     notice, this list of conditions and the following disclaimer in the
     14  1.1  cube  *     documentation and/or other materials provided with the distribution.
     15  1.1  cube  *
     16  1.1  cube  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  1.1  cube  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  1.1  cube  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  1.1  cube  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  1.1  cube  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  1.1  cube  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  1.1  cube  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  1.1  cube  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  1.1  cube  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  1.1  cube  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  1.1  cube  *  POSSIBILITY OF SUCH DAMAGE.
     27  1.1  cube  */
     28  1.1  cube 
     29  1.1  cube #include <sys/cdefs.h>
     30  1.8    ad __KERNEL_RCSID(0, "$NetBSD: netbsd32_sem.c,v 1.8 2008/11/14 15:49:20 ad Exp $");
     31  1.1  cube 
     32  1.1  cube #ifdef _KERNEL_OPT
     33  1.1  cube #include "opt_posix.h"
     34  1.1  cube #endif
     35  1.1  cube 
     36  1.1  cube #include <sys/types.h>
     37  1.1  cube #include <sys/param.h>
     38  1.1  cube #include <sys/systm.h>
     39  1.1  cube #include <sys/kernel.h>
     40  1.1  cube #include <sys/dirent.h>
     41  1.1  cube #include <sys/ksem.h>
     42  1.1  cube #include <sys/mount.h>
     43  1.1  cube #include <sys/proc.h>
     44  1.1  cube #include <sys/syscallargs.h>
     45  1.1  cube 
     46  1.1  cube #include <compat/netbsd32/netbsd32.h>
     47  1.1  cube #include <compat/netbsd32/netbsd32_syscallargs.h>
     48  1.1  cube #include <compat/netbsd32/netbsd32_conv.h>
     49  1.1  cube 
     50  1.1  cube static int
     51  1.1  cube netbsd32_ksem_copyout(const void *src, void *dst, size_t size)
     52  1.1  cube {
     53  1.8    ad 	const intptr_t *idp = src;
     54  1.8    ad 	netbsd32_intptr_t id32, *outidp = dst;
     55  1.1  cube 
     56  1.8    ad 	KASSERT(size == sizeof(intptr_t));
     57  1.1  cube 
     58  1.3   dsl 	/* Returning a kernel pointer to userspace sucks badly :-( */
     59  1.8    ad 	id32 = (netbsd32_intptr_t)*idp;
     60  1.1  cube 	return copyout(&id32, outidp, sizeof(id32));
     61  1.1  cube }
     62  1.1  cube 
     63  1.1  cube int
     64  1.6   dsl netbsd32__ksem_init(struct lwp *l, const struct netbsd32__ksem_init_args *uap, register_t *retval)
     65  1.1  cube {
     66  1.6   dsl 	/* {
     67  1.1  cube 		syscallarg(unsigned int) value;
     68  1.1  cube 		syscallarg(netbsd32_semidp_t) idp;
     69  1.6   dsl 	} */
     70  1.1  cube 
     71  1.1  cube 	return do_ksem_init(l, SCARG(uap, value),
     72  1.4   dsl 	    SCARG_P32(uap, idp), netbsd32_ksem_copyout);
     73  1.1  cube }
     74  1.1  cube 
     75  1.1  cube int
     76  1.6   dsl netbsd32__ksem_open(struct lwp *l, const struct netbsd32__ksem_open_args *uap, register_t *retval)
     77  1.1  cube {
     78  1.6   dsl 	/* {
     79  1.1  cube 		syscallarg(const netbsd32_charp) name;
     80  1.1  cube 		syscallarg(int) oflag;
     81  1.1  cube 		syscallarg(mode_t) mode;
     82  1.1  cube 		syscallarg(unsigned int) value;
     83  1.1  cube 		syscallarg(netbsd32_semidp_t) idp;
     84  1.6   dsl 	} */
     85  1.1  cube 
     86  1.4   dsl 	return do_ksem_open(l, SCARG_P32(uap, name),
     87  1.1  cube 	    SCARG(uap, oflag), SCARG(uap, mode), SCARG(uap, value),
     88  1.4   dsl 	    SCARG_P32(uap, idp), netbsd32_ksem_copyout);
     89  1.1  cube }
     90  1.1  cube 
     91  1.1  cube int
     92  1.6   dsl netbsd32__ksem_unlink(struct lwp *l, const struct netbsd32__ksem_unlink_args *uap, register_t *retval)
     93  1.1  cube {
     94  1.6   dsl 	/* {
     95  1.1  cube 		syscallarg(const netbsd32_charp) name;
     96  1.6   dsl 	} */
     97  1.1  cube 	struct sys__ksem_unlink_args ua;
     98  1.1  cube 
     99  1.1  cube 	NETBSD32TOP_UAP(name, const char);
    100  1.1  cube 	return sys__ksem_unlink(l, &ua, retval);
    101  1.1  cube }
    102  1.1  cube 
    103  1.1  cube int
    104  1.6   dsl netbsd32__ksem_close(struct lwp *l, const struct netbsd32__ksem_close_args *uap, register_t *retval)
    105  1.1  cube {
    106  1.6   dsl 	/* {
    107  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    108  1.6   dsl 	} */
    109  1.1  cube 	struct sys__ksem_close_args ua;
    110  1.1  cube 
    111  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    112  1.1  cube 	return sys__ksem_close(l, &ua, retval);
    113  1.1  cube }
    114  1.1  cube 
    115  1.1  cube int
    116  1.6   dsl netbsd32__ksem_post(struct lwp *l, const struct netbsd32__ksem_post_args *uap, register_t *retval)
    117  1.1  cube {
    118  1.6   dsl 	/* {
    119  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    120  1.6   dsl 	} */
    121  1.1  cube 	struct sys__ksem_post_args ua;
    122  1.1  cube 
    123  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    124  1.1  cube 	return sys__ksem_post(l, &ua, retval);
    125  1.1  cube }
    126  1.1  cube 
    127  1.1  cube int
    128  1.6   dsl netbsd32__ksem_wait(struct lwp *l, const struct netbsd32__ksem_wait_args *uap, register_t *retval)
    129  1.1  cube {
    130  1.6   dsl 	/* {
    131  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    132  1.6   dsl 	} */
    133  1.1  cube 	struct sys__ksem_wait_args ua;
    134  1.1  cube 
    135  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    136  1.1  cube 	return sys__ksem_wait(l, &ua, retval);
    137  1.1  cube }
    138  1.1  cube 
    139  1.1  cube int
    140  1.6   dsl netbsd32__ksem_trywait(struct lwp *l, const struct netbsd32__ksem_trywait_args *uap, register_t *retval)
    141  1.1  cube {
    142  1.6   dsl 	/* {
    143  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    144  1.6   dsl 	} */
    145  1.1  cube 	struct sys__ksem_trywait_args ua;
    146  1.1  cube 
    147  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    148  1.1  cube 	return sys__ksem_trywait(l, &ua, retval);
    149  1.1  cube }
    150  1.1  cube 
    151  1.1  cube int
    152  1.6   dsl netbsd32__ksem_destroy(struct lwp *l, const struct netbsd32__ksem_destroy_args *uap, register_t *retval)
    153  1.1  cube {
    154  1.6   dsl 	/* {
    155  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    156  1.6   dsl 	} */
    157  1.1  cube 	struct sys__ksem_destroy_args ua;
    158  1.1  cube 
    159  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    160  1.1  cube 	return sys__ksem_destroy(l, &ua, retval);
    161  1.1  cube }
    162  1.1  cube 
    163  1.1  cube int
    164  1.6   dsl netbsd32__ksem_getvalue(struct lwp *l, const struct netbsd32__ksem_getvalue_args *uap, register_t *retval)
    165  1.1  cube {
    166  1.6   dsl 	/* {
    167  1.8    ad 		syscallarg(netbsd32_intptr_t) id;
    168  1.1  cube 		syscallarg(netbsd32_intp) value;
    169  1.6   dsl 	} */
    170  1.1  cube 	struct sys__ksem_getvalue_args ua;
    171  1.1  cube 
    172  1.8    ad 	NETBSD32TOX_UAP(id, intptr_t);
    173  1.1  cube 	NETBSD32TOP_UAP(value, unsigned int);
    174  1.1  cube 	return sys__ksem_getvalue(l, &ua, retval);
    175  1.1  cube }
    176