From 76589fafd476824aadf83c79436658c43d68801c Mon Sep 17 00:00:00 2001 From: thorpej Date: Wed, 11 Oct 2000 17:27:58 +0000 Subject: [PATCH] - uvmspace_share(): If p2 has a vmspace already, make sure to deactivate it and free it as appropriate. Activate p2's new address space once it references p1's. - uvm_fork(): Make sure the child's vmspace is NULL before calling uvmspace_share() (the child doens't have one already in this case). These changes do not change the behavior for the current use of uvmspace_share() (vfork(2)), but make it possible for an already running process (such as a kernel thread) to properly attach to another process's address space. --- sys/uvm/uvm_glue.c | 7 ++++--- sys/uvm/uvm_map.c | 11 ++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/sys/uvm/uvm_glue.c b/sys/uvm/uvm_glue.c index 3a4947f45d29..19b1d819c2bd 100644 --- a/sys/uvm/uvm_glue.c +++ b/sys/uvm/uvm_glue.c @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_glue.c,v 1.41 2000/09/23 00:43:10 enami Exp $ */ +/* $NetBSD: uvm_glue.c,v 1.42 2000/10/11 17:27:59 thorpej Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -278,9 +278,10 @@ uvm_fork(p1, p2, shared, stack, stacksize, func, arg) struct user *up = p2->p_addr; int rv; - if (shared == TRUE) + if (shared == TRUE) { + p2->p_vmspace = NULL; uvmspace_share(p1, p2); /* share vmspace */ - else + } else p2->p_vmspace = uvmspace_fork(p1->p_vmspace); /* fork vmspace */ /* diff --git a/sys/uvm/uvm_map.c b/sys/uvm/uvm_map.c index 2e02cc2d9512..de35d928413d 100644 --- a/sys/uvm/uvm_map.c +++ b/sys/uvm/uvm_map.c @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_map.c,v 1.82 2000/10/11 17:21:11 thorpej Exp $ */ +/* $NetBSD: uvm_map.c,v 1.83 2000/10/11 17:27:58 thorpej Exp $ */ /* * Copyright (c) 1997 Charles D. Cranor and Washington University. @@ -2779,8 +2779,17 @@ void uvmspace_share(p1, p2) struct proc *p1, *p2; { + struct vmspace *ovm = p2->p_vmspace; + + if (ovm != NULL) + pmap_deactivate(p2); + p2->p_vmspace = p1->p_vmspace; p1->p_vmspace->vm_refcnt++; + pmap_activate(p2); + + if (ovm != NULL) + uvmspace_free(ovm); } /*