summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.github/workflows/bors.yml4
-rw-r--r--ci/semver.sh2
-rw-r--r--libc-test/Cargo.toml2
-rw-r--r--libc-test/build.rs26
-rw-r--r--src/unix/bsd/apple/mod.rs19
-rw-r--r--src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs1
-rw-r--r--src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs14
-rw-r--r--src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs23
-rw-r--r--src/unix/bsd/freebsdlike/freebsd/mod.rs485
9 files changed, 558 insertions, 18 deletions
diff --git a/.github/workflows/bors.yml b/.github/workflows/bors.yml
index 25852318e2..3ad1ef6c13 100644
--- a/.github/workflows/bors.yml
+++ b/.github/workflows/bors.yml
@@ -258,7 +258,7 @@ jobs:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
# Should update the semverver revision in semver.sh if we touch nightly ver.
- run: TOOLCHAIN=nightly-2021-07-23 sh ./ci/install-rust.sh
+ run: TOOLCHAIN=nightly-2021-09-30 sh ./ci/install-rust.sh
- name: Check breaking changes
run: sh ci/semver.sh linux
@@ -270,7 +270,7 @@ jobs:
- uses: actions/checkout@v2
- name: Setup Rust toolchain
# Pin nightly version to make semverver compilable.
- run: TOOLCHAIN=nightly-2021-07-23 sh ./ci/install-rust.sh
+ run: TOOLCHAIN=nightly-2021-09-30 sh ./ci/install-rust.sh
- name: Check breaking changes
run: sh ci/semver.sh macos
diff --git a/ci/semver.sh b/ci/semver.sh
index 318e8244ce..bdd68f5986 100644
--- a/ci/semver.sh
+++ b/ci/semver.sh
@@ -16,7 +16,7 @@ fi
rustup component add rustc-dev llvm-tools-preview
# Should update the nightly version in bors CI config if we touch this.
-cargo install semverver --version=0.1.47
+cargo install semverver --version=0.1.48
TARGETS=
case "${OS}" in
diff --git a/libc-test/Cargo.toml b/libc-test/Cargo.toml
index 526e7b5a9a..493f1e8357 100644
--- a/libc-test/Cargo.toml
+++ b/libc-test/Cargo.toml
@@ -18,7 +18,7 @@ default-features = false
[build-dependencies]
cc = "1.0.61"
# FIXME: Use fork ctest until the maintainer gets back.
-ctest2 = "0.4"
+ctest2 = "0.4.2"
[features]
default = [ "std" ]
diff --git a/libc-test/build.rs b/libc-test/build.rs
index e593e494e0..e712646449 100644
--- a/libc-test/build.rs
+++ b/libc-test/build.rs
@@ -1840,6 +1840,7 @@ fn test_freebsd(target: &str) {
"sys/times.h",
"sys/timex.h",
"sys/types.h",
+ "kvm.h", // must be after "sys/types.h"
"sys/ucontext.h",
"sys/uio.h",
"sys/ktrace.h",
@@ -1994,6 +1995,16 @@ fn test_freebsd(target: &str) {
}
});
+ cfg.skip_type(move |ty| {
+ match ty {
+ // the struct "__kvm" is quite tricky to bind so since we only use a pointer to it
+ // for now, it doesn't matter too much...
+ "kvm_t" => true,
+
+ _ => false,
+ }
+ });
+
cfg.skip_struct(move |ty| {
if ty.starts_with("__c_anonymous_") {
return true;
@@ -2087,6 +2098,21 @@ fn test_freebsd(target: &str) {
// a_un field is a union
("Elf32_Auxinfo", "a_un") => true,
("Elf64_Auxinfo", "a_un") => true,
+
+ // FIXME: structs too complicated to bind for now...
+ ("kinfo_proc", "ki_paddr") => true,
+ ("kinfo_proc", "ki_addr") => true,
+ ("kinfo_proc", "ki_tracep") => true,
+ ("kinfo_proc", "ki_textvp") => true,
+ ("kinfo_proc", "ki_fd") => true,
+ ("kinfo_proc", "ki_vmspace") => true,
+ ("kinfo_proc", "ki_pcb") => true,
+ ("kinfo_proc", "ki_tdaddr") => true,
+ ("kinfo_proc", "ki_pd") => true,
+
+ // We ignore this field because we needed to use a hack in order to make rust 1.19
+ // happy...
+ ("kinfo_proc", "ki_sparestrings") => true,
_ => false,
}
});
diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs
index 51319a5b6d..ce82585bfd 100644
--- a/src/unix/bsd/apple/mod.rs
+++ b/src/unix/bsd/apple/mod.rs
@@ -52,7 +52,7 @@ pub type host_flavor_t = integer_t;
pub type host_info64_t = *mut integer_t;
pub type processor_flavor_t = ::c_int;
pub type thread_flavor_t = natural_t;
-pub type thread_inspect_t = mach_port_t;
+pub type thread_inspect_t = ::mach_port_t;
pub type policy_t = ::c_int;
pub type mach_vm_address_t = u64;
pub type mach_vm_offset_t = u64;
@@ -90,7 +90,7 @@ pub type thread_identifier_info_data_t = thread_identifier_info;
pub type thread_extended_info_t = *mut thread_extended_info;
pub type thread_extended_info_data_t = thread_extended_info;
-pub type thread_t = mach_port_t;
+pub type thread_t = ::mach_port_t;
pub type thread_policy_flavor_t = natural_t;
pub type thread_policy_t = *mut integer_t;
pub type thread_latency_qos_t = integer_t;
@@ -120,7 +120,7 @@ pub type vm_statistics_data_t = vm_statistics;
pub type vm_statistics64_t = *mut vm_statistics64;
pub type vm_statistics64_data_t = vm_statistics64;
-pub type task_t = mach_port_t;
+pub type task_t = ::mach_port_t;
pub type sysdir_search_path_enumeration_state = ::c_uint;
@@ -5293,11 +5293,14 @@ extern "C" {
out_processor_infoCnt: *mut mach_msg_type_number_t,
) -> ::kern_return_t;
- pub static mut mach_task_self_: mach_port_t;
- pub fn task_for_pid(host: mach_port_t, pid: ::pid_t, task: *mut mach_port_t)
- -> ::kern_return_t;
+ pub static mut mach_task_self_: ::mach_port_t;
+ pub fn task_for_pid(
+ host: ::mach_port_t,
+ pid: ::pid_t,
+ task: *mut ::mach_port_t,
+ ) -> ::kern_return_t;
pub fn task_info(
- host: mach_port_t,
+ host: ::mach_port_t,
flavor: task_flavor_t,
task_info_out: task_info_t,
task_info_count: *mut mach_msg_type_number_t,
@@ -5322,7 +5325,7 @@ extern "C" {
pub static vm_page_size: vm_size_t;
}
-pub unsafe fn mach_task_self() -> mach_port_t {
+pub unsafe fn mach_task_self() -> ::mach_port_t {
mach_task_self_
}
diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs
index a0b510514f..863de940f4 100644
--- a/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/freebsd11/mod.rs
@@ -191,6 +191,7 @@ cfg_if! {
pub const ELAST: ::c_int = 96;
pub const RAND_MAX: ::c_int = 0x7fff_fffd;
+pub const KI_NSPARE_PTR: usize = 6;
extern "C" {
// Return type ::c_int was removed in FreeBSD 12
diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs
index 05cadd1de9..a58354b3db 100644
--- a/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/freebsd12/mod.rs
@@ -26,6 +26,16 @@ s! {
pub udata: *mut ::c_void,
pub ext: [u64; 4],
}
+
+ pub struct kvm_page {
+ pub version: ::c_uint,
+ pub paddr: ::c_ulong,
+ pub kmap_vaddr: ::c_ulong,
+ pub dmap_vaddr: ::c_ulong,
+ pub prot: ::vm_prot_t,
+ pub offset: ::u_long,
+ pub len: ::size_t,
+ }
}
s_no_extra_traits! {
@@ -212,6 +222,10 @@ pub const SO_DOMAIN: ::c_int = 0x1019;
pub const EINTEGRITY: ::c_int = 97;
pub const ELAST: ::c_int = 97;
+/// max length of devicename
+pub const SPECNAMELEN: ::c_int = 63;
+pub const KI_NSPARE_PTR: usize = 6;
+
extern "C" {
pub fn setgrent();
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
diff --git a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs
index 93ef2a2ad4..944f620fc3 100644
--- a/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/freebsd13/mod.rs
@@ -4,6 +4,8 @@ pub type nlink_t = u64;
pub type dev_t = u64;
pub type ino_t = ::c_ulong;
pub type shmatt_t = ::c_uint;
+pub type kpaddr_t = u64;
+pub type kssize_t = i64;
s! {
pub struct shmid_ds {
@@ -37,6 +39,16 @@ s! {
pub sc_ngroups: ::c_int,
pub sc_groups: [::gid_t; 1],
}
+
+ pub struct kvm_page {
+ pub kp_version: ::u_int,
+ pub kp_paddr: ::kpaddr_t,
+ pub kp_kmap_vaddr: ::kvaddr_t,
+ pub kp_dmap_vaddr: ::kvaddr_t,
+ pub kp_prot: ::vm_prot_t,
+ pub kp_offset: ::off_t,
+ pub kp_len: ::size_t,
+ }
}
s_no_extra_traits! {
@@ -228,6 +240,12 @@ pub const PROC_PROCCTL_MD_MIN: ::c_int = 0x10000000;
pub const LOCAL_CREDS_PERSISTENT: ::c_int = 3;
pub const SCM_CREDS2: ::c_int = 0x08;
+pub const KF_TYPE_EVENTFD: ::c_int = 13;
+
+/// max length of devicename
+pub const SPECNAMELEN: ::c_int = 255;
+pub const KI_NSPARE_PTR: usize = 5;
+
f! {
pub fn SOCKCRED2SIZE(ngrps: usize) -> usize {
let ngrps = if ngrps > 0 {
@@ -269,6 +287,11 @@ extern "C" {
pub fn timingsafe_memcmp(a: *const ::c_void, b: *const ::c_void, len: ::size_t) -> ::c_int;
}
+#[link(name = "kvm")]
+extern "C" {
+ pub fn kvm_kerndisp(kd: *mut ::kvm_t) -> ::kssize_t;
+}
+
cfg_if! {
if #[cfg(any(target_arch = "x86_64",
target_arch = "aarch64"))] {
diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs
index 92d8dac922..99f272aad6 100644
--- a/src/unix/bsd/freebsdlike/freebsd/mod.rs
+++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs
@@ -1,7 +1,13 @@
pub type fflags_t = u32;
pub type clock_t = i32;
-pub type lwpid_t = i32;
+pub type vm_prot_t = u_char;
+pub type kvaddr_t = u64;
+pub type segsz_t = isize;
+pub type __fixpt_t = u32;
+pub type fixpt_t = __fixpt_t;
+pub type __lwpid_t = i32;
+pub type lwpid_t = __lwpid_t;
pub type blksize_t = i32;
pub type clockid_t = ::c_int;
pub type sem_t = _sem;
@@ -26,6 +32,14 @@ pub type pthread_barrierattr_t = *mut __c_anonymous_pthread_barrierattr;
pub type pthread_barrier_t = *mut __c_anonymous_pthread_barrier;
pub type uuid_t = ::uuid;
+pub type u_int = ::c_uint;
+pub type u_char = ::c_uchar;
+pub type u_long = ::c_ulong;
+pub type u_short = ::c_ushort;
+
+// It's an alias over "struct __kvm_t". However, its fields aren't supposed to be used directly,
+// making the type definition system dependent. Better not bind it exactly.
+pub type kvm_t = ::c_void;
s! {
pub struct aiocb {
@@ -218,10 +232,6 @@ s! {
pub kve_path: [[::c_char; 32]; 32],
}
- pub struct kinfo_proc {
- __pad0: [[::uintptr_t; 17]; 8],
- }
-
pub struct filestat {
fs_type: ::c_int,
fs_flags: ::c_int,
@@ -259,6 +269,164 @@ s! {
pub struct __c_anonymous__timer {
_priv: [::c_int; 3],
}
+
+ /// Used to hold a copy of the command line, if it had a sane length.
+ pub struct pargs {
+ /// Reference count.
+ pub ar_ref: u_int,
+ /// Length.
+ pub ar_length: u_int,
+ /// Arguments.
+ pub ar_args: [::c_uchar; 1],
+ }
+
+ pub struct priority {
+ /// Scheduling class.
+ pub pri_class: u_char,
+ /// Normal priority level.
+ pub pri_level: u_char,
+ /// Priority before propagation.
+ pub pri_native: u_char,
+ /// User priority based on p_cpu and p_nice.
+ pub pri_user: u_char,
+ }
+
+ pub struct kinfo_proc {
+ pub ki_structsize: ::c_int,
+ pub ki_layout: ::c_int,
+ pub ki_args: *mut pargs,
+ // This is normally "struct proc".
+ pub ki_paddr: *mut ::c_void,
+ // This is normally "struct user".
+ pub ki_addr: *mut ::c_void,
+ // This is normally "struct vnode".
+ pub ki_tracep: *mut ::c_void,
+ // This is normally "struct vnode".
+ pub ki_textvp: *mut ::c_void,
+ // This is normally "struct filedesc".
+ pub ki_fd: *mut ::c_void,
+ // This is normally "struct vmspace".
+ pub ki_vmspace: *mut ::c_void,
+ #[cfg(freebsd13)]
+ pub ki_wchan: *const ::c_void,
+ #[cfg(not(freebsd13))]
+ pub ki_wchan: *mut ::c_void,
+ pub ki_pid: ::pid_t,
+ pub ki_ppid: ::pid_t,
+ pub ki_pgid: ::pid_t,
+ pub ki_tpgid: ::pid_t,
+ pub ki_sid: ::pid_t,
+ pub ki_tsid: ::pid_t,
+ pub ki_jobc: ::c_short,
+ pub ki_spare_short1: ::c_short,
+ #[cfg(any(freebsd12, freebsd13))]
+ pub ki_tdev_freebsd11: u32,
+ #[cfg(freebsd11)]
+ pub ki_tdev: ::dev_t,
+ pub ki_siglist: ::sigset_t,
+ pub ki_sigmask: ::sigset_t,
+ pub ki_sigignore: ::sigset_t,
+ pub ki_sigcatch: ::sigset_t,
+ pub ki_uid: ::uid_t,
+ pub ki_ruid: ::uid_t,
+ pub ki_svuid: ::uid_t,
+ pub ki_rgid: ::gid_t,
+ pub ki_svgid: ::gid_t,
+ pub ki_ngroups: ::c_short,
+ pub ki_spare_short2: ::c_short,
+ pub ki_groups: [::gid_t; ::KI_NGROUPS],
+ pub ki_size: ::vm_size_t,
+ pub ki_rssize: segsz_t,
+ pub ki_swrss: segsz_t,
+ pub ki_tsize: segsz_t,
+ pub ki_dsize: segsz_t,
+ pub ki_ssize: segsz_t,
+ pub ki_xstat: ::u_short,
+ pub ki_acflag: ::u_short,
+ pub ki_pctcpu: fixpt_t,
+ pub ki_estcpu: u_int,
+ pub ki_slptime: u_int,
+ pub ki_swtime: u_int,
+ pub ki_cow: u_int,
+ pub ki_runtime: u64,
+ pub ki_start: ::timeval,
+ pub ki_childtime: ::timeval,
+ pub ki_flag: ::c_long,
+ pub ki_kiflag: ::c_long,
+ pub ki_traceflag: ::c_int,
+ pub ki_stat: ::c_char,
+ pub ki_nice: i8, // signed char
+ pub ki_lock: ::c_char,
+ pub ki_rqindex: ::c_char,
+ pub ki_oncpu_old: ::c_uchar,
+ pub ki_lastcpu_old: ::c_uchar,
+ pub ki_tdname: [::c_char; TDNAMLEN + 1],
+ pub ki_wmesg: [::c_char; ::WMESGLEN + 1],
+ pub ki_login: [::c_char; ::LOGNAMELEN + 1],
+ pub ki_lockname: [::c_char; ::LOCKNAMELEN + 1],
+ pub ki_comm: [::c_char; ::COMMLEN + 1],
+ pub ki_emul: [::c_char; ::KI_EMULNAMELEN + 1],
+ pub ki_loginclass: [::c_char; ::LOGINCLASSLEN + 1],
+ pub ki_moretdname: [::c_char; ::MAXCOMLEN - ::TDNAMLEN + 1],
+ pub ki_sparestrings: [[::c_char; 23]; 2], // little hack to allow PartialEq
+ pub ki_spareints: [::c_int; ::KI_NSPARE_INT],
+ #[cfg(freebsd13)]
+ pub ki_tdev: u64,
+ #[cfg(freebsd12)]
+ pub ki_tdev: ::dev_t,
+ pub ki_oncpu: ::c_int,
+ pub ki_lastcpu: ::c_int,
+ pub ki_tracer: ::c_int,
+ pub ki_flag2: ::c_int,
+ pub ki_fibnum: ::c_int,
+ pub ki_cr_flags: u_int,
+ pub ki_jid: ::c_int,
+ pub ki_numthreads: ::c_int,
+ pub ki_tid: lwpid_t,
+ pub ki_pri: priority,
+ pub ki_rusage: ::rusage,
+ pub ki_rusage_ch: ::rusage,
+ // This is normally "struct pcb".
+ pub ki_pcb: *mut ::c_void,
+ pub ki_kstack: *mut ::c_void,
+ pub ki_udata: *mut ::c_void,
+ // This is normally "struct thread".
+ pub ki_tdaddr: *mut ::c_void,
+ // This is normally "struct pwddesc".
+ #[cfg(freebsd13)]
+ pub ki_pd: *mut ::c_void,
+ pub ki_spareptrs: [*mut ::c_void; ::KI_NSPARE_PTR],
+ pub ki_sparelongs: [::c_long; ::KI_NSPARE_LONG],
+ pub ki_sflag: ::c_long,
+ pub ki_tdflags: ::c_long,
+ }
+
+ pub struct kvm_swap {
+ pub ksw_devname: [::c_char; 32],
+ pub ksw_used: u_int,
+ pub ksw_total: u_int,
+ pub ksw_flags: ::c_int,
+ pub ksw_reserved1: u_int,
+ pub ksw_reserved2: u_int,
+ }
+
+ pub struct nlist {
+ /// symbol name (in memory)
+ pub n_name: *const ::c_char,
+ /// type defines
+ pub n_type: ::c_uchar,
+ /// "type" and binding information
+ pub n_other: ::c_char,
+ /// used by stab entries
+ pub n_desc: ::c_short,
+ pub n_value: ::c_ulong,
+ }
+
+ pub struct kvm_nlist {
+ pub n_name: *const ::c_char,
+ pub n_type: ::c_uchar,
+ pub n_value: ::kvaddr_t,
+ }
}
s_no_extra_traits! {
@@ -718,7 +886,6 @@ pub const NOTE_USECONDS: u32 = 0x00000004;
pub const NOTE_NSECONDS: u32 = 0x00000008;
pub const MADV_PROTECT: ::c_int = 10;
-pub const RUSAGE_THREAD: ::c_int = 1;
#[doc(hidden)]
#[deprecated(
@@ -1465,6 +1632,241 @@ pub const RFSPAWN: ::c_int = 2147483648;
pub const MALLOCX_ZERO: ::c_int = 0x40;
+/// size of returned wchan message
+pub const WMESGLEN: usize = 8;
+/// size of returned lock name
+pub const LOCKNAMELEN: usize = 8;
+/// size of returned thread name
+pub const TDNAMLEN: usize = 16;
+/// size of returned ki_comm name
+pub const COMMLEN: usize = 19;
+/// size of returned ki_emul
+pub const KI_EMULNAMELEN: usize = 16;
+/// number of groups in ki_groups
+pub const KI_NGROUPS: usize = 16;
+cfg_if! {
+ if #[cfg(freebsd11)] {
+ pub const KI_NSPARE_INT: usize = 4;
+ } else {
+ pub const KI_NSPARE_INT: usize = 2;
+ }
+}
+pub const KI_NSPARE_LONG: usize = 12;
+/// Flags for the process credential.
+pub const KI_CRF_CAPABILITY_MODE: usize = 0x00000001;
+/// Steal a bit from ki_cr_flags to indicate that the cred had more than
+/// KI_NGROUPS groups.
+pub const KI_CRF_GRP_OVERFLOW: usize = 0x80000000;
+/// controlling tty vnode active
+pub const KI_CTTY: usize = 0x00000001;
+/// session leader
+pub const KI_SLEADER: usize = 0x00000002;
+/// proc blocked on lock ki_lockname
+pub const KI_LOCKBLOCK: usize = 0x00000004;
+/// size of returned ki_login
+pub const LOGNAMELEN: usize = 17;
+/// size of returned ki_loginclass
+pub const LOGINCLASSLEN: usize = 17;
+
+pub const KF_ATTR_VALID: ::c_int = 0x0001;
+pub const KF_TYPE_NONE: ::c_int = 0;
+pub const KF_TYPE_VNODE: ::c_int = 1;
+pub const KF_TYPE_SOCKET: ::c_int = 2;
+pub const KF_TYPE_PIPE: ::c_int = 3;
+pub const KF_TYPE_FIFO: ::c_int = 4;
+pub const KF_TYPE_KQUEUE: ::c_int = 5;
+pub const KF_TYPE_MQUEUE: ::c_int = 7;
+pub const KF_TYPE_SHM: ::c_int = 8;
+pub const KF_TYPE_SEM: ::c_int = 9;
+pub const KF_TYPE_PTS: ::c_int = 10;
+pub const KF_TYPE_PROCDESC: ::c_int = 11;
+pub const KF_TYPE_DEV: ::c_int = 12;
+pub const KF_TYPE_UNKNOWN: ::c_int = 255;
+
+pub const KF_VTYPE_VNON: ::c_int = 0;
+pub const KF_VTYPE_VREG: ::c_int = 1;
+pub const KF_VTYPE_VDIR: ::c_int = 2;
+pub const KF_VTYPE_VBLK: ::c_int = 3;
+pub const KF_VTYPE_VCHR: ::c_int = 4;
+pub const KF_VTYPE_VLNK: ::c_int = 5;
+pub const KF_VTYPE_VSOCK: ::c_int = 6;
+pub const KF_VTYPE_VFIFO: ::c_int = 7;
+pub const KF_VTYPE_VBAD: ::c_int = 8;
+pub const KF_VTYPE_UNKNOWN: ::c_int = 255;
+
+/// Current working directory
+pub const KF_FD_TYPE_CWD: ::c_int = -1;
+/// Root directory
+pub const KF_FD_TYPE_ROOT: ::c_int = -2;
+/// Jail directory
+pub const KF_FD_TYPE_JAIL: ::c_int = -3;
+/// Ktrace vnode
+pub const KF_FD_TYPE_TRACE: ::c_int = -4;
+pub const KF_FD_TYPE_TEXT: ::c_int = -5;
+/// Controlling terminal
+pub const KF_FD_TYPE_CTTY: ::c_int = -6;
+pub const KF_FLAG_READ: ::c_int = 0x00000001;
+pub const KF_FLAG_WRITE: ::c_int = 0x00000002;
+pub const KF_FLAG_APPEND: ::c_int = 0x00000004;
+pub const KF_FLAG_ASYNC: ::c_int = 0x00000008;
+pub const KF_FLAG_FSYNC: ::c_int = 0x00000010;
+pub const KF_FLAG_NONBLOCK: ::c_int = 0x00000020;
+pub const KF_FLAG_DIRECT: ::c_int = 0x00000040;
+pub const KF_FLAG_HASLOCK: ::c_int = 0x00000080;
+pub const KF_FLAG_SHLOCK: ::c_int = 0x00000100;
+pub const KF_FLAG_EXLOCK: ::c_int = 0x00000200;
+pub const KF_FLAG_NOFOLLOW: ::c_int = 0x00000400;
+pub const KF_FLAG_CREAT: ::c_int = 0x00000800;
+pub const KF_FLAG_TRUNC: ::c_int = 0x00001000;
+pub const KF_FLAG_EXCL: ::c_int = 0x00002000;
+pub const KF_FLAG_EXEC: ::c_int = 0x00004000;
+
+pub const KVME_TYPE_NONE: ::c_int = 0;
+pub const KVME_TYPE_DEFAULT: ::c_int = 1;
+pub const KVME_TYPE_VNODE: ::c_int = 2;
+pub const KVME_TYPE_SWAP: ::c_int = 3;
+pub const KVME_TYPE_DEVICE: ::c_int = 4;
+pub const KVME_TYPE_PHYS: ::c_int = 5;
+pub const KVME_TYPE_DEAD: ::c_int = 6;
+pub const KVME_TYPE_SG: ::c_int = 7;
+pub const KVME_TYPE_MGTDEVICE: ::c_int = 8;
+// Present in `sys/user.h` but is undefined for whatever reason...
+// pub const KVME_TYPE_GUARD: ::c_int = 9;
+pub const KVME_TYPE_UNKNOWN: ::c_int = 255;
+pub const KVME_PROT_READ: ::c_int = 0x00000001;
+pub const KVME_PROT_WRITE: ::c_int = 0x00000002;
+pub const KVME_PROT_EXEC: ::c_int = 0x00000004;
+pub const KVME_FLAG_COW: ::c_int = 0x00000001;
+pub const KVME_FLAG_NEEDS_COPY: ::c_int = 0x00000002;
+pub const KVME_FLAG_NOCOREDUMP: ::c_int = 0x00000004;
+pub const KVME_FLAG_SUPER: ::c_int = 0x00000008;
+pub const KVME_FLAG_GROWS_UP: ::c_int = 0x00000010;
+pub const KVME_FLAG_GROWS_DOWN: ::c_int = 0x00000020;
+cfg_if! {
+ if #[cfg(any(freebsd12, freebsd13))] {
+ pub const KVME_FLAG_USER_WIRED: ::c_int = 0x00000040;
+ }
+}
+
+pub const KKST_MAXLEN: ::c_int = 1024;
+/// Stack is valid.
+pub const KKST_STATE_STACKOK: ::c_int = 0;
+/// Stack swapped out.
+pub const KKST_STATE_SWAPPED: ::c_int = 1;
+pub const KKST_STATE_RUNNING: ::c_int = 2;
+
+// Constants about priority.
+pub const PRI_MIN: ::c_int = 0;
+pub const PRI_MAX: ::c_int = 255;
+pub const PRI_MIN_ITHD: ::c_int = PRI_MIN;
+pub const PRI_MAX_ITHD: ::c_int = PRI_MIN_REALTIME - 1;
+pub const PI_REALTIME: ::c_int = PRI_MIN_ITHD + 0;
+pub const PI_AV: ::c_int = PRI_MIN_ITHD + 4;
+pub const PI_NET: ::c_int = PRI_MIN_ITHD + 8;
+pub const PI_DISK: ::c_int = PRI_MIN_ITHD + 12;
+pub const PI_TTY: ::c_int = PRI_MIN_ITHD + 16;
+pub const PI_DULL: ::c_int = PRI_MIN_ITHD + 20;
+pub const PI_SOFT: ::c_int = PRI_MIN_ITHD + 24;
+pub const PRI_MIN_REALTIME: ::c_int = 48;
+pub const PRI_MAX_REALTIME: ::c_int = PRI_MIN_KERN - 1;
+pub const PRI_MIN_KERN: ::c_int = 80;
+pub const PRI_MAX_KERN: ::c_int = PRI_MIN_TIMESHARE - 1;
+pub const PSWP: ::c_int = PRI_MIN_KERN + 0;
+pub const PVM: ::c_int = PRI_MIN_KERN + 4;
+pub const PINOD: ::c_int = PRI_MIN_KERN + 8;
+pub const PRIBIO: ::c_int = PRI_MIN_KERN + 12;
+pub const PVFS: ::c_int = PRI_MIN_KERN + 16;
+pub const PZERO: ::c_int = PRI_MIN_KERN + 20;
+pub const PSOCK: ::c_int = PRI_MIN_KERN + 24;
+pub const PWAIT: ::c_int = PRI_MIN_KERN + 28;
+pub const PLOCK: ::c_int = PRI_MIN_KERN + 32;
+pub const PPAUSE: ::c_int = PRI_MIN_KERN + 36;
+pub const PRI_MIN_TIMESHARE: ::c_int = 120;
+pub const PRI_MAX_TIMESHARE: ::c_int = PRI_MIN_IDLE - 1;
+pub const PUSER: ::c_int = PRI_MIN_TIMESHARE;
+pub const PRI_MIN_IDLE: ::c_int = 224;
+pub const PRI_MAX_IDLE: ::c_int = PRI_MAX;
+
+// Resource utilization information.
+pub const RUSAGE_THREAD: ::c_int = 1;
+
+cfg_if! {
+ if #[cfg(any(freebsd11, target_pointer_width = "32"))] {
+ pub const ARG_MAX: ::c_int = 256 * 1024;
+ } else {
+ pub const ARG_MAX: ::c_int = 2 * 256 * 1024;
+ }
+}
+pub const CHILD_MAX: ::c_int = 40;
+/// max command name remembered
+pub const MAXCOMLEN: usize = 19;
+/// max interpreter file name length
+pub const MAXINTERP: ::c_int = ::PATH_MAX;
+/// max login name length (incl. NUL)
+pub const MAXLOGNAME: ::c_int = 33;
+/// max simultaneous processes
+pub const MAXUPRC: ::c_int = CHILD_MAX;
+/// max bytes for an exec function
+pub const NCARGS: ::c_int = ARG_MAX;
+/// /* max number groups
+pub const NGROUPS: ::c_int = NGROUPS_MAX + 1;
+/// max open files per process
+pub const NOFILE: ::c_int = OPEN_MAX;
+/// marker for empty group set member
+pub const NOGROUP: ::c_int = 65535;
+/// max hostname size
+pub const MAXHOSTNAMELEN: ::c_int = 256;
+/// max bytes in term canon input line
+pub const MAX_CANON: ::c_int = 255;
+/// max bytes in terminal input
+pub const MAX_INPUT: ::c_int = 255;
+/// max bytes in a file name
+pub const NAME_MAX: ::c_int = 255;
+pub const MAXSYMLINKS: ::c_int = 32;
+/// max supplemental group id's
+pub const NGROUPS_MAX: ::c_int = 1023;
+/// max open files per process
+pub const OPEN_MAX: ::c_int = 64;
+
+pub const _POSIX_ARG_MAX: ::c_int = 4096;
+pub const _POSIX_LINK_MAX: ::c_int = 8;
+pub const _POSIX_MAX_CANON: ::c_int = 255;
+pub const _POSIX_MAX_INPUT: ::c_int = 255;
+pub const _POSIX_NAME_MAX: ::c_int = 14;
+pub const _POSIX_PIPE_BUF: ::c_int = 512;
+pub const _POSIX_SSIZE_MAX: ::c_int = 32767;
+pub const _POSIX_STREAM_MAX: ::c_int = 8;
+
+/// max ibase/obase values in bc(1)
+pub const BC_BASE_MAX: ::c_int = 99;
+/// max array elements in bc(1)
+pub const BC_DIM_MAX: ::c_int = 2048;
+/// max scale value in bc(1)
+pub const BC_SCALE_MAX: ::c_int = 99;
+/// max const string length in bc(1)
+pub const BC_STRING_MAX: ::c_int = 1000;
+/// max character class name size
+pub const CHARCLASS_NAME_MAX: ::c_int = 14;
+/// max weights for order keyword
+pub const COLL_WEIGHTS_MAX: ::c_int = 10;
+/// max expressions nested in expr(1)
+pub const EXPR_NEST_MAX: ::c_int = 32;
+/// max bytes in an input line
+pub const LINE_MAX: ::c_int = 2048;
+/// max RE's in interval notation
+pub const RE_DUP_MAX: ::c_int = 255;
+
+pub const _POSIX2_BC_BASE_MAX: ::c_int = 99;
+pub const _POSIX2_BC_DIM_MAX: ::c_int = 2048;
+pub const _POSIX2_BC_SCALE_MAX: ::c_int = 99;
+pub const _POSIX2_BC_STRING_MAX: ::c_int = 1000;
+pub const _POSIX2_CHARCLASS_NAME_MAX: ::c_int = 14;
+pub const _POSIX2_COLL_WEIGHTS_MAX: ::c_int = 2;
+pub const _POSIX2_EQUIV_CLASS_MAX: ::c_int = 2;
+pub const _POSIX2_EXPR_NEST_MAX: ::c_int = 32;
+pub const _POSIX2_LINE_MAX: ::c_int = 2048;
+pub const _POSIX2_RE_DUP_MAX: ::c_int = 255;
+
const_fn! {
{const} fn _ALIGN(p: usize) -> usize {
(p + _ALIGNBYTES) & !_ALIGNBYTES
@@ -1930,6 +2332,77 @@ extern "C" {
pub fn nallocx(size: ::size_t, flags: ::c_int) -> ::size_t;
pub fn procctl(idtype: ::idtype_t, id: ::id_t, cmd: ::c_int, data: *mut ::c_void) -> ::c_int;
+
+ pub fn getpagesize() -> ::c_int;
+}
+
+#[link(name = "kvm")]
+extern "C" {
+ pub fn kvm_open(
+ execfile: *const ::c_char,
+ corefile: *const ::c_char,
+ swapfile: *const ::c_char,
+ flags: ::c_int,
+ errstr: *const ::c_char,
+ ) -> *mut kvm_t;
+ pub fn kvm_close(kd: *mut kvm_t) -> ::c_int;
+ pub fn kvm_dpcpu_setcpu(kd: *mut kvm_t, cpu: ::c_uint) -> ::c_int;
+ pub fn kvm_getargv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
+ pub fn kvm_getcptime(kd: *mut kvm_t, cp_time: *mut ::c_long) -> ::c_int;
+ pub fn kvm_getenvv(kd: *mut kvm_t, p: *const kinfo_proc, nchr: ::c_int) -> *mut *mut ::c_char;
+ pub fn kvm_geterr(kd: *mut kvm_t) -> *mut ::c_char;
+ pub fn kvm_getloadavg(kd: *mut kvm_t, loadavg: *mut ::c_double, nelem: ::c_int) -> ::c_int;
+ pub fn kvm_getmaxcpu(kd: *mut kvm_t) -> ::c_int;
+ pub fn kvm_getncpus(kd: *mut kvm_t) -> ::c_int;
+ pub fn kvm_getpcpu(kd: *mut kvm_t, cpu: ::c_int) -> *mut ::c_void;
+ pub fn kvm_counter_u64_fetch(kd: *mut kvm_t, base: ::c_ulong) -> u64;
+ pub fn kvm_getprocs(
+ kd: *mut kvm_t,
+ op: ::c_int,
+ arg: ::c_int,
+ cnt: *mut ::c_int,
+ ) -> *mut kinfo_proc;
+ pub fn kvm_getswapinfo(
+ kd: *mut kvm_t,
+ info: *mut kvm_swap,
+ maxswap: ::c_int,
+ flags: ::c_int,
+ ) -> ::c_int;
+ pub fn kvm_native(kd: *mut kvm_t) -> ::c_int;
+ pub fn kvm_nlist(kd: *mut kvm_t, nl: *mut nlist) -> ::c_int;
+ pub fn kvm_nlist2(kd: *mut kvm_t, nl: *mut kvm_nlist) -> ::c_int;
+ pub fn kvm_openfiles(
+ execfile: *const ::c_char,
+ corefile: *const ::c_char,
+ swapfile: *const ::c_char,
+ flags: ::c_int,
+ errbuf: *mut ::c_char,
+ ) -> *mut kvm_t;
+ pub fn kvm_read(
+ kd: *mut kvm_t,
+ addr: ::c_ulong,
+ buf: *mut ::c_void,
+ nbytes: ::size_t,
+ ) -> ::ssize_t;
+ pub fn kvm_read_zpcpu(
+ kd: *mut kvm_t,
+ base: ::c_ulong,
+ buf: *mut ::c_void,
+ size: ::size_t,
+ cpu: ::c_int,
+ ) -> ::ssize_t;
+ pub fn kvm_read2(
+ kd: *mut kvm_t,
+ addr: kvaddr_t,
+ buf: *mut ::c_void,
+ nbytes: ::size_t,
+ ) -> ::ssize_t;
+ pub fn kvm_write(
+ kd: *mut kvm_t,
+ addr: ::c_ulong,
+ buf: *const ::c_void,
+ nbytes: ::size_t,
+ ) -> ::ssize_t;
}
#[link(name = "util")]