linux_sched.c revision 1.28 1 1.28 manu /* $NetBSD: linux_sched.c,v 1.28 2005/11/29 16:24:41 manu Exp $ */
2 1.1 tron
3 1.1 tron /*-
4 1.1 tron * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 1.1 tron * All rights reserved.
6 1.1 tron *
7 1.1 tron * This code is derived from software contributed to The NetBSD Foundation
8 1.2 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 tron * NASA Ames Research Center; by Matthias Scheler.
10 1.1 tron *
11 1.1 tron * Redistribution and use in source and binary forms, with or without
12 1.1 tron * modification, are permitted provided that the following conditions
13 1.1 tron * are met:
14 1.1 tron * 1. Redistributions of source code must retain the above copyright
15 1.1 tron * notice, this list of conditions and the following disclaimer.
16 1.1 tron * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 tron * notice, this list of conditions and the following disclaimer in the
18 1.1 tron * documentation and/or other materials provided with the distribution.
19 1.1 tron * 3. All advertising materials mentioning features or use of this software
20 1.1 tron * must display the following acknowledgement:
21 1.1 tron * This product includes software developed by the NetBSD
22 1.1 tron * Foundation, Inc. and its contributors.
23 1.1 tron * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 tron * contributors may be used to endorse or promote products derived
25 1.1 tron * from this software without specific prior written permission.
26 1.1 tron *
27 1.1 tron * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 tron * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 tron * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 tron * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 tron * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 tron * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 tron * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 tron * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 tron * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 tron * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 tron * POSSIBILITY OF SUCH DAMAGE.
38 1.1 tron */
39 1.1 tron
40 1.1 tron /*
41 1.1 tron * Linux compatibility module. Try to deal with scheduler related syscalls.
42 1.1 tron */
43 1.8 lukem
44 1.8 lukem #include <sys/cdefs.h>
45 1.28 manu __KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.28 2005/11/29 16:24:41 manu Exp $");
46 1.1 tron
47 1.1 tron #include <sys/param.h>
48 1.1 tron #include <sys/mount.h>
49 1.1 tron #include <sys/proc.h>
50 1.1 tron #include <sys/systm.h>
51 1.22 manu #include <sys/sysctl.h>
52 1.22 manu #include <sys/malloc.h>
53 1.12 thorpej #include <sys/sa.h>
54 1.27 manu #include <sys/savar.h>
55 1.1 tron #include <sys/syscallargs.h>
56 1.14 jdolecek #include <sys/wait.h>
57 1.3 itohy
58 1.3 itohy #include <machine/cpu.h>
59 1.1 tron
60 1.1 tron #include <compat/linux/common/linux_types.h>
61 1.27 manu #include <compat/linux/common/linux_exec.h>
62 1.1 tron #include <compat/linux/common/linux_signal.h>
63 1.21 manu #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
64 1.19 manu #include <compat/linux/common/linux_emuldata.h>
65 1.1 tron
66 1.1 tron #include <compat/linux/linux_syscallargs.h>
67 1.1 tron
68 1.1 tron #include <compat/linux/common/linux_sched.h>
69 1.1 tron
70 1.1 tron int
71 1.12 thorpej linux_sys_clone(l, v, retval)
72 1.12 thorpej struct lwp *l;
73 1.1 tron void *v;
74 1.1 tron register_t *retval;
75 1.1 tron {
76 1.1 tron struct linux_sys_clone_args /* {
77 1.1 tron syscallarg(int) flags;
78 1.1 tron syscallarg(void *) stack;
79 1.21 manu #ifdef LINUX_NPTL
80 1.19 manu syscallarg(void *) parent_tidptr;
81 1.19 manu syscallarg(void *) child_tidptr;
82 1.19 manu #endif
83 1.1 tron } */ *uap = v;
84 1.1 tron int flags, sig;
85 1.19 manu int error;
86 1.21 manu #ifdef LINUX_NPTL
87 1.19 manu struct linux_emuldata *led;
88 1.19 manu #endif
89 1.1 tron
90 1.1 tron /*
91 1.1 tron * We don't support the Linux CLONE_PID or CLONE_PTRACE flags.
92 1.1 tron */
93 1.1 tron if (SCARG(uap, flags) & (LINUX_CLONE_PID|LINUX_CLONE_PTRACE))
94 1.1 tron return (EINVAL);
95 1.1 tron
96 1.13 jdolecek /*
97 1.13 jdolecek * Thread group implies shared signals. Shared signals
98 1.13 jdolecek * imply shared VM. This matches what Linux kernel does.
99 1.13 jdolecek */
100 1.13 jdolecek if (SCARG(uap, flags) & LINUX_CLONE_THREAD
101 1.13 jdolecek && (SCARG(uap, flags) & LINUX_CLONE_SIGHAND) == 0)
102 1.13 jdolecek return (EINVAL);
103 1.13 jdolecek if (SCARG(uap, flags) & LINUX_CLONE_SIGHAND
104 1.13 jdolecek && (SCARG(uap, flags) & LINUX_CLONE_VM) == 0)
105 1.13 jdolecek return (EINVAL);
106 1.13 jdolecek
107 1.1 tron flags = 0;
108 1.1 tron
109 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_VM)
110 1.1 tron flags |= FORK_SHAREVM;
111 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_FS)
112 1.1 tron flags |= FORK_SHARECWD;
113 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_FILES)
114 1.1 tron flags |= FORK_SHAREFILES;
115 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_SIGHAND)
116 1.1 tron flags |= FORK_SHARESIGS;
117 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_VFORK)
118 1.1 tron flags |= FORK_PPWAIT;
119 1.1 tron
120 1.28 manu /* Thread should not issue a SIGCHLD on termination */
121 1.28 manu if (SCARG(uap, flags) & LINUX_CLONE_THREAD) {
122 1.28 manu sig = 0;
123 1.28 manu } else {
124 1.28 manu sig = SCARG(uap, flags) & LINUX_CLONE_CSIGNAL;
125 1.28 manu if (sig < 0 || sig >= LINUX__NSIG)
126 1.28 manu return (EINVAL);
127 1.28 manu sig = linux_to_native_signo[sig];
128 1.28 manu }
129 1.1 tron
130 1.21 manu #ifdef LINUX_NPTL
131 1.19 manu led = (struct linux_emuldata *)l->l_proc->p_emuldata;
132 1.19 manu
133 1.19 manu if (SCARG(uap, flags) & LINUX_CLONE_PARENT_SETTID) {
134 1.19 manu if (SCARG(uap, parent_tidptr) == NULL) {
135 1.19 manu printf("linux_sys_clone: NULL parent_tidptr\n");
136 1.19 manu return EINVAL;
137 1.19 manu }
138 1.19 manu
139 1.19 manu if ((error = copyout(&l->l_proc->p_pid,
140 1.19 manu SCARG(uap, parent_tidptr),
141 1.19 manu sizeof(l->l_proc->p_pid))) != 0)
142 1.19 manu return error;
143 1.19 manu }
144 1.19 manu
145 1.19 manu /* CLONE_CHILD_CLEARTID: TID clear in the child on exit() */
146 1.19 manu if (SCARG(uap, flags) & LINUX_CLONE_CHILD_CLEARTID)
147 1.19 manu led->child_clear_tid = SCARG(uap, child_tidptr);
148 1.19 manu else
149 1.19 manu led->child_clear_tid = NULL;
150 1.19 manu
151 1.19 manu /* CLONE_CHILD_SETTID: TID set in the child on clone() */
152 1.19 manu if (SCARG(uap, flags) & LINUX_CLONE_CHILD_SETTID)
153 1.19 manu led->child_set_tid = SCARG(uap, child_tidptr);
154 1.19 manu else
155 1.19 manu led->child_set_tid = NULL;
156 1.21 manu
157 1.21 manu /* CLONE_SETTLS: new Thread Local Storage in the child */
158 1.21 manu if (SCARG(uap, flags) & LINUX_CLONE_SETTLS)
159 1.21 manu led->set_tls = linux_get_newtls(l);
160 1.21 manu else
161 1.21 manu led->set_tls = 0;
162 1.21 manu #endif /* LINUX_NPTL */
163 1.1 tron /*
164 1.1 tron * Note that Linux does not provide a portable way of specifying
165 1.1 tron * the stack area; the caller must know if the stack grows up
166 1.1 tron * or down. So, we pass a stack size of 0, so that the code
167 1.1 tron * that makes this adjustment is a noop.
168 1.1 tron */
169 1.19 manu if ((error = fork1(l, flags, sig, SCARG(uap, stack), 0,
170 1.19 manu NULL, NULL, retval, NULL)) != 0)
171 1.19 manu return error;
172 1.19 manu
173 1.19 manu return 0;
174 1.1 tron }
175 1.1 tron
176 1.1 tron int
177 1.12 thorpej linux_sys_sched_setparam(cl, v, retval)
178 1.12 thorpej struct lwp *cl;
179 1.1 tron void *v;
180 1.1 tron register_t *retval;
181 1.1 tron {
182 1.1 tron struct linux_sys_sched_setparam_args /* {
183 1.1 tron syscallarg(linux_pid_t) pid;
184 1.1 tron syscallarg(const struct linux_sched_param *) sp;
185 1.1 tron } */ *uap = v;
186 1.12 thorpej struct proc *cp = cl->l_proc;
187 1.1 tron int error;
188 1.1 tron struct linux_sched_param lp;
189 1.5 augustss struct proc *p;
190 1.1 tron
191 1.1 tron /*
192 1.1 tron * We only check for valid parameters and return afterwards.
193 1.1 tron */
194 1.1 tron
195 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
196 1.1 tron return EINVAL;
197 1.1 tron
198 1.1 tron error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
199 1.1 tron if (error)
200 1.1 tron return error;
201 1.1 tron
202 1.1 tron if (SCARG(uap, pid) != 0) {
203 1.5 augustss struct pcred *pc = cp->p_cred;
204 1.1 tron
205 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
206 1.1 tron return ESRCH;
207 1.1 tron if (!(cp == p ||
208 1.1 tron pc->pc_ucred->cr_uid == 0 ||
209 1.1 tron pc->p_ruid == p->p_cred->p_ruid ||
210 1.1 tron pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
211 1.1 tron pc->p_ruid == p->p_ucred->cr_uid ||
212 1.1 tron pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
213 1.1 tron return EPERM;
214 1.1 tron }
215 1.1 tron
216 1.1 tron return 0;
217 1.1 tron }
218 1.1 tron
219 1.1 tron int
220 1.12 thorpej linux_sys_sched_getparam(cl, v, retval)
221 1.12 thorpej struct lwp *cl;
222 1.1 tron void *v;
223 1.1 tron register_t *retval;
224 1.1 tron {
225 1.1 tron struct linux_sys_sched_getparam_args /* {
226 1.1 tron syscallarg(linux_pid_t) pid;
227 1.1 tron syscallarg(struct linux_sched_param *) sp;
228 1.1 tron } */ *uap = v;
229 1.12 thorpej struct proc *cp = cl->l_proc;
230 1.5 augustss struct proc *p;
231 1.1 tron struct linux_sched_param lp;
232 1.1 tron
233 1.1 tron /*
234 1.1 tron * We only check for valid parameters and return a dummy priority afterwards.
235 1.1 tron */
236 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
237 1.1 tron return EINVAL;
238 1.1 tron
239 1.1 tron if (SCARG(uap, pid) != 0) {
240 1.5 augustss struct pcred *pc = cp->p_cred;
241 1.1 tron
242 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
243 1.1 tron return ESRCH;
244 1.1 tron if (!(cp == p ||
245 1.1 tron pc->pc_ucred->cr_uid == 0 ||
246 1.1 tron pc->p_ruid == p->p_cred->p_ruid ||
247 1.1 tron pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
248 1.1 tron pc->p_ruid == p->p_ucred->cr_uid ||
249 1.1 tron pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
250 1.1 tron return EPERM;
251 1.1 tron }
252 1.1 tron
253 1.1 tron lp.sched_priority = 0;
254 1.1 tron return copyout(&lp, SCARG(uap, sp), sizeof(lp));
255 1.1 tron }
256 1.1 tron
257 1.1 tron int
258 1.12 thorpej linux_sys_sched_setscheduler(cl, v, retval)
259 1.12 thorpej struct lwp *cl;
260 1.1 tron void *v;
261 1.1 tron register_t *retval;
262 1.1 tron {
263 1.1 tron struct linux_sys_sched_setscheduler_args /* {
264 1.1 tron syscallarg(linux_pid_t) pid;
265 1.1 tron syscallarg(int) policy;
266 1.1 tron syscallarg(cont struct linux_sched_scheduler *) sp;
267 1.1 tron } */ *uap = v;
268 1.12 thorpej struct proc *cp = cl->l_proc;
269 1.1 tron int error;
270 1.1 tron struct linux_sched_param lp;
271 1.5 augustss struct proc *p;
272 1.1 tron
273 1.1 tron /*
274 1.1 tron * We only check for valid parameters and return afterwards.
275 1.1 tron */
276 1.1 tron
277 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
278 1.1 tron return EINVAL;
279 1.1 tron
280 1.1 tron error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
281 1.1 tron if (error)
282 1.1 tron return error;
283 1.1 tron
284 1.1 tron if (SCARG(uap, pid) != 0) {
285 1.5 augustss struct pcred *pc = cp->p_cred;
286 1.1 tron
287 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
288 1.1 tron return ESRCH;
289 1.1 tron if (!(cp == p ||
290 1.1 tron pc->pc_ucred->cr_uid == 0 ||
291 1.1 tron pc->p_ruid == p->p_cred->p_ruid ||
292 1.1 tron pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
293 1.1 tron pc->p_ruid == p->p_ucred->cr_uid ||
294 1.1 tron pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
295 1.1 tron return EPERM;
296 1.1 tron }
297 1.1 tron
298 1.1 tron /*
299 1.1 tron * We can't emulate anything put the default scheduling policy.
300 1.1 tron */
301 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER || lp.sched_priority != 0)
302 1.1 tron return EINVAL;
303 1.1 tron
304 1.1 tron return 0;
305 1.1 tron }
306 1.1 tron
307 1.1 tron int
308 1.12 thorpej linux_sys_sched_getscheduler(cl, v, retval)
309 1.12 thorpej struct lwp *cl;
310 1.1 tron void *v;
311 1.1 tron register_t *retval;
312 1.1 tron {
313 1.1 tron struct linux_sys_sched_getscheduler_args /* {
314 1.1 tron syscallarg(linux_pid_t) pid;
315 1.1 tron } */ *uap = v;
316 1.12 thorpej struct proc *cp = cl->l_proc;
317 1.5 augustss struct proc *p;
318 1.1 tron
319 1.1 tron *retval = -1;
320 1.1 tron /*
321 1.1 tron * We only check for valid parameters and return afterwards.
322 1.1 tron */
323 1.1 tron
324 1.1 tron if (SCARG(uap, pid) != 0) {
325 1.5 augustss struct pcred *pc = cp->p_cred;
326 1.1 tron
327 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
328 1.1 tron return ESRCH;
329 1.1 tron if (!(cp == p ||
330 1.1 tron pc->pc_ucred->cr_uid == 0 ||
331 1.1 tron pc->p_ruid == p->p_cred->p_ruid ||
332 1.1 tron pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
333 1.1 tron pc->p_ruid == p->p_ucred->cr_uid ||
334 1.1 tron pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
335 1.1 tron return EPERM;
336 1.1 tron }
337 1.1 tron
338 1.1 tron /*
339 1.1 tron * We can't emulate anything put the default scheduling policy.
340 1.1 tron */
341 1.1 tron *retval = LINUX_SCHED_OTHER;
342 1.1 tron return 0;
343 1.1 tron }
344 1.1 tron
345 1.1 tron int
346 1.12 thorpej linux_sys_sched_yield(cl, v, retval)
347 1.12 thorpej struct lwp *cl;
348 1.1 tron void *v;
349 1.1 tron register_t *retval;
350 1.1 tron {
351 1.11 gmcgarry
352 1.11 gmcgarry yield();
353 1.1 tron return 0;
354 1.1 tron }
355 1.1 tron
356 1.1 tron int
357 1.12 thorpej linux_sys_sched_get_priority_max(cl, v, retval)
358 1.12 thorpej struct lwp *cl;
359 1.1 tron void *v;
360 1.1 tron register_t *retval;
361 1.1 tron {
362 1.1 tron struct linux_sys_sched_get_priority_max_args /* {
363 1.1 tron syscallarg(int) policy;
364 1.1 tron } */ *uap = v;
365 1.1 tron
366 1.1 tron /*
367 1.1 tron * We can't emulate anything put the default scheduling policy.
368 1.1 tron */
369 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
370 1.1 tron *retval = -1;
371 1.1 tron return EINVAL;
372 1.1 tron }
373 1.1 tron
374 1.1 tron *retval = 0;
375 1.1 tron return 0;
376 1.1 tron }
377 1.1 tron
378 1.1 tron int
379 1.12 thorpej linux_sys_sched_get_priority_min(cl, v, retval)
380 1.12 thorpej struct lwp *cl;
381 1.1 tron void *v;
382 1.1 tron register_t *retval;
383 1.1 tron {
384 1.1 tron struct linux_sys_sched_get_priority_min_args /* {
385 1.1 tron syscallarg(int) policy;
386 1.1 tron } */ *uap = v;
387 1.1 tron
388 1.1 tron /*
389 1.1 tron * We can't emulate anything put the default scheduling policy.
390 1.1 tron */
391 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
392 1.1 tron *retval = -1;
393 1.1 tron return EINVAL;
394 1.1 tron }
395 1.1 tron
396 1.1 tron *retval = 0;
397 1.1 tron return 0;
398 1.1 tron }
399 1.14 jdolecek
400 1.14 jdolecek #ifndef __m68k__
401 1.14 jdolecek /* Present on everything but m68k */
402 1.14 jdolecek int
403 1.14 jdolecek linux_sys_exit_group(l, v, retval)
404 1.14 jdolecek struct lwp *l;
405 1.14 jdolecek void *v;
406 1.14 jdolecek register_t *retval;
407 1.14 jdolecek {
408 1.14 jdolecek struct linux_sys_exit_group_args /* {
409 1.14 jdolecek syscallarg(int) error_code;
410 1.14 jdolecek } */ *uap = v;
411 1.27 manu struct proc *p;
412 1.27 manu struct linux_emuldata *led;
413 1.27 manu pid_t group_pid;
414 1.14 jdolecek
415 1.14 jdolecek /*
416 1.27 manu * The calling thread is supposed to kill all threads
417 1.14 jdolecek * in the same thread group (i.e. all threads created
418 1.27 manu * via clone(2) with CLONE_THREAD flag set).
419 1.14 jdolecek */
420 1.27 manu led = l->l_proc->p_emuldata;
421 1.27 manu group_pid = led->s->group_pid;
422 1.27 manu PROCLIST_FOREACH(p, &allproc) {
423 1.27 manu if (p->p_emul != &emul_linux)
424 1.27 manu continue;
425 1.27 manu
426 1.27 manu if (p == l->l_proc)
427 1.27 manu continue;
428 1.27 manu
429 1.27 manu led = p->p_emuldata;
430 1.27 manu if (led->s->group_pid == group_pid) {
431 1.27 manu /* XXX we should exit, not send a SIGKILL */
432 1.27 manu psignal(p, SIGKILL);
433 1.27 manu }
434 1.27 manu }
435 1.14 jdolecek
436 1.14 jdolecek exit1(l, W_EXITCODE(SCARG(uap, error_code), 0));
437 1.14 jdolecek /* NOTREACHED */
438 1.15 tron return 0;
439 1.14 jdolecek }
440 1.14 jdolecek #endif /* !__m68k__ */
441 1.19 manu
442 1.21 manu #ifdef LINUX_NPTL
443 1.19 manu int
444 1.19 manu linux_sys_set_tid_address(l, v, retval)
445 1.19 manu struct lwp *l;
446 1.19 manu void *v;
447 1.19 manu register_t *retval;
448 1.19 manu {
449 1.19 manu struct linux_sys_set_tid_address_args /* {
450 1.19 manu syscallarg(int *) tidptr;
451 1.19 manu } */ *uap = v;
452 1.19 manu struct linux_emuldata *led;
453 1.19 manu
454 1.19 manu led = (struct linux_emuldata *)l->l_proc->p_emuldata;
455 1.19 manu led->clear_tid = SCARG(uap, tid);
456 1.19 manu
457 1.19 manu *retval = l->l_proc->p_pid;
458 1.19 manu
459 1.19 manu return 0;
460 1.19 manu }
461 1.20 manu
462 1.20 manu /* ARGUSED1 */
463 1.20 manu int
464 1.20 manu linux_sys_gettid(l, v, retval)
465 1.20 manu struct lwp *l;
466 1.20 manu void *v;
467 1.20 manu register_t *retval;
468 1.20 manu {
469 1.20 manu *retval = l->l_proc->p_pid;
470 1.20 manu return 0;
471 1.20 manu }
472 1.22 manu
473 1.22 manu int
474 1.22 manu linux_sys_sched_getaffinity(l, v, retval)
475 1.22 manu struct lwp *l;
476 1.22 manu void *v;
477 1.22 manu register_t *retval;
478 1.22 manu {
479 1.22 manu struct linux_sys_sched_getaffinity_args /* {
480 1.22 manu syscallarg(pid_t) pid;
481 1.22 manu syscallarg(unsigned int) len;
482 1.22 manu syscallarg(unsigned long *) mask;
483 1.22 manu } */ *uap = v;
484 1.22 manu int error;
485 1.22 manu int ret;
486 1.22 manu int ncpu;
487 1.22 manu int name[2];
488 1.22 manu size_t sz;
489 1.22 manu char *data;
490 1.22 manu int *retp;
491 1.22 manu
492 1.22 manu if (SCARG(uap, mask) == NULL)
493 1.22 manu return EINVAL;
494 1.22 manu
495 1.22 manu if (SCARG(uap, len) < sizeof(int))
496 1.22 manu return EINVAL;
497 1.22 manu
498 1.22 manu if (pfind(SCARG(uap, pid)) == NULL)
499 1.22 manu return ESRCH;
500 1.22 manu
501 1.22 manu /*
502 1.22 manu * return the actual number of CPU, tag all of them as available
503 1.22 manu * The result is a mask, the first CPU being in the least significant
504 1.22 manu * bit.
505 1.22 manu */
506 1.22 manu name[0] = CTL_HW;
507 1.22 manu name[1] = HW_NCPU;
508 1.22 manu sz = sizeof(ncpu);
509 1.22 manu
510 1.22 manu if ((error = old_sysctl(&name[0], 2, &ncpu, &sz, NULL, 0, NULL)) != 0)
511 1.22 manu return error;
512 1.22 manu
513 1.22 manu ret = (1 << ncpu) - 1;
514 1.22 manu
515 1.22 manu data = malloc(SCARG(uap, len), M_TEMP, M_WAITOK|M_ZERO);
516 1.22 manu retp = (int *)&data[SCARG(uap, len) - sizeof(ret)];
517 1.22 manu *retp = ret;
518 1.22 manu
519 1.22 manu if ((error = copyout(data, SCARG(uap, mask), SCARG(uap, len))) != 0)
520 1.22 manu return error;
521 1.22 manu
522 1.22 manu free(data, M_TEMP);
523 1.22 manu
524 1.22 manu return 0;
525 1.22 manu
526 1.22 manu }
527 1.22 manu
528 1.22 manu int
529 1.22 manu linux_sys_sched_setaffinity(l, v, retval)
530 1.22 manu struct lwp *l;
531 1.22 manu void *v;
532 1.22 manu register_t *retval;
533 1.22 manu {
534 1.22 manu struct linux_sys_sched_setaffinity_args /* {
535 1.22 manu syscallarg(pid_t) pid;
536 1.22 manu syscallarg(unsigned int) len;
537 1.22 manu syscallarg(unsigned long *) mask;
538 1.22 manu } */ *uap = v;
539 1.22 manu
540 1.22 manu if (pfind(SCARG(uap, pid)) == NULL)
541 1.22 manu return ESRCH;
542 1.22 manu
543 1.22 manu /* Let's ignore it */
544 1.22 manu #ifdef DEBUG_LINUX
545 1.22 manu printf("linux_sys_sched_setaffinity\n");
546 1.22 manu #endif
547 1.22 manu return 0;
548 1.22 manu };
549 1.23 manu #endif /* LINUX_NPTL */
550