netbsd32_sem.c revision 1.7.2.1 1 /* $NetBSD: netbsd32_sem.c,v 1.7.2.1 2008/05/10 23:48:58 wrstuden 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.2.1 2008/05/10 23:48:58 wrstuden 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/sa.h>
45 #include <sys/syscallargs.h>
46
47 #include <compat/netbsd32/netbsd32.h>
48 #include <compat/netbsd32/netbsd32_syscallargs.h>
49 #include <compat/netbsd32/netbsd32_conv.h>
50
51 static int
52 netbsd32_ksem_copyout(const void *src, void *dst, size_t size)
53 {
54 const semid_t *idp = src;
55 netbsd32_semid_t id32, *outidp = dst;
56
57 KASSERT(size == sizeof(semid_t));
58
59 /* Returning a kernel pointer to userspace sucks badly :-( */
60 id32 = (netbsd32_semid_t)*idp;
61 return copyout(&id32, outidp, sizeof(id32));
62 }
63
64 int
65 netbsd32__ksem_init(struct lwp *l, const struct netbsd32__ksem_init_args *uap, register_t *retval)
66 {
67 /* {
68 syscallarg(unsigned int) value;
69 syscallarg(netbsd32_semidp_t) idp;
70 } */
71
72 return do_ksem_init(l, SCARG(uap, value),
73 SCARG_P32(uap, idp), netbsd32_ksem_copyout);
74 }
75
76 int
77 netbsd32__ksem_open(struct lwp *l, const struct netbsd32__ksem_open_args *uap, register_t *retval)
78 {
79 /* {
80 syscallarg(const netbsd32_charp) name;
81 syscallarg(int) oflag;
82 syscallarg(mode_t) mode;
83 syscallarg(unsigned int) value;
84 syscallarg(netbsd32_semidp_t) idp;
85 } */
86
87 return do_ksem_open(l, SCARG_P32(uap, name),
88 SCARG(uap, oflag), SCARG(uap, mode), SCARG(uap, value),
89 SCARG_P32(uap, idp), netbsd32_ksem_copyout);
90 }
91
92 int
93 netbsd32__ksem_unlink(struct lwp *l, const struct netbsd32__ksem_unlink_args *uap, register_t *retval)
94 {
95 /* {
96 syscallarg(const netbsd32_charp) name;
97 } */
98 struct sys__ksem_unlink_args ua;
99
100 NETBSD32TOP_UAP(name, const char);
101 return sys__ksem_unlink(l, &ua, retval);
102 }
103
104 int
105 netbsd32__ksem_close(struct lwp *l, const struct netbsd32__ksem_close_args *uap, register_t *retval)
106 {
107 /* {
108 syscallarg(netbsd32_semid_t) id;
109 } */
110 struct sys__ksem_close_args ua;
111
112 NETBSD32TOX_UAP(id, semid_t);
113 return sys__ksem_close(l, &ua, retval);
114 }
115
116 int
117 netbsd32__ksem_post(struct lwp *l, const struct netbsd32__ksem_post_args *uap, register_t *retval)
118 {
119 /* {
120 syscallarg(netbsd32_semid_t) id;
121 } */
122 struct sys__ksem_post_args ua;
123
124 NETBSD32TOX_UAP(id, semid_t);
125 return sys__ksem_post(l, &ua, retval);
126 }
127
128 int
129 netbsd32__ksem_wait(struct lwp *l, const struct netbsd32__ksem_wait_args *uap, register_t *retval)
130 {
131 /* {
132 syscallarg(netbsd32_semid_t) id;
133 } */
134 struct sys__ksem_wait_args ua;
135
136 NETBSD32TOX_UAP(id, semid_t);
137 return sys__ksem_wait(l, &ua, retval);
138 }
139
140 int
141 netbsd32__ksem_trywait(struct lwp *l, const struct netbsd32__ksem_trywait_args *uap, register_t *retval)
142 {
143 /* {
144 syscallarg(netbsd32_semid_t) id;
145 } */
146 struct sys__ksem_trywait_args ua;
147
148 NETBSD32TOX_UAP(id, semid_t);
149 return sys__ksem_trywait(l, &ua, retval);
150 }
151
152 int
153 netbsd32__ksem_destroy(struct lwp *l, const struct netbsd32__ksem_destroy_args *uap, register_t *retval)
154 {
155 /* {
156 syscallarg(netbsd32_semid_t) id;
157 } */
158 struct sys__ksem_destroy_args ua;
159
160 NETBSD32TOX_UAP(id, semid_t);
161 return sys__ksem_destroy(l, &ua, retval);
162 }
163
164 int
165 netbsd32__ksem_getvalue(struct lwp *l, const struct netbsd32__ksem_getvalue_args *uap, register_t *retval)
166 {
167 /* {
168 syscallarg(netbsd32_semid_t) id;
169 syscallarg(netbsd32_intp) value;
170 } */
171 struct sys__ksem_getvalue_args ua;
172
173 NETBSD32TOX_UAP(id, semid_t);
174 NETBSD32TOP_UAP(value, unsigned int);
175 return sys__ksem_getvalue(l, &ua, retval);
176 }
177