linux_sched.c revision 1.47 1 1.47 elad /* $NetBSD: linux_sched.c,v 1.47 2008/01/23 15:04:39 elad 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.47 elad __KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.47 2008/01/23 15:04:39 elad 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.1 tron #include <sys/syscallargs.h>
54 1.14 jdolecek #include <sys/wait.h>
55 1.30 elad #include <sys/kauth.h>
56 1.34 manu #include <sys/ptrace.h>
57 1.3 itohy
58 1.43 ad #include <sys/cpu.h>
59 1.1 tron
60 1.1 tron #include <compat/linux/common/linux_types.h>
61 1.1 tron #include <compat/linux/common/linux_signal.h>
62 1.21 manu #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
63 1.19 manu #include <compat/linux/common/linux_emuldata.h>
64 1.44 njoly #include <compat/linux/common/linux_ipc.h>
65 1.44 njoly #include <compat/linux/common/linux_sem.h>
66 1.1 tron
67 1.1 tron #include <compat/linux/linux_syscallargs.h>
68 1.1 tron
69 1.1 tron #include <compat/linux/common/linux_sched.h>
70 1.1 tron
71 1.1 tron int
72 1.46 dsl linux_sys_clone(struct lwp *l, const struct linux_sys_clone_args *uap, register_t *retval)
73 1.1 tron {
74 1.46 dsl /* {
75 1.1 tron syscallarg(int) flags;
76 1.1 tron syscallarg(void *) stack;
77 1.21 manu #ifdef LINUX_NPTL
78 1.19 manu syscallarg(void *) parent_tidptr;
79 1.19 manu syscallarg(void *) child_tidptr;
80 1.19 manu #endif
81 1.46 dsl } */
82 1.1 tron int flags, sig;
83 1.19 manu int error;
84 1.21 manu #ifdef LINUX_NPTL
85 1.19 manu struct linux_emuldata *led;
86 1.19 manu #endif
87 1.1 tron
88 1.1 tron /*
89 1.1 tron * We don't support the Linux CLONE_PID or CLONE_PTRACE flags.
90 1.1 tron */
91 1.1 tron if (SCARG(uap, flags) & (LINUX_CLONE_PID|LINUX_CLONE_PTRACE))
92 1.1 tron return (EINVAL);
93 1.1 tron
94 1.13 jdolecek /*
95 1.13 jdolecek * Thread group implies shared signals. Shared signals
96 1.13 jdolecek * imply shared VM. This matches what Linux kernel does.
97 1.13 jdolecek */
98 1.13 jdolecek if (SCARG(uap, flags) & LINUX_CLONE_THREAD
99 1.13 jdolecek && (SCARG(uap, flags) & LINUX_CLONE_SIGHAND) == 0)
100 1.13 jdolecek return (EINVAL);
101 1.13 jdolecek if (SCARG(uap, flags) & LINUX_CLONE_SIGHAND
102 1.13 jdolecek && (SCARG(uap, flags) & LINUX_CLONE_VM) == 0)
103 1.13 jdolecek return (EINVAL);
104 1.13 jdolecek
105 1.1 tron flags = 0;
106 1.1 tron
107 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_VM)
108 1.1 tron flags |= FORK_SHAREVM;
109 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_FS)
110 1.1 tron flags |= FORK_SHARECWD;
111 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_FILES)
112 1.1 tron flags |= FORK_SHAREFILES;
113 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_SIGHAND)
114 1.1 tron flags |= FORK_SHARESIGS;
115 1.1 tron if (SCARG(uap, flags) & LINUX_CLONE_VFORK)
116 1.1 tron flags |= FORK_PPWAIT;
117 1.1 tron
118 1.34 manu sig = SCARG(uap, flags) & LINUX_CLONE_CSIGNAL;
119 1.34 manu if (sig < 0 || sig >= LINUX__NSIG)
120 1.34 manu return (EINVAL);
121 1.34 manu sig = linux_to_native_signo[sig];
122 1.1 tron
123 1.21 manu #ifdef LINUX_NPTL
124 1.19 manu led = (struct linux_emuldata *)l->l_proc->p_emuldata;
125 1.19 manu
126 1.34 manu led->parent_tidptr = SCARG(uap, parent_tidptr);
127 1.34 manu led->child_tidptr = SCARG(uap, child_tidptr);
128 1.34 manu led->clone_flags = SCARG(uap, flags);
129 1.34 manu #endif /* LINUX_NPTL */
130 1.19 manu
131 1.1 tron /*
132 1.1 tron * Note that Linux does not provide a portable way of specifying
133 1.1 tron * the stack area; the caller must know if the stack grows up
134 1.1 tron * or down. So, we pass a stack size of 0, so that the code
135 1.1 tron * that makes this adjustment is a noop.
136 1.1 tron */
137 1.19 manu if ((error = fork1(l, flags, sig, SCARG(uap, stack), 0,
138 1.19 manu NULL, NULL, retval, NULL)) != 0)
139 1.19 manu return error;
140 1.19 manu
141 1.19 manu return 0;
142 1.1 tron }
143 1.1 tron
144 1.1 tron int
145 1.46 dsl linux_sys_sched_setparam(struct lwp *l, const struct linux_sys_sched_setparam_args *uap, register_t *retval)
146 1.1 tron {
147 1.46 dsl /* {
148 1.1 tron syscallarg(linux_pid_t) pid;
149 1.1 tron syscallarg(const struct linux_sched_param *) sp;
150 1.46 dsl } */
151 1.1 tron int error;
152 1.1 tron struct linux_sched_param lp;
153 1.5 augustss struct proc *p;
154 1.1 tron
155 1.1 tron /*
156 1.1 tron * We only check for valid parameters and return afterwards.
157 1.1 tron */
158 1.1 tron
159 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
160 1.1 tron return EINVAL;
161 1.1 tron
162 1.1 tron error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
163 1.1 tron if (error)
164 1.1 tron return error;
165 1.1 tron
166 1.1 tron if (SCARG(uap, pid) != 0) {
167 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
168 1.1 tron return ESRCH;
169 1.47 elad
170 1.47 elad if (l->l_proc != p &&
171 1.47 elad kauth_authorize_process(l->l_cred, KAUTH_PROCESS_SCHEDULER,
172 1.47 elad p, KAUTH_ARG(KAUTH_REQ_PROCESS_SCHEDULER_SETPARAM), NULL,
173 1.47 elad &lp) != 0)
174 1.1 tron return EPERM;
175 1.1 tron }
176 1.1 tron
177 1.1 tron return 0;
178 1.1 tron }
179 1.1 tron
180 1.1 tron int
181 1.46 dsl linux_sys_sched_getparam(struct lwp *l, const struct linux_sys_sched_getparam_args *uap, register_t *retval)
182 1.1 tron {
183 1.46 dsl /* {
184 1.1 tron syscallarg(linux_pid_t) pid;
185 1.1 tron syscallarg(struct linux_sched_param *) sp;
186 1.46 dsl } */
187 1.5 augustss struct proc *p;
188 1.1 tron struct linux_sched_param lp;
189 1.1 tron
190 1.1 tron /*
191 1.1 tron * We only check for valid parameters and return a dummy priority afterwards.
192 1.1 tron */
193 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
194 1.1 tron return EINVAL;
195 1.1 tron
196 1.1 tron if (SCARG(uap, pid) != 0) {
197 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
198 1.1 tron return ESRCH;
199 1.47 elad
200 1.47 elad if (l->l_proc != p &&
201 1.47 elad kauth_authorize_process(l->l_cred, KAUTH_PROCESS_SCHEDULER,
202 1.47 elad p, KAUTH_ARG(KAUTH_REQ_PROCESS_SCHEDULER_GETPARAM), NULL,
203 1.47 elad NULL) != 0)
204 1.1 tron return EPERM;
205 1.1 tron }
206 1.1 tron
207 1.1 tron lp.sched_priority = 0;
208 1.1 tron return copyout(&lp, SCARG(uap, sp), sizeof(lp));
209 1.1 tron }
210 1.1 tron
211 1.1 tron int
212 1.46 dsl linux_sys_sched_setscheduler(struct lwp *l, const struct linux_sys_sched_setscheduler_args *uap, register_t *retval)
213 1.1 tron {
214 1.46 dsl /* {
215 1.1 tron syscallarg(linux_pid_t) pid;
216 1.1 tron syscallarg(int) policy;
217 1.1 tron syscallarg(cont struct linux_sched_scheduler *) sp;
218 1.46 dsl } */
219 1.1 tron int error;
220 1.1 tron struct linux_sched_param lp;
221 1.5 augustss struct proc *p;
222 1.1 tron
223 1.1 tron /*
224 1.1 tron * We only check for valid parameters and return afterwards.
225 1.1 tron */
226 1.1 tron
227 1.1 tron if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
228 1.1 tron return EINVAL;
229 1.1 tron
230 1.1 tron error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
231 1.1 tron if (error)
232 1.1 tron return error;
233 1.1 tron
234 1.1 tron if (SCARG(uap, pid) != 0) {
235 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
236 1.1 tron return ESRCH;
237 1.47 elad
238 1.47 elad if (l->l_proc != p &&
239 1.47 elad kauth_authorize_process(l->l_cred, KAUTH_PROCESS_SCHEDULER,
240 1.47 elad p, KAUTH_ARG(KAUTH_REQ_PROCESS_SCHEDULER_SET),
241 1.47 elad KAUTH_ARG(SCARG(uap, policy)), &lp) != 0)
242 1.1 tron return EPERM;
243 1.1 tron }
244 1.1 tron
245 1.34 manu return 0;
246 1.1 tron /*
247 1.1 tron * We can't emulate anything put the default scheduling policy.
248 1.1 tron */
249 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER || lp.sched_priority != 0)
250 1.1 tron return EINVAL;
251 1.1 tron
252 1.1 tron return 0;
253 1.1 tron }
254 1.1 tron
255 1.1 tron int
256 1.46 dsl linux_sys_sched_getscheduler(struct lwp *l, const struct linux_sys_sched_getscheduler_args *uap, register_t *retval)
257 1.1 tron {
258 1.46 dsl /* {
259 1.1 tron syscallarg(linux_pid_t) pid;
260 1.46 dsl } */
261 1.5 augustss struct proc *p;
262 1.1 tron
263 1.1 tron *retval = -1;
264 1.1 tron /*
265 1.1 tron * We only check for valid parameters and return afterwards.
266 1.1 tron */
267 1.1 tron
268 1.1 tron if (SCARG(uap, pid) != 0) {
269 1.1 tron if ((p = pfind(SCARG(uap, pid))) == NULL)
270 1.1 tron return ESRCH;
271 1.47 elad
272 1.47 elad if (l->l_proc != p &&
273 1.47 elad kauth_authorize_process(l->l_cred, KAUTH_PROCESS_SCHEDULER,
274 1.47 elad p, KAUTH_ARG(KAUTH_REQ_PROCESS_SCHEDULER_GET), NULL,
275 1.47 elad NULL) != 0)
276 1.1 tron return EPERM;
277 1.1 tron }
278 1.1 tron
279 1.1 tron /*
280 1.1 tron * We can't emulate anything put the default scheduling policy.
281 1.1 tron */
282 1.1 tron *retval = LINUX_SCHED_OTHER;
283 1.1 tron return 0;
284 1.1 tron }
285 1.1 tron
286 1.1 tron int
287 1.46 dsl linux_sys_sched_yield(struct lwp *l, const void *v, register_t *retval)
288 1.1 tron {
289 1.11 gmcgarry
290 1.11 gmcgarry yield();
291 1.1 tron return 0;
292 1.1 tron }
293 1.1 tron
294 1.1 tron int
295 1.46 dsl linux_sys_sched_get_priority_max(struct lwp *l, const struct linux_sys_sched_get_priority_max_args *uap, register_t *retval)
296 1.1 tron {
297 1.46 dsl /* {
298 1.1 tron syscallarg(int) policy;
299 1.46 dsl } */
300 1.1 tron
301 1.1 tron /*
302 1.1 tron * We can't emulate anything put the default scheduling policy.
303 1.1 tron */
304 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
305 1.1 tron *retval = -1;
306 1.1 tron return EINVAL;
307 1.1 tron }
308 1.1 tron
309 1.1 tron *retval = 0;
310 1.1 tron return 0;
311 1.1 tron }
312 1.1 tron
313 1.1 tron int
314 1.46 dsl linux_sys_sched_get_priority_min(struct lwp *l, const struct linux_sys_sched_get_priority_min_args *uap, register_t *retval)
315 1.1 tron {
316 1.46 dsl /* {
317 1.1 tron syscallarg(int) policy;
318 1.46 dsl } */
319 1.1 tron
320 1.1 tron /*
321 1.1 tron * We can't emulate anything put the default scheduling policy.
322 1.1 tron */
323 1.1 tron if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
324 1.1 tron *retval = -1;
325 1.1 tron return EINVAL;
326 1.1 tron }
327 1.1 tron
328 1.1 tron *retval = 0;
329 1.1 tron return 0;
330 1.1 tron }
331 1.14 jdolecek
332 1.14 jdolecek #ifndef __m68k__
333 1.14 jdolecek /* Present on everything but m68k */
334 1.14 jdolecek int
335 1.46 dsl linux_sys_exit_group(struct lwp *l, const struct linux_sys_exit_group_args *uap, register_t *retval)
336 1.14 jdolecek {
337 1.35 dogcow #ifdef LINUX_NPTL
338 1.46 dsl /* {
339 1.14 jdolecek syscallarg(int) error_code;
340 1.46 dsl } */
341 1.31 manu struct proc *p = l->l_proc;
342 1.31 manu struct linux_emuldata *led = p->p_emuldata;
343 1.31 manu struct linux_emuldata *e;
344 1.14 jdolecek
345 1.39 njoly if (led->s->flags & LINUX_LES_USE_NPTL) {
346 1.39 njoly
347 1.34 manu #ifdef DEBUG_LINUX
348 1.39 njoly printf("%s:%d, led->s->refs = %d\n", __func__, __LINE__,
349 1.39 njoly led->s->refs);
350 1.34 manu #endif
351 1.39 njoly
352 1.39 njoly /*
353 1.39 njoly * The calling thread is supposed to kill all threads
354 1.39 njoly * in the same thread group (i.e. all threads created
355 1.39 njoly * via clone(2) with CLONE_THREAD flag set).
356 1.39 njoly *
357 1.39 njoly * If there is only one thread, things are quite simple
358 1.39 njoly */
359 1.39 njoly if (led->s->refs == 1)
360 1.46 dsl return sys_exit(l, (const void *)uap, retval);
361 1.31 manu
362 1.31 manu #ifdef DEBUG_LINUX
363 1.39 njoly printf("%s:%d\n", __func__, __LINE__);
364 1.31 manu #endif
365 1.34 manu
366 1.39 njoly led->s->flags |= LINUX_LES_INEXITGROUP;
367 1.39 njoly led->s->xstat = W_EXITCODE(SCARG(uap, error_code), 0);
368 1.34 manu
369 1.39 njoly /*
370 1.39 njoly * Kill all threads in the group. The emulation exit hook takes
371 1.39 njoly * care of hiding the zombies and reporting the exit code
372 1.39 njoly * properly.
373 1.39 njoly */
374 1.41 ad mutex_enter(&proclist_mutex);
375 1.39 njoly LIST_FOREACH(e, &led->s->threads, threads) {
376 1.39 njoly if (e->proc == p)
377 1.39 njoly continue;
378 1.31 manu
379 1.34 manu #ifdef DEBUG_LINUX
380 1.39 njoly printf("%s: kill PID %d\n", __func__, e->proc->p_pid);
381 1.34 manu #endif
382 1.39 njoly psignal(e->proc, SIGKILL);
383 1.39 njoly }
384 1.39 njoly
385 1.39 njoly /* Now, kill ourselves */
386 1.39 njoly psignal(p, SIGKILL);
387 1.41 ad mutex_exit(&proclist_mutex);
388 1.41 ad
389 1.39 njoly return 0;
390 1.39 njoly
391 1.31 manu }
392 1.39 njoly #endif /* LINUX_NPTL */
393 1.14 jdolecek
394 1.46 dsl return sys_exit(l, (const void *)uap, retval);
395 1.14 jdolecek }
396 1.14 jdolecek #endif /* !__m68k__ */
397 1.19 manu
398 1.21 manu #ifdef LINUX_NPTL
399 1.19 manu int
400 1.46 dsl linux_sys_set_tid_address(struct lwp *l, const struct linux_sys_set_tid_address_args *uap, register_t *retval)
401 1.19 manu {
402 1.46 dsl /* {
403 1.19 manu syscallarg(int *) tidptr;
404 1.46 dsl } */
405 1.19 manu struct linux_emuldata *led;
406 1.19 manu
407 1.19 manu led = (struct linux_emuldata *)l->l_proc->p_emuldata;
408 1.19 manu led->clear_tid = SCARG(uap, tid);
409 1.19 manu
410 1.39 njoly led->s->flags |= LINUX_LES_USE_NPTL;
411 1.39 njoly
412 1.19 manu *retval = l->l_proc->p_pid;
413 1.19 manu
414 1.19 manu return 0;
415 1.19 manu }
416 1.20 manu
417 1.20 manu /* ARGUSED1 */
418 1.20 manu int
419 1.46 dsl linux_sys_gettid(struct lwp *l, const void *v, register_t *retval)
420 1.20 manu {
421 1.31 manu /* The Linux kernel does it exactly that way */
422 1.20 manu *retval = l->l_proc->p_pid;
423 1.20 manu return 0;
424 1.20 manu }
425 1.22 manu
426 1.31 manu #ifdef LINUX_NPTL
427 1.31 manu /* ARGUSED1 */
428 1.31 manu int
429 1.46 dsl linux_sys_getpid(struct lwp *l, const void *v, register_t *retval)
430 1.31 manu {
431 1.39 njoly struct linux_emuldata *led = l->l_proc->p_emuldata;
432 1.31 manu
433 1.39 njoly if (led->s->flags & LINUX_LES_USE_NPTL) {
434 1.39 njoly /* The Linux kernel does it exactly that way */
435 1.39 njoly *retval = led->s->group_pid;
436 1.39 njoly } else {
437 1.39 njoly *retval = l->l_proc->p_pid;
438 1.39 njoly }
439 1.31 manu
440 1.31 manu return 0;
441 1.31 manu }
442 1.31 manu
443 1.31 manu /* ARGUSED1 */
444 1.31 manu int
445 1.46 dsl linux_sys_getppid(struct lwp *l, const void *v, register_t *retval)
446 1.31 manu {
447 1.31 manu struct proc *p = l->l_proc;
448 1.31 manu struct linux_emuldata *led = p->p_emuldata;
449 1.31 manu struct proc *glp;
450 1.31 manu struct proc *pp;
451 1.31 manu
452 1.39 njoly if (led->s->flags & LINUX_LES_USE_NPTL) {
453 1.31 manu
454 1.39 njoly /* Find the thread group leader's parent */
455 1.39 njoly if ((glp = pfind(led->s->group_pid)) == NULL) {
456 1.39 njoly /* Maybe panic... */
457 1.39 njoly printf("linux_sys_getppid: missing group leader PID"
458 1.39 njoly " %d\n", led->s->group_pid);
459 1.39 njoly return -1;
460 1.39 njoly }
461 1.39 njoly pp = glp->p_pptr;
462 1.39 njoly
463 1.39 njoly /* If this is a Linux process too, return thread group PID */
464 1.39 njoly if (pp->p_emul == p->p_emul) {
465 1.39 njoly struct linux_emuldata *pled;
466 1.39 njoly
467 1.39 njoly pled = pp->p_emuldata;
468 1.39 njoly *retval = pled->s->group_pid;
469 1.39 njoly } else {
470 1.39 njoly *retval = pp->p_pid;
471 1.39 njoly }
472 1.31 manu
473 1.31 manu } else {
474 1.39 njoly *retval = p->p_pptr->p_pid;
475 1.31 manu }
476 1.31 manu
477 1.31 manu return 0;
478 1.31 manu }
479 1.31 manu #endif /* LINUX_NPTL */
480 1.31 manu
481 1.22 manu int
482 1.46 dsl linux_sys_sched_getaffinity(struct lwp *l, const struct linux_sys_sched_getaffinity_args *uap, register_t *retval)
483 1.22 manu {
484 1.46 dsl /* {
485 1.22 manu syscallarg(pid_t) pid;
486 1.22 manu syscallarg(unsigned int) len;
487 1.22 manu syscallarg(unsigned long *) mask;
488 1.46 dsl } */
489 1.22 manu int error;
490 1.22 manu int ret;
491 1.22 manu char *data;
492 1.22 manu int *retp;
493 1.22 manu
494 1.22 manu if (SCARG(uap, mask) == NULL)
495 1.22 manu return EINVAL;
496 1.22 manu
497 1.22 manu if (SCARG(uap, len) < sizeof(int))
498 1.22 manu return EINVAL;
499 1.22 manu
500 1.22 manu if (pfind(SCARG(uap, pid)) == NULL)
501 1.22 manu return ESRCH;
502 1.22 manu
503 1.22 manu /*
504 1.22 manu * return the actual number of CPU, tag all of them as available
505 1.22 manu * The result is a mask, the first CPU being in the least significant
506 1.22 manu * bit.
507 1.22 manu */
508 1.22 manu ret = (1 << ncpu) - 1;
509 1.22 manu data = malloc(SCARG(uap, len), M_TEMP, M_WAITOK|M_ZERO);
510 1.22 manu retp = (int *)&data[SCARG(uap, len) - sizeof(ret)];
511 1.22 manu *retp = ret;
512 1.22 manu
513 1.22 manu if ((error = copyout(data, SCARG(uap, mask), SCARG(uap, len))) != 0)
514 1.22 manu return error;
515 1.22 manu
516 1.22 manu free(data, M_TEMP);
517 1.22 manu
518 1.22 manu return 0;
519 1.22 manu
520 1.22 manu }
521 1.22 manu
522 1.22 manu int
523 1.46 dsl linux_sys_sched_setaffinity(struct lwp *l, const struct linux_sys_sched_setaffinity_args *uap, register_t *retval)
524 1.22 manu {
525 1.46 dsl /* {
526 1.22 manu syscallarg(pid_t) pid;
527 1.22 manu syscallarg(unsigned int) len;
528 1.22 manu syscallarg(unsigned long *) mask;
529 1.46 dsl } */
530 1.22 manu
531 1.22 manu if (pfind(SCARG(uap, pid)) == NULL)
532 1.22 manu return ESRCH;
533 1.22 manu
534 1.22 manu /* Let's ignore it */
535 1.22 manu #ifdef DEBUG_LINUX
536 1.22 manu printf("linux_sys_sched_setaffinity\n");
537 1.22 manu #endif
538 1.22 manu return 0;
539 1.22 manu };
540 1.23 manu #endif /* LINUX_NPTL */
541