2 * Copyright (c) 2003 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@
23 #include <sys/systm.h>
24 #include <sys/proc_internal.h>
25 #include <sys/vnode_internal.h> // vn_getpath()
26 #include <kern/task.h>
29 int chudxnu_pid_for_task(task_t task
);
30 task_t
chudxnu_task_for_pid(int pid
);
31 int chudxnu_current_pid(void);
33 __private_extern__
int
34 chudxnu_pid_for_task(task_t task
)
39 p
= (struct proc
*)(get_bsdtask_info(task
));
47 __private_extern__ task_t
48 chudxnu_task_for_pid(int pid
)
50 struct proc
*p
= pfind(pid
);
57 __private_extern__
int
58 chudxnu_current_pid(void)
61 struct uthread
*ut
= get_bsdthread_info(current_thread());
62 task_t t
= current_task();
65 pid
= chudxnu_pid_for_task(t
);
67 // no task, so try looking in the uthread and/or proc
68 pid
= current_proc()->p_pid
;
70 if(ut
&& ut
->uu_proc
) {
71 pid
= ut
->uu_proc
->p_pid
;