]>
git.saurik.com Git - apple/xnu.git/blob - bsd/kern/kern_fork.c
59e6e5019f6146329b900ac33366f96ab857ebb6
2 * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 /* Copyright (c) 1995, 1997 Apple Computer, Inc. All Rights Reserved */
32 * Copyright (c) 1982, 1986, 1989, 1991, 1993
33 * The Regents of the University of California. All rights reserved.
34 * (c) UNIX System Laboratories, Inc.
35 * All or some portions of this file are derived from material licensed
36 * to the University of California by American Telephone and Telegraph
37 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
38 * the permission of UNIX System Laboratories, Inc.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. All advertising materials mentioning features or use of this software
49 * must display the following acknowledgement:
50 * This product includes software developed by the University of
51 * California, Berkeley and its contributors.
52 * 4. Neither the name of the University nor the names of its contributors
53 * may be used to endorse or promote products derived from this software
54 * without specific prior written permission.
56 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
57 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
58 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
59 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
60 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
61 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
62 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
63 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
64 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
65 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 * @(#)kern_fork.c 8.8 (Berkeley) 2/14/95
71 #include <kern/assert.h>
72 #include <sys/param.h>
73 #include <sys/systm.h>
74 #include <sys/filedesc.h>
75 #include <sys/kernel.h>
76 #include <sys/malloc.h>
77 #include <sys/proc_internal.h>
78 #include <sys/kauth.h>
80 #include <sys/resourcevar.h>
81 #include <sys/vnode_internal.h>
82 #include <sys/file_internal.h>
85 #include <sys/ktrace.h>
88 #include <bsm/audit_kernel.h>
90 #include <mach/mach_types.h>
91 #include <kern/kern_types.h>
92 #include <kern/kalloc.h>
93 #include <kern/mach_param.h>
94 #include <kern/task.h>
95 #include <kern/zalloc.h>
97 #include <machine/spl.h>
99 #include <vm/vm_protos.h> // for vm_map_commpage64
101 thread_t
cloneproc(struct proc
*, int);
102 struct proc
* forkproc(struct proc
*, int);
103 thread_t
procdup(struct proc
*child
, struct proc
*parent
);
105 #define DOFORK 0x1 /* fork() system call */
106 #define DOVFORK 0x2 /* vfork() system call */
107 static int fork1(struct proc
*, long, register_t
*);
113 fork(struct proc
*p
, __unused
void *uap
, register_t
*retval
)
115 return (fork1(p
, (long)DOFORK
, retval
));
122 vfork(struct proc
*p
, void *uap
, register_t
*retval
)
124 register struct proc
* newproc
;
126 thread_t cur_act
= (thread_t
)current_thread();
132 * Although process entries are dynamically created, we still keep
133 * a global limit on the maximum number we will create. Don't allow
134 * a nonprivileged user to use the last process; don't let root
135 * exceed the limit. The variable nprocs is the current number of
136 * processes, maxproc is the limit.
138 uid
= kauth_cred_get()->cr_ruid
;
139 if ((nprocs
>= maxproc
- 1 && uid
!= 0) || nprocs
>= maxproc
) {
146 * Increment the count of procs running with this uid. Don't allow
147 * a nonprivileged user to exceed their current limit.
149 count
= chgproccnt(uid
, 1);
150 if (uid
!= 0 && count
> p
->p_rlimit
[RLIMIT_NPROC
].rlim_cur
) {
151 (void)chgproccnt(uid
, -1);
155 ut
= (struct uthread
*)get_bsdthread_info(cur_act
);
156 if (ut
->uu_flag
& UT_VFORK
) {
157 printf("vfork called recursively by %s\n", p
->p_comm
);
158 (void)chgproccnt(uid
, -1);
161 p
->p_flag
|= P_VFORK
;
164 /* The newly created process comes with signal lock held */
165 newproc
= (struct proc
*)forkproc(p
,1);
167 AUDIT_ARG(pid
, newproc
->p_pid
);
169 LIST_INSERT_AFTER(p
, newproc
, p_pglist
);
171 newproc
->task
= p
->task
;
172 LIST_INSERT_HEAD(&p
->p_children
, newproc
, p_sibling
);
173 LIST_INIT(&newproc
->p_children
);
174 LIST_INSERT_HEAD(&allproc
, newproc
, p_list
);
175 LIST_INSERT_HEAD(PIDHASH(newproc
->p_pid
), newproc
, p_hash
);
176 TAILQ_INIT(& newproc
->p_evlist
);
177 newproc
->p_stat
= SRUN
;
178 newproc
->p_flag
|= P_INVFORK
;
179 newproc
->p_vforkact
= cur_act
;
181 ut
->uu_flag
|= UT_VFORK
;
182 ut
->uu_proc
= newproc
;
183 ut
->uu_userstate
= (void *)act_thread_csave();
184 ut
->uu_vforkmask
= ut
->uu_sigmask
;
186 /* temporarily drop thread-set-id state */
187 if (ut
->uu_flag
& UT_SETUID
) {
188 ut
->uu_flag
|= UT_WASSETUID
;
189 ut
->uu_flag
&= ~UT_SETUID
;
192 thread_set_child(cur_act
, newproc
->p_pid
);
194 microtime(&newproc
->p_stats
->p_start
);
195 newproc
->p_acflag
= AFORK
;
198 * Preserve synchronization semantics of vfork. If waiting for
199 * child to exec or exit, set P_PPWAIT on child, and sleep on our
200 * proc (in case of exit).
202 newproc
->p_flag
|= P_PPWAIT
;
204 /* drop the signal lock on the child */
205 signal_unlock(newproc
);
207 retval
[0] = newproc
->p_pid
;
208 retval
[1] = 1; /* mark child */
214 * Return to parent vfork ehread()
217 vfork_return(__unused thread_t th_act
, struct proc
*p
, struct proc
*p2
,
220 thread_t cur_act
= (thread_t
)current_thread();
223 ut
= (struct uthread
*)get_bsdthread_info(cur_act
);
225 act_thread_catt(ut
->uu_userstate
);
227 /* Make sure only one at this time */
229 if (p
->p_vforkcnt
<0)
230 panic("vfork cnt is -ve");
231 if (p
->p_vforkcnt
<=0)
232 p
->p_flag
&= ~P_VFORK
;
233 ut
->uu_userstate
= 0;
234 ut
->uu_flag
&= ~UT_VFORK
;
235 /* restore thread-set-id state */
236 if (ut
->uu_flag
& UT_WASSETUID
) {
237 ut
->uu_flag
|= UT_SETUID
;
238 ut
->uu_flag
&= UT_WASSETUID
;
241 ut
->uu_sigmask
= ut
->uu_vforkmask
;
242 p2
->p_flag
&= ~P_INVFORK
;
243 p2
->p_vforkact
= (void *)0;
245 thread_set_parent(cur_act
, p2
->p_pid
);
248 retval
[0] = p2
->p_pid
;
249 retval
[1] = 0; /* mark parent */
256 procdup(struct proc
*child
, struct proc
*parent
)
260 kern_return_t result
;
262 if (parent
->task
== kernel_task
)
263 result
= task_create_internal(TASK_NULL
, FALSE
, FALSE
, &task
);
265 result
= task_create_internal(parent
->task
, TRUE
, (parent
->p_flag
& P_LP64
), &task
);
266 if (result
!= KERN_SUCCESS
)
267 printf("fork/procdup: task_create failed. Code: 0x%x\n", result
);
269 /* task->proc = child; */
270 set_bsdtask_info(task
, child
);
271 if (parent
->p_flag
& P_LP64
) {
272 task_set_64bit(task
, TRUE
);
273 vm_map_set_64bit(get_task_map(task
));
274 child
->p_flag
|= P_LP64
;
275 /* LP64todo - clean up this hacked mapping of commpage */
276 pmap_map_sharedpage(task
, get_map_pmap(get_task_map(task
)));
277 vm_map_commpage64(get_task_map(task
));
279 task_set_64bit(task
, FALSE
);
280 vm_map_set_32bit(get_task_map(task
));
281 child
->p_flag
&= ~P_LP64
;
284 * On Intel, the comm page doesn't get mapped automatically
285 * because it goes beyond the end of the VM map in the current
286 * 3GB/1GB address space model.
287 * XXX This explicit mapping will probably become unnecessary
288 * when we switch to the new 4GB/4GB address space model.
290 vm_map_commpage32(get_task_map(task
));
291 #endif /* __i386__ */
293 if (child
->p_nice
!= 0)
294 resetpriority(child
);
296 result
= thread_create(task
, &thread
);
297 if (result
!= KERN_SUCCESS
)
298 printf("fork/procdup: thread_create failed. Code: 0x%x\n", result
);
305 fork1(p1
, flags
, retval
)
310 register struct proc
*p2
;
317 * Although process entries are dynamically created, we still keep
318 * a global limit on the maximum number we will create. Don't allow
319 * a nonprivileged user to use the last process; don't let root
320 * exceed the limit. The variable nprocs is the current number of
321 * processes, maxproc is the limit.
323 uid
= kauth_cred_get()->cr_ruid
;
324 if ((nprocs
>= maxproc
- 1 && uid
!= 0) || nprocs
>= maxproc
) {
331 * Increment the count of procs running with this uid. Don't allow
332 * a nonprivileged user to exceed their current limit.
334 count
= chgproccnt(uid
, 1);
335 if (uid
!= 0 && count
> p1
->p_rlimit
[RLIMIT_NPROC
].rlim_cur
) {
336 (void)chgproccnt(uid
, -1);
340 /* The newly created process comes with signal lock held */
341 newth
= cloneproc(p1
, 1);
343 /* p2 = newth->task->proc; */
344 p2
= (struct proc
*)(get_bsdtask_info(get_threadtask(newth
)));
345 set_security_token(p2
); /* propagate change of PID */
347 AUDIT_ARG(pid
, p2
->p_pid
);
349 thread_set_child(newth
, p2
->p_pid
);
351 microtime(&p2
->p_stats
->p_start
);
352 p2
->p_acflag
= AFORK
;
355 * Preserve synchronization semantics of vfork. If waiting for
356 * child to exec or exit, set P_PPWAIT on child, and sleep on our
357 * proc (in case of exit).
359 if (flags
== DOVFORK
)
360 p2
->p_flag
|= P_PPWAIT
;
361 /* drop the signal lock on the child */
364 (void) thread_resume(newth
);
366 /* drop the extra references we got during the creation */
367 if ((t
= (task_t
)get_threadtask(newth
)) != NULL
) {
370 thread_deallocate(newth
);
372 KNOTE(&p1
->p_klist
, NOTE_FORK
| p2
->p_pid
);
374 while (p2
->p_flag
& P_PPWAIT
)
375 tsleep(p1
, PWAIT
, "ppwait", 0);
377 retval
[0] = p2
->p_pid
;
378 retval
[1] = 0; /* mark parent */
386 * Create a new process from a specified process.
387 * On return newly created child process has signal
388 * lock held to block delivery of signal to it if called with
389 * lock set. fork() code needs to explicity remove this lock
390 * before signals can be delivered
394 register struct proc
*p1
;
397 register struct proc
*p2
;
400 p2
= (struct proc
*)forkproc(p1
,lock
);
403 th
= procdup(p2
, p1
); /* child, parent */
405 LIST_INSERT_AFTER(p1
, p2
, p_pglist
);
407 LIST_INSERT_HEAD(&p1
->p_children
, p2
, p_sibling
);
408 LIST_INIT(&p2
->p_children
);
409 LIST_INSERT_HEAD(&allproc
, p2
, p_list
);
410 LIST_INSERT_HEAD(PIDHASH(p2
->p_pid
), p2
, p_hash
);
411 TAILQ_INIT(&p2
->p_evlist
);
413 * Make child runnable, set start time.
422 register struct proc
*p1
;
425 register struct proc
*p2
, *newproc
;
426 static int nextpid
= 0, pidchecked
= 0;
428 /* Allocate new proc. */
429 MALLOC_ZONE(newproc
, struct proc
*,
430 sizeof *newproc
, M_PROC
, M_WAITOK
);
432 panic("forkproc: M_PROC zone exhausted");
433 MALLOC_ZONE(newproc
->p_stats
, struct pstats
*,
434 sizeof *newproc
->p_stats
, M_SUBPROC
, M_WAITOK
);
435 if (newproc
->p_stats
== NULL
)
436 panic("forkproc: M_SUBPROC zone exhausted (p_stats)");
437 MALLOC_ZONE(newproc
->p_sigacts
, struct sigacts
*,
438 sizeof *newproc
->p_sigacts
, M_SUBPROC
, M_WAITOK
);
439 if (newproc
->p_sigacts
== NULL
)
440 panic("forkproc: M_SUBPROC zone exhausted (p_sigacts)");
443 * Find an unused process ID. We remember a range of unused IDs
444 * ready to use (from nextpid+1 through pidchecked-1).
449 * If the process ID prototype has wrapped around,
450 * restart somewhat above 0, as the low-numbered procs
451 * tend to include daemons that don't exit.
453 if (nextpid
>= PID_MAX
) {
457 if (nextpid
>= pidchecked
) {
460 pidchecked
= PID_MAX
;
462 * Scan the active and zombie procs to check whether this pid
463 * is in use. Remember the lowest pid that's greater
464 * than nextpid, so we can avoid checking for a while.
466 p2
= allproc
.lh_first
;
468 for (; p2
!= 0; p2
= p2
->p_list
.le_next
) {
469 while (p2
->p_pid
== nextpid
||
470 p2
->p_pgrp
->pg_id
== nextpid
||
471 p2
->p_session
->s_sid
== nextpid
) {
473 if (nextpid
>= pidchecked
)
476 if (p2
->p_pid
> nextpid
&& pidchecked
> p2
->p_pid
)
477 pidchecked
= p2
->p_pid
;
478 if (p2
->p_pgrp
&& p2
->p_pgrp
->pg_id
> nextpid
&&
479 pidchecked
> p2
->p_pgrp
->pg_id
)
480 pidchecked
= p2
->p_pgrp
->pg_id
;
481 if (p2
->p_session
->s_sid
> nextpid
&&
482 pidchecked
> p2
->p_session
->s_sid
)
483 pidchecked
= p2
->p_session
->s_sid
;
487 p2
= zombproc
.lh_first
;
495 p2
->p_shutdownstate
= 0;
499 * Make a proc table entry for the new process.
500 * Start by zeroing the section of proc that is zero-initialized,
501 * then copy the section that is copied directly from the parent.
503 bzero(&p2
->p_startzero
,
504 (unsigned) ((caddr_t
)&p2
->p_endzero
- (caddr_t
)&p2
->p_startzero
));
505 bcopy(&p1
->p_startcopy
, &p2
->p_startcopy
,
506 (unsigned) ((caddr_t
)&p2
->p_endcopy
- (caddr_t
)&p2
->p_startcopy
));
507 p2
->vm_shm
= (void *)NULL
; /* Make sure it is zero */
510 * Some flags are inherited from the parent.
511 * Duplicate sub-structures as needed.
512 * Increase reference counts on shared objects.
513 * The p_stats and p_sigacts substructs are set in vm_fork.
515 p2
->p_flag
= (p1
->p_flag
& (P_LP64
| P_TRANSLATED
| P_AFFINITY
));
516 if (p1
->p_flag
& P_PROFIL
)
519 * Note that if the current thread has an assumed identity, this
520 * credential will be granted to the new process.
522 p2
->p_ucred
= kauth_cred_get_with_ref();
524 lck_mtx_init(&p2
->p_mlock
, proc_lck_grp
, proc_lck_attr
);
525 lck_mtx_init(&p2
->p_fdmlock
, proc_lck_grp
, proc_lck_attr
);
526 klist_init(&p2
->p_klist
);
528 /* bump references to the text vnode */
529 p2
->p_textvp
= p1
->p_textvp
;
531 vnode_rele(p2
->p_textvp
);
533 /* XXX may fail to copy descriptors to child */
534 p2
->p_fd
= fdcopy(p1
);
537 /* XXX may fail to attach shm to child */
538 (void)shmfork(p1
,p2
);
541 * If p_limit is still copy-on-write, bump refcnt,
542 * otherwise get a copy that won't be modified.
543 * (If PL_SHAREMOD is clear, the structure is shared
546 if (p1
->p_limit
->p_lflags
& PL_SHAREMOD
)
547 p2
->p_limit
= limcopy(p1
->p_limit
);
549 p2
->p_limit
= p1
->p_limit
;
550 p2
->p_limit
->p_refcnt
++;
553 bzero(&p2
->p_stats
->pstat_startzero
,
554 (unsigned) ((caddr_t
)&p2
->p_stats
->pstat_endzero
-
555 (caddr_t
)&p2
->p_stats
->pstat_startzero
));
556 bcopy(&p1
->p_stats
->pstat_startcopy
, &p2
->p_stats
->pstat_startcopy
,
557 ((caddr_t
)&p2
->p_stats
->pstat_endcopy
-
558 (caddr_t
)&p2
->p_stats
->pstat_startcopy
));
560 bzero(&p2
->p_stats
->user_p_prof
, sizeof(struct user_uprof
));
562 if (p1
->p_sigacts
!= NULL
)
563 (void)memcpy(p2
->p_sigacts
,
564 p1
->p_sigacts
, sizeof *p2
->p_sigacts
);
566 (void)memset(p2
->p_sigacts
, 0, sizeof *p2
->p_sigacts
);
568 if (p1
->p_session
->s_ttyvp
!= NULL
&& p1
->p_flag
& P_CONTROLT
)
569 p2
->p_flag
|= P_CONTROLT
;
571 p2
->p_argslen
= p1
->p_argslen
;
572 p2
->p_argc
= p1
->p_argc
;
576 p2
->p_debugger
= 0; /* don't inherit */
577 lockinit(&p2
->signal_lock
, PVM
, "signal", 0, 0);
578 /* block all signals to reach the process */
582 p2
->sigwait_thread
= NULL
;
583 p2
->exit_thread
= NULL
;
584 p2
->user_stack
= p1
->user_stack
;
589 p2
->p_internalref
= 0;
590 TAILQ_INIT(&p2
->p_uthlist
);
591 TAILQ_INIT(&p2
->aio_activeq
);
592 TAILQ_INIT(&p2
->aio_doneq
);
593 p2
->aio_active_count
= 0;
594 p2
->aio_done_count
= 0;
598 * Copy traceflag and tracefile if enabled.
599 * If not inherited, these were zeroed above.
601 if (p1
->p_traceflag
&KTRFAC_INHERIT
) {
602 p2
->p_traceflag
= p1
->p_traceflag
;
603 if ((p2
->p_tracep
= p1
->p_tracep
) != NULL
) {
604 vnode_ref(p2
->p_tracep
);
615 lck_mtx_lock(&p
->p_mlock
);
619 proc_unlock(proc_t p
)
621 lck_mtx_unlock(&p
->p_mlock
);
624 #include <kern/zalloc.h>
626 struct zone
*uthread_zone
;
627 int uthread_zone_inited
= 0;
630 uthread_zone_init(void)
632 if (!uthread_zone_inited
) {
633 uthread_zone
= zinit(sizeof(struct uthread
),
634 THREAD_MAX
* sizeof(struct uthread
),
635 THREAD_CHUNK
* sizeof(struct uthread
),
637 uthread_zone_inited
= 1;
642 uthread_alloc(task_t task
, thread_t thr_act
)
645 struct uthread
*uth
, *uth_parent
;
647 boolean_t funnel_state
;
649 if (!uthread_zone_inited
)
652 ut
= (void *)zalloc(uthread_zone
);
653 bzero(ut
, sizeof(struct uthread
));
655 p
= (struct proc
*) get_bsdtask_info(task
);
656 uth
= (struct uthread
*)ut
;
659 * Thread inherits credential from the creating thread, if both
660 * are in the same task.
662 * If the creating thread has no credential or is from another
663 * task we can leave the new thread credential NULL. If it needs
664 * one later, it will be lazily assigned from the task's process.
666 uth_parent
= (struct uthread
*)get_bsdthread_info(current_thread());
667 if ((task
== current_task()) &&
668 (uth_parent
!= NULL
) &&
669 (uth_parent
->uu_ucred
!= NOCRED
)) {
670 uth
->uu_ucred
= uth_parent
->uu_ucred
;
671 kauth_cred_ref(uth
->uu_ucred
);
672 /* the credential we just inherited is an assumed credential */
673 if (uth_parent
->uu_flag
& UT_SETUID
)
674 uth
->uu_flag
|= UT_SETUID
;
676 uth
->uu_ucred
= NOCRED
;
679 if (task
!= kernel_task
) {
681 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
683 if (uth_parent
->uu_flag
& UT_SAS_OLDMASK
)
684 uth
->uu_sigmask
= uth_parent
->uu_oldmask
;
686 uth
->uu_sigmask
= uth_parent
->uu_sigmask
;
688 uth
->uu_act
= thr_act
;
691 TAILQ_INSERT_TAIL(&p
->p_uthlist
, uth
, uu_list
);
694 (void)thread_funnel_set(kernel_flock
, funnel_state
);
702 uthread_free(task_t task
, void *uthread
, void * bsd_info
)
705 struct uthread
*uth
= (struct uthread
*)uthread
;
706 struct proc
* p
= (struct proc
*)bsd_info
;
707 boolean_t funnel_state
;
710 * Per-thread audit state should never last beyond system
711 * call return. Since we don't audit the thread creation/
712 * removal, the thread state pointer should never be
713 * non-NULL when we get here.
715 assert(uth
->uu_ar
== NULL
);
717 sel
= &uth
->uu_select
;
718 /* cleanup the select bit space */
720 FREE(sel
->ibits
, M_TEMP
);
721 FREE(sel
->obits
, M_TEMP
);
724 if (sel
->allocsize
&& sel
->wqset
){
725 kfree(sel
->wqset
, sel
->allocsize
);
732 if (uth
->uu_ucred
!= NOCRED
)
733 kauth_cred_rele(uth
->uu_ucred
);
735 if ((task
!= kernel_task
) && p
) {
736 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
738 TAILQ_REMOVE(&p
->p_uthlist
, uth
, uu_list
);
740 (void)thread_funnel_set(kernel_flock
, funnel_state
);
742 /* and free the uthread itself */
743 zfree(uthread_zone
, uthread
);