vm: use assert() instead of vm_assert(); remove vm_assert().
[minix.git] / servers / vm / exit.c
blob7c339a5abee40e7858ea65c80ea0ec8c5fb13bfa
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/keymap.h>
11 #include <minix/minlib.h>
12 #include <minix/type.h>
13 #include <minix/ipc.h>
14 #include <minix/sysutil.h>
15 #include <minix/syslib.h>
16 #include <minix/bitmap.h>
18 #include <errno.h>
19 #include <assert.h>
20 #include <env.h>
22 #include "glo.h"
23 #include "proto.h"
24 #include "util.h"
25 #include "sanitycheck.h"
27 PUBLIC void free_proc(struct vmproc *vmp)
29 map_free_proc(vmp);
30 if(vmp->vm_flags & VMF_HASPT) {
31 vmp->vm_flags &= ~VMF_HASPT;
32 pt_free(&vmp->vm_pt);
34 vmp->vm_regions = NULL;
35 #if VMSTATS
36 vmp->vm_bytecopies = 0;
37 #endif
40 PUBLIC void clear_proc(struct vmproc *vmp)
42 vmp->vm_regions = NULL;
43 vmp->vm_callback = NULL; /* No pending vfs callback. */
44 vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
45 vmp->vm_count = 0;
46 vmp->vm_heap = NULL;
47 #if VMSTATS
48 vmp->vm_bytecopies = 0;
49 #endif
52 /*===========================================================================*
53 * do_exit *
54 *===========================================================================*/
55 PUBLIC int do_exit(message *msg)
57 int proc;
58 struct vmproc *vmp;
60 SANITYCHECK(SCL_FUNCTIONS);
62 if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
63 printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
64 return EINVAL;
66 vmp = &vmproc[proc];
67 if(!(vmp->vm_flags & VMF_EXITING)) {
68 printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
69 return EINVAL;
72 if(vmp->vm_flags & VMF_HAS_DMA) {
73 release_dma(vmp);
74 } else if(vmp->vm_flags & VMF_HASPT) {
75 /* Free pagetable and pages allocated by pt code. */
76 SANITYCHECK(SCL_DETAIL);
77 free_proc(vmp);
78 SANITYCHECK(SCL_DETAIL);
79 } else {
80 /* Free the data and stack segments. */
81 free_mem(vmp->vm_arch.vm_seg[D].mem_phys,
82 vmp->vm_arch.vm_seg[S].mem_vir +
83 vmp->vm_arch.vm_seg[S].mem_len -
84 vmp->vm_arch.vm_seg[D].mem_vir);
86 if (find_share(vmp, vmp->vm_ino, vmp->vm_dev, vmp->vm_ctime) == NULL) {
87 /* No other process shares the text segment,
88 * so free it.
90 free_mem(vmp->vm_arch.vm_seg[T].mem_phys,
91 vmp->vm_arch.vm_seg[T].mem_len);
94 SANITYCHECK(SCL_DETAIL);
96 /* Reset process slot fields. */
97 clear_proc(vmp);
99 SANITYCHECK(SCL_FUNCTIONS);
100 return OK;
103 /*===========================================================================*
104 * do_willexit *
105 *===========================================================================*/
106 PUBLIC int do_willexit(message *msg)
108 int proc;
109 struct vmproc *vmp;
111 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
112 printf("VM: bogus endpoint VM_EXITING %d\n",
113 msg->VMWE_ENDPOINT);
114 return EINVAL;
116 vmp = &vmproc[proc];
118 vmp->vm_flags |= VMF_EXITING;
120 return OK;