]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/chud/chud_process.c
a27928e1a10256541a97a137e0151f867abf66f3
[apple/xnu.git] / bsd / dev / chud / chud_process.c
1 /*
2 * Copyright (c) 2003 Apple Computer, 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
29 #include <sys/systm.h>
30 #include <sys/proc_internal.h>
31 #include <sys/vnode_internal.h> // vn_getpath()
32 #include <kern/task.h>
33 #include <sys/user.h>
34
35 int chudxnu_pid_for_task(task_t task);
36 task_t chudxnu_task_for_pid(int pid);
37 int chudxnu_current_pid(void);
38
39 __private_extern__ int
40 chudxnu_pid_for_task(task_t task)
41 {
42 struct proc *p;
43
44 if(task!=TASK_NULL) {
45 p = (struct proc *)(get_bsdtask_info(task));
46 if(p) {
47 return (p->p_pid);
48 }
49 }
50 return -1;
51 }
52
53 __private_extern__ task_t
54 chudxnu_task_for_pid(int pid)
55 {
56 struct proc *p = pfind(pid);
57 if(p) {
58 return p->task;
59 }
60 return TASK_NULL;
61 }
62
63 __private_extern__ int
64 chudxnu_current_pid(void)
65 {
66 int pid = -1;
67 struct uthread *ut = get_bsdthread_info(current_thread());
68 task_t t = current_task();
69
70 if(t != TASK_NULL) {
71 pid = chudxnu_pid_for_task(t);
72 } else {
73 // no task, so try looking in the uthread and/or proc
74 pid = current_proc()->p_pid;
75
76 if(ut && ut->uu_proc) {
77 pid = ut->uu_proc->p_pid;
78 }
79 }
80
81 return pid;
82 }