MCPcopy Create free account
hub / github.com/F-Stack/f-stack / vmspace_unshare

Function vmspace_unshare

freebsd/vm/vm_map.c:4892–4916  ·  view source on GitHub ↗

* Unshare the specified VM space for forcing COW. This * is called by rfork, for the (RFMEM|RFPROC) == 0 case. */

Source from the content-addressed store, hash-verified

4890 * is called by rfork, for the (RFMEM|RFPROC) == 0 case.
4891 */
4892int
4893vmspace_unshare(struct proc *p)
4894{
4895 struct vmspace *oldvmspace = p->p_vmspace;
4896 struct vmspace *newvmspace;
4897 vm_ooffset_t fork_charge;
4898
4899 if (refcount_load(&oldvmspace->vm_refcnt) == 1)
4900 return (0);
4901 fork_charge = 0;
4902 newvmspace = vmspace_fork(oldvmspace, &fork_charge);
4903 if (newvmspace == NULL)
4904 return (ENOMEM);
4905 if (!swap_reserve_by_cred(fork_charge, p->p_ucred)) {
4906 vmspace_free(newvmspace);
4907 return (ENOMEM);
4908 }
4909 PROC_VMSPACE_LOCK(p);
4910 p->p_vmspace = newvmspace;
4911 PROC_VMSPACE_UNLOCK(p);
4912 if (p == curthread->td_proc)
4913 pmap_activate(curthread);
4914 vmspace_free(oldvmspace);
4915 return (0);
4916}
4917
4918/*
4919 * vm_map_lookup:

Callers 1

vm_forkprocFunction · 0.85

Calls 5

refcount_loadFunction · 0.85
vmspace_forkFunction · 0.85
swap_reserve_by_credFunction · 0.85
vmspace_freeFunction · 0.85
pmap_activateFunction · 0.50

Tested by

no test coverage detected