1 | /* $NetBSD: netbsd32_lwp.c,v 1.18 2015/05/15 07:56:25 matt 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.18 2015/05/15 07:56:25 matt 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(ucontext_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(ucontext_t)); |
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_park60(struct lwp *l, |
156 | const struct netbsd32____lwp_park60_args *uap, register_t *retval) |
157 | { |
158 | /* { |
159 | syscallarg(const netbsd32_clockid_t) clock_id; |
160 | syscallarg(int) flags; |
161 | syscallarg(const netbsd32_timespec50p) ts; |
162 | syscallarg(netbsd32_lwpid_t) unpark; |
163 | syscallarg(netbsd32_voidp) hint; |
164 | syscallarg(netbsd32_voidp) unparkhint; |
165 | } */ |
166 | struct timespec ts, *tsp; |
167 | struct netbsd32_timespec ts32; |
168 | int error; |
169 | |
170 | if (SCARG_P32(uap, ts) == NULL) |
171 | tsp = NULL; |
172 | else { |
173 | error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32); |
174 | if (error != 0) |
175 | return error; |
176 | netbsd32_to_timespec(&ts32, &ts); |
177 | tsp = &ts; |
178 | } |
179 | |
180 | if (SCARG(uap, unpark) != 0) { |
181 | error = lwp_unpark(SCARG(uap, unpark), |
182 | SCARG_P32(uap, unparkhint)); |
183 | if (error != 0) |
184 | return error; |
185 | } |
186 | |
187 | return lwp_park(SCARG(uap, clock_id), SCARG(uap, flags), tsp, |
188 | SCARG_P32(uap, hint)); |
189 | } |
190 | |
191 | int |
192 | netbsd32__lwp_kill(struct lwp *l, const struct netbsd32__lwp_kill_args *uap, register_t *retval) |
193 | { |
194 | /* { |
195 | syscallarg(lwpid_t) target; |
196 | syscallarg(int) signo; |
197 | } */ |
198 | struct sys__lwp_kill_args ua; |
199 | |
200 | NETBSD32TO64_UAP(target); |
201 | NETBSD32TO64_UAP(signo); |
202 | return sys__lwp_kill(l, &ua, retval); |
203 | } |
204 | int |
205 | netbsd32__lwp_detach(struct lwp *l, const struct netbsd32__lwp_detach_args *uap, register_t *retval) |
206 | { |
207 | /* { |
208 | syscallarg(lwpid_t) target; |
209 | } */ |
210 | struct sys__lwp_detach_args ua; |
211 | |
212 | NETBSD32TO64_UAP(target); |
213 | return sys__lwp_detach(l, &ua, retval); |
214 | } |
215 | |
216 | int |
217 | netbsd32__lwp_unpark(struct lwp *l, const struct netbsd32__lwp_unpark_args *uap, register_t *retval) |
218 | { |
219 | /* { |
220 | syscallarg(lwpid_t) target; |
221 | syscallarg(netbsd32_voidp) hint; |
222 | } */ |
223 | struct sys__lwp_unpark_args ua; |
224 | |
225 | NETBSD32TO64_UAP(target); |
226 | NETBSD32TOP_UAP(hint, void); |
227 | return sys__lwp_unpark(l, &ua, retval); |
228 | } |
229 | |
230 | int |
231 | netbsd32__lwp_unpark_all(struct lwp *l, const struct netbsd32__lwp_unpark_all_args *uap, register_t *retval) |
232 | { |
233 | /* { |
234 | syscallarg(const netbsd32_lwpidp) targets; |
235 | syscallarg(netbsd32_size_t) ntargets; |
236 | syscallarg(netbsd32_voidp) hint; |
237 | } */ |
238 | struct sys__lwp_unpark_all_args ua; |
239 | |
240 | NETBSD32TOP_UAP(targets, const lwpid_t); |
241 | NETBSD32TOX_UAP(ntargets, size_t); |
242 | NETBSD32TOP_UAP(hint, void); |
243 | return sys__lwp_unpark_all(l, &ua, retval); |
244 | } |
245 | |
246 | int |
247 | netbsd32__lwp_setname(struct lwp *l, const struct netbsd32__lwp_setname_args *uap, register_t *retval) |
248 | { |
249 | /* { |
250 | syscallarg(lwpid_t) target; |
251 | syscallarg(const netbsd32_charp) name; |
252 | } */ |
253 | struct sys__lwp_setname_args ua; |
254 | |
255 | NETBSD32TO64_UAP(target); |
256 | NETBSD32TOP_UAP(name, char *); |
257 | return sys__lwp_setname(l, &ua, retval); |
258 | } |
259 | |
260 | int |
261 | netbsd32__lwp_getname(struct lwp *l, const struct netbsd32__lwp_getname_args *uap, register_t *retval) |
262 | { |
263 | /* { |
264 | syscallarg(lwpid_t) target; |
265 | syscallarg(netbsd32_charp) name; |
266 | syscallarg(netbsd32_size_t) len; |
267 | } */ |
268 | struct sys__lwp_getname_args ua; |
269 | |
270 | NETBSD32TO64_UAP(target); |
271 | NETBSD32TOP_UAP(name, char *); |
272 | NETBSD32TOX_UAP(len, size_t); |
273 | return sys__lwp_getname(l, &ua, retval); |
274 | } |
275 | |
276 | int |
277 | netbsd32__lwp_ctl(struct lwp *l, const struct netbsd32__lwp_ctl_args *uap, register_t *retval) |
278 | { |
279 | /* { |
280 | syscallarg(int) features; |
281 | syscallarg(netbsd32_pointer_t) address; |
282 | } */ |
283 | netbsd32_pointer_t vaddr32; |
284 | int error, features; |
285 | vaddr_t vaddr; |
286 | |
287 | features = SCARG(uap, features); |
288 | features &= ~(LWPCTL_FEATURE_CURCPU | LWPCTL_FEATURE_PCTR); |
289 | if (features != 0) |
290 | return ENODEV; |
291 | if ((error = lwp_ctl_alloc(&vaddr)) != 0) |
292 | return error; |
293 | NETBSD32PTR32(vaddr32, (void *)vaddr); |
294 | return copyout(&vaddr32, SCARG_P32(uap, address), sizeof(vaddr32)); |
295 | } |
296 | |