Home | History | Annotate | Line # | Download | only in common
linux_sched.c revision 1.12.2.3
      1  1.12.2.3     skrll /*	$NetBSD: linux_sched.c,v 1.12.2.3 2005/11/10 14:01:07 skrll 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.12.2.3     skrll __KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.12.2.3 2005/11/10 14:01:07 skrll 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.12.2.3     skrll #include <sys/sysctl.h>
     52  1.12.2.3     skrll #include <sys/malloc.h>
     53      1.12   thorpej #include <sys/sa.h>
     54  1.12.2.3     skrll #include <sys/savar.h>
     55       1.1      tron #include <sys/syscallargs.h>
     56  1.12.2.1     skrll #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.12.2.3     skrll #include <compat/linux/common/linux_exec.h>
     62       1.1      tron #include <compat/linux/common/linux_signal.h>
     63  1.12.2.3     skrll #include <compat/linux/common/linux_machdep.h> /* For LINUX_NPTL */
     64  1.12.2.3     skrll #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.12.2.3     skrll #ifdef LINUX_NPTL
     80  1.12.2.3     skrll 		syscallarg(void *) parent_tidptr;
     81  1.12.2.3     skrll 		syscallarg(void *) child_tidptr;
     82  1.12.2.3     skrll #endif
     83       1.1      tron 	} */ *uap = v;
     84       1.1      tron 	int flags, sig;
     85  1.12.2.3     skrll 	int error;
     86  1.12.2.3     skrll #ifdef LINUX_NPTL
     87  1.12.2.3     skrll 	struct linux_emuldata *led;
     88  1.12.2.3     skrll #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.12.2.1     skrll 	/*
     97  1.12.2.1     skrll 	 * Thread group implies shared signals. Shared signals
     98  1.12.2.1     skrll 	 * imply shared VM. This matches what Linux kernel does.
     99  1.12.2.1     skrll 	 */
    100  1.12.2.1     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_THREAD
    101  1.12.2.1     skrll 	    && (SCARG(uap, flags) & LINUX_CLONE_SIGHAND) == 0)
    102  1.12.2.1     skrll 		return (EINVAL);
    103  1.12.2.1     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_SIGHAND
    104  1.12.2.1     skrll 	    && (SCARG(uap, flags) & LINUX_CLONE_VM) == 0)
    105  1.12.2.1     skrll 		return (EINVAL);
    106  1.12.2.1     skrll 
    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.1      tron 	sig = SCARG(uap, flags) & LINUX_CLONE_CSIGNAL;
    121       1.4      tron 	if (sig < 0 || sig >= LINUX__NSIG)
    122       1.1      tron 		return (EINVAL);
    123      1.10  christos 	sig = linux_to_native_signo[sig];
    124       1.1      tron 
    125  1.12.2.3     skrll #ifdef LINUX_NPTL
    126  1.12.2.3     skrll 	led = (struct linux_emuldata *)l->l_proc->p_emuldata;
    127  1.12.2.3     skrll 
    128  1.12.2.3     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_PARENT_SETTID) {
    129  1.12.2.3     skrll 		if (SCARG(uap, parent_tidptr) == NULL) {
    130  1.12.2.3     skrll 			printf("linux_sys_clone: NULL parent_tidptr\n");
    131  1.12.2.3     skrll 			return EINVAL;
    132  1.12.2.3     skrll 		}
    133  1.12.2.3     skrll 
    134  1.12.2.3     skrll 		if ((error = copyout(&l->l_proc->p_pid,
    135  1.12.2.3     skrll 		    SCARG(uap, parent_tidptr),
    136  1.12.2.3     skrll 		    sizeof(l->l_proc->p_pid))) != 0)
    137  1.12.2.3     skrll 			return error;
    138  1.12.2.3     skrll 	}
    139  1.12.2.3     skrll 
    140  1.12.2.3     skrll 	/* CLONE_CHILD_CLEARTID: TID clear in the child on exit() */
    141  1.12.2.3     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_CHILD_CLEARTID)
    142  1.12.2.3     skrll 		led->child_clear_tid = SCARG(uap, child_tidptr);
    143  1.12.2.3     skrll 	else
    144  1.12.2.3     skrll 		led->child_clear_tid = NULL;
    145  1.12.2.3     skrll 
    146  1.12.2.3     skrll 	/* CLONE_CHILD_SETTID: TID set in the child on clone() */
    147  1.12.2.3     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_CHILD_SETTID)
    148  1.12.2.3     skrll 		led->child_set_tid = SCARG(uap, child_tidptr);
    149  1.12.2.3     skrll 	else
    150  1.12.2.3     skrll 		led->child_set_tid = NULL;
    151  1.12.2.3     skrll 
    152  1.12.2.3     skrll 	/* CLONE_SETTLS: new Thread Local Storage in the child */
    153  1.12.2.3     skrll 	if (SCARG(uap, flags) & LINUX_CLONE_SETTLS)
    154  1.12.2.3     skrll 		led->set_tls = linux_get_newtls(l);
    155  1.12.2.3     skrll 	else
    156  1.12.2.3     skrll 		led->set_tls = 0;
    157  1.12.2.3     skrll #endif /* LINUX_NPTL */
    158       1.1      tron 	/*
    159       1.1      tron 	 * Note that Linux does not provide a portable way of specifying
    160       1.1      tron 	 * the stack area; the caller must know if the stack grows up
    161       1.1      tron 	 * or down.  So, we pass a stack size of 0, so that the code
    162       1.1      tron 	 * that makes this adjustment is a noop.
    163       1.1      tron 	 */
    164  1.12.2.3     skrll 	if ((error = fork1(l, flags, sig, SCARG(uap, stack), 0,
    165  1.12.2.3     skrll 	    NULL, NULL, retval, NULL)) != 0)
    166  1.12.2.3     skrll 		return error;
    167  1.12.2.3     skrll 
    168  1.12.2.3     skrll 	return 0;
    169       1.1      tron }
    170       1.1      tron 
    171       1.1      tron int
    172      1.12   thorpej linux_sys_sched_setparam(cl, v, retval)
    173      1.12   thorpej 	struct lwp *cl;
    174       1.1      tron 	void *v;
    175       1.1      tron 	register_t *retval;
    176       1.1      tron {
    177       1.1      tron 	struct linux_sys_sched_setparam_args /* {
    178       1.1      tron 		syscallarg(linux_pid_t) pid;
    179       1.1      tron 		syscallarg(const struct linux_sched_param *) sp;
    180       1.1      tron 	} */ *uap = v;
    181      1.12   thorpej 	struct proc *cp = cl->l_proc;
    182       1.1      tron 	int error;
    183       1.1      tron 	struct linux_sched_param lp;
    184       1.5  augustss 	struct proc *p;
    185       1.1      tron 
    186       1.1      tron /*
    187       1.1      tron  * We only check for valid parameters and return afterwards.
    188       1.1      tron  */
    189       1.1      tron 
    190       1.1      tron 	if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
    191       1.1      tron 		return EINVAL;
    192       1.1      tron 
    193       1.1      tron 	error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
    194       1.1      tron 	if (error)
    195       1.1      tron 		return error;
    196       1.1      tron 
    197       1.1      tron 	if (SCARG(uap, pid) != 0) {
    198       1.5  augustss 		struct pcred *pc = cp->p_cred;
    199       1.1      tron 
    200       1.1      tron 		if ((p = pfind(SCARG(uap, pid))) == NULL)
    201       1.1      tron 			return ESRCH;
    202       1.1      tron 		if (!(cp == p ||
    203       1.1      tron 		      pc->pc_ucred->cr_uid == 0 ||
    204       1.1      tron 		      pc->p_ruid == p->p_cred->p_ruid ||
    205       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
    206       1.1      tron 		      pc->p_ruid == p->p_ucred->cr_uid ||
    207       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
    208       1.1      tron 			return EPERM;
    209       1.1      tron 	}
    210       1.1      tron 
    211       1.1      tron 	return 0;
    212       1.1      tron }
    213       1.1      tron 
    214       1.1      tron int
    215      1.12   thorpej linux_sys_sched_getparam(cl, v, retval)
    216      1.12   thorpej 	struct lwp *cl;
    217       1.1      tron 	void *v;
    218       1.1      tron 	register_t *retval;
    219       1.1      tron {
    220       1.1      tron 	struct linux_sys_sched_getparam_args /* {
    221       1.1      tron 		syscallarg(linux_pid_t) pid;
    222       1.1      tron 		syscallarg(struct linux_sched_param *) sp;
    223       1.1      tron 	} */ *uap = v;
    224      1.12   thorpej 	struct proc *cp = cl->l_proc;
    225       1.5  augustss 	struct proc *p;
    226       1.1      tron 	struct linux_sched_param lp;
    227       1.1      tron 
    228       1.1      tron /*
    229       1.1      tron  * We only check for valid parameters and return a dummy priority afterwards.
    230       1.1      tron  */
    231       1.1      tron 	if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
    232       1.1      tron 		return EINVAL;
    233       1.1      tron 
    234       1.1      tron 	if (SCARG(uap, pid) != 0) {
    235       1.5  augustss 		struct pcred *pc = cp->p_cred;
    236       1.1      tron 
    237       1.1      tron 		if ((p = pfind(SCARG(uap, pid))) == NULL)
    238       1.1      tron 			return ESRCH;
    239       1.1      tron 		if (!(cp == p ||
    240       1.1      tron 		      pc->pc_ucred->cr_uid == 0 ||
    241       1.1      tron 		      pc->p_ruid == p->p_cred->p_ruid ||
    242       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
    243       1.1      tron 		      pc->p_ruid == p->p_ucred->cr_uid ||
    244       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
    245       1.1      tron 			return EPERM;
    246       1.1      tron 	}
    247       1.1      tron 
    248       1.1      tron 	lp.sched_priority = 0;
    249       1.1      tron 	return copyout(&lp, SCARG(uap, sp), sizeof(lp));
    250       1.1      tron }
    251       1.1      tron 
    252       1.1      tron int
    253      1.12   thorpej linux_sys_sched_setscheduler(cl, v, retval)
    254      1.12   thorpej 	struct lwp *cl;
    255       1.1      tron 	void *v;
    256       1.1      tron 	register_t *retval;
    257       1.1      tron {
    258       1.1      tron 	struct linux_sys_sched_setscheduler_args /* {
    259       1.1      tron 		syscallarg(linux_pid_t) pid;
    260       1.1      tron 		syscallarg(int) policy;
    261       1.1      tron 		syscallarg(cont struct linux_sched_scheduler *) sp;
    262       1.1      tron 	} */ *uap = v;
    263      1.12   thorpej 	struct proc *cp = cl->l_proc;
    264       1.1      tron 	int error;
    265       1.1      tron 	struct linux_sched_param lp;
    266       1.5  augustss 	struct proc *p;
    267       1.1      tron 
    268       1.1      tron /*
    269       1.1      tron  * We only check for valid parameters and return afterwards.
    270       1.1      tron  */
    271       1.1      tron 
    272       1.1      tron 	if (SCARG(uap, pid) < 0 || SCARG(uap, sp) == NULL)
    273       1.1      tron 		return EINVAL;
    274       1.1      tron 
    275       1.1      tron 	error = copyin(SCARG(uap, sp), &lp, sizeof(lp));
    276       1.1      tron 	if (error)
    277       1.1      tron 		return error;
    278       1.1      tron 
    279       1.1      tron 	if (SCARG(uap, pid) != 0) {
    280       1.5  augustss 		struct pcred *pc = cp->p_cred;
    281       1.1      tron 
    282       1.1      tron 		if ((p = pfind(SCARG(uap, pid))) == NULL)
    283       1.1      tron 			return ESRCH;
    284       1.1      tron 		if (!(cp == p ||
    285       1.1      tron 		      pc->pc_ucred->cr_uid == 0 ||
    286       1.1      tron 		      pc->p_ruid == p->p_cred->p_ruid ||
    287       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
    288       1.1      tron 		      pc->p_ruid == p->p_ucred->cr_uid ||
    289       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
    290       1.1      tron 			return EPERM;
    291       1.1      tron 	}
    292       1.1      tron 
    293       1.1      tron /*
    294       1.1      tron  * We can't emulate anything put the default scheduling policy.
    295       1.1      tron  */
    296       1.1      tron 	if (SCARG(uap, policy) != LINUX_SCHED_OTHER || lp.sched_priority != 0)
    297       1.1      tron 		return EINVAL;
    298       1.1      tron 
    299       1.1      tron 	return 0;
    300       1.1      tron }
    301       1.1      tron 
    302       1.1      tron int
    303      1.12   thorpej linux_sys_sched_getscheduler(cl, v, retval)
    304      1.12   thorpej 	struct lwp *cl;
    305       1.1      tron 	void *v;
    306       1.1      tron 	register_t *retval;
    307       1.1      tron {
    308       1.1      tron 	struct linux_sys_sched_getscheduler_args /* {
    309       1.1      tron 		syscallarg(linux_pid_t) pid;
    310       1.1      tron 	} */ *uap = v;
    311      1.12   thorpej 	struct proc *cp = cl->l_proc;
    312       1.5  augustss 	struct proc *p;
    313       1.1      tron 
    314       1.1      tron 	*retval = -1;
    315       1.1      tron /*
    316       1.1      tron  * We only check for valid parameters and return afterwards.
    317       1.1      tron  */
    318       1.1      tron 
    319       1.1      tron 	if (SCARG(uap, pid) != 0) {
    320       1.5  augustss 		struct pcred *pc = cp->p_cred;
    321       1.1      tron 
    322       1.1      tron 		if ((p = pfind(SCARG(uap, pid))) == NULL)
    323       1.1      tron 			return ESRCH;
    324       1.1      tron 		if (!(cp == p ||
    325       1.1      tron 		      pc->pc_ucred->cr_uid == 0 ||
    326       1.1      tron 		      pc->p_ruid == p->p_cred->p_ruid ||
    327       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_cred->p_ruid ||
    328       1.1      tron 		      pc->p_ruid == p->p_ucred->cr_uid ||
    329       1.1      tron 		      pc->pc_ucred->cr_uid == p->p_ucred->cr_uid))
    330       1.1      tron 			return EPERM;
    331       1.1      tron 	}
    332       1.1      tron 
    333       1.1      tron /*
    334       1.1      tron  * We can't emulate anything put the default scheduling policy.
    335       1.1      tron  */
    336       1.1      tron 	*retval = LINUX_SCHED_OTHER;
    337       1.1      tron 	return 0;
    338       1.1      tron }
    339       1.1      tron 
    340       1.1      tron int
    341      1.12   thorpej linux_sys_sched_yield(cl, v, retval)
    342      1.12   thorpej 	struct lwp *cl;
    343       1.1      tron 	void *v;
    344       1.1      tron 	register_t *retval;
    345       1.1      tron {
    346      1.11  gmcgarry 
    347      1.11  gmcgarry 	yield();
    348       1.1      tron 	return 0;
    349       1.1      tron }
    350       1.1      tron 
    351       1.1      tron int
    352      1.12   thorpej linux_sys_sched_get_priority_max(cl, v, retval)
    353      1.12   thorpej 	struct lwp *cl;
    354       1.1      tron 	void *v;
    355       1.1      tron 	register_t *retval;
    356       1.1      tron {
    357       1.1      tron 	struct linux_sys_sched_get_priority_max_args /* {
    358       1.1      tron 		syscallarg(int) policy;
    359       1.1      tron 	} */ *uap = v;
    360       1.1      tron 
    361       1.1      tron /*
    362       1.1      tron  * We can't emulate anything put the default scheduling policy.
    363       1.1      tron  */
    364       1.1      tron 	if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
    365       1.1      tron 		*retval = -1;
    366       1.1      tron 		return EINVAL;
    367       1.1      tron 	}
    368       1.1      tron 
    369       1.1      tron 	*retval = 0;
    370       1.1      tron 	return 0;
    371       1.1      tron }
    372       1.1      tron 
    373       1.1      tron int
    374      1.12   thorpej linux_sys_sched_get_priority_min(cl, v, retval)
    375      1.12   thorpej 	struct lwp *cl;
    376       1.1      tron 	void *v;
    377       1.1      tron 	register_t *retval;
    378       1.1      tron {
    379       1.1      tron 	struct linux_sys_sched_get_priority_min_args /* {
    380       1.1      tron 		syscallarg(int) policy;
    381       1.1      tron 	} */ *uap = v;
    382       1.1      tron 
    383       1.1      tron /*
    384       1.1      tron  * We can't emulate anything put the default scheduling policy.
    385       1.1      tron  */
    386       1.1      tron 	if (SCARG(uap, policy) != LINUX_SCHED_OTHER) {
    387       1.1      tron 		*retval = -1;
    388       1.1      tron 		return EINVAL;
    389       1.1      tron 	}
    390       1.1      tron 
    391       1.1      tron 	*retval = 0;
    392       1.1      tron 	return 0;
    393       1.1      tron }
    394  1.12.2.1     skrll 
    395  1.12.2.1     skrll #ifndef __m68k__
    396  1.12.2.1     skrll /* Present on everything but m68k */
    397  1.12.2.1     skrll int
    398  1.12.2.1     skrll linux_sys_exit_group(l, v, retval)
    399  1.12.2.1     skrll 	struct lwp *l;
    400  1.12.2.1     skrll 	void *v;
    401  1.12.2.1     skrll 	register_t *retval;
    402  1.12.2.1     skrll {
    403  1.12.2.1     skrll 	struct linux_sys_exit_group_args /* {
    404  1.12.2.1     skrll 		syscallarg(int) error_code;
    405  1.12.2.1     skrll 	} */ *uap = v;
    406  1.12.2.3     skrll 	struct proc *p;
    407  1.12.2.3     skrll 	struct linux_emuldata *led;
    408  1.12.2.3     skrll 	pid_t group_pid;
    409  1.12.2.1     skrll 
    410  1.12.2.1     skrll 	/*
    411  1.12.2.3     skrll 	 * The calling thread is supposed to kill all threads
    412  1.12.2.1     skrll 	 * in the same thread group (i.e. all threads created
    413  1.12.2.3     skrll 	 * via clone(2) with CLONE_THREAD flag set).
    414  1.12.2.1     skrll 	 */
    415  1.12.2.3     skrll 	led = l->l_proc->p_emuldata;
    416  1.12.2.3     skrll 	group_pid = led->s->group_pid;
    417  1.12.2.3     skrll 	PROCLIST_FOREACH(p, &allproc) {
    418  1.12.2.3     skrll 		if (p->p_emul != &emul_linux)
    419  1.12.2.3     skrll 			continue;
    420  1.12.2.3     skrll 
    421  1.12.2.3     skrll 		if (p == l->l_proc)
    422  1.12.2.3     skrll 			continue;
    423  1.12.2.3     skrll 
    424  1.12.2.3     skrll 		led = p->p_emuldata;
    425  1.12.2.3     skrll 		if (led->s->group_pid == group_pid) {
    426  1.12.2.3     skrll 			/* XXX we should exit, not send a SIGKILL */
    427  1.12.2.3     skrll 			psignal(p, SIGKILL);
    428  1.12.2.3     skrll 		}
    429  1.12.2.3     skrll 	}
    430  1.12.2.1     skrll 
    431  1.12.2.1     skrll 	exit1(l, W_EXITCODE(SCARG(uap, error_code), 0));
    432  1.12.2.1     skrll 	/* NOTREACHED */
    433  1.12.2.1     skrll 	return 0;
    434  1.12.2.1     skrll }
    435  1.12.2.1     skrll #endif /* !__m68k__ */
    436  1.12.2.3     skrll 
    437  1.12.2.3     skrll #ifdef LINUX_NPTL
    438  1.12.2.3     skrll int
    439  1.12.2.3     skrll linux_sys_set_tid_address(l, v, retval)
    440  1.12.2.3     skrll 	struct lwp *l;
    441  1.12.2.3     skrll 	void *v;
    442  1.12.2.3     skrll 	register_t *retval;
    443  1.12.2.3     skrll {
    444  1.12.2.3     skrll 	struct linux_sys_set_tid_address_args /* {
    445  1.12.2.3     skrll 		syscallarg(int *) tidptr;
    446  1.12.2.3     skrll 	} */ *uap = v;
    447  1.12.2.3     skrll 	struct linux_emuldata *led;
    448  1.12.2.3     skrll 
    449  1.12.2.3     skrll 	led = (struct linux_emuldata *)l->l_proc->p_emuldata;
    450  1.12.2.3     skrll 	led->clear_tid = SCARG(uap, tid);
    451  1.12.2.3     skrll 
    452  1.12.2.3     skrll 	*retval = l->l_proc->p_pid;
    453  1.12.2.3     skrll 
    454  1.12.2.3     skrll 	return 0;
    455  1.12.2.3     skrll }
    456  1.12.2.3     skrll 
    457  1.12.2.3     skrll /* ARGUSED1 */
    458  1.12.2.3     skrll int
    459  1.12.2.3     skrll linux_sys_gettid(l, v, retval)
    460  1.12.2.3     skrll 	struct lwp *l;
    461  1.12.2.3     skrll 	void *v;
    462  1.12.2.3     skrll 	register_t *retval;
    463  1.12.2.3     skrll {
    464  1.12.2.3     skrll 	*retval = l->l_proc->p_pid;
    465  1.12.2.3     skrll 	return 0;
    466  1.12.2.3     skrll }
    467  1.12.2.3     skrll 
    468  1.12.2.3     skrll int
    469  1.12.2.3     skrll linux_sys_sched_getaffinity(l, v, retval)
    470  1.12.2.3     skrll 	struct lwp *l;
    471  1.12.2.3     skrll 	void *v;
    472  1.12.2.3     skrll 	register_t *retval;
    473  1.12.2.3     skrll {
    474  1.12.2.3     skrll 	struct linux_sys_sched_getaffinity_args /* {
    475  1.12.2.3     skrll 		syscallarg(pid_t) pid;
    476  1.12.2.3     skrll 		syscallarg(unsigned int) len;
    477  1.12.2.3     skrll 		syscallarg(unsigned long *) mask;
    478  1.12.2.3     skrll 	} */ *uap = v;
    479  1.12.2.3     skrll 	int error;
    480  1.12.2.3     skrll 	int ret;
    481  1.12.2.3     skrll 	int ncpu;
    482  1.12.2.3     skrll 	int name[2];
    483  1.12.2.3     skrll 	size_t sz;
    484  1.12.2.3     skrll 	char *data;
    485  1.12.2.3     skrll 	int *retp;
    486  1.12.2.3     skrll 
    487  1.12.2.3     skrll 	if (SCARG(uap, mask) == NULL)
    488  1.12.2.3     skrll 		return EINVAL;
    489  1.12.2.3     skrll 
    490  1.12.2.3     skrll 	if (SCARG(uap, len) < sizeof(int))
    491  1.12.2.3     skrll 		return EINVAL;
    492  1.12.2.3     skrll 
    493  1.12.2.3     skrll 	if (pfind(SCARG(uap, pid)) == NULL)
    494  1.12.2.3     skrll 		return ESRCH;
    495  1.12.2.3     skrll 
    496  1.12.2.3     skrll 	/*
    497  1.12.2.3     skrll 	 * return the actual number of CPU, tag all of them as available
    498  1.12.2.3     skrll 	 * The result is a mask, the first CPU being in the least significant
    499  1.12.2.3     skrll 	 * bit.
    500  1.12.2.3     skrll 	 */
    501  1.12.2.3     skrll 	name[0] = CTL_HW;
    502  1.12.2.3     skrll 	name[1] = HW_NCPU;
    503  1.12.2.3     skrll 	sz = sizeof(ncpu);
    504  1.12.2.3     skrll 
    505  1.12.2.3     skrll 	if ((error = old_sysctl(&name[0], 2, &ncpu, &sz, NULL, 0, NULL)) != 0)
    506  1.12.2.3     skrll 		return error;
    507  1.12.2.3     skrll 
    508  1.12.2.3     skrll 	ret = (1 << ncpu) - 1;
    509  1.12.2.3     skrll 
    510  1.12.2.3     skrll 	data = malloc(SCARG(uap, len), M_TEMP, M_WAITOK|M_ZERO);
    511  1.12.2.3     skrll 	retp = (int *)&data[SCARG(uap, len) - sizeof(ret)];
    512  1.12.2.3     skrll 	*retp = ret;
    513  1.12.2.3     skrll 
    514  1.12.2.3     skrll 	if ((error = copyout(data, SCARG(uap, mask), SCARG(uap, len))) != 0)
    515  1.12.2.3     skrll 		return error;
    516  1.12.2.3     skrll 
    517  1.12.2.3     skrll 	free(data, M_TEMP);
    518  1.12.2.3     skrll 
    519  1.12.2.3     skrll 	return 0;
    520  1.12.2.3     skrll 
    521  1.12.2.3     skrll }
    522  1.12.2.3     skrll 
    523  1.12.2.3     skrll int
    524  1.12.2.3     skrll linux_sys_sched_setaffinity(l, v, retval)
    525  1.12.2.3     skrll 	struct lwp *l;
    526  1.12.2.3     skrll 	void *v;
    527  1.12.2.3     skrll 	register_t *retval;
    528  1.12.2.3     skrll {
    529  1.12.2.3     skrll 	struct linux_sys_sched_setaffinity_args /* {
    530  1.12.2.3     skrll 		syscallarg(pid_t) pid;
    531  1.12.2.3     skrll 		syscallarg(unsigned int) len;
    532  1.12.2.3     skrll 		syscallarg(unsigned long *) mask;
    533  1.12.2.3     skrll 	} */ *uap = v;
    534  1.12.2.3     skrll 
    535  1.12.2.3     skrll 	if (pfind(SCARG(uap, pid)) == NULL)
    536  1.12.2.3     skrll 		return ESRCH;
    537  1.12.2.3     skrll 
    538  1.12.2.3     skrll 	/* Let's ignore it */
    539  1.12.2.3     skrll #ifdef DEBUG_LINUX
    540  1.12.2.3     skrll 	printf("linux_sys_sched_setaffinity\n");
    541  1.12.2.3     skrll #endif
    542  1.12.2.3     skrll 	return 0;
    543  1.12.2.3     skrll };
    544  1.12.2.3     skrll #endif /* LINUX_NPTL */
    545