netbsd32_lwp.c revision 1.13 1 /* $NetBSD: netbsd32_lwp.c,v 1.13 2012/05/21 14:15:19 martin Exp $ */
2
3 /*
4 * Copyright (c) 2005, 2006, 2007 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_lwp.c,v 1.13 2012/05/21 14:15:19 martin Exp $");
31
32 #include <sys/types.h>
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/kernel.h>
36 #include <sys/dirent.h>
37 #include <sys/mount.h>
38 #include <sys/proc.h>
39 #include <sys/syscallargs.h>
40 #include <sys/lwpctl.h>
41
42 #include <compat/netbsd32/netbsd32.h>
43 #include <compat/netbsd32/netbsd32_syscallargs.h>
44 #include <compat/netbsd32/netbsd32_conv.h>
45
46 /* Sycalls conversion */
47
48 int
49 netbsd32__lwp_create(struct lwp *l, const struct netbsd32__lwp_create_args *uap, register_t *retval)
50 {
51 /* {
52 syscallarg(const netbsd32_ucontextp) ucp;
53 syscallarg(netbsd32_u_long) flags;
54 syscallarg(netbsd32_lwpidp) new_lwp;
55 } */
56 struct proc *p = l->l_proc;
57 ucontext32_t *newuc = NULL;
58 lwpid_t lid;
59 int error;
60
61 KASSERT(p->p_emul->e_ucsize == sizeof(*newuc));
62
63 newuc = kmem_alloc(sizeof(ucontext32_t), KM_SLEEP);
64 error = copyin(SCARG_P32(uap, ucp), newuc, p->p_emul->e_ucsize);
65 if (error)
66 goto fail;
67
68 /* validate the ucontext */
69 if ((newuc->uc_flags & _UC_CPU) == 0) {
70 error = EINVAL;
71 goto fail;
72 }
73 error = cpu_mcontext32_validate(l, &newuc->uc_mcontext);
74 if (error)
75 goto fail;
76
77 error = do_lwp_create(l, newuc, SCARG(uap, flags), &lid);
78 if (error)
79 goto fail;
80
81 /*
82 * do not free ucontext in case of an error here,
83 * the lwp will actually run and access it
84 */
85 return copyout(&lid, SCARG_P32(uap, new_lwp), sizeof(lid));
86
87 fail:
88 kmem_free(newuc, sizeof(*newuc));
89 return error;
90 }
91
92 int
93 netbsd32__lwp_wait(struct lwp *l, const struct netbsd32__lwp_wait_args *uap, register_t *retval)
94 {
95 /* {
96 syscallarg(lwpid_t) wait_for;
97 syscallarg(netbsd32_lwpidp) departed;
98 } */
99 struct sys__lwp_wait_args ua;
100
101 NETBSD32TO64_UAP(wait_for);
102 NETBSD32TOP_UAP(departed, lwpid_t);
103 return sys__lwp_wait(l, &ua, retval);
104 }
105
106 int
107 netbsd32__lwp_suspend(struct lwp *l, const struct netbsd32__lwp_suspend_args *uap, register_t *retval)
108 {
109 /* {
110 syscallarg(lwpid_t) target;
111 } */
112 struct sys__lwp_suspend_args ua;
113
114 NETBSD32TO64_UAP(target);
115 return sys__lwp_suspend(l, &ua, retval);
116 }
117
118 int
119 netbsd32__lwp_continue(struct lwp *l, const struct netbsd32__lwp_continue_args *uap, register_t *retval)
120 {
121 /* {
122 syscallarg(lwpid_t) target;
123 } */
124 struct sys__lwp_continue_args ua;
125
126 NETBSD32TO64_UAP(target);
127 return sys__lwp_continue(l, &ua, retval);
128 }
129
130 int
131 netbsd32__lwp_wakeup(struct lwp *l, const struct netbsd32__lwp_wakeup_args *uap, register_t *retval)
132 {
133 /* {
134 syscallarg(lwpid_t) target;
135 } */
136 struct sys__lwp_wakeup_args ua;
137
138 NETBSD32TO64_UAP(target);
139 return sys__lwp_wakeup(l, &ua, retval);
140 }
141
142 int
143 netbsd32__lwp_setprivate(struct lwp *l, const struct netbsd32__lwp_setprivate_args *uap, register_t *retval)
144 {
145 /* {
146 syscallarg(netbsd32_voidp) ptr;
147 } */
148 struct sys__lwp_setprivate_args ua;
149
150 NETBSD32TOP_UAP(ptr, void);
151 return sys__lwp_setprivate(l, &ua, retval);
152 }
153
154 int
155 netbsd32____lwp_park50(struct lwp *l,
156 const struct netbsd32____lwp_park50_args *uap, register_t *retval)
157 {
158 /* {
159 syscallarg(const netbsd32_timespec50p) ts;
160 syscallarg(lwpid_t) unpark;
161 syscallarg(netbsd32_voidp) hint;
162 syscallarg(netbsd32_voidp) unparkhint;
163 } */
164 struct timespec ts, *tsp;
165 struct netbsd32_timespec ts32;
166 int error;
167
168 if (SCARG_P32(uap, ts) == NULL)
169 tsp = NULL;
170 else {
171 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
172 if (error != 0)
173 return error;
174 netbsd32_to_timespec(&ts32, &ts);
175 tsp = &ts;
176 }
177
178 if (SCARG(uap, unpark) != 0) {
179 error = lwp_unpark(SCARG(uap, unpark),
180 SCARG_P32(uap, unparkhint));
181 if (error != 0)
182 return error;
183 }
184
185 return lwp_park(tsp, SCARG_P32(uap, hint));
186 }
187
188 int
189 netbsd32__lwp_kill(struct lwp *l, const struct netbsd32__lwp_kill_args *uap, register_t *retval)
190 {
191 /* {
192 syscallarg(lwpid_t) target;
193 syscallarg(int) signo;
194 } */
195 struct sys__lwp_kill_args ua;
196
197 NETBSD32TO64_UAP(target);
198 NETBSD32TO64_UAP(signo);
199 return sys__lwp_kill(l, &ua, retval);
200 }
201 int
202 netbsd32__lwp_detach(struct lwp *l, const struct netbsd32__lwp_detach_args *uap, register_t *retval)
203 {
204 /* {
205 syscallarg(lwpid_t) target;
206 } */
207 struct sys__lwp_detach_args ua;
208
209 NETBSD32TO64_UAP(target);
210 return sys__lwp_detach(l, &ua, retval);
211 }
212
213 int
214 netbsd32__lwp_unpark(struct lwp *l, const struct netbsd32__lwp_unpark_args *uap, register_t *retval)
215 {
216 /* {
217 syscallarg(lwpid_t) target;
218 syscallarg(netbsd32_voidp) hint;
219 } */
220 struct sys__lwp_unpark_args ua;
221
222 NETBSD32TO64_UAP(target);
223 NETBSD32TOP_UAP(hint, void);
224 return sys__lwp_unpark(l, &ua, retval);
225 }
226
227 int
228 netbsd32__lwp_unpark_all(struct lwp *l, const struct netbsd32__lwp_unpark_all_args *uap, register_t *retval)
229 {
230 /* {
231 syscallarg(const netbsd32_lwpidp) targets;
232 syscallarg(netbsd32_size_t) ntargets;
233 syscallarg(netbsd32_voidp) hint;
234 } */
235 struct sys__lwp_unpark_all_args ua;
236
237 NETBSD32TOP_UAP(targets, const lwpid_t);
238 NETBSD32TOX_UAP(ntargets, size_t);
239 NETBSD32TOP_UAP(hint, void);
240 return sys__lwp_unpark_all(l, &ua, retval);
241 }
242
243 int
244 netbsd32__lwp_setname(struct lwp *l, const struct netbsd32__lwp_setname_args *uap, register_t *retval)
245 {
246 /* {
247 syscallarg(lwpid_t) target;
248 syscallarg(const netbsd32_charp) name;
249 } */
250 struct sys__lwp_setname_args ua;
251
252 NETBSD32TO64_UAP(target);
253 NETBSD32TOP_UAP(name, char *);
254 return sys__lwp_setname(l, &ua, retval);
255 }
256
257 int
258 netbsd32__lwp_getname(struct lwp *l, const struct netbsd32__lwp_getname_args *uap, register_t *retval)
259 {
260 /* {
261 syscallarg(lwpid_t) target;
262 syscallarg(netbsd32_charp) name;
263 syscallarg(netbsd32_size_t) len;
264 } */
265 struct sys__lwp_getname_args ua;
266
267 NETBSD32TO64_UAP(target);
268 NETBSD32TOP_UAP(name, char *);
269 NETBSD32TOX_UAP(len, size_t);
270 return sys__lwp_getname(l, &ua, retval);
271 }
272
273 int
274 netbsd32__lwp_ctl(struct lwp *l, const struct netbsd32__lwp_ctl_args *uap, register_t *retval)
275 {
276 /* {
277 syscallarg(int) features;
278 syscallarg(netbsd32_pointer_t) address;
279 } */
280 struct sys__lwp_ctl_args ua;
281
282 NETBSD32TO64_UAP(features);
283 NETBSD32TOP_UAP(address, struct lwpctl *);
284 return sys__lwp_ctl(l, &ua, retval);
285 }
286