Skip to content

Commit 9613051

Browse files
committed
Auto merge of #887 - myfreeweb:freebsd-procdesc, r=alexcrichton
Add missing FreeBSD APIs Process descriptors, realtime process priority, a couple missing kqueue event filters.
2 parents e228797 + c13302d commit 9613051

File tree

4 files changed

+51
-2
lines changed

4 files changed

+51
-2
lines changed

libc-test/build.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,8 @@ fn main() {
287287
cfg.header("sys/ipc.h");
288288
cfg.header("sys/msg.h");
289289
cfg.header("sys/shm.h");
290+
cfg.header("sys/procdesc.h");
291+
cfg.header("sys/rtprio.h");
290292
}
291293

292294
if netbsd {
@@ -310,6 +312,7 @@ fn main() {
310312
cfg.header("ufs/ufs/quota.h");
311313
cfg.header("pthread_np.h");
312314
cfg.header("sys/ioctl_compat.h");
315+
cfg.header("sys/rtprio.h");
313316
}
314317

315318
if solaris {
@@ -380,9 +383,9 @@ fn main() {
380383
}
381384
}
382385
"u64" if struct_ == "epoll_event" => "data.u64".to_string(),
383-
"type_" if linux &&
386+
"type_" if (linux || freebsd || dragonfly) &&
384387
(struct_ == "input_event" || struct_ == "input_mask" ||
385-
struct_ == "ff_effect") => "type".to_string(),
388+
struct_ == "ff_effect" || struct_ == "rtprio") => "type".to_string(),
386389
s => s.to_string(),
387390
}
388391
});
@@ -496,6 +499,10 @@ fn main() {
496499
"HW_MAXID" |
497500
"USER_MAXID" if freebsd => true,
498501

502+
// These constants were added in FreeBSD 11
503+
"EVFILT_PROCDESC" | "EVFILT_SENDFILE" | "EVFILT_EMPTY" |
504+
"PD_CLOEXEC" | "PD_ALLOWED_AT_FORK" if freebsd => true,
505+
499506
// These OSX constants are removed in Sierra.
500507
// https://developer.apple.com/library/content/releasenotes/General/APIDiffsMacOS10_12/Swift/Darwin.html
501508
"KERN_KDENABLE_BG_TRACE" if apple => true,

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub type clock_t = u64;
22
pub type ino_t = u64;
3+
pub type lwpid_t = i32;
34
pub type nlink_t = u32;
45
pub type blksize_t = i64;
56
pub type clockid_t = ::c_ulong;
@@ -737,6 +738,12 @@ pub const _SC_THREAD_ROBUST_PRIO_PROTECT: ::c_int = 127;
737738
pub const WCONTINUED: ::c_int = 4;
738739
pub const WSTOPPED: ::c_int = 0o177;
739740

741+
// Values for struct rtprio (type_ field)
742+
pub const RTP_PRIO_REALTIME: ::c_ushort = 0;
743+
pub const RTP_PRIO_NORMAL: ::c_ushort = 1;
744+
pub const RTP_PRIO_IDLE: ::c_ushort = 2;
745+
pub const RTP_PRIO_THREAD: ::c_ushort = 3;
746+
740747
extern {
741748
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int)
742749
-> ::c_int;
@@ -750,4 +757,7 @@ extern {
750757
timeout: *mut ::timespec) -> ::c_int;
751758

752759
pub fn freelocale(loc: ::locale_t);
760+
761+
pub fn lwp_rtprio(function: ::c_int, pid: ::pid_t, lwpid: lwpid_t,
762+
rtp: *mut super::rtprio) -> ::c_int;
753763
}

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,9 +200,12 @@ pub const EVFILT_VNODE: ::int16_t = -4;
200200
pub const EVFILT_PROC: ::int16_t = -5;
201201
pub const EVFILT_SIGNAL: ::int16_t = -6;
202202
pub const EVFILT_TIMER: ::int16_t = -7;
203+
pub const EVFILT_PROCDESC: ::int16_t = -8;
203204
pub const EVFILT_FS: ::int16_t = -9;
204205
pub const EVFILT_LIO: ::int16_t = -10;
205206
pub const EVFILT_USER: ::int16_t = -11;
207+
pub const EVFILT_SENDFILE: ::int16_t = -12;
208+
pub const EVFILT_EMPTY: ::int16_t = -13;
206209

207210
pub const EV_ADD: ::uint16_t = 0x1;
208211
pub const EV_DELETE: ::uint16_t = 0x2;
@@ -838,6 +841,16 @@ pub const _SC_CPUSET_SIZE: ::c_int = 122;
838841
pub const XU_NGROUPS: ::c_int = 16;
839842
pub const XUCRED_VERSION: ::c_uint = 0;
840843

844+
// Flags which can be passed to pdfork(2)
845+
pub const PD_DAEMON: ::c_int = 0x00000001;
846+
pub const PD_CLOEXEC: ::c_int = 0x00000002;
847+
pub const PD_ALLOWED_AT_FORK: ::c_int = PD_DAEMON | PD_CLOEXEC;
848+
849+
// Values for struct rtprio (type_ field)
850+
pub const RTP_PRIO_REALTIME: ::c_ushort = 2;
851+
pub const RTP_PRIO_NORMAL: ::c_ushort = 3;
852+
pub const RTP_PRIO_IDLE: ::c_ushort = 4;
853+
841854
extern {
842855
pub fn __error() -> *mut ::c_int;
843856

@@ -893,6 +906,13 @@ extern {
893906
pub fn fexecve(fd: ::c_int, argv: *const *const ::c_char,
894907
envp: *const *const ::c_char)
895908
-> ::c_int;
909+
910+
pub fn pdfork(fdp: *mut ::c_int, flags: ::c_int) -> ::pid_t;
911+
pub fn pdgetpid(fd: ::c_int, pidp: *mut ::pid_t) -> ::c_int;
912+
pub fn pdkill(fd: ::c_int, signum: ::c_int) -> ::c_int;
913+
914+
pub fn rtprio_thread(function: ::c_int, lwpid: ::lwpid_t,
915+
rtp: *mut super::rtprio) -> ::c_int;
896916
}
897917

898918
cfg_if! {

src/unix/bsd/freebsdlike/mod.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,11 @@ s! {
170170
pub cmcred_ngroups: ::c_short,
171171
pub cmcred_groups: [::gid_t; CMGROUP_MAX],
172172
}
173+
174+
pub struct rtprio {
175+
pub type_: ::c_ushort,
176+
pub prio: ::c_ushort,
177+
}
173178
}
174179

175180
pub const AIO_LISTIO_MAX: ::c_int = 16;
@@ -960,6 +965,12 @@ pub const CMGROUP_MAX: usize = 16;
960965
// sizeof(long)
961966
pub const BPF_ALIGNMENT: ::c_int = 8;
962967

968+
// Values for rtprio struct (prio field) and syscall (function argument)
969+
pub const RTP_PRIO_MIN: ::c_ushort = 0;
970+
pub const RTP_PRIO_MAX: ::c_ushort = 31;
971+
pub const RTP_LOOKUP: ::c_int = 0;
972+
pub const RTP_SET: ::c_int = 1;
973+
963974
f! {
964975
pub fn WIFCONTINUED(status: ::c_int) -> bool {
965976
status == 0x13
@@ -1135,6 +1146,7 @@ extern {
11351146
val: ::c_int) -> ::c_int;
11361147
pub fn getpriority(which: ::c_int, who: ::c_int) -> ::c_int;
11371148
pub fn setpriority(which: ::c_int, who: ::c_int, prio: ::c_int) -> ::c_int;
1149+
pub fn rtprio(function: ::c_int, pid: ::pid_t, rtp: *mut rtprio) -> ::c_int;
11381150

11391151
pub fn fdopendir(fd: ::c_int) -> *mut ::DIR;
11401152

0 commit comments

Comments
 (0)