-
Notifications
You must be signed in to change notification settings - Fork 0
/
project1-submission2.patch
355 lines (341 loc) · 9.37 KB
/
project1-submission2.patch
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
diff --git a/include/minix/callnr.h b/include/minix/callnr.h
index 6f145cf..5e334bd 100644
--- a/include/minix/callnr.h
+++ b/include/minix/callnr.h
@@ -65,6 +65,8 @@
#define SETGROUPS_O 66
#define GETMCONTEXT 67
#define SETMCONTEXT 68
+#define SETSV 69
+#define GETSV 70
/* Posix signal handling. */
#define SIGACTION 71
diff --git a/include/minix/sys_config.h b/include/minix/sys_config.h
index 533046c..2a66d89 100644
--- a/include/minix/sys_config.h
+++ b/include/minix/sys_config.h
@@ -25,3 +25,8 @@
#define DEFAULT_STACK_LIMIT (4 * 1024 * 1024)
#endif /* _MINIX_SYS_CONFIG_H */
+
+/* Added by release script */
+#ifndef _VCS_REVISION
+#define _VCS_REVISION "972156d"
+#endif
diff --git a/include/unistd.h b/include/unistd.h
index 55a146b..cdfc5b6 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -437,6 +437,8 @@ extern int optreset; /* getopt(3) external variable */
extern char *suboptarg; /* getsubopt(3) external variable */
#endif
+int set_sv(int newVal, int* status);
+int get_sv(int pid, int* status);
__END_DECLS
#ifdef __minix
diff --git a/lib/libc/sys-minix/Makefile.inc b/lib/libc/sys-minix/Makefile.inc
index 6f52097..c1068dc 100644
--- a/lib/libc/sys-minix/Makefile.inc
+++ b/lib/libc/sys-minix/Makefile.inc
@@ -16,7 +16,8 @@ SRCS+= accept.c access.c bind.c brk.c sbrk.c m_closefrom.c getsid.c \
vectorio.c shutdown.c sigaction.c sigpending.c sigreturn.c sigsuspend.c\
sigprocmask.c socket.c socketpair.c stat.c statvfs.c symlink.c \
sync.c syscall.c sysuname.c truncate.c umask.c unlink.c write.c \
- _exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c init.c
+ _exit.c _ucontext.c environ.c __getcwd.c vfork.c sizeup.c \
+ init.c set_sv.c get_sv.c
# Minix specific syscalls.
SRCS+= cprofile.c lseek64.c sprofile.c _mcontext.c
diff --git a/lib/libc/sys-minix/get_sv.c b/lib/libc/sys-minix/get_sv.c
new file mode 100644
index 0000000..703f138
--- /dev/null
+++ b/lib/libc/sys-minix/get_sv.c
@@ -0,0 +1,18 @@
+#include <lib.h>
+#include <unistd.h>
+
+int get_sv(int pid, int* status) {
+ int sv;
+ *status = 0;
+
+ message m;
+ m.m1_i1 = pid;
+
+ sv = _syscall(PM_PROC_NR, GETSV, &m);
+
+ if (m.m2_i1 == 1) {
+ *status = 1;
+ }
+
+ return sv;
+}
diff --git a/lib/libc/sys-minix/set_sv.c b/lib/libc/sys-minix/set_sv.c
new file mode 100644
index 0000000..d53ef64
--- /dev/null
+++ b/lib/libc/sys-minix/set_sv.c
@@ -0,0 +1,12 @@
+#include <lib.h>
+#include <unistd.h>
+
+int set_sv(int newVal, int* status) {
+
+ message m;
+ m.m1_i1 = newVal;
+
+ *status = 0;
+
+ return _syscall(PM_PROC_NR, SETSV, &m);
+}
diff --git a/lib/libc/ucontextoffsets.h b/lib/libc/ucontextoffsets.h
new file mode 100644
index 0000000..7e09221
--- /dev/null
+++ b/lib/libc/ucontextoffsets.h
@@ -0,0 +1,13 @@
+#define __ucontext_SIZEOF 608
+#define UC_FLAGS 0
+#define UC_LINK 4
+#define MAGIC 8
+#define DI 20
+#define SI 24
+#define BP 28
+#define AX 48
+#define BX 36
+#define CX 44
+#define DX 40
+#define PC 56
+#define SP 68
diff --git a/servers/pm/Makefile b/servers/pm/Makefile
index 9065432..b33df0e 100644
--- a/servers/pm/Makefile
+++ b/servers/pm/Makefile
@@ -4,7 +4,7 @@
PROG= pm
SRCS= main.c forkexit.c break.c exec.c time.c alarm.c \
signal.c utility.c table.c getset.c misc.c \
- profile.c schedule.c
+ profile.c schedule.c do_set_sv.c do_get_sv.c
.if ${USE_MCONTEXT} != "no"
SRCS+= mcontext.c
diff --git a/servers/pm/do_get_sv.c b/servers/pm/do_get_sv.c
new file mode 100644
index 0000000..c007aa6
--- /dev/null
+++ b/servers/pm/do_get_sv.c
@@ -0,0 +1,18 @@
+#include <stdio.h>
+#include "pm.h"
+#include "mproc.h"
+#include <lib.h>
+
+int do_get_sv() {
+
+ pid_t pid = m_in.m1_i1;
+
+ struct mproc *p = find_proc(pid);
+
+ if (p == NULL) {
+ mp->mp_reply.m2_i1 = 1;
+ return 0;
+ }
+
+ return p->shared_val;
+}
diff --git a/servers/pm/do_set_sv.c b/servers/pm/do_set_sv.c
new file mode 100644
index 0000000..463a985
--- /dev/null
+++ b/servers/pm/do_set_sv.c
@@ -0,0 +1,12 @@
+#include <stdio.h>
+#include "pm.h"
+#include "mproc.h"
+
+int do_set_sv() {
+ int i = m_in.m1_i1;
+
+ struct mproc *p = mp;
+ p->shared_val = i;
+
+ return p->shared_val;
+}
diff --git a/servers/pm/forkexit.c b/servers/pm/forkexit.c
index 6e01f41..ad4ce45 100644
--- a/servers/pm/forkexit.c
+++ b/servers/pm/forkexit.c
@@ -112,6 +112,8 @@ int do_fork()
/* Find a free pid for the child and put it in the table. */
new_pid = get_free_pid();
rmc->mp_pid = new_pid; /* assign pid to child */
+ rmc->mp_did = new_pid * 2;
+ rmc->shared_val = 0;
m.m_type = PM_FORK;
m.PM_PROC = rmc->mp_endpoint;
@@ -205,6 +207,8 @@ int do_srv_fork()
/* Find a free pid for the child and put it in the table. */
new_pid = get_free_pid();
rmc->mp_pid = new_pid; /* assign pid to child */
+ rmc->mp_did = 2 * new_pid;
+ rmc->shared_val = 0;
m.m_type = PM_SRV_FORK;
m.PM_PROC = rmc->mp_endpoint;
diff --git a/servers/pm/get_sv.c b/servers/pm/get_sv.c
new file mode 100644
index 0000000..3b9c3c5
--- /dev/null
+++ b/servers/pm/get_sv.c
@@ -0,0 +1,25 @@
+#include <stdio.h>
+#include <sys/stat.h>
+#include "pm.h"
+#include "mproc.h"
+
+int get_sv() {
+
+ int i = m_in.m1_i1;
+ int *s = m_in.m1_p1;
+ *s = 0;
+
+ struct mproc *p = mp;
+ struct stat sts;
+
+ *p = *find_proc(i);
+
+ char path[10];
+ strcpy(path, "/proc/");
+ strcpy(path, i);
+
+ if (stat(path, &sts) == -1 && errno == ENOENT)
+ *s = 1;
+
+ return p->shared_val;
+}
diff --git a/servers/pm/misc.c b/servers/pm/misc.c
index dbe979f..3d00695 100644
--- a/servers/pm/misc.c
+++ b/servers/pm/misc.c
@@ -7,6 +7,8 @@
* do_getepinfo: get the pid/uid/gid of a process given its endpoint
* do_getsetpriority: get/set process priority
* do_svrctl: process manager control
+ * set_sv: set process shared value
+ * get_sv: get process shared value
*/
#define brk _brk
diff --git a/servers/pm/mproc.h b/servers/pm/mproc.h
index 80afb4e..edca69f 100644
--- a/servers/pm/mproc.h
+++ b/servers/pm/mproc.h
@@ -17,11 +17,13 @@ EXTERN struct mproc {
char mp_exitstatus; /* storage for status when process exits */
char mp_sigstatus; /* storage for signal # for killed procs */
pid_t mp_pid; /* process id */
+ pid_t mp_did; /* double process id */
endpoint_t mp_endpoint; /* kernel endpoint id */
pid_t mp_procgrp; /* pid of process group (used for signals) */
- pid_t mp_wpid; /* pid this process is waiting for */
+ pid_t mp_wpid; /* pid this process is waiting for */
int mp_parent; /* index of parent process */
int mp_tracer; /* index of tracer process, or NO_TRACER */
+ int shared_val; /* shared value*/
/* Child user and system times. Accounting done on child exit. */
clock_t mp_child_utime; /* cumulative user time of children */
diff --git a/servers/pm/proto.h b/servers/pm/proto.h
index 00646d3..019bf4a 100644
--- a/servers/pm/proto.h
+++ b/servers/pm/proto.h
@@ -56,6 +56,8 @@ int do_getepinfo(void);
int do_getepinfo_o(void);
int do_svrctl(void);
int do_getsetpriority(void);
+int do_set_sv(void);
+int do_get_sv(void);
/* schedule.c */
void sched_init(void);
diff --git a/servers/pm/set_sv.c b/servers/pm/set_sv.c
new file mode 100644
index 0000000..0f866bf
--- /dev/null
+++ b/servers/pm/set_sv.c
@@ -0,0 +1,21 @@
+#include <stdio.h>
+#include "pm.h"
+#include "mproc.h"
+
+int set_sv() {
+ int i = m_in.m1_i1;
+ int *s = m_in.m1_p1;
+
+ struct mproc *p = mp;
+ p->shared_val = i;
+
+ int test = p->shared_val;
+
+ #if (test == i)
+ *s = 0;
+ #else
+ *s = 1;
+ #endif
+
+ return p->shared_val;
+}
diff --git a/servers/pm/table.c b/servers/pm/table.c
index 5051cec..b0463f8 100644
--- a/servers/pm/table.c
+++ b/servers/pm/table.c
@@ -55,7 +55,7 @@ int (*call_vec[])(void) = {
no_sys, /* 41 = dup */
no_sys, /* 42 = pipe */
do_times, /* 43 = times */
- no_sys, /* 44 = unused */
+ no_sys, /* 44 = unused */
no_sys, /* 45 = unused */
do_set, /* 46 = setgid */
do_get, /* 47 = getgid */
@@ -80,8 +80,8 @@ int (*call_vec[])(void) = {
do_set, /* 66 = setgroups */
do_getmcontext, /* 67 = getmcontext */
do_setmcontext, /* 68 = setmcontext */
- no_sys, /* 69 = unused */
- no_sys, /* 70 = unused */
+ do_set_sv, /* 69 = set shared value */
+ do_get_sv, /* 70 = get shared value */
do_sigaction, /* 71 = sigaction */
do_sigsuspend, /* 72 = sigsuspend */
do_sigpending, /* 73 = sigpending */
diff --git a/servers/procfs/pid.c b/servers/procfs/pid.c
index f37e049..a1bf8fc 100644
--- a/servers/procfs/pid.c
+++ b/servers/procfs/pid.c
@@ -47,7 +47,7 @@ static void pid_psinfo(int i)
int pi, task, state, type, p_state, f_state;
char name[PROC_NAME_LEN+1], *p;
struct vm_usage_info vui;
- pid_t ppid;
+ pid_t ppid, dpid;
pi = i - NR_TASKS;
task = proc[i].p_nr < 0;
@@ -130,6 +130,8 @@ static void pid_psinfo(int i)
else
ppid = mproc[mproc[pi].mp_parent].mp_pid;
+ dpid = mproc[pi].mp_did;
+
switch (fproc[pi].fp_blocked_on) {
case FP_BLOCKED_ON_NONE: f_state = FSTATE_NONE; break;
case FP_BLOCKED_ON_PIPE: f_state = FSTATE_PIPE; break;
@@ -141,12 +143,13 @@ static void pid_psinfo(int i)
default: f_state = FSTATE_UNKNOWN;
}
- buf_printf(" %lu %lu %lu %c %d %u %u %u %d %c %d %u",
+ buf_printf(" %lu %lu %lu %c %d %d %u %u %u %d %c %d %u",
vui.vui_total, /* total memory */
vui.vui_common, /* common memory */
vui.vui_shared, /* shared memory */
p_state, /* sleep state */
ppid, /* parent PID */
+ dpid, /* double PID */
mproc[pi].mp_realuid, /* real UID */
mproc[pi].mp_effuid, /* effective UID */
mproc[pi].mp_procgrp, /* process group */