diff --git a/src/unix/bsd/freebsdlike/dragonfly/mod.rs b/src/unix/bsd/freebsdlike/dragonfly/mod.rs index 865244265f8a5..141b2ad25d156 100644 --- a/src/unix/bsd/freebsdlike/dragonfly/mod.rs +++ b/src/unix/bsd/freebsdlike/dragonfly/mod.rs @@ -2,6 +2,7 @@ pub type clock_t = u64; pub type ino_t = u64; pub type nlink_t = u32; pub type blksize_t = i64; +pub type clockid_t = ::c_ulong; pub type c_long = i64; pub type c_ulong = u64; @@ -96,23 +97,24 @@ pub const RLIM_NLIMITS: ::rlim_t = 12; pub const Q_GETQUOTA: ::c_int = 0x300; pub const Q_SETQUOTA: ::c_int = 0x400; -pub const CLOCK_REALTIME: ::c_ulong = 0; -pub const CLOCK_VIRTUAL: ::c_ulong = 1; -pub const CLOCK_PROF: ::c_ulong = 2; -pub const CLOCK_MONOTONIC: ::c_ulong = 4; -pub const CLOCK_UPTIME: ::c_ulong = 5; -pub const CLOCK_UPTIME_PRECISE: ::c_ulong = 7; -pub const CLOCK_UPTIME_FAST: ::c_ulong = 8; -pub const CLOCK_REALTIME_PRECISE: ::c_ulong = 9; -pub const CLOCK_REALTIME_FAST: ::c_ulong = 10; -pub const CLOCK_MONOTONIC_PRECISE: ::c_ulong = 11; -pub const CLOCK_MONOTONIC_FAST: ::c_ulong = 12; -pub const CLOCK_SECOND: ::c_ulong = 13; -pub const CLOCK_THREAD_CPUTIME_ID: ::c_ulong = 14; -pub const CLOCK_PROCESS_CPUTIME_ID: ::c_ulong = 15; +pub const CLOCK_REALTIME: clockid_t = 0; +pub const CLOCK_VIRTUAL: clockid_t = 1; +pub const CLOCK_PROF: clockid_t = 2; +pub const CLOCK_MONOTONIC: clockid_t = 4; +pub const CLOCK_UPTIME: clockid_t = 5; +pub const CLOCK_UPTIME_PRECISE: clockid_t = 7; +pub const CLOCK_UPTIME_FAST: clockid_t = 8; +pub const CLOCK_REALTIME_PRECISE: clockid_t = 9; +pub const CLOCK_REALTIME_FAST: clockid_t = 10; +pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11; +pub const CLOCK_MONOTONIC_FAST: clockid_t = 12; +pub const CLOCK_SECOND: clockid_t = 13; +pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14; +pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15; extern { pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; - pub fn clock_gettime(clk_id: ::c_ulong, tp: *mut ::timespec) -> ::c_int; + pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; + pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; } diff --git a/src/unix/bsd/freebsdlike/freebsd/mod.rs b/src/unix/bsd/freebsdlike/freebsd/mod.rs index 5171735343c1f..ae521f28c51aa 100644 --- a/src/unix/bsd/freebsdlike/freebsd/mod.rs +++ b/src/unix/bsd/freebsdlike/freebsd/mod.rs @@ -3,6 +3,7 @@ pub type clock_t = i32; pub type ino_t = u32; pub type nlink_t = u16; pub type blksize_t = u32; +pub type clockid_t = ::c_int; pub type fsblkcnt_t = ::uint64_t; pub type fsfilcnt_t = ::uint64_t; @@ -60,8 +61,20 @@ pub const POSIX_FADV_NOREUSE: ::c_int = 5; pub const MADV_PROTECT: ::c_int = 10; pub const RUSAGE_THREAD: ::c_int = 1; -pub const CLOCK_REALTIME: ::c_int = 0; -pub const CLOCK_MONOTONIC: ::c_int = 4; +pub const CLOCK_REALTIME: clockid_t = 0; +pub const CLOCK_VIRTUAL: clockid_t = 1; +pub const CLOCK_PROF: clockid_t = 2; +pub const CLOCK_MONOTONIC: clockid_t = 4; +pub const CLOCK_UPTIME: clockid_t = 5; +pub const CLOCK_UPTIME_PRECISE: clockid_t = 7; +pub const CLOCK_UPTIME_FAST: clockid_t = 8; +pub const CLOCK_REALTIME_PRECISE: clockid_t = 9; +pub const CLOCK_REALTIME_FAST: clockid_t = 10; +pub const CLOCK_MONOTONIC_PRECISE: clockid_t = 11; +pub const CLOCK_MONOTONIC_FAST: clockid_t = 12; +pub const CLOCK_SECOND: clockid_t = 13; +pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 14; +pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 15; extern { pub fn __error() -> *mut ::c_int; @@ -69,7 +82,8 @@ extern { pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; + pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; + pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int; diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs index ebca1ccc01f3e..c772e2e9c72bc 100644 --- a/src/unix/bsd/openbsdlike/mod.rs +++ b/src/unix/bsd/openbsdlike/mod.rs @@ -8,6 +8,7 @@ pub type pthread_key_t = ::c_int; pub type rlim_t = u64; pub type speed_t = ::c_uint; pub type tcflag_t = ::c_uint; +pub type clockid_t = ::c_int; pub enum timezone {} @@ -258,8 +259,16 @@ pub const _SC_XOPEN_SHM : ::c_int = 30; pub const PTHREAD_CREATE_JOINABLE : ::c_int = 0; pub const PTHREAD_CREATE_DETACHED : ::c_int = 1; -pub const CLOCK_REALTIME : ::c_int = 0; -pub const CLOCK_MONOTONIC : ::c_int = 3; +// http://man.openbsd.org/OpenBSD-current/man2/clock_getres.2 +// The man page says clock_gettime(3) can accept various values as clockid_t but +// http://fxr.watson.org/fxr/source/kern/kern_time.c?v=OPENBSD;im=excerpts#L161 +// the implementation rejects anything other than the below two +// +// http://netbsd.gw.com/cgi-bin/man-cgi?clock_gettime +// https://github.com/jsonn/src/blob/HEAD/sys/kern/subr_time.c#L222 +// Basically the same goes for NetBSD +pub const CLOCK_REALTIME: clockid_t = 0; +pub const CLOCK_MONOTONIC: clockid_t = 3; pub const RLIMIT_CPU: ::c_int = 0; pub const RLIMIT_FSIZE: ::c_int = 1; @@ -380,8 +389,10 @@ pub const RTLD_GLOBAL: ::c_int = 0x100; extern { pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_char) -> ::c_int; + #[cfg_attr(target_os = "netbsd", link_name = "__clock_getres50")] + pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; #[cfg_attr(target_os = "netbsd", link_name = "__clock_gettime50")] - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; + pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; pub fn __errno() -> *mut ::c_int; pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t) -> ::c_int; diff --git a/src/unix/notbsd/linux/musl/mod.rs b/src/unix/notbsd/linux/musl/mod.rs index 1cbfd8f25e57a..cd04d851a5462 100644 --- a/src/unix/notbsd/linux/musl/mod.rs +++ b/src/unix/notbsd/linux/musl/mod.rs @@ -148,6 +148,11 @@ pub const TIOCINQ: ::c_ulong = ::FIONREAD; pub const RTLD_GLOBAL: ::c_int = 0x100; pub const RTLD_NOLOAD: ::c_int = 0x4; +// TODO(#247) Temporarily musl-specific (available since musl 0.9.12 / Linux +// kernel 3.10). See also notbsd/mod.rs +pub const CLOCK_SGI_CYCLE: ::clockid_t = 10; +pub const CLOCK_TAI: ::clockid_t = 11; + extern { pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 4dbad3c33f88f..c2405e3d1b7b6 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -5,6 +5,7 @@ pub type pthread_key_t = ::c_uint; pub type speed_t = ::c_uint; pub type tcflag_t = ::c_uint; pub type loff_t = ::c_longlong; +pub type clockid_t = ::c_int; pub enum timezone {} @@ -203,8 +204,20 @@ pub const SIGTRAP: ::c_int = 5; pub const PTHREAD_CREATE_JOINABLE: ::c_int = 0; pub const PTHREAD_CREATE_DETACHED: ::c_int = 1; -pub const CLOCK_REALTIME: ::c_int = 0; -pub const CLOCK_MONOTONIC: ::c_int = 1; +pub const CLOCK_REALTIME: clockid_t = 0; +pub const CLOCK_MONOTONIC: clockid_t = 1; +pub const CLOCK_PROCESS_CPUTIME_ID: clockid_t = 2; +pub const CLOCK_THREAD_CPUTIME_ID: clockid_t = 3; +pub const CLOCK_MONOTONIC_RAW: clockid_t = 4; +pub const CLOCK_REALTIME_COARSE: clockid_t = 5; +pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6; +pub const CLOCK_BOOTTIME: clockid_t = 7; +pub const CLOCK_REALTIME_ALARM: clockid_t = 8; +pub const CLOCK_BOOTTIME_ALARM: clockid_t = 9; +// TODO(#247) Someday our Travis shall have glibc 2.21 (released in Sep +// 2014.) See also musl/mod.rs +// pub const CLOCK_SGI_CYCLE: clockid_t = 10; +// pub const CLOCK_TAI: clockid_t = 11; pub const RLIMIT_CPU: ::c_int = 0; pub const RLIMIT_FSIZE: ::c_int = 1; @@ -666,7 +679,8 @@ extern { pub fn fdatasync(fd: ::c_int) -> ::c_int; pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_uchar) -> ::c_int; - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; + pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; + pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; pub fn prctl(option: ::c_int, ...) -> ::c_int; pub fn pthread_getattr_np(native: ::pthread_t, attr: *mut ::pthread_attr_t) -> ::c_int; diff --git a/src/unix/solaris/mod.rs b/src/unix/solaris/mod.rs index 4ad520c8ff01e..a47d1baaaab1b 100644 --- a/src/unix/solaris/mod.rs +++ b/src/unix/solaris/mod.rs @@ -1,6 +1,7 @@ pub type c_char = i8; pub type c_long = i64; pub type c_ulong = u64; +pub type clockid_t = ::c_int; pub type blkcnt_t = i64; pub type clock_t = i64; @@ -540,8 +541,18 @@ pub const PTHREAD_STACK_MIN: ::size_t = 4096; pub const SIGSTKSZ: ::size_t = 8192; -pub const CLOCK_REALTIME: ::c_int = 3; -pub const CLOCK_MONOTONIC: ::c_int = 4; +// https://illumos.org/man/3c/clock_gettime +// https://github.com/illumos/illumos-gate/ +// blob/HEAD/usr/src/lib/libc/amd64/sys/__clock_gettime.s +// clock_gettime(3c) doesn't seem to accept anything other than CLOCK_REALTIME +// or __CLOCK_REALTIME0 +// +// https://github.com/illumos/illumos-gate/ +// blob/HEAD/usr/src/uts/common/sys/time_impl.h +// Confusing! CLOCK_HIGHRES==CLOCK_MONOTONIC==4 +// __CLOCK_REALTIME0==0 is an obsoleted version of CLOCK_REALTIME==3 +pub const CLOCK_REALTIME: clockid_t = 3; +pub const CLOCK_MONOTONIC: clockid_t = 4; pub const RLIMIT_CPU: ::c_int = 0; pub const RLIMIT_FSIZE: ::c_int = 1; @@ -752,7 +763,8 @@ extern { pub fn ioctl(fildes: ::c_int, request: ::c_int, ...) -> ::c_int; pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int; - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; + pub fn clock_getres(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; + pub fn clock_gettime(clk_id: clockid_t, tp: *mut ::timespec) -> ::c_int; pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, host: *mut ::c_char,