PERFORCE change 113097 for review
Roman Divacky
rdivacky at FreeBSD.org
Thu Jan 18 09:30:11 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=113097
Change 113097 by rdivacky at rdivacky_witten on 2007/01/18 09:29:19
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]
Affected files ...
.. //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#23 edit
.. //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#16 edit
Differences ...
==== //depot/projects/linuxolator/src/sys/amd64/linux32/linux32_machdep.c#23 (text+ko) ====
@@ -474,14 +474,21 @@
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;
@@ -489,6 +496,14 @@
if (error)
return (error);
+ td2 = FIRST_THREAD_IN_PROC(p2);
+
+ /* make it run */
+ mtx_lock_spin(&sched_lock);
+ TD_SET_CAN_RUN(td2);
+ setrunqueue(td2, SRQ_BORING);
+ mtx_unlock_spin(&sched_lock);
+
return (0);
}
@@ -497,6 +512,7 @@
{
int error;
struct proc *p2;
+ struct thread *td2;
#ifdef DEBUG
if (ldebug(vfork))
@@ -504,7 +520,7 @@
#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;
@@ -516,12 +532,23 @@
error = linux_proc_init(td, td->td_retval[0], 0);
if (error)
return (error);
+
+ p2->p_flag |= P_PPWAIT;
+
+ td2 = FIRST_THREAD_IN_PROC(p2);
+
+ /* make it run */
+ 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);
- p2->p_flag |= P_PPWAIT;
while (p2->p_flag & P_PPWAIT)
msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0);
PROC_UNLOCK(p2);
+
return (0);
}
@@ -682,6 +709,8 @@
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)
+ p2->p_flag |= P_PPWAIT;
/*
* Make this runnable after we are finished with it.
@@ -697,7 +726,6 @@
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);
==== //depot/projects/linuxolator/src/sys/i386/linux/linux_machdep.c#16 (text+ko) ====
@@ -297,14 +297,21 @@
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,14 @@
if (error)
return (error);
+ td2 = FIRST_THREAD_IN_PROC(p2);
+
+ /* make it run */
+ mtx_lock_spin(&sched_lock);
+ TD_SET_CAN_RUN(td2);
+ setrunqueue(td2, SRQ_BORING);
+ mtx_unlock_spin(&sched_lock);
+
return (0);
}
@@ -320,6 +335,7 @@
{
int error;
struct proc *p2;
+ struct thread *td2;
#ifdef DEBUG
if (ldebug(vfork))
@@ -327,10 +343,10 @@
#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 +355,19 @@
error = linux_proc_init(td, td->td_retval[0], 0);
if (error)
return (error);
+
+ p2->p_flag |= P_PPWAIT;
+
+ td2 = FIRST_THREAD_IN_PROC(p2);
+
+ /* make it run */
+ 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);
- p2->p_flag |= P_PPWAIT;
while (p2->p_flag & P_PPWAIT)
msleep(td->td_proc, &p2->p_mtx, PWAIT, "ppwait", 0);
PROC_UNLOCK(p2);
@@ -520,6 +546,8 @@
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)
+ p2->p_flag |= P_PPWAIT;
/*
* Make this runnable after we are finished with it.
@@ -535,7 +563,6 @@
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);
More information about the p4-projects
mailing list