| 1 | /* |
| 2 | * Copyright (c) 2005-2021 Apple 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 | #ifndef _SYS_PROC_INFO_H |
| 30 | #define _SYS_PROC_INFO_H |
| 31 | |
| 32 | #include <sys/cdefs.h> |
| 33 | #include <sys/param.h> |
| 34 | #include <sys/types.h> |
| 35 | #include <sys/stat.h> |
| 36 | #include <sys/mount.h> |
| 37 | #include <sys/socket.h> |
| 38 | #include <sys/un.h> |
| 39 | #include <sys/kern_control.h> |
| 40 | #include <sys/event.h> |
| 41 | #include <net/if.h> |
| 42 | #include <net/route.h> |
| 43 | #include <netinet/in.h> |
| 44 | #include <netinet/tcp.h> |
| 45 | #include <mach/machine.h> |
| 46 | #include <uuid/uuid.h> |
| 47 | |
| 48 | __BEGIN_DECLS |
| 49 | |
| 50 | |
| 51 | #define PROC_ALL_PIDS 1 |
| 52 | #define PROC_PGRP_ONLY 2 |
| 53 | #define PROC_TTY_ONLY 3 |
| 54 | #define PROC_UID_ONLY 4 |
| 55 | #define PROC_RUID_ONLY 5 |
| 56 | #define PROC_PPID_ONLY 6 |
| 57 | #define PROC_KDBG_ONLY 7 |
| 58 | |
| 59 | struct proc_bsdinfo { |
| 60 | 	uint32_t pbi_flags; /* 64bit; emulated etc */ |
| 61 | 	uint32_t pbi_status; |
| 62 | 	uint32_t pbi_xstatus; |
| 63 | 	uint32_t pbi_pid; |
| 64 | 	uint32_t pbi_ppid; |
| 65 | 	uid_t pbi_uid; |
| 66 | 	gid_t pbi_gid; |
| 67 | 	uid_t pbi_ruid; |
| 68 | 	gid_t pbi_rgid; |
| 69 | 	uid_t pbi_svuid; |
| 70 | 	gid_t pbi_svgid; |
| 71 | 	uint32_t rfu_1; /* reserved */ |
| 72 | 	char pbi_comm[MAXCOMLEN]; |
| 73 | 	char pbi_name[2 * MAXCOMLEN]; /* empty if no name is registered */ |
| 74 | 	uint32_t pbi_nfiles; |
| 75 | 	uint32_t pbi_pgid; |
| 76 | 	uint32_t pbi_pjobc; |
| 77 | 	uint32_t e_tdev; /* controlling tty dev */ |
| 78 | 	uint32_t e_tpgid; /* tty process group id */ |
| 79 | 	int32_t pbi_nice; |
| 80 | 	uint64_t pbi_start_tvsec; |
| 81 | 	uint64_t pbi_start_tvusec; |
| 82 | }; |
| 83 | |
| 84 | |
| 85 | struct proc_bsdshortinfo { |
| 86 | 	uint32_t pbsi_pid; /* process id */ |
| 87 | 	uint32_t pbsi_ppid; /* process parent id */ |
| 88 | 	uint32_t pbsi_pgid; /* process perp id */ |
| 89 | 	uint32_t pbsi_status; /* p_stat value, SZOMB, SRUN, etc */ |
| 90 | 	char pbsi_comm[MAXCOMLEN]; /* upto 16 characters of process name */ |
| 91 | 	uint32_t pbsi_flags; /* 64bit; emulated etc */ |
| 92 | 	uid_t pbsi_uid; /* current uid on process */ |
| 93 | 	gid_t pbsi_gid; /* current gid on process */ |
| 94 | 	uid_t pbsi_ruid; /* current ruid on process */ |
| 95 | 	gid_t pbsi_rgid; /* current tgid on process */ |
| 96 | 	uid_t pbsi_svuid; /* current svuid on process */ |
| 97 | 	gid_t pbsi_svgid; /* current svgid on process */ |
| 98 | 	uint32_t pbsi_rfu; /* reserved for future use*/ |
| 99 | }; |
| 100 | |
| 101 | |
| 102 | /* pbi_flags values */ |
| 103 | #define PROC_FLAG_SYSTEM 1 /* System process */ |
| 104 | #define PROC_FLAG_TRACED 2 /* process currently being traced, possibly by gdb */ |
| 105 | #define PROC_FLAG_INEXIT 4 /* process is working its way in exit() */ |
| 106 | #define PROC_FLAG_PPWAIT 8 |
| 107 | #define PROC_FLAG_LP64 0x10 /* 64bit process */ |
| 108 | #define PROC_FLAG_SLEADER 0x20 /* The process is the session leader */ |
| 109 | #define PROC_FLAG_CTTY 0x40 /* process has a control tty */ |
| 110 | #define PROC_FLAG_CONTROLT 0x80 /* Has a controlling terminal */ |
| 111 | #define PROC_FLAG_THCWD 0x100 /* process has a thread with cwd */ |
| 112 | /* process control bits for resource starvation */ |
| 113 | #define PROC_FLAG_PC_THROTTLE 0x200 /* In resource starvation situations, this process is to be throttled */ |
| 114 | #define PROC_FLAG_PC_SUSP 0x400 /* In resource starvation situations, this process is to be suspended */ |
| 115 | #define PROC_FLAG_PC_KILL 0x600 /* In resource starvation situations, this process is to be terminated */ |
| 116 | #define PROC_FLAG_PC_MASK 0x600 |
| 117 | /* process action bits for resource starvation */ |
| 118 | #define PROC_FLAG_PA_THROTTLE 0x800 /* The process is currently throttled due to resource starvation */ |
| 119 | #define PROC_FLAG_PA_SUSP 0x1000 /* The process is currently suspended due to resource starvation */ |
| 120 | #define PROC_FLAG_PSUGID 0x2000 /* process has set privileges since last exec */ |
| 121 | #define PROC_FLAG_EXEC 0x4000 /* process has called exec */ |
| 122 | |
| 123 | |
| 124 | struct proc_taskinfo { |
| 125 | 	uint64_t pti_virtual_size; /* virtual memory size (bytes) */ |
| 126 | 	uint64_t pti_resident_size; /* resident memory size (bytes) */ |
| 127 | 	uint64_t pti_total_user; /* total time */ |
| 128 | 	uint64_t pti_total_system; |
| 129 | 	uint64_t pti_threads_user; /* existing threads only */ |
| 130 | 	uint64_t pti_threads_system; |
| 131 | 	int32_t pti_policy; /* default policy for new threads */ |
| 132 | 	int32_t pti_faults; /* number of page faults */ |
| 133 | 	int32_t pti_pageins; /* number of actual pageins */ |
| 134 | 	int32_t pti_cow_faults; /* number of copy-on-write faults */ |
| 135 | 	int32_t pti_messages_sent; /* number of messages sent */ |
| 136 | 	int32_t pti_messages_received; /* number of messages received */ |
| 137 | 	int32_t pti_syscalls_mach; /* number of mach system calls */ |
| 138 | 	int32_t pti_syscalls_unix; /* number of unix system calls */ |
| 139 | 	int32_t pti_csw; /* number of context switches */ |
| 140 | 	int32_t pti_threadnum; /* number of threads in the task */ |
| 141 | 	int32_t pti_numrunning; /* number of running threads */ |
| 142 | 	int32_t pti_priority; /* task priority*/ |
| 143 | }; |
| 144 | |
| 145 | struct proc_taskallinfo { |
| 146 | 	struct proc_bsdinfo pbsd; |
| 147 | 	struct proc_taskinfo ptinfo; |
| 148 | }; |
| 149 | |
| 150 | #define MAXTHREADNAMESIZE 64 |
| 151 | |
| 152 | struct proc_threadinfo { |
| 153 | 	uint64_t pth_user_time; /* user run time */ |
| 154 | 	uint64_t pth_system_time; /* system run time */ |
| 155 | 	int32_t pth_cpu_usage; /* scaled cpu usage percentage */ |
| 156 | 	int32_t pth_policy; /* scheduling policy in effect */ |
| 157 | 	int32_t pth_run_state; /* run state (see below) */ |
| 158 | 	int32_t pth_flags; /* various flags (see below) */ |
| 159 | 	int32_t pth_sleep_time; /* number of seconds that thread */ |
| 160 | 	int32_t pth_curpri; /* cur priority*/ |
| 161 | 	int32_t pth_priority; /* priority*/ |
| 162 | 	int32_t pth_maxpriority; /* max priority*/ |
| 163 | 	char pth_name[MAXTHREADNAMESIZE]; /* thread name, if any */ |
| 164 | }; |
| 165 | |
| 166 | struct proc_regioninfo { |
| 167 | 	uint32_t pri_protection; |
| 168 | 	uint32_t pri_max_protection; |
| 169 | 	uint32_t pri_inheritance; |
| 170 | 	uint32_t pri_flags; /* shared, external pager, is submap */ |
| 171 | 	uint64_t pri_offset; |
| 172 | 	uint32_t pri_behavior; |
| 173 | 	uint32_t pri_user_wired_count; |
| 174 | 	uint32_t pri_user_tag; |
| 175 | 	uint32_t pri_pages_resident; |
| 176 | 	uint32_t pri_pages_shared_now_private; |
| 177 | 	uint32_t pri_pages_swapped_out; |
| 178 | 	uint32_t pri_pages_dirtied; |
| 179 | 	uint32_t pri_ref_count; |
| 180 | 	uint32_t pri_shadow_depth; |
| 181 | 	uint32_t pri_share_mode; |
| 182 | 	uint32_t pri_private_pages_resident; |
| 183 | 	uint32_t pri_shared_pages_resident; |
| 184 | 	uint32_t pri_obj_id; |
| 185 | 	uint32_t pri_depth; |
| 186 | 	uint64_t pri_address; |
| 187 | 	uint64_t pri_size; |
| 188 | }; |
| 189 | |
| 190 | #define PROC_REGION_SUBMAP 1 |
| 191 | #define PROC_REGION_SHARED 2 |
| 192 | |
| 193 | #define SM_COW 1 |
| 194 | #define SM_PRIVATE 2 |
| 195 | #define SM_EMPTY 3 |
| 196 | #define SM_SHARED 4 |
| 197 | #define SM_TRUESHARED 5 |
| 198 | #define SM_PRIVATE_ALIASED 6 |
| 199 | #define SM_SHARED_ALIASED 7 |
| 200 | #define SM_LARGE_PAGE 8 |
| 201 | |
| 202 | |
| 203 | /* |
| 204 | *	Thread run states (state field). |
| 205 | */ |
| 206 | |
| 207 | #define TH_STATE_RUNNING 1 /* thread is running normally */ |
| 208 | #define TH_STATE_STOPPED 2 /* thread is stopped */ |
| 209 | #define TH_STATE_WAITING 3 /* thread is waiting normally */ |
| 210 | #define TH_STATE_UNINTERRUPTIBLE 4 /* thread is in an uninterruptible |
| 211 | 	 * wait */ |
| 212 | #define TH_STATE_HALTED 5 /* thread is halted at a |
| 213 | 	 * clean point */ |
| 214 | |
| 215 | /* |
| 216 | *	Thread flags (flags field). |
| 217 | */ |
| 218 | #define TH_FLAGS_SWAPPED 0x1 /* thread is swapped out */ |
| 219 | #define TH_FLAGS_IDLE 0x2 /* thread is an idle thread */ |
| 220 | |
| 221 | |
| 222 | struct proc_workqueueinfo { |
| 223 | 	uint32_t pwq_nthreads; /* total number of workqueue threads */ |
| 224 | 	uint32_t pwq_runthreads; /* total number of running workqueue threads */ |
| 225 | 	uint32_t pwq_blockedthreads; /* total number of blocked workqueue threads */ |
| 226 | 	uint32_t pwq_state; |
| 227 | }; |
| 228 | |
| 229 | /* |
| 230 | *	workqueue state (pwq_state field) |
| 231 | */ |
| 232 | #define WQ_EXCEEDED_CONSTRAINED_THREAD_LIMIT 0x1 |
| 233 | #define WQ_EXCEEDED_TOTAL_THREAD_LIMIT 0x2 |
| 234 | #define WQ_FLAGS_AVAILABLE 0x4 |
| 235 | /* |
| 236 | * WQ_EXCEEDED_COOPERATIVE_THREAD_LIMIT is set if wq has scheduled cooperative |
| 237 | * threads upto the cooperative thread pool limit and there is still more work |
| 238 | * pending in the cooperative pool that require a thread. |
| 239 | */ |
| 240 | #define WQ_EXCEEDED_COOPERATIVE_THREAD_LIMIT 0x8 |
| 241 | /* |
| 242 | * WQ_EXCEEDED_ACTIVE_CONSTRAINED_THREAD_LIMIT is set when wq has pending thread |
| 243 | * requests for the constrained thread pool; but, has failed the allowance check |
| 244 | * because of active thread limit. |
| 245 | */ |
| 246 | #define WQ_EXCEEDED_ACTIVE_CONSTRAINED_THREAD_LIMIT 0x10 |
| 247 | |
| 248 | struct proc_fileinfo { |
| 249 | 	uint32_t fi_openflags; |
| 250 | 	uint32_t fi_status; |
| 251 | 	off_t fi_offset; |
| 252 | 	int32_t fi_type; |
| 253 | 	uint32_t fi_guardflags; |
| 254 | }; |
| 255 | |
| 256 | /* stats flags in proc_fileinfo */ |
| 257 | #define PROC_FP_SHARED 1 /* shared by more than one fd */ |
| 258 | #define PROC_FP_CLEXEC 2 /* close on exec */ |
| 259 | #define PROC_FP_GUARDED 4 /* guarded fd */ |
| 260 | #define PROC_FP_CLFORK 8 /* close on fork */ |
| 261 | |
| 262 | #define PROC_FI_GUARD_CLOSE (1u << 0) |
| 263 | #define PROC_FI_GUARD_DUP (1u << 1) |
| 264 | #define PROC_FI_GUARD_SOCKET_IPC (1u << 2) |
| 265 | #define PROC_FI_GUARD_FILEPORT (1u << 3) |
| 266 | |
| 267 | struct proc_exitreasonbasicinfo { |
| 268 | 	uint32_t beri_namespace; |
| 269 | 	uint64_t beri_code; |
| 270 | 	uint64_t beri_flags; |
| 271 | 	uint32_t beri_reason_buf_size; |
| 272 | } __attribute__((packed)); |
| 273 | |
| 274 | struct proc_exitreasoninfo { |
| 275 | 	uint32_t eri_namespace; |
| 276 | 	uint64_t eri_code; |
| 277 | 	uint64_t eri_flags; |
| 278 | 	uint32_t eri_reason_buf_size; |
| 279 | 	uint64_t eri_kcd_buf; |
| 280 | } __attribute__((packed)); |
| 281 | |
| 282 | /* |
| 283 | * A copy of stat64 with static sized fields. |
| 284 | */ |
| 285 | struct vinfo_stat { |
| 286 | 	uint32_t vst_dev; /* [XSI] ID of device containing file */ |
| 287 | 	uint16_t vst_mode; /* [XSI] Mode of file (see below) */ |
| 288 | 	uint16_t vst_nlink; /* [XSI] Number of hard links */ |
| 289 | 	uint64_t vst_ino; /* [XSI] File serial number */ |
| 290 | 	uid_t vst_uid; /* [XSI] User ID of the file */ |
| 291 | 	gid_t vst_gid; /* [XSI] Group ID of the file */ |
| 292 | 	int64_t vst_atime; /* [XSI] Time of last access */ |
| 293 | 	int64_t vst_atimensec; /* nsec of last access */ |
| 294 | 	int64_t vst_mtime; /* [XSI] Last data modification time */ |
| 295 | 	int64_t vst_mtimensec; /* last data modification nsec */ |
| 296 | 	int64_t vst_ctime; /* [XSI] Time of last status change */ |
| 297 | 	int64_t vst_ctimensec; /* nsec of last status change */ |
| 298 | 	int64_t vst_birthtime; /* File creation time(birth) */ |
| 299 | 	int64_t vst_birthtimensec; /* nsec of File creation time */ |
| 300 | 	off_t vst_size; /* [XSI] file size, in bytes */ |
| 301 | 	int64_t vst_blocks; /* [XSI] blocks allocated for file */ |
| 302 | 	int32_t vst_blksize; /* [XSI] optimal blocksize for I/O */ |
| 303 | 	uint32_t vst_flags; /* user defined flags for file */ |
| 304 | 	uint32_t vst_gen; /* file generation number */ |
| 305 | 	uint32_t vst_rdev; /* [XSI] Device ID */ |
| 306 | 	int64_t vst_qspare[2]; /* RESERVED: DO NOT USE! */ |
| 307 | }; |
| 308 | |
| 309 | struct vnode_info { |
| 310 | 	struct vinfo_stat vi_stat; |
| 311 | 	int vi_type; |
| 312 | 	int vi_pad; |
| 313 | 	fsid_t vi_fsid; |
| 314 | }; |
| 315 | |
| 316 | struct vnode_info_path { |
| 317 | 	struct vnode_info vip_vi; |
| 318 | 	char vip_path[MAXPATHLEN]; /* tail end of it */ |
| 319 | }; |
| 320 | |
| 321 | struct vnode_fdinfo { |
| 322 | 	struct proc_fileinfo pfi; |
| 323 | 	struct vnode_info pvi; |
| 324 | }; |
| 325 | |
| 326 | struct vnode_fdinfowithpath { |
| 327 | 	struct proc_fileinfo pfi; |
| 328 | 	struct vnode_info_path pvip; |
| 329 | }; |
| 330 | |
| 331 | struct proc_regionwithpathinfo { |
| 332 | 	struct proc_regioninfo prp_prinfo; |
| 333 | 	struct vnode_info_path prp_vip; |
| 334 | }; |
| 335 | |
| 336 | struct proc_regionpath { |
| 337 | 	uint64_t prpo_addr; |
| 338 | 	uint64_t prpo_regionlength; |
| 339 | 	char prpo_path[MAXPATHLEN]; |
| 340 | }; |
| 341 | |
| 342 | struct proc_vnodepathinfo { |
| 343 | 	struct vnode_info_path pvi_cdir; |
| 344 | 	struct vnode_info_path pvi_rdir; |
| 345 | }; |
| 346 | |
| 347 | struct proc_threadwithpathinfo { |
| 348 | 	struct proc_threadinfo pt; |
| 349 | 	struct vnode_info_path pvip; |
| 350 | }; |
| 351 | |
| 352 | struct proc_archinfo { |
| 353 | 	cpu_type_t p_cputype; |
| 354 | 	cpu_subtype_t p_cpusubtype; |
| 355 | }; |
| 356 | |
| 357 | /* |
| 358 | * Socket |
| 359 | */ |
| 360 | |
| 361 | |
| 362 | /* |
| 363 | * IPv4 and IPv6 Sockets |
| 364 | */ |
| 365 | |
| 366 | #define INI_IPV4 0x1 |
| 367 | #define INI_IPV6 0x2 |
| 368 | |
| 369 | struct in4in6_addr { |
| 370 | 	u_int32_t i46a_pad32[3]; |
| 371 | 	struct in_addr i46a_addr4; |
| 372 | }; |
| 373 | |
| 374 | struct in_sockinfo { |
| 375 | 	int insi_fport; /* foreign port */ |
| 376 | 	int insi_lport; /* local port */ |
| 377 | 	uint64_t insi_gencnt; /* generation count of this instance */ |
| 378 | 	uint32_t insi_flags; /* generic IP/datagram flags */ |
| 379 | 	uint32_t insi_flow; |
| 380 | |
| 381 | 	uint8_t insi_vflag; /* ini_IPV4 or ini_IPV6 */ |
| 382 | 	uint8_t insi_ip_ttl; /* time to live proto */ |
| 383 | 	uint32_t rfu_1; /* reserved */ |
| 384 | 	/* protocol dependent part */ |
| 385 | 	union { |
| 386 | 		struct in4in6_addr ina_46; |
| 387 | 		struct in6_addr ina_6; |
| 388 | 	} insi_faddr; /* foreign host table entry */ |
| 389 | 	union { |
| 390 | 		struct in4in6_addr ina_46; |
| 391 | 		struct in6_addr ina_6; |
| 392 | 	} insi_laddr; /* local host table entry */ |
| 393 | 	struct { |
| 394 | 		u_char in4_tos; /* type of service */ |
| 395 | 	} insi_v4; |
| 396 | 	struct { |
| 397 | 		uint8_t in6_hlim; |
| 398 | 		int in6_cksum; |
| 399 | 		u_short in6_ifindex; |
| 400 | 		short in6_hops; |
| 401 | 	} insi_v6; |
| 402 | }; |
| 403 | |
| 404 | /* |
| 405 | * TCP Sockets |
| 406 | */ |
| 407 | |
| 408 | #define TSI_T_REXMT 0 /* retransmit */ |
| 409 | #define TSI_T_PERSIST 1 /* retransmit persistence */ |
| 410 | #define TSI_T_KEEP 2 /* keep alive */ |
| 411 | #define TSI_T_2MSL 3 /* 2*msl quiet time timer */ |
| 412 | #define TSI_T_NTIMERS 4 |
| 413 | |
| 414 | #define TSI_S_CLOSED 0 /* closed */ |
| 415 | #define TSI_S_LISTEN 1 /* listening for connection */ |
| 416 | #define TSI_S_SYN_SENT 2 /* active, have sent syn */ |
| 417 | #define TSI_S_SYN_RECEIVED 3 /* have send and received syn */ |
| 418 | #define TSI_S_ESTABLISHED 4 /* established */ |
| 419 | #define TSI_S__CLOSE_WAIT 5 /* rcvd fin, waiting for close */ |
| 420 | #define TSI_S_FIN_WAIT_1 6 /* have closed, sent fin */ |
| 421 | #define TSI_S_CLOSING 7 /* closed xchd FIN; await FIN ACK */ |
| 422 | #define TSI_S_LAST_ACK 8 /* had fin and close; await FIN ACK */ |
| 423 | #define TSI_S_FIN_WAIT_2 9 /* have closed, fin is acked */ |
| 424 | #define TSI_S_TIME_WAIT 10 /* in 2*msl quiet wait after close */ |
| 425 | #define TSI_S_RESERVED 11 /* pseudo state: reserved */ |
| 426 | |
| 427 | struct tcp_sockinfo { |
| 428 | 	struct in_sockinfo tcpsi_ini; |
| 429 | 	int tcpsi_state; |
| 430 | 	int tcpsi_timer[TSI_T_NTIMERS]; |
| 431 | 	int tcpsi_mss; |
| 432 | 	uint32_t tcpsi_flags; |
| 433 | 	uint32_t rfu_1; /* reserved */ |
| 434 | 	uint64_t tcpsi_tp; /* opaque handle of TCP protocol control block */ |
| 435 | }; |
| 436 | |
| 437 | /* |
| 438 | * Unix Domain Sockets |
| 439 | */ |
| 440 | |
| 441 | |
| 442 | struct un_sockinfo { |
| 443 | 	uint64_t unsi_conn_so; /* opaque handle of connected socket */ |
| 444 | 	uint64_t unsi_conn_pcb; /* opaque handle of connected protocol control block */ |
| 445 | 	union { |
| 446 | 		struct sockaddr_un ua_sun; |
| 447 | 		char ua_dummy[SOCK_MAXADDRLEN]; |
| 448 | 	} unsi_addr; /* bound address */ |
| 449 | 	union { |
| 450 | 		struct sockaddr_un ua_sun; |
| 451 | 		char ua_dummy[SOCK_MAXADDRLEN]; |
| 452 | 	} unsi_caddr; /* address of socket connected to */ |
| 453 | }; |
| 454 | |
| 455 | /* |
| 456 | * PF_NDRV Sockets |
| 457 | */ |
| 458 | |
| 459 | struct ndrv_info { |
| 460 | 	uint32_t ndrvsi_if_family; |
| 461 | 	uint32_t ndrvsi_if_unit; |
| 462 | 	char ndrvsi_if_name[IF_NAMESIZE]; |
| 463 | }; |
| 464 | |
| 465 | /* |
| 466 | * Kernel Event Sockets |
| 467 | */ |
| 468 | |
| 469 | struct kern_event_info { |
| 470 | 	uint32_t kesi_vendor_code_filter; |
| 471 | 	uint32_t kesi_class_filter; |
| 472 | 	uint32_t kesi_subclass_filter; |
| 473 | }; |
| 474 | |
| 475 | /* |
| 476 | * Kernel Control Sockets |
| 477 | */ |
| 478 | |
| 479 | struct kern_ctl_info { |
| 480 | 	uint32_t kcsi_id; |
| 481 | 	uint32_t kcsi_reg_unit; |
| 482 | 	uint32_t kcsi_flags; /* support flags */ |
| 483 | 	uint32_t kcsi_recvbufsize; /* request more than the default buffer size */ |
| 484 | 	uint32_t kcsi_sendbufsize; /* request more than the default buffer size */ |
| 485 | 	uint32_t kcsi_unit; |
| 486 | 	char kcsi_name[MAX_KCTL_NAME]; /* unique nke identifier, provided by DTS */ |
| 487 | }; |
| 488 | |
| 489 | /* |
| 490 | * VSock Sockets |
| 491 | */ |
| 492 | |
| 493 | struct vsock_sockinfo { |
| 494 | 	uint32_t local_cid; |
| 495 | 	uint32_t local_port; |
| 496 | 	uint32_t remote_cid; |
| 497 | 	uint32_t remote_port; |
| 498 | }; |
| 499 | |
| 500 | /* soi_state */ |
| 501 | |
| 502 | #define SOI_S_NOFDREF 0x0001 /* no file table ref any more */ |
| 503 | #define SOI_S_ISCONNECTED 0x0002 /* socket connected to a peer */ |
| 504 | #define SOI_S_ISCONNECTING 0x0004 /* in process of connecting to peer */ |
| 505 | #define SOI_S_ISDISCONNECTING 0x0008 /* in process of disconnecting */ |
| 506 | #define SOI_S_CANTSENDMORE 0x0010 /* can't send more data to peer */ |
| 507 | #define SOI_S_CANTRCVMORE 0x0020 /* can't receive more data from peer */ |
| 508 | #define SOI_S_RCVATMARK 0x0040 /* at mark on input */ |
| 509 | #define SOI_S_PRIV 0x0080 /* privileged for broadcast, raw... */ |
| 510 | #define SOI_S_NBIO 0x0100 /* non-blocking ops */ |
| 511 | #define SOI_S_ASYNC 0x0200 /* async i/o notify */ |
| 512 | #define SOI_S_INCOMP 0x0800 /* Unaccepted, incomplete connection */ |
| 513 | #define SOI_S_COMP 0x1000 /* unaccepted, complete connection */ |
| 514 | #define SOI_S_ISDISCONNECTED 0x2000 /* socket disconnected from peer */ |
| 515 | #define SOI_S_DRAINING 0x4000 /* close waiting for blocked system calls to drain */ |
| 516 | |
| 517 | struct sockbuf_info { |
| 518 | 	uint32_t sbi_cc; |
| 519 | 	uint32_t sbi_hiwat; /* SO_RCVBUF, SO_SNDBUF */ |
| 520 | 	uint32_t sbi_mbcnt; |
| 521 | 	uint32_t sbi_mbmax; |
| 522 | 	uint32_t sbi_lowat; |
| 523 | 	short sbi_flags; |
| 524 | 	short sbi_timeo; |
| 525 | }; |
| 526 | |
| 527 | enum { |
| 528 | 	SOCKINFO_GENERIC = 0, |
| 529 | 	SOCKINFO_IN = 1, |
| 530 | 	SOCKINFO_TCP = 2, |
| 531 | 	SOCKINFO_UN = 3, |
| 532 | 	SOCKINFO_NDRV = 4, |
| 533 | 	SOCKINFO_KERN_EVENT = 5, |
| 534 | 	SOCKINFO_KERN_CTL = 6, |
| 535 | 	SOCKINFO_VSOCK = 7, |
| 536 | }; |
| 537 | |
| 538 | struct socket_info { |
| 539 | 	struct vinfo_stat soi_stat; |
| 540 | 	uint64_t soi_so; /* opaque handle of socket */ |
| 541 | 	uint64_t soi_pcb; /* opaque handle of protocol control block */ |
| 542 | 	int soi_type; |
| 543 | 	int soi_protocol; |
| 544 | 	int soi_family; |
| 545 | 	short soi_options; |
| 546 | 	short soi_linger; |
| 547 | 	short soi_state; |
| 548 | 	short soi_qlen; |
| 549 | 	short soi_incqlen; |
| 550 | 	short soi_qlimit; |
| 551 | 	short soi_timeo; |
| 552 | 	u_short soi_error; |
| 553 | 	uint32_t soi_oobmark; |
| 554 | 	struct sockbuf_info soi_rcv; |
| 555 | 	struct sockbuf_info soi_snd; |
| 556 | 	int soi_kind; |
| 557 | 	uint32_t rfu_1; /* reserved */ |
| 558 | 	union { |
| 559 | 		struct in_sockinfo pri_in; /* SOCKINFO_IN */ |
| 560 | 		struct tcp_sockinfo pri_tcp; /* SOCKINFO_TCP */ |
| 561 | 		struct un_sockinfo pri_un; /* SOCKINFO_UN */ |
| 562 | 		struct ndrv_info pri_ndrv; /* SOCKINFO_NDRV */ |
| 563 | 		struct kern_event_info pri_kern_event; /* SOCKINFO_KERN_EVENT */ |
| 564 | 		struct kern_ctl_info pri_kern_ctl; /* SOCKINFO_KERN_CTL */ |
| 565 | 		struct vsock_sockinfo pri_vsock; /* SOCKINFO_VSOCK */ |
| 566 | 	} soi_proto; |
| 567 | }; |
| 568 | |
| 569 | struct socket_fdinfo { |
| 570 | 	struct proc_fileinfo pfi; |
| 571 | 	struct socket_info psi; |
| 572 | }; |
| 573 | |
| 574 | |
| 575 | |
| 576 | struct psem_info { |
| 577 | 	struct vinfo_stat psem_stat; |
| 578 | 	char psem_name[MAXPATHLEN]; |
| 579 | }; |
| 580 | |
| 581 | struct psem_fdinfo { |
| 582 | 	struct proc_fileinfo pfi; |
| 583 | 	struct psem_info pseminfo; |
| 584 | }; |
| 585 | |
| 586 | |
| 587 | |
| 588 | struct pshm_info { |
| 589 | 	struct vinfo_stat pshm_stat; |
| 590 | 	uint64_t pshm_mappaddr; |
| 591 | 	char pshm_name[MAXPATHLEN]; |
| 592 | }; |
| 593 | |
| 594 | struct pshm_fdinfo { |
| 595 | 	struct proc_fileinfo pfi; |
| 596 | 	struct pshm_info pshminfo; |
| 597 | }; |
| 598 | |
| 599 | |
| 600 | struct pipe_info { |
| 601 | 	struct vinfo_stat pipe_stat; |
| 602 | 	uint64_t pipe_handle; |
| 603 | 	uint64_t pipe_peerhandle; |
| 604 | 	int pipe_status; |
| 605 | 	int rfu_1; /* reserved */ |
| 606 | }; |
| 607 | |
| 608 | struct pipe_fdinfo { |
| 609 | 	struct proc_fileinfo pfi; |
| 610 | 	struct pipe_info pipeinfo; |
| 611 | }; |
| 612 | |
| 613 | |
| 614 | struct kqueue_info { |
| 615 | 	struct vinfo_stat kq_stat; |
| 616 | 	uint32_t kq_state; |
| 617 | 	uint32_t rfu_1; /* reserved */ |
| 618 | }; |
| 619 | |
| 620 | struct kqueue_dyninfo { |
| 621 | 	struct kqueue_info kqdi_info; |
| 622 | 	uint64_t kqdi_servicer; |
| 623 | 	uint64_t kqdi_owner; |
| 624 | 	uint32_t kqdi_sync_waiters; |
| 625 | 	uint8_t kqdi_sync_waiter_qos; |
| 626 | 	uint8_t kqdi_async_qos; |
| 627 | 	uint16_t kqdi_request_state; |
| 628 | 	uint8_t kqdi_events_qos; |
| 629 | 	uint8_t kqdi_pri; |
| 630 | 	uint8_t kqdi_pol; |
| 631 | 	uint8_t kqdi_cpupercent; |
| 632 | 	uint8_t _kqdi_reserved0[4]; |
| 633 | 	uint64_t _kqdi_reserved1[4]; |
| 634 | }; |
| 635 | |
| 636 | /* keep in sync with KQ_* in sys/eventvar.h */ |
| 637 | #define PROC_KQUEUE_SELECT 0x0001 |
| 638 | #define PROC_KQUEUE_SLEEP 0x0002 |
| 639 | #define PROC_KQUEUE_32 0x0008 |
| 640 | #define PROC_KQUEUE_64 0x0010 |
| 641 | #define PROC_KQUEUE_QOS 0x0020 |
| 642 | |
| 643 | struct kqueue_fdinfo { |
| 644 | 	struct proc_fileinfo pfi; |
| 645 | 	struct kqueue_info kqueueinfo; |
| 646 | }; |
| 647 | |
| 648 | struct appletalk_info { |
| 649 | 	struct vinfo_stat atalk_stat; |
| 650 | }; |
| 651 | |
| 652 | struct appletalk_fdinfo { |
| 653 | 	struct proc_fileinfo pfi; |
| 654 | 	struct appletalk_info appletalkinfo; |
| 655 | }; |
| 656 | |
| 657 | typedef uint64_t proc_info_udata_t; |
| 658 | |
| 659 | /* defns of process file desc type */ |
| 660 | #define PROX_FDTYPE_ATALK 0 |
| 661 | #define PROX_FDTYPE_VNODE 1 |
| 662 | #define PROX_FDTYPE_SOCKET 2 |
| 663 | #define PROX_FDTYPE_PSHM 3 |
| 664 | #define PROX_FDTYPE_PSEM 4 |
| 665 | #define PROX_FDTYPE_KQUEUE 5 |
| 666 | #define PROX_FDTYPE_PIPE 6 |
| 667 | #define PROX_FDTYPE_FSEVENTS 7 |
| 668 | #define PROX_FDTYPE_NETPOLICY 9 |
| 669 | #define PROX_FDTYPE_CHANNEL 10 |
| 670 | #define PROX_FDTYPE_NEXUS 11 |
| 671 | |
| 672 | struct proc_fdinfo { |
| 673 | 	int32_t proc_fd; |
| 674 | 	uint32_t proc_fdtype; |
| 675 | }; |
| 676 | |
| 677 | struct proc_fileportinfo { |
| 678 | 	uint32_t proc_fileport; |
| 679 | 	uint32_t proc_fdtype; |
| 680 | }; |
| 681 | |
| 682 | /* |
| 683 | * Channel |
| 684 | */ |
| 685 | |
| 686 | /* type */ |
| 687 | #define PROC_CHANNEL_TYPE_USER_PIPE 0 |
| 688 | #define PROC_CHANNEL_TYPE_KERNEL_PIPE 1 |
| 689 | #define PROC_CHANNEL_TYPE_NET_IF 2 |
| 690 | #define PROC_CHANNEL_TYPE_FLOW_SWITCH 3 |
| 691 | |
| 692 | /* flags */ |
| 693 | #define PROC_CHANNEL_FLAGS_MONITOR_TX 0x1 |
| 694 | #define PROC_CHANNEL_FLAGS_MONITOR_RX 0x2 |
| 695 | #define PROC_CHANNEL_FLAGS_MONITOR_NO_COPY 0x4 |
| 696 | #define PROC_CHANNEL_FLAGS_EXCLUSIVE 0x10 |
| 697 | #define PROC_CHANNEL_FLAGS_USER_PACKET_POOL 0x20 |
| 698 | #define PROC_CHANNEL_FLAGS_DEFUNCT_OK 0x40 |
| 699 | #define PROC_CHANNEL_FLAGS_LOW_LATENCY 0x80 |
| 700 | #define PROC_CHANNEL_FLAGS_MONITOR \ |
| 701 | 	(PROC_CHANNEL_FLAGS_MONITOR_TX | PROC_CHANNEL_FLAGS_MONITOR_RX) |
| 702 | |
| 703 | struct proc_channel_info { |
| 704 | 	uuid_t chi_instance; |
| 705 | 	uint32_t chi_port; |
| 706 | 	uint32_t chi_type; |
| 707 | 	uint32_t chi_flags; |
| 708 | 	uint32_t rfu_1;/* reserved */ |
| 709 | }; |
| 710 | |
| 711 | struct channel_fdinfo { |
| 712 | 	struct proc_fileinfo pfi; |
| 713 | 	struct proc_channel_info channelinfo; |
| 714 | }; |
| 715 | |
| 716 | /* Flavors for proc_pidinfo() */ |
| 717 | #define PROC_PIDLISTFDS 1 |
| 718 | #define PROC_PIDLISTFD_SIZE (sizeof(struct proc_fdinfo)) |
| 719 | |
| 720 | #define PROC_PIDTASKALLINFO 2 |
| 721 | #define PROC_PIDTASKALLINFO_SIZE (sizeof(struct proc_taskallinfo)) |
| 722 | |
| 723 | #define PROC_PIDTBSDINFO 3 |
| 724 | #define PROC_PIDTBSDINFO_SIZE (sizeof(struct proc_bsdinfo)) |
| 725 | |
| 726 | #define PROC_PIDTASKINFO 4 |
| 727 | #define PROC_PIDTASKINFO_SIZE (sizeof(struct proc_taskinfo)) |
| 728 | |
| 729 | #define PROC_PIDTHREADINFO 5 |
| 730 | #define PROC_PIDTHREADINFO_SIZE (sizeof(struct proc_threadinfo)) |
| 731 | |
| 732 | #define PROC_PIDLISTTHREADS 6 |
| 733 | #define PROC_PIDLISTTHREADS_SIZE (2* sizeof(uint32_t)) |
| 734 | |
| 735 | #define PROC_PIDREGIONINFO 7 |
| 736 | #define PROC_PIDREGIONINFO_SIZE (sizeof(struct proc_regioninfo)) |
| 737 | |
| 738 | #define PROC_PIDREGIONPATHINFO 8 |
| 739 | #define PROC_PIDREGIONPATHINFO_SIZE (sizeof(struct proc_regionwithpathinfo)) |
| 740 | |
| 741 | #define PROC_PIDVNODEPATHINFO 9 |
| 742 | #define PROC_PIDVNODEPATHINFO_SIZE (sizeof(struct proc_vnodepathinfo)) |
| 743 | |
| 744 | #define PROC_PIDTHREADPATHINFO 10 |
| 745 | #define PROC_PIDTHREADPATHINFO_SIZE (sizeof(struct proc_threadwithpathinfo)) |
| 746 | |
| 747 | #define PROC_PIDPATHINFO 11 |
| 748 | #define PROC_PIDPATHINFO_SIZE (MAXPATHLEN) |
| 749 | #define PROC_PIDPATHINFO_MAXSIZE (4*MAXPATHLEN) |
| 750 | |
| 751 | #define PROC_PIDWORKQUEUEINFO 12 |
| 752 | #define PROC_PIDWORKQUEUEINFO_SIZE (sizeof(struct proc_workqueueinfo)) |
| 753 | |
| 754 | #define PROC_PIDT_SHORTBSDINFO 13 |
| 755 | #define PROC_PIDT_SHORTBSDINFO_SIZE (sizeof(struct proc_bsdshortinfo)) |
| 756 | |
| 757 | #define PROC_PIDLISTFILEPORTS 14 |
| 758 | #define PROC_PIDLISTFILEPORTS_SIZE (sizeof(struct proc_fileportinfo)) |
| 759 | |
| 760 | #define PROC_PIDTHREADID64INFO 15 |
| 761 | #define PROC_PIDTHREADID64INFO_SIZE (sizeof(struct proc_threadinfo)) |
| 762 | |
| 763 | #define PROC_PID_RUSAGE 16 |
| 764 | #define PROC_PID_RUSAGE_SIZE 0 |
| 765 | |
| 766 | #define PROC_PIDARCHINFO 19 |
| 767 | #define PROC_PIDARCHINFO_SIZE (sizeof(struct proc_archinfo)) |
| 768 | |
| 769 | /* Flavors for proc_pidfdinfo */ |
| 770 | |
| 771 | #define PROC_PIDFDVNODEINFO 1 |
| 772 | #define PROC_PIDFDVNODEINFO_SIZE (sizeof(struct vnode_fdinfo)) |
| 773 | |
| 774 | #define PROC_PIDFDVNODEPATHINFO 2 |
| 775 | #define PROC_PIDFDVNODEPATHINFO_SIZE (sizeof(struct vnode_fdinfowithpath)) |
| 776 | |
| 777 | #define PROC_PIDFDSOCKETINFO 3 |
| 778 | #define PROC_PIDFDSOCKETINFO_SIZE (sizeof(struct socket_fdinfo)) |
| 779 | |
| 780 | #define PROC_PIDFDPSEMINFO 4 |
| 781 | #define PROC_PIDFDPSEMINFO_SIZE (sizeof(struct psem_fdinfo)) |
| 782 | |
| 783 | #define PROC_PIDFDPSHMINFO 5 |
| 784 | #define PROC_PIDFDPSHMINFO_SIZE (sizeof(struct pshm_fdinfo)) |
| 785 | |
| 786 | #define PROC_PIDFDPIPEINFO 6 |
| 787 | #define PROC_PIDFDPIPEINFO_SIZE (sizeof(struct pipe_fdinfo)) |
| 788 | |
| 789 | #define PROC_PIDFDKQUEUEINFO 7 |
| 790 | #define PROC_PIDFDKQUEUEINFO_SIZE (sizeof(struct kqueue_fdinfo)) |
| 791 | |
| 792 | #define PROC_PIDFDATALKINFO 8 |
| 793 | #define PROC_PIDFDATALKINFO_SIZE (sizeof(struct appletalk_fdinfo)) |
| 794 | |
| 795 | |
| 796 | #define PROC_PIDFDCHANNELINFO 10 |
| 797 | #define PROC_PIDFDCHANNELINFO_SIZE (sizeof(struct channel_fdinfo)) |
| 798 | |
| 799 | /* Flavors for proc_pidfileportinfo */ |
| 800 | |
| 801 | #define PROC_PIDFILEPORTVNODEPATHINFO 2 /* out: vnode_fdinfowithpath */ |
| 802 | #define PROC_PIDFILEPORTVNODEPATHINFO_SIZE \ |
| 803 | 	 PROC_PIDFDVNODEPATHINFO_SIZE |
| 804 | |
| 805 | #define PROC_PIDFILEPORTSOCKETINFO 3 /* out: socket_fdinfo */ |
| 806 | #define PROC_PIDFILEPORTSOCKETINFO_SIZE PROC_PIDFDSOCKETINFO_SIZE |
| 807 | |
| 808 | #define PROC_PIDFILEPORTPSHMINFO 5 /* out: pshm_fdinfo */ |
| 809 | #define PROC_PIDFILEPORTPSHMINFO_SIZE PROC_PIDFDPSHMINFO_SIZE |
| 810 | |
| 811 | #define PROC_PIDFILEPORTPIPEINFO 6 /* out: pipe_fdinfo */ |
| 812 | #define PROC_PIDFILEPORTPIPEINFO_SIZE PROC_PIDFDPIPEINFO_SIZE |
| 813 | |
| 814 | /* used for proc_setcontrol */ |
| 815 | #define PROC_SELFSET_PCONTROL 1 |
| 816 | |
| 817 | #define PROC_SELFSET_THREADNAME 2 |
| 818 | #define PROC_SELFSET_THREADNAME_SIZE (MAXTHREADNAMESIZE -1) |
| 819 | |
| 820 | #define PROC_SELFSET_VMRSRCOWNER 3 |
| 821 | |
| 822 | #define PROC_SELFSET_DELAYIDLESLEEP 4 |
| 823 | |
| 824 | /* used for proc_dirtycontrol */ |
| 825 | #define PROC_DIRTYCONTROL_TRACK 1 |
| 826 | #define PROC_DIRTYCONTROL_SET 2 |
| 827 | #define PROC_DIRTYCONTROL_GET 3 |
| 828 | #define PROC_DIRTYCONTROL_CLEAR 4 |
| 829 | |
| 830 | /* proc_track_dirty() flags */ |
| 831 | #define PROC_DIRTY_TRACK 0x1 |
| 832 | #define PROC_DIRTY_ALLOW_IDLE_EXIT 0x2 |
| 833 | #define PROC_DIRTY_DEFER 0x4 |
| 834 | #define PROC_DIRTY_LAUNCH_IN_PROGRESS 0x8 |
| 835 | #define PROC_DIRTY_DEFER_ALWAYS 0x10 |
| 836 | #define PROC_DIRTY_SHUTDOWN_ON_CLEAN 0x20 |
| 837 | |
| 838 | /* proc_get_dirty() flags */ |
| 839 | #define PROC_DIRTY_TRACKED 0x1 |
| 840 | #define PROC_DIRTY_ALLOWS_IDLE_EXIT 0x2 |
| 841 | #define PROC_DIRTY_IS_DIRTY 0x4 |
| 842 | #define PROC_DIRTY_LAUNCH_IS_IN_PROGRESS 0x8 |
| 843 | |
| 844 | /* Flavors for proc_udata_info */ |
| 845 | #define PROC_UDATA_INFO_GET 1 |
| 846 | #define PROC_UDATA_INFO_SET 2 |
| 847 | |
| 848 | __END_DECLS |
| 849 | |
| 850 | |
| 851 | #endif /*_SYS_PROC_INFO_H */ |