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