netbsd32_lwp.c revision 1.1.6.4 1 /* $NetBSD: netbsd32_lwp.c,v 1.1.6.4 2007/03/24 14:55:15 yamt 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.1.6.4 2007/03/24 14:55:15 yamt 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(netbsd32_ucontextp) ucp;
138 syscallarg(netbsd32_voidp) hint;
139 } */ *uap = v;
140 struct sys__lwp_park_args ua;
141 struct timespec *tsp = NULL;
142
143 if (SCARG_P32(uap, ts)) {
144 struct timespec ts;
145 struct netbsd32_timespec ts32;
146 int error;
147 void *sg;
148
149 if ((error = copyin(SCARG_P32(uap, ts), &ts32,
150 sizeof ts32)) != 0)
151 return error;
152 netbsd32_to_timespec(&ts32, &ts);
153
154 sg = stackgap_init(l->l_proc, sizeof(ts));
155 tsp = (struct timespec *)stackgap_alloc(l->l_proc, &sg,
156 sizeof(ts));
157 if ((error = copyout(&ts, tsp, sizeof(ts))) != 0)
158 return error;
159 }
160
161 /*
162 * sys__lwp_park() ignores the ucontext_t argument, so we won't be
163 * doing anything to it for now. While that situation could change,
164 * there's still a good chance it will only be considered as an
165 * opaque value.
166 */
167
168 SCARG(&ua, ts) = tsp;
169 NETBSD32TOP_UAP(ucp, ucontext_t);
170 NETBSD32TOP_UAP(hint, void);
171 return sys__lwp_park(l, &ua, retval);
172 }
173
174 int
175 netbsd32__lwp_kill(struct lwp *l, void *v, register_t *retval)
176 {
177 struct netbsd32__lwp_kill_args /* {
178 syscallarg(lwpid_t) target;
179 syscallarg(int) signo;
180 } */ *uap = v;
181 struct sys__lwp_kill_args ua;
182
183 NETBSD32TO64_UAP(target);
184 NETBSD32TO64_UAP(signo);
185 return sys__lwp_kill(l, &ua, retval);
186 }
187 int
188 netbsd32__lwp_detach(struct lwp *l, void *v, register_t *retval)
189 {
190 struct netbsd32__lwp_detach_args /* {
191 syscallarg(lwpid_t) target;
192 } */ *uap = v;
193 struct sys__lwp_detach_args ua;
194
195 NETBSD32TO64_UAP(target);
196 return sys__lwp_detach(l, &ua, retval);
197 }
198
199 int
200 netbsd32__lwp_unpark(struct lwp *l, void *v, register_t *retval)
201 {
202 struct netbsd32__lwp_unpark_args /* {
203 syscallarg(lwpid_t) target;
204 syscallarg(netbsd32_voidp) hint;
205 } */ *uap = v;
206 struct sys__lwp_unpark_args ua;
207
208 NETBSD32TO64_UAP(target);
209 NETBSD32TOP_UAP(hint, void);
210 return sys__lwp_unpark(l, &ua, retval);
211 }
212
213 int
214 netbsd32__lwp_unpark_all(struct lwp *l, void *v, register_t *retval)
215 {
216 struct netbsd32__lwp_unpark_all_args /* {
217 syscallarg(const netbsd32_lwpidp) targets;
218 syscallarg(netbsd32_size_t) ntargets;
219 syscallarg(netbsd32_voidp) hint;
220 } */ *uap = v;
221 struct sys__lwp_unpark_all_args ua;
222
223 NETBSD32TOP_UAP(targets, const lwpid_t);
224 NETBSD32TOX_UAP(ntargets, size_t);
225 NETBSD32TOP_UAP(hint, void);
226 return sys__lwp_unpark_all(l, &ua, retval);
227 }
228