panic() cleanup.
[minix.git] / servers / vm / exit.c
blob7990684a038f9ae8e642d6070325029779fadfc5
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 <env.h>
21 #include "glo.h"
22 #include "proto.h"
23 #include "util.h"
24 #include "sanitycheck.h"
26 PUBLIC void free_proc(struct vmproc *vmp)
28 if(vmp->vm_flags & VMF_HASPT) {
29 vmp->vm_flags &= ~VMF_HASPT;
30 pt_free(&vmp->vm_pt);
32 map_free_proc(vmp);
33 vmp->vm_regions = NULL;
34 #if VMSTATS
35 vmp->vm_bytecopies = 0;
36 #endif
39 PUBLIC void clear_proc(struct vmproc *vmp)
41 vmp->vm_regions = NULL;
42 vmp->vm_callback = NULL; /* No pending vfs callback. */
43 vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
44 vmp->vm_count = 0;
45 vmp->vm_heap = NULL;
46 #if VMSTATS
47 vmp->vm_bytecopies = 0;
48 #endif
51 /*===========================================================================*
52 * do_exit *
53 *===========================================================================*/
54 PUBLIC int do_exit(message *msg)
56 int proc;
57 struct vmproc *vmp;
59 SANITYCHECK(SCL_FUNCTIONS);
61 if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
62 printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
63 return EINVAL;
65 vmp = &vmproc[proc];
66 if(!(vmp->vm_flags & VMF_EXITING)) {
67 printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
68 return EINVAL;
71 if(vmp->vm_flags & VMF_HAS_DMA) {
72 release_dma(vmp);
73 } else if(vmp->vm_flags & VMF_HASPT) {
74 /* Free pagetable and pages allocated by pt code. */
75 SANITYCHECK(SCL_DETAIL);
76 free_proc(vmp);
77 SANITYCHECK(SCL_DETAIL);
78 } else {
79 /* Free the data and stack segments. */
80 FREE_MEM(vmp->vm_arch.vm_seg[D].mem_phys,
81 vmp->vm_arch.vm_seg[S].mem_vir +
82 vmp->vm_arch.vm_seg[S].mem_len -
83 vmp->vm_arch.vm_seg[D].mem_vir);
85 if (find_share(vmp, vmp->vm_ino, vmp->vm_dev, vmp->vm_ctime) == NULL) {
86 /* No other process shares the text segment,
87 * so free it.
89 FREE_MEM(vmp->vm_arch.vm_seg[T].mem_phys,
90 vmp->vm_arch.vm_seg[T].mem_len);
93 SANITYCHECK(SCL_DETAIL);
95 /* Reset process slot fields. */
96 clear_proc(vmp);
98 SANITYCHECK(SCL_FUNCTIONS);
99 return OK;
102 /*===========================================================================*
103 * do_willexit *
104 *===========================================================================*/
105 PUBLIC int do_willexit(message *msg)
107 int proc;
108 struct vmproc *vmp;
110 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
111 printf("VM: bogus endpoint VM_EXITING %d\n",
112 msg->VMWE_ENDPOINT);
113 return EINVAL;
115 vmp = &vmproc[proc];
117 vmp->vm_flags |= VMF_EXITING;
119 return OK;
122 PUBLIC void _exit(int code)
124 sys_exit(SELF);
127 PUBLIC void __exit(int code)
129 sys_exit(SELF);