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

Function exec_new_vmspace

freebsd/kern/kern_exec.c:1035–1149  ·  view source on GitHub ↗

* Destroy old address space, and allocate a new stack. * The new stack is only sgrowsiz large because it is grown * automatically on a page fault. */

Source from the content-addressed store, hash-verified

1033 * automatically on a page fault.
1034 */
1035int
1036exec_new_vmspace(struct image_params *imgp, struct sysentvec *sv)
1037{
1038 int error;
1039 struct proc *p = imgp->proc;
1040 struct vmspace *vmspace = p->p_vmspace;
1041 struct thread *td = curthread;
1042 vm_object_t obj;
1043 struct rlimit rlim_stack;
1044 vm_offset_t sv_minuser, stack_addr;
1045 vm_map_t map;
1046 vm_prot_t stack_prot;
1047 u_long ssiz;
1048
1049 imgp->vmspace_destroyed = 1;
1050 imgp->sysent = sv;
1051
1052 sigfastblock_clear(td);
1053 umtx_exec(p);
1054 itimers_exec(p);
1055 if (sv->sv_onexec != NULL)
1056 sv->sv_onexec(p, imgp);
1057
1058 EVENTHANDLER_DIRECT_INVOKE(process_exec, p, imgp);
1059
1060 /*
1061 * Blow away entire process VM, if address space not shared,
1062 * otherwise, create a new VM space so that other threads are
1063 * not disrupted
1064 */
1065 map = &vmspace->vm_map;
1066 if (map_at_zero)
1067 sv_minuser = sv->sv_minuser;
1068 else
1069 sv_minuser = MAX(sv->sv_minuser, PAGE_SIZE);
1070 if (refcount_load(&vmspace->vm_refcnt) == 1 &&
1071 vm_map_min(map) == sv_minuser &&
1072 vm_map_max(map) == sv->sv_maxuser &&
1073 cpu_exec_vmspace_reuse(p, map)) {
1074 shmexit(vmspace);
1075 pmap_remove_pages(vmspace_pmap(vmspace));
1076 vm_map_remove(map, vm_map_min(map), vm_map_max(map));
1077 /*
1078 * An exec terminates mlockall(MCL_FUTURE).
1079 * ASLR and W^X states must be re-evaluated.
1080 */
1081 vm_map_lock(map);
1082 vm_map_modflags(map, 0, MAP_WIREFUTURE | MAP_ASLR |
1083 MAP_ASLR_IGNSTART | MAP_WXORX);
1084 vm_map_unlock(map);
1085 } else {
1086 error = vmspace_exec(p, sv_minuser, sv->sv_maxuser);
1087 if (error)
1088 return (error);
1089 vmspace = p->p_vmspace;
1090 map = &vmspace->vm_map;
1091 }
1092 map->flags |= imgp->map_flags;

Callers 3

exec_linux_imgactFunction · 0.85
exec_aout_imgactFunction · 0.85

Calls 15

sigfastblock_clearFunction · 0.85
umtx_execFunction · 0.85
itimers_execFunction · 0.85
refcount_loadFunction · 0.85
vm_map_minFunction · 0.85
vm_map_maxFunction · 0.85
shmexitFunction · 0.85
vmspace_pmapFunction · 0.85
vm_map_removeFunction · 0.85
vm_map_modflagsFunction · 0.85
vmspace_execFunction · 0.85
vm_object_referenceFunction · 0.85

Tested by

no test coverage detected