Skip to content

Commit 427dc35

Browse files
committed
Auto merge of #2313 - devnexen:fbsd_procstat, r=JohnTitor
freebsd add subset of libprocstat
2 parents 6756263 + 735c993 commit 427dc35

File tree

3 files changed

+76
-0
lines changed

3 files changed

+76
-0
lines changed

libc-test/build.rs

+5
Original file line numberDiff line numberDiff line change
@@ -1778,6 +1778,7 @@ fn test_freebsd(target: &str) {
17781778
"sys/msg.h",
17791779
"sys/procdesc.h",
17801780
"sys/ptrace.h",
1781+
"sys/queue.h",
17811782
"sys/random.h",
17821783
"sys/resource.h",
17831784
"sys/rtprio.h",
@@ -1796,6 +1797,7 @@ fn test_freebsd(target: &str) {
17961797
"sys/user.h",
17971798
"sys/utsname.h",
17981799
"sys/wait.h",
1800+
"libprocstat.h",
17991801
"syslog.h",
18001802
"termios.h",
18011803
"time.h",
@@ -1951,6 +1953,9 @@ fn test_freebsd(target: &str) {
19511953
// `max_align_t` is not available in FreeBSD 10
19521954
"max_align_t" if Some(10) == freebsd_ver => true,
19531955

1956+
// `procstat` is a private struct
1957+
"procstat" => true,
1958+
19541959
_ => false,
19551960
}
19561961
});

libc-test/semver/freebsd.txt

+13
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,8 @@ fflags_t
14011401
ffs
14021402
ffsl
14031403
ffsll
1404+
filestat
1405+
filestat_list
14041406
fls
14051407
flsl
14061408
flsll
@@ -1465,6 +1467,8 @@ kevent
14651467
key_t
14661468
killpg
14671469
kinfo_getvmmap
1470+
kinfo_proc
1471+
kinfo_vmentry
14681472
kqueue
14691473
kld_isloaded
14701474
kld_load
@@ -1560,6 +1564,15 @@ posix_spawnattr_t
15601564
posix_spawnp
15611565
ppoll
15621566
preadv
1567+
procstat
1568+
procstat_close
1569+
procstat_freefiles
1570+
procstat_freeprocs
1571+
procstat_freevmmap
1572+
procstat_getfiles
1573+
procstat_getprocs
1574+
procstat_getvmmap
1575+
procstat_open_sysctl
15631576
pseudo_AF_HDRCMPLT
15641577
pseudo_AF_KEY
15651578
pseudo_AF_PIP

src/unix/bsd/freebsdlike/freebsd/mod.rs

+58
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,39 @@ s! {
216216
_kve_is_spare: [::c_int; 12],
217217
pub kve_path: [[::c_char; 32]; 32],
218218
}
219+
220+
pub struct kinfo_proc {
221+
__pad0: [::uintptr_t; 136],
222+
}
223+
224+
pub struct filestat {
225+
fs_type: ::c_int,
226+
fs_flags: ::c_int,
227+
fs_fflags: ::c_int,
228+
fs_uflags: ::c_int,
229+
fs_fd: ::c_int,
230+
fs_ref_count: ::c_int,
231+
fs_offset: ::off_t,
232+
fs_typedep: *mut ::c_void,
233+
fs_path: *mut ::c_char,
234+
next: *mut filestat,
235+
fs_cap_rights: cap_rights_t,
236+
}
237+
238+
pub struct filestat_list {
239+
stqh_first: *mut filestat,
240+
stqh_last: *mut *mut filestat,
241+
}
242+
243+
pub struct procstat {
244+
tpe: ::c_int,
245+
kd: ::uintptr_t,
246+
vmentries: *mut ::c_void,
247+
files: *mut ::c_void,
248+
argv: *mut ::c_void,
249+
envv: *mut ::c_void,
250+
core: ::uintptr_t,
251+
}
219252
}
220253

221254
s_no_extra_traits! {
@@ -1812,6 +1845,31 @@ extern "C" {
18121845
pub fn kinfo_getvmmap(pid: ::pid_t, cntp: *mut ::c_int) -> *mut kinfo_vmentry;
18131846
}
18141847

1848+
#[link(name = "procstat")]
1849+
extern "C" {
1850+
pub fn procstat_open_sysctl() -> *mut procstat;
1851+
pub fn procstat_getfiles(
1852+
procstat: *mut procstat,
1853+
kp: *mut kinfo_proc,
1854+
mmapped: ::c_int,
1855+
) -> *mut filestat_list;
1856+
pub fn procstat_freefiles(procstat: *mut procstat, head: *mut filestat_list);
1857+
pub fn procstat_getprocs(
1858+
procstat: *mut procstat,
1859+
what: ::c_int,
1860+
arg: ::c_int,
1861+
count: *mut ::c_uint,
1862+
) -> *mut kinfo_proc;
1863+
pub fn procstat_freeprocs(procstat: *mut procstat, p: *mut kinfo_proc);
1864+
pub fn procstat_getvmmap(
1865+
procstat: *mut procstat,
1866+
kp: *mut kinfo_proc,
1867+
count: *mut ::c_uint,
1868+
) -> *mut kinfo_vmentry;
1869+
pub fn procstat_freevmmap(procstat: *mut procstat, vmmap: *mut kinfo_vmentry);
1870+
pub fn procstat_close(procstat: *mut procstat);
1871+
}
1872+
18151873
cfg_if! {
18161874
if #[cfg(freebsd13)] {
18171875
mod freebsd13;

0 commit comments

Comments
 (0)