diff --git a/libc-test/build.rs b/libc-test/build.rs index 26df46f9ab56fcdcdb10aea92104ee598476f55e..56bc6f1f46c4ab0a93557c9958b8a335decde5a4 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -287,6 +287,8 @@ fn main() { cfg.header("sys/ipc.h"); cfg.header("sys/msg.h"); cfg.header("sys/shm.h"); + cfg.header("sys/procdesc.h"); + cfg.header("sys/rtprio.h"); } if netbsd { @@ -310,6 +312,7 @@ fn main() { cfg.header("ufs/ufs/quota.h"); cfg.header("pthread_np.h"); cfg.header("sys/ioctl_compat.h"); + cfg.header("sys/rtprio.h"); } if solaris { @@ -380,9 +383,9 @@ fn main() { } } "u64" if struct_ == "epoll_event" => "data.u64".to_string(), - "type_" if linux && + "type_" if (linux || freebsd || dragonfly) && (struct_ == "input_event" || struct_ == "input_mask" || - struct_ == "ff_effect") => "type".to_string(), + struct_ == "ff_effect" || struct_ == "rtprio") => "type".to_string(), s => s.to_string(), } }); @@ -496,6 +499,10 @@ fn main() { "HW_MAXID" | "USER_MAXID" if freebsd => true, + // These constants were added in FreeBSD 11 + "EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" | + "PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" if freebsd => true, + // These OSX constants are removed in Sierra. // https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html "KERN_KDENABLE_BG_TRACE" if apple => true, diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 620fad44e46ff0fb47df36e9e7afe4aef45f9955..f399f27ccb09b91343fe335e4593251eb653f557 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -1,5 +1,6 @@ pub type clock_t = u64; pub type ino_t = u64; +pub type lwpid_t = i32; pub type nlink_t = u32; pub type blksize_t = i64; pub type clockid_t = ::c_ulong; @@ -737,6 +738,12 @@ pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 127; pub const WCONTINUED: ::c_int = 4; pub const WSTOPPED: ::c_int = 0o177; +// Values for struct rtprio (type_ field) +pub const RTP_PRIO_REALTIME: ::c_ushort = 0; +pub const RTP_PRIO_NORMAL: ::c_ushort = 1; +pub const RTP_PRIO_IDLE: ::c_ushort = 2; +pub const RTP_PRIO_THREAD: ::c_ushort = 3; + extern { pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; @@ -750,4 +757,7 @@ extern { timeout: *mut ::timespec) -> ::c_int; pub fn freelocale(loc: ::locale_t); + + pub fn lwp_rtprio(function: ::c_int, pid: ::pid_t, lwpid: lwpid_t, + rtp: *mut super::rtprio) -> ::c_int; } diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 74f2cf8332660a8e7bc87413eb8e3675f7e29a54..1e5f4f03ee30a1c47ddb43e7b864e0c8b22d108b 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -200,9 +200,12 @@ pub const EVFILT_VNODE: ::int16_t = -4; pub const EVFILT_PROC: ::int16_t = -5; pub const EVFILT_SIGNAL: ::int16_t = -6; pub const EVFILT_TIMER: ::int16_t = -7; +pub const EVFILT_PROCDESC: ::int16_t = -8; pub const EVFILT_FS: ::int16_t = -9; pub const EVFILT_LIO: ::int16_t = -10; pub const EVFILT_USER: ::int16_t = -11; +pub const EVFILT_SENDFILE: ::int16_t = -12; +pub const EVFILT_EMPTY: ::int16_t = -13; pub const EV_ADD: ::uint16_t = 0x1; pub const EV_DELETE: ::uint16_t = 0x2; @@ -838,6 +841,16 @@ pub const _SC_CPUSET_SIZE: ::c_int = 122; pub const XU_NGROUPS: ::c_int = 16; pub const XUCRED_VERSION: ::c_uint = 0; +// Flags which can be passed to pdfork(2) +pub const PD_DAEMON: ::c_int = 0x00000001; +pub const PD_CLOEXEC: ::c_int = 0x00000002; +pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC; + +// Values for struct rtprio (type_ field) +pub const RTP_PRIO_REALTIME: ::c_ushort = 2; +pub const RTP_PRIO_NORMAL: ::c_ushort = 3; +pub const RTP_PRIO_IDLE: ::c_ushort = 4; + extern { pub fn __error() -> *mut ::c_int; @@ -893,6 +906,13 @@ extern { pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char, envp: *const *const ::c_char) -> ::c_int; + + pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t; + pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int; + pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int; + + pub fn rtprio_thread(function: ::c_int, lwpid: ::lwpid_t, + rtp: *mut super::rtprio) -> ::c_int; } cfg_if! { diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 80a66b732180c2aeaad6e6c400bef99edfe43c6b..df32d2c427192b144ead880639861e966811691e 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -170,6 +170,11 @@ s! { pub cmcred_ngroups: ::c_short, pub cmcred_groups: [::gid_t; CMGROUP_MAX], } + + pub struct rtprio { + pub type_: ::c_ushort, + pub prio: ::c_ushort, + } } pub const AIO_LISTIO_MAX: ::c_int = 16; @@ -960,6 +965,12 @@ pub const CMGROUP_MAX: usize = 16; // sizeof(long) pub const BPF_ALIGNMENT: ::c_int = 8; +// Values for rtprio struct (prio field) and syscall (function argument) +pub const RTP_PRIO_MIN: ::c_ushort = 0; +pub const RTP_PRIO_MAX: ::c_ushort = 31; +pub const RTP_LOOKUP: ::c_int = 0; +pub const RTP_SET: ::c_int = 1; + f! { pub fn WIFCONTINUED(status: ::c_int) -> bool { status == 0x13 @@ -1135,6 +1146,7 @@ extern { val: ::c_int) -> ::c_int; pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int; pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int; + pub fn rtprio(function: ::c_int, pid: ::pid_t, rtp: *mut rtprio) -> ::c_int; pub fn fdopendir(fd: ::c_int) -> *mut ::DIR;