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