netbsd32_lwp.c revision 1.6 1 /* $NetBSD: netbsd32_lwp.c,v 1.6 2007/08/07 19:00:42 ad 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.6 2007/08/07 19:00:42 ad 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
47 #include <compat/netbsd32/netbsd32.h>
48 #include <compat/netbsd32/netbsd32_syscallargs.h>
49 #include <compat/netbsd32/netbsd32_conv.h>
50
51 /* Sycalls conversion */
52
53 int
54 netbsd32__lwp_create(struct lwp *l, void *v, register_t *retval)
55 {
56 struct netbsd32__lwp_create_args /* {
57 syscallarg(const netbsd32_ucontextp) ucp;
58 syscallarg(netbsd32_u_long) flags;
59 syscallarg(netbsd32_lwpidp) new_lwp;
60 } */ *uap = v;
61 struct sys__lwp_create_args ua;
62
63 NETBSD32TOP_UAP(ucp, const ucontext_t);
64 NETBSD32TO64_UAP(flags);
65 NETBSD32TOP_UAP(new_lwp, lwpid_t);
66
67 return sys__lwp_create(l, &ua, retval);
68 }
69
70 int
71 netbsd32__lwp_wait(struct lwp *l, void *v, register_t *retval)
72 {
73 struct netbsd32__lwp_wait_args /* {
74 syscallarg(lwpid_t) wait_for;
75 syscallarg(netbsd32_lwpidp) departed;
76 } */ *uap = v;
77 struct sys__lwp_wait_args ua;
78
79 NETBSD32TO64_UAP(wait_for);
80 NETBSD32TOP_UAP(departed, lwpid_t);
81 return sys__lwp_wait(l, &ua, retval);
82 }
83
84 int
85 netbsd32__lwp_suspend(struct lwp *l, void *v, register_t *retval)
86 {
87 struct netbsd32__lwp_suspend_args /* {
88 syscallarg(lwpid_t) target;
89 } */ *uap = v;
90 struct sys__lwp_suspend_args ua;
91
92 NETBSD32TO64_UAP(target);
93 return sys__lwp_suspend(l, &ua, retval);
94 }
95
96 int
97 netbsd32__lwp_continue(struct lwp *l, void *v, register_t *retval)
98 {
99 struct netbsd32__lwp_continue_args /* {
100 syscallarg(lwpid_t) target;
101 } */ *uap = v;
102 struct sys__lwp_continue_args ua;
103
104 NETBSD32TO64_UAP(target);
105 return sys__lwp_continue(l, &ua, retval);
106 }
107
108 int
109 netbsd32__lwp_wakeup(struct lwp *l, void *v, register_t *retval)
110 {
111 struct netbsd32__lwp_wakeup_args /* {
112 syscallarg(lwpid_t) target;
113 } */ *uap = v;
114 struct sys__lwp_wakeup_args ua;
115
116 NETBSD32TO64_UAP(target);
117 return sys__lwp_wakeup(l, &ua, retval);
118 }
119
120 int
121 netbsd32__lwp_setprivate(struct lwp *l, void *v, register_t *retval)
122 {
123 struct netbsd32__lwp_setprivate_args /* {
124 syscallarg(netbsd32_voidp) ptr;
125 } */ *uap = v;
126 struct sys__lwp_setprivate_args ua;
127
128 NETBSD32TOP_UAP(ptr, void);
129 return sys__lwp_setprivate(l, &ua, retval);
130 }
131
132 int
133 netbsd32__lwp_park(struct lwp *l, void *v, register_t *retval)
134 {
135 struct netbsd32__lwp_park_args /* {
136 syscallarg(const netbsd32_timespecp) ts;
137 syscallarg(lwpid_t) unpark;
138 syscallarg(netbsd32_voidp) hint;
139 syscallarg(netbsd32_voidp) unparkhint;
140 } */ *uap = v;
141 struct timespec ts, *tsp;
142 struct netbsd32_timespec ts32;
143 int error;
144
145 if (SCARG_P32(uap, ts) == NULL)
146 tsp = NULL;
147 else {
148 error = copyin(SCARG_P32(uap, ts), &ts32, sizeof ts32);
149 if (error != 0)
150 return error;
151 netbsd32_to_timespec(&ts32, &ts);
152 tsp = &ts;
153 }
154
155 if (SCARG(uap, unpark) != 0) {
156 error = lwp_unpark(SCARG(uap, unpark),
157 SCARG_P32(uap, unparkhint));
158 if (error != 0)
159 return error;
160 }
161
162 return lwp_park(tsp, SCARG_P32(uap, hint));
163 }
164
165 int
166 netbsd32__lwp_kill(struct lwp *l, void *v, register_t *retval)
167 {
168 struct netbsd32__lwp_kill_args /* {
169 syscallarg(lwpid_t) target;
170 syscallarg(int) signo;
171 } */ *uap = v;
172 struct sys__lwp_kill_args ua;
173
174 NETBSD32TO64_UAP(target);
175 NETBSD32TO64_UAP(signo);
176 return sys__lwp_kill(l, &ua, retval);
177 }
178 int
179 netbsd32__lwp_detach(struct lwp *l, void *v, register_t *retval)
180 {
181 struct netbsd32__lwp_detach_args /* {
182 syscallarg(lwpid_t) target;
183 } */ *uap = v;
184 struct sys__lwp_detach_args ua;
185
186 NETBSD32TO64_UAP(target);
187 return sys__lwp_detach(l, &ua, retval);
188 }
189
190 int
191 netbsd32__lwp_unpark(struct lwp *l, void *v, register_t *retval)
192 {
193 struct netbsd32__lwp_unpark_args /* {
194 syscallarg(lwpid_t) target;
195 syscallarg(netbsd32_voidp) hint;
196 } */ *uap = v;
197 struct sys__lwp_unpark_args ua;
198
199 NETBSD32TO64_UAP(target);
200 NETBSD32TOP_UAP(hint, void);
201 return sys__lwp_unpark(l, &ua, retval);
202 }
203
204 int
205 netbsd32__lwp_unpark_all(struct lwp *l, void *v, register_t *retval)
206 {
207 struct netbsd32__lwp_unpark_all_args /* {
208 syscallarg(const netbsd32_lwpidp) targets;
209 syscallarg(netbsd32_size_t) ntargets;
210 syscallarg(netbsd32_voidp) hint;
211 } */ *uap = v;
212 struct sys__lwp_unpark_all_args ua;
213
214 NETBSD32TOP_UAP(targets, const lwpid_t);
215 NETBSD32TOX_UAP(ntargets, size_t);
216 NETBSD32TOP_UAP(hint, void);
217 return sys__lwp_unpark_all(l, &ua, retval);
218 }
219