Commit | Line | Data |
---|---|---|
cf1233e6 | 1 | /* kern_proc.c 4.58 83/02/10 */ |
961945a8 SL |
2 | |
3 | #include "../machine/reg.h" | |
4 | #include "../machine/pte.h" | |
5 | #include "../machine/psl.h" | |
29dd101b BJ |
6 | |
7 | #include "../h/param.h" | |
8 | #include "../h/systm.h" | |
9 | #include "../h/map.h" | |
29dd101b BJ |
10 | #include "../h/dir.h" |
11 | #include "../h/user.h" | |
a1bce776 | 12 | #include "../h/kernel.h" |
29dd101b BJ |
13 | #include "../h/proc.h" |
14 | #include "../h/buf.h" | |
29dd101b BJ |
15 | #include "../h/inode.h" |
16 | #include "../h/seg.h" | |
17 | #include "../h/acct.h" | |
cf1233e6 | 18 | #include "../h/wait.h" |
29dd101b BJ |
19 | #include "../h/vm.h" |
20 | #include "../h/text.h" | |
3ca1542b | 21 | #include "../h/file.h" |
feab6b5e | 22 | #include "../h/quota.h" |
4147b3f6 | 23 | #include "../h/descrip.h" |
6fd40cea | 24 | #include "../h/uio.h" |
a1bce776 | 25 | #include "../h/mbuf.h" |
4f083fd7 | 26 | #include "../h/nami.h" |
a1bce776 BJ |
27 | |
28 | gethostid() | |
29 | { | |
30 | ||
1edb1cf8 | 31 | u.u_r.r_val1 = hostid; |
a1bce776 BJ |
32 | } |
33 | ||
34 | sethostid() | |
35 | { | |
1edb1cf8 BJ |
36 | struct a { |
37 | int hostid; | |
38 | } *uap = (struct a *)u.u_ap; | |
a1bce776 | 39 | |
1edb1cf8 BJ |
40 | if (suser()) |
41 | hostid = uap->hostid; | |
42 | } | |
43 | ||
44 | gethostname() | |
45 | { | |
46 | register struct a { | |
47 | char *hostname; | |
48 | int len; | |
49 | } *uap = (struct a *)u.u_ap; | |
50 | register u_int len; | |
51 | ||
52 | len = uap->len; | |
53 | if (len > hostnamelen) | |
54 | len = hostnamelen; | |
127f7d76 | 55 | u.u_error = copyout((caddr_t)hostname, (caddr_t)uap->hostname, len); |
1edb1cf8 BJ |
56 | } |
57 | ||
58 | sethostname() | |
59 | { | |
60 | register struct a { | |
61 | char *hostname; | |
62 | u_int len; | |
63 | } *uap = (struct a *)u.u_ap; | |
64 | ||
65 | if (!suser()) | |
66 | return; | |
67 | if (uap->len > sizeof (hostname) - 1) { | |
68 | u.u_error = EINVAL; | |
69 | return; | |
70 | } | |
71 | hostnamelen = uap->len; | |
127f7d76 | 72 | u.u_error = copyin((caddr_t)uap->hostname, hostname, uap->len); |
1edb1cf8 | 73 | hostname[hostnamelen] = 0; |
a1bce776 | 74 | } |
29dd101b BJ |
75 | |
76 | /* | |
77 | * exec system call, with and without environments. | |
78 | */ | |
79 | struct execa { | |
80 | char *fname; | |
81 | char **argp; | |
82 | char **envp; | |
83 | }; | |
84 | ||
a1bce776 | 85 | execv() |
29dd101b BJ |
86 | { |
87 | ((struct execa *)u.u_ap)->envp = NULL; | |
a1bce776 | 88 | execve(); |
29dd101b BJ |
89 | } |
90 | ||
a1bce776 | 91 | execve() |
29dd101b BJ |
92 | { |
93 | register nc; | |
94 | register char *cp; | |
95 | register struct buf *bp; | |
96 | register struct execa *uap; | |
97 | int na, ne, ucp, ap, c; | |
7eeaac77 RE |
98 | int indir, uid, gid; |
99 | char *sharg; | |
29dd101b BJ |
100 | struct inode *ip; |
101 | swblk_t bno; | |
6459ebe0 | 102 | char cfname[MAXNAMLEN + 1]; |
7eeaac77 | 103 | char cfarg[SHSIZE]; |
a6b6f679 | 104 | int resid; |
29dd101b | 105 | |
4f083fd7 | 106 | if ((ip = namei(uchar, LOOKUP, 1)) == NULL) |
29dd101b BJ |
107 | return; |
108 | bno = 0; | |
109 | bp = 0; | |
7eeaac77 RE |
110 | indir = 0; |
111 | uid = u.u_uid; | |
112 | gid = u.u_gid; | |
7eeaac77 RE |
113 | if (ip->i_mode & ISUID) |
114 | uid = ip->i_uid; | |
115 | if (ip->i_mode & ISGID) | |
116 | gid = ip->i_gid; | |
117 | ||
118 | again: | |
e92a04af | 119 | if (access(ip, IEXEC)) |
29dd101b | 120 | goto bad; |
e92a04af | 121 | if ((u.u_procp->p_flag&STRC) && access(ip, IREAD)) |
eb83bf86 | 122 | goto bad; |
e92a04af | 123 | if ((ip->i_mode & IFMT) != IFREG || |
29dd101b BJ |
124 | (ip->i_mode & (IEXEC|(IEXEC>>3)|(IEXEC>>6))) == 0) { |
125 | u.u_error = EACCES; | |
126 | goto bad; | |
127 | } | |
7eeaac77 RE |
128 | |
129 | /* | |
130 | * Read in first few bytes of file for segment sizes, ux_mag: | |
131 | * 407 = plain executable | |
132 | * 410 = RO text | |
133 | * 413 = demand paged RO text | |
134 | * Also an ASCII line beginning with #! is | |
135 | * the file name of a ``shell'' and arguments may be prepended | |
136 | * to the argument list if given here. | |
137 | * | |
138 | * SHELL NAMES ARE LIMITED IN LENGTH. | |
139 | * | |
140 | * ONLY ONE ARGUMENT MAY BE PASSED TO THE SHELL FROM | |
141 | * THE ASCII LINE. | |
142 | */ | |
961945a8 | 143 | u.u_exdata.ux_shell[0] = 0; /* for zero length files */ |
a2a2a0d6 | 144 | u.u_error = rdwri(UIO_READ, ip, (caddr_t)&u.u_exdata, sizeof (u.u_exdata), |
a6b6f679 | 145 | 0, 1, &resid); |
e92a04af | 146 | if (u.u_error) |
7eeaac77 | 147 | goto bad; |
a6b6f679 | 148 | u.u_count = resid; |
a2a2a0d6 | 149 | #ifndef lint |
348d7c13 BJ |
150 | if (u.u_count > sizeof(u.u_exdata) - sizeof(u.u_exdata.Ux_A) && |
151 | u.u_exdata.ux_shell[0] != '#') { | |
7eeaac77 RE |
152 | u.u_error = ENOEXEC; |
153 | goto bad; | |
154 | } | |
a2a2a0d6 | 155 | #endif |
7eeaac77 RE |
156 | switch (u.u_exdata.ux_mag) { |
157 | ||
158 | case 0407: | |
159 | u.u_exdata.ux_dsize += u.u_exdata.ux_tsize; | |
160 | u.u_exdata.ux_tsize = 0; | |
161 | break; | |
162 | ||
163 | case 0413: | |
164 | case 0410: | |
165 | if (u.u_exdata.ux_tsize == 0) { | |
166 | u.u_error = ENOEXEC; | |
167 | goto bad; | |
168 | } | |
169 | break; | |
170 | ||
171 | default: | |
172 | if (u.u_exdata.ux_shell[0] != '#' || | |
173 | u.u_exdata.ux_shell[1] != '!' || | |
174 | indir) { | |
175 | u.u_error = ENOEXEC; | |
176 | goto bad; | |
177 | } | |
178 | cp = &u.u_exdata.ux_shell[2]; /* skip "#!" */ | |
179 | while (cp < &u.u_exdata.ux_shell[SHSIZE]) { | |
180 | if (*cp == '\t') | |
181 | *cp = ' '; | |
182 | else if (*cp == '\n') { | |
183 | *cp = '\0'; | |
184 | break; | |
185 | } | |
186 | cp++; | |
187 | } | |
188 | if (*cp != '\0') { | |
189 | u.u_error = ENOEXEC; | |
190 | goto bad; | |
191 | } | |
192 | cp = &u.u_exdata.ux_shell[2]; | |
193 | while (*cp == ' ') | |
194 | cp++; | |
195 | u.u_dirp = cp; | |
196 | while (*cp && *cp != ' ') | |
197 | cp++; | |
198 | sharg = NULL; | |
199 | if (*cp) { | |
200 | *cp++ = '\0'; | |
201 | while (*cp == ' ') | |
202 | cp++; | |
203 | if (*cp) { | |
204 | bcopy((caddr_t)cp, (caddr_t)cfarg, SHSIZE); | |
205 | sharg = cfarg; | |
206 | } | |
207 | } | |
6459ebe0 | 208 | bcopy((caddr_t)u.u_dent.d_name, (caddr_t)cfname, |
a2a2a0d6 | 209 | (unsigned)(u.u_dent.d_namlen + 1)); |
7eeaac77 RE |
210 | indir = 1; |
211 | iput(ip); | |
4f083fd7 | 212 | ip = namei(schar, LOOKUP, 1); |
7eeaac77 RE |
213 | if (ip == NULL) |
214 | return; | |
215 | goto again; | |
216 | } | |
217 | ||
29dd101b BJ |
218 | /* |
219 | * Collect arguments on "file" in swap space. | |
220 | */ | |
221 | na = 0; | |
222 | ne = 0; | |
223 | nc = 0; | |
224 | uap = (struct execa *)u.u_ap; | |
39d536e6 | 225 | if ((bno = rmalloc(argmap, (long)ctod(clrnd((int)btoc(NCARGS))))) == 0) { |
29dd101b BJ |
226 | swkill(u.u_procp, "exece"); |
227 | goto bad; | |
228 | } | |
229 | if (bno % CLSIZE) | |
b725a0ca | 230 | panic("execa rmalloc"); |
29dd101b BJ |
231 | if (uap->argp) for (;;) { |
232 | ap = NULL; | |
40d07ebb | 233 | if (indir && (na == 1 || na == 2 && sharg)) |
7eeaac77 RE |
234 | ap = (int)uap->fname; |
235 | else if (uap->argp) { | |
29dd101b BJ |
236 | ap = fuword((caddr_t)uap->argp); |
237 | uap->argp++; | |
238 | } | |
239 | if (ap==NULL && uap->envp) { | |
240 | uap->argp = NULL; | |
241 | if ((ap = fuword((caddr_t)uap->envp)) == NULL) | |
242 | break; | |
243 | uap->envp++; | |
244 | ne++; | |
245 | } | |
6459ebe0 | 246 | if (ap == NULL) |
29dd101b BJ |
247 | break; |
248 | na++; | |
e92a04af | 249 | if (ap == -1) |
29dd101b BJ |
250 | u.u_error = EFAULT; |
251 | do { | |
252 | if (nc >= NCARGS-1) | |
253 | u.u_error = E2BIG; | |
7eeaac77 RE |
254 | if (indir && na == 2 && sharg != NULL) |
255 | c = *sharg++ & 0377; | |
256 | else if ((c = fubyte((caddr_t)ap++)) < 0) | |
29dd101b | 257 | u.u_error = EFAULT; |
64d6118b BJ |
258 | if (u.u_error) { |
259 | if (bp) | |
260 | brelse(bp); | |
261 | bp = 0; | |
29dd101b | 262 | goto badarg; |
64d6118b | 263 | } |
6459ebe0 | 264 | if (nc % (CLSIZE*NBPG) == 0) { |
29dd101b BJ |
265 | if (bp) |
266 | bdwrite(bp); | |
e0fc9a90 | 267 | bp = getblk(argdev, bno + ctod(nc / NBPG), |
6459ebe0 | 268 | CLSIZE*NBPG); |
29dd101b BJ |
269 | cp = bp->b_un.b_addr; |
270 | } | |
271 | nc++; | |
272 | *cp++ = c; | |
6459ebe0 | 273 | } while (c > 0); |
29dd101b BJ |
274 | } |
275 | if (bp) | |
276 | bdwrite(bp); | |
277 | bp = 0; | |
278 | nc = (nc + NBPW-1) & ~(NBPW-1); | |
6459ebe0 KM |
279 | if (indir) { |
280 | u.u_dent.d_namlen = strlen(cfname); | |
281 | bcopy((caddr_t)cfname, (caddr_t)u.u_dent.d_name, | |
a2a2a0d6 | 282 | (unsigned)(u.u_dent.d_namlen + 1)); |
6459ebe0 | 283 | } |
7eeaac77 | 284 | getxfile(ip, nc + (na+4)*NBPW, uid, gid); |
29a06346 | 285 | if (u.u_error) { |
29dd101b | 286 | badarg: |
0981aef0 BJ |
287 | for (c = 0; c < nc; c += CLSIZE*NBPG) { |
288 | bp = baddr(argdev, bno + ctod(c / NBPG), CLSIZE*NBPG); | |
e0fc9a90 | 289 | if (bp) { |
29dd101b BJ |
290 | bp->b_flags |= B_AGE; /* throw away */ |
291 | bp->b_flags &= ~B_DELWRI; /* cancel io */ | |
292 | brelse(bp); | |
293 | bp = 0; | |
294 | } | |
0981aef0 | 295 | } |
29dd101b BJ |
296 | goto bad; |
297 | } | |
298 | ||
299 | /* | |
300 | * copy back arglist | |
301 | */ | |
29dd101b BJ |
302 | ucp = USRSTACK - nc - NBPW; |
303 | ap = ucp - na*NBPW - 3*NBPW; | |
304 | u.u_ar0[SP] = ap; | |
81263dba | 305 | (void) suword((caddr_t)ap, na-ne); |
29dd101b BJ |
306 | nc = 0; |
307 | for (;;) { | |
308 | ap += NBPW; | |
309 | if (na==ne) { | |
81263dba | 310 | (void) suword((caddr_t)ap, 0); |
29dd101b BJ |
311 | ap += NBPW; |
312 | } | |
313 | if (--na < 0) | |
314 | break; | |
81263dba | 315 | (void) suword((caddr_t)ap, ucp); |
29dd101b | 316 | do { |
6459ebe0 | 317 | if (nc % (CLSIZE*NBPG) == 0) { |
29dd101b BJ |
318 | if (bp) |
319 | brelse(bp); | |
62cd6584 | 320 | bp = bread(argdev, bno + ctod(nc / NBPG), |
6459ebe0 | 321 | CLSIZE*NBPG); |
29dd101b BJ |
322 | bp->b_flags |= B_AGE; /* throw away */ |
323 | bp->b_flags &= ~B_DELWRI; /* cancel io */ | |
324 | cp = bp->b_un.b_addr; | |
325 | } | |
81263dba | 326 | (void) subyte((caddr_t)ucp++, (c = *cp++)); |
29dd101b BJ |
327 | nc++; |
328 | } while(c&0377); | |
329 | } | |
81263dba | 330 | (void) suword((caddr_t)ap, 0); |
29dd101b BJ |
331 | setregs(); |
332 | bad: | |
333 | if (bp) | |
334 | brelse(bp); | |
335 | if (bno) | |
30c36259 | 336 | rmfree(argmap, (long)ctod(clrnd((int) btoc(NCARGS))), bno); |
29dd101b BJ |
337 | iput(ip); |
338 | } | |
339 | ||
340 | /* | |
341 | * Read in and set up memory for executed file. | |
29dd101b | 342 | */ |
7eeaac77 | 343 | getxfile(ip, nargc, uid, gid) |
29dd101b BJ |
344 | register struct inode *ip; |
345 | { | |
29dd101b | 346 | register size_t ts, ds, ss; |
7eeaac77 | 347 | int pagi; |
29dd101b | 348 | |
7eeaac77 | 349 | if (u.u_exdata.ux_mag == 0413) |
29dd101b | 350 | pagi = SPAGI; |
7eeaac77 RE |
351 | else |
352 | pagi = 0; | |
e92a04af BJ |
353 | if (u.u_exdata.ux_tsize!=0 && (ip->i_flag&ITEXT)==0 && |
354 | ip->i_count!=1) { | |
3ca1542b BJ |
355 | register struct file *fp; |
356 | ||
e92a04af | 357 | for (fp = file; fp < fileNFILE; fp++) { |
4147b3f6 | 358 | if (fp->f_type == DTYPE_FILE && |
ea726938 | 359 | fp->f_count > 0 && |
4147b3f6 | 360 | fp->f_inode == ip && (fp->f_flag&FWRITE)) { |
3ca1542b BJ |
361 | u.u_error = ETXTBSY; |
362 | goto bad; | |
363 | } | |
e92a04af | 364 | } |
29dd101b BJ |
365 | } |
366 | ||
367 | /* | |
e92a04af | 368 | * Compute text and data sizes and make sure not too large. |
29dd101b | 369 | */ |
29dd101b BJ |
370 | ts = clrnd(btoc(u.u_exdata.ux_tsize)); |
371 | ds = clrnd(btoc((u.u_exdata.ux_dsize+u.u_exdata.ux_bsize))); | |
372 | ss = clrnd(SSIZE + btoc(nargc)); | |
29a06346 BJ |
373 | if (chksize(ts, ds, ss)) |
374 | goto bad; | |
e92a04af BJ |
375 | |
376 | /* | |
377 | * Make sure enough space to start process. | |
378 | */ | |
29a06346 BJ |
379 | u.u_cdmap = zdmap; |
380 | u.u_csmap = zdmap; | |
381 | if (swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap) == NULL) | |
382 | goto bad; | |
29dd101b | 383 | |
29a06346 BJ |
384 | /* |
385 | * At this point, committed to the new image! | |
386 | * Release virtual memory resources of old process, and | |
387 | * initialize the virtual memory of the new process. | |
388 | * If we resulted from vfork(), instead wakeup our | |
389 | * parent who will set SVFDONE when he has taken back | |
390 | * our resources. | |
391 | */ | |
29a06346 BJ |
392 | if ((u.u_procp->p_flag & SVFORK) == 0) |
393 | vrelvm(); | |
394 | else { | |
395 | u.u_procp->p_flag &= ~SVFORK; | |
396 | u.u_procp->p_flag |= SKEEP; | |
397 | wakeup((caddr_t)u.u_procp); | |
398 | while ((u.u_procp->p_flag & SVFDONE) == 0) | |
399 | sleep((caddr_t)u.u_procp, PZERO - 1); | |
400 | u.u_procp->p_flag &= ~(SVFDONE|SKEEP); | |
401 | } | |
2ce421b6 | 402 | u.u_procp->p_flag &= ~(SPAGI|SSEQL|SUANOM|SNUSIG); |
29a06346 BJ |
403 | u.u_procp->p_flag |= pagi; |
404 | u.u_dmap = u.u_cdmap; | |
405 | u.u_smap = u.u_csmap; | |
406 | vgetvm(ts, ds, ss); | |
29dd101b | 407 | |
a6b6f679 | 408 | if (pagi == 0) |
a2a2a0d6 BJ |
409 | u.u_error = |
410 | rdwri(UIO_READ, ip, | |
e0fc9a90 BJ |
411 | (char *)ctob(dptov(u.u_procp, 0)), |
412 | (int)u.u_exdata.ux_dsize, | |
a2a2a0d6 BJ |
413 | (int)(sizeof(u.u_exdata)+u.u_exdata.ux_tsize), |
414 | 0, (int *)0); | |
29a06346 BJ |
415 | xalloc(ip, pagi); |
416 | if (pagi && u.u_procp->p_textp) | |
417 | vinifod((struct fpte *)dptopte(u.u_procp, 0), | |
418 | PG_FTEXT, u.u_procp->p_textp->x_iptr, | |
39d536e6 | 419 | (long)(1 + ts/CLSIZE), (int)btoc(u.u_exdata.ux_dsize)); |
29a06346 | 420 | |
e0fc9a90 | 421 | #ifdef vax |
29a06346 | 422 | /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */ |
206ecc72 | 423 | #include "../vax/mtpr.h" /* XXX */ |
29a06346 | 424 | mtpr(TBIA, 0); |
e0fc9a90 | 425 | #endif |
29a06346 | 426 | |
5b98abb9 BJ |
427 | if (u.u_error) |
428 | swkill(u.u_procp, "i/o error mapping pages"); | |
29a06346 BJ |
429 | /* |
430 | * set SUID/SGID protections, if no tracing | |
431 | */ | |
432 | if ((u.u_procp->p_flag&STRC)==0) { | |
e92a04af BJ |
433 | u.u_uid = uid; |
434 | u.u_procp->p_uid = uid; | |
7eeaac77 | 435 | u.u_gid = gid; |
39d536e6 | 436 | (void) entergroup(gid); |
29a06346 BJ |
437 | } else |
438 | psignal(u.u_procp, SIGTRAP); | |
29dd101b BJ |
439 | u.u_tsize = ts; |
440 | u.u_dsize = ds; | |
441 | u.u_ssize = ss; | |
29dd101b | 442 | bad: |
29a06346 | 443 | return; |
29dd101b BJ |
444 | } |
445 | ||
446 | /* | |
447 | * Clear registers on exec | |
448 | */ | |
449 | setregs() | |
450 | { | |
594ebedd | 451 | register int (**rp)(); |
29dd101b | 452 | register i; |
bdfe5b0f | 453 | long sigmask; |
29dd101b | 454 | |
4e6e3887 | 455 | for (rp = &u.u_signal[1], sigmask = 1L; rp < &u.u_signal[NSIG]; |
bdfe5b0f BJ |
456 | sigmask <<= 1, rp++) { |
457 | switch (*rp) { | |
458 | ||
459 | case SIG_IGN: | |
460 | case SIG_DFL: | |
461 | case SIG_HOLD: | |
462 | continue; | |
463 | ||
464 | default: | |
465 | /* | |
99fa88a2 | 466 | * Normal or deferring catch; revert to default. |
bdfe5b0f | 467 | */ |
99fa88a2 BJ |
468 | (void) spl6(); |
469 | *rp = SIG_DFL; | |
bdfe5b0f BJ |
470 | if ((int)*rp & 1) |
471 | u.u_procp->p_siga0 |= sigmask; | |
472 | else | |
a4aaef65 | 473 | u.u_procp->p_siga0 &= ~sigmask; |
bdfe5b0f BJ |
474 | if ((int)*rp & 2) |
475 | u.u_procp->p_siga1 |= sigmask; | |
476 | else | |
477 | u.u_procp->p_siga1 &= ~sigmask; | |
99fa88a2 | 478 | (void) spl0(); |
bdfe5b0f BJ |
479 | continue; |
480 | } | |
481 | } | |
e0fc9a90 | 482 | #ifdef vax |
29dd101b | 483 | /* |
e92a04af | 484 | for (rp = &u.u_ar0[0]; rp < &u.u_ar0[16];) |
29dd101b BJ |
485 | *rp++ = 0; |
486 | */ | |
e0fc9a90 BJ |
487 | u.u_ar0[PC] = u.u_exdata.ux_entloc+2; |
488 | #endif | |
489 | #ifdef sun | |
490 | { register struct regs *r = (struct regs *)u.u_ar0; | |
491 | for (i = 0; i < 8; i++) { | |
492 | r->r_dreg[i] = 0; | |
493 | if (&r->r_areg[i] != &r->r_sp) | |
494 | r->r_areg[i] = 0; | |
495 | } | |
496 | r->r_sr = PSL_USERSET; | |
497 | r->r_pc = u.u_exdata.ux_entloc; | |
498 | } | |
499 | #endif | |
e92a04af | 500 | for (i=0; i<NOFILE; i++) { |
3650c37d | 501 | if (u.u_pofile[i]&UF_EXCLOSE) { |
a81e9a81 | 502 | closef(u.u_ofile[i], 1, u.u_pofile[i]); |
29dd101b | 503 | u.u_ofile[i] = NULL; |
a81e9a81 | 504 | u.u_pofile[i] = 0; |
29dd101b | 505 | } |
e0fc9a90 | 506 | u.u_pofile[i] &= ~UF_MAPPED; |
29dd101b | 507 | } |
e92a04af | 508 | |
29dd101b BJ |
509 | /* |
510 | * Remember file name for accounting. | |
511 | */ | |
512 | u.u_acflag &= ~AFORK; | |
6459ebe0 | 513 | bcopy((caddr_t)u.u_dent.d_name, (caddr_t)u.u_comm, |
a2a2a0d6 | 514 | (unsigned)(u.u_dent.d_namlen + 1)); |
e0fc9a90 BJ |
515 | #ifdef sun |
516 | u.u_eosys = REALLYRETURN; | |
517 | #endif | |
29dd101b BJ |
518 | } |
519 | ||
520 | /* | |
e92a04af | 521 | * Exit system call: pass back caller's arg |
29dd101b BJ |
522 | */ |
523 | rexit() | |
524 | { | |
525 | register struct a { | |
526 | int rval; | |
527 | } *uap; | |
528 | ||
529 | uap = (struct a *)u.u_ap; | |
530 | exit((uap->rval & 0377) << 8); | |
531 | } | |
532 | ||
533 | /* | |
534 | * Release resources. | |
535 | * Save u. area for parent to look at. | |
536 | * Enter zombie state. | |
537 | * Wake up parent and init processes, | |
538 | * and dispose of children. | |
539 | */ | |
540 | exit(rv) | |
541 | { | |
542 | register int i; | |
543 | register struct proc *p, *q; | |
29dd101b | 544 | register int x; |
cce93e4b | 545 | struct mbuf *m = m_getclr(M_WAIT, MT_ZOMBIE); |
29dd101b BJ |
546 | |
547 | #ifdef PGINPROF | |
548 | vmsizmon(); | |
549 | #endif | |
550 | p = u.u_procp; | |
551 | p->p_flag &= ~(STRC|SULOCK); | |
552 | p->p_flag |= SWEXIT; | |
bdfe5b0f BJ |
553 | (void) spl6(); |
554 | if ((int)SIG_IGN & 1) | |
555 | p->p_siga0 = ~0; | |
556 | else | |
557 | p->p_siga0 = 0; | |
558 | if ((int)SIG_IGN & 2) | |
559 | p->p_siga1 = ~0; | |
560 | else | |
99fa88a2 | 561 | p->p_siga1 = 0; |
bdfe5b0f | 562 | (void) spl0(); |
dd808ba3 BJ |
563 | p->p_cpticks = 0; |
564 | p->p_pctcpu = 0; | |
e92a04af | 565 | for (i=0; i<NSIG; i++) |
594ebedd | 566 | u.u_signal[i] = SIG_IGN; |
b32450f4 | 567 | untimeout(realitexpire, (caddr_t)p); |
29dd101b BJ |
568 | /* |
569 | * Release virtual memory. If we resulted from | |
570 | * a vfork(), instead give the resources back to | |
571 | * the parent. | |
572 | */ | |
573 | if ((p->p_flag & SVFORK) == 0) | |
574 | vrelvm(); | |
575 | else { | |
576 | p->p_flag &= ~SVFORK; | |
577 | wakeup((caddr_t)p); | |
578 | while ((p->p_flag & SVFDONE) == 0) | |
579 | sleep((caddr_t)p, PZERO - 1); | |
580 | p->p_flag &= ~SVFDONE; | |
581 | } | |
a81e9a81 | 582 | for (i = 0; i < NOFILE; i++) { |
c5c236f8 SL |
583 | struct file *f; |
584 | int p; | |
585 | ||
29dd101b BJ |
586 | f = u.u_ofile[i]; |
587 | u.u_ofile[i] = NULL; | |
c5c236f8 | 588 | p = u.u_pofile[i]; |
a81e9a81 | 589 | u.u_pofile[i] = 0; |
c5c236f8 | 590 | closef(f, 1, p); |
29dd101b | 591 | } |
e92a04af | 592 | ilock(u.u_cdir); |
29dd101b BJ |
593 | iput(u.u_cdir); |
594 | if (u.u_rdir) { | |
e92a04af | 595 | ilock(u.u_rdir); |
29dd101b BJ |
596 | iput(u.u_rdir); |
597 | } | |
a1bce776 | 598 | u.u_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; |
29dd101b | 599 | acct(); |
feab6b5e RE |
600 | #ifdef QUOTA |
601 | qclean(); | |
e0fc9a90 BJ |
602 | #endif |
603 | #ifdef sun | |
604 | ctxfree(&u); | |
feab6b5e | 605 | #endif |
29dd101b BJ |
606 | vrelpt(u.u_procp); |
607 | vrelu(u.u_procp, 0); | |
f12a8410 | 608 | (void) spl5(); /* hack for mem alloc race XXX */ |
29dd101b | 609 | multprog--; |
29dd101b | 610 | p->p_stat = SZOMB; |
42343c0f | 611 | noproc = 1; |
29dd101b BJ |
612 | i = PIDHASH(p->p_pid); |
613 | x = p - proc; | |
614 | if (pidhash[i] == x) | |
615 | pidhash[i] = p->p_idhash; | |
616 | else { | |
617 | for (i = pidhash[i]; i != 0; i = proc[i].p_idhash) | |
618 | if (proc[i].p_idhash == x) { | |
619 | proc[i].p_idhash = p->p_idhash; | |
620 | goto done; | |
621 | } | |
622 | panic("exit"); | |
623 | } | |
9c82b9fd BJ |
624 | if (p->p_pid == 1) |
625 | panic("init died"); | |
29dd101b | 626 | done: |
a1bce776 | 627 | p->p_xstat = rv; |
c5c236f8 SL |
628 | if (m == 0) |
629 | panic("exit: m_getclr"); | |
8c2b0bcd | 630 | p->p_ru = mtod(m, struct rusage *); |
a1bce776 BJ |
631 | *p->p_ru = u.u_ru; |
632 | ruadd(p->p_ru, &u.u_cru); | |
e92a04af BJ |
633 | for (q = proc; q < procNPROC; q++) |
634 | if (q->p_pptr == p) { | |
feab6b5e RE |
635 | if (q->p_osptr) |
636 | q->p_osptr->p_ysptr = q->p_ysptr; | |
637 | if (q->p_ysptr) | |
638 | q->p_ysptr->p_osptr = q->p_osptr; | |
639 | if (proc[1].p_cptr) | |
640 | proc[1].p_cptr->p_ysptr = q; | |
641 | q->p_osptr = proc[1].p_cptr; | |
642 | q->p_ysptr = NULL; | |
643 | proc[1].p_cptr = q; | |
644 | ||
bdfe5b0f | 645 | q->p_pptr = &proc[1]; |
29dd101b | 646 | q->p_ppid = 1; |
bdfe5b0f BJ |
647 | wakeup((caddr_t)&proc[1]); |
648 | /* | |
0dde1c43 | 649 | * Traced processes are killed |
bdfe5b0f | 650 | * since their existence means someone is screwing up. |
62bac59f | 651 | * Stopped processes are sent a hangup and a continue. |
0dde1c43 BJ |
652 | * This is designed to be ``safe'' for setuid |
653 | * processes since they must be willing to tolerate | |
654 | * hangups anyways. | |
bdfe5b0f | 655 | */ |
0dde1c43 | 656 | if (q->p_flag&STRC) { |
bdfe5b0f BJ |
657 | q->p_flag &= ~STRC; |
658 | psignal(q, SIGKILL); | |
0dde1c43 BJ |
659 | } else if (q->p_stat == SSTOP) { |
660 | psignal(q, SIGHUP); | |
661 | psignal(q, SIGCONT); | |
bdfe5b0f | 662 | } |
8643403f BJ |
663 | /* |
664 | * Protect this process from future | |
7ac93404 | 665 | * tty signals, clear TSTP/TTIN/TTOU if pending. |
8643403f | 666 | */ |
934e4ecf | 667 | (void) spgrp(q, -1); |
29dd101b | 668 | } |
bdfe5b0f | 669 | psignal(p->p_pptr, SIGCHLD); |
4e6e3887 | 670 | wakeup((caddr_t)p->p_pptr); |
29dd101b BJ |
671 | swtch(); |
672 | } | |
673 | ||
8ec6ce7a SL |
674 | wait() |
675 | { | |
676 | struct rusage ru, *rup; | |
677 | ||
678 | if ((u.u_ar0[PS] & PSL_ALLCC) != PSL_ALLCC) { | |
679 | u.u_error = wait1(0, (struct rusage *)0); | |
680 | return; | |
681 | } | |
682 | rup = (struct rusage *)u.u_ar0[R1]; | |
683 | u.u_error = wait1(u.u_ar0[R0], &ru); | |
684 | if (u.u_error) | |
685 | return; | |
686 | (void) copyout((caddr_t)&ru, (caddr_t)rup, sizeof (struct rusage)); | |
687 | } | |
688 | ||
689 | #ifndef NOCOMPAT | |
961945a8 | 690 | #include "../h/vtimes.h" |
3269c554 | 691 | |
1edb1cf8 | 692 | owait() |
29dd101b | 693 | { |
3269c554 BJ |
694 | struct rusage ru; |
695 | struct vtimes *vtp, avt; | |
29dd101b | 696 | |
bdfe5b0f | 697 | if ((u.u_ar0[PS] & PSL_ALLCC) != PSL_ALLCC) { |
8ec6ce7a | 698 | u.u_error = wait1(0, (struct rusage *)0); |
bdfe5b0f BJ |
699 | return; |
700 | } | |
3269c554 | 701 | vtp = (struct vtimes *)u.u_ar0[R1]; |
8ec6ce7a | 702 | u.u_error = wait1(u.u_ar0[R0], &ru); |
bdfe5b0f BJ |
703 | if (u.u_error) |
704 | return; | |
3269c554 BJ |
705 | getvtimes(&ru, &avt); |
706 | (void) copyout((caddr_t)&avt, (caddr_t)vtp, sizeof (struct vtimes)); | |
29dd101b | 707 | } |
8ec6ce7a | 708 | #endif |
29dd101b BJ |
709 | |
710 | /* | |
711 | * Wait system call. | |
712 | * Search for a terminated (zombie) child, | |
713 | * finally lay it to rest, and collect its status. | |
714 | * Look also for stopped (traced) children, | |
715 | * and pass back status from them. | |
716 | */ | |
a1bce776 BJ |
717 | wait1(options, ru) |
718 | register int options; | |
719 | struct rusage *ru; | |
29dd101b BJ |
720 | { |
721 | register f; | |
feab6b5e | 722 | register struct proc *p, *q; |
29dd101b BJ |
723 | |
724 | f = 0; | |
29dd101b | 725 | loop: |
e92a04af BJ |
726 | for (p = proc; p < procNPROC; p++) |
727 | if (p->p_pptr == u.u_procp) { | |
29dd101b | 728 | f++; |
e92a04af | 729 | if (p->p_stat == SZOMB) { |
29dd101b | 730 | u.u_r.r_val1 = p->p_pid; |
a1bce776 BJ |
731 | u.u_r.r_val2 = p->p_xstat; |
732 | p->p_xstat = 0; | |
733 | if (ru) | |
734 | *ru = *p->p_ru; | |
735 | ruadd(&u.u_cru, p->p_ru); | |
39d536e6 | 736 | (void) m_free(dtom(p->p_ru)); |
a1bce776 | 737 | p->p_ru = 0; |
29dd101b BJ |
738 | p->p_stat = NULL; |
739 | p->p_pid = 0; | |
740 | p->p_ppid = 0; | |
feab6b5e RE |
741 | if (q = p->p_ysptr) |
742 | q->p_osptr = p->p_osptr; | |
743 | if (q = p->p_osptr) | |
744 | q->p_ysptr = p->p_ysptr; | |
745 | if ((q = p->p_pptr)->p_cptr == p) | |
746 | q->p_cptr = p->p_osptr; | |
bdfe5b0f | 747 | p->p_pptr = 0; |
feab6b5e RE |
748 | p->p_ysptr = 0; |
749 | p->p_osptr = 0; | |
750 | p->p_cptr = 0; | |
29dd101b | 751 | p->p_sig = 0; |
bdfe5b0f BJ |
752 | p->p_siga0 = 0; |
753 | p->p_siga1 = 0; | |
29dd101b BJ |
754 | p->p_pgrp = 0; |
755 | p->p_flag = 0; | |
756 | p->p_wchan = 0; | |
bdfe5b0f | 757 | p->p_cursig = 0; |
8ec6ce7a | 758 | return (0); |
29dd101b | 759 | } |
bdfe5b0f BJ |
760 | if (p->p_stat == SSTOP && (p->p_flag&SWTED)==0 && |
761 | (p->p_flag&STRC || options&WUNTRACED)) { | |
762 | p->p_flag |= SWTED; | |
763 | u.u_r.r_val1 = p->p_pid; | |
764 | u.u_r.r_val2 = (p->p_cursig<<8) | WSTOPPED; | |
8ec6ce7a | 765 | return (0); |
29dd101b BJ |
766 | } |
767 | } | |
8ec6ce7a SL |
768 | if (f == 0) { |
769 | return (ECHILD); | |
bdfe5b0f BJ |
770 | } |
771 | if (options&WNOHANG) { | |
772 | u.u_r.r_val1 = 0; | |
8ec6ce7a | 773 | return (0); |
bdfe5b0f | 774 | } |
f9c5db19 | 775 | if ((u.u_procp->p_flag&SNUSIG) && setjmp(&u.u_qsave)) { |
bdfe5b0f | 776 | u.u_eosys = RESTARTSYS; |
8ec6ce7a | 777 | return (0); |
29dd101b | 778 | } |
bdfe5b0f BJ |
779 | sleep((caddr_t)u.u_procp, PWAIT); |
780 | goto loop; | |
29dd101b BJ |
781 | } |
782 | ||
783 | /* | |
784 | * fork system call. | |
785 | */ | |
786 | fork() | |
787 | { | |
788 | ||
789 | u.u_cdmap = zdmap; | |
790 | u.u_csmap = zdmap; | |
791 | if (swpexpand(u.u_dsize, u.u_ssize, &u.u_cdmap, &u.u_csmap) == 0) { | |
792 | u.u_r.r_val2 = 0; | |
793 | return; | |
794 | } | |
795 | fork1(0); | |
796 | } | |
797 | ||
798 | fork1(isvfork) | |
799 | { | |
800 | register struct proc *p1, *p2; | |
feab6b5e | 801 | #ifndef QUOTA |
29dd101b BJ |
802 | register a; |
803 | ||
804 | a = 0; | |
feab6b5e RE |
805 | #else |
806 | if (u.u_quota != NOQUOT && u.u_quota->q_plim && | |
807 | u.u_quota->q_cnt >= u.u_quota->q_plim) { | |
808 | u.u_error = EPROCLIM; | |
809 | return; | |
810 | } | |
811 | #endif | |
29dd101b | 812 | p2 = NULL; |
e92a04af | 813 | for (p1 = proc; p1 < procNPROC; p1++) { |
feab6b5e RE |
814 | #ifdef QUOTA |
815 | if (p1->p_stat == NULL) { | |
816 | p2 = p1; | |
817 | break; | |
818 | } | |
819 | #else | |
29dd101b BJ |
820 | if (p1->p_stat==NULL && p2==NULL) |
821 | p2 = p1; | |
822 | else { | |
823 | if (p1->p_uid==u.u_uid && p1->p_stat!=NULL) | |
824 | a++; | |
825 | } | |
feab6b5e | 826 | #endif |
29dd101b BJ |
827 | } |
828 | /* | |
829 | * Disallow if | |
830 | * No processes at all; | |
831 | * not su and too many procs owned; or | |
832 | * not su and would take last slot. | |
833 | */ | |
62901f34 BJ |
834 | if (p2==NULL) |
835 | tablefull("proc"); | |
feab6b5e RE |
836 | #ifdef QUOTA |
837 | if (p2==NULL || (u.u_uid!=0 && p2==procNPROC-1)) { | |
838 | #else | |
86fd527f | 839 | if (p2==NULL || (u.u_uid!=0 && (p2==procNPROC-1 || a>MAXUPRC))) { |
feab6b5e | 840 | #endif |
29dd101b BJ |
841 | u.u_error = EAGAIN; |
842 | if (!isvfork) { | |
81263dba BJ |
843 | (void) vsexpand(0, &u.u_cdmap, 1); |
844 | (void) vsexpand(0, &u.u_csmap, 1); | |
29dd101b BJ |
845 | } |
846 | goto out; | |
847 | } | |
848 | p1 = u.u_procp; | |
e92a04af | 849 | if (newproc(isvfork)) { |
29dd101b BJ |
850 | u.u_r.r_val1 = p1->p_pid; |
851 | u.u_r.r_val2 = 1; /* child */ | |
a1bce776 | 852 | u.u_start = time.tv_sec; |
29dd101b | 853 | u.u_acflag = AFORK; |
feab6b5e RE |
854 | #ifdef QUOTA |
855 | u.u_qflags &= ~QUF_LOGIN; | |
856 | #endif | |
29dd101b BJ |
857 | return; |
858 | } | |
859 | u.u_r.r_val1 = p2->p_pid; | |
860 | ||
861 | out: | |
862 | u.u_r.r_val2 = 0; | |
863 | } | |
864 | ||
4147b3f6 BJ |
865 | spgrp(top, npgrp) |
866 | register struct proc *top; | |
867 | { | |
868 | register struct proc *pp, *p; | |
869 | int f = 0; | |
870 | ||
871 | for (p = top; npgrp == -1 || u.u_uid == p->p_uid || | |
872 | !u.u_uid || inferior(p); p = pp) { | |
873 | if (npgrp == -1) { | |
874 | #define bit(a) (1<<(a-1)) | |
875 | p->p_sig &= ~(bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU)); | |
876 | } else | |
877 | p->p_pgrp = npgrp; | |
878 | f++; | |
879 | /* | |
880 | * Search for children. | |
881 | */ | |
882 | for (pp = proc; pp < procNPROC; pp++) | |
883 | if (pp->p_pptr == p) | |
884 | goto cont; | |
885 | /* | |
886 | * Search for siblings. | |
887 | */ | |
888 | for (; p != top; p = p->p_pptr) | |
889 | for (pp = p + 1; pp < procNPROC; pp++) | |
890 | if (pp->p_pptr == p->p_pptr) | |
891 | goto cont; | |
892 | break; | |
893 | cont: | |
894 | ; | |
895 | } | |
896 | return (f); | |
897 | } | |
898 | ||
29dd101b | 899 | /* |
4147b3f6 | 900 | * Is p an inferior of the current process? |
29dd101b | 901 | */ |
4147b3f6 | 902 | inferior(p) |
a2a2a0d6 | 903 | register struct proc *p; |
29dd101b | 904 | { |
29dd101b | 905 | |
4147b3f6 BJ |
906 | for (; p != u.u_procp; p = p->p_pptr) |
907 | if (p->p_ppid == 0) | |
908 | return (0); | |
909 | return (1); | |
29dd101b | 910 | } |
a2a2a0d6 BJ |
911 | |
912 | struct proc * | |
913 | pfind(pid) | |
914 | int pid; | |
915 | { | |
916 | register struct proc *p; | |
917 | ||
918 | for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash]) | |
919 | if (p->p_pid == pid) | |
920 | return (p); | |
921 | return ((struct proc *)0); | |
922 | } | |
1edb1cf8 BJ |
923 | |
924 | /* | |
925 | * Create a new process-- the internal version of | |
926 | * sys fork. | |
927 | * It returns 1 in the new process, 0 in the old. | |
928 | */ | |
929 | newproc(isvfork) | |
930 | int isvfork; | |
931 | { | |
932 | register struct proc *p; | |
933 | register struct proc *rpp, *rip; | |
934 | register int n; | |
935 | register struct file *fp; | |
936 | ||
937 | p = NULL; | |
938 | /* | |
939 | * First, just locate a slot for a process | |
940 | * and copy the useful info from this process into it. | |
941 | * The panic "cannot happen" because fork has already | |
942 | * checked for the existence of a slot. | |
943 | */ | |
944 | retry: | |
945 | mpid++; | |
946 | if (mpid >= 30000) { | |
947 | mpid = 0; | |
948 | goto retry; | |
949 | } | |
950 | for (rpp = proc; rpp < procNPROC; rpp++) { | |
951 | if (rpp->p_stat == NULL && p==NULL) | |
952 | p = rpp; | |
953 | if (rpp->p_pid==mpid || rpp->p_pgrp==mpid) | |
954 | goto retry; | |
955 | } | |
956 | if ((rpp = p) == NULL) | |
957 | panic("no procs"); | |
958 | ||
959 | /* | |
960 | * Make a proc table entry for the new process. | |
961 | */ | |
962 | rip = u.u_procp; | |
963 | #ifdef QUOTA | |
964 | (rpp->p_quota = rip->p_quota)->q_cnt++; | |
965 | #endif | |
966 | rpp->p_stat = SIDL; | |
967 | timerclear(&rpp->p_realtimer.it_value); | |
968 | rpp->p_flag = SLOAD | (rip->p_flag & (SPAGI|SNUSIG)); | |
969 | if (isvfork) { | |
970 | rpp->p_flag |= SVFORK; | |
971 | rpp->p_ndx = rip->p_ndx; | |
972 | } else | |
973 | rpp->p_ndx = rpp - proc; | |
974 | rpp->p_uid = rip->p_uid; | |
975 | rpp->p_pgrp = rip->p_pgrp; | |
976 | rpp->p_nice = rip->p_nice; | |
977 | rpp->p_textp = isvfork ? 0 : rip->p_textp; | |
978 | rpp->p_pid = mpid; | |
979 | rpp->p_ppid = rip->p_pid; | |
980 | rpp->p_pptr = rip; | |
981 | rpp->p_osptr = rip->p_cptr; | |
982 | if (rip->p_cptr) | |
983 | rip->p_cptr->p_ysptr = rpp; | |
984 | rpp->p_ysptr = NULL; | |
985 | rpp->p_cptr = NULL; | |
986 | rip->p_cptr = rpp; | |
987 | rpp->p_time = 0; | |
988 | rpp->p_cpu = 0; | |
989 | rpp->p_siga0 = rip->p_siga0; | |
990 | rpp->p_siga1 = rip->p_siga1; | |
991 | /* take along any pending signals, like stops? */ | |
992 | if (isvfork) { | |
993 | rpp->p_tsize = rpp->p_dsize = rpp->p_ssize = 0; | |
994 | rpp->p_szpt = clrnd(ctopt(UPAGES)); | |
995 | forkstat.cntvfork++; | |
996 | forkstat.sizvfork += rip->p_dsize + rip->p_ssize; | |
997 | } else { | |
998 | rpp->p_tsize = rip->p_tsize; | |
999 | rpp->p_dsize = rip->p_dsize; | |
1000 | rpp->p_ssize = rip->p_ssize; | |
1001 | rpp->p_szpt = rip->p_szpt; | |
1002 | forkstat.cntfork++; | |
1003 | forkstat.sizfork += rip->p_dsize + rip->p_ssize; | |
1004 | } | |
1005 | rpp->p_rssize = 0; | |
1006 | rpp->p_maxrss = rip->p_maxrss; | |
1007 | rpp->p_wchan = 0; | |
1008 | rpp->p_slptime = 0; | |
1009 | rpp->p_pctcpu = 0; | |
1010 | rpp->p_cpticks = 0; | |
1011 | n = PIDHASH(rpp->p_pid); | |
1012 | p->p_idhash = pidhash[n]; | |
1013 | pidhash[n] = rpp - proc; | |
1014 | multprog++; | |
1015 | ||
1016 | /* | |
1017 | * Increase reference counts on shared objects. | |
1018 | */ | |
1019 | for (n = 0; n < NOFILE; n++) { | |
1020 | fp = u.u_ofile[n]; | |
1021 | if (fp == NULL) | |
1022 | continue; | |
1023 | fp->f_count++; | |
3650c37d | 1024 | if (u.u_pofile[n]&UF_SHLOCK) |
4f083fd7 | 1025 | fp->f_inode->i_shlockc++; |
3650c37d | 1026 | if (u.u_pofile[n]&UF_EXLOCK) |
4f083fd7 | 1027 | fp->f_inode->i_exlockc++; |
1edb1cf8 BJ |
1028 | } |
1029 | u.u_cdir->i_count++; | |
1030 | if (u.u_rdir) | |
1031 | u.u_rdir->i_count++; | |
1032 | ||
1033 | /* | |
1034 | * Partially simulate the environment | |
1035 | * of the new process so that when it is actually | |
1036 | * created (by copying) it will look right. | |
1037 | * This begins the section where we must prevent the parent | |
1038 | * from being swapped. | |
1039 | */ | |
1040 | rip->p_flag |= SKEEP; | |
1041 | if (procdup(rpp, isvfork)) | |
1042 | return (1); | |
1043 | ||
1044 | /* | |
1045 | * Make child runnable and add to run queue. | |
1046 | */ | |
1047 | (void) spl6(); | |
1048 | rpp->p_stat = SRUN; | |
1049 | setrq(rpp); | |
1050 | (void) spl0(); | |
1051 | ||
1052 | /* | |
1053 | * Cause child to take a non-local goto as soon as it runs. | |
1054 | * On older systems this was done with SSWAP bit in proc | |
1055 | * table; on VAX we use u.u_pcb.pcb_sswap so don't need | |
1056 | * to do rpp->p_flag |= SSWAP. Actually do nothing here. | |
1057 | */ | |
1058 | /* rpp->p_flag |= SSWAP; */ | |
1059 | ||
1060 | /* | |
1061 | * Now can be swapped. | |
1062 | */ | |
1063 | rip->p_flag &= ~SKEEP; | |
1064 | ||
1065 | /* | |
1066 | * If vfork make chain from parent process to child | |
1067 | * (where virtal memory is temporarily). Wait for | |
1068 | * child to finish, steal virtual memory back, | |
1069 | * and wakeup child to let it die. | |
1070 | */ | |
1071 | if (isvfork) { | |
1072 | u.u_procp->p_xlink = rpp; | |
1073 | u.u_procp->p_flag |= SNOVM; | |
1074 | while (rpp->p_flag & SVFORK) | |
1075 | sleep((caddr_t)rpp, PZERO - 1); | |
1076 | if ((rpp->p_flag & SLOAD) == 0) | |
1077 | panic("newproc vfork"); | |
1078 | uaccess(rpp, Vfmap, &vfutl); | |
1079 | u.u_procp->p_xlink = 0; | |
1080 | vpassvm(rpp, u.u_procp, &vfutl, &u, Vfmap); | |
1081 | u.u_procp->p_flag &= ~SNOVM; | |
1082 | rpp->p_ndx = rpp - proc; | |
1083 | rpp->p_flag |= SVFDONE; | |
1084 | wakeup((caddr_t)rpp); | |
1085 | } | |
1086 | ||
1087 | /* | |
1088 | * 0 return means parent. | |
1089 | */ | |
1090 | return (0); | |
1091 | } |