Skip to content

Commit b82289f

Browse files
committed
Auto merge of #2313 - devnexen:fbsd_procstat, r=JohnTitor
freebsd add subset of libprocstat
2 parents 200345c + 250965a commit b82289f

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

Diff for: libc-test/build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ fn test_freebsd(target: &str) {
17871787
"sys/procctl.h",
17881788
"sys/procdesc.h",
17891789
"sys/ptrace.h",
1790+
"sys/queue.h",
17901791
"sys/random.h",
17911792
"sys/resource.h",
17921793
"sys/rtprio.h",
@@ -1805,6 +1806,7 @@ fn test_freebsd(target: &str) {
18051806
"sys/user.h",
18061807
"sys/utsname.h",
18071808
"sys/wait.h",
1809+
"libprocstat.h",
18081810
"syslog.h",
18091811
"termios.h",
18101812
"time.h",
@@ -1960,6 +1962,9 @@ fn test_freebsd(target: &str) {
19601962
// `max_align_t` is not available in FreeBSD 10
19611963
"max_align_t" if Some(10) == freebsd_ver => true,
19621964

1965+
// `procstat` is a private struct
1966+
"procstat" => true,
1967+
19631968
_ => false,
19641969
}
19651970
});

Diff for: libc-test/semver/freebsd.txt

+13
Original file line numberDiff line numberDiff line change
@@ -1414,6 +1414,8 @@ fflags_t
14141414
ffs
14151415
ffsl
14161416
ffsll
1417+
filestat
1418+
filestat_list
14171419
fls
14181420
flsl
14191421
flsll
@@ -1479,6 +1481,8 @@ kevent
14791481
key_t
14801482
killpg
14811483
kinfo_getvmmap
1484+
kinfo_proc
1485+
kinfo_vmentry
14821486
kqueue
14831487
kld_isloaded
14841488
kld_load
@@ -1575,6 +1579,15 @@ posix_spawnp
15751579
ppoll
15761580
preadv
15771581
procctl
1582+
procstat
1583+
procstat_close
1584+
procstat_freefiles
1585+
procstat_freeprocs
1586+
procstat_freevmmap
1587+
procstat_getfiles
1588+
procstat_getprocs
1589+
procstat_getvmmap
1590+
procstat_open_sysctl
15781591
pseudo_AF_HDRCMPLT
15791592
pseudo_AF_KEY
15801593
pseudo_AF_PIP

Diff for: src/unix/bsd/freebsdlike/freebsd/mod.rs

+58
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,39 @@ s! {
205205
_kve_is_spare: [::c_int; 12],
206206
pub kve_path: [[::c_char; 32]; 32],
207207
}
208+
209+
pub struct kinfo_proc {
210+
__pad0: [[::uintptr_t; 17]; 8],
211+
}
212+
213+
pub struct filestat {
214+
fs_type: ::c_int,
215+
fs_flags: ::c_int,
216+
fs_fflags: ::c_int,
217+
fs_uflags: ::c_int,
218+
fs_fd: ::c_int,
219+
fs_ref_count: ::c_int,
220+
fs_offset: ::off_t,
221+
fs_typedep: *mut ::c_void,
222+
fs_path: *mut ::c_char,
223+
next: *mut filestat,
224+
fs_cap_rights: cap_rights_t,
225+
}
226+
227+
pub struct filestat_list {
228+
stqh_first: *mut filestat,
229+
stqh_last: *mut *mut filestat,
230+
}
231+
232+
pub struct procstat {
233+
tpe: ::c_int,
234+
kd: ::uintptr_t,
235+
vmentries: *mut ::c_void,
236+
files: *mut ::c_void,
237+
argv: *mut ::c_void,
238+
envv: *mut ::c_void,
239+
core: ::uintptr_t,
240+
}
208241
}
209242

210243
s_no_extra_traits! {
@@ -1804,6 +1837,31 @@ extern "C" {
18041837
pub fn kinfo_getvmmap(pid: ::pid_t, cntp: *mut ::c_int) -> *mut kinfo_vmentry;
18051838
}
18061839

1840+
#[link(name = "procstat")]
1841+
extern "C" {
1842+
pub fn procstat_open_sysctl() -> *mut procstat;
1843+
pub fn procstat_getfiles(
1844+
procstat: *mut procstat,
1845+
kp: *mut kinfo_proc,
1846+
mmapped: ::c_int,
1847+
) -> *mut filestat_list;
1848+
pub fn procstat_freefiles(procstat: *mut procstat, head: *mut filestat_list);
1849+
pub fn procstat_getprocs(
1850+
procstat: *mut procstat,
1851+
what: ::c_int,
1852+
arg: ::c_int,
1853+
count: *mut ::c_uint,
1854+
) -> *mut kinfo_proc;
1855+
pub fn procstat_freeprocs(procstat: *mut procstat, p: *mut kinfo_proc);
1856+
pub fn procstat_getvmmap(
1857+
procstat: *mut procstat,
1858+
kp: *mut kinfo_proc,
1859+
count: *mut ::c_uint,
1860+
) -> *mut kinfo_vmentry;
1861+
pub fn procstat_freevmmap(procstat: *mut procstat, vmmap: *mut kinfo_vmentry);
1862+
pub fn procstat_close(procstat: *mut procstat);
1863+
}
1864+
18071865
cfg_if! {
18081866
if #[cfg(freebsd13)] {
18091867
mod freebsd13;

0 commit comments

Comments
 (0)