Skip to content

Commit

Permalink
Auto merge of #2313 - devnexen:fbsd_procstat, r=JohnTitor
Browse files Browse the repository at this point in the history
freebsd add subset of libprocstat
  • Loading branch information
bors committed Aug 19, 2021
2 parents e4d2225 + be8fc00 commit 9247b83
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
5 changes: 5 additions & 0 deletions libc-test/build.rs
Expand Up @@ -1787,6 +1787,7 @@ fn test_freebsd(target: &str) {
"sys/procctl.h",
"sys/procdesc.h",
"sys/ptrace.h",
"sys/queue.h",
"sys/random.h",
"sys/resource.h",
"sys/rtprio.h",
Expand All @@ -1805,6 +1806,7 @@ fn test_freebsd(target: &str) {
"sys/user.h",
"sys/utsname.h",
"sys/wait.h",
"libprocstat.h",
"syslog.h",
"termios.h",
"time.h",
Expand Down Expand Up @@ -1960,6 +1962,9 @@ fn test_freebsd(target: &str) {
// `max_align_t` is not available in FreeBSD 10
"max_align_t" if Some(10) == freebsd_ver => true,

// `procstat` is a private struct
"procstat" => true,

_ => false,
}
});
Expand Down
13 changes: 13 additions & 0 deletions libc-test/semver/freebsd.txt
Expand Up @@ -1414,6 +1414,8 @@ fflags_t
ffs
ffsl
ffsll
filestat
filestat_list
fls
flsl
flsll
Expand Down Expand Up @@ -1479,6 +1481,8 @@ kevent
key_t
killpg
kinfo_getvmmap
kinfo_proc
kinfo_vmentry
kqueue
kld_isloaded
kld_load
Expand Down Expand Up @@ -1575,6 +1579,15 @@ posix_spawnp
ppoll
preadv
procctl
procstat
procstat_close
procstat_freefiles
procstat_freeprocs
procstat_freevmmap
procstat_getfiles
procstat_getprocs
procstat_getvmmap
procstat_open_sysctl
pseudo_AF_HDRCMPLT
pseudo_AF_KEY
pseudo_AF_PIP
Expand Down
58 changes: 58 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Expand Up @@ -205,6 +205,39 @@ s! {
_kve_is_spare: [::c_int; 12],
pub kve_path: [[::c_char; 32]; 32],
}

pub struct kinfo_proc {
__pad0: [::uintptr_t; 136],
}

pub struct filestat {
fs_type: ::c_int,
fs_flags: ::c_int,
fs_fflags: ::c_int,
fs_uflags: ::c_int,
fs_fd: ::c_int,
fs_ref_count: ::c_int,
fs_offset: ::off_t,
fs_typedep: *mut ::c_void,
fs_path: *mut ::c_char,
next: *mut filestat,
fs_cap_rights: cap_rights_t,
}

pub struct filestat_list {
stqh_first: *mut filestat,
stqh_last: *mut *mut filestat,
}

pub struct procstat {
tpe: ::c_int,
kd: ::uintptr_t,
vmentries: *mut ::c_void,
files: *mut ::c_void,
argv: *mut ::c_void,
envv: *mut ::c_void,
core: ::uintptr_t,
}
}

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

#[link(name = "procstat")]
extern "C" {
pub fn procstat_open_sysctl() -> *mut procstat;
pub fn procstat_getfiles(
procstat: *mut procstat,
kp: *mut kinfo_proc,
mmapped: ::c_int,
) -> *mut filestat_list;
pub fn procstat_freefiles(procstat: *mut procstat, head: *mut filestat_list);
pub fn procstat_getprocs(
procstat: *mut procstat,
what: ::c_int,
arg: ::c_int,
count: *mut ::c_uint,
) -> *mut kinfo_proc;
pub fn procstat_freeprocs(procstat: *mut procstat, p: *mut kinfo_proc);
pub fn procstat_getvmmap(
procstat: *mut procstat,
kp: *mut kinfo_proc,
count: *mut ::c_uint,
) -> *mut kinfo_vmentry;
pub fn procstat_freevmmap(procstat: *mut procstat, vmmap: *mut kinfo_vmentry);
pub fn procstat_close(procstat: *mut procstat);
}

cfg_if! {
if #[cfg(freebsd13)] {
mod freebsd13;
Expand Down

0 comments on commit 9247b83

Please sign in to comment.