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