make vfs & filesystems use failable copying
[minix3.git] / servers / vm / exit.c
bloba62a7d49091170cc04941e499202b1ef58eb3848
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;
80 /* Free pagetable and pages allocated by pt code. */
81 SANITYCHECK(SCL_DETAIL);
82 free_proc(vmp);
83 SANITYCHECK(SCL_DETAIL);
85 SANITYCHECK(SCL_DETAIL);
87 /* Reset process slot fields. */
88 clear_proc(vmp);
90 SANITYCHECK(SCL_FUNCTIONS);
91 return OK;
94 /*===========================================================================*
95 * do_willexit *
96 *===========================================================================*/
97 int do_willexit(message *msg)
99 int proc;
100 struct vmproc *vmp;
102 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
103 printf("VM: bogus endpoint VM_EXITING %d\n",
104 msg->VMWE_ENDPOINT);
105 return EINVAL;
107 vmp = &vmproc[proc];
109 vmp->vm_flags |= VMF_EXITING;
111 return OK;
114 int do_procctl(message *msg, int transid)
116 endpoint_t proc;
117 struct vmproc *vmp;
119 if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
120 printf("VM: bogus endpoint VM_PROCCTL %ld\n",
121 msg->VMPCTL_WHO);
122 return EINVAL;
124 vmp = &vmproc[proc];
126 switch(msg->VMPCTL_PARAM) {
127 case VMPPARAM_CLEAR:
128 if(msg->m_source != RS_PROC_NR
129 && msg->m_source != VFS_PROC_NR)
130 return EPERM;
131 free_proc(vmp);
132 if(pt_new(&vmp->vm_pt) != OK)
133 panic("VMPPARAM_CLEAR: pt_new failed");
134 pt_bind(&vmp->vm_pt, vmp);
135 return OK;
136 case VMPPARAM_HANDLEMEM:
138 if(msg->m_source != VFS_PROC_NR)
139 return EPERM;
141 handle_memory_start(vmp, msg->VMPCTL_M1,
142 msg->VMPCTL_LEN, msg->VMPCTL_FLAGS,
143 VFS_PROC_NR, VFS_PROC_NR, transid, 1);
145 return SUSPEND;
147 default:
148 return EINVAL;
151 return OK;