From owner-svn-src-stable@FreeBSD.ORG Wed Mar 2 19:36:06 2011 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 91277106566B; Wed, 2 Mar 2011 19:36:06 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 7D5D28FC0C; Wed, 2 Mar 2011 19:36:06 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id p22Ja6mB041410; Wed, 2 Mar 2011 19:36:06 GMT (envelope-from dchagin@svn.freebsd.org) Received: (from dchagin@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id p22Ja66I041400; Wed, 2 Mar 2011 19:36:06 GMT (envelope-from dchagin@svn.freebsd.org) Message-Id: <201103021936.p22Ja66I041400@svn.freebsd.org> From: Dmitry Chagin Date: Wed, 2 Mar 2011 19:36:06 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r219193 - in stable/8/sys: amd64/linux32 compat/linux conf i386/linux modules/linux X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 02 Mar 2011 19:36:06 -0000 Author: dchagin Date: Wed Mar 2 19:36:06 2011 New Revision: 219193 URL: http://svn.freebsd.org/changeset/base/219193 Log: MFC r218616: Move linux_clone(), linux_fork(), linux_vfork() to a MI path. Added: stable/8/sys/compat/linux/linux_fork.c - copied unchanged from r218616, head/sys/compat/linux/linux_fork.c Modified: stable/8/sys/amd64/linux32/linux.h stable/8/sys/amd64/linux32/linux32_machdep.c stable/8/sys/conf/files.amd64 stable/8/sys/conf/files.i386 stable/8/sys/conf/files.pc98 stable/8/sys/i386/linux/linux.h stable/8/sys/i386/linux/linux_machdep.c stable/8/sys/modules/linux/Makefile Directory Properties: stable/8/sys/ (props changed) stable/8/sys/amd64/include/xen/ (props changed) stable/8/sys/cddl/contrib/opensolaris/ (props changed) stable/8/sys/contrib/dev/acpica/ (props changed) stable/8/sys/contrib/pf/ (props changed) Modified: stable/8/sys/amd64/linux32/linux.h ============================================================================== --- stable/8/sys/amd64/linux32/linux.h Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/amd64/linux32/linux.h Wed Mar 2 19:36:06 2011 (r219193) @@ -921,5 +921,6 @@ struct linux_robust_list_head { }; int linux_set_upcall_kse(struct thread *td, register_t stack); +int linux_set_cloned_tls(struct thread *td, void *desc); #endif /* !_AMD64_LINUX_H_ */ Modified: stable/8/sys/amd64/linux32/linux32_machdep.c ============================================================================== --- stable/8/sys/amd64/linux32/linux32_machdep.c Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/amd64/linux32/linux32_machdep.c Wed Mar 2 19:36:06 2011 (r219193) @@ -409,94 +409,6 @@ linux_old_select(struct thread *td, stru } int -linux_fork(struct thread *td, struct linux_fork_args *args) -{ - int error; - struct proc *p2; - struct thread *td2; - -#ifdef DEBUG - if (ldebug(fork)) - printf(ARGS(fork, "")); -#endif - - if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) - return (error); - - if (error == 0) { - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - } - - if (td->td_retval[1] == 1) - td->td_retval[0] = 0; - error = linux_proc_init(td, td->td_retval[0], 0); - if (error) - return (error); - - td2 = FIRST_THREAD_IN_PROC(p2); - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - return (0); -} - -int -linux_vfork(struct thread *td, struct linux_vfork_args *args) -{ - int error; - struct proc *p2; - struct thread *td2; - -#ifdef DEBUG - if (ldebug(vfork)) - printf(ARGS(vfork, "")); -#endif - - /* Exclude RFPPWAIT */ - if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) - return (error); - if (error == 0) { - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - } - /* Are we the child? */ - if (td->td_retval[1] == 1) - td->td_retval[0] = 0; - error = linux_proc_init(td, td->td_retval[0], 0); - if (error) - return (error); - - PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; - PROC_UNLOCK(p2); - - td2 = FIRST_THREAD_IN_PROC(p2); - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - /* wait for the children to exit, ie. emulate vfork */ - PROC_LOCK(p2); - while (p2->p_flag & P_PPWAIT) - cv_wait(&p2->p_pwait, &p2->p_mtx); - PROC_UNLOCK(p2); - - return (0); -} - -static int linux_set_cloned_tls(struct thread *td, void *desc) { struct user_segment_descriptor sd; @@ -541,160 +453,6 @@ linux_set_cloned_tls(struct thread *td, } int -linux_clone(struct thread *td, struct linux_clone_args *args) -{ - int error, ff = RFPROC | RFSTOPPED; - struct proc *p2; - struct thread *td2; - int exit_signal; - struct linux_emuldata *em; - -#ifdef DEBUG - if (ldebug(clone)) { - printf(ARGS(clone, "flags %x, stack %p, parent tid: %p, " - "child tid: %p"), (unsigned)args->flags, - args->stack, args->parent_tidptr, args->child_tidptr); - } -#endif - - exit_signal = args->flags & 0x000000ff; - if (LINUX_SIG_VALID(exit_signal)) { - if (exit_signal <= LINUX_SIGTBLSZ) - exit_signal = - linux_to_bsd_signal[_SIG_IDX(exit_signal)]; - } else if (exit_signal != 0) - return (EINVAL); - - if (args->flags & LINUX_CLONE_VM) - ff |= RFMEM; - if (args->flags & LINUX_CLONE_SIGHAND) - ff |= RFSIGSHARE; - /* - * XXX: In Linux, sharing of fs info (chroot/cwd/umask) - * and open files is independant. In FreeBSD, its in one - * structure but in reality it does not cause any problems - * because both of these flags are usually set together. - */ - if (!(args->flags & (LINUX_CLONE_FILES | LINUX_CLONE_FS))) - ff |= RFFDG; - - /* - * Attempt to detect when linux_clone(2) is used for creating - * kernel threads. Unfortunately despite the existence of the - * CLONE_THREAD flag, version of linuxthreads package used in - * most popular distros as of beginning of 2005 doesn't make - * any use of it. Therefore, this detection relies on - * empirical observation that linuxthreads sets certain - * combination of flags, so that we can make more or less - * precise detection and notify the FreeBSD kernel that several - * processes are in fact part of the same threading group, so - * that special treatment is necessary for signal delivery - * between those processes and fd locking. - */ - if ((args->flags & 0xffffff00) == LINUX_THREADING_FLAGS) - ff |= RFTHREAD; - - if (args->flags & LINUX_CLONE_PARENT_SETTID) - if (args->parent_tidptr == NULL) - return (EINVAL); - - error = fork1(td, ff, 0, &p2); - if (error) - return (error); - - if (args->flags & (LINUX_CLONE_PARENT | LINUX_CLONE_THREAD)) { - sx_xlock(&proctree_lock); - PROC_LOCK(p2); - proc_reparent(p2, td->td_proc->p_pptr); - PROC_UNLOCK(p2); - sx_xunlock(&proctree_lock); - } - - /* create the emuldata */ - error = linux_proc_init(td, p2->p_pid, args->flags); - /* reference it - no need to check this */ - em = em_find(p2, EMUL_DOLOCK); - KASSERT(em != NULL, ("clone: emuldata not found.\n")); - /* and adjust it */ - - if (args->flags & LINUX_CLONE_THREAD) { -#ifdef notyet - PROC_LOCK(p2); - p2->p_pgrp = td->td_proc->p_pgrp; - PROC_UNLOCK(p2); -#endif - exit_signal = 0; - } - - if (args->flags & LINUX_CLONE_CHILD_SETTID) - em->child_set_tid = args->child_tidptr; - else - em->child_set_tid = NULL; - - if (args->flags & LINUX_CLONE_CHILD_CLEARTID) - em->child_clear_tid = args->child_tidptr; - else - em->child_clear_tid = NULL; - - EMUL_UNLOCK(&emul_lock); - - if (args->flags & LINUX_CLONE_PARENT_SETTID) { - error = copyout(&p2->p_pid, args->parent_tidptr, - sizeof(p2->p_pid)); - if (error) - printf(LMSG("copyout failed!")); - } - - PROC_LOCK(p2); - p2->p_sigparent = exit_signal; - PROC_UNLOCK(p2); - td2 = FIRST_THREAD_IN_PROC(p2); - /* - * In a case of stack = NULL, we are supposed to COW calling process - * stack. This is what normal fork() does, so we just keep tf_rsp arg - * intact. - */ - if (args->stack) - linux_set_upcall_kse(td2, PTROUT(args->stack)); - - if (args->flags & LINUX_CLONE_SETTLS) - linux_set_cloned_tls(td2, args->tls); - -#ifdef DEBUG - if (ldebug(clone)) - printf(LMSG("clone: successful rfork to %d, " - "stack %p sig = %d"), (int)p2->p_pid, args->stack, - exit_signal); -#endif - if (args->flags & LINUX_CLONE_VFORK) { - PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; - PROC_UNLOCK(p2); - } - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - - if (args->flags & LINUX_CLONE_VFORK) { - /* wait for the children to exit, ie. emulate vfork */ - PROC_LOCK(p2); - while (p2->p_flag & P_PPWAIT) - cv_wait(&p2->p_pwait, &p2->p_mtx); - PROC_UNLOCK(p2); - } - - return (0); -} - -int linux_set_upcall_kse(struct thread *td, register_t stack) { Copied: stable/8/sys/compat/linux/linux_fork.c (from r218616, head/sys/compat/linux/linux_fork.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ stable/8/sys/compat/linux/linux_fork.c Wed Mar 2 19:36:06 2011 (r219193, copy of r218616, head/sys/compat/linux/linux_fork.c) @@ -0,0 +1,297 @@ +/*- + * Copyright (c) 2004 Tim J. Robbins + * Copyright (c) 2002 Doug Rabson + * Copyright (c) 2000 Marcel Moolenaar + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer + * in this position and unchanged. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include "opt_compat.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#ifdef COMPAT_LINUX32 +#include +#include +#else +#include +#include +#endif +#include +#include + + +int +linux_fork(struct thread *td, struct linux_fork_args *args) +{ + int error; + struct proc *p2; + struct thread *td2; + +#ifdef DEBUG + if (ldebug(fork)) + printf(ARGS(fork, "")); +#endif + + if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) + return (error); + + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } + + if (td->td_retval[1] == 1) + td->td_retval[0] = 0; + error = linux_proc_init(td, td->td_retval[0], 0); + if (error) + return (error); + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + return (0); +} + +int +linux_vfork(struct thread *td, struct linux_vfork_args *args) +{ + int error; + struct proc *p2; + struct thread *td2; + +#ifdef DEBUG + if (ldebug(vfork)) + printf(ARGS(vfork, "")); +#endif + + /* Exclude RFPPWAIT */ + if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) + return (error); + if (error == 0) { + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + } + /* Are we the child? */ + if (td->td_retval[1] == 1) + td->td_retval[0] = 0; + error = linux_proc_init(td, td->td_retval[0], 0); + if (error) + return (error); + + PROC_LOCK(p2); + p2->p_flag |= P_PPWAIT; + PROC_UNLOCK(p2); + + td2 = FIRST_THREAD_IN_PROC(p2); + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + /* wait for the children to exit, ie. emulate vfork */ + PROC_LOCK(p2); + while (p2->p_flag & P_PPWAIT) + cv_wait(&p2->p_pwait, &p2->p_mtx); + PROC_UNLOCK(p2); + + return (0); +} + +int +linux_clone(struct thread *td, struct linux_clone_args *args) +{ + int error, ff = RFPROC | RFSTOPPED; + struct proc *p2; + struct thread *td2; + int exit_signal; + struct linux_emuldata *em; + +#ifdef DEBUG + if (ldebug(clone)) { + printf(ARGS(clone, "flags %x, stack %p, parent tid: %p, " + "child tid: %p"), (unsigned)args->flags, + args->stack, args->parent_tidptr, args->child_tidptr); + } +#endif + + exit_signal = args->flags & 0x000000ff; + if (LINUX_SIG_VALID(exit_signal)) { + if (exit_signal <= LINUX_SIGTBLSZ) + exit_signal = + linux_to_bsd_signal[_SIG_IDX(exit_signal)]; + } else if (exit_signal != 0) + return (EINVAL); + + if (args->flags & LINUX_CLONE_VM) + ff |= RFMEM; + if (args->flags & LINUX_CLONE_SIGHAND) + ff |= RFSIGSHARE; + /* + * XXX: In Linux, sharing of fs info (chroot/cwd/umask) + * and open files is independant. In FreeBSD, its in one + * structure but in reality it does not cause any problems + * because both of these flags are usually set together. + */ + if (!(args->flags & (LINUX_CLONE_FILES | LINUX_CLONE_FS))) + ff |= RFFDG; + + /* + * Attempt to detect when linux_clone(2) is used for creating + * kernel threads. Unfortunately despite the existence of the + * CLONE_THREAD flag, version of linuxthreads package used in + * most popular distros as of beginning of 2005 doesn't make + * any use of it. Therefore, this detection relies on + * empirical observation that linuxthreads sets certain + * combination of flags, so that we can make more or less + * precise detection and notify the FreeBSD kernel that several + * processes are in fact part of the same threading group, so + * that special treatment is necessary for signal delivery + * between those processes and fd locking. + */ + if ((args->flags & 0xffffff00) == LINUX_THREADING_FLAGS) + ff |= RFTHREAD; + + if (args->flags & LINUX_CLONE_PARENT_SETTID) + if (args->parent_tidptr == NULL) + return (EINVAL); + + error = fork1(td, ff, 0, &p2); + if (error) + return (error); + + if (args->flags & (LINUX_CLONE_PARENT | LINUX_CLONE_THREAD)) { + sx_xlock(&proctree_lock); + PROC_LOCK(p2); + proc_reparent(p2, td->td_proc->p_pptr); + PROC_UNLOCK(p2); + sx_xunlock(&proctree_lock); + } + + /* create the emuldata */ + error = linux_proc_init(td, p2->p_pid, args->flags); + /* reference it - no need to check this */ + em = em_find(p2, EMUL_DOLOCK); + KASSERT(em != NULL, ("clone: emuldata not found.")); + /* and adjust it */ + + if (args->flags & LINUX_CLONE_THREAD) { +#ifdef notyet + PROC_LOCK(p2); + p2->p_pgrp = td->td_proc->p_pgrp; + PROC_UNLOCK(p2); +#endif + exit_signal = 0; + } + + if (args->flags & LINUX_CLONE_CHILD_SETTID) + em->child_set_tid = args->child_tidptr; + else + em->child_set_tid = NULL; + + if (args->flags & LINUX_CLONE_CHILD_CLEARTID) + em->child_clear_tid = args->child_tidptr; + else + em->child_clear_tid = NULL; + + EMUL_UNLOCK(&emul_lock); + + if (args->flags & LINUX_CLONE_PARENT_SETTID) { + error = copyout(&p2->p_pid, args->parent_tidptr, + sizeof(p2->p_pid)); + if (error) + printf(LMSG("copyout failed!")); + } + + PROC_LOCK(p2); + p2->p_sigparent = exit_signal; + PROC_UNLOCK(p2); + td2 = FIRST_THREAD_IN_PROC(p2); + /* + * In a case of stack = NULL, we are supposed to COW calling process + * stack. This is what normal fork() does, so we just keep tf_rsp arg + * intact. + */ + if (args->stack) + linux_set_upcall_kse(td2, PTROUT(args->stack)); + + if (args->flags & LINUX_CLONE_SETTLS) + linux_set_cloned_tls(td2, args->tls); + +#ifdef DEBUG + if (ldebug(clone)) + printf(LMSG("clone: successful rfork to %d, " + "stack %p sig = %d"), (int)p2->p_pid, args->stack, + exit_signal); +#endif + if (args->flags & LINUX_CLONE_VFORK) { + PROC_LOCK(p2); + p2->p_flag |= P_PPWAIT; + PROC_UNLOCK(p2); + } + + /* + * Make this runnable after we are finished with it. + */ + thread_lock(td2); + TD_SET_CAN_RUN(td2); + sched_add(td2, SRQ_BORING); + thread_unlock(td2); + + td->td_retval[0] = p2->p_pid; + td->td_retval[1] = 0; + + if (args->flags & LINUX_CLONE_VFORK) { + /* wait for the children to exit, ie. emulate vfork */ + PROC_LOCK(p2); + while (p2->p_flag & P_PPWAIT) + cv_wait(&p2->p_pwait, &p2->p_mtx); + PROC_UNLOCK(p2); + } + + return (0); +} Modified: stable/8/sys/conf/files.amd64 ============================================================================== --- stable/8/sys/conf/files.amd64 Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/conf/files.amd64 Wed Mar 2 19:36:06 2011 (r219193) @@ -266,6 +266,7 @@ amd64/linux32/linux32_sysent.c optional amd64/linux32/linux32_sysvec.c optional compat_linux32 compat/linux/linux_emul.c optional compat_linux32 compat/linux/linux_file.c optional compat_linux32 +compat/linux/linux_fork.c optional compat_linux32 compat/linux/linux_futex.c optional compat_linux32 compat/linux/linux_getcwd.c optional compat_linux32 compat/linux/linux_ioctl.c optional compat_linux32 Modified: stable/8/sys/conf/files.i386 ============================================================================== --- stable/8/sys/conf/files.i386 Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/conf/files.i386 Wed Mar 2 19:36:06 2011 (r219193) @@ -71,6 +71,7 @@ compat/linprocfs/linprocfs.c optional li compat/linsysfs/linsysfs.c optional linsysfs compat/linux/linux_emul.c optional compat_linux compat/linux/linux_file.c optional compat_linux +compat/linux/linux_fork.c optional compat_linux compat/linux/linux_futex.c optional compat_linux compat/linux/linux_getcwd.c optional compat_linux compat/linux/linux_ioctl.c optional compat_linux Modified: stable/8/sys/conf/files.pc98 ============================================================================== --- stable/8/sys/conf/files.pc98 Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/conf/files.pc98 Wed Mar 2 19:36:06 2011 (r219193) @@ -42,6 +42,7 @@ compat/linprocfs/linprocfs.c optional li compat/linsysfs/linsysfs.c optional linsysfs compat/linux/linux_emul.c optional compat_linux compat/linux/linux_file.c optional compat_linux +compat/linux/linux_fork.c optional compat_linux compat/linux/linux_futex.c optional compat_linux compat/linux/linux_getcwd.c optional compat_linux compat/linux/linux_ioctl.c optional compat_linux Modified: stable/8/sys/i386/linux/linux.h ============================================================================== --- stable/8/sys/i386/linux/linux.h Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/i386/linux/linux.h Wed Mar 2 19:36:06 2011 (r219193) @@ -881,5 +881,6 @@ struct linux_robust_list_head { }; int linux_set_upcall_kse(struct thread *td, register_t stack); +int linux_set_cloned_tls(struct thread *td, void *desc); #endif /* !_I386_LINUX_H_ */ Modified: stable/8/sys/i386/linux/linux_machdep.c ============================================================================== --- stable/8/sys/i386/linux/linux_machdep.c Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/i386/linux/linux_machdep.c Wed Mar 2 19:36:06 2011 (r219193) @@ -300,94 +300,6 @@ linux_old_select(struct thread *td, stru } int -linux_fork(struct thread *td, struct linux_fork_args *args) -{ - int error; - struct proc *p2; - struct thread *td2; - -#ifdef DEBUG - if (ldebug(fork)) - printf(ARGS(fork, "")); -#endif - - if ((error = fork1(td, RFFDG | RFPROC | RFSTOPPED, 0, &p2)) != 0) - return (error); - - if (error == 0) { - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - } - - if (td->td_retval[1] == 1) - td->td_retval[0] = 0; - error = linux_proc_init(td, td->td_retval[0], 0); - if (error) - return (error); - - td2 = FIRST_THREAD_IN_PROC(p2); - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - return (0); -} - -int -linux_vfork(struct thread *td, struct linux_vfork_args *args) -{ - int error; - struct proc *p2; - struct thread *td2; - -#ifdef DEBUG - if (ldebug(vfork)) - printf(ARGS(vfork, "")); -#endif - - /* exclude RFPPWAIT */ - if ((error = fork1(td, RFFDG | RFPROC | RFMEM | RFSTOPPED, 0, &p2)) != 0) - return (error); - if (error == 0) { - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - } - /* Are we the child? */ - if (td->td_retval[1] == 1) - td->td_retval[0] = 0; - error = linux_proc_init(td, td->td_retval[0], 0); - if (error) - return (error); - - PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; - PROC_UNLOCK(p2); - - td2 = FIRST_THREAD_IN_PROC(p2); - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - /* wait for the children to exit, ie. emulate vfork */ - PROC_LOCK(p2); - while (p2->p_flag & P_PPWAIT) - cv_wait(&p2->p_pwait, &p2->p_mtx); - PROC_UNLOCK(p2); - - return (0); -} - -static int linux_set_cloned_tls(struct thread *td, void *desc) { struct segment_descriptor sd; @@ -444,160 +356,6 @@ linux_set_cloned_tls(struct thread *td, } int -linux_clone(struct thread *td, struct linux_clone_args *args) -{ - int error, ff = RFPROC | RFSTOPPED; - struct proc *p2; - struct thread *td2; - int exit_signal; - struct linux_emuldata *em; - -#ifdef DEBUG - if (ldebug(clone)) { - printf(ARGS(clone, "flags %x, stack %x, parent tid: %x, child tid: %x"), - (unsigned int)args->flags, (unsigned int)args->stack, - (unsigned int)args->parent_tidptr, (unsigned int)args->child_tidptr); - } -#endif - - exit_signal = args->flags & 0x000000ff; - if (LINUX_SIG_VALID(exit_signal)) { - if (exit_signal <= LINUX_SIGTBLSZ) - exit_signal = - linux_to_bsd_signal[_SIG_IDX(exit_signal)]; - } else if (exit_signal != 0) - return (EINVAL); - - if (args->flags & LINUX_CLONE_VM) - ff |= RFMEM; - if (args->flags & LINUX_CLONE_SIGHAND) - ff |= RFSIGSHARE; - /* - * XXX: in linux sharing of fs info (chroot/cwd/umask) - * and open files is independant. in fbsd its in one - * structure but in reality it doesn't cause any problems - * because both of these flags are usually set together. - */ - if (!(args->flags & (LINUX_CLONE_FILES | LINUX_CLONE_FS))) - ff |= RFFDG; - - /* - * Attempt to detect when linux_clone(2) is used for creating - * kernel threads. Unfortunately despite the existence of the - * CLONE_THREAD flag, version of linuxthreads package used in - * most popular distros as of beginning of 2005 doesn't make - * any use of it. Therefore, this detection relies on - * empirical observation that linuxthreads sets certain - * combination of flags, so that we can make more or less - * precise detection and notify the FreeBSD kernel that several - * processes are in fact part of the same threading group, so - * that special treatment is necessary for signal delivery - * between those processes and fd locking. - */ - if ((args->flags & 0xffffff00) == LINUX_THREADING_FLAGS) - ff |= RFTHREAD; - - if (args->flags & LINUX_CLONE_PARENT_SETTID) - if (args->parent_tidptr == NULL) - return (EINVAL); - - error = fork1(td, ff, 0, &p2); - if (error) - return (error); - - if (args->flags & (LINUX_CLONE_PARENT | LINUX_CLONE_THREAD)) { - sx_xlock(&proctree_lock); - PROC_LOCK(p2); - proc_reparent(p2, td->td_proc->p_pptr); - PROC_UNLOCK(p2); - sx_xunlock(&proctree_lock); - } - - /* create the emuldata */ - error = linux_proc_init(td, p2->p_pid, args->flags); - /* reference it - no need to check this */ - em = em_find(p2, EMUL_DOLOCK); - KASSERT(em != NULL, ("clone: emuldata not found.\n")); - /* and adjust it */ - - if (args->flags & LINUX_CLONE_THREAD) { - /* XXX: linux mangles pgrp and pptr somehow - * I think it might be this but I am not sure. - */ -#ifdef notyet - PROC_LOCK(p2); - p2->p_pgrp = td->td_proc->p_pgrp; - PROC_UNLOCK(p2); -#endif - exit_signal = 0; - } - - if (args->flags & LINUX_CLONE_CHILD_SETTID) - em->child_set_tid = args->child_tidptr; - else - em->child_set_tid = NULL; - - if (args->flags & LINUX_CLONE_CHILD_CLEARTID) - em->child_clear_tid = args->child_tidptr; - else - em->child_clear_tid = NULL; - - EMUL_UNLOCK(&emul_lock); - - if (args->flags & LINUX_CLONE_PARENT_SETTID) { - error = copyout(&p2->p_pid, args->parent_tidptr, sizeof(p2->p_pid)); - if (error) - printf(LMSG("copyout failed!")); - } - - PROC_LOCK(p2); - p2->p_sigparent = exit_signal; - PROC_UNLOCK(p2); - td2 = FIRST_THREAD_IN_PROC(p2); - /* - * in a case of stack = NULL we are supposed to COW calling process stack - * this is what normal fork() does so we just keep the tf_esp arg intact - */ - if (args->stack) - linux_set_upcall_kse(td2, PTROUT(args->stack)); - - if (args->flags & LINUX_CLONE_SETTLS) - linux_set_cloned_tls(td2, args->tls); - -#ifdef DEBUG - if (ldebug(clone)) - printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"), - (long)p2->p_pid, args->stack, exit_signal); -#endif - if (args->flags & LINUX_CLONE_VFORK) { - PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; - PROC_UNLOCK(p2); - } - - /* - * Make this runnable after we are finished with it. - */ - thread_lock(td2); - TD_SET_CAN_RUN(td2); - sched_add(td2, SRQ_BORING); - thread_unlock(td2); - - td->td_retval[0] = p2->p_pid; - td->td_retval[1] = 0; - - if (args->flags & LINUX_CLONE_VFORK) { - /* wait for the children to exit, ie. emulate vfork */ - PROC_LOCK(p2); - while (p2->p_flag & P_PPWAIT) - cv_wait(&p2->p_pwait, &p2->p_mtx); - PROC_UNLOCK(p2); - } - - return (0); -} - -int linux_set_upcall_kse(struct thread *td, register_t stack) { Modified: stable/8/sys/modules/linux/Makefile ============================================================================== --- stable/8/sys/modules/linux/Makefile Wed Mar 2 19:33:46 2011 (r219192) +++ stable/8/sys/modules/linux/Makefile Wed Mar 2 19:36:06 2011 (r219193) @@ -8,7 +8,7 @@ CFLAGS+=-DCOMPAT_FREEBSD32 -DCOMPAT_LINU .PATH: ${.CURDIR}/../../compat/linux ${.CURDIR}/../../${MACHINE_ARCH}/linux${SFX} KMOD= linux -SRCS= linux${SFX}_dummy.c linux_emul.c linux_file.c \ +SRCS= linux_fork.c linux${SFX}_dummy.c linux_emul.c linux_file.c \ linux_futex.c linux_getcwd.c linux_ioctl.c linux_ipc.c \ linux${SFX}_machdep.c linux_mib.c linux_misc.c linux_signal.c \ linux_socket.c linux_stats.c linux_sysctl.c linux${SFX}_sysent.c \