netbsd32_sem.c revision 1.4
1/*	$NetBSD: netbsd32_sem.c,v 1.4 2007/03/18 21:38:34 dsl 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.4 2007/03/18 21:38:34 dsl 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	/* Returning a kernel pointer to userspace sucks badly :-( */
69	id32 = (netbsd32_semid_t)*idp;
70	return copyout(&id32, outidp, sizeof(id32));
71}
72
73int
74netbsd32__ksem_init(struct lwp *l, void *v, register_t *retval)
75{
76	struct netbsd32__ksem_init_args /* {
77		syscallarg(unsigned int) value;
78		syscallarg(netbsd32_semidp_t) idp;
79	} */ *uap = v;
80
81	return do_ksem_init(l, SCARG(uap, value),
82	    SCARG_P32(uap, idp), netbsd32_ksem_copyout);
83}
84
85int
86netbsd32__ksem_open(struct lwp *l, void *v, register_t *retval)
87{
88	struct netbsd32__ksem_open_args /* {
89		syscallarg(const netbsd32_charp) name;
90		syscallarg(int) oflag;
91		syscallarg(mode_t) mode;
92		syscallarg(unsigned int) value;
93		syscallarg(netbsd32_semidp_t) idp;
94	} */ *uap = v;
95
96	return do_ksem_open(l, SCARG_P32(uap, name),
97	    SCARG(uap, oflag), SCARG(uap, mode), SCARG(uap, value),
98	    SCARG_P32(uap, idp), netbsd32_ksem_copyout);
99}
100
101int
102netbsd32__ksem_unlink(struct lwp *l, void *v, register_t *retval)
103{
104	struct netbsd32__ksem_unlink_args /* {
105		syscallarg(const netbsd32_charp) name;
106	} */ *uap = v;
107	struct sys__ksem_unlink_args ua;
108
109	NETBSD32TOP_UAP(name, const char);
110	return sys__ksem_unlink(l, &ua, retval);
111}
112
113int
114netbsd32__ksem_close(struct lwp *l, void *v, register_t *retval)
115{
116	struct netbsd32__ksem_close_args /* {
117		syscallarg(netbsd32_semid_t) id;
118	} */ *uap = v;
119	struct sys__ksem_close_args ua;
120
121	NETBSD32TOX_UAP(id, semid_t);
122	return sys__ksem_close(l, &ua, retval);
123}
124
125int
126netbsd32__ksem_post(struct lwp *l, void *v, register_t *retval)
127{
128	struct netbsd32__ksem_post_args /* {
129		syscallarg(netbsd32_semid_t) id;
130	} */ *uap = v;
131	struct sys__ksem_post_args ua;
132
133	NETBSD32TOX_UAP(id, semid_t);
134	return sys__ksem_post(l, &ua, retval);
135}
136
137int
138netbsd32__ksem_wait(struct lwp *l, void *v, register_t *retval)
139{
140	struct netbsd32__ksem_wait_args /* {
141		syscallarg(netbsd32_semid_t) id;
142	} */ *uap = v;
143	struct sys__ksem_wait_args ua;
144
145	NETBSD32TOX_UAP(id, semid_t);
146	return sys__ksem_wait(l, &ua, retval);
147}
148
149int
150netbsd32__ksem_trywait(struct lwp *l, void *v, register_t *retval)
151{
152	struct netbsd32__ksem_trywait_args /* {
153		syscallarg(netbsd32_semid_t) id;
154	} */ *uap = v;
155	struct sys__ksem_trywait_args ua;
156
157	NETBSD32TOX_UAP(id, semid_t);
158	return sys__ksem_trywait(l, &ua, retval);
159}
160
161int
162netbsd32__ksem_destroy(struct lwp *l, void *v, register_t *retval)
163{
164	struct netbsd32__ksem_destroy_args /* {
165		syscallarg(netbsd32_semid_t) id;
166	} */ *uap = v;
167	struct sys__ksem_destroy_args ua;
168
169	NETBSD32TOX_UAP(id, semid_t);
170	return sys__ksem_destroy(l, &ua, retval);
171}
172
173int
174netbsd32__ksem_getvalue(struct lwp *l, void *v, register_t *retval)
175{
176	struct netbsd32__ksem_getvalue_args /* {
177		syscallarg(netbsd32_semid_t) id;
178		syscallarg(netbsd32_intp) value;
179	} */ *uap = v;
180	struct sys__ksem_getvalue_args ua;
181
182	NETBSD32TOX_UAP(id, semid_t);
183	NETBSD32TOP_UAP(value, unsigned int);
184	return sys__ksem_getvalue(l, &ua, retval);
185}
186