Repository navigation
Expand file tree
/
Copy pathqueryexit.c
More file actions
144 lines (122 loc) · 3.05 KB
/
Copy pathqueryexit.c
File metadata and controls
144 lines (122 loc) · 3.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#define _SYSTEM 1
#include <minix/callnr.h>
#include <minix/com.h>
#include <minix/config.h>
#include <minix/const.h>
#include <minix/ds.h>
#include <minix/endpoint.h>
#include <minix/minlib.h>
#include <minix/type.h>
#include <minix/ipc.h>
#include <minix/sysutil.h>
#include <minix/syslib.h>
#include <minix/safecopies.h>
#include <minix/bitmap.h>
#include <minix/vm.h>
#include <minix/ds.h>
#include <errno.h>
#include <string.h>
#include <env.h>
#include <stdio.h>
#include "glo.h"
#include "proto.h"
#include "util.h"
struct query_exit_struct {
int avail;
endpoint_t ep;
};
static struct query_exit_struct array[NR_PROCS];
/*===========================================================================*
* do_query_exit *
*===========================================================================*/
int do_query_exit(message *m)
{
int i, nr;
endpoint_t ep = NONE;
for (i = 0; i < NR_PROCS; i++) {
if (!array[i].avail) {
array[i].avail = 1;
ep = array[i].ep;
array[i].ep = 0;
break;
}
}
nr = 0;
for (i = 0; i < NR_PROCS; i++) {
if (!array[i].avail)
nr++;
}
m->m_lsys_vm_query_exit.ret_pt = ep;
m->m_lsys_vm_query_exit.is_more = (nr > 0);
return OK;
}
/*===========================================================================*
* do_notify_sig *
*===========================================================================*/
int do_notify_sig(message *m)
{
int i, avails = 0;
endpoint_t ep = m->VM_NOTIFY_SIG_ENDPOINT;
endpoint_t ipc_ep = m->VM_NOTIFY_SIG_IPC;
int r;
struct vmproc *vmp;
int pslot;
if(vm_isokendpt(ep, &pslot) != OK) return ESRCH;
vmp = &vmproc[pslot];
/* Only record the event if we've been asked to report it. */
if(!(vmp->vm_flags & VMF_WATCHEXIT))
return OK;
for (i = 0; i < NR_PROCS; i++) {
/* its signal is already here */
if (!array[i].avail && array[i].ep == ep)
goto out;
if (array[i].avail)
avails++;
}
if (!avails) {
/* no slot for signals, unlikely */
printf("VM: no slot for signals!\n");
return ENOMEM;
}
for (i = 0; i < NR_PROCS; i++) {
if (array[i].avail) {
array[i].avail = 0;
array[i].ep = ep;
break;
}
}
out:
/* only care when IPC server starts up,
* and bypass the process to be signal is IPC itself.
*/
if (ipc_ep != 0 && ep != ipc_ep) {
r = ipc_notify(ipc_ep);
if (r != OK)
printf("VM: ipc_notify error!\n");
}
return OK;
}
/*===========================================================================*
* do_watch_exit *
*===========================================================================*/
int do_watch_exit(message *m)
{
endpoint_t e = m->m_lsys_vm_watch_exit.ep;
struct vmproc *vmp;
int p;
if(vm_isokendpt(e, &p) != OK) return ESRCH;
vmp = &vmproc[p];
vmp->vm_flags |= VMF_WATCHEXIT;
return OK;
}
/*===========================================================================*
* init_query_exit *
*===========================================================================*/
void init_query_exit(void)
{
int i;
for (i = 0; i < NR_PROCS; i++) {
array[i].avail = 1;
array[i].ep = 0;
}
}