Remove building with NOCRYPTO option
[minix3.git] / minix / servers / vm / exit.c
blob58c3c25761e77a21e1ce5b56085a4d3008ac441b
2 #define _SYSTEM 1
4 #include <minix/callnr.h>
5 #include <minix/com.h>
6 #include <minix/config.h>
7 #include <minix/const.h>
8 #include <minix/ds.h>
9 #include <minix/endpoint.h>
10 #include <minix/minlib.h>
11 #include <minix/type.h>
12 #include <minix/ipc.h>
13 #include <minix/sysutil.h>
14 #include <minix/syslib.h>
15 #include <minix/bitmap.h>
17 #include <errno.h>
18 #include <assert.h>
20 #include "glo.h"
21 #include "proto.h"
22 #include "util.h"
23 #include "sanitycheck.h"
25 static void reset_vm_rusage(struct vmproc *vmp)
27 vmp->vm_total = 0;
28 vmp->vm_total_max = 0;
29 vmp->vm_minor_page_fault = 0;
30 vmp->vm_major_page_fault = 0;
33 void free_proc(struct vmproc *vmp)
35 map_free_proc(vmp);
36 pt_free(&vmp->vm_pt);
37 region_init(&vmp->vm_regions_avl);
38 #if VMSTATS
39 vmp->vm_bytecopies = 0;
40 #endif
41 vmp->vm_region_top = 0;
42 reset_vm_rusage(vmp);
45 void clear_proc(struct vmproc *vmp)
47 region_init(&vmp->vm_regions_avl);
48 acl_clear(vmp);
49 vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
50 #if VMSTATS
51 vmp->vm_bytecopies = 0;
52 #endif
53 vmp->vm_region_top = 0;
54 reset_vm_rusage(vmp);
57 /*===========================================================================*
58 * do_exit *
59 *===========================================================================*/
60 int do_exit(message *msg)
62 int proc;
63 struct vmproc *vmp;
65 SANITYCHECK(SCL_FUNCTIONS);
67 if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
68 printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
69 return EINVAL;
71 vmp = &vmproc[proc];
73 if(!(vmp->vm_flags & VMF_EXITING)) {
74 printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
75 return EINVAL;
77 if(vmp->vm_flags & VMF_VM_INSTANCE) {
78 vmp->vm_flags &= ~VMF_VM_INSTANCE;
79 num_vm_instances--;
83 /* Free pagetable and pages allocated by pt code. */
84 SANITYCHECK(SCL_DETAIL);
85 free_proc(vmp);
86 SANITYCHECK(SCL_DETAIL);
88 SANITYCHECK(SCL_DETAIL);
90 /* Reset process slot fields. */
91 clear_proc(vmp);
93 SANITYCHECK(SCL_FUNCTIONS);
94 return OK;
97 /*===========================================================================*
98 * do_willexit *
99 *===========================================================================*/
100 int do_willexit(message *msg)
102 int proc;
103 struct vmproc *vmp;
105 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
106 printf("VM: bogus endpoint VM_EXITING %d\n",
107 msg->VMWE_ENDPOINT);
108 return EINVAL;
110 vmp = &vmproc[proc];
112 vmp->vm_flags |= VMF_EXITING;
114 return OK;
117 int do_procctl(message *msg, int transid)
119 endpoint_t proc;
120 struct vmproc *vmp;
122 if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
123 printf("VM: bogus endpoint VM_PROCCTL %ld\n",
124 msg->VMPCTL_WHO);
125 return EINVAL;
127 vmp = &vmproc[proc];
129 switch(msg->VMPCTL_PARAM) {
130 case VMPPARAM_CLEAR:
131 if(msg->m_source != RS_PROC_NR
132 && msg->m_source != VFS_PROC_NR)
133 return EPERM;
134 free_proc(vmp);
135 if(pt_new(&vmp->vm_pt) != OK)
136 panic("VMPPARAM_CLEAR: pt_new failed");
137 pt_bind(&vmp->vm_pt, vmp);
138 return OK;
139 case VMPPARAM_HANDLEMEM:
141 if(msg->m_source != VFS_PROC_NR)
142 return EPERM;
144 handle_memory_start(vmp, msg->VMPCTL_M1,
145 msg->VMPCTL_LEN, msg->VMPCTL_FLAGS,
146 VFS_PROC_NR, VFS_PROC_NR, transid, 1);
148 return SUSPEND;
150 default:
151 return EINVAL;
154 return OK;