From a322314f51419cd72f20b45ff9c3679a41904258 Mon Sep 17 00:00:00 2001 From: thorpej Date: Wed, 31 Dec 1997 07:47:41 +0000 Subject: [PATCH] Split out the code that prepares a VM space for exec into a new vmspace_exec() function. --- sys/kern/kern_exec.c | 23 +++++++++-------------- sys/vm/vm_extern.h | 3 ++- sys/vm/vm_map.c | 29 ++++++++++++++++++++++++++++- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/sys/kern/kern_exec.c b/sys/kern/kern_exec.c index 7fca768ebf1b..3ebab485a3b2 100644 --- a/sys/kern/kern_exec.c +++ b/sys/kern/kern_exec.c @@ -1,4 +1,4 @@ -/* $NetBSD: kern_exec.c,v 1.85 1997/09/11 23:02:32 mycroft Exp $ */ +/* $NetBSD: kern_exec.c,v 1.86 1997/12/31 07:47:44 thorpej Exp $ */ /*- * Copyright (C) 1993, 1994, 1996 Christopher G. Demetriou @@ -224,7 +224,7 @@ sys_execve(p, v, retval) size_t len; char *stack; struct ps_strings arginfo; - struct vmspace *vm = p->p_vmspace; + struct vmspace *vm; char **tmpfap; int szsigcode; extern struct emul emul_netbsd; @@ -357,20 +357,15 @@ sys_execve(p, v, retval) /* adjust "active stack depth" for process VSZ */ pack.ep_ssize = len; /* maybe should go elsewhere, but... */ - /* Unmap old program */ - /* XXX cgd 960926: the sparc #ifdef should be a MD hook */ -#ifdef sparc - kill_user_windows(p); /* before stack addresses go away */ -#endif - /* Kill shared memory and unmap old program */ -#ifdef SYSVSHM - if (vm->vm_shm) - shmexit(p); -#endif - vm_deallocate(&vm->vm_map, VM_MIN_ADDRESS, - VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS); + /* + * Do whatever is necessary to prepare the address space + * for remapping. Note that this might replace the current + * vmspace with another! + */ + vmspace_exec(p); /* Now map address space */ + vm = p->p_vmspace; vm->vm_taddr = (char *) pack.ep_taddr; vm->vm_tsize = btoc(pack.ep_tsize); vm->vm_daddr = (char *) pack.ep_daddr; diff --git a/sys/vm/vm_extern.h b/sys/vm/vm_extern.h index 97c38eef1c1c..405442c204c7 100644 --- a/sys/vm/vm_extern.h +++ b/sys/vm/vm_extern.h @@ -1,4 +1,4 @@ -/* $NetBSD: vm_extern.h,v 1.27 1997/08/27 02:35:38 mrg Exp $ */ +/* $NetBSD: vm_extern.h,v 1.28 1997/12/31 07:47:41 thorpej Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -132,6 +132,7 @@ void vm_set_page_size __P((void)); void vmmeter __P((void)); struct vmspace *vmspace_alloc __P((vm_offset_t, vm_offset_t, int)); struct vmspace *vmspace_fork __P((struct vmspace *)); +void vmspace_exec __P((struct proc *)); void vmspace_free __P((struct vmspace *)); void vmtotal __P((struct vmtotal *)); void vnode_pager_setsize __P((struct vnode *, u_quad_t)); diff --git a/sys/vm/vm_map.c b/sys/vm/vm_map.c index 00d96b34a9ee..0ad48cf64d0d 100644 --- a/sys/vm/vm_map.c +++ b/sys/vm/vm_map.c @@ -1,4 +1,4 @@ -/* $NetBSD: vm_map.c,v 1.29 1997/10/16 23:29:26 christos Exp $ */ +/* $NetBSD: vm_map.c,v 1.30 1997/12/31 07:47:42 thorpej Exp $ */ /* * Copyright (c) 1991, 1993 @@ -72,6 +72,10 @@ #include #include +#ifdef SYSVSHM +#include +#endif + #include #include #include @@ -201,6 +205,29 @@ vmspace_alloc(min, max, pageable) return (vm); } +/* + * Perform operations on VM space that need to happen during exec. + */ +void +vmspace_exec(p) + struct proc *p; +{ + struct vmspace *ovm = p->p_vmspace; + vm_map_t map = &ovm->vm_map; + +#ifdef sparc + /* XXX cgd 960926: the sparc #ifdef should be a MD hook */ + kill_user_windows(p); /* before stack addresses go away */ +#endif + /* Kill shared memory and unmap old program. */ +#ifdef SYSVSHM + if (ovm->vm_shm) + shmexit(p); +#endif + vm_deallocate(map, VM_MIN_ADDRESS, + VM_MAXUSER_ADDRESS - VM_MIN_ADDRESS); +} + void vmspace_free(vm) register struct vmspace *vm;