coverity appeasement - redundant check
[minix.git] / servers / vm / exit.c
blob894a131939423cb646868caf3b57b10ae78faa74
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 void free_proc(struct vmproc *vmp)
29 map_free_proc(vmp);
30 pt_free(&vmp->vm_pt);
31 region_init(&vmp->vm_regions_avl);
32 vmp->vm_region_top = 0;
33 #if VMSTATS
34 vmp->vm_bytecopies = 0;
35 #endif
38 void clear_proc(struct vmproc *vmp)
40 region_init(&vmp->vm_regions_avl);
41 vmp->vm_region_top = 0;
42 vmp->vm_callback = NULL; /* No pending vfs callback. */
43 vmp->vm_flags = 0; /* Clear INUSE, so slot is free. */
44 vmp->vm_yielded = 0;
45 #if VMSTATS
46 vmp->vm_bytecopies = 0;
47 #endif
50 /*===========================================================================*
51 * do_exit *
52 *===========================================================================*/
53 int do_exit(message *msg)
55 int proc;
56 struct vmproc *vmp;
58 SANITYCHECK(SCL_FUNCTIONS);
60 if(vm_isokendpt(msg->VME_ENDPOINT, &proc) != OK) {
61 printf("VM: bogus endpoint VM_EXIT %d\n", msg->VME_ENDPOINT);
62 return EINVAL;
64 vmp = &vmproc[proc];
65 if(!(vmp->vm_flags & VMF_EXITING)) {
66 printf("VM: unannounced VM_EXIT %d\n", msg->VME_ENDPOINT);
67 return EINVAL;
71 /* Free pagetable and pages allocated by pt code. */
72 SANITYCHECK(SCL_DETAIL);
73 free_proc(vmp);
74 SANITYCHECK(SCL_DETAIL);
76 SANITYCHECK(SCL_DETAIL);
78 /* Reset process slot fields. */
79 clear_proc(vmp);
81 SANITYCHECK(SCL_FUNCTIONS);
82 return OK;
85 /*===========================================================================*
86 * do_willexit *
87 *===========================================================================*/
88 int do_willexit(message *msg)
90 int proc;
91 struct vmproc *vmp;
93 if(vm_isokendpt(msg->VMWE_ENDPOINT, &proc) != OK) {
94 printf("VM: bogus endpoint VM_EXITING %d\n",
95 msg->VMWE_ENDPOINT);
96 return EINVAL;
98 vmp = &vmproc[proc];
100 vmp->vm_flags |= VMF_EXITING;
102 return OK;
105 int do_procctl(message *msg)
107 endpoint_t proc;
108 struct vmproc *vmp;
110 if(vm_isokendpt(msg->VMPCTL_WHO, &proc) != OK) {
111 printf("VM: bogus endpoint VM_PROCCTL %d\n",
112 msg->VMPCTL_WHO);
113 return EINVAL;
115 vmp = &vmproc[proc];
117 switch(msg->VMPCTL_PARAM) {
118 case VMPPARAM_CLEAR:
119 if(msg->m_source != RS_PROC_NR
120 && msg->m_source != VFS_PROC_NR)
121 return EPERM;
122 free_proc(vmp);
123 pt_new(&vmp->vm_pt);
124 pt_bind(&vmp->vm_pt, vmp);
125 return OK;
126 default:
127 return EINVAL;
131 return OK;