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