summaryrefslogtreecommitdiffstats
path: root/sys/i386
diff options
context:
space:
mode:
authordchagin <dchagin@FreeBSD.org>2011-02-12 18:17:12 +0000
committerdchagin <dchagin@FreeBSD.org>2011-02-12 18:17:12 +0000
commit9f708ad0aa73636aa198ed08a3a8a2b3e776197c (patch)
tree4a71aeb972cbaf16dfb39a6211de31ee24619e56 /sys/i386
parenta999d3553b8c6d5ba61c9b15cb3ac797ad448aee (diff)
downloadFreeBSD-src-9f708ad0aa73636aa198ed08a3a8a2b3e776197c.zip
FreeBSD-src-9f708ad0aa73636aa198ed08a3a8a2b3e776197c.tar.gz
Move linux_clone(), linux_fork(), linux_vfork() to a MI path.
Diffstat (limited to 'sys/i386')
-rw-r--r--sys/i386/linux/linux.h1
-rw-r--r--sys/i386/linux/linux_machdep.c242
2 files changed, 1 insertions, 242 deletions
diff --git a/sys/i386/linux/linux.h b/sys/i386/linux/linux.h
index b9e3f27..08f0fbd 100644
--- a/sys/i386/linux/linux.h
+++ b/sys/i386/linux/linux.h
@@ -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_ */
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c
index 6af39d2..d1f6ab9 100644
--- a/sys/i386/linux/linux_machdep.c
+++ b/sys/i386/linux/linux_machdep.c
@@ -300,94 +300,6 @@ linux_old_select(struct thread *td, struct linux_old_select_args *args)
}
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, void *desc)
}
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)
{
OpenPOWER on IntegriCloud