From 42392e7a0b343fe5280991684011be7f99879d3f Mon Sep 17 00:00:00 2001 From: netchild Date: Sat, 20 Jan 2007 14:58:59 +0000 Subject: 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 --- sys/compat/linux/linux_emul.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) (limited to 'sys/compat/linux/linux_emul.c') diff --git a/sys/compat/linux/linux_emul.c b/sys/compat/linux/linux_emul.c index a06e231..70e6887 100644 --- a/sys/compat/linux/linux_emul.c +++ b/sys/compat/linux/linux_emul.c @@ -91,17 +91,12 @@ linux_proc_init(struct thread *td, pid_t child, int flags) struct linux_emuldata_shared *s; s = malloc(sizeof *s, M_LINUX, M_WAITOK | M_ZERO); - em->shared = s; s->refs = 1; s->group_pid = child; LIST_INIT(&s->threads); + em->shared = s; } - p = pfind(child); - KASSERT(p != NULL, ("process not found in proc_init\n")); - p->p_emuldata = em; - PROC_UNLOCK(p); - EMUL_LOCK(&emul_lock); } else { /* lookup the old one */ em = em_find(td->td_proc, EMUL_DOLOCK); @@ -120,11 +115,12 @@ linux_proc_init(struct thread *td, pid_t child, int flags) if (flags & CLONE_THREAD) { /* lookup the parent */ EMUL_SHARED_WLOCK(&emul_shared_lock); - p_em = em_find(td->td_proc, EMUL_DONTLOCK); + p_em = em_find(td->td_proc, EMUL_DOLOCK); KASSERT(p_em != NULL, ("proc_init: parent emuldata not found for CLONE_THREAD\n")); em->shared = p_em->shared; em->shared->refs++; EMUL_SHARED_WUNLOCK(&emul_shared_lock); + EMUL_UNLOCK(&emul_lock); } else { /* * handled earlier to avoid malloc(M_WAITOK) with @@ -133,12 +129,13 @@ linux_proc_init(struct thread *td, pid_t child, int flags) } } if (child != 0) { - EMUL_UNLOCK(&emul_lock); EMUL_SHARED_WLOCK(&emul_shared_lock); LIST_INSERT_HEAD(&em->shared->threads, em, threads); EMUL_SHARED_WUNLOCK(&emul_shared_lock); p = pfind(child); + KASSERT(p != NULL, ("process not found in proc_init\n")); + p->p_emuldata = em; /* we might have a sleeping linux_schedtail */ wakeup(&p->p_emuldata); PROC_UNLOCK(p); -- cgit v1.1