netbsd32_lwp.c revision 1.2.6.3 1 1.2.6.3 reinoud /* $NetBSD: netbsd32_lwp.c,v 1.2.6.3 2007/12/09 16:03:57 reinoud Exp $ */
2 1.1 cube
3 1.1 cube /*
4 1.1 cube * Copyright (c) 2005, 2006, 2007 The NetBSD Foundation.
5 1.1 cube * All rights reserved.
6 1.1 cube *
7 1.1 cube * This code is derived from software contributed to the NetBSD Foundation
8 1.1 cube * by Quentin Garnier.
9 1.1 cube *
10 1.1 cube * Redistribution and use in source and binary forms, with or without
11 1.1 cube * modification, are permitted provided that the following conditions
12 1.1 cube * are met:
13 1.1 cube * 1. Redistributions of source code must retain the above copyright
14 1.1 cube * notice, this list of conditions and the following disclaimer.
15 1.1 cube * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 cube * notice, this list of conditions and the following disclaimer in the
17 1.1 cube * documentation and/or other materials provided with the distribution.
18 1.1 cube * 3. Neither the name of The NetBSD Foundation nor the names of its
19 1.1 cube * contributors may be used to endorse or promote products derived
20 1.1 cube * from this software without specific prior written permission.
21 1.1 cube *
22 1.1 cube * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1 cube * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1 cube * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1 cube * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1 cube * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1 cube * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1 cube * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1 cube * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1 cube * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1 cube * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1 cube * POSSIBILITY OF SUCH DAMAGE.
33 1.1 cube */
34 1.1 cube
35 1.1 cube #include <sys/cdefs.h>
36 1.2.6.3 reinoud __KERNEL_RCSID(0, "$NetBSD: netbsd32_lwp.c,v 1.2.6.3 2007/12/09 16:03:57 reinoud Exp $");
37 1.1 cube
38 1.1 cube #include <sys/types.h>
39 1.1 cube #include <sys/param.h>
40 1.1 cube #include <sys/systm.h>
41 1.1 cube #include <sys/kernel.h>
42 1.1 cube #include <sys/dirent.h>
43 1.1 cube #include <sys/mount.h>
44 1.1 cube #include <sys/proc.h>
45 1.1 cube #include <sys/syscallargs.h>
46 1.2.6.3 reinoud #include <sys/lwpctl.h>
47 1.1 cube
48 1.1 cube #include <compat/netbsd32/netbsd32.h>
49 1.1 cube #include <compat/netbsd32/netbsd32_syscallargs.h>
50 1.1 cube #include <compat/netbsd32/netbsd32_conv.h>
51 1.1 cube
52 1.1 cube /* Sycalls conversion */
53 1.1 cube
54 1.1 cube int
55 1.1 cube netbsd32__lwp_create(struct lwp *l, void *v, register_t *retval)
56 1.1 cube {
57 1.1 cube struct netbsd32__lwp_create_args /* {
58 1.1 cube syscallarg(const netbsd32_ucontextp) ucp;
59 1.1 cube syscallarg(netbsd32_u_long) flags;
60 1.1 cube syscallarg(netbsd32_lwpidp) new_lwp;
61 1.1 cube } */ *uap = v;
62 1.1 cube struct sys__lwp_create_args ua;
63 1.1 cube
64 1.1 cube NETBSD32TOP_UAP(ucp, const ucontext_t);
65 1.1 cube NETBSD32TO64_UAP(flags);
66 1.1 cube NETBSD32TOP_UAP(new_lwp, lwpid_t);
67 1.1 cube
68 1.1 cube return sys__lwp_create(l, &ua, retval);
69 1.1 cube }
70 1.1 cube
71 1.1 cube int
72 1.1 cube netbsd32__lwp_wait(struct lwp *l, void *v, register_t *retval)
73 1.1 cube {
74 1.1 cube struct netbsd32__lwp_wait_args /* {
75 1.1 cube syscallarg(lwpid_t) wait_for;
76 1.1 cube syscallarg(netbsd32_lwpidp) departed;
77 1.1 cube } */ *uap = v;
78 1.1 cube struct sys__lwp_wait_args ua;
79 1.1 cube
80 1.1 cube NETBSD32TO64_UAP(wait_for);
81 1.1 cube NETBSD32TOP_UAP(departed, lwpid_t);
82 1.1 cube return sys__lwp_wait(l, &ua, retval);
83 1.1 cube }
84 1.1 cube
85 1.1 cube int
86 1.1 cube netbsd32__lwp_suspend(struct lwp *l, void *v, register_t *retval)
87 1.1 cube {
88 1.1 cube struct netbsd32__lwp_suspend_args /* {
89 1.1 cube syscallarg(lwpid_t) target;
90 1.1 cube } */ *uap = v;
91 1.1 cube struct sys__lwp_suspend_args ua;
92 1.1 cube
93 1.1 cube NETBSD32TO64_UAP(target);
94 1.1 cube return sys__lwp_suspend(l, &ua, retval);
95 1.1 cube }
96 1.1 cube
97 1.1 cube int
98 1.1 cube netbsd32__lwp_continue(struct lwp *l, void *v, register_t *retval)
99 1.1 cube {
100 1.1 cube struct netbsd32__lwp_continue_args /* {
101 1.1 cube syscallarg(lwpid_t) target;
102 1.1 cube } */ *uap = v;
103 1.1 cube struct sys__lwp_continue_args ua;
104 1.1 cube
105 1.1 cube NETBSD32TO64_UAP(target);
106 1.1 cube return sys__lwp_continue(l, &ua, retval);
107 1.1 cube }
108 1.1 cube
109 1.1 cube int
110 1.1 cube netbsd32__lwp_wakeup(struct lwp *l, void *v, register_t *retval)
111 1.1 cube {
112 1.1 cube struct netbsd32__lwp_wakeup_args /* {
113 1.1 cube syscallarg(lwpid_t) target;
114 1.1 cube } */ *uap = v;
115 1.1 cube struct sys__lwp_wakeup_args ua;
116 1.1 cube
117 1.1 cube NETBSD32TO64_UAP(target);
118 1.1 cube return sys__lwp_wakeup(l, &ua, retval);
119 1.1 cube }
120 1.1 cube
121 1.1 cube int
122 1.1 cube netbsd32__lwp_setprivate(struct lwp *l, void *v, register_t *retval)
123 1.1 cube {
124 1.1 cube struct netbsd32__lwp_setprivate_args /* {
125 1.1 cube syscallarg(netbsd32_voidp) ptr;
126 1.1 cube } */ *uap = v;
127 1.1 cube struct sys__lwp_setprivate_args ua;
128 1.1 cube
129 1.1 cube NETBSD32TOP_UAP(ptr, void);
130 1.1 cube return sys__lwp_setprivate(l, &ua, retval);
131 1.1 cube }
132 1.1 cube
133 1.1 cube int
134 1.1 cube netbsd32__lwp_park(struct lwp *l, void *v, register_t *retval)
135 1.1 cube {
136 1.1 cube struct netbsd32__lwp_park_args /* {
137 1.1 cube syscallarg(const netbsd32_timespecp) ts;
138 1.1 cube syscallarg(netbsd32_ucontextp) ucp;
139 1.1 cube syscallarg(netbsd32_voidp) hint;
140 1.1 cube } */ *uap = v;
141 1.1 cube struct sys__lwp_park_args ua;
142 1.1 cube struct timespec *tsp = NULL;
143 1.1 cube
144 1.2.6.2 reinoud if (SCARG_P32(uap, ts)) {
145 1.1 cube struct timespec ts;
146 1.1 cube struct netbsd32_timespec ts32;
147 1.1 cube int error;
148 1.2 christos void *sg;
149 1.1 cube
150 1.2.6.2 reinoud if ((error = copyin(SCARG_P32(uap, ts), &ts32,
151 1.1 cube sizeof ts32)) != 0)
152 1.1 cube return error;
153 1.1 cube netbsd32_to_timespec(&ts32, &ts);
154 1.1 cube
155 1.1 cube sg = stackgap_init(l->l_proc, sizeof(ts));
156 1.1 cube tsp = (struct timespec *)stackgap_alloc(l->l_proc, &sg,
157 1.1 cube sizeof(ts));
158 1.1 cube if ((error = copyout(&ts, tsp, sizeof(ts))) != 0)
159 1.1 cube return error;
160 1.1 cube }
161 1.1 cube
162 1.1 cube /*
163 1.1 cube * sys__lwp_park() ignores the ucontext_t argument, so we won't be
164 1.1 cube * doing anything to it for now. While that situation could change,
165 1.1 cube * there's still a good chance it will only be considered as an
166 1.1 cube * opaque value.
167 1.1 cube */
168 1.1 cube
169 1.1 cube SCARG(&ua, ts) = tsp;
170 1.1 cube NETBSD32TOP_UAP(ucp, ucontext_t);
171 1.1 cube NETBSD32TOP_UAP(hint, void);
172 1.1 cube return sys__lwp_park(l, &ua, retval);
173 1.1 cube }
174 1.1 cube
175 1.1 cube int
176 1.1 cube netbsd32__lwp_kill(struct lwp *l, void *v, register_t *retval)
177 1.1 cube {
178 1.1 cube struct netbsd32__lwp_kill_args /* {
179 1.1 cube syscallarg(lwpid_t) target;
180 1.1 cube syscallarg(int) signo;
181 1.1 cube } */ *uap = v;
182 1.1 cube struct sys__lwp_kill_args ua;
183 1.1 cube
184 1.1 cube NETBSD32TO64_UAP(target);
185 1.1 cube NETBSD32TO64_UAP(signo);
186 1.1 cube return sys__lwp_kill(l, &ua, retval);
187 1.1 cube }
188 1.1 cube int
189 1.1 cube netbsd32__lwp_detach(struct lwp *l, void *v, register_t *retval)
190 1.1 cube {
191 1.1 cube struct netbsd32__lwp_detach_args /* {
192 1.1 cube syscallarg(lwpid_t) target;
193 1.1 cube } */ *uap = v;
194 1.1 cube struct sys__lwp_detach_args ua;
195 1.1 cube
196 1.1 cube NETBSD32TO64_UAP(target);
197 1.1 cube return sys__lwp_detach(l, &ua, retval);
198 1.1 cube }
199 1.1 cube
200 1.1 cube int
201 1.1 cube netbsd32__lwp_unpark(struct lwp *l, void *v, register_t *retval)
202 1.1 cube {
203 1.1 cube struct netbsd32__lwp_unpark_args /* {
204 1.1 cube syscallarg(lwpid_t) target;
205 1.1 cube syscallarg(netbsd32_voidp) hint;
206 1.1 cube } */ *uap = v;
207 1.1 cube struct sys__lwp_unpark_args ua;
208 1.1 cube
209 1.1 cube NETBSD32TO64_UAP(target);
210 1.1 cube NETBSD32TOP_UAP(hint, void);
211 1.1 cube return sys__lwp_unpark(l, &ua, retval);
212 1.1 cube }
213 1.1 cube
214 1.1 cube int
215 1.1 cube netbsd32__lwp_unpark_all(struct lwp *l, void *v, register_t *retval)
216 1.1 cube {
217 1.1 cube struct netbsd32__lwp_unpark_all_args /* {
218 1.1 cube syscallarg(const netbsd32_lwpidp) targets;
219 1.1 cube syscallarg(netbsd32_size_t) ntargets;
220 1.1 cube syscallarg(netbsd32_voidp) hint;
221 1.1 cube } */ *uap = v;
222 1.1 cube struct sys__lwp_unpark_all_args ua;
223 1.1 cube
224 1.1 cube NETBSD32TOP_UAP(targets, const lwpid_t);
225 1.1 cube NETBSD32TOX_UAP(ntargets, size_t);
226 1.1 cube NETBSD32TOP_UAP(hint, void);
227 1.1 cube return sys__lwp_unpark_all(l, &ua, retval);
228 1.1 cube }
229 1.2.6.3 reinoud
230 1.2.6.3 reinoud int
231 1.2.6.3 reinoud netbsd32__lwp_setname(struct lwp *l, void *v, register_t *retval)
232 1.2.6.3 reinoud {
233 1.2.6.3 reinoud struct netbsd32__lwp_setname_args /* {
234 1.2.6.3 reinoud syscallarg(lwpid_t) target;
235 1.2.6.3 reinoud syscallarg(const netbsd32_charp) name;
236 1.2.6.3 reinoud } */ *uap = v;
237 1.2.6.3 reinoud struct sys__lwp_setname_args ua;
238 1.2.6.3 reinoud
239 1.2.6.3 reinoud NETBSD32TO64_UAP(target);
240 1.2.6.3 reinoud NETBSD32TOP_UAP(name, char *);
241 1.2.6.3 reinoud return sys__lwp_setname(l, &ua, retval);
242 1.2.6.3 reinoud }
243 1.2.6.3 reinoud
244 1.2.6.3 reinoud int
245 1.2.6.3 reinoud netbsd32__lwp_getname(struct lwp *l, void *v, register_t *retval)
246 1.2.6.3 reinoud {
247 1.2.6.3 reinoud struct netbsd32__lwp_getname_args /* {
248 1.2.6.3 reinoud syscallarg(lwpid_t) target;
249 1.2.6.3 reinoud syscallarg(netbsd32_charp) name;
250 1.2.6.3 reinoud syscallarg(netbsd32_size_t) len;
251 1.2.6.3 reinoud } */ *uap = v;
252 1.2.6.3 reinoud struct sys__lwp_getname_args ua;
253 1.2.6.3 reinoud
254 1.2.6.3 reinoud NETBSD32TO64_UAP(target);
255 1.2.6.3 reinoud NETBSD32TOP_UAP(name, char *);
256 1.2.6.3 reinoud NETBSD32TOX_UAP(len, size_t);
257 1.2.6.3 reinoud return sys__lwp_getname(l, &ua, retval);
258 1.2.6.3 reinoud }
259 1.2.6.3 reinoud
260 1.2.6.3 reinoud int
261 1.2.6.3 reinoud netbsd32__lwp_ctl(struct lwp *l, void *v, register_t *retval)
262 1.2.6.3 reinoud {
263 1.2.6.3 reinoud struct netbsd32__lwp_ctl_args /* {
264 1.2.6.3 reinoud syscallarg(int) features;
265 1.2.6.3 reinoud syscallarg(netbsd32_pointer_t) address;
266 1.2.6.3 reinoud } */ *uap = v;
267 1.2.6.3 reinoud struct sys__lwp_ctl_args ua;
268 1.2.6.3 reinoud
269 1.2.6.3 reinoud NETBSD32TO64_UAP(features);
270 1.2.6.3 reinoud NETBSD32TOP_UAP(address, struct lwpctl *);
271 1.2.6.3 reinoud return sys__lwp_ctl(l, &ua, retval);
272 1.2.6.3 reinoud }
273