darwin_libproc_sys/
pidinfo.rs

1//! Flavors for proc_pidinfo()
2//!
3//! See `bsd/sys/proc_info.h` for originals
4
5use std::mem;
6
7#[repr(C)]
8#[derive(Copy, Clone, Debug)]
9pub struct proc_bsdinfo {
10    /// 64bit; emulated etc
11    pub pbi_flags: u32,
12    pub pbi_status: u32,
13    pub pbi_xstatus: u32,
14    pub pbi_pid: u32,
15    pub pbi_ppid: u32,
16    pub pbi_uid: libc::uid_t,
17    pub pbi_gid: libc::gid_t,
18    pub pbi_ruid: libc::uid_t,
19    pub pbi_rgid: libc::gid_t,
20    pub pbi_svuid: libc::uid_t,
21    pub pbi_svgid: libc::gid_t,
22    /// reserved
23    pub rfu_1: u32,
24    pub pbi_comm: [libc::c_char; libc::MAXCOMLEN],
25    /// Empty if no name is registered
26    pub pbi_name: [libc::c_char; 2 * libc::MAXCOMLEN],
27    pub pbi_nfiles: u32,
28    pub pbi_pgid: u32,
29    pub pbi_pjobc: u32,
30    /// Controlling tty dev
31    pub e_tdev: u32,
32    /// tty process group id
33    pub e_tpgid: u32,
34    pub pbi_nice: i32,
35    pub pbi_start_tvsec: u64,
36    pub pbi_start_tvusec: u64,
37}
38
39//struct proc_bsdshortinfo {
40//        uint32_t                pbsi_pid;		/* process id */
41//        uint32_t                pbsi_ppid;		/* process parent id */
42//        uint32_t                pbsi_pgid;		/* process perp id */
43//	uint32_t                pbsi_status;		/* p_stat value, SZOMB, SRUN, etc */
44//	char                    pbsi_comm[MAXCOMLEN];	/* upto 16 characters of process name */
45//	uint32_t                pbsi_flags;              /* 64bit; emulated etc */
46//        uid_t                   pbsi_uid;		/* current uid on process */
47//        gid_t                   pbsi_gid;		/* current gid on process */
48//        uid_t                   pbsi_ruid;		/* current ruid on process */
49//        gid_t                   pbsi_rgid;		/* current tgid on process */
50//        uid_t                   pbsi_svuid;		/* current svuid on process */
51//        gid_t                   pbsi_svgid;		/* current svgid on process */
52//        uint32_t                pbsi_rfu;		/* reserved for future use*/
53//};
54
55#[repr(C)]
56#[derive(Copy, Clone, Debug)]
57pub struct proc_taskinfo {
58    /// virtual memory size (bytes)
59    pub pti_virtual_size: u64,
60    /// resident memory size (bytes)
61    pub pti_resident_size: u64,
62    /// total time
63    pub pti_total_user: u64,
64    pub pti_total_system: u64,
65    /// existing threads only
66    pub pti_threads_user: u64,
67    pub pti_threads_system: u64,
68    /// default policy for new threads
69    pub pti_policy: i32,
70    /// number of page faults
71    pub pti_faults: i32,
72    /// number of actual pageins
73    pub pti_pageins: i32,
74    /// number of copy-on-write faults
75    pub pti_cow_faults: i32,
76    /// number of messages sent
77    pub pti_messages_sent: i32,
78    /// number of messages received
79    pub pti_messages_received: i32,
80    /// number of mach system calls
81    pub pti_syscalls_mach: i32,
82    /// number of unix system calls
83    pub pti_syscalls_unix: i32,
84    /// number of context switches
85    pub pti_csw: i32,
86    /// number of threads in the task
87    pub pti_threadnum: i32,
88    /// number of running threads
89    pub pti_numrunning: i32,
90    /// task priority
91    pub pti_priority: i32,
92}
93
94#[repr(C)]
95#[derive(Copy, Clone, Debug)]
96pub struct proc_taskallinfo {
97    pub pbsd: proc_bsdinfo,
98    pub ptinfo: proc_taskinfo,
99}
100
101#[repr(C)]
102#[derive(Copy, Clone, Debug)]
103pub struct proc_fdinfo {
104    pub proc_fd: i32,
105    pub proc_fdtype: u32,
106}
107
108#[repr(C)]
109#[derive(Copy, Clone)]
110pub struct vinfo_stat {
111    /// \[XSI\] ID of device containing file
112    pub vst_dev: u32,
113    /// \[XSI\] Mode of file
114    pub vst_mode: u16,
115    /// \[XSI\] Number of hard links
116    pub vst_nlink: u16,
117    /// \[XSI\] File serial number
118    pub vst_ino: u64,
119    /// \[XSI\] User ID of the file
120    pub vst_uid: libc::uid_t,
121    /// \[XSI\] Group ID of the file
122    pub vst_gid: libc::gid_t,
123    /// \[XSI\] Time of last access
124    pub vst_atime: i64,
125    /// nsec of last access
126    pub vst_atimensec: i64,
127    /// \[XSI\] Last data modification time
128    pub vst_mtime: i64,
129    /// last data modification nsec
130    pub vst_mtimensec: i64,
131    /// \[XSI\] Time of last status change
132    pub vst_ctime: i64,
133    /// nsec of last status change
134    pub vst_ctimensec: i64,
135    /// File creation time(birth)
136    pub vst_birthtime: i64,
137    /// nsec of File creation time
138    pub vst_birthtimensec: i64,
139    /// \[XSI\] file size, in bytes
140    pub vst_size: libc::off_t,
141    /// \[XSI\] blocks allocated for file
142    pub vst_blocks: i64,
143    /// \[XSI\] optimal blocksize for I/O
144    pub vst_blksize: i32,
145    /// user defined flags for file
146    pub vst_flags: u32,
147    /// file generation number
148    pub vst_gen: u32,
149    /// \[XSI\] Device ID
150    pub vst_rdev: u32,
151    /// RESERVED: DO NOT USE!
152    pub vst_qspare: [i64; 2],
153}
154
155#[repr(C)]
156#[derive(Copy, Clone)]
157pub struct vnode_info {
158    pub vi_stat: vinfo_stat,
159    pub vi_type: libc::c_int,
160    pub vi_fsid: libc::fsid_t,
161    pub vi_pad: libc::c_int,
162}
163
164#[repr(C)]
165#[derive(Copy, Clone)]
166pub struct vnode_info_path {
167    pub vip_vi: vnode_info,
168    pub vip_path: [libc::c_char; crate::MAXPATHLEN],
169}
170
171#[repr(C)]
172#[derive(Copy, Clone)]
173pub struct proc_vnodepathinfo {
174    pub pvi_cdir: vnode_info_path,
175    pub pvi_rdir: vnode_info_path,
176}
177
178// Flavors for proc_pidinfo()
179
180pub const PROC_PIDLISTFDS: libc::c_int = 1;
181pub const PROC_PIDLISTFD_SIZE: libc::c_int =
182    mem::size_of::<proc_fdinfo>() as libc::c_int; // Should be 8
183
184pub const PROC_PIDTASKALLINFO: libc::c_int = 2;
185pub const PROC_PIDTASKALLINFO_SIZE: libc::c_int =
186    mem::size_of::<proc_taskallinfo>() as libc::c_int; // Should be 232
187
188pub const PROC_PIDTBSDINFO: libc::c_int = 3;
189pub const PROC_PIDTBSDINFO_SIZE: libc::c_int =
190    mem::size_of::<proc_bsdinfo>() as libc::c_int; // Should be 136
191
192pub const PROC_PIDTASKINFO: libc::c_int = 4;
193pub const PROC_PIDTASKINFO_SIZE: libc::c_int =
194    mem::size_of::<proc_taskinfo>() as libc::c_int; // Should be 96
195
196//#define PROC_PIDTHREADINFO 5
197//#define PROC_PIDTHREADINFO_SIZE  (sizeof(struct proc_threadinfo))
198//
199
200pub const PROC_PIDLISTTHREADS: libc::c_int = 6;
201pub const PROC_PIDLISTTHREADS_SIZE: libc::c_int =
202    2 * mem::size_of::<u32>() as libc::c_int;
203
204//#define PROC_PIDREGIONINFO 7
205//#define PROC_PIDREGIONINFO_SIZE  (sizeof(struct proc_regioninfo))
206//
207//#define PROC_PIDREGIONPATHINFO 8
208//#define PROC_PIDREGIONPATHINFO_SIZE  (sizeof(struct proc_regionwithpathinfo))
209
210pub const PROC_PIDVNODEPATHINFO: libc::c_int = 9;
211pub const PROC_PIDVNODEPATHINFO_SIZE: libc::c_int =
212    mem::size_of::<proc_vnodepathinfo>() as libc::c_int;
213
214//
215//#define PROC_PIDTHREADPATHINFO 10
216//#define PROC_PIDTHREADPATHINFO_SIZE  (sizeof(struct proc_threadwithpathinfo))
217//
218//#define PROC_PIDPATHINFO 11
219//#define PROC_PIDPATHINFO_SIZE  (MAXPATHLEN)
220//#define PROC_PIDPATHINFO_MAXSIZE  (4*MAXPATHLEN)
221
222extern "C" {
223    pub fn proc_pidinfo(
224        pid: libc::c_int,
225        flavor: libc::c_int,
226        arg: u64,
227        buffer: *mut libc::c_void,
228        buffersize: libc::c_int,
229    ) -> libc::c_int;
230}
231
232#[cfg(test)]
233mod tests {
234    use super::*;
235    use std::mem;
236
237    #[test]
238    fn test_size() {
239        assert_eq!(mem::size_of::<proc_fdinfo>(), 8);
240        assert_eq!(PROC_PIDLISTFD_SIZE, 8);
241
242        assert_eq!(mem::size_of::<proc_taskallinfo>(), 232);
243        assert_eq!(PROC_PIDTASKALLINFO_SIZE, 232);
244
245        assert_eq!(mem::size_of::<proc_bsdinfo>(), 136);
246        assert_eq!(PROC_PIDTBSDINFO_SIZE, 136);
247    }
248}