2 * Copyright (c) 2006 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
24 #include <sys/cdefs.h>
29 #include <sys/errno.h>
30 #include <sys/msgbuf.h>
34 int __proc_info(int callnum
, int pid
, int flavor
, uint64_t arg
, void * buffer
, int buffersize
);
39 proc_listpids(uint32_t type
, uint32_t typeinfo
, void *buffer
, int buffersize
)
43 if ((type
== PROC_ALL_PIDS
) || (type
== PROC_PGRP_ONLY
) || (type
== PROC_TTY_ONLY
) || (type
== PROC_UID_ONLY
) || (type
== PROC_RUID_ONLY
)) {
44 if ((retval
= __proc_info(1, type
, typeinfo
,(uint64_t)0, buffer
, buffersize
)) == -1)
55 proc_pidinfo(int pid
, int flavor
, uint64_t arg
, void *buffer
, int buffersize
)
59 if ((retval
= __proc_info(2, pid
, flavor
, arg
, buffer
, buffersize
)) == -1)
67 proc_pidfdinfo(int pid
, int fd
, int flavor
, void * buffer
, int buffersize
)
71 if ((retval
= __proc_info(3, pid
, flavor
, (uint64_t)fd
, buffer
, buffersize
)) == -1)
80 proc_name(int pid
, void * buffer
, uint32_t buffersize
)
83 struct proc_bsdinfo pbsd
;
86 if (buffersize
< sizeof(pbsd
.pbi_name
)) {
91 retval
= proc_pidinfo(pid
, PROC_PIDTBSDINFO
, (uint64_t)0, &pbsd
, sizeof(struct proc_bsdinfo
));
93 if (pbsd
.pbi_name
[0]) {
94 bcopy(&pbsd
.pbi_name
, buffer
, sizeof(pbsd
.pbi_name
));
96 bcopy(&pbsd
.pbi_comm
, buffer
, sizeof(pbsd
.pbi_comm
));
105 proc_regionfilename(int pid
, uint64_t address
, void * buffer
, uint32_t buffersize
)
108 struct proc_regionwithpathinfo reginfo
;
110 if (buffersize
< MAXPATHLEN
) {
115 retval
= proc_pidinfo(pid
, PROC_PIDREGIONPATHINFO
, (uint64_t)address
, ®info
, sizeof(struct proc_regionwithpathinfo
));
117 len
= strlen(®info
.prp_vip
.vip_path
[0]);
119 if (len
> MAXPATHLEN
)
121 bcopy(®info
.prp_vip
.vip_path
[0], buffer
, len
);
131 proc_kmsgbuf(void * buffer
, uint32_t buffersize
)
135 if ((retval
= __proc_info(4, 0, 0, (uint64_t)0, buffer
, buffersize
)) == -1)
141 proc_pidpath(int pid
, void * buffer
, uint32_t buffersize
)
145 if (buffersize
< PROC_PIDPATHINFO_SIZE
) {
149 if (buffersize
> PROC_PIDPATHINFO_MAXSIZE
) {
154 retval
= __proc_info(2, pid
, PROC_PIDPATHINFO
, (uint64_t)0, buffer
, buffersize
);
156 len
= strlen(buffer
);
164 proc_libversion(int *major
, int * minor
)
175 proc_setpcontrol(const int control
)
179 if (control
< PROC_SETPC_NONE
|| control
> PROC_SETPC_TERMINATE
)
182 if ((retval
= __proc_info(5, getpid(), PROC_SELFSET_PCONTROL
,(uint64_t)control
, NULL
, 0)) == -1)