1433d6423SLionel Sambuc 2433d6423SLionel Sambuc /* This file contains some utility routines for VM. */ 3433d6423SLionel Sambuc 4433d6423SLionel Sambuc #define _SYSTEM 1 5433d6423SLionel Sambuc 6433d6423SLionel Sambuc #define brk _brk /* get rid of no previous prototype warning */ 7433d6423SLionel Sambuc 8433d6423SLionel Sambuc #include <minix/callnr.h> 9433d6423SLionel Sambuc #include <minix/com.h> 10433d6423SLionel Sambuc #include <minix/config.h> 11433d6423SLionel Sambuc #include <minix/const.h> 12433d6423SLionel Sambuc #include <minix/ds.h> 13433d6423SLionel Sambuc #include <minix/endpoint.h> 14433d6423SLionel Sambuc #include <minix/minlib.h> 15433d6423SLionel Sambuc #include <minix/type.h> 16433d6423SLionel Sambuc #include <minix/ipc.h> 17433d6423SLionel Sambuc #include <minix/sysutil.h> 18433d6423SLionel Sambuc #include <minix/syslib.h> 19433d6423SLionel Sambuc #include <minix/type.h> 20433d6423SLionel Sambuc #include <minix/bitmap.h> 2163483e02SCristiano Giuffrida #include <minix/rs.h> 22433d6423SLionel Sambuc #include <string.h> 23433d6423SLionel Sambuc #include <errno.h> 24433d6423SLionel Sambuc #include <env.h> 25433d6423SLionel Sambuc #include <unistd.h> 26433d6423SLionel Sambuc #include <assert.h> 27433d6423SLionel Sambuc #include <sys/param.h> 28433d6423SLionel Sambuc #include <sys/mman.h> 29433d6423SLionel Sambuc #include <sys/resource.h> 30433d6423SLionel Sambuc 31433d6423SLionel Sambuc #include "proto.h" 32433d6423SLionel Sambuc #include "glo.h" 33433d6423SLionel Sambuc #include "util.h" 34433d6423SLionel Sambuc #include "region.h" 35433d6423SLionel Sambuc #include "sanitycheck.h" 36433d6423SLionel Sambuc 37433d6423SLionel Sambuc #include <machine/archtypes.h> 38433d6423SLionel Sambuc #include "kernel/const.h" 39433d6423SLionel Sambuc #include "kernel/config.h" 40433d6423SLionel Sambuc #include "kernel/type.h" 41433d6423SLionel Sambuc #include "kernel/proc.h" 42433d6423SLionel Sambuc 43433d6423SLionel Sambuc /*===========================================================================* 44433d6423SLionel Sambuc * get_mem_chunks * 45433d6423SLionel Sambuc *===========================================================================*/ 46433d6423SLionel Sambuc void get_mem_chunks( 47433d6423SLionel Sambuc struct memory *mem_chunks) /* store mem chunks here */ 48433d6423SLionel Sambuc { 49433d6423SLionel Sambuc /* Initialize the free memory list from the kernel-provided memory map. Translate 50433d6423SLionel Sambuc * the byte offsets and sizes in this list to clicks, properly truncated. 51433d6423SLionel Sambuc */ 52433d6423SLionel Sambuc phys_bytes base, size, limit; 53433d6423SLionel Sambuc int i; 54433d6423SLionel Sambuc struct memory *memp; 55433d6423SLionel Sambuc 56433d6423SLionel Sambuc /* Initialize everything to zero. */ 57433d6423SLionel Sambuc memset(mem_chunks, 0, NR_MEMS*sizeof(*mem_chunks)); 58433d6423SLionel Sambuc 59433d6423SLionel Sambuc /* Obtain and parse memory from kernel environment. */ 60433d6423SLionel Sambuc /* XXX Any memory chunk in excess of NR_MEMS is silently ignored. */ 61433d6423SLionel Sambuc for(i = 0; i < MIN(MAXMEMMAP, NR_MEMS); i++) { 62433d6423SLionel Sambuc mem_chunks[i].base = kernel_boot_info.memmap[i].mm_base_addr; 63433d6423SLionel Sambuc mem_chunks[i].size = kernel_boot_info.memmap[i].mm_length; 64433d6423SLionel Sambuc } 65433d6423SLionel Sambuc 66433d6423SLionel Sambuc /* Round physical memory to clicks. Round start up, round end down. */ 67433d6423SLionel Sambuc for (i = 0; i < NR_MEMS; i++) { 68433d6423SLionel Sambuc memp = &mem_chunks[i]; /* next mem chunk is stored here */ 69433d6423SLionel Sambuc base = mem_chunks[i].base; 70433d6423SLionel Sambuc size = mem_chunks[i].size; 71433d6423SLionel Sambuc limit = base + size; 72433d6423SLionel Sambuc base = (phys_bytes) (CLICK_CEIL(base)); 73433d6423SLionel Sambuc limit = (phys_bytes) (CLICK_FLOOR(limit)); 74433d6423SLionel Sambuc if (limit <= base) { 75433d6423SLionel Sambuc memp->base = memp->size = 0; 76433d6423SLionel Sambuc } else { 77433d6423SLionel Sambuc memp->base = base >> CLICK_SHIFT; 78433d6423SLionel Sambuc memp->size = (limit - base) >> CLICK_SHIFT; 79433d6423SLionel Sambuc } 80433d6423SLionel Sambuc } 81433d6423SLionel Sambuc } 82433d6423SLionel Sambuc 83433d6423SLionel Sambuc /*===========================================================================* 84433d6423SLionel Sambuc * vm_isokendpt * 85433d6423SLionel Sambuc *===========================================================================*/ 86433d6423SLionel Sambuc int vm_isokendpt(endpoint_t endpoint, int *procn) 87433d6423SLionel Sambuc { 88433d6423SLionel Sambuc *procn = _ENDPOINT_P(endpoint); 89433d6423SLionel Sambuc if(*procn < 0 || *procn >= NR_PROCS) 90433d6423SLionel Sambuc return EINVAL; 91433d6423SLionel Sambuc if(*procn >= 0 && endpoint != vmproc[*procn].vm_endpoint) 92433d6423SLionel Sambuc return EDEADEPT; 93433d6423SLionel Sambuc if(*procn >= 0 && !(vmproc[*procn].vm_flags & VMF_INUSE)) 94433d6423SLionel Sambuc return EDEADEPT; 95433d6423SLionel Sambuc return OK; 96433d6423SLionel Sambuc } 97433d6423SLionel Sambuc 98433d6423SLionel Sambuc 99433d6423SLionel Sambuc /*===========================================================================* 100433d6423SLionel Sambuc * do_info * 101433d6423SLionel Sambuc *===========================================================================*/ 102433d6423SLionel Sambuc int do_info(message *m) 103433d6423SLionel Sambuc { 104433d6423SLionel Sambuc struct vm_stats_info vsi; 105433d6423SLionel Sambuc struct vm_usage_info vui; 106433d6423SLionel Sambuc static struct vm_region_info vri[MAX_VRI_COUNT]; 107433d6423SLionel Sambuc struct vmproc *vmp; 108433d6423SLionel Sambuc vir_bytes addr, size, next, ptr; 109433d6423SLionel Sambuc int r, pr, dummy, count, free_pages, largest_contig; 110433d6423SLionel Sambuc 111433d6423SLionel Sambuc if (vm_isokendpt(m->m_source, &pr) != OK) 112433d6423SLionel Sambuc return EINVAL; 113433d6423SLionel Sambuc vmp = &vmproc[pr]; 114433d6423SLionel Sambuc 115433d6423SLionel Sambuc ptr = (vir_bytes) m->m_lsys_vm_info.ptr; 116433d6423SLionel Sambuc 117433d6423SLionel Sambuc switch(m->m_lsys_vm_info.what) { 118433d6423SLionel Sambuc case VMIW_STATS: 119433d6423SLionel Sambuc vsi.vsi_pagesize = VM_PAGE_SIZE; 120433d6423SLionel Sambuc vsi.vsi_total = total_pages; 121433d6423SLionel Sambuc memstats(&dummy, &free_pages, &largest_contig); 122433d6423SLionel Sambuc vsi.vsi_free = free_pages; 123433d6423SLionel Sambuc vsi.vsi_largest = largest_contig; 124433d6423SLionel Sambuc 125433d6423SLionel Sambuc get_stats_info(&vsi); 126433d6423SLionel Sambuc 127433d6423SLionel Sambuc addr = (vir_bytes) &vsi; 128433d6423SLionel Sambuc size = sizeof(vsi); 129433d6423SLionel Sambuc 130433d6423SLionel Sambuc break; 131433d6423SLionel Sambuc 132433d6423SLionel Sambuc case VMIW_USAGE: 133433d6423SLionel Sambuc if(m->m_lsys_vm_info.ep < 0) 134433d6423SLionel Sambuc get_usage_info_kernel(&vui); 135433d6423SLionel Sambuc else if (vm_isokendpt(m->m_lsys_vm_info.ep, &pr) != OK) 136433d6423SLionel Sambuc return EINVAL; 137433d6423SLionel Sambuc else get_usage_info(&vmproc[pr], &vui); 138433d6423SLionel Sambuc 139433d6423SLionel Sambuc addr = (vir_bytes) &vui; 140433d6423SLionel Sambuc size = sizeof(vui); 141433d6423SLionel Sambuc 142433d6423SLionel Sambuc break; 143433d6423SLionel Sambuc 144433d6423SLionel Sambuc case VMIW_REGION: 145*65b4b952SCristiano Giuffrida if(m->m_lsys_vm_info.ep == SELF) { 146*65b4b952SCristiano Giuffrida m->m_lsys_vm_info.ep = m->m_source; 147*65b4b952SCristiano Giuffrida } 148433d6423SLionel Sambuc if (vm_isokendpt(m->m_lsys_vm_info.ep, &pr) != OK) 149433d6423SLionel Sambuc return EINVAL; 150433d6423SLionel Sambuc 151433d6423SLionel Sambuc count = MIN(m->m_lsys_vm_info.count, MAX_VRI_COUNT); 152433d6423SLionel Sambuc next = m->m_lsys_vm_info.next; 153433d6423SLionel Sambuc 154433d6423SLionel Sambuc count = get_region_info(&vmproc[pr], vri, count, &next); 155433d6423SLionel Sambuc 156433d6423SLionel Sambuc m->m_lsys_vm_info.count = count; 157433d6423SLionel Sambuc m->m_lsys_vm_info.next = next; 158433d6423SLionel Sambuc 159433d6423SLionel Sambuc addr = (vir_bytes) vri; 160433d6423SLionel Sambuc size = sizeof(vri[0]) * count; 161433d6423SLionel Sambuc 162433d6423SLionel Sambuc break; 163433d6423SLionel Sambuc 164433d6423SLionel Sambuc default: 165433d6423SLionel Sambuc return EINVAL; 166433d6423SLionel Sambuc } 167433d6423SLionel Sambuc 168433d6423SLionel Sambuc if (size == 0) 169433d6423SLionel Sambuc return OK; 170433d6423SLionel Sambuc 171433d6423SLionel Sambuc /* Make sure that no page faults can occur while copying out. A page 172433d6423SLionel Sambuc * fault would cause the kernel to send a notify to us, while we would 173433d6423SLionel Sambuc * be waiting for the result of the copy system call, resulting in a 174433d6423SLionel Sambuc * deadlock. Note that no memory mapping can be undone without the 175433d6423SLionel Sambuc * involvement of VM, so we are safe until we're done. 176433d6423SLionel Sambuc */ 177433d6423SLionel Sambuc r = handle_memory_once(vmp, ptr, size, 1 /*wrflag*/); 178433d6423SLionel Sambuc if (r != OK) return r; 179433d6423SLionel Sambuc 180433d6423SLionel Sambuc /* Now that we know the copy out will succeed, perform the actual copy 181433d6423SLionel Sambuc * operation. 182433d6423SLionel Sambuc */ 183433d6423SLionel Sambuc return sys_datacopy(SELF, addr, 184433d6423SLionel Sambuc (vir_bytes) vmp->vm_endpoint, ptr, size); 185433d6423SLionel Sambuc } 186433d6423SLionel Sambuc 187433d6423SLionel Sambuc /*===========================================================================* 188433d6423SLionel Sambuc * swap_proc_slot * 189433d6423SLionel Sambuc *===========================================================================*/ 190433d6423SLionel Sambuc int swap_proc_slot(struct vmproc *src_vmp, struct vmproc *dst_vmp) 191433d6423SLionel Sambuc { 192433d6423SLionel Sambuc struct vmproc orig_src_vmproc, orig_dst_vmproc; 193433d6423SLionel Sambuc 194433d6423SLionel Sambuc #if LU_DEBUG 195433d6423SLionel Sambuc printf("VM: swap_proc: swapping %d (%d) and %d (%d)\n", 196433d6423SLionel Sambuc src_vmp->vm_endpoint, src_vmp->vm_slot, 197433d6423SLionel Sambuc dst_vmp->vm_endpoint, dst_vmp->vm_slot); 198433d6423SLionel Sambuc #endif 199433d6423SLionel Sambuc 200433d6423SLionel Sambuc /* Save existing data. */ 201433d6423SLionel Sambuc orig_src_vmproc = *src_vmp; 202433d6423SLionel Sambuc orig_dst_vmproc = *dst_vmp; 203433d6423SLionel Sambuc 204433d6423SLionel Sambuc /* Swap slots. */ 205433d6423SLionel Sambuc *src_vmp = orig_dst_vmproc; 206433d6423SLionel Sambuc *dst_vmp = orig_src_vmproc; 207433d6423SLionel Sambuc 208433d6423SLionel Sambuc /* Preserve endpoints and slot numbers. */ 209433d6423SLionel Sambuc src_vmp->vm_endpoint = orig_src_vmproc.vm_endpoint; 210433d6423SLionel Sambuc src_vmp->vm_slot = orig_src_vmproc.vm_slot; 211433d6423SLionel Sambuc dst_vmp->vm_endpoint = orig_dst_vmproc.vm_endpoint; 212433d6423SLionel Sambuc dst_vmp->vm_slot = orig_dst_vmproc.vm_slot; 213433d6423SLionel Sambuc 214433d6423SLionel Sambuc #if LU_DEBUG 215433d6423SLionel Sambuc printf("VM: swap_proc: swapped %d (%d) and %d (%d)\n", 216433d6423SLionel Sambuc src_vmp->vm_endpoint, src_vmp->vm_slot, 217433d6423SLionel Sambuc dst_vmp->vm_endpoint, dst_vmp->vm_slot); 218433d6423SLionel Sambuc #endif 219433d6423SLionel Sambuc 220433d6423SLionel Sambuc return OK; 221433d6423SLionel Sambuc } 222433d6423SLionel Sambuc 223433d6423SLionel Sambuc /*===========================================================================* 224433d6423SLionel Sambuc * swap_proc_dyn_data * 225433d6423SLionel Sambuc *===========================================================================*/ 22663483e02SCristiano Giuffrida int swap_proc_dyn_data(struct vmproc *src_vmp, struct vmproc *dst_vmp, 22763483e02SCristiano Giuffrida int sys_upd_flags) 228433d6423SLionel Sambuc { 229433d6423SLionel Sambuc int is_vm; 230433d6423SLionel Sambuc int r; 23163483e02SCristiano Giuffrida struct vir_region *start_vr, *end_vr; 232433d6423SLionel Sambuc 233433d6423SLionel Sambuc is_vm = (dst_vmp->vm_endpoint == VM_PROC_NR); 234433d6423SLionel Sambuc 23563483e02SCristiano Giuffrida /* For VM, transfer memory mapped regions first. */ 236433d6423SLionel Sambuc if(is_vm) { 237433d6423SLionel Sambuc #if LU_DEBUG 23863483e02SCristiano Giuffrida printf("VM: swap_proc_dyn_data: tranferring memory mapped regions from old (%d) to new VM (%d)\n", 239433d6423SLionel Sambuc src_vmp->vm_endpoint, dst_vmp->vm_endpoint); 240433d6423SLionel Sambuc #endif 24163483e02SCristiano Giuffrida r = pt_map_in_range(src_vmp, dst_vmp, VM_OWN_HEAPBASE, VM_OWN_MMAPTOP); 242433d6423SLionel Sambuc if(r != OK) { 243433d6423SLionel Sambuc printf("swap_proc_dyn_data: pt_map_in_range failed\n"); 244433d6423SLionel Sambuc return r; 245433d6423SLionel Sambuc } 246433d6423SLionel Sambuc } 247433d6423SLionel Sambuc 248433d6423SLionel Sambuc #if LU_DEBUG 249433d6423SLionel Sambuc printf("VM: swap_proc_dyn_data: swapping regions' parents for %d (%d) and %d (%d)\n", 250433d6423SLionel Sambuc src_vmp->vm_endpoint, src_vmp->vm_slot, 251433d6423SLionel Sambuc dst_vmp->vm_endpoint, dst_vmp->vm_slot); 252433d6423SLionel Sambuc #endif 253433d6423SLionel Sambuc 254433d6423SLionel Sambuc /* Swap vir_regions' parents. */ 255433d6423SLionel Sambuc map_setparent(src_vmp); 256433d6423SLionel Sambuc map_setparent(dst_vmp); 257433d6423SLionel Sambuc 25863483e02SCristiano Giuffrida /* Don't transfer mmapped regions if not required. */ 25963483e02SCristiano Giuffrida if(is_vm || (sys_upd_flags & (SF_VM_ROLLBACK|SF_VM_NOMMAP))) { 26063483e02SCristiano Giuffrida return OK; 26163483e02SCristiano Giuffrida } 26263483e02SCristiano Giuffrida 26363483e02SCristiano Giuffrida /* Make sure regions are consistent. */ 26463483e02SCristiano Giuffrida assert(region_search_root(&src_vmp->vm_regions_avl) && region_search_root(&dst_vmp->vm_regions_avl)); 26563483e02SCristiano Giuffrida 26663483e02SCristiano Giuffrida /* Transfer memory mapped regions now. To sandbox the new instance and 26763483e02SCristiano Giuffrida * prevent state corruption on rollback, we share all the regions 26863483e02SCristiano Giuffrida * between the two instances as COW. 269433d6423SLionel Sambuc */ 27063483e02SCristiano Giuffrida start_vr = region_search(&dst_vmp->vm_regions_avl, VM_MMAPBASE, AVL_GREATER_EQUAL); 27163483e02SCristiano Giuffrida end_vr = region_search(&dst_vmp->vm_regions_avl, VM_MMAPTOP, AVL_LESS); 27263483e02SCristiano Giuffrida if(start_vr) { 273433d6423SLionel Sambuc #if LU_DEBUG 27463483e02SCristiano Giuffrida printf("VM: swap_proc_dyn_data: tranferring memory mapped regions from %d to %d\n", 27563483e02SCristiano Giuffrida dst_vmp->vm_endpoint, src_vmp->vm_endpoint); 276433d6423SLionel Sambuc #endif 27763483e02SCristiano Giuffrida assert(end_vr); 27863483e02SCristiano Giuffrida r = map_proc_copy_range(src_vmp, dst_vmp, start_vr, end_vr); 279433d6423SLionel Sambuc if(r != OK) { 280433d6423SLionel Sambuc return r; 281433d6423SLionel Sambuc } 282433d6423SLionel Sambuc } 283433d6423SLionel Sambuc 284433d6423SLionel Sambuc return OK; 285433d6423SLionel Sambuc } 286433d6423SLionel Sambuc 287433d6423SLionel Sambuc void *mmap(void *addr, size_t len, int f, int f2, int f3, off_t o) 288433d6423SLionel Sambuc { 289433d6423SLionel Sambuc void *ret; 290433d6423SLionel Sambuc phys_bytes p; 291433d6423SLionel Sambuc 292433d6423SLionel Sambuc assert(!addr); 293433d6423SLionel Sambuc assert(!(len % VM_PAGE_SIZE)); 294433d6423SLionel Sambuc 295433d6423SLionel Sambuc ret = vm_allocpages(&p, VMP_SLAB, len/VM_PAGE_SIZE); 296433d6423SLionel Sambuc 297433d6423SLionel Sambuc if(!ret) return MAP_FAILED; 298433d6423SLionel Sambuc memset(ret, 0, len); 299433d6423SLionel Sambuc return ret; 300433d6423SLionel Sambuc } 301433d6423SLionel Sambuc 302433d6423SLionel Sambuc int munmap(void * addr, size_t len) 303433d6423SLionel Sambuc { 304433d6423SLionel Sambuc vm_freepages((vir_bytes) addr, roundup(len, VM_PAGE_SIZE)/VM_PAGE_SIZE); 305433d6423SLionel Sambuc return 0; 306433d6423SLionel Sambuc } 307433d6423SLionel Sambuc 308433d6423SLionel Sambuc int brk(void *addr) 309433d6423SLionel Sambuc { 310433d6423SLionel Sambuc /* brk is a special case function to allow vm itself to 311433d6423SLionel Sambuc allocate memory in it's own (cacheable) HEAP */ 312433d6423SLionel Sambuc vir_bytes target = roundup((vir_bytes)addr, VM_PAGE_SIZE), v; 313433d6423SLionel Sambuc extern char _end; 314433d6423SLionel Sambuc extern char *_brksize; 315433d6423SLionel Sambuc static vir_bytes prevbrk = (vir_bytes) &_end; 316433d6423SLionel Sambuc struct vmproc *vmprocess = &vmproc[VM_PROC_NR]; 317433d6423SLionel Sambuc 318433d6423SLionel Sambuc for(v = roundup(prevbrk, VM_PAGE_SIZE); v < target; 319433d6423SLionel Sambuc v += VM_PAGE_SIZE) { 320433d6423SLionel Sambuc phys_bytes mem, newpage = alloc_mem(1, 0); 321433d6423SLionel Sambuc if(newpage == NO_MEM) return -1; 322433d6423SLionel Sambuc mem = CLICK2ABS(newpage); 323433d6423SLionel Sambuc if(pt_writemap(vmprocess, &vmprocess->vm_pt, 324433d6423SLionel Sambuc v, mem, VM_PAGE_SIZE, 325433d6423SLionel Sambuc ARCH_VM_PTE_PRESENT 326433d6423SLionel Sambuc | ARCH_VM_PTE_USER 327433d6423SLionel Sambuc | ARCH_VM_PTE_RW 328433d6423SLionel Sambuc #if defined(__arm__) 329433d6423SLionel Sambuc | ARM_VM_PTE_CACHED 330433d6423SLionel Sambuc #endif 331433d6423SLionel Sambuc , 0) != OK) { 332433d6423SLionel Sambuc free_mem(newpage, 1); 333433d6423SLionel Sambuc return -1; 334433d6423SLionel Sambuc } 335433d6423SLionel Sambuc prevbrk = v + VM_PAGE_SIZE; 336433d6423SLionel Sambuc } 337433d6423SLionel Sambuc 338433d6423SLionel Sambuc _brksize = (char *) addr; 339433d6423SLionel Sambuc 340433d6423SLionel Sambuc if(sys_vmctl(SELF, VMCTL_FLUSHTLB, 0) != OK) 341433d6423SLionel Sambuc panic("flushtlb failed"); 342433d6423SLionel Sambuc 343433d6423SLionel Sambuc return 0; 344433d6423SLionel Sambuc } 345433d6423SLionel Sambuc 346433d6423SLionel Sambuc /*===========================================================================* 347433d6423SLionel Sambuc * do_getrusage * 348433d6423SLionel Sambuc *===========================================================================*/ 349433d6423SLionel Sambuc int do_getrusage(message *m) 350433d6423SLionel Sambuc { 351433d6423SLionel Sambuc int res, slot; 352433d6423SLionel Sambuc struct vmproc *vmp; 353433d6423SLionel Sambuc struct rusage r_usage; 354433d6423SLionel Sambuc if ((res = vm_isokendpt(m->m_source, &slot)) != OK) 355433d6423SLionel Sambuc return ESRCH; 356433d6423SLionel Sambuc 357433d6423SLionel Sambuc vmp = &vmproc[slot]; 358433d6423SLionel Sambuc 359433d6423SLionel Sambuc if ((res = sys_datacopy(m->m_source, m->m_lc_vm_rusage.addr, 360433d6423SLionel Sambuc SELF, (vir_bytes) &r_usage, (vir_bytes) sizeof(r_usage))) < 0) 361433d6423SLionel Sambuc return res; 362433d6423SLionel Sambuc 363433d6423SLionel Sambuc r_usage.ru_maxrss = vmp->vm_total_max; 364433d6423SLionel Sambuc r_usage.ru_minflt = vmp->vm_minor_page_fault; 365433d6423SLionel Sambuc r_usage.ru_majflt = vmp->vm_major_page_fault; 366433d6423SLionel Sambuc 367433d6423SLionel Sambuc return sys_datacopy(SELF, (vir_bytes) &r_usage, m->m_source, 368433d6423SLionel Sambuc m->m_lc_vm_rusage.addr, (vir_bytes) sizeof(r_usage)); 369433d6423SLionel Sambuc } 37063483e02SCristiano Giuffrida 37163483e02SCristiano Giuffrida /*===========================================================================* 37263483e02SCristiano Giuffrida * adjust_proc_refs * 37363483e02SCristiano Giuffrida *===========================================================================*/ 37463483e02SCristiano Giuffrida void adjust_proc_refs() 37563483e02SCristiano Giuffrida { 37663483e02SCristiano Giuffrida struct vmproc *vmp; 37763483e02SCristiano Giuffrida region_iter iter; 37863483e02SCristiano Giuffrida 37963483e02SCristiano Giuffrida /* Fix up region parents. */ 38063483e02SCristiano Giuffrida for(vmp = vmproc; vmp < &vmproc[VMP_NR]; vmp++) { 38163483e02SCristiano Giuffrida struct vir_region *vr; 38263483e02SCristiano Giuffrida if(!(vmp->vm_flags & VMF_INUSE)) 38363483e02SCristiano Giuffrida continue; 38463483e02SCristiano Giuffrida region_start_iter_least(&vmp->vm_regions_avl, &iter); 38563483e02SCristiano Giuffrida while((vr = region_get_iter(&iter))) { 38663483e02SCristiano Giuffrida USE(vr, vr->parent = vmp;); 38763483e02SCristiano Giuffrida region_incr_iter(&iter); 38863483e02SCristiano Giuffrida } 38963483e02SCristiano Giuffrida } 39063483e02SCristiano Giuffrida } 39163483e02SCristiano Giuffrida 392