2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/* This file contains some utility routines for VM. */
|
|
|
|
|
2013-02-25 12:43:15 +01:00
|
|
|
#define _SYSTEM 1
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2013-08-20 14:02:33 +02:00
|
|
|
#define brk _brk /* get rid of no previous prototype warning */
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <minix/callnr.h>
|
|
|
|
#include <minix/com.h>
|
|
|
|
#include <minix/config.h>
|
|
|
|
#include <minix/const.h>
|
|
|
|
#include <minix/ds.h>
|
|
|
|
#include <minix/endpoint.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
|
|
|
#include <minix/type.h>
|
2009-09-21 16:49:49 +02:00
|
|
|
#include <minix/bitmap.h>
|
2014-03-12 00:13:37 +01:00
|
|
|
#include <minix/rs.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <env.h>
|
|
|
|
#include <unistd.h>
|
2010-04-27 13:17:30 +02:00
|
|
|
#include <assert.h>
|
2010-08-21 15:10:41 +02:00
|
|
|
#include <sys/param.h>
|
2012-12-17 19:26:52 +01:00
|
|
|
#include <sys/mman.h>
|
2013-06-25 14:41:01 +02:00
|
|
|
#include <sys/resource.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#include "proto.h"
|
|
|
|
#include "glo.h"
|
|
|
|
#include "util.h"
|
2010-04-27 13:17:30 +02:00
|
|
|
#include "region.h"
|
2010-07-19 20:19:38 +02:00
|
|
|
#include "sanitycheck.h"
|
2008-11-19 13:26:10 +01:00
|
|
|
|
2010-03-09 10:41:14 +01:00
|
|
|
#include <machine/archtypes.h>
|
2010-04-02 00:22:33 +02:00
|
|
|
#include "kernel/const.h"
|
|
|
|
#include "kernel/config.h"
|
|
|
|
#include "kernel/type.h"
|
|
|
|
#include "kernel/proc.h"
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* get_mem_chunks *
|
|
|
|
*===========================================================================*/
|
2013-04-03 15:14:34 +02:00
|
|
|
void get_mem_chunks(
|
|
|
|
struct memory *mem_chunks) /* store mem chunks here */
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
2013-04-03 15:14:34 +02:00
|
|
|
/* Initialize the free memory list from the kernel-provided memory map. Translate
|
2008-11-19 13:26:10 +01:00
|
|
|
* the byte offsets and sizes in this list to clicks, properly truncated.
|
|
|
|
*/
|
2009-01-22 14:05:20 +01:00
|
|
|
phys_bytes base, size, limit;
|
2008-11-19 13:26:10 +01:00
|
|
|
int i;
|
|
|
|
struct memory *memp;
|
|
|
|
|
2013-04-03 15:14:34 +02:00
|
|
|
/* Initialize everything to zero. */
|
|
|
|
memset(mem_chunks, 0, NR_MEMS*sizeof(*mem_chunks));
|
|
|
|
|
|
|
|
/* Obtain and parse memory from kernel environment. */
|
|
|
|
/* XXX Any memory chunk in excess of NR_MEMS is silently ignored. */
|
|
|
|
for(i = 0; i < MIN(MAXMEMMAP, NR_MEMS); i++) {
|
2013-12-10 22:47:53 +01:00
|
|
|
mem_chunks[i].base = kernel_boot_info.memmap[i].mm_base_addr;
|
|
|
|
mem_chunks[i].size = kernel_boot_info.memmap[i].mm_length;
|
2013-04-03 15:14:34 +02:00
|
|
|
}
|
|
|
|
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Round physical memory to clicks. Round start up, round end down. */
|
|
|
|
for (i = 0; i < NR_MEMS; i++) {
|
|
|
|
memp = &mem_chunks[i]; /* next mem chunk is stored here */
|
|
|
|
base = mem_chunks[i].base;
|
|
|
|
size = mem_chunks[i].size;
|
|
|
|
limit = base + size;
|
2010-01-14 16:24:16 +01:00
|
|
|
base = (phys_bytes) (CLICK_CEIL(base));
|
|
|
|
limit = (phys_bytes) (CLICK_FLOOR(limit));
|
2008-11-19 13:26:10 +01:00
|
|
|
if (limit <= base) {
|
|
|
|
memp->base = memp->size = 0;
|
|
|
|
} else {
|
|
|
|
memp->base = base >> CLICK_SHIFT;
|
|
|
|
memp->size = (limit - base) >> CLICK_SHIFT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* vm_isokendpt *
|
|
|
|
*===========================================================================*/
|
2013-08-20 14:02:33 +02:00
|
|
|
int vm_isokendpt(endpoint_t endpoint, int *procn)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
2013-08-20 14:02:33 +02:00
|
|
|
*procn = _ENDPOINT_P(endpoint);
|
|
|
|
if(*procn < 0 || *procn >= NR_PROCS)
|
2010-01-19 22:00:20 +01:00
|
|
|
return EINVAL;
|
2013-08-20 14:02:33 +02:00
|
|
|
if(*procn >= 0 && endpoint != vmproc[*procn].vm_endpoint)
|
2010-06-24 09:37:26 +02:00
|
|
|
return EDEADEPT;
|
2013-08-20 14:02:33 +02:00
|
|
|
if(*procn >= 0 && !(vmproc[*procn].vm_flags & VMF_INUSE))
|
2010-06-24 09:37:26 +02:00
|
|
|
return EDEADEPT;
|
2008-11-19 13:26:10 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-09-21 16:49:49 +02:00
|
|
|
/*===========================================================================*
|
2010-01-19 22:00:20 +01:00
|
|
|
* do_info *
|
2009-09-21 16:49:49 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_info(message *m)
|
2009-09-21 16:49:49 +02:00
|
|
|
{
|
2010-01-19 22:00:20 +01:00
|
|
|
struct vm_stats_info vsi;
|
|
|
|
struct vm_usage_info vui;
|
|
|
|
static struct vm_region_info vri[MAX_VRI_COUNT];
|
2009-09-21 16:49:49 +02:00
|
|
|
struct vmproc *vmp;
|
2010-01-19 22:00:20 +01:00
|
|
|
vir_bytes addr, size, next, ptr;
|
2010-09-14 23:22:56 +02:00
|
|
|
int r, pr, dummy, count, free_pages, largest_contig;
|
2009-09-21 16:49:49 +02:00
|
|
|
|
2010-01-19 22:00:20 +01:00
|
|
|
if (vm_isokendpt(m->m_source, &pr) != OK)
|
|
|
|
return EINVAL;
|
|
|
|
vmp = &vmproc[pr];
|
|
|
|
|
2014-07-26 13:53:48 +02:00
|
|
|
ptr = (vir_bytes) m->m_lsys_vm_info.ptr;
|
2010-01-19 22:00:20 +01:00
|
|
|
|
2014-07-26 13:53:48 +02:00
|
|
|
switch(m->m_lsys_vm_info.what) {
|
2010-01-19 22:00:20 +01:00
|
|
|
case VMIW_STATS:
|
|
|
|
vsi.vsi_pagesize = VM_PAGE_SIZE;
|
|
|
|
vsi.vsi_total = total_pages;
|
2010-09-14 23:22:56 +02:00
|
|
|
memstats(&dummy, &free_pages, &largest_contig);
|
|
|
|
vsi.vsi_free = free_pages;
|
|
|
|
vsi.vsi_largest = largest_contig;
|
|
|
|
|
|
|
|
get_stats_info(&vsi);
|
2010-01-19 22:00:20 +01:00
|
|
|
|
|
|
|
addr = (vir_bytes) &vsi;
|
|
|
|
size = sizeof(vsi);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VMIW_USAGE:
|
2014-07-26 13:53:48 +02:00
|
|
|
if(m->m_lsys_vm_info.ep < 0)
|
2012-09-18 22:19:22 +02:00
|
|
|
get_usage_info_kernel(&vui);
|
2014-07-26 13:53:48 +02:00
|
|
|
else if (vm_isokendpt(m->m_lsys_vm_info.ep, &pr) != OK)
|
2010-01-19 22:00:20 +01:00
|
|
|
return EINVAL;
|
2012-09-18 22:19:22 +02:00
|
|
|
else get_usage_info(&vmproc[pr], &vui);
|
2010-01-19 22:00:20 +01:00
|
|
|
|
|
|
|
addr = (vir_bytes) &vui;
|
|
|
|
size = sizeof(vui);
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
case VMIW_REGION:
|
2014-07-26 13:53:48 +02:00
|
|
|
if (vm_isokendpt(m->m_lsys_vm_info.ep, &pr) != OK)
|
2009-09-21 16:49:49 +02:00
|
|
|
return EINVAL;
|
2010-01-19 22:00:20 +01:00
|
|
|
|
2014-07-26 13:53:48 +02:00
|
|
|
count = MIN(m->m_lsys_vm_info.count, MAX_VRI_COUNT);
|
|
|
|
next = m->m_lsys_vm_info.next;
|
2010-01-19 22:00:20 +01:00
|
|
|
|
|
|
|
count = get_region_info(&vmproc[pr], vri, count, &next);
|
|
|
|
|
2014-07-26 13:53:48 +02:00
|
|
|
m->m_lsys_vm_info.count = count;
|
|
|
|
m->m_lsys_vm_info.next = next;
|
2010-01-19 22:00:20 +01:00
|
|
|
|
|
|
|
addr = (vir_bytes) vri;
|
|
|
|
size = sizeof(vri[0]) * count;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
2009-09-21 16:49:49 +02:00
|
|
|
}
|
|
|
|
|
2010-01-19 22:00:20 +01:00
|
|
|
if (size == 0)
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
/* Make sure that no page faults can occur while copying out. A page
|
|
|
|
* fault would cause the kernel to send a notify to us, while we would
|
|
|
|
* be waiting for the result of the copy system call, resulting in a
|
|
|
|
* deadlock. Note that no memory mapping can be undone without the
|
|
|
|
* involvement of VM, so we are safe until we're done.
|
|
|
|
*/
|
make vfs & filesystems use failable copying
Change the kernel to add features to vircopy and safecopies so that
transparent copy fixing won't happen to avoid deadlocks, and such copies
fail with EFAULT.
Transparently making copying work from filesystems (as normally done by
the kernel & VM when copying fails because of missing/readonly memory)
is problematic as it can happen that, for file-mapped ranges, that that
same filesystem that is blocked on the copy request is needed to satisfy
the memory range, leading to deadlock. Dito for VFS itself, if done with
a blocking call.
This change makes the copying done from a filesystem fail in such cases
with EFAULT by VFS adding the CPF_TRY flag to the grants. If a FS call
fails with EFAULT, VFS will then request the range to be made available
to VM after the FS is unblocked, allowing it to be used to satisfy the
range if need be in another VFS thread.
Similarly, for datacopies that VFS itself does, it uses the failable
vircopy variant and callers use a wrapper that talk to VM if necessary
to get the copy to work.
. kernel: add CPF_TRY flag to safecopies
. kernel: only request writable ranges to VM for the
target buffer when copying fails
. do copying in VFS TRY-first
. some fixes in VM to build SANITYCHECK mode
. add regression test for the cases where
- a FS system call needs memory mapped in a process that the
FS itself must map.
- such a range covers more than one file-mapped region.
. add 'try' mode to vircopy, physcopy
. add flags field to copy kernel call messages
. if CP_FLAG_TRY is set, do not transparently try
to fix memory ranges
. for use by VFS when accessing user buffers to avoid
deadlock
. remove some obsolete backwards compatability assignments
. VFS: let thread scheduling work for VM requests too
Allows VFS to make calls to VM while suspending and resuming
the currently running thread. Does currently not work for the
main thread.
. VM: add fix memory range call for use by VFS
Change-Id: I295794269cea51a3163519a9cfe5901301d90b32
2014-01-16 14:22:13 +01:00
|
|
|
r = handle_memory_once(vmp, ptr, size, 1 /*wrflag*/);
|
2010-01-19 22:00:20 +01:00
|
|
|
if (r != OK) return r;
|
|
|
|
|
|
|
|
/* Now that we know the copy out will succeed, perform the actual copy
|
|
|
|
* operation.
|
|
|
|
*/
|
|
|
|
return sys_datacopy(SELF, addr,
|
|
|
|
(vir_bytes) vmp->vm_endpoint, ptr, size);
|
2009-09-21 16:49:49 +02:00
|
|
|
}
|
|
|
|
|
2010-04-27 13:17:30 +02:00
|
|
|
/*===========================================================================*
|
2010-07-21 01:03:52 +02:00
|
|
|
* swap_proc_slot *
|
2010-04-27 13:17:30 +02:00
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int swap_proc_slot(struct vmproc *src_vmp, struct vmproc *dst_vmp)
|
2010-04-27 13:17:30 +02:00
|
|
|
{
|
|
|
|
struct vmproc orig_src_vmproc, orig_dst_vmproc;
|
|
|
|
|
2010-07-21 01:03:52 +02:00
|
|
|
#if LU_DEBUG
|
|
|
|
printf("VM: swap_proc: swapping %d (%d) and %d (%d)\n",
|
|
|
|
src_vmp->vm_endpoint, src_vmp->vm_slot,
|
|
|
|
dst_vmp->vm_endpoint, dst_vmp->vm_slot);
|
2010-04-27 13:17:30 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Save existing data. */
|
|
|
|
orig_src_vmproc = *src_vmp;
|
|
|
|
orig_dst_vmproc = *dst_vmp;
|
|
|
|
|
|
|
|
/* Swap slots. */
|
|
|
|
*src_vmp = orig_dst_vmproc;
|
|
|
|
*dst_vmp = orig_src_vmproc;
|
|
|
|
|
|
|
|
/* Preserve endpoints and slot numbers. */
|
|
|
|
src_vmp->vm_endpoint = orig_src_vmproc.vm_endpoint;
|
|
|
|
src_vmp->vm_slot = orig_src_vmproc.vm_slot;
|
|
|
|
dst_vmp->vm_endpoint = orig_dst_vmproc.vm_endpoint;
|
|
|
|
dst_vmp->vm_slot = orig_dst_vmproc.vm_slot;
|
|
|
|
|
2010-07-21 01:03:52 +02:00
|
|
|
#if LU_DEBUG
|
|
|
|
printf("VM: swap_proc: swapped %d (%d) and %d (%d)\n",
|
|
|
|
src_vmp->vm_endpoint, src_vmp->vm_slot,
|
|
|
|
dst_vmp->vm_endpoint, dst_vmp->vm_slot);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* swap_proc_dyn_data *
|
|
|
|
*===========================================================================*/
|
2014-03-12 00:13:37 +01:00
|
|
|
int swap_proc_dyn_data(struct vmproc *src_vmp, struct vmproc *dst_vmp,
|
|
|
|
int sys_upd_flags)
|
2010-07-21 01:03:52 +02:00
|
|
|
{
|
|
|
|
int is_vm;
|
|
|
|
int r;
|
2014-03-12 00:13:37 +01:00
|
|
|
struct vir_region *start_vr, *end_vr;
|
2010-07-21 01:03:52 +02:00
|
|
|
|
|
|
|
is_vm = (dst_vmp->vm_endpoint == VM_PROC_NR);
|
|
|
|
|
2014-03-12 00:13:37 +01:00
|
|
|
/* For VM, transfer memory mapped regions first. */
|
2010-07-21 01:03:52 +02:00
|
|
|
if(is_vm) {
|
|
|
|
#if LU_DEBUG
|
2014-03-12 00:13:37 +01:00
|
|
|
printf("VM: swap_proc_dyn_data: tranferring memory mapped regions from old (%d) to new VM (%d)\n",
|
2010-07-21 01:03:52 +02:00
|
|
|
src_vmp->vm_endpoint, dst_vmp->vm_endpoint);
|
|
|
|
#endif
|
2014-03-12 00:13:37 +01:00
|
|
|
r = pt_map_in_range(src_vmp, dst_vmp, VM_OWN_HEAPBASE, VM_OWN_MMAPTOP);
|
2010-07-21 01:03:52 +02:00
|
|
|
if(r != OK) {
|
|
|
|
printf("swap_proc_dyn_data: pt_map_in_range failed\n");
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#if LU_DEBUG
|
|
|
|
printf("VM: swap_proc_dyn_data: swapping regions' parents for %d (%d) and %d (%d)\n",
|
|
|
|
src_vmp->vm_endpoint, src_vmp->vm_slot,
|
|
|
|
dst_vmp->vm_endpoint, dst_vmp->vm_slot);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Swap vir_regions' parents. */
|
2010-10-04 13:41:10 +02:00
|
|
|
map_setparent(src_vmp);
|
|
|
|
map_setparent(dst_vmp);
|
2010-04-27 13:17:30 +02:00
|
|
|
|
2014-03-12 00:13:37 +01:00
|
|
|
/* Don't transfer mmapped regions if not required. */
|
|
|
|
if(is_vm || (sys_upd_flags & (SF_VM_ROLLBACK|SF_VM_NOMMAP))) {
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Make sure regions are consistent. */
|
|
|
|
assert(region_search_root(&src_vmp->vm_regions_avl) && region_search_root(&dst_vmp->vm_regions_avl));
|
|
|
|
|
|
|
|
/* Transfer memory mapped regions now. To sandbox the new instance and
|
|
|
|
* prevent state corruption on rollback, we share all the regions
|
|
|
|
* between the two instances as COW.
|
2010-07-21 01:03:52 +02:00
|
|
|
*/
|
2014-03-12 00:13:37 +01:00
|
|
|
start_vr = region_search(&dst_vmp->vm_regions_avl, VM_MMAPBASE, AVL_GREATER_EQUAL);
|
|
|
|
end_vr = region_search(&dst_vmp->vm_regions_avl, VM_MMAPTOP, AVL_LESS);
|
|
|
|
if(start_vr) {
|
2010-07-21 01:03:52 +02:00
|
|
|
#if LU_DEBUG
|
2014-03-12 00:13:37 +01:00
|
|
|
printf("VM: swap_proc_dyn_data: tranferring memory mapped regions from %d to %d\n",
|
|
|
|
dst_vmp->vm_endpoint, src_vmp->vm_endpoint);
|
2010-04-27 13:17:30 +02:00
|
|
|
#endif
|
2014-03-12 00:13:37 +01:00
|
|
|
assert(end_vr);
|
|
|
|
r = map_proc_copy_range(src_vmp, dst_vmp, start_vr, end_vr);
|
|
|
|
if(r != OK) {
|
|
|
|
return r;
|
2010-07-21 01:03:52 +02:00
|
|
|
}
|
|
|
|
}
|
2010-04-27 13:17:30 +02:00
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:38:29 +01:00
|
|
|
void *mmap(void *addr, size_t len, int f, int f2, int f3, off_t o)
|
2012-12-17 19:26:52 +01:00
|
|
|
{
|
|
|
|
void *ret;
|
|
|
|
phys_bytes p;
|
|
|
|
|
|
|
|
assert(!addr);
|
|
|
|
assert(!(len % VM_PAGE_SIZE));
|
|
|
|
|
|
|
|
ret = vm_allocpages(&p, VMP_SLAB, len/VM_PAGE_SIZE);
|
|
|
|
|
|
|
|
if(!ret) return MAP_FAILED;
|
|
|
|
memset(ret, 0, len);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-11-22 16:38:29 +01:00
|
|
|
int munmap(void * addr, size_t len)
|
2012-12-17 19:26:52 +01:00
|
|
|
{
|
|
|
|
vm_freepages((vir_bytes) addr, roundup(len, VM_PAGE_SIZE)/VM_PAGE_SIZE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-08-20 14:02:33 +02:00
|
|
|
int brk(void *addr)
|
2012-12-17 19:26:52 +01:00
|
|
|
{
|
2013-09-13 09:40:20 +02:00
|
|
|
/* brk is a special case function to allow vm itself to
|
|
|
|
allocate memory in it's own (cacheable) HEAP */
|
2012-12-17 19:26:52 +01:00
|
|
|
vir_bytes target = roundup((vir_bytes)addr, VM_PAGE_SIZE), v;
|
|
|
|
extern char _end;
|
|
|
|
extern char *_brksize;
|
|
|
|
static vir_bytes prevbrk = (vir_bytes) &_end;
|
|
|
|
struct vmproc *vmprocess = &vmproc[VM_PROC_NR];
|
|
|
|
|
|
|
|
for(v = roundup(prevbrk, VM_PAGE_SIZE); v < target;
|
|
|
|
v += VM_PAGE_SIZE) {
|
|
|
|
phys_bytes mem, newpage = alloc_mem(1, 0);
|
|
|
|
if(newpage == NO_MEM) return -1;
|
|
|
|
mem = CLICK2ABS(newpage);
|
|
|
|
if(pt_writemap(vmprocess, &vmprocess->vm_pt,
|
2013-02-10 20:20:14 +01:00
|
|
|
v, mem, VM_PAGE_SIZE,
|
|
|
|
ARCH_VM_PTE_PRESENT
|
|
|
|
| ARCH_VM_PTE_USER
|
|
|
|
| ARCH_VM_PTE_RW
|
|
|
|
#if defined(__arm__)
|
2013-09-13 09:40:20 +02:00
|
|
|
| ARM_VM_PTE_CACHED
|
2013-02-10 20:20:14 +01:00
|
|
|
#endif
|
|
|
|
, 0) != OK) {
|
2012-12-17 19:26:52 +01:00
|
|
|
free_mem(newpage, 1);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
prevbrk = v + VM_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
|
|
|
|
_brksize = (char *) addr;
|
|
|
|
|
|
|
|
if(sys_vmctl(SELF, VMCTL_FLUSHTLB, 0) != OK)
|
|
|
|
panic("flushtlb failed");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-06-25 14:41:01 +02:00
|
|
|
/*===========================================================================*
|
|
|
|
* do_getrusage *
|
|
|
|
*===========================================================================*/
|
|
|
|
int do_getrusage(message *m)
|
|
|
|
{
|
|
|
|
int res, slot;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
struct rusage r_usage;
|
|
|
|
if ((res = vm_isokendpt(m->m_source, &slot)) != OK)
|
|
|
|
return ESRCH;
|
2012-12-17 19:26:52 +01:00
|
|
|
|
2013-06-25 14:41:01 +02:00
|
|
|
vmp = &vmproc[slot];
|
|
|
|
|
2014-05-19 11:18:20 +02:00
|
|
|
if ((res = sys_datacopy(m->m_source, m->m_lc_vm_rusage.addr,
|
2013-06-25 14:41:01 +02:00
|
|
|
SELF, (vir_bytes) &r_usage, (vir_bytes) sizeof(r_usage))) < 0)
|
|
|
|
return res;
|
|
|
|
|
|
|
|
r_usage.ru_maxrss = vmp->vm_total_max;
|
|
|
|
r_usage.ru_minflt = vmp->vm_minor_page_fault;
|
|
|
|
r_usage.ru_majflt = vmp->vm_major_page_fault;
|
|
|
|
|
2013-08-07 22:03:47 +02:00
|
|
|
return sys_datacopy(SELF, (vir_bytes) &r_usage, m->m_source,
|
2014-05-19 11:18:20 +02:00
|
|
|
m->m_lc_vm_rusage.addr, (vir_bytes) sizeof(r_usage));
|
2013-06-25 14:41:01 +02:00
|
|
|
}
|
2014-03-12 00:13:37 +01:00
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* adjust_proc_refs *
|
|
|
|
*===========================================================================*/
|
|
|
|
void adjust_proc_refs()
|
|
|
|
{
|
|
|
|
struct vmproc *vmp;
|
|
|
|
region_iter iter;
|
|
|
|
|
|
|
|
/* Fix up region parents. */
|
|
|
|
for(vmp = vmproc; vmp < &vmproc[VMP_NR]; vmp++) {
|
|
|
|
struct vir_region *vr;
|
|
|
|
if(!(vmp->vm_flags & VMF_INUSE))
|
|
|
|
continue;
|
|
|
|
region_start_iter_least(&vmp->vm_regions_avl, &iter);
|
|
|
|
while((vr = region_get_iter(&iter))) {
|
|
|
|
USE(vr, vr->parent = vmp;);
|
|
|
|
region_incr_iter(&iter);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|