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