Improve the process for GNU tools
[minix3.git] / minix / servers / vm / exit.c
blobdd0ee6d630408bb9060fceb6f05ec383692ddb8c
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>
19 #include <env.h>
21 #include "glo.h"
22 #include "proto.h"
23 #include "util.h"
24 #include "sanitycheck.h"
26 static void reset_vm_rusage(struct vmproc *vmp)
28 vmp->vm_total = 0;
29 vmp->vm_total_max = 0;
30 vmp->vm_minor_page_fault = 0;
31 vmp->vm_major_page_fault = 0;
34 void free_proc(struct vmproc *vmp)
36 map_free_proc(vmp);
37 pt_free(&vmp->vm_pt);
38 region_init(&vmp->vm_regions_avl);
39 #if VMSTATS
40 vmp->vm_bytecopies = 0;
41 #endif
42 vmp->vm_region_top = 0;
43 reset_vm_rusage(vmp);
46 void clear_proc(struct vmproc *vmp)
48 region_init(&vmp->vm_regions_avl);
49 acl_clear(vmp);
50 vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
51 #if VMSTATS
52 vmp->vm_bytecopies = 0;
53 #endif
54 vmp->vm_region_top = 0;
55 reset_vm_rusage(vmp);
58 /*===========================================================================*
59 * do_exit *
60 *===========================================================================*/
61 int do_exit(message *msg)
63 int proc;
64 struct vmproc *vmp;
66 SANITYCHECK(SCL_FUNCTIONS);
68 if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
69 printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
70 return EINVAL;
72 vmp = &vmproc[proc];
74 if(!(vmp->vm_flags & VMF_EXITING)) {
75 printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
76 return EINVAL;
78 if(vmp->vm_flags & VMF_VM_INSTANCE) {
79 vmp->vm_flags &= ~VMF_VM_INSTANCE;
80 num_vm_instances--;
84 /* Free pagetable and pages allocated by pt code. */
85 SANITYCHECK(SCL_DETAIL);
86 free_proc(vmp);
87 SANITYCHECK(SCL_DETAIL);
89 SANITYCHECK(SCL_DETAIL);
91 /* Reset process slot fields. */
92 clear_proc(vmp);
94 SANITYCHECK(SCL_FUNCTIONS);
95 return OK;
98 /*===========================================================================*
99 * do_willexit *
100 *===========================================================================*/
101 int do_willexit(message *msg)
103 int proc;
104 struct vmproc *vmp;
106 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
107 printf("VM: bogus endpoint VM_EXITING %d\n",
108 msg->VMWE_ENDPOINT);
109 return EINVAL;
111 vmp = &vmproc[proc];
113 vmp->vm_flags |= VMF_EXITING;
115 return OK;
118 int do_procctl(message *msg, int transid)
120 endpoint_t proc;
121 struct vmproc *vmp;
123 if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
124 printf("VM: bogus endpoint VM_PROCCTL %ld\n",
125 msg->VMPCTL_WHO);
126 return EINVAL;
128 vmp = &vmproc[proc];
130 switch(msg->VMPCTL_PARAM) {
131 case VMPPARAM_CLEAR:
132 if(msg->m_source != RS_PROC_NR
133 && msg->m_source != VFS_PROC_NR)
134 return EPERM;
135 free_proc(vmp);
136 if(pt_new(&vmp->vm_pt) != OK)
137 panic("VMPPARAM_CLEAR: pt_new failed");
138 pt_bind(&vmp->vm_pt, vmp);
139 return OK;
140 case VMPPARAM_HANDLEMEM:
142 if(msg->m_source != VFS_PROC_NR)
143 return EPERM;
145 handle_memory_start(vmp, msg->VMPCTL_M1,
146 msg->VMPCTL_LEN, msg->VMPCTL_FLAGS,
147 VFS_PROC_NR, VFS_PROC_NR, transid, 1);
149 return SUSPEND;
151 default:
152 return EINVAL;
155 return OK;