diff options
author | netchild <netchild@FreeBSD.org> | 2007-01-20 14:58:59 +0000 |
---|---|---|
committer | netchild <netchild@FreeBSD.org> | 2007-01-20 14:58:59 +0000 |
commit | 42392e7a0b343fe5280991684011be7f99879d3f (patch) | |
tree | 735da62fdf6f010dbbbf89d9b4d09a061540de1a /sys/i386 | |
parent | de8f010827ae8f0e61df55a100777f1dddcb379d (diff) | |
download | FreeBSD-src-42392e7a0b343fe5280991684011be7f99879d3f.zip FreeBSD-src-42392e7a0b343fe5280991684011be7f99879d3f.tar.gz |
MFp4 (113077, 113083, 113103, 113124, 113097):
Dont expose em->shared to the outside world before its properly
initialized. Might not affect anything but its at least a better
coding style.
Dont expose em via p->p_emuldata until its properly initialized.
This also enables us to get rid of some locking and simplify the
code because we are workin on a local copy.
In linux_fork and linux_vfork create the process in stopped state
to be sure that the new process runs with fully initialized emuldata
structure [1]. Also fix the vfork (both in linux_clone and linux_vfork)
race that could result in never woken up process [2].
Reported by: Scot Hetzel [1]
Suggested by: jhb [2]
Reviewed by: jhb (at least some important parts)
Submitted by: rdivacky
Tested by: Scot Hetzel (on amd64)
Change 2 comments (in the new code) to comply to style(9).
Suggested by: jhb
Diffstat (limited to 'sys/i386')
-rw-r--r-- | sys/i386/linux/linux_machdep.c | 46 |
1 files changed, 41 insertions, 5 deletions
diff --git a/sys/i386/linux/linux_machdep.c b/sys/i386/linux/linux_machdep.c index 5b1f6b1..162180a 100644 --- a/sys/i386/linux/linux_machdep.c +++ b/sys/i386/linux/linux_machdep.c @@ -297,14 +297,21 @@ 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 = fork(td, (struct fork_args *)args)) != 0) + 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; @@ -312,6 +319,16 @@ linux_fork(struct thread *td, struct linux_fork_args *args) if (error) return (error); + td2 = FIRST_THREAD_IN_PROC(p2); + + /* + * Make this runnable after we are finished with it. + */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + return (0); } @@ -320,6 +337,7 @@ linux_vfork(struct thread *td, struct linux_vfork_args *args) { int error; struct proc *p2; + struct thread *td2; #ifdef DEBUG if (ldebug(vfork)) @@ -327,10 +345,10 @@ linux_vfork(struct thread *td, struct linux_vfork_args *args) #endif /* exclude RFPPWAIT */ - if ((error = fork1(td, RFFDG | RFPROC | RFMEM, 0, &p2)) != 0) + 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[0] = p2->p_pid; td->td_retval[1] = 0; } /* Are we the child? */ @@ -339,9 +357,23 @@ linux_vfork(struct thread *td, struct linux_vfork_args *args) error = linux_proc_init(td, td->td_retval[0], 0); if (error) return (error); - /* wait for the children to exit, ie. emulate vfork */ + 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. + */ + mtx_lock_spin(&sched_lock); + TD_SET_CAN_RUN(td2); + setrunqueue(td2, SRQ_BORING); + mtx_unlock_spin(&sched_lock); + + /* wait for the children to exit, ie. emulate vfork */ + PROC_LOCK(p2); while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2); @@ -523,6 +555,11 @@ linux_clone(struct thread *td, struct linux_clone_args *args) printf(LMSG("clone: successful rfork to %ld, stack %p sig = %d"), (long)p2->p_pid, args->stack, exit_signal); #endif + if (args->flags & CLONE_VFORK) { + PROC_LOCK(p2); + p2->p_flag |= P_PPWAIT; + PROC_UNLOCK(p2); + } /* * Make this runnable after we are finished with it. @@ -538,7 +575,6 @@ linux_clone(struct thread *td, struct linux_clone_args *args) if (args->flags & CLONE_VFORK) { /* wait for the children to exit, ie. emulate vfork */ PROC_LOCK(p2); - p2->p_flag |= P_PPWAIT; while (p2->p_flag & P_PPWAIT) msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0); PROC_UNLOCK(p2); |