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