vm_glue.c (22975) | vm_glue.c (24691) |
---|---|
1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55 * School of Computer Science 56 * Carnegie Mellon University 57 * Pittsburgh PA 15213-3890 58 * 59 * any improvements or extensions that they make and grant Carnegie the 60 * rights to redistribute these changes. 61 * | 1/* 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * The Mach Operating System project at Carnegie-Mellon University. 7 * 8 * Redistribution and use in source and binary forms, with or without --- 45 unchanged lines hidden (view full) --- 54 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 55 * School of Computer Science 56 * Carnegie Mellon University 57 * Pittsburgh PA 15213-3890 58 * 59 * any improvements or extensions that they make and grant Carnegie the 60 * rights to redistribute these changes. 61 * |
62 * $Id$ | 62 * $Id: vm_glue.c,v 1.61 1997/02/22 09:48:17 peter Exp $ |
63 */ 64 65#include "opt_rlimit.h" 66 67#include <sys/param.h> 68#include <sys/systm.h> 69#include <sys/proc.h> 70#include <sys/resourcevar.h> 71#include <sys/buf.h> 72#include <sys/shm.h> 73#include <sys/vmmeter.h> 74 75#include <sys/kernel.h> 76#include <sys/dkstat.h> | 63 */ 64 65#include "opt_rlimit.h" 66 67#include <sys/param.h> 68#include <sys/systm.h> 69#include <sys/proc.h> 70#include <sys/resourcevar.h> 71#include <sys/buf.h> 72#include <sys/shm.h> 73#include <sys/vmmeter.h> 74 75#include <sys/kernel.h> 76#include <sys/dkstat.h> |
77#include <sys/unistd.h> |
|
77 78#include <vm/vm.h> 79#include <vm/vm_param.h> 80#include <vm/vm_inherit.h> 81#include <vm/vm_prot.h> 82#include <sys/lock.h> 83#include <vm/pmap.h> 84#include <vm/vm_map.h> --- 107 unchanged lines hidden (view full) --- 192 round_page(addr + len), TRUE); 193} 194 195/* 196 * Implement fork's actions on an address space. 197 * Here we arrange for the address space to be copied or referenced, 198 * allocate a user struct (pcb and kernel stack), then call the 199 * machine-dependent layer to fill those in and make the new process | 78 79#include <vm/vm.h> 80#include <vm/vm_param.h> 81#include <vm/vm_inherit.h> 82#include <vm/vm_prot.h> 83#include <sys/lock.h> 84#include <vm/pmap.h> 85#include <vm/vm_map.h> --- 107 unchanged lines hidden (view full) --- 193 round_page(addr + len), TRUE); 194} 195 196/* 197 * Implement fork's actions on an address space. 198 * Here we arrange for the address space to be copied or referenced, 199 * allocate a user struct (pcb and kernel stack), then call the 200 * machine-dependent layer to fill those in and make the new process |
200 * ready to run. 201 * NOTE: the kernel stack may be at a different location in the child 202 * process, and thus addresses of automatic variables may be invalid 203 * after cpu_fork returns in the child process. We do nothing here 204 * after cpu_fork returns. | 201 * ready to run. The new process is set up so that it returns directly 202 * to user mode to avoid stack copying and relocation problems. |
205 */ | 203 */ |
206int 207vm_fork(p1, p2) | 204void 205vm_fork(p1, p2, flags) |
208 register struct proc *p1, *p2; | 206 register struct proc *p1, *p2; |
207 int flags; |
|
209{ 210 register struct user *up; 211 int i; 212 pmap_t pvp; 213 vm_object_t upobj; 214 215 while ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_free_min) { 216 VM_WAIT; 217 } 218 | 208{ 209 register struct user *up; 210 int i; 211 pmap_t pvp; 212 vm_object_t upobj; 213 214 while ((cnt.v_free_count + cnt.v_cache_count) < cnt.v_free_min) { 215 VM_WAIT; 216 } 217 |
219 p2->p_vmspace = vmspace_fork(p1->p_vmspace); | 218 if (flags & RFMEM) { 219 p2->p_vmspace = p1->p_vmspace; 220 p1->p_vmspace->vm_refcnt++; 221 } else { 222 p2->p_vmspace = vmspace_fork(p1->p_vmspace); |
220 | 223 |
221 if (p1->p_vmspace->vm_shm) 222 shmfork(p1, p2); | 224 if (p1->p_vmspace->vm_shm) 225 shmfork(p1, p2); 226 } |
223 224 pmap_new_proc(p2); 225 226 up = p2->p_addr; 227 228 /* 229 * p_stats and p_sigacts currently point at fields in the user struct 230 * but not at &u, instead at p_addr. Copy p_sigacts and parts of --- 6 unchanged lines hidden (view full) --- 237 (unsigned) ((caddr_t) &up->u_stats.pstat_endzero - 238 (caddr_t) &up->u_stats.pstat_startzero)); 239 bcopy(&p1->p_stats->pstat_startcopy, &up->u_stats.pstat_startcopy, 240 ((caddr_t) &up->u_stats.pstat_endcopy - 241 (caddr_t) &up->u_stats.pstat_startcopy)); 242 243 244 /* | 227 228 pmap_new_proc(p2); 229 230 up = p2->p_addr; 231 232 /* 233 * p_stats and p_sigacts currently point at fields in the user struct 234 * but not at &u, instead at p_addr. Copy p_sigacts and parts of --- 6 unchanged lines hidden (view full) --- 241 (unsigned) ((caddr_t) &up->u_stats.pstat_endzero - 242 (caddr_t) &up->u_stats.pstat_startzero)); 243 bcopy(&p1->p_stats->pstat_startcopy, &up->u_stats.pstat_startcopy, 244 ((caddr_t) &up->u_stats.pstat_endcopy - 245 (caddr_t) &up->u_stats.pstat_startcopy)); 246 247 248 /* |
245 * cpu_fork will copy and update the kernel stack and pcb, and make 246 * the child ready to run. It marks the child so that it can return 247 * differently than the parent. It returns twice, once in the parent 248 * process and once in the child. | 249 * cpu_fork will copy and update the pcb, set up the kernel stack, 250 * and make the child ready to run. |
249 */ | 251 */ |
250 return (cpu_fork(p1, p2)); | 252 cpu_fork(p1, p2); |
251} 252 253/* 254 * Set default limits for VM system. 255 * Called for proc 0, and then inherited by all others. 256 * 257 * XXX should probably act directly on proc0. 258 */ --- 227 unchanged lines hidden --- | 253} 254 255/* 256 * Set default limits for VM system. 257 * Called for proc 0, and then inherited by all others. 258 * 259 * XXX should probably act directly on proc0. 260 */ --- 227 unchanged lines hidden --- |