Sat Jul 30 20:05:46 2011 UTC ()
Make uvmspace_exec() deal with procs that have no vmspace (yet) at all.
Greatly simplifies the upcoming posix_spawn implementation.


(martin)
diff -r1.301 -r1.302 src/sys/uvm/uvm_map.c

cvs diff -r1.301 -r1.302 src/sys/uvm/uvm_map.c (expand / switch to unified diff)

--- src/sys/uvm/uvm_map.c 2011/07/30 19:29:12 1.301
+++ src/sys/uvm/uvm_map.c 2011/07/30 20:05:46 1.302
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: uvm_map.c,v 1.301 2011/07/30 19:29:12 martin Exp $ */ 1/* $NetBSD: uvm_map.c,v 1.302 2011/07/30 20:05:46 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1997 Charles D. Cranor and Washington University. 4 * Copyright (c) 1997 Charles D. Cranor and Washington University.
5 * Copyright (c) 1991, 1993, The Regents of the University of California. 5 * Copyright (c) 1991, 1993, The Regents of the University of California.
6 * 6 *
7 * All rights reserved. 7 * All rights reserved.
8 * 8 *
9 * This code is derived from software contributed to Berkeley by 9 * This code is derived from software contributed to Berkeley by
10 * The Mach Operating System project at Carnegie-Mellon University. 10 * The Mach Operating System project at Carnegie-Mellon University.
11 * 11 *
12 * Redistribution and use in source and binary forms, with or without 12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions 13 * modification, are permitted provided that the following conditions
14 * are met: 14 * are met:
@@ -56,27 +56,27 @@ @@ -56,27 +56,27 @@
56 * School of Computer Science 56 * School of Computer Science
57 * Carnegie Mellon University 57 * Carnegie Mellon University
58 * Pittsburgh PA 15213-3890 58 * Pittsburgh PA 15213-3890
59 * 59 *
60 * any improvements or extensions that they make and grant Carnegie the 60 * any improvements or extensions that they make and grant Carnegie the
61 * rights to redistribute these changes. 61 * rights to redistribute these changes.
62 */ 62 */
63 63
64/* 64/*
65 * uvm_map.c: uvm map operations 65 * uvm_map.c: uvm map operations
66 */ 66 */
67 67
68#include <sys/cdefs.h> 68#include <sys/cdefs.h>
69__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.301 2011/07/30 19:29:12 martin Exp $"); 69__KERNEL_RCSID(0, "$NetBSD: uvm_map.c,v 1.302 2011/07/30 20:05:46 martin Exp $");
70 70
71#include "opt_ddb.h" 71#include "opt_ddb.h"
72#include "opt_uvmhist.h" 72#include "opt_uvmhist.h"
73#include "opt_uvm.h" 73#include "opt_uvm.h"
74#include "opt_sysv.h" 74#include "opt_sysv.h"
75 75
76#include <sys/param.h> 76#include <sys/param.h>
77#include <sys/systm.h> 77#include <sys/systm.h>
78#include <sys/mman.h> 78#include <sys/mman.h>
79#include <sys/proc.h> 79#include <sys/proc.h>
80#include <sys/malloc.h> 80#include <sys/malloc.h>
81#include <sys/pool.h> 81#include <sys/pool.h>
82#include <sys/kernel.h> 82#include <sys/kernel.h>
@@ -4174,33 +4174,44 @@ uvmspace_unshare(struct lwp *l) @@ -4174,33 +4174,44 @@ uvmspace_unshare(struct lwp *l)
4174} 4174}
4175 4175
4176#endif 4176#endif
4177 4177
4178/* 4178/*
4179 * uvmspace_exec: the process wants to exec a new program 4179 * uvmspace_exec: the process wants to exec a new program
4180 */ 4180 */
4181 4181
4182void 4182void
4183uvmspace_exec(struct lwp *l, vaddr_t start, vaddr_t end) 4183uvmspace_exec(struct lwp *l, vaddr_t start, vaddr_t end)
4184{ 4184{
4185 struct proc *p = l->l_proc; 4185 struct proc *p = l->l_proc;
4186 struct vmspace *nvm, *ovm = p->p_vmspace; 4186 struct vmspace *nvm, *ovm = p->p_vmspace;
4187 struct vm_map *map = &ovm->vm_map; 4187 struct vm_map *map;
4188 4188
4189#ifdef __HAVE_CPU_VMSPACE_EXEC 4189#ifdef __HAVE_CPU_VMSPACE_EXEC
4190 cpu_vmspace_exec(l, start, end); 4190 cpu_vmspace_exec(l, start, end);
4191#endif 4191#endif
4192 4192
4193 /* 4193 /*
 4194 * Special case: no vmspace yet (see posix_spawn) -
 4195 * no races possible in this case.
 4196 */
 4197 if (ovm == NULL) {
 4198 p->p_vmspace = uvmspace_alloc(start, end);
 4199 pmap_activate(l);
 4200 return;
 4201 }
 4202
 4203 map = &ovm->vm_map;
 4204 /*
4194 * see if more than one process is using this vmspace... 4205 * see if more than one process is using this vmspace...
4195 */ 4206 */
4196 4207
4197 if (ovm->vm_refcnt == 1) { 4208 if (ovm->vm_refcnt == 1) {
4198 4209
4199 /* 4210 /*
4200 * if p is the only process using its vmspace then we can safely 4211 * if p is the only process using its vmspace then we can safely
4201 * recycle that vmspace for the program that is being exec'd. 4212 * recycle that vmspace for the program that is being exec'd.
4202 */ 4213 */
4203 4214
4204#ifdef SYSVSHM 4215#ifdef SYSVSHM
4205 /* 4216 /*
4206 * SYSV SHM semantics require us to kill all segments on an exec 4217 * SYSV SHM semantics require us to kill all segments on an exec