2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1982, 1986, 1989, 1991, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)kern_exit.c 8.7 (Berkeley) 2/12/94
63 #include <machine/reg.h>
64 #include <machine/psl.h>
66 #include "compat_43.h"
68 #include <sys/param.h>
69 #include <sys/systm.h>
70 #include <sys/ioctl.h>
74 #include <sys/resource.h>
75 #include <sys/kernel.h>
79 #include <sys/vnode.h>
80 #include <sys/syslog.h>
81 #include <sys/malloc.h>
82 #include <sys/resourcevar.h>
83 #include <sys/ptrace.h>
86 #include <mach/mach_types.h>
87 #include <kern/thread.h>
88 #include <kern/thread_act.h>
89 #include <kern/sched_prim.h>
90 #include <kern/assert.h>
92 #include <sys/ktrace.h>
95 extern char init_task_failure_data
[];
96 int exit1
__P((struct proc
*, int, int *));
108 struct exit_args
*uap
;
111 exit1(p
, W_EXITCODE(uap
->rval
, 0), retval
);
113 /* drop funnel before we return */
114 thread_funnel_set(kernel_flock
, FALSE
);
115 thread_exception_return();
118 thread_block(THREAD_CONTINUE_NULL
);
123 * Exit: deallocate address space and other resources, change proc state
124 * to zombie, and unlink proc from allproc and parent's lists. Save exit
125 * status and rusage for wait(). Check for child processes and orphan them.
129 register struct proc
*p
;
133 register struct proc
*q
, *nq
;
134 thread_t self
= current_thread();
135 thread_act_t th_act_self
= current_act();
136 struct task
*task
= p
->task
;
141 * If a thread in this task has already
142 * called exit(), then halt any others
146 ut
= get_bsdthread_info(th_act_self
);
147 if (ut
->uu_flag
& P_VFORK
) {
148 (void)vfork_exit(p
, rv
);
149 vfork_return(th_act_self
, p
->p_pptr
, p
, retval
);
150 unix_syscall_return(0);
154 while (p
->exit_thread
!= self
) {
155 if (sig_try_locked(p
) <= 0) {
156 if (get_threadtask(th_act_self
) != task
) {
161 thread_terminate(th_act_self
);
162 thread_funnel_set(kernel_flock
, FALSE
);
163 thread_exception_return();
170 printf("pid 1 exited (signal %d, exit %d)",
171 WTERMSIG(rv
), WEXITSTATUS(rv
));
172 panic("init died\nState at Last Exception:\n\n%s",
173 init_task_failure_data
);
177 p
->p_flag
|= P_WEXIT
;
179 (void)proc_prepareexit(p
);
182 /* task terminate will call proc_terminate and that cleans it up */
183 task_terminate_internal(task
);
186 * we come back and returns to AST which
187 * should cleanup the rest
190 if (task
== current_task()) {
191 thread_exception_return();
195 while (task
== current_task()) {
196 thread_terminate_self();
204 proc_prepareexit(struct proc
*p
)
208 thread_t self
= current_thread();
209 thread_act_t th_act_self
= current_act();
212 * Remove proc from allproc queue and from pidhash chain.
213 * Need to do this before we do anything that can block.
214 * Not doing causes things like mount() find this on allproc
215 * in partially cleaned state.
217 LIST_REMOVE(p
, p_list
);
218 LIST_REMOVE(p
, p_hash
);
224 * If parent is waiting for us to exit or exec,
225 * P_PPWAIT is set; we will wakeup the parent below.
227 p
->p_flag
&= ~(P_TRACED
| P_PPWAIT
);
230 ut
= get_bsdthread_info(th_act_self
);
232 untimeout(realitexpire
, (caddr_t
)p
->p_pid
);
236 proc_exit(struct proc
*p
)
238 register struct proc
*q
, *nq
, *pp
;
239 thread_t self
= current_thread();
240 thread_act_t th_act_self
= current_act();
241 struct task
*task
= p
->task
;
243 boolean_t funnel_state
;
245 /* This can happen if thread_terminate of the single thread
249 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
250 if( !(p
->p_flag
& P_WEXIT
)) {
252 p
->p_flag
|= P_WEXIT
;
257 MALLOC_ZONE(p
->p_ru
, struct rusage
*,
258 sizeof (*p
->p_ru
), M_ZOMBIE
, M_WAITOK
);
261 * Close open files and release open-file table.
266 /* Close ref SYSV Shared memory*/
269 /* Release SYSV semaphores */
272 if (SESS_LEADER(p
)) {
273 register struct session
*sp
= p
->p_session
;
279 * Controlling process.
280 * Signal foreground pgrp,
281 * drain controlling terminal
282 * and revoke access to controlling terminal.
284 if (sp
->s_ttyp
->t_session
== sp
) {
285 if (sp
->s_ttyp
->t_pgrp
)
286 pgsignal(sp
->s_ttyp
->t_pgrp
, SIGHUP
, 1);
287 (void) ttywait(sp
->s_ttyp
);
289 * The tty could have been revoked
293 VOP_REVOKE(sp
->s_ttyvp
, REVOKEALL
);
300 * s_ttyp is not zero'd; we use this to indicate
301 * that the session once had a controlling terminal.
302 * (for logging and informational purposes)
308 fixjobc(p
, p
->p_pgrp
, 0);
309 p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
= RLIM_INFINITY
;
310 (void)acct_process(p
);
316 p
->p_traceflag
= 0; /* don't trace the vrele() */
318 struct vnode
*tvp
= p
->p_tracep
;
324 q
= p
->p_children
.lh_first
;
325 if (q
) /* only need this if any child is S_ZOMB */
326 wakeup((caddr_t
) initproc
);
327 for (; q
!= 0; q
= nq
) {
328 nq
= q
->p_sibling
.le_next
;
329 proc_reparent(q
, initproc
);
331 * Traced processes are killed
332 * since their existence means someone is messing up.
334 if (q
->p_flag
& P_TRACED
) {
335 q
->p_flag
&= ~P_TRACED
;
336 if (q
->sigwait_thread
) {
337 thread_t sig_shuttle
;
339 sig_shuttle
= (thread_t
)getshuttle_thread((thread_act_t
)q
->sigwait_thread
);
341 * The sigwait_thread could be stopped at a
342 * breakpoint. Wake it up to kill.
343 * Need to do this as it could be a thread which is not
344 * the first thread in the task. So any attempts to kill
345 * the process would result into a deadlock on q->sigwait.
347 thread_resume((thread_act_t
)q
->sigwait_thread
);
348 clear_wait(sig_shuttle
, THREAD_INTERRUPTED
);
349 threadsignal((thread_act_t
)q
->sigwait_thread
, SIGKILL
, 0);
356 * Save exit status and final rusage info, adding in child rusage
357 * info and self times.
359 *p
->p_ru
= p
->p_stats
->p_ru
;
361 timerclear(&p
->p_ru
->ru_utime
);
362 timerclear(&p
->p_ru
->ru_stime
);
365 task_basic_info_data_t tinfo
;
366 task_thread_times_info_data_t ttimesinfo
;
367 int task_info_stuff
, task_ttimes_stuff
;
368 struct timeval ut
,st
;
370 task_info_stuff
= TASK_BASIC_INFO_COUNT
;
371 task_info(task
, TASK_BASIC_INFO
,
372 &tinfo
, &task_info_stuff
);
373 p
->p_ru
->ru_utime
.tv_sec
= tinfo
.user_time
.seconds
;
374 p
->p_ru
->ru_utime
.tv_usec
= tinfo
.user_time
.microseconds
;
375 p
->p_ru
->ru_stime
.tv_sec
= tinfo
.system_time
.seconds
;
376 p
->p_ru
->ru_stime
.tv_usec
= tinfo
.system_time
.microseconds
;
378 task_ttimes_stuff
= TASK_THREAD_TIMES_INFO_COUNT
;
379 task_info(task
, TASK_THREAD_TIMES_INFO
,
380 &ttimesinfo
, &task_ttimes_stuff
);
382 ut
.tv_sec
= ttimesinfo
.user_time
.seconds
;
383 ut
.tv_usec
= ttimesinfo
.user_time
.microseconds
;
384 st
.tv_sec
= ttimesinfo
.system_time
.seconds
;
385 st
.tv_usec
= ttimesinfo
.system_time
.microseconds
;
386 timeradd(&ut
,&p
->p_ru
->ru_utime
,&p
->p_ru
->ru_utime
);
387 timeradd(&st
,&p
->p_ru
->ru_stime
,&p
->p_ru
->ru_stime
);
390 ruadd(p
->p_ru
, &p
->p_stats
->p_cru
);
393 * Free up profiling buffers.
396 struct uprof
*p0
= &p
->p_stats
->p_prof
, *p1
, *pn
;
402 for (; p1
!= NULL
; p1
= pn
) {
404 kfree((vm_offset_t
)p1
, sizeof *p1
);
409 * Other substructures are freed from wait().
411 FREE_ZONE(p
->p_stats
, sizeof *p
->p_stats
, M_SUBPROC
);
414 FREE_ZONE(p
->p_sigacts
, sizeof *p
->p_sigacts
, M_SUBPROC
);
417 if (--p
->p_limit
->p_refcnt
== 0)
418 FREE_ZONE(p
->p_limit
, sizeof *p
->p_limit
, M_SUBPROC
);
422 * Finish up by terminating the task
423 * and halt this thread (only if a
424 * member of the task exiting).
428 set_bsdtask_info(task
, NULL
);
431 * Notify parent that we're gone.
433 if (p
->p_pptr
->p_flag
& P_NOCLDWAIT
) {
434 struct proc
* pp
= p
->p_pptr
;
436 proc_reparent(p
, initproc
);
437 /* If there are no more children wakeup parent */
438 if (LIST_EMPTY(&pp
->p_children
))
441 /* should be fine as parent proc would be initproc */
443 if (pp
!= initproc
) {
444 pp
->si_pid
= p
->p_pid
;
445 pp
->si_status
= p
->p_xstat
;
446 pp
->si_code
= CLD_EXITED
;
447 pp
->si_uid
= p
->p_cred
->p_ruid
;
449 psignal(pp
, SIGCHLD
);
452 /* Place onto zombproc. */
453 LIST_INSERT_HEAD(&zombproc
, p
, p_list
);
456 /* and now wakeup the parent */
457 wakeup((caddr_t
)p
->p_pptr
);
459 (void) thread_funnel_set(kernel_flock
, funnel_state
);
467 struct rusage
*rusage
;
472 owait(p
, uap
, retval
)
477 struct wait4_args
*a
;
479 a
= (struct wait4_args
*)get_bsduthreadarg(current_act());
485 return (wait1(p
, a
, retval
, 1));
489 wait4(p
, uap
, retval
)
491 struct wait4_args
*uap
;
494 return (wait1(p
, uap
, retval
, 0));
500 struct rusage
*rusage
;
504 owait3(p
, uap
, retval
)
506 struct owait3_args
*uap
;
509 struct wait4_args
*a
;
511 a
= (struct wait4_args
*)get_bsduthreadarg(current_act
);
513 a
->rusage
= uap
->rusage
;
514 a
->options
= uap
->options
;
515 a
->status
= uap
->status
;
518 return (wait1(p
, a
, retval
, 1));
526 wait1continue(result
)
537 thread
= current_act();
538 vt
= (void *)get_bsduthreadarg(thread
);
539 retval
= (int *)get_bsduthreadrval(thread
);
540 wait1((struct proc
*)p
, (struct wait4_args
*)vt
, retval
, 0);
544 wait1(q
, uap
, retval
, compat
)
545 register struct proc
*q
;
546 register struct wait4_args
*uap
;
553 register struct proc
*p
, *t
;
559 uap
->pid
= -q
->p_pgid
;
563 for (p
= q
->p_children
.lh_first
; p
!= 0; p
= p
->p_sibling
.le_next
) {
564 if (uap
->pid
!= WAIT_ANY
&&
565 p
->p_pid
!= uap
->pid
&&
566 p
->p_pgid
!= -(uap
->pid
))
569 if (p
->p_flag
& P_WAITING
) {
570 (void)tsleep(&p
->p_stat
, PWAIT
, "waitcoll", 0);
573 p
->p_flag
|= P_WAITING
; /* only allow single thread to wait() */
575 if (p
->p_stat
== SZOMB
) {
576 retval
[0] = p
->p_pid
;
579 retval
[1] = p
->p_xstat
;
583 status
= p
->p_xstat
; /* convert to int */
584 if (error
= copyout((caddr_t
)&status
,
585 (caddr_t
)uap
->status
,
587 p
->p_flag
&= ~P_WAITING
;
593 (error
= copyout((caddr_t
)p
->p_ru
,
594 (caddr_t
)uap
->rusage
,
595 sizeof (struct rusage
)))) {
596 p
->p_flag
&= ~P_WAITING
;
601 * If we got the child via a ptrace 'attach',
602 * we need to give it back to the old parent.
604 if (p
->p_oppid
&& (t
= pfind(p
->p_oppid
))) {
608 t
->si_pid
= p
->p_pid
;
609 t
->si_status
= p
->p_xstat
;
610 t
->si_code
= CLD_CONTINUED
;
611 t
->si_uid
= p
->p_cred
->p_ruid
;
615 p
->p_flag
&= ~P_WAITING
;
621 ruadd(&q
->p_stats
->p_cru
, p
->p_ru
);
622 FREE_ZONE(p
->p_ru
, sizeof *p
->p_ru
, M_ZOMBIE
);
625 printf("Warning : lost p_ru for %s\n", p
->p_comm
);
629 * Decrement the count of procs running with this uid.
631 (void)chgproccnt(p
->p_cred
->p_ruid
, -1);
634 * Free up credentials.
636 if (--p
->p_cred
->p_refcnt
== 0) {
637 struct ucred
*ucr
= p
->p_ucred
;
646 FREE_ZONE(pcr
, sizeof *pcr
, M_SUBPROC
);
650 * Release reference to text vnode
658 * Finally finished with old proc entry.
659 * Unlink it from its process group and free it.
662 LIST_REMOVE(p
, p_list
); /* off zombproc */
663 LIST_REMOVE(p
, p_sibling
);
664 p
->p_flag
&= ~P_WAITING
;
665 FREE_ZONE(p
, sizeof *p
, M_PROC
);
670 if (p
->p_stat
== SSTOP
&& (p
->p_flag
& P_WAITED
) == 0 &&
671 (p
->p_flag
& P_TRACED
|| uap
->options
& WUNTRACED
)) {
672 p
->p_flag
|= P_WAITED
;
673 retval
[0] = p
->p_pid
;
676 retval
[1] = W_STOPCODE(p
->p_xstat
);
681 status
= W_STOPCODE(p
->p_xstat
);
682 error
= copyout((caddr_t
)&status
,
683 (caddr_t
)uap
->status
,
687 p
->p_flag
&= ~P_WAITING
;
691 p
->p_flag
&= ~P_WAITING
;
697 if (uap
->options
& WNOHANG
) {
702 if (error
= tsleep0((caddr_t
)q
, PWAIT
| PCATCH
, "wait", 0, wait1continue
))
709 * make process 'parent' the new parent of process 'child'.
712 proc_reparent(child
, parent
)
713 register struct proc
*child
;
714 register struct proc
*parent
;
717 if (child
->p_pptr
== parent
)
720 LIST_REMOVE(child
, p_sibling
);
721 LIST_INSERT_HEAD(&parent
->p_children
, child
, p_sibling
);
722 child
->p_pptr
= parent
;
726 * Make the current process an "init" process, meaning
727 * that it doesn't have a parent, and that it won't be
728 * gunned down by kill(-1, 0).
733 register struct proc
*p
= current_proc();
735 if (suser(p
->p_ucred
, &p
->p_acflag
))
736 return(KERN_NO_ACCESS
);
738 if (p
->p_pid
!= 1 && p
->p_pgid
!= p
->p_pid
)
739 enterpgrp(p
, p
->p_pid
, 0);
740 p
->p_flag
|= P_SYSTEM
;
743 * Take us out of the sibling chain, and
744 * out of our parent's child chain.
746 LIST_REMOVE(p
, p_sibling
);
747 p
->p_sibling
.le_prev
= NULL
;
748 p
->p_sibling
.le_next
= NULL
;
749 p
->p_pptr
= kernproc
;
751 return(KERN_SUCCESS
);
755 process_terminate_self(void)
757 struct proc
*p
= current_proc();
760 exit1(p
, W_EXITCODE(0, SIGKILL
), (int *)NULL
);
766 * Exit: deallocate address space and other resources, change proc state
767 * to zombie, and unlink proc from allproc and parent's lists. Save exit
768 * status and rusage for wait(). Check for child processes and orphan them.
776 register struct proc
*q
, *nq
;
777 thread_t self
= current_thread();
778 thread_act_t th_act_self
= current_act();
779 struct task
*task
= p
->task
;
784 * If a thread in this task has already
785 * called exit(), then halt any others
789 ut
= get_bsdthread_info(th_act_self
);
792 while (p
->exit_thread
!= self
) {
793 if (sig_try_locked(p
) <= 0) {
794 if (get_threadtask(th_act_self
) != task
) {
799 thread_terminate(th_act_self
);
800 thread_funnel_set(kernel_flock
, FALSE
);
801 thread_exception_return();
808 printf("pid 1 exited (signal %d, exit %d)",
809 WTERMSIG(rv
), WEXITSTATUS(rv
));
810 panic("init died\nState at Last Exception:\n\n%s", init_task_failure_data
);
815 p
->p_flag
|= P_WEXIT
;
818 * Remove proc from allproc queue and from pidhash chain.
819 * Need to do this before we do anything that can block.
820 * Not doing causes things like mount() find this on allproc
821 * in partially cleaned state.
823 LIST_REMOVE(p
, p_list
);
824 LIST_REMOVE(p
, p_hash
);
826 * If parent is waiting for us to exit or exec,
827 * P_PPWAIT is set; we will wakeup the parent below.
829 p
->p_flag
&= ~(P_TRACED
| P_PPWAIT
);
834 untimeout(realitexpire
, (caddr_t
)p
->p_pid
);
842 vproc_exit(struct proc
*p
)
844 register struct proc
*q
, *nq
, *pp
;
845 thread_t self
= current_thread();
846 thread_act_t th_act_self
= current_act();
847 struct task
*task
= p
->task
;
849 boolean_t funnel_state
;
851 MALLOC_ZONE(p
->p_ru
, struct rusage
*,
852 sizeof (*p
->p_ru
), M_ZOMBIE
, M_WAITOK
);
855 * Close open files and release open-file table.
860 if (SESS_LEADER(p
)) {
861 register struct session
*sp
= p
->p_session
;
867 * Controlling process.
868 * Signal foreground pgrp,
869 * drain controlling terminal
870 * and revoke access to controlling terminal.
872 if (sp
->s_ttyp
->t_session
== sp
) {
873 if (sp
->s_ttyp
->t_pgrp
)
874 pgsignal(sp
->s_ttyp
->t_pgrp
, SIGHUP
, 1);
875 (void) ttywait(sp
->s_ttyp
);
877 * The tty could have been revoked
881 VOP_REVOKE(sp
->s_ttyvp
, REVOKEALL
);
888 * s_ttyp is not zero'd; we use this to indicate
889 * that the session once had a controlling terminal.
890 * (for logging and informational purposes)
896 fixjobc(p
, p
->p_pgrp
, 0);
897 p
->p_rlimit
[RLIMIT_FSIZE
].rlim_cur
= RLIM_INFINITY
;
903 p
->p_traceflag
= 0; /* don't trace the vrele() */
905 struct vnode
*tvp
= p
->p_tracep
;
911 q
= p
->p_children
.lh_first
;
912 if (q
) /* only need this if any child is S_ZOMB */
913 wakeup((caddr_t
) initproc
);
914 for (; q
!= 0; q
= nq
) {
915 nq
= q
->p_sibling
.le_next
;
916 proc_reparent(q
, initproc
);
918 * Traced processes are killed
919 * since their existence means someone is messing up.
921 if (q
->p_flag
& P_TRACED
) {
922 q
->p_flag
&= ~P_TRACED
;
923 if (q
->sigwait_thread
) {
924 thread_t sig_shuttle
;
926 sig_shuttle
= (thread_t
) getshuttle_thread((thread_act_t
)q
->sigwait_thread
);
928 * The sigwait_thread could be stopped at a
929 * breakpoint. Wake it up to kill.
930 * Need to do this as it could be a thread which is not
931 * the first thread in the task. So any attempts to kill
932 * the process would result into a deadlock on q->sigwait.
934 thread_resume((thread_act_t
)q
->sigwait_thread
);
935 clear_wait(sig_shuttle
, THREAD_INTERRUPTED
);
936 threadsignal((thread_act_t
)q
->sigwait_thread
, SIGKILL
, 0);
943 * Save exit status and final rusage info, adding in child rusage
944 * info and self times.
946 *p
->p_ru
= p
->p_stats
->p_ru
;
948 timerclear(&p
->p_ru
->ru_utime
);
949 timerclear(&p
->p_ru
->ru_stime
);
953 task_basic_info_data_t tinfo
;
954 task_thread_times_info_data_t ttimesinfo
;
955 int task_info_stuff
, task_ttimes_stuff
;
956 struct timeval ut
,st
;
958 task_info_stuff
= TASK_BASIC_INFO_COUNT
;
959 task_info(task
, TASK_BASIC_INFO
,
960 &tinfo
, &task_info_stuff
);
961 p
->p_ru
->ru_utime
.tv_sec
= tinfo
.user_time
.seconds
;
962 p
->p_ru
->ru_utime
.tv_usec
= tinfo
.user_time
.microseconds
;
963 p
->p_ru
->ru_stime
.tv_sec
= tinfo
.system_time
.seconds
;
964 p
->p_ru
->ru_stime
.tv_usec
= tinfo
.system_time
.microseconds
;
966 task_ttimes_stuff
= TASK_THREAD_TIMES_INFO_COUNT
;
967 task_info(task
, TASK_THREAD_TIMES_INFO
,
968 &ttimesinfo
, &task_ttimes_stuff
);
970 ut
.tv_sec
= ttimesinfo
.user_time
.seconds
;
971 ut
.tv_usec
= ttimesinfo
.user_time
.microseconds
;
972 st
.tv_sec
= ttimesinfo
.system_time
.seconds
;
973 st
.tv_usec
= ttimesinfo
.system_time
.microseconds
;
974 timeradd(&ut
,&p
->p_ru
->ru_utime
,&p
->p_ru
->ru_utime
);
975 timeradd(&st
,&p
->p_ru
->ru_stime
,&p
->p_ru
->ru_stime
);
979 ruadd(p
->p_ru
, &p
->p_stats
->p_cru
);
982 * Free up profiling buffers.
985 struct uprof
*p0
= &p
->p_stats
->p_prof
, *p1
, *pn
;
991 for (; p1
!= NULL
; p1
= pn
) {
993 kfree((vm_offset_t
)p1
, sizeof *p1
);
998 * Other substructures are freed from wait().
1000 FREE_ZONE(p
->p_stats
, sizeof *p
->p_stats
, M_SUBPROC
);
1003 FREE_ZONE(p
->p_sigacts
, sizeof *p
->p_sigacts
, M_SUBPROC
);
1004 p
->p_sigacts
= NULL
;
1006 if (--p
->p_limit
->p_refcnt
== 0)
1007 FREE_ZONE(p
->p_limit
, sizeof *p
->p_limit
, M_SUBPROC
);
1011 * Finish up by terminating the task
1012 * and halt this thread (only if a
1013 * member of the task exiting).
1015 p
->task
= TASK_NULL
;
1018 * Notify parent that we're gone.
1021 if (pp
!= initproc
) {
1022 pp
->si_pid
= p
->p_pid
;
1023 pp
->si_status
= p
->p_xstat
;
1024 pp
->si_code
= CLD_EXITED
;
1025 pp
->si_uid
= p
->p_cred
->p_ruid
;
1027 psignal(p
->p_pptr
, SIGCHLD
);
1029 /* Place onto zombproc. */
1030 LIST_INSERT_HEAD(&zombproc
, p
, p_list
);
1033 /* and now wakeup the parent */
1034 wakeup((caddr_t
)p
->p_pptr
);