2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#define _SYSTEM 1
|
|
|
|
|
|
|
|
#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/keymap.h>
|
|
|
|
#include <minix/minlib.h>
|
|
|
|
#include <minix/type.h>
|
|
|
|
#include <minix/ipc.h>
|
|
|
|
#include <minix/sysutil.h>
|
|
|
|
#include <minix/syslib.h>
|
2009-09-21 16:49:49 +02:00
|
|
|
#include <minix/bitmap.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
|
|
|
|
#include <errno.h>
|
2010-04-12 13:25:24 +02:00
|
|
|
#include <assert.h>
|
2008-11-19 13:26:10 +01:00
|
|
|
#include <env.h>
|
|
|
|
|
|
|
|
#include "glo.h"
|
|
|
|
#include "proto.h"
|
|
|
|
#include "util.h"
|
|
|
|
#include "sanitycheck.h"
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void free_proc(struct vmproc *vmp)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
2010-04-12 13:25:24 +02:00
|
|
|
map_free_proc(vmp);
|
2012-05-30 19:34:07 +02:00
|
|
|
vmp->vm_heap = NULL;
|
2009-09-21 16:49:49 +02:00
|
|
|
if(vmp->vm_flags & VMF_HASPT) {
|
|
|
|
vmp->vm_flags &= ~VMF_HASPT;
|
|
|
|
pt_free(&vmp->vm_pt);
|
|
|
|
}
|
2010-10-04 13:41:10 +02:00
|
|
|
region_init(&vmp->vm_regions_avl);
|
2010-10-07 12:04:05 +02:00
|
|
|
vmp->vm_region_top = 0;
|
2008-11-19 13:26:10 +01:00
|
|
|
#if VMSTATS
|
|
|
|
vmp->vm_bytecopies = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2012-03-25 20:25:53 +02:00
|
|
|
void clear_proc(struct vmproc *vmp)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
2010-10-04 13:41:10 +02:00
|
|
|
region_init(&vmp->vm_regions_avl);
|
2010-10-07 12:04:05 +02:00
|
|
|
vmp->vm_region_top = 0;
|
2008-11-19 13:26:10 +01:00
|
|
|
vmp->vm_callback = NULL; /* No pending vfs callback. */
|
|
|
|
vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
|
|
|
|
vmp->vm_heap = NULL;
|
2010-10-15 11:10:14 +02:00
|
|
|
vmp->vm_yielded = 0;
|
2008-11-19 13:26:10 +01:00
|
|
|
#if VMSTATS
|
|
|
|
vmp->vm_bytecopies = 0;
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_exit *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_exit(message *msg)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
|
|
|
int proc;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
|
|
|
|
SANITYCHECK(SCL_FUNCTIONS);
|
|
|
|
|
|
|
|
if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
|
|
|
|
printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
vmp = &vmproc[proc];
|
|
|
|
if(!(vmp->vm_flags & VMF_EXITING)) {
|
|
|
|
printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(vmp->vm_flags & VMF_HAS_DMA) {
|
|
|
|
release_dma(vmp);
|
2010-06-28 23:53:37 +02:00
|
|
|
} else if(vmp->vm_flags & VMF_HASPT) {
|
2008-11-19 13:26:10 +01:00
|
|
|
/* Free pagetable and pages allocated by pt code. */
|
|
|
|
SANITYCHECK(SCL_DETAIL);
|
|
|
|
free_proc(vmp);
|
|
|
|
SANITYCHECK(SCL_DETAIL);
|
2010-06-28 23:53:37 +02:00
|
|
|
} else {
|
|
|
|
/* Free the data and stack segments. */
|
|
|
|
free_mem(vmp->vm_arch.vm_seg[D].mem_phys,
|
|
|
|
vmp->vm_arch.vm_seg[S].mem_vir +
|
|
|
|
vmp->vm_arch.vm_seg[S].mem_len -
|
|
|
|
vmp->vm_arch.vm_seg[D].mem_vir);
|
2008-11-19 13:26:10 +01:00
|
|
|
}
|
|
|
|
SANITYCHECK(SCL_DETAIL);
|
|
|
|
|
|
|
|
/* Reset process slot fields. */
|
|
|
|
clear_proc(vmp);
|
|
|
|
|
|
|
|
SANITYCHECK(SCL_FUNCTIONS);
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*===========================================================================*
|
|
|
|
* do_willexit *
|
|
|
|
*===========================================================================*/
|
2012-03-25 20:25:53 +02:00
|
|
|
int do_willexit(message *msg)
|
2008-11-19 13:26:10 +01:00
|
|
|
{
|
|
|
|
int proc;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
|
|
|
|
if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
|
|
|
|
printf("VM: bogus endpoint VM_EXITING %d\n",
|
|
|
|
msg->VMWE_ENDPOINT);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
vmp = &vmproc[proc];
|
|
|
|
|
|
|
|
vmp->vm_flags |= VMF_EXITING;
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2012-06-06 00:50:13 +02:00
|
|
|
int do_procctl(message *msg)
|
|
|
|
{
|
|
|
|
endpoint_t proc;
|
|
|
|
struct vmproc *vmp;
|
|
|
|
|
|
|
|
if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
|
|
|
|
printf("VM: bogus endpoint VM_PROCCTL %d\n",
|
|
|
|
msg->VMPCTL_WHO);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
vmp = &vmproc[proc];
|
|
|
|
|
|
|
|
switch(msg->VMPCTL_PARAM) {
|
|
|
|
case VMPPARAM_CLEAR:
|
|
|
|
if(msg->m_source != RS_PROC_NR
|
|
|
|
&& msg->m_source != VFS_PROC_NR)
|
|
|
|
return EPERM;
|
|
|
|
free_proc(vmp);
|
|
|
|
pt_new(&vmp->vm_pt);
|
|
|
|
vmp->vm_flags |= VMF_HASPT;
|
|
|
|
pt_bind(&vmp->vm_pt, vmp);
|
2012-05-30 19:34:07 +02:00
|
|
|
regular_segs(vmp);
|
2012-06-06 00:50:13 +02:00
|
|
|
return OK;
|
|
|
|
default:
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|