netbsd32_sem.c revision 1.5
1/*	$NetBSD: netbsd32_sem.c,v 1.5 2007/09/10 10:35:53 cube 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.5 2007/09/10 10:35:53 cube 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, void *v, register_t *retval)
68{
69	struct netbsd32__ksem_init_args /* {
70		syscallarg(unsigned int) value;
71		syscallarg(netbsd32_semidp_t) idp;
72	} */ *uap = v;
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, void *v, register_t *retval)
80{
81	struct netbsd32__ksem_open_args /* {
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	} */ *uap = v;
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, void *v, register_t *retval)
96{
97	struct netbsd32__ksem_unlink_args /* {
98		syscallarg(const netbsd32_charp) name;
99	} */ *uap = v;
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, void *v, register_t *retval)
108{
109	struct netbsd32__ksem_close_args /* {
110		syscallarg(netbsd32_semid_t) id;
111	} */ *uap = v;
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, void *v, register_t *retval)
120{
121	struct netbsd32__ksem_post_args /* {
122		syscallarg(netbsd32_semid_t) id;
123	} */ *uap = v;
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, void *v, register_t *retval)
132{
133	struct netbsd32__ksem_wait_args /* {
134		syscallarg(netbsd32_semid_t) id;
135	} */ *uap = v;
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, void *v, register_t *retval)
144{
145	struct netbsd32__ksem_trywait_args /* {
146		syscallarg(netbsd32_semid_t) id;
147	} */ *uap = v;
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, void *v, register_t *retval)
156{
157	struct netbsd32__ksem_destroy_args /* {
158		syscallarg(netbsd32_semid_t) id;
159	} */ *uap = v;
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, void *v, register_t *retval)
168{
169	struct netbsd32__ksem_getvalue_args /* {
170		syscallarg(netbsd32_semid_t) id;
171		syscallarg(netbsd32_intp) value;
172	} */ *uap = v;
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