]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/chud/chud_process.c
xnu-792.10.96.tar.gz
[apple/xnu.git] / bsd / dev / chud / chud_process.c
1 /*
2 * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23 #include <sys/systm.h>
24 #include <sys/proc_internal.h>
25 #include <sys/vnode_internal.h> // vn_getpath()
26 #include <kern/task.h>
27 #include <sys/user.h>
28
29 int chudxnu_pid_for_task(task_t task);
30 task_t chudxnu_task_for_pid(int pid);
31 int chudxnu_current_pid(void);
32
33 __private_extern__ int
34 chudxnu_pid_for_task(task_t task)
35 {
36 struct proc *p;
37
38 if(task!=TASK_NULL) {
39 p = (struct proc *)(get_bsdtask_info(task));
40 if(p) {
41 return (p->p_pid);
42 }
43 }
44 return -1;
45 }
46
47 __private_extern__ task_t
48 chudxnu_task_for_pid(int pid)
49 {
50 struct proc *p = pfind(pid);
51 if(p) {
52 return p->task;
53 }
54 return TASK_NULL;
55 }
56
57 __private_extern__ int
58 chudxnu_current_pid(void)
59 {
60 int pid = -1;
61 struct uthread *ut = get_bsdthread_info(current_thread());
62 task_t t = current_task();
63
64 if(t != TASK_NULL) {
65 pid = chudxnu_pid_for_task(t);
66 } else {
67 // no task, so try looking in the uthread and/or proc
68 pid = current_proc()->p_pid;
69
70 if(ut && ut->uu_proc) {
71 pid = ut->uu_proc->p_pid;
72 }
73 }
74
75 return pid;
76 }