Commit | Line | Data |
---|---|---|
127f7d76 | 1 | /* kern_proc.c 4.56 82/12/28 */ |
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" | |
e0fc9a90 | 18 | #include <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 BJ |
330 | (void) suword((caddr_t)ap, 0); |
331 | (void) suword((caddr_t)ucp, 0); | |
29dd101b BJ |
332 | setregs(); |
333 | bad: | |
334 | if (bp) | |
335 | brelse(bp); | |
336 | if (bno) | |
30c36259 | 337 | rmfree(argmap, (long)ctod(clrnd((int) btoc(NCARGS))), bno); |
29dd101b BJ |
338 | iput(ip); |
339 | } | |
340 | ||
341 | /* | |
342 | * Read in and set up memory for executed file. | |
29dd101b | 343 | */ |
7eeaac77 | 344 | getxfile(ip, nargc, uid, gid) |
29dd101b BJ |
345 | register struct inode *ip; |
346 | { | |
29dd101b | 347 | register size_t ts, ds, ss; |
7eeaac77 | 348 | int pagi; |
29dd101b | 349 | |
7eeaac77 | 350 | if (u.u_exdata.ux_mag == 0413) |
29dd101b | 351 | pagi = SPAGI; |
7eeaac77 RE |
352 | else |
353 | pagi = 0; | |
e92a04af BJ |
354 | if (u.u_exdata.ux_tsize!=0 && (ip->i_flag&ITEXT)==0 && |
355 | ip->i_count!=1) { | |
3ca1542b BJ |
356 | register struct file *fp; |
357 | ||
e92a04af | 358 | for (fp = file; fp < fileNFILE; fp++) { |
4147b3f6 | 359 | if (fp->f_type == DTYPE_FILE && |
ea726938 | 360 | fp->f_count > 0 && |
4147b3f6 | 361 | fp->f_inode == ip && (fp->f_flag&FWRITE)) { |
3ca1542b BJ |
362 | u.u_error = ETXTBSY; |
363 | goto bad; | |
364 | } | |
e92a04af | 365 | } |
29dd101b BJ |
366 | } |
367 | ||
368 | /* | |
e92a04af | 369 | * Compute text and data sizes and make sure not too large. |
29dd101b | 370 | */ |
29dd101b BJ |
371 | ts = clrnd(btoc(u.u_exdata.ux_tsize)); |
372 | ds = clrnd(btoc((u.u_exdata.ux_dsize+u.u_exdata.ux_bsize))); | |
373 | ss = clrnd(SSIZE + btoc(nargc)); | |
29a06346 BJ |
374 | if (chksize(ts, ds, ss)) |
375 | goto bad; | |
e92a04af BJ |
376 | |
377 | /* | |
378 | * Make sure enough space to start process. | |
379 | */ | |
29a06346 BJ |
380 | u.u_cdmap = zdmap; |
381 | u.u_csmap = zdmap; | |
382 | if (swpexpand(ds, ss, &u.u_cdmap, &u.u_csmap) == NULL) | |
383 | goto bad; | |
29dd101b | 384 | |
29a06346 BJ |
385 | /* |
386 | * At this point, committed to the new image! | |
387 | * Release virtual memory resources of old process, and | |
388 | * initialize the virtual memory of the new process. | |
389 | * If we resulted from vfork(), instead wakeup our | |
390 | * parent who will set SVFDONE when he has taken back | |
391 | * our resources. | |
392 | */ | |
29a06346 BJ |
393 | if ((u.u_procp->p_flag & SVFORK) == 0) |
394 | vrelvm(); | |
395 | else { | |
396 | u.u_procp->p_flag &= ~SVFORK; | |
397 | u.u_procp->p_flag |= SKEEP; | |
398 | wakeup((caddr_t)u.u_procp); | |
399 | while ((u.u_procp->p_flag & SVFDONE) == 0) | |
400 | sleep((caddr_t)u.u_procp, PZERO - 1); | |
401 | u.u_procp->p_flag &= ~(SVFDONE|SKEEP); | |
402 | } | |
2ce421b6 | 403 | u.u_procp->p_flag &= ~(SPAGI|SSEQL|SUANOM|SNUSIG); |
29a06346 BJ |
404 | u.u_procp->p_flag |= pagi; |
405 | u.u_dmap = u.u_cdmap; | |
406 | u.u_smap = u.u_csmap; | |
407 | vgetvm(ts, ds, ss); | |
29dd101b | 408 | |
a6b6f679 | 409 | if (pagi == 0) |
a2a2a0d6 BJ |
410 | u.u_error = |
411 | rdwri(UIO_READ, ip, | |
e0fc9a90 BJ |
412 | (char *)ctob(dptov(u.u_procp, 0)), |
413 | (int)u.u_exdata.ux_dsize, | |
a2a2a0d6 BJ |
414 | (int)(sizeof(u.u_exdata)+u.u_exdata.ux_tsize), |
415 | 0, (int *)0); | |
29a06346 BJ |
416 | xalloc(ip, pagi); |
417 | if (pagi && u.u_procp->p_textp) | |
418 | vinifod((struct fpte *)dptopte(u.u_procp, 0), | |
419 | PG_FTEXT, u.u_procp->p_textp->x_iptr, | |
39d536e6 | 420 | (long)(1 + ts/CLSIZE), (int)btoc(u.u_exdata.ux_dsize)); |
29a06346 | 421 | |
e0fc9a90 | 422 | #ifdef vax |
29a06346 | 423 | /* THIS SHOULD BE DONE AT A LOWER LEVEL, IF AT ALL */ |
206ecc72 | 424 | #include "../vax/mtpr.h" /* XXX */ |
29a06346 | 425 | mtpr(TBIA, 0); |
e0fc9a90 | 426 | #endif |
29a06346 | 427 | |
5b98abb9 BJ |
428 | if (u.u_error) |
429 | swkill(u.u_procp, "i/o error mapping pages"); | |
29a06346 BJ |
430 | /* |
431 | * set SUID/SGID protections, if no tracing | |
432 | */ | |
433 | if ((u.u_procp->p_flag&STRC)==0) { | |
e92a04af BJ |
434 | u.u_uid = uid; |
435 | u.u_procp->p_uid = uid; | |
7eeaac77 | 436 | u.u_gid = gid; |
39d536e6 | 437 | (void) entergroup(gid); |
29a06346 BJ |
438 | } else |
439 | psignal(u.u_procp, SIGTRAP); | |
29dd101b BJ |
440 | u.u_tsize = ts; |
441 | u.u_dsize = ds; | |
442 | u.u_ssize = ss; | |
29dd101b | 443 | bad: |
29a06346 | 444 | return; |
29dd101b BJ |
445 | } |
446 | ||
447 | /* | |
448 | * Clear registers on exec | |
449 | */ | |
450 | setregs() | |
451 | { | |
594ebedd | 452 | register int (**rp)(); |
29dd101b | 453 | register i; |
bdfe5b0f | 454 | long sigmask; |
29dd101b | 455 | |
4e6e3887 | 456 | for (rp = &u.u_signal[1], sigmask = 1L; rp < &u.u_signal[NSIG]; |
bdfe5b0f BJ |
457 | sigmask <<= 1, rp++) { |
458 | switch (*rp) { | |
459 | ||
460 | case SIG_IGN: | |
461 | case SIG_DFL: | |
462 | case SIG_HOLD: | |
463 | continue; | |
464 | ||
465 | default: | |
466 | /* | |
99fa88a2 | 467 | * Normal or deferring catch; revert to default. |
bdfe5b0f | 468 | */ |
99fa88a2 BJ |
469 | (void) spl6(); |
470 | *rp = SIG_DFL; | |
bdfe5b0f BJ |
471 | if ((int)*rp & 1) |
472 | u.u_procp->p_siga0 |= sigmask; | |
473 | else | |
a4aaef65 | 474 | u.u_procp->p_siga0 &= ~sigmask; |
bdfe5b0f BJ |
475 | if ((int)*rp & 2) |
476 | u.u_procp->p_siga1 |= sigmask; | |
477 | else | |
478 | u.u_procp->p_siga1 &= ~sigmask; | |
99fa88a2 | 479 | (void) spl0(); |
bdfe5b0f BJ |
480 | continue; |
481 | } | |
482 | } | |
e0fc9a90 | 483 | #ifdef vax |
29dd101b | 484 | /* |
e92a04af | 485 | for (rp = &u.u_ar0[0]; rp < &u.u_ar0[16];) |
29dd101b BJ |
486 | *rp++ = 0; |
487 | */ | |
e0fc9a90 BJ |
488 | u.u_ar0[PC] = u.u_exdata.ux_entloc+2; |
489 | #endif | |
490 | #ifdef sun | |
491 | { register struct regs *r = (struct regs *)u.u_ar0; | |
492 | for (i = 0; i < 8; i++) { | |
493 | r->r_dreg[i] = 0; | |
494 | if (&r->r_areg[i] != &r->r_sp) | |
495 | r->r_areg[i] = 0; | |
496 | } | |
497 | r->r_sr = PSL_USERSET; | |
498 | r->r_pc = u.u_exdata.ux_entloc; | |
499 | } | |
500 | #endif | |
e92a04af | 501 | for (i=0; i<NOFILE; i++) { |
3650c37d | 502 | if (u.u_pofile[i]&UF_EXCLOSE) { |
a81e9a81 | 503 | closef(u.u_ofile[i], 1, u.u_pofile[i]); |
29dd101b | 504 | u.u_ofile[i] = NULL; |
a81e9a81 | 505 | u.u_pofile[i] = 0; |
29dd101b | 506 | } |
e0fc9a90 | 507 | u.u_pofile[i] &= ~UF_MAPPED; |
29dd101b | 508 | } |
e92a04af | 509 | |
29dd101b BJ |
510 | /* |
511 | * Remember file name for accounting. | |
512 | */ | |
513 | u.u_acflag &= ~AFORK; | |
6459ebe0 | 514 | bcopy((caddr_t)u.u_dent.d_name, (caddr_t)u.u_comm, |
a2a2a0d6 | 515 | (unsigned)(u.u_dent.d_namlen + 1)); |
e0fc9a90 BJ |
516 | #ifdef sun |
517 | u.u_eosys = REALLYRETURN; | |
518 | #endif | |
29dd101b BJ |
519 | } |
520 | ||
521 | /* | |
e92a04af | 522 | * Exit system call: pass back caller's arg |
29dd101b BJ |
523 | */ |
524 | rexit() | |
525 | { | |
526 | register struct a { | |
527 | int rval; | |
528 | } *uap; | |
529 | ||
530 | uap = (struct a *)u.u_ap; | |
531 | exit((uap->rval & 0377) << 8); | |
532 | } | |
533 | ||
534 | /* | |
535 | * Release resources. | |
536 | * Save u. area for parent to look at. | |
537 | * Enter zombie state. | |
538 | * Wake up parent and init processes, | |
539 | * and dispose of children. | |
540 | */ | |
541 | exit(rv) | |
542 | { | |
543 | register int i; | |
544 | register struct proc *p, *q; | |
29dd101b | 545 | register int x; |
cce93e4b | 546 | struct mbuf *m = m_getclr(M_WAIT, MT_ZOMBIE); |
29dd101b BJ |
547 | |
548 | #ifdef PGINPROF | |
549 | vmsizmon(); | |
550 | #endif | |
551 | p = u.u_procp; | |
552 | p->p_flag &= ~(STRC|SULOCK); | |
553 | p->p_flag |= SWEXIT; | |
bdfe5b0f BJ |
554 | (void) spl6(); |
555 | if ((int)SIG_IGN & 1) | |
556 | p->p_siga0 = ~0; | |
557 | else | |
558 | p->p_siga0 = 0; | |
559 | if ((int)SIG_IGN & 2) | |
560 | p->p_siga1 = ~0; | |
561 | else | |
99fa88a2 | 562 | p->p_siga1 = 0; |
bdfe5b0f | 563 | (void) spl0(); |
dd808ba3 BJ |
564 | p->p_cpticks = 0; |
565 | p->p_pctcpu = 0; | |
e92a04af | 566 | for (i=0; i<NSIG; i++) |
594ebedd | 567 | u.u_signal[i] = SIG_IGN; |
b32450f4 | 568 | untimeout(realitexpire, (caddr_t)p); |
29dd101b BJ |
569 | /* |
570 | * Release virtual memory. If we resulted from | |
571 | * a vfork(), instead give the resources back to | |
572 | * the parent. | |
573 | */ | |
574 | if ((p->p_flag & SVFORK) == 0) | |
575 | vrelvm(); | |
576 | else { | |
577 | p->p_flag &= ~SVFORK; | |
578 | wakeup((caddr_t)p); | |
579 | while ((p->p_flag & SVFDONE) == 0) | |
580 | sleep((caddr_t)p, PZERO - 1); | |
581 | p->p_flag &= ~SVFDONE; | |
582 | } | |
a81e9a81 | 583 | for (i = 0; i < NOFILE; i++) { |
c5c236f8 SL |
584 | struct file *f; |
585 | int p; | |
586 | ||
29dd101b BJ |
587 | f = u.u_ofile[i]; |
588 | u.u_ofile[i] = NULL; | |
c5c236f8 | 589 | p = u.u_pofile[i]; |
a81e9a81 | 590 | u.u_pofile[i] = 0; |
c5c236f8 | 591 | closef(f, 1, p); |
29dd101b | 592 | } |
e92a04af | 593 | ilock(u.u_cdir); |
29dd101b BJ |
594 | iput(u.u_cdir); |
595 | if (u.u_rdir) { | |
e92a04af | 596 | ilock(u.u_rdir); |
29dd101b BJ |
597 | iput(u.u_rdir); |
598 | } | |
a1bce776 | 599 | u.u_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY; |
29dd101b | 600 | acct(); |
feab6b5e RE |
601 | #ifdef QUOTA |
602 | qclean(); | |
e0fc9a90 BJ |
603 | #endif |
604 | #ifdef sun | |
605 | ctxfree(&u); | |
feab6b5e | 606 | #endif |
29dd101b BJ |
607 | vrelpt(u.u_procp); |
608 | vrelu(u.u_procp, 0); | |
f12a8410 | 609 | (void) spl5(); /* hack for mem alloc race XXX */ |
29dd101b | 610 | multprog--; |
29dd101b | 611 | p->p_stat = SZOMB; |
42343c0f | 612 | noproc = 1; |
29dd101b BJ |
613 | i = PIDHASH(p->p_pid); |
614 | x = p - proc; | |
615 | if (pidhash[i] == x) | |
616 | pidhash[i] = p->p_idhash; | |
617 | else { | |
618 | for (i = pidhash[i]; i != 0; i = proc[i].p_idhash) | |
619 | if (proc[i].p_idhash == x) { | |
620 | proc[i].p_idhash = p->p_idhash; | |
621 | goto done; | |
622 | } | |
623 | panic("exit"); | |
624 | } | |
9c82b9fd BJ |
625 | if (p->p_pid == 1) |
626 | panic("init died"); | |
29dd101b | 627 | done: |
a1bce776 | 628 | p->p_xstat = rv; |
c5c236f8 SL |
629 | if (m == 0) |
630 | panic("exit: m_getclr"); | |
8c2b0bcd | 631 | p->p_ru = mtod(m, struct rusage *); |
a1bce776 BJ |
632 | *p->p_ru = u.u_ru; |
633 | ruadd(p->p_ru, &u.u_cru); | |
e92a04af BJ |
634 | for (q = proc; q < procNPROC; q++) |
635 | if (q->p_pptr == p) { | |
feab6b5e RE |
636 | if (q->p_osptr) |
637 | q->p_osptr->p_ysptr = q->p_ysptr; | |
638 | if (q->p_ysptr) | |
639 | q->p_ysptr->p_osptr = q->p_osptr; | |
640 | if (proc[1].p_cptr) | |
641 | proc[1].p_cptr->p_ysptr = q; | |
642 | q->p_osptr = proc[1].p_cptr; | |
643 | q->p_ysptr = NULL; | |
644 | proc[1].p_cptr = q; | |
645 | ||
bdfe5b0f | 646 | q->p_pptr = &proc[1]; |
29dd101b | 647 | q->p_ppid = 1; |
bdfe5b0f BJ |
648 | wakeup((caddr_t)&proc[1]); |
649 | /* | |
0dde1c43 | 650 | * Traced processes are killed |
bdfe5b0f | 651 | * since their existence means someone is screwing up. |
62bac59f | 652 | * Stopped processes are sent a hangup and a continue. |
0dde1c43 BJ |
653 | * This is designed to be ``safe'' for setuid |
654 | * processes since they must be willing to tolerate | |
655 | * hangups anyways. | |
bdfe5b0f | 656 | */ |
0dde1c43 | 657 | if (q->p_flag&STRC) { |
bdfe5b0f BJ |
658 | q->p_flag &= ~STRC; |
659 | psignal(q, SIGKILL); | |
0dde1c43 BJ |
660 | } else if (q->p_stat == SSTOP) { |
661 | psignal(q, SIGHUP); | |
662 | psignal(q, SIGCONT); | |
bdfe5b0f | 663 | } |
8643403f BJ |
664 | /* |
665 | * Protect this process from future | |
7ac93404 | 666 | * tty signals, clear TSTP/TTIN/TTOU if pending. |
8643403f | 667 | */ |
934e4ecf | 668 | (void) spgrp(q, -1); |
29dd101b | 669 | } |
bdfe5b0f | 670 | psignal(p->p_pptr, SIGCHLD); |
4e6e3887 | 671 | wakeup((caddr_t)p->p_pptr); |
29dd101b BJ |
672 | swtch(); |
673 | } | |
674 | ||
8ec6ce7a SL |
675 | wait() |
676 | { | |
677 | struct rusage ru, *rup; | |
678 | ||
679 | if ((u.u_ar0[PS] & PSL_ALLCC) != PSL_ALLCC) { | |
680 | u.u_error = wait1(0, (struct rusage *)0); | |
681 | return; | |
682 | } | |
683 | rup = (struct rusage *)u.u_ar0[R1]; | |
684 | u.u_error = wait1(u.u_ar0[R0], &ru); | |
685 | if (u.u_error) | |
686 | return; | |
687 | (void) copyout((caddr_t)&ru, (caddr_t)rup, sizeof (struct rusage)); | |
688 | } | |
689 | ||
690 | #ifndef NOCOMPAT | |
961945a8 | 691 | #include "../h/vtimes.h" |
3269c554 | 692 | |
1edb1cf8 | 693 | owait() |
29dd101b | 694 | { |
3269c554 BJ |
695 | struct rusage ru; |
696 | struct vtimes *vtp, avt; | |
29dd101b | 697 | |
bdfe5b0f | 698 | if ((u.u_ar0[PS] & PSL_ALLCC) != PSL_ALLCC) { |
8ec6ce7a | 699 | u.u_error = wait1(0, (struct rusage *)0); |
bdfe5b0f BJ |
700 | return; |
701 | } | |
3269c554 | 702 | vtp = (struct vtimes *)u.u_ar0[R1]; |
8ec6ce7a | 703 | u.u_error = wait1(u.u_ar0[R0], &ru); |
bdfe5b0f BJ |
704 | if (u.u_error) |
705 | return; | |
3269c554 BJ |
706 | getvtimes(&ru, &avt); |
707 | (void) copyout((caddr_t)&avt, (caddr_t)vtp, sizeof (struct vtimes)); | |
29dd101b | 708 | } |
8ec6ce7a | 709 | #endif |
29dd101b BJ |
710 | |
711 | /* | |
712 | * Wait system call. | |
713 | * Search for a terminated (zombie) child, | |
714 | * finally lay it to rest, and collect its status. | |
715 | * Look also for stopped (traced) children, | |
716 | * and pass back status from them. | |
717 | */ | |
a1bce776 BJ |
718 | wait1(options, ru) |
719 | register int options; | |
720 | struct rusage *ru; | |
29dd101b BJ |
721 | { |
722 | register f; | |
feab6b5e | 723 | register struct proc *p, *q; |
29dd101b BJ |
724 | |
725 | f = 0; | |
29dd101b | 726 | loop: |
e92a04af BJ |
727 | for (p = proc; p < procNPROC; p++) |
728 | if (p->p_pptr == u.u_procp) { | |
29dd101b | 729 | f++; |
e92a04af | 730 | if (p->p_stat == SZOMB) { |
29dd101b | 731 | u.u_r.r_val1 = p->p_pid; |
a1bce776 BJ |
732 | u.u_r.r_val2 = p->p_xstat; |
733 | p->p_xstat = 0; | |
734 | if (ru) | |
735 | *ru = *p->p_ru; | |
736 | ruadd(&u.u_cru, p->p_ru); | |
39d536e6 | 737 | (void) m_free(dtom(p->p_ru)); |
a1bce776 | 738 | p->p_ru = 0; |
29dd101b BJ |
739 | p->p_stat = NULL; |
740 | p->p_pid = 0; | |
741 | p->p_ppid = 0; | |
feab6b5e RE |
742 | if (q = p->p_ysptr) |
743 | q->p_osptr = p->p_osptr; | |
744 | if (q = p->p_osptr) | |
745 | q->p_ysptr = p->p_ysptr; | |
746 | if ((q = p->p_pptr)->p_cptr == p) | |
747 | q->p_cptr = p->p_osptr; | |
bdfe5b0f | 748 | p->p_pptr = 0; |
feab6b5e RE |
749 | p->p_ysptr = 0; |
750 | p->p_osptr = 0; | |
751 | p->p_cptr = 0; | |
29dd101b | 752 | p->p_sig = 0; |
bdfe5b0f BJ |
753 | p->p_siga0 = 0; |
754 | p->p_siga1 = 0; | |
29dd101b BJ |
755 | p->p_pgrp = 0; |
756 | p->p_flag = 0; | |
757 | p->p_wchan = 0; | |
bdfe5b0f | 758 | p->p_cursig = 0; |
8ec6ce7a | 759 | return (0); |
29dd101b | 760 | } |
bdfe5b0f BJ |
761 | if (p->p_stat == SSTOP && (p->p_flag&SWTED)==0 && |
762 | (p->p_flag&STRC || options&WUNTRACED)) { | |
763 | p->p_flag |= SWTED; | |
764 | u.u_r.r_val1 = p->p_pid; | |
765 | u.u_r.r_val2 = (p->p_cursig<<8) | WSTOPPED; | |
8ec6ce7a | 766 | return (0); |
29dd101b BJ |
767 | } |
768 | } | |
8ec6ce7a SL |
769 | if (f == 0) { |
770 | return (ECHILD); | |
bdfe5b0f BJ |
771 | } |
772 | if (options&WNOHANG) { | |
773 | u.u_r.r_val1 = 0; | |
8ec6ce7a | 774 | return (0); |
bdfe5b0f | 775 | } |
f9c5db19 | 776 | if ((u.u_procp->p_flag&SNUSIG) && setjmp(&u.u_qsave)) { |
bdfe5b0f | 777 | u.u_eosys = RESTARTSYS; |
8ec6ce7a | 778 | return (0); |
29dd101b | 779 | } |
bdfe5b0f BJ |
780 | sleep((caddr_t)u.u_procp, PWAIT); |
781 | goto loop; | |
29dd101b BJ |
782 | } |
783 | ||
784 | /* | |
785 | * fork system call. | |
786 | */ | |
787 | fork() | |
788 | { | |
789 | ||
790 | u.u_cdmap = zdmap; | |
791 | u.u_csmap = zdmap; | |
792 | if (swpexpand(u.u_dsize, u.u_ssize, &u.u_cdmap, &u.u_csmap) == 0) { | |
793 | u.u_r.r_val2 = 0; | |
794 | return; | |
795 | } | |
796 | fork1(0); | |
797 | } | |
798 | ||
799 | fork1(isvfork) | |
800 | { | |
801 | register struct proc *p1, *p2; | |
feab6b5e | 802 | #ifndef QUOTA |
29dd101b BJ |
803 | register a; |
804 | ||
805 | a = 0; | |
feab6b5e RE |
806 | #else |
807 | if (u.u_quota != NOQUOT && u.u_quota->q_plim && | |
808 | u.u_quota->q_cnt >= u.u_quota->q_plim) { | |
809 | u.u_error = EPROCLIM; | |
810 | return; | |
811 | } | |
812 | #endif | |
29dd101b | 813 | p2 = NULL; |
e92a04af | 814 | for (p1 = proc; p1 < procNPROC; p1++) { |
feab6b5e RE |
815 | #ifdef QUOTA |
816 | if (p1->p_stat == NULL) { | |
817 | p2 = p1; | |
818 | break; | |
819 | } | |
820 | #else | |
29dd101b BJ |
821 | if (p1->p_stat==NULL && p2==NULL) |
822 | p2 = p1; | |
823 | else { | |
824 | if (p1->p_uid==u.u_uid && p1->p_stat!=NULL) | |
825 | a++; | |
826 | } | |
feab6b5e | 827 | #endif |
29dd101b BJ |
828 | } |
829 | /* | |
830 | * Disallow if | |
831 | * No processes at all; | |
832 | * not su and too many procs owned; or | |
833 | * not su and would take last slot. | |
834 | */ | |
62901f34 BJ |
835 | if (p2==NULL) |
836 | tablefull("proc"); | |
feab6b5e RE |
837 | #ifdef QUOTA |
838 | if (p2==NULL || (u.u_uid!=0 && p2==procNPROC-1)) { | |
839 | #else | |
86fd527f | 840 | if (p2==NULL || (u.u_uid!=0 && (p2==procNPROC-1 || a>MAXUPRC))) { |
feab6b5e | 841 | #endif |
29dd101b BJ |
842 | u.u_error = EAGAIN; |
843 | if (!isvfork) { | |
81263dba BJ |
844 | (void) vsexpand(0, &u.u_cdmap, 1); |
845 | (void) vsexpand(0, &u.u_csmap, 1); | |
29dd101b BJ |
846 | } |
847 | goto out; | |
848 | } | |
849 | p1 = u.u_procp; | |
e92a04af | 850 | if (newproc(isvfork)) { |
29dd101b BJ |
851 | u.u_r.r_val1 = p1->p_pid; |
852 | u.u_r.r_val2 = 1; /* child */ | |
a1bce776 | 853 | u.u_start = time.tv_sec; |
29dd101b | 854 | u.u_acflag = AFORK; |
feab6b5e RE |
855 | #ifdef QUOTA |
856 | u.u_qflags &= ~QUF_LOGIN; | |
857 | #endif | |
29dd101b BJ |
858 | return; |
859 | } | |
860 | u.u_r.r_val1 = p2->p_pid; | |
861 | ||
862 | out: | |
863 | u.u_r.r_val2 = 0; | |
864 | } | |
865 | ||
4147b3f6 BJ |
866 | spgrp(top, npgrp) |
867 | register struct proc *top; | |
868 | { | |
869 | register struct proc *pp, *p; | |
870 | int f = 0; | |
871 | ||
872 | for (p = top; npgrp == -1 || u.u_uid == p->p_uid || | |
873 | !u.u_uid || inferior(p); p = pp) { | |
874 | if (npgrp == -1) { | |
875 | #define bit(a) (1<<(a-1)) | |
876 | p->p_sig &= ~(bit(SIGTSTP)|bit(SIGTTIN)|bit(SIGTTOU)); | |
877 | } else | |
878 | p->p_pgrp = npgrp; | |
879 | f++; | |
880 | /* | |
881 | * Search for children. | |
882 | */ | |
883 | for (pp = proc; pp < procNPROC; pp++) | |
884 | if (pp->p_pptr == p) | |
885 | goto cont; | |
886 | /* | |
887 | * Search for siblings. | |
888 | */ | |
889 | for (; p != top; p = p->p_pptr) | |
890 | for (pp = p + 1; pp < procNPROC; pp++) | |
891 | if (pp->p_pptr == p->p_pptr) | |
892 | goto cont; | |
893 | break; | |
894 | cont: | |
895 | ; | |
896 | } | |
897 | return (f); | |
898 | } | |
899 | ||
29dd101b | 900 | /* |
4147b3f6 | 901 | * Is p an inferior of the current process? |
29dd101b | 902 | */ |
4147b3f6 | 903 | inferior(p) |
a2a2a0d6 | 904 | register struct proc *p; |
29dd101b | 905 | { |
29dd101b | 906 | |
4147b3f6 BJ |
907 | for (; p != u.u_procp; p = p->p_pptr) |
908 | if (p->p_ppid == 0) | |
909 | return (0); | |
910 | return (1); | |
29dd101b | 911 | } |
a2a2a0d6 BJ |
912 | |
913 | struct proc * | |
914 | pfind(pid) | |
915 | int pid; | |
916 | { | |
917 | register struct proc *p; | |
918 | ||
919 | for (p = &proc[pidhash[PIDHASH(pid)]]; p != &proc[0]; p = &proc[p->p_idhash]) | |
920 | if (p->p_pid == pid) | |
921 | return (p); | |
922 | return ((struct proc *)0); | |
923 | } | |
1edb1cf8 BJ |
924 | |
925 | /* | |
926 | * Create a new process-- the internal version of | |
927 | * sys fork. | |
928 | * It returns 1 in the new process, 0 in the old. | |
929 | */ | |
930 | newproc(isvfork) | |
931 | int isvfork; | |
932 | { | |
933 | register struct proc *p; | |
934 | register struct proc *rpp, *rip; | |
935 | register int n; | |
936 | register struct file *fp; | |
937 | ||
938 | p = NULL; | |
939 | /* | |
940 | * First, just locate a slot for a process | |
941 | * and copy the useful info from this process into it. | |
942 | * The panic "cannot happen" because fork has already | |
943 | * checked for the existence of a slot. | |
944 | */ | |
945 | retry: | |
946 | mpid++; | |
947 | if (mpid >= 30000) { | |
948 | mpid = 0; | |
949 | goto retry; | |
950 | } | |
951 | for (rpp = proc; rpp < procNPROC; rpp++) { | |
952 | if (rpp->p_stat == NULL && p==NULL) | |
953 | p = rpp; | |
954 | if (rpp->p_pid==mpid || rpp->p_pgrp==mpid) | |
955 | goto retry; | |
956 | } | |
957 | if ((rpp = p) == NULL) | |
958 | panic("no procs"); | |
959 | ||
960 | /* | |
961 | * Make a proc table entry for the new process. | |
962 | */ | |
963 | rip = u.u_procp; | |
964 | #ifdef QUOTA | |
965 | (rpp->p_quota = rip->p_quota)->q_cnt++; | |
966 | #endif | |
967 | rpp->p_stat = SIDL; | |
968 | timerclear(&rpp->p_realtimer.it_value); | |
969 | rpp->p_flag = SLOAD | (rip->p_flag & (SPAGI|SNUSIG)); | |
970 | if (isvfork) { | |
971 | rpp->p_flag |= SVFORK; | |
972 | rpp->p_ndx = rip->p_ndx; | |
973 | } else | |
974 | rpp->p_ndx = rpp - proc; | |
975 | rpp->p_uid = rip->p_uid; | |
976 | rpp->p_pgrp = rip->p_pgrp; | |
977 | rpp->p_nice = rip->p_nice; | |
978 | rpp->p_textp = isvfork ? 0 : rip->p_textp; | |
979 | rpp->p_pid = mpid; | |
980 | rpp->p_ppid = rip->p_pid; | |
981 | rpp->p_pptr = rip; | |
982 | rpp->p_osptr = rip->p_cptr; | |
983 | if (rip->p_cptr) | |
984 | rip->p_cptr->p_ysptr = rpp; | |
985 | rpp->p_ysptr = NULL; | |
986 | rpp->p_cptr = NULL; | |
987 | rip->p_cptr = rpp; | |
988 | rpp->p_time = 0; | |
989 | rpp->p_cpu = 0; | |
990 | rpp->p_siga0 = rip->p_siga0; | |
991 | rpp->p_siga1 = rip->p_siga1; | |
992 | /* take along any pending signals, like stops? */ | |
993 | if (isvfork) { | |
994 | rpp->p_tsize = rpp->p_dsize = rpp->p_ssize = 0; | |
995 | rpp->p_szpt = clrnd(ctopt(UPAGES)); | |
996 | forkstat.cntvfork++; | |
997 | forkstat.sizvfork += rip->p_dsize + rip->p_ssize; | |
998 | } else { | |
999 | rpp->p_tsize = rip->p_tsize; | |
1000 | rpp->p_dsize = rip->p_dsize; | |
1001 | rpp->p_ssize = rip->p_ssize; | |
1002 | rpp->p_szpt = rip->p_szpt; | |
1003 | forkstat.cntfork++; | |
1004 | forkstat.sizfork += rip->p_dsize + rip->p_ssize; | |
1005 | } | |
1006 | rpp->p_rssize = 0; | |
1007 | rpp->p_maxrss = rip->p_maxrss; | |
1008 | rpp->p_wchan = 0; | |
1009 | rpp->p_slptime = 0; | |
1010 | rpp->p_pctcpu = 0; | |
1011 | rpp->p_cpticks = 0; | |
1012 | n = PIDHASH(rpp->p_pid); | |
1013 | p->p_idhash = pidhash[n]; | |
1014 | pidhash[n] = rpp - proc; | |
1015 | multprog++; | |
1016 | ||
1017 | /* | |
1018 | * Increase reference counts on shared objects. | |
1019 | */ | |
1020 | for (n = 0; n < NOFILE; n++) { | |
1021 | fp = u.u_ofile[n]; | |
1022 | if (fp == NULL) | |
1023 | continue; | |
1024 | fp->f_count++; | |
3650c37d | 1025 | if (u.u_pofile[n]&UF_SHLOCK) |
4f083fd7 | 1026 | fp->f_inode->i_shlockc++; |
3650c37d | 1027 | if (u.u_pofile[n]&UF_EXLOCK) |
4f083fd7 | 1028 | fp->f_inode->i_exlockc++; |
1edb1cf8 BJ |
1029 | } |
1030 | u.u_cdir->i_count++; | |
1031 | if (u.u_rdir) | |
1032 | u.u_rdir->i_count++; | |
1033 | ||
1034 | /* | |
1035 | * Partially simulate the environment | |
1036 | * of the new process so that when it is actually | |
1037 | * created (by copying) it will look right. | |
1038 | * This begins the section where we must prevent the parent | |
1039 | * from being swapped. | |
1040 | */ | |
1041 | rip->p_flag |= SKEEP; | |
1042 | if (procdup(rpp, isvfork)) | |
1043 | return (1); | |
1044 | ||
1045 | /* | |
1046 | * Make child runnable and add to run queue. | |
1047 | */ | |
1048 | (void) spl6(); | |
1049 | rpp->p_stat = SRUN; | |
1050 | setrq(rpp); | |
1051 | (void) spl0(); | |
1052 | ||
1053 | /* | |
1054 | * Cause child to take a non-local goto as soon as it runs. | |
1055 | * On older systems this was done with SSWAP bit in proc | |
1056 | * table; on VAX we use u.u_pcb.pcb_sswap so don't need | |
1057 | * to do rpp->p_flag |= SSWAP. Actually do nothing here. | |
1058 | */ | |
1059 | /* rpp->p_flag |= SSWAP; */ | |
1060 | ||
1061 | /* | |
1062 | * Now can be swapped. | |
1063 | */ | |
1064 | rip->p_flag &= ~SKEEP; | |
1065 | ||
1066 | /* | |
1067 | * If vfork make chain from parent process to child | |
1068 | * (where virtal memory is temporarily). Wait for | |
1069 | * child to finish, steal virtual memory back, | |
1070 | * and wakeup child to let it die. | |
1071 | */ | |
1072 | if (isvfork) { | |
1073 | u.u_procp->p_xlink = rpp; | |
1074 | u.u_procp->p_flag |= SNOVM; | |
1075 | while (rpp->p_flag & SVFORK) | |
1076 | sleep((caddr_t)rpp, PZERO - 1); | |
1077 | if ((rpp->p_flag & SLOAD) == 0) | |
1078 | panic("newproc vfork"); | |
1079 | uaccess(rpp, Vfmap, &vfutl); | |
1080 | u.u_procp->p_xlink = 0; | |
1081 | vpassvm(rpp, u.u_procp, &vfutl, &u, Vfmap); | |
1082 | u.u_procp->p_flag &= ~SNOVM; | |
1083 | rpp->p_ndx = rpp - proc; | |
1084 | rpp->p_flag |= SVFDONE; | |
1085 | wakeup((caddr_t)rpp); | |
1086 | } | |
1087 | ||
1088 | /* | |
1089 | * 0 return means parent. | |
1090 | */ | |
1091 | return (0); | |
1092 | } |