]> git.saurik.com Git - apple/xnu.git/blob - bsd/kern/kern_exit.c
e585c0d279deb5ce7fbc1a9ff2ffd6199c6fad54
[apple/xnu.git] / bsd / kern / kern_exit.c
1 /*
2 * Copyright (c) 2000-2011 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
29 /*
30 * Copyright (c) 1982, 1986, 1989, 1991, 1993
31 * The Regents of the University of California. All rights reserved.
32 * (c) UNIX System Laboratories, Inc.
33 * All or some portions of this file are derived from material licensed
34 * to the University of California by American Telephone and Telegraph
35 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
36 * the permission of UNIX System Laboratories, Inc.
37 *
38 * Redistribution and use in source and binary forms, with or without
39 * modification, are permitted provided that the following conditions
40 * are met:
41 * 1. Redistributions of source code must retain the above copyright
42 * notice, this list of conditions and the following disclaimer.
43 * 2. Redistributions in binary form must reproduce the above copyright
44 * notice, this list of conditions and the following disclaimer in the
45 * documentation and/or other materials provided with the distribution.
46 * 3. All advertising materials mentioning features or use of this software
47 * must display the following acknowledgement:
48 * This product includes software developed by the University of
49 * California, Berkeley and its contributors.
50 * 4. Neither the name of the University nor the names of its contributors
51 * may be used to endorse or promote products derived from this software
52 * without specific prior written permission.
53 *
54 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
55 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
56 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
57 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
58 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
59 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
60 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
61 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
62 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
63 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64 * SUCH DAMAGE.
65 *
66 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94
67 */
68 /*
69 * NOTICE: This file was modified by SPARTA, Inc. in 2005 to introduce
70 * support for mandatory and extensible security protections. This notice
71 * is included in support of clause 2.2 (b) of the Apple Public License,
72 * Version 2.0.
73 */
74
75 #include <machine/reg.h>
76 #include <machine/psl.h>
77
78 #include "compat_43.h"
79
80 #include <sys/param.h>
81 #include <sys/systm.h>
82 #include <sys/ioctl.h>
83 #include <sys/proc_internal.h>
84 #include <sys/proc.h>
85 #include <sys/kauth.h>
86 #include <sys/tty.h>
87 #include <sys/time.h>
88 #include <sys/resource.h>
89 #include <sys/kernel.h>
90 #include <sys/wait.h>
91 #include <sys/file_internal.h>
92 #include <sys/vnode_internal.h>
93 #include <sys/syslog.h>
94 #include <sys/malloc.h>
95 #include <sys/resourcevar.h>
96 #include <sys/ptrace.h>
97 #include <sys/user.h>
98 #include <sys/aio_kern.h>
99 #include <sys/sysproto.h>
100 #include <sys/signalvar.h>
101 #include <sys/kdebug.h>
102 #include <sys/filedesc.h> /* fdfree */
103 #if SYSV_SHM
104 #include <sys/shm_internal.h> /* shmexit */
105 #endif
106 #include <sys/acct.h> /* acct_process */
107
108 #include <security/audit/audit.h>
109 #include <bsm/audit_kevents.h>
110
111 #include <mach/mach_types.h>
112
113 #include <kern/kern_types.h>
114 #include <kern/kalloc.h>
115 #include <kern/task.h>
116 #include <kern/thread.h>
117 #include <kern/thread_call.h>
118 #include <kern/sched_prim.h>
119 #include <kern/assert.h>
120 #include <sys/codesign.h>
121
122 #if VM_PRESSURE_EVENTS
123 #include <kern/vm_pressure.h>
124 #endif
125
126 #if CONFIG_MEMORYSTATUS
127 #include <sys/kern_memorystatus.h>
128 #endif
129
130 #if CONFIG_DTRACE
131 /* Do not include dtrace.h, it redefines kmem_[alloc/free] */
132 extern void (*dtrace_fasttrap_exit_ptr)(proc_t);
133 extern void (*dtrace_helpers_cleanup)(proc_t);
134 extern void dtrace_lazy_dofs_destroy(proc_t);
135
136 #include <sys/dtrace_ptss.h>
137 #endif
138
139 #if CONFIG_MACF
140 #include <security/mac.h>
141 #include <sys/syscall.h>
142 #endif
143
144 #include <mach/mach_types.h>
145 #include <mach/task.h>
146 #include <mach/thread_act.h>
147
148 #include <sys/sdt.h>
149
150 extern char init_task_failure_data[];
151 void proc_prepareexit(proc_t p, int rv, boolean_t perf_notify);
152 void vfork_exit(proc_t p, int rv);
153 void vproc_exit(proc_t p);
154 __private_extern__ void munge_user64_rusage(struct rusage *a_rusage_p, struct user64_rusage *a_user_rusage_p);
155 __private_extern__ void munge_user32_rusage(struct rusage *a_rusage_p, struct user32_rusage *a_user_rusage_p);
156 static int reap_child_locked(proc_t parent, proc_t child, int deadparent, int locked, int droplock);
157
158 /*
159 * Things which should have prototypes in headers, but don't
160 */
161 void *get_bsduthreadarg(thread_t);
162 void proc_exit(proc_t p);
163 int wait1continue(int result);
164 int waitidcontinue(int result);
165 int *get_bsduthreadrval(thread_t);
166 kern_return_t sys_perf_notify(thread_t thread, int pid);
167 kern_return_t task_exception_notify(exception_type_t exception,
168 mach_exception_data_type_t code, mach_exception_data_type_t subcode);
169 void delay(int);
170
171 /*
172 * NOTE: Source and target may *NOT* overlap!
173 * XXX Should share code with bsd/dev/ppc/unix_signal.c
174 */
175 void
176 siginfo_user_to_user32(user_siginfo_t *in, user32_siginfo_t *out)
177 {
178 out->si_signo = in->si_signo;
179 out->si_errno = in->si_errno;
180 out->si_code = in->si_code;
181 out->si_pid = in->si_pid;
182 out->si_uid = in->si_uid;
183 out->si_status = in->si_status;
184 out->si_addr = CAST_DOWN_EXPLICIT(user32_addr_t,in->si_addr);
185 /* following cast works for sival_int because of padding */
186 out->si_value.sival_ptr = CAST_DOWN_EXPLICIT(user32_addr_t,in->si_value.sival_ptr);
187 out->si_band = in->si_band; /* range reduction */
188 }
189
190 void
191 siginfo_user_to_user64(user_siginfo_t *in, user64_siginfo_t *out)
192 {
193 out->si_signo = in->si_signo;
194 out->si_errno = in->si_errno;
195 out->si_code = in->si_code;
196 out->si_pid = in->si_pid;
197 out->si_uid = in->si_uid;
198 out->si_status = in->si_status;
199 out->si_addr = in->si_addr;
200 /* following cast works for sival_int because of padding */
201 out->si_value.sival_ptr = in->si_value.sival_ptr;
202 out->si_band = in->si_band; /* range reduction */
203 }
204
205 static int
206 copyoutsiginfo(user_siginfo_t *native, boolean_t is64, user_addr_t uaddr)
207 {
208 if (is64) {
209 user64_siginfo_t sinfo64;
210
211 bzero(&sinfo64, sizeof (sinfo64));
212 siginfo_user_to_user64(native, &sinfo64);
213 return (copyout(&sinfo64, uaddr, sizeof (sinfo64)));
214 } else {
215 user32_siginfo_t sinfo32;
216
217 bzero(&sinfo32, sizeof (sinfo32));
218 siginfo_user_to_user32(native, &sinfo32);
219 return (copyout(&sinfo32, uaddr, sizeof (sinfo32)));
220 }
221 }
222
223 /*
224 * exit --
225 * Death of process.
226 */
227 void
228 exit(proc_t p, struct exit_args *uap, int *retval)
229 {
230 exit1(p, W_EXITCODE(uap->rval, 0), retval);
231
232 /* drop funnel before we return */
233 thread_exception_return();
234 /* NOTREACHED */
235 while (TRUE)
236 thread_block(THREAD_CONTINUE_NULL);
237 /* NOTREACHED */
238 }
239
240 /*
241 * Exit: deallocate address space and other resources, change proc state
242 * to zombie, and unlink proc from allproc and parent's lists. Save exit
243 * status and rusage for wait(). Check for child processes and orphan them.
244 */
245 int
246 exit1(proc_t p, int rv, int *retval)
247 {
248 return exit1_internal(p, rv, retval, TRUE, TRUE);
249 }
250
251 int
252 exit1_internal(proc_t p, int rv, int *retval, boolean_t thread_can_terminate, boolean_t perf_notify)
253 {
254 thread_t self = current_thread();
255 struct task *task = p->task;
256 struct uthread *ut;
257 int error = 0;
258
259 /*
260 * If a thread in this task has already
261 * called exit(), then halt any others
262 * right here.
263 */
264
265 ut = get_bsdthread_info(self);
266 if (ut->uu_flag & UT_VFORK) {
267 if (!thread_can_terminate) {
268 return EINVAL;
269 }
270
271 vfork_exit(p, rv);
272 vfork_return(p , retval, p->p_pid);
273 unix_syscall_return(0);
274 /* NOT REACHED */
275 }
276
277 /*
278 * The parameter list of audit_syscall_exit() was augmented to
279 * take the Darwin syscall number as the first parameter,
280 * which is currently required by mac_audit_postselect().
281 */
282
283 /*
284 * The BSM token contains two components: an exit status as passed
285 * to exit(), and a return value to indicate what sort of exit it
286 * was. The exit status is WEXITSTATUS(rv), but it's not clear
287 * what the return value is.
288 */
289 AUDIT_ARG(exit, WEXITSTATUS(rv), 0);
290 AUDIT_SYSCALL_EXIT(SYS_exit, p, ut, 0); /* Exit is always successfull */
291
292 DTRACE_PROC1(exit, int, CLD_EXITED);
293
294 /* mark process is going to exit and pull out of DBG/disk throttle */
295 proc_removethrottle(p);
296
297 #if CONFIG_MEMORYSTATUS
298 memorystatus_list_remove(p->p_pid);
299 #endif
300
301 proc_lock(p);
302 error = proc_transstart(p, 1);
303 if (error == EDEADLK) {
304 /* Temp: If deadlock error, then it implies multithreaded exec is
305 * in progress. Instread of letting exit continue and
306 * corrupting the freed memory, let the exit thread
307 * return. This will save corruption in remote case.
308 */
309 proc_unlock(p);
310 if (current_proc() == p){
311 thread_exception_return();
312 } else {
313 /* external termination like jetsam */
314 return(error);
315 }
316 }
317
318 while (p->exit_thread != self) {
319 if (sig_try_locked(p) <= 0) {
320 proc_transend(p, 1);
321 if (get_threadtask(self) != task) {
322 proc_unlock(p);
323 return(0);
324 }
325 proc_unlock(p);
326
327 thread_terminate(self);
328 if (!thread_can_terminate) {
329 return 0;
330 }
331
332 thread_exception_return();
333 /* NOTREACHED */
334 }
335 sig_lock_to_exit(p);
336 }
337 if (p == initproc) {
338 proc_unlock(p);
339 printf("pid 1 exited (signal %d, exit %d)",
340 WTERMSIG(rv), WEXITSTATUS(rv));
341 panic("%s died\nState at Last Exception:\n\n%s",
342 (p->p_comm[0] != '\0' ?
343 p->p_comm :
344 "launchd"),
345 init_task_failure_data);
346 }
347
348 p->p_lflag |= P_LEXIT;
349 p->p_xstat = rv;
350
351 proc_transend(p, 1);
352 proc_unlock(p);
353
354 proc_prepareexit(p, rv, perf_notify);
355
356 /* Last thread to terminate will call proc_exit() */
357 task_terminate_internal(task);
358
359 return(0);
360 }
361
362 void
363 proc_prepareexit(proc_t p, int rv, boolean_t perf_notify)
364 {
365 mach_exception_data_type_t code, subcode;
366 struct uthread *ut;
367 thread_t self = current_thread();
368 ut = get_bsdthread_info(self);
369
370 /* If a core should be generated, notify crash reporter */
371 if (hassigprop(WTERMSIG(rv), SA_CORE) || ((p->p_csflags & CS_KILLED) != 0)) {
372 /*
373 * Workaround for processes checking up on PT_DENY_ATTACH:
374 * should be backed out post-Leopard (details in 5431025).
375 */
376 if ((SIGSEGV == WTERMSIG(rv)) &&
377 (p->p_pptr->p_lflag & P_LNOATTACH)) {
378 goto skipcheck;
379 }
380
381 /*
382 * Crash Reporter looks for the signal value, original exception
383 * type, and low 20 bits of the original code in code[0]
384 * (8, 4, and 20 bits respectively). code[1] is unmodified.
385 */
386 code = ((WTERMSIG(rv) & 0xff) << 24) |
387 ((ut->uu_exception & 0x0f) << 20) |
388 ((int)ut->uu_code & 0xfffff);
389 subcode = ut->uu_subcode;
390 (void) task_exception_notify(EXC_CRASH, code, subcode);
391 }
392
393 skipcheck:
394 /* Notify the perf server? */
395 if (perf_notify) {
396 (void)sys_perf_notify(self, p->p_pid);
397 }
398
399 /*
400 * Remove proc from allproc queue and from pidhash chain.
401 * Need to do this before we do anything that can block.
402 * Not doing causes things like mount() find this on allproc
403 * in partially cleaned state.
404 */
405
406 proc_list_lock();
407
408 LIST_REMOVE(p, p_list);
409 LIST_INSERT_HEAD(&zombproc, p, p_list); /* Place onto zombproc. */
410 /* will not be visible via proc_find */
411 p->p_listflag |= P_LIST_EXITED;
412
413 proc_list_unlock();
414
415
416 #ifdef PGINPROF
417 vmsizmon();
418 #endif
419 /*
420 * If parent is waiting for us to exit or exec,
421 * P_LPPWAIT is set; we will wakeup the parent below.
422 */
423 proc_lock(p);
424 p->p_lflag &= ~(P_LTRACED | P_LPPWAIT);
425 p->p_sigignore = ~(sigcantmask);
426 ut->uu_siglist = 0;
427 proc_unlock(p);
428 }
429
430 void
431 proc_exit(proc_t p)
432 {
433 proc_t q;
434 proc_t pp;
435 struct task *task = p->task;
436 vnode_t tvp = NULLVP;
437 struct pgrp * pg;
438 struct session *sessp;
439 struct uthread * uth;
440 pid_t pid;
441 int exitval;
442 int knote_hint;
443
444 uth = (struct uthread *)get_bsdthread_info(current_thread());
445
446 proc_lock(p);
447 proc_transstart(p, 1);
448 if( !(p->p_lflag & P_LEXIT)) {
449 /*
450 * This can happen if a thread_terminate() occurs
451 * in a single-threaded process.
452 */
453 p->p_lflag |= P_LEXIT;
454 proc_transend(p, 1);
455 proc_unlock(p);
456 proc_prepareexit(p, 0, TRUE);
457 (void) task_terminate_internal(task);
458 proc_lock(p);
459 } else {
460 proc_transend(p, 1);
461 }
462
463 p->p_lflag |= P_LPEXIT;
464
465 /*
466 * Other kernel threads may be in the middle of signalling this process.
467 * Wait for those threads to wrap it up before making the process
468 * disappear on them.
469 */
470 if ((p->p_lflag & P_LINSIGNAL) || (p->p_sigwaitcnt > 0)) {
471 p->p_sigwaitcnt++;
472 while ((p->p_lflag & P_LINSIGNAL) || (p->p_sigwaitcnt > 1))
473 msleep(&p->p_sigmask, &p->p_mlock, PWAIT, "proc_sigdrain", NULL);
474 p->p_sigwaitcnt--;
475 }
476
477 proc_unlock(p);
478 pid = p->p_pid;
479 exitval = p->p_xstat;
480 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_COMMON,
481 BSDDBG_CODE(DBG_BSD_PROC, BSD_PROC_EXIT) | DBG_FUNC_START,
482 pid, exitval, 0, 0, 0);
483
484 #if CONFIG_DTRACE
485 /*
486 * Free any outstanding lazy dof entries. It is imperative we
487 * always call dtrace_lazy_dofs_destroy, rather than null check
488 * and call if !NULL. If we NULL test, during lazy dof faulting
489 * we can race with the faulting code and proceed from here to
490 * beyond the helpers cleanup. The lazy dof faulting will then
491 * install new helpers which will never be cleaned up, and leak.
492 */
493 dtrace_lazy_dofs_destroy(p);
494
495 /*
496 * Clean up any DTrace helper actions or probes for the process.
497 */
498 if (p->p_dtrace_helpers != NULL) {
499 (*dtrace_helpers_cleanup)(p);
500 }
501
502 /*
503 * Clean up any DTrace probes associated with this process.
504 */
505 /*
506 * APPLE NOTE: We release ptss pages/entries in dtrace_fasttrap_exit_ptr(),
507 * call this after dtrace_helpers_cleanup()
508 */
509 proc_lock(p);
510 if (p->p_dtrace_probes && dtrace_fasttrap_exit_ptr) {
511 (*dtrace_fasttrap_exit_ptr)(p);
512 }
513 proc_unlock(p);
514 #endif
515
516 /* XXX Zombie allocation may fail, in which case stats get lost */
517 MALLOC_ZONE(p->p_ru, struct rusage *,
518 sizeof (*p->p_ru), M_ZOMBIE, M_WAITOK);
519
520 nspace_proc_exit(p);
521
522 #if VM_PRESSURE_EVENTS
523 vm_pressure_proc_cleanup(p);
524 #endif
525
526 /*
527 * need to cancel async IO requests that can be cancelled and wait for those
528 * already active. MAY BLOCK!
529 */
530
531 proc_refdrain(p);
532
533 /* if any pending cpu limits action, clear it */
534 task_clear_cpuusage(p->task);
535
536 workqueue_mark_exiting(p);
537 workqueue_exit(p);
538
539 _aio_exit( p );
540
541 /*
542 * Close open files and release open-file table.
543 * This may block!
544 */
545 fdfree(p);
546
547 if (uth->uu_lowpri_window) {
548 /*
549 * task is marked as a low priority I/O type
550 * and the I/O we issued while in flushing files on close
551 * collided with normal I/O operations...
552 * no need to throttle this thread since its going away
553 * but we do need to update our bookeeping w/r to throttled threads
554 */
555 throttle_lowpri_io(FALSE);
556 }
557
558 #if !CONFIG_EMBEDDED
559 if (p->p_legacy_behavior & PROC_LEGACY_BEHAVIOR_IOTHROTTLE) {
560 throttle_legacy_process_decr();
561 }
562 #endif
563
564 #if SYSV_SHM
565 /* Close ref SYSV Shared memory*/
566 if (p->vm_shm)
567 shmexit(p);
568 #endif
569 #if SYSV_SEM
570 /* Release SYSV semaphores */
571 semexit(p);
572 #endif
573
574 #if PSYNCH
575 pth_proc_hashdelete(p);
576 #endif /* PSYNCH */
577
578 sessp = proc_session(p);
579 if (SESS_LEADER(p, sessp)) {
580
581 if (sessp->s_ttyvp != NULLVP) {
582 struct vnode *ttyvp;
583 int ttyvid;
584 struct vfs_context context;
585 struct tty *tp;
586
587 /*
588 * Controlling process.
589 * Signal foreground pgrp,
590 * drain controlling terminal
591 * and revoke access to controlling terminal.
592 */
593 session_lock(sessp);
594 tp = SESSION_TP(sessp);
595 if ((tp != TTY_NULL) && (tp->t_session == sessp)) {
596 session_unlock(sessp);
597
598 tty_pgsignal(tp, SIGHUP, 1);
599
600 session_lock(sessp);
601 tp = SESSION_TP(sessp);
602 }
603 ttyvp = sessp->s_ttyvp;
604 ttyvid = sessp->s_ttyvid;
605 sessp->s_ttyvp = NULLVP;
606 sessp->s_ttyvid = 0;
607 sessp->s_ttyp = TTY_NULL;
608 sessp->s_ttypgrpid = NO_PID;
609 session_unlock(sessp);
610
611 if ((ttyvp != NULLVP) && (vnode_getwithvid(ttyvp, ttyvid) == 0)) {
612 if (tp != TTY_NULL) {
613 tty_lock(tp);
614 (void) ttywait(tp);
615 tty_unlock(tp);
616 }
617 context.vc_thread = proc_thread(p); /* XXX */
618 context.vc_ucred = kauth_cred_proc_ref(p);
619 vnode_rele(ttyvp);
620 VNOP_REVOKE(ttyvp, REVOKEALL, &context);
621 vnode_put(ttyvp);
622 kauth_cred_unref(&context.vc_ucred);
623 ttyvp = NULLVP;
624 }
625 if (ttyvp)
626 vnode_rele(ttyvp);
627 if (tp)
628 ttyfree(tp);
629 }
630 session_lock(sessp);
631 sessp->s_leader = NULL;
632 session_unlock(sessp);
633 }
634 session_rele(sessp);
635
636 pg = proc_pgrp(p);
637 fixjobc(p, pg, 0);
638 pg_rele(pg);
639
640 p->p_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
641 (void)acct_process(p);
642
643 proc_list_lock();
644
645 if ((p->p_listflag & P_LIST_EXITCOUNT) == P_LIST_EXITCOUNT) {
646 p->p_listflag &= ~P_LIST_EXITCOUNT;
647 proc_shutdown_exitcount--;
648 if (proc_shutdown_exitcount == 0)
649 wakeup(&proc_shutdown_exitcount);
650 }
651
652 /* wait till parentrefs are dropped and grant no more */
653 proc_childdrainstart(p);
654 while ((q = p->p_children.lh_first) != NULL) {
655 q->p_listflag |= P_LIST_DEADPARENT;
656 if (q->p_stat == SZOMB) {
657 if (p != q->p_pptr)
658 panic("parent child linkage broken");
659 /* check for sysctl zomb lookup */
660 while ((q->p_listflag & P_LIST_WAITING) == P_LIST_WAITING) {
661 msleep(&q->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
662 }
663 q->p_listflag |= P_LIST_WAITING;
664 /*
665 * This is a named reference and it is not granted
666 * if the reap is already in progress. So we get
667 * the reference here exclusively and their can be
668 * no waiters. So there is no need for a wakeup
669 * after we are done. Also the reap frees the structure
670 * and the proc struct cannot be used for wakeups as well.
671 * It is safe to use q here as this is system reap
672 */
673 (void)reap_child_locked(p, q, 1, 1, 0);
674 } else {
675 proc_reparentlocked(q, initproc, 0, 1);
676 /*
677 * Traced processes are killed
678 * since their existence means someone is messing up.
679 */
680 if (q->p_lflag & P_LTRACED) {
681 /*
682 * Take a reference on the child process to
683 * ensure it doesn't exit and disappear between
684 * the time we drop the list_lock and attempt
685 * to acquire its proc_lock.
686 */
687 if (proc_ref_locked(q) != q)
688 continue;
689
690 proc_list_unlock();
691 proc_lock(q);
692 q->p_lflag &= ~P_LTRACED;
693 if (q->sigwait_thread) {
694 thread_t thread = q->sigwait_thread;
695
696 proc_unlock(q);
697 /*
698 * The sigwait_thread could be stopped at a
699 * breakpoint. Wake it up to kill.
700 * Need to do this as it could be a thread which is not
701 * the first thread in the task. So any attempts to kill
702 * the process would result into a deadlock on q->sigwait.
703 */
704 thread_resume(thread);
705 clear_wait(thread, THREAD_INTERRUPTED);
706 threadsignal(thread, SIGKILL, 0);
707 } else {
708 proc_unlock(q);
709 }
710
711 psignal(q, SIGKILL);
712 proc_list_lock();
713 proc_rele_locked(q);
714 }
715 }
716 }
717
718 proc_childdrainend(p);
719 proc_list_unlock();
720
721 /*
722 * Release reference to text vnode
723 */
724 tvp = p->p_textvp;
725 p->p_textvp = NULL;
726 if (tvp != NULLVP) {
727 vnode_rele(tvp);
728 }
729
730 /*
731 * Save exit status and final rusage info, adding in child rusage
732 * info and self times. If we were unable to allocate a zombie
733 * structure, this information is lost.
734 */
735 /* No need for locking here as no one than this thread can access this */
736 if (p->p_ru != NULL) {
737 calcru(p, &p->p_stats->p_ru.ru_utime, &p->p_stats->p_ru.ru_stime, NULL);
738 *p->p_ru = p->p_stats->p_ru;
739
740 ruadd(p->p_ru, &p->p_stats->p_cru);
741 }
742
743 /*
744 * Free up profiling buffers.
745 */
746 {
747 struct uprof *p0 = &p->p_stats->p_prof, *p1, *pn;
748
749 p1 = p0->pr_next;
750 p0->pr_next = NULL;
751 p0->pr_scale = 0;
752
753 for (; p1 != NULL; p1 = pn) {
754 pn = p1->pr_next;
755 kfree(p1, sizeof *p1);
756 }
757 }
758
759 proc_spinlock(p);
760 if (thread_call_cancel(p->p_rcall))
761 p->p_ractive--;
762
763 while (p->p_ractive > 0) {
764 proc_spinunlock(p);
765
766 delay(1);
767
768 proc_spinlock(p);
769 }
770 proc_spinunlock(p);
771
772 thread_call_free(p->p_rcall);
773 p->p_rcall = NULL;
774
775 /*
776 * Other substructures are freed from wait().
777 */
778 FREE_ZONE(p->p_stats, sizeof *p->p_stats, M_PSTATS);
779 p->p_stats = NULL;
780
781 FREE_ZONE(p->p_sigacts, sizeof *p->p_sigacts, M_SIGACTS);
782 p->p_sigacts = NULL;
783
784 proc_limitdrop(p, 1);
785 p->p_limit = NULL;
786
787
788 /*
789 * Finish up by terminating the task
790 * and halt this thread (only if a
791 * member of the task exiting).
792 */
793 p->task = TASK_NULL;
794 set_bsdtask_info(task, NULL);
795
796 knote_hint = NOTE_EXIT | (p->p_xstat & 0xffff);
797 if (p->p_oppid != 0) {
798 knote_hint |= NOTE_EXIT_REPARENTED;
799 }
800
801 proc_knote(p, knote_hint);
802
803 /* mark the thread as the one that is doing proc_exit
804 * no need to hold proc lock in uthread_free
805 */
806 uth->uu_flag |= UT_PROCEXIT;
807 /*
808 * Notify parent that we're gone.
809 */
810 pp = proc_parent(p);
811 if (pp->p_flag & P_NOCLDWAIT) {
812
813 #if 3839178
814 /*
815 * If the parent is ignoring SIGCHLD, then POSIX requires
816 * us to not add the resource usage to the parent process -
817 * we are only going to hand it off to init to get reaped.
818 * We should contest the standard in this case on the basis
819 * of RLIMIT_CPU.
820 */
821 #else /* !3839178 */
822 /*
823 * Add child resource usage to parent before giving
824 * zombie to init. If we were unable to allocate a
825 * zombie structure, this information is lost.
826 */
827 if (p->p_ru != NULL) {
828 proc_lock(pp);
829 ruadd(&pp->p_stats->p_cru, p->p_ru);
830 proc_unlock(pp);
831 }
832 #endif /* !3839178 */
833
834 /* kernel can reap this one, no need to move it to launchd */
835 proc_list_lock();
836 p->p_listflag |= P_LIST_DEADPARENT;
837 proc_list_unlock();
838 }
839 if ((p->p_listflag & P_LIST_DEADPARENT) == 0) {
840 if (pp != initproc) {
841 proc_lock(pp);
842 pp->si_pid = p->p_pid;
843 pp->si_status = p->p_xstat;
844 pp->si_code = CLD_EXITED;
845 /*
846 * p_ucred usage is safe as it is an exiting process
847 * and reference is dropped in reap
848 */
849 pp->si_uid = kauth_cred_getruid(p->p_ucred);
850 proc_unlock(pp);
851 }
852 /* mark as a zombie */
853 /* No need to take proc lock as all refs are drained and
854 * no one except parent (reaping ) can look at this.
855 * The write is to an int and is coherent. Also parent is
856 * keyed off of list lock for reaping
857 */
858 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_COMMON,
859 BSDDBG_CODE(DBG_BSD_PROC, BSD_PROC_EXIT) | DBG_FUNC_END,
860 pid, exitval, 0, 0, 0);
861 p->p_stat = SZOMB;
862 /*
863 * The current process can be reaped so, no one
864 * can depend on this
865 */
866
867 psignal(pp, SIGCHLD);
868
869 /* and now wakeup the parent */
870 proc_list_lock();
871 wakeup((caddr_t)pp);
872 proc_list_unlock();
873 } else {
874 /* should be fine as parent proc would be initproc */
875 /* mark as a zombie */
876 /* No need to take proc lock as all refs are drained and
877 * no one except parent (reaping ) can look at this.
878 * The write is to an int and is coherent. Also parent is
879 * keyed off of list lock for reaping
880 */
881 proc_list_lock();
882 KERNEL_DEBUG_CONSTANT_IST(KDEBUG_COMMON,
883 BSDDBG_CODE(DBG_BSD_PROC, BSD_PROC_EXIT) | DBG_FUNC_END,
884 pid, exitval, 0, 0, 0);
885 /* check for sysctl zomb lookup */
886 while ((p->p_listflag & P_LIST_WAITING) == P_LIST_WAITING) {
887 msleep(&p->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
888 }
889 /* safe to use p as this is a system reap */
890 p->p_stat = SZOMB;
891 p->p_listflag |= P_LIST_WAITING;
892
893 /*
894 * This is a named reference and it is not granted
895 * if the reap is already in progress. So we get
896 * the reference here exclusively and their can be
897 * no waiters. So there is no need for a wakeup
898 * after we are done. AlsO the reap frees the structure
899 * and the proc struct cannot be used for wakeups as well.
900 * It is safe to use p here as this is system reap
901 */
902 (void)reap_child_locked(pp, p, 1, 1, 1);
903 /* list lock dropped by reap_child_locked */
904 }
905 if (uth->uu_lowpri_window) {
906 /*
907 * task is marked as a low priority I/O type and we've
908 * somehow picked up another throttle during exit processing...
909 * no need to throttle this thread since its going away
910 * but we do need to update our bookeeping w/r to throttled threads
911 */
912 throttle_lowpri_io(FALSE);
913 }
914
915 proc_rele(pp);
916
917 }
918
919
920 /*
921 * reap_child_locked
922 *
923 * Description: Given a process from which all status information needed
924 * has already been extracted, if the process is a ptrace
925 * attach process, detach it and give it back to its real
926 * parent, else recover all resources remaining associated
927 * with it.
928 *
929 * Parameters: proc_t parent Parent of process being reaped
930 * proc_t child Process to reap
931 *
932 * Returns: 0 Process was not reaped because it
933 * came from an attach
934 * 1 Process was reaped
935 */
936 static int
937 reap_child_locked(proc_t parent, proc_t child, int deadparent, int locked, int droplock)
938 {
939 proc_t trace_parent = PROC_NULL; /* Traced parent process, if tracing */
940
941 if (locked == 1)
942 proc_list_unlock();
943
944 /*
945 * If we got the child via a ptrace 'attach',
946 * we need to give it back to the old parent.
947 *
948 * Exception: someone who has been reparented to launchd before being
949 * ptraced can simply be reaped, refer to radar 5677288
950 * p_oppid -> ptraced
951 * trace_parent == initproc -> away from launchd
952 * P_LIST_DEADPARENT -> came to launchd by reparenting
953 */
954 if (child->p_oppid && (trace_parent = proc_find(child->p_oppid))
955 && !((trace_parent == initproc) && (child->p_lflag & P_LIST_DEADPARENT))) {
956 proc_lock(child);
957 child->p_oppid = 0;
958 proc_unlock(child);
959 if (trace_parent != initproc) {
960 /*
961 * proc internal fileds and p_ucred usage safe
962 * here as child is dead and is not reaped or
963 * reparented yet
964 */
965 proc_lock(trace_parent);
966 trace_parent->si_pid = child->p_pid;
967 trace_parent->si_status = child->p_xstat;
968 trace_parent->si_code = CLD_CONTINUED;
969 trace_parent->si_uid = kauth_cred_getruid(child->p_ucred);
970 proc_unlock(trace_parent);
971 }
972 proc_reparentlocked(child, trace_parent, 1, 0);
973 psignal(trace_parent, SIGCHLD);
974 proc_list_lock();
975 wakeup((caddr_t)trace_parent);
976 child->p_listflag &= ~P_LIST_WAITING;
977 wakeup(&child->p_stat);
978 proc_list_unlock();
979 proc_rele(trace_parent);
980 if ((locked == 1) && (droplock == 0))
981 proc_list_lock();
982 return (0);
983 }
984
985 if (trace_parent != PROC_NULL) {
986 proc_rele(trace_parent);
987 }
988
989 proc_knote(child, NOTE_REAP);
990 proc_knote_drain(child);
991
992 child->p_xstat = 0;
993 if (child->p_ru) {
994 proc_lock(parent);
995 #if 3839178
996 /*
997 * If the parent is ignoring SIGCHLD, then POSIX requires
998 * us to not add the resource usage to the parent process -
999 * we are only going to hand it off to init to get reaped.
1000 * We should contest the standard in this case on the basis
1001 * of RLIMIT_CPU.
1002 */
1003 if (!(parent->p_flag & P_NOCLDWAIT))
1004 #endif /* 3839178 */
1005 ruadd(&parent->p_stats->p_cru, child->p_ru);
1006 proc_unlock(parent);
1007 FREE_ZONE(child->p_ru, sizeof *child->p_ru, M_ZOMBIE);
1008 child->p_ru = NULL;
1009 } else {
1010 printf("Warning : lost p_ru for %s\n", child->p_comm);
1011 }
1012
1013 AUDIT_SESSION_PROCEXIT(child);
1014
1015 /*
1016 * Decrement the count of procs running with this uid.
1017 * p_ucred usage is safe here as it is an exited process.
1018 * and refernce is dropped after these calls down below
1019 * (locking protection is provided by list lock held in chgproccnt)
1020 */
1021 (void)chgproccnt(kauth_cred_getruid(child->p_ucred), -1);
1022
1023 #if CONFIG_LCTX
1024 ALLLCTX_LOCK;
1025 leavelctx(child);
1026 ALLLCTX_UNLOCK;
1027 #endif
1028
1029 /*
1030 * Free up credentials.
1031 */
1032 if (IS_VALID_CRED(child->p_ucred)) {
1033 kauth_cred_unref(&child->p_ucred);
1034 }
1035
1036 /* XXXX Note NOT SAFE TO USE p_ucred from this point onwards */
1037
1038 /*
1039 * Finally finished with old proc entry.
1040 * Unlink it from its process group and free it.
1041 */
1042 leavepgrp(child);
1043
1044 proc_list_lock();
1045 LIST_REMOVE(child, p_list); /* off zombproc */
1046 parent->p_childrencnt--;
1047 LIST_REMOVE(child, p_sibling);
1048 /* If there are no more children wakeup parent */
1049 if ((deadparent != 0) && (LIST_EMPTY(&parent->p_children)))
1050 wakeup((caddr_t)parent); /* with list lock held */
1051 child->p_listflag &= ~P_LIST_WAITING;
1052 wakeup(&child->p_stat);
1053
1054 /* Take it out of process hash */
1055 LIST_REMOVE(child, p_hash);
1056 child->p_listflag &= ~P_LIST_INHASH;
1057 proc_checkdeadrefs(child);
1058 nprocs--;
1059
1060 proc_list_unlock();
1061
1062 #if CONFIG_FINE_LOCK_GROUPS
1063 lck_mtx_destroy(&child->p_mlock, proc_mlock_grp);
1064 lck_mtx_destroy(&child->p_fdmlock, proc_fdmlock_grp);
1065 #if CONFIG_DTRACE
1066 lck_mtx_destroy(&child->p_dtrace_sprlock, proc_lck_grp);
1067 #endif
1068 lck_spin_destroy(&child->p_slock, proc_slock_grp);
1069 #else /* CONFIG_FINE_LOCK_GROUPS */
1070 lck_mtx_destroy(&child->p_mlock, proc_lck_grp);
1071 lck_mtx_destroy(&child->p_fdmlock, proc_lck_grp);
1072 #if CONFIG_DTRACE
1073 lck_mtx_destroy(&child->p_dtrace_sprlock, proc_lck_grp);
1074 #endif
1075 lck_spin_destroy(&child->p_slock, proc_lck_grp);
1076 #endif /* CONFIG_FINE_LOCK_GROUPS */
1077 workqueue_destroy_lock(child);
1078
1079 FREE_ZONE(child, sizeof *child, M_PROC);
1080 if ((locked == 1) && (droplock == 0))
1081 proc_list_lock();
1082
1083 return (1);
1084 }
1085
1086
1087 int
1088 wait1continue(int result)
1089 {
1090 void *vt;
1091 thread_t thread;
1092 int *retval;
1093 proc_t p;
1094
1095 if (result)
1096 return(result);
1097
1098 p = current_proc();
1099 thread = current_thread();
1100 vt = get_bsduthreadarg(thread);
1101 retval = get_bsduthreadrval(thread);
1102 return(wait4(p, (struct wait4_args *)vt, retval));
1103 }
1104
1105 int
1106 wait4(proc_t q, struct wait4_args *uap, int32_t *retval)
1107 {
1108 __pthread_testcancel(1);
1109 return(wait4_nocancel(q, (struct wait4_nocancel_args *)uap, retval));
1110 }
1111
1112 int
1113 wait4_nocancel(proc_t q, struct wait4_nocancel_args *uap, int32_t *retval)
1114 {
1115 int nfound;
1116 int sibling_count;
1117 proc_t p;
1118 int status, error;
1119
1120 AUDIT_ARG(pid, uap->pid);
1121
1122 if (uap->pid == 0)
1123 uap->pid = -q->p_pgrpid;
1124
1125 loop:
1126 proc_list_lock();
1127 loop1:
1128 nfound = 0;
1129 sibling_count = 0;
1130
1131 for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
1132 if ( p->p_sibling.le_next != 0 )
1133 sibling_count++;
1134 if (uap->pid != WAIT_ANY &&
1135 p->p_pid != uap->pid &&
1136 p->p_pgrpid != -(uap->pid))
1137 continue;
1138
1139 nfound++;
1140
1141 /* XXX This is racy because we don't get the lock!!!! */
1142
1143 if (p->p_listflag & P_LIST_WAITING) {
1144 (void)msleep(&p->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
1145 goto loop1;
1146 }
1147 p->p_listflag |= P_LIST_WAITING; /* only allow single thread to wait() */
1148
1149
1150 if (p->p_stat == SZOMB) {
1151 proc_list_unlock();
1152 #if CONFIG_MACF
1153 if ((error = mac_proc_check_wait(q, p)) != 0)
1154 goto out;
1155 #endif
1156 retval[0] = p->p_pid;
1157 if (uap->status) {
1158 /* Legacy apps expect only 8 bits of status */
1159 status = 0xffff & p->p_xstat; /* convert to int */
1160 error = copyout((caddr_t)&status,
1161 uap->status,
1162 sizeof(status));
1163 if (error)
1164 goto out;
1165 }
1166 if (uap->rusage) {
1167 if (p->p_ru == NULL) {
1168 error = ENOMEM;
1169 } else {
1170 if (IS_64BIT_PROCESS(q)) {
1171 struct user64_rusage my_rusage;
1172 munge_user64_rusage(p->p_ru, &my_rusage);
1173 error = copyout((caddr_t)&my_rusage,
1174 uap->rusage,
1175 sizeof (my_rusage));
1176 }
1177 else {
1178 struct user32_rusage my_rusage;
1179 munge_user32_rusage(p->p_ru, &my_rusage);
1180 error = copyout((caddr_t)&my_rusage,
1181 uap->rusage,
1182 sizeof (my_rusage));
1183 }
1184 }
1185 /* information unavailable? */
1186 if (error)
1187 goto out;
1188 }
1189
1190 /* Conformance change for 6577252.
1191 * When SIGCHLD is blocked and wait() returns because the status
1192 * of a child process is available and there are no other
1193 * children processes, then any pending SIGCHLD signal is cleared.
1194 */
1195 if ( sibling_count == 0 ) {
1196 int mask = sigmask(SIGCHLD);
1197 uthread_t uth = (struct uthread *)get_bsdthread_info(current_thread());
1198
1199 if ( (uth->uu_sigmask & mask) != 0 ) {
1200 /* we are blocking SIGCHLD signals. clear any pending SIGCHLD.
1201 * This locking looks funny but it is protecting access to the
1202 * thread via p_uthlist.
1203 */
1204 proc_lock(q);
1205 uth->uu_siglist &= ~mask; /* clear pending signal */
1206 proc_unlock(q);
1207 }
1208 }
1209
1210 /* Clean up */
1211 (void)reap_child_locked(q, p, 0, 0, 0);
1212
1213 return (0);
1214 }
1215 if (p->p_stat == SSTOP && (p->p_lflag & P_LWAITED) == 0 &&
1216 (p->p_lflag & P_LTRACED || uap->options & WUNTRACED)) {
1217 proc_list_unlock();
1218 #if CONFIG_MACF
1219 if ((error = mac_proc_check_wait(q, p)) != 0)
1220 goto out;
1221 #endif
1222 proc_lock(p);
1223 p->p_lflag |= P_LWAITED;
1224 proc_unlock(p);
1225 retval[0] = p->p_pid;
1226 if (uap->status) {
1227 status = W_STOPCODE(p->p_xstat);
1228 error = copyout((caddr_t)&status,
1229 uap->status,
1230 sizeof(status));
1231 } else
1232 error = 0;
1233 goto out;
1234 }
1235 /*
1236 * If we are waiting for continued processses, and this
1237 * process was continued
1238 */
1239 if ((uap->options & WCONTINUED) &&
1240 (p->p_flag & P_CONTINUED)) {
1241 proc_list_unlock();
1242 #if CONFIG_MACF
1243 if ((error = mac_proc_check_wait(q, p)) != 0)
1244 goto out;
1245 #endif
1246
1247 /* Prevent other process for waiting for this event */
1248 OSBitAndAtomic(~((uint32_t)P_CONTINUED), &p->p_flag);
1249 retval[0] = p->p_pid;
1250 if (uap->status) {
1251 status = W_STOPCODE(SIGCONT);
1252 error = copyout((caddr_t)&status,
1253 uap->status,
1254 sizeof(status));
1255 } else
1256 error = 0;
1257 goto out;
1258 }
1259 p->p_listflag &= ~P_LIST_WAITING;
1260 wakeup(&p->p_stat);
1261 }
1262 /* list lock is held when we get here any which way */
1263 if (nfound == 0) {
1264 proc_list_unlock();
1265 return (ECHILD);
1266 }
1267
1268 if (uap->options & WNOHANG) {
1269 retval[0] = 0;
1270 proc_list_unlock();
1271 return (0);
1272 }
1273
1274 if ((error = msleep0((caddr_t)q, proc_list_mlock, PWAIT | PCATCH | PDROP, "wait", 0, wait1continue)))
1275 return (error);
1276
1277 goto loop;
1278 out:
1279 proc_list_lock();
1280 p->p_listflag &= ~P_LIST_WAITING;
1281 wakeup(&p->p_stat);
1282 proc_list_unlock();
1283 return (error);
1284 }
1285
1286 #if DEBUG
1287 #define ASSERT_LCK_MTX_OWNED(lock) \
1288 lck_mtx_assert(lock, LCK_MTX_ASSERT_OWNED)
1289 #else
1290 #define ASSERT_LCK_MTX_OWNED(lock) /* nothing */
1291 #endif
1292
1293 int
1294 waitidcontinue(int result)
1295 {
1296 void *vt;
1297 thread_t thread;
1298 int *retval;
1299
1300 if (result)
1301 return (result);
1302
1303 thread = current_thread();
1304 vt = get_bsduthreadarg(thread);
1305 retval = get_bsduthreadrval(thread);
1306 return (waitid(current_proc(), (struct waitid_args *)vt, retval));
1307 }
1308
1309 /*
1310 * Description: Suspend the calling thread until one child of the process
1311 * containing the calling thread changes state.
1312 *
1313 * Parameters: uap->idtype one of P_PID, P_PGID, P_ALL
1314 * uap->id pid_t or gid_t or ignored
1315 * uap->infop Address of siginfo_t struct in
1316 * user space into which to return status
1317 * uap->options flag values
1318 *
1319 * Returns: 0 Success
1320 * !0 Error returning status to user space
1321 */
1322 int
1323 waitid(proc_t q, struct waitid_args *uap, int32_t *retval)
1324 {
1325 __pthread_testcancel(1);
1326 return (waitid_nocancel(q, (struct waitid_nocancel_args *)uap, retval));
1327 }
1328
1329 int
1330 waitid_nocancel(proc_t q, struct waitid_nocancel_args *uap,
1331 __unused int32_t *retval)
1332 {
1333 user_siginfo_t siginfo; /* siginfo data to return to caller */
1334 boolean_t caller64 = IS_64BIT_PROCESS(q);
1335 int nfound;
1336 proc_t p;
1337 int error;
1338
1339 if (uap->options == 0 ||
1340 (uap->options & ~(WNOHANG|WNOWAIT|WCONTINUED|WSTOPPED|WEXITED)))
1341 return (EINVAL); /* bits set that aren't recognized */
1342
1343 switch (uap->idtype) {
1344 case P_PID: /* child with process ID equal to... */
1345 case P_PGID: /* child with process group ID equal to... */
1346 if (((int)uap->id) < 0)
1347 return (EINVAL);
1348 break;
1349 case P_ALL: /* any child */
1350 break;
1351 }
1352
1353 loop:
1354 proc_list_lock();
1355 loop1:
1356 nfound = 0;
1357 for (p = q->p_children.lh_first; p != 0; p = p->p_sibling.le_next) {
1358
1359 switch (uap->idtype) {
1360 case P_PID: /* child with process ID equal to... */
1361 if (p->p_pid != (pid_t)uap->id)
1362 continue;
1363 break;
1364 case P_PGID: /* child with process group ID equal to... */
1365 if (p->p_pgrpid != (pid_t)uap->id)
1366 continue;
1367 break;
1368 case P_ALL: /* any child */
1369 break;
1370 }
1371
1372 /* XXX This is racy because we don't get the lock!!!! */
1373
1374 /*
1375 * Wait collision; go to sleep and restart; used to maintain
1376 * the single return for waited process guarantee.
1377 */
1378 if (p->p_listflag & P_LIST_WAITING) {
1379 (void) msleep(&p->p_stat, proc_list_mlock,
1380 PWAIT, "waitidcoll", 0);
1381 goto loop1;
1382 }
1383 p->p_listflag |= P_LIST_WAITING; /* mark busy */
1384
1385 nfound++;
1386
1387 bzero(&siginfo, sizeof (siginfo));
1388
1389 switch (p->p_stat) {
1390 case SZOMB: /* Exited */
1391 if (!(uap->options & WEXITED))
1392 break;
1393 proc_list_unlock();
1394 #if CONFIG_MACF
1395 if ((error = mac_proc_check_wait(q, p)) != 0)
1396 goto out;
1397 #endif
1398 siginfo.si_signo = SIGCHLD;
1399 siginfo.si_pid = p->p_pid;
1400 siginfo.si_status = WEXITSTATUS(p->p_xstat);
1401 if (WIFSIGNALED(p->p_xstat)) {
1402 siginfo.si_code = WCOREDUMP(p->p_xstat) ?
1403 CLD_DUMPED : CLD_KILLED;
1404 } else
1405 siginfo.si_code = CLD_EXITED;
1406
1407 if ((error = copyoutsiginfo(&siginfo,
1408 caller64, uap->infop)) != 0)
1409 goto out;
1410
1411 /* Prevent other process for waiting for this event? */
1412 if (!(uap->options & WNOWAIT)) {
1413 (void) reap_child_locked(q, p, 0, 0, 0);
1414 return (0);
1415 }
1416 goto out;
1417
1418 case SSTOP: /* Stopped */
1419 /*
1420 * If we are not interested in stopped processes, then
1421 * ignore this one.
1422 */
1423 if (!(uap->options & WSTOPPED))
1424 break;
1425
1426 /*
1427 * If someone has already waited it, we lost a race
1428 * to be the one to return status.
1429 */
1430 if ((p->p_lflag & P_LWAITED) != 0)
1431 break;
1432 proc_list_unlock();
1433 #if CONFIG_MACF
1434 if ((error = mac_proc_check_wait(q, p)) != 0)
1435 goto out;
1436 #endif
1437 siginfo.si_signo = SIGCHLD;
1438 siginfo.si_pid = p->p_pid;
1439 siginfo.si_status = p->p_xstat; /* signal number */
1440 siginfo.si_code = CLD_STOPPED;
1441
1442 if ((error = copyoutsiginfo(&siginfo,
1443 caller64, uap->infop)) != 0)
1444 goto out;
1445
1446 /* Prevent other process for waiting for this event? */
1447 if (!(uap->options & WNOWAIT)) {
1448 proc_lock(p);
1449 p->p_lflag |= P_LWAITED;
1450 proc_unlock(p);
1451 }
1452 goto out;
1453
1454 default: /* All other states => Continued */
1455 if (!(uap->options & WCONTINUED))
1456 break;
1457
1458 /*
1459 * If the flag isn't set, then this process has not
1460 * been stopped and continued, or the status has
1461 * already been reaped by another caller of waitid().
1462 */
1463 if ((p->p_flag & P_CONTINUED) == 0)
1464 break;
1465 proc_list_unlock();
1466 #if CONFIG_MACF
1467 if ((error = mac_proc_check_wait(q, p)) != 0)
1468 goto out;
1469 #endif
1470 siginfo.si_signo = SIGCHLD;
1471 siginfo.si_code = CLD_CONTINUED;
1472 proc_lock(p);
1473 siginfo.si_pid = p->p_contproc;
1474 siginfo.si_status = p->p_xstat;
1475 proc_unlock(p);
1476
1477 if ((error = copyoutsiginfo(&siginfo,
1478 caller64, uap->infop)) != 0)
1479 goto out;
1480
1481 /* Prevent other process for waiting for this event? */
1482 if (!(uap->options & WNOWAIT)) {
1483 OSBitAndAtomic(~((uint32_t)P_CONTINUED),
1484 &p->p_flag);
1485 }
1486 goto out;
1487 }
1488 ASSERT_LCK_MTX_OWNED(proc_list_mlock);
1489
1490 /* Not a process we are interested in; go on to next child */
1491
1492 p->p_listflag &= ~P_LIST_WAITING;
1493 wakeup(&p->p_stat);
1494 }
1495 ASSERT_LCK_MTX_OWNED(proc_list_mlock);
1496
1497 /* No child processes that could possibly satisfy the request? */
1498
1499 if (nfound == 0) {
1500 proc_list_unlock();
1501 return (ECHILD);
1502 }
1503
1504 if (uap->options & WNOHANG) {
1505 proc_list_unlock();
1506 #if CONFIG_MACF
1507 if ((error = mac_proc_check_wait(q, p)) != 0)
1508 return (error);
1509 #endif
1510 /*
1511 * The state of the siginfo structure in this case
1512 * is undefined. Some implementations bzero it, some
1513 * (like here) leave it untouched for efficiency.
1514 *
1515 * Thus the most portable check for "no matching pid with
1516 * WNOHANG" is to store a zero into si_pid before
1517 * invocation, then check for a non-zero value afterwards.
1518 */
1519 return (0);
1520 }
1521
1522 if ((error = msleep0(q, proc_list_mlock,
1523 PWAIT | PCATCH | PDROP, "waitid", 0, waitidcontinue)) != 0)
1524 return (error);
1525
1526 goto loop;
1527 out:
1528 proc_list_lock();
1529 p->p_listflag &= ~P_LIST_WAITING;
1530 wakeup(&p->p_stat);
1531 proc_list_unlock();
1532 return (error);
1533 }
1534
1535 /*
1536 * make process 'parent' the new parent of process 'child'.
1537 */
1538 void
1539 proc_reparentlocked(proc_t child, proc_t parent, int cansignal, int locked)
1540 {
1541 proc_t oldparent = PROC_NULL;
1542
1543 if (child->p_pptr == parent)
1544 return;
1545
1546 if (locked == 0)
1547 proc_list_lock();
1548
1549 oldparent = child->p_pptr;
1550 #if __PROC_INTERNAL_DEBUG
1551 if (oldparent == PROC_NULL)
1552 panic("proc_reparent: process %p does not have a parent\n", child);
1553 #endif
1554
1555 LIST_REMOVE(child, p_sibling);
1556 #if __PROC_INTERNAL_DEBUG
1557 if (oldparent->p_childrencnt == 0)
1558 panic("process children count already 0\n");
1559 #endif
1560 oldparent->p_childrencnt--;
1561 #if __PROC_INTERNAL_DEBUG1
1562 if (oldparent->p_childrencnt < 0)
1563 panic("process children count -ve\n");
1564 #endif
1565 LIST_INSERT_HEAD(&parent->p_children, child, p_sibling);
1566 parent->p_childrencnt++;
1567 child->p_pptr = parent;
1568 child->p_ppid = parent->p_pid;
1569
1570 proc_list_unlock();
1571
1572 if ((cansignal != 0) && (initproc == parent) && (child->p_stat == SZOMB))
1573 psignal(initproc, SIGCHLD);
1574 if (locked == 1)
1575 proc_list_lock();
1576 }
1577
1578 /*
1579 * Exit: deallocate address space and other resources, change proc state
1580 * to zombie, and unlink proc from allproc and parent's lists. Save exit
1581 * status and rusage for wait(). Check for child processes and orphan them.
1582 */
1583
1584 void
1585 vfork_exit(proc_t p, int rv)
1586 {
1587 vfork_exit_internal(p, rv, 0);
1588 }
1589
1590 void
1591 vfork_exit_internal(proc_t p, int rv, int forceexit)
1592 {
1593 thread_t self = current_thread();
1594 #ifdef FIXME
1595 struct task *task = p->task;
1596 #endif
1597 struct uthread *ut;
1598
1599 /*
1600 * If a thread in this task has already
1601 * called exit(), then halt any others
1602 * right here.
1603 */
1604
1605 ut = get_bsdthread_info(self);
1606
1607
1608 proc_lock(p);
1609 if ((p->p_lflag & P_LPEXIT) == P_LPEXIT) {
1610 /*
1611 * This happens when a parent exits/killed and vfork is in progress
1612 * other threads. But shutdown code for ex has already called exit1()
1613 */
1614 proc_unlock(p);
1615 return;
1616 }
1617 p->p_lflag |= (P_LEXIT | P_LPEXIT);
1618 proc_unlock(p);
1619
1620 if (forceexit == 0) {
1621 /*
1622 * parent of a vfork child has already called exit() and the
1623 * thread that has vfork in proress terminates. So there is no
1624 * separate address space here and it has already been marked for
1625 * termination. This was never covered before and could cause problems
1626 * if we block here for outside code.
1627 */
1628 /* Notify the perf server */
1629 (void)sys_perf_notify(self, p->p_pid);
1630 }
1631
1632 /*
1633 * Remove proc from allproc queue and from pidhash chain.
1634 * Need to do this before we do anything that can block.
1635 * Not doing causes things like mount() find this on allproc
1636 * in partially cleaned state.
1637 */
1638
1639 proc_list_lock();
1640
1641 LIST_REMOVE(p, p_list);
1642 LIST_INSERT_HEAD(&zombproc, p, p_list); /* Place onto zombproc. */
1643 /* will not be visible via proc_find */
1644 p->p_listflag |= P_LIST_EXITED;
1645
1646 proc_list_unlock();
1647
1648 proc_lock(p);
1649 p->p_xstat = rv;
1650 p->p_lflag &= ~(P_LTRACED | P_LPPWAIT);
1651 p->p_sigignore = ~0;
1652 proc_unlock(p);
1653
1654 proc_spinlock(p);
1655 if (thread_call_cancel(p->p_rcall))
1656 p->p_ractive--;
1657
1658 while (p->p_ractive > 0) {
1659 proc_spinunlock(p);
1660
1661 delay(1);
1662
1663 proc_spinlock(p);
1664 }
1665 proc_spinunlock(p);
1666
1667 thread_call_free(p->p_rcall);
1668 p->p_rcall = NULL;
1669
1670 ut->uu_siglist = 0;
1671
1672 vproc_exit(p);
1673 }
1674
1675 void
1676 vproc_exit(proc_t p)
1677 {
1678 proc_t q;
1679 proc_t pp;
1680
1681 vnode_t tvp;
1682 #ifdef FIXME
1683 struct task *task = p->task;
1684 #endif
1685 struct pgrp * pg;
1686 struct session *sessp;
1687
1688 /* XXX Zombie allocation may fail, in which case stats get lost */
1689 MALLOC_ZONE(p->p_ru, struct rusage *,
1690 sizeof (*p->p_ru), M_ZOMBIE, M_WAITOK);
1691
1692
1693 proc_refdrain(p);
1694
1695 /*
1696 * Close open files and release open-file table.
1697 * This may block!
1698 */
1699 fdfree(p);
1700
1701 #if !CONFIG_EMBEDDED
1702 if (p->p_legacy_behavior & PROC_LEGACY_BEHAVIOR_IOTHROTTLE) {
1703 throttle_legacy_process_decr();
1704 }
1705 #endif
1706
1707 sessp = proc_session(p);
1708 if (SESS_LEADER(p, sessp)) {
1709
1710 if (sessp->s_ttyvp != NULLVP) {
1711 struct vnode *ttyvp;
1712 int ttyvid;
1713 struct vfs_context context;
1714 struct tty *tp;
1715
1716 /*
1717 * Controlling process.
1718 * Signal foreground pgrp,
1719 * drain controlling terminal
1720 * and revoke access to controlling terminal.
1721 */
1722 session_lock(sessp);
1723 tp = SESSION_TP(sessp);
1724 if ((tp != TTY_NULL) && (tp->t_session == sessp)) {
1725 session_unlock(sessp);
1726
1727 tty_pgsignal(tp, SIGHUP, 1);
1728
1729 session_lock(sessp);
1730 tp = SESSION_TP(sessp);
1731 }
1732 ttyvp = sessp->s_ttyvp;
1733 ttyvid = sessp->s_ttyvid;
1734 sessp->s_ttyvp = NULL;
1735 sessp->s_ttyvid = 0;
1736 sessp->s_ttyp = TTY_NULL;
1737 sessp->s_ttypgrpid = NO_PID;
1738 session_unlock(sessp);
1739
1740 if ((ttyvp != NULLVP) && (vnode_getwithvid(ttyvp, ttyvid) == 0)) {
1741 if (tp != TTY_NULL) {
1742 tty_lock(tp);
1743 (void) ttywait(tp);
1744 tty_unlock(tp);
1745 }
1746 context.vc_thread = proc_thread(p); /* XXX */
1747 context.vc_ucred = kauth_cred_proc_ref(p);
1748 vnode_rele(ttyvp);
1749 VNOP_REVOKE(ttyvp, REVOKEALL, &context);
1750 vnode_put(ttyvp);
1751 kauth_cred_unref(&context.vc_ucred);
1752 ttyvp = NULLVP;
1753 }
1754 if (ttyvp)
1755 vnode_rele(ttyvp);
1756 if (tp)
1757 ttyfree(tp);
1758 }
1759 session_lock(sessp);
1760 sessp->s_leader = NULL;
1761 session_unlock(sessp);
1762 }
1763 session_rele(sessp);
1764
1765 pg = proc_pgrp(p);
1766 fixjobc(p, pg, 0);
1767 pg_rele(pg);
1768
1769 p->p_rlimit[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
1770
1771 proc_list_lock();
1772 proc_childdrainstart(p);
1773 while ((q = p->p_children.lh_first) != NULL) {
1774 q->p_listflag |= P_LIST_DEADPARENT;
1775 if (q->p_stat == SZOMB) {
1776 if (p != q->p_pptr)
1777 panic("parent child linkage broken");
1778 /* check for lookups by zomb sysctl */
1779 while ((q->p_listflag & P_LIST_WAITING) == P_LIST_WAITING) {
1780 msleep(&q->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
1781 }
1782 q->p_listflag |= P_LIST_WAITING;
1783 /*
1784 * This is a named reference and it is not granted
1785 * if the reap is already in progress. So we get
1786 * the reference here exclusively and their can be
1787 * no waiters. So there is no need for a wakeup
1788 * after we are done. AlsO the reap frees the structure
1789 * and the proc struct cannot be used for wakeups as well.
1790 * It is safe to use q here as this is system reap
1791 */
1792 (void)reap_child_locked(p, q, 1, 1, 0);
1793 } else {
1794 proc_reparentlocked(q, initproc, 0, 1);
1795 /*
1796 * Traced processes are killed
1797 * since their existence means someone is messing up.
1798 */
1799 if (q->p_lflag & P_LTRACED) {
1800 proc_list_unlock();
1801 proc_lock(q);
1802 q->p_lflag &= ~P_LTRACED;
1803 if (q->sigwait_thread) {
1804 thread_t thread = q->sigwait_thread;
1805
1806 proc_unlock(q);
1807 /*
1808 * The sigwait_thread could be stopped at a
1809 * breakpoint. Wake it up to kill.
1810 * Need to do this as it could be a thread which is not
1811 * the first thread in the task. So any attempts to kill
1812 * the process would result into a deadlock on q->sigwait.
1813 */
1814 thread_resume(thread);
1815 clear_wait(thread, THREAD_INTERRUPTED);
1816 threadsignal(thread, SIGKILL, 0);
1817 } else {
1818 proc_unlock(q);
1819 }
1820
1821 psignal(q, SIGKILL);
1822 proc_list_lock();
1823 }
1824 }
1825 }
1826
1827 proc_childdrainend(p);
1828 proc_list_unlock();
1829
1830 /*
1831 * Release reference to text vnode
1832 */
1833 tvp = p->p_textvp;
1834 p->p_textvp = NULL;
1835 if (tvp != NULLVP) {
1836 vnode_rele(tvp);
1837 }
1838
1839 /*
1840 * Save exit status and final rusage info, adding in child rusage
1841 * info and self times. If we were unable to allocate a zombie
1842 * structure, this information is lost.
1843 */
1844 /* No need for locking here as no one than this thread can access this */
1845 if (p->p_ru != NULL) {
1846 *p->p_ru = p->p_stats->p_ru;
1847 timerclear(&p->p_ru->ru_utime);
1848 timerclear(&p->p_ru->ru_stime);
1849
1850 #ifdef FIXME
1851 if (task) {
1852 mach_task_basic_info_data_t tinfo;
1853 task_thread_times_info_data_t ttimesinfo;
1854 int task_info_stuff, task_ttimes_stuff;
1855 struct timeval ut,st;
1856
1857 task_info_stuff = MACH_TASK_BASIC_INFO_COUNT;
1858 task_info(task, MACH_TASK_BASIC_INFO,
1859 &tinfo, &task_info_stuff);
1860 p->p_ru->ru_utime.tv_sec = tinfo.user_time.seconds;
1861 p->p_ru->ru_utime.tv_usec = tinfo.user_time.microseconds;
1862 p->p_ru->ru_stime.tv_sec = tinfo.system_time.seconds;
1863 p->p_ru->ru_stime.tv_usec = tinfo.system_time.microseconds;
1864
1865 task_ttimes_stuff = TASK_THREAD_TIMES_INFO_COUNT;
1866 task_info(task, TASK_THREAD_TIMES_INFO,
1867 &ttimesinfo, &task_ttimes_stuff);
1868
1869 ut.tv_sec = ttimesinfo.user_time.seconds;
1870 ut.tv_usec = ttimesinfo.user_time.microseconds;
1871 st.tv_sec = ttimesinfo.system_time.seconds;
1872 st.tv_usec = ttimesinfo.system_time.microseconds;
1873 timeradd(&ut,&p->p_ru->ru_utime,&p->p_ru->ru_utime);
1874 timeradd(&st,&p->p_ru->ru_stime,&p->p_ru->ru_stime);
1875 }
1876 #endif /* FIXME */
1877
1878 ruadd(p->p_ru, &p->p_stats->p_cru);
1879 }
1880
1881 /*
1882 * Free up profiling buffers.
1883 */
1884 {
1885 struct uprof *p0 = &p->p_stats->p_prof, *p1, *pn;
1886
1887 p1 = p0->pr_next;
1888 p0->pr_next = NULL;
1889 p0->pr_scale = 0;
1890
1891 for (; p1 != NULL; p1 = pn) {
1892 pn = p1->pr_next;
1893 kfree(p1, sizeof *p1);
1894 }
1895 }
1896
1897 #if PSYNCH
1898 pth_proc_hashdelete(p);
1899 #endif /* PSYNCH */
1900
1901 /*
1902 * Other substructures are freed from wait().
1903 */
1904 FREE_ZONE(p->p_stats, sizeof *p->p_stats, M_PSTATS);
1905 p->p_stats = NULL;
1906
1907 FREE_ZONE(p->p_sigacts, sizeof *p->p_sigacts, M_SIGACTS);
1908 p->p_sigacts = NULL;
1909
1910 proc_limitdrop(p, 1);
1911 p->p_limit = NULL;
1912
1913 /*
1914 * Finish up by terminating the task
1915 * and halt this thread (only if a
1916 * member of the task exiting).
1917 */
1918 p->task = TASK_NULL;
1919
1920 /*
1921 * Notify parent that we're gone.
1922 */
1923 pp = proc_parent(p);
1924 if ((p->p_listflag & P_LIST_DEADPARENT) == 0) {
1925 if (pp != initproc) {
1926 proc_lock(pp);
1927 pp->si_pid = p->p_pid;
1928 pp->si_status = p->p_xstat;
1929 pp->si_code = CLD_EXITED;
1930 /*
1931 * p_ucred usage is safe as it is an exiting process
1932 * and reference is dropped in reap
1933 */
1934 pp->si_uid = kauth_cred_getruid(p->p_ucred);
1935 proc_unlock(pp);
1936 }
1937 /* mark as a zombie */
1938 /* mark as a zombie */
1939 /* No need to take proc lock as all refs are drained and
1940 * no one except parent (reaping ) can look at this.
1941 * The write is to an int and is coherent. Also parent is
1942 * keyed off of list lock for reaping
1943 */
1944 p->p_stat = SZOMB;
1945
1946 psignal(pp, SIGCHLD);
1947
1948 /* and now wakeup the parent */
1949 proc_list_lock();
1950 wakeup((caddr_t)pp);
1951 proc_list_unlock();
1952 } else {
1953 proc_list_lock();
1954 /* check for lookups by zomb sysctl */
1955 while ((p->p_listflag & P_LIST_WAITING) == P_LIST_WAITING) {
1956 msleep(&p->p_stat, proc_list_mlock, PWAIT, "waitcoll", 0);
1957 }
1958 p->p_stat = SZOMB;
1959 p->p_listflag |= P_LIST_WAITING;
1960
1961 /*
1962 * This is a named reference and it is not granted
1963 * if the reap is already in progress. So we get
1964 * the reference here exclusively and their can be
1965 * no waiters. So there is no need for a wakeup
1966 * after we are done. AlsO the reap frees the structure
1967 * and the proc struct cannot be used for wakeups as well.
1968 * It is safe to use p here as this is system reap
1969 */
1970 (void)reap_child_locked(pp, p, 0, 1, 1);
1971 /* list lock dropped by reap_child_locked */
1972 }
1973 proc_rele(pp);
1974 }
1975
1976
1977 /*
1978 * munge_rusage
1979 * LP64 support - long is 64 bits if we are dealing with a 64 bit user
1980 * process. We munge the kernel version of rusage into the
1981 * 64 bit version.
1982 */
1983 __private_extern__ void
1984 munge_user64_rusage(struct rusage *a_rusage_p, struct user64_rusage *a_user_rusage_p)
1985 {
1986 /* timeval changes size, so utime and stime need special handling */
1987 a_user_rusage_p->ru_utime.tv_sec = a_rusage_p->ru_utime.tv_sec;
1988 a_user_rusage_p->ru_utime.tv_usec = a_rusage_p->ru_utime.tv_usec;
1989 a_user_rusage_p->ru_stime.tv_sec = a_rusage_p->ru_stime.tv_sec;
1990 a_user_rusage_p->ru_stime.tv_usec = a_rusage_p->ru_stime.tv_usec;
1991 /*
1992 * everything else can be a direct assign, since there is no loss
1993 * of precision implied boing 32->64.
1994 */
1995 a_user_rusage_p->ru_maxrss = a_rusage_p->ru_maxrss;
1996 a_user_rusage_p->ru_ixrss = a_rusage_p->ru_ixrss;
1997 a_user_rusage_p->ru_idrss = a_rusage_p->ru_idrss;
1998 a_user_rusage_p->ru_isrss = a_rusage_p->ru_isrss;
1999 a_user_rusage_p->ru_minflt = a_rusage_p->ru_minflt;
2000 a_user_rusage_p->ru_majflt = a_rusage_p->ru_majflt;
2001 a_user_rusage_p->ru_nswap = a_rusage_p->ru_nswap;
2002 a_user_rusage_p->ru_inblock = a_rusage_p->ru_inblock;
2003 a_user_rusage_p->ru_oublock = a_rusage_p->ru_oublock;
2004 a_user_rusage_p->ru_msgsnd = a_rusage_p->ru_msgsnd;
2005 a_user_rusage_p->ru_msgrcv = a_rusage_p->ru_msgrcv;
2006 a_user_rusage_p->ru_nsignals = a_rusage_p->ru_nsignals;
2007 a_user_rusage_p->ru_nvcsw = a_rusage_p->ru_nvcsw;
2008 a_user_rusage_p->ru_nivcsw = a_rusage_p->ru_nivcsw;
2009 }
2010
2011 /* For a 64-bit kernel and 32-bit userspace, munging may be needed */
2012 __private_extern__ void
2013 munge_user32_rusage(struct rusage *a_rusage_p, struct user32_rusage *a_user_rusage_p)
2014 {
2015 /* timeval changes size, so utime and stime need special handling */
2016 a_user_rusage_p->ru_utime.tv_sec = a_rusage_p->ru_utime.tv_sec;
2017 a_user_rusage_p->ru_utime.tv_usec = a_rusage_p->ru_utime.tv_usec;
2018 a_user_rusage_p->ru_stime.tv_sec = a_rusage_p->ru_stime.tv_sec;
2019 a_user_rusage_p->ru_stime.tv_usec = a_rusage_p->ru_stime.tv_usec;
2020 /*
2021 * everything else can be a direct assign. We currently ignore
2022 * the loss of precision
2023 */
2024 a_user_rusage_p->ru_maxrss = a_rusage_p->ru_maxrss;
2025 a_user_rusage_p->ru_ixrss = a_rusage_p->ru_ixrss;
2026 a_user_rusage_p->ru_idrss = a_rusage_p->ru_idrss;
2027 a_user_rusage_p->ru_isrss = a_rusage_p->ru_isrss;
2028 a_user_rusage_p->ru_minflt = a_rusage_p->ru_minflt;
2029 a_user_rusage_p->ru_majflt = a_rusage_p->ru_majflt;
2030 a_user_rusage_p->ru_nswap = a_rusage_p->ru_nswap;
2031 a_user_rusage_p->ru_inblock = a_rusage_p->ru_inblock;
2032 a_user_rusage_p->ru_oublock = a_rusage_p->ru_oublock;
2033 a_user_rusage_p->ru_msgsnd = a_rusage_p->ru_msgsnd;
2034 a_user_rusage_p->ru_msgrcv = a_rusage_p->ru_msgrcv;
2035 a_user_rusage_p->ru_nsignals = a_rusage_p->ru_nsignals;
2036 a_user_rusage_p->ru_nvcsw = a_rusage_p->ru_nvcsw;
2037 a_user_rusage_p->ru_nivcsw = a_rusage_p->ru_nivcsw;
2038 }