From bb6f198a201af6a078067d170642cbe77069393d Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 18 Jan 2016 11:18:22 -0800 Subject: Fix all definitions on FreeBSD * The `flock` structure has an extra field * Some `flock`-related constants have different value * Some constants like `TABN` don't exist * The `fsblkcnt_t` and `fsfilcnt_t` type definitions are u64 for x86_64 FreeBSD * The `d_namelen` field in `dirent` was renamed correctly to `d_namlen` * The alignment of `fd_set` was off, and the macros were updated to not always assume a 32-bit integer is used. --- libc-test/build.rs | 11 +++++++-- src/unix/bsd/apple/mod.rs | 27 ++++++++++++++++++++++ src/unix/bsd/freebsdlike/dragonfly.rs | 5 +++++ src/unix/bsd/freebsdlike/freebsd.rs | 3 +++ src/unix/bsd/freebsdlike/mod.rs | 23 ++++++++++++++----- src/unix/bsd/mod.rs | 42 +++++++++++------------------------ src/unix/bsd/openbsdlike/mod.rs | 14 ++++++++++++ 7 files changed, 88 insertions(+), 37 deletions(-) diff --git a/libc-test/build.rs b/libc-test/build.rs index 1982a723e4..d703e336e3 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -101,10 +101,11 @@ fn main() { } else if !windows { cfg.header("glob.h"); cfg.header("ifaddrs.h"); - if !openbsd { + cfg.header("sys/statvfs.h"); + + if !openbsd && !freebsd { cfg.header("sys/quota.h"); } - cfg.header("sys/statvfs.h"); if !musl { cfg.header("sys/sysctl.h"); @@ -159,6 +160,7 @@ fn main() { if freebsd { cfg.header("pthread_np.h"); cfg.header("sched.h"); + cfg.header("ufs/ufs/quota.h"); } if netbsd { @@ -364,6 +366,11 @@ fn main() { // [3]: https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/unix/sysv/linux/sys/eventfd.h;h=6295f32e937e779e74318eb9d3bdbe76aef8a8f3;hb=4e42b5b8f89f0e288e68be7ad70f9525aebc2cff#l34 "eventfd" if linux => true, + // The `uname` funcion in freebsd is now an inline wrapper that + // delegates to another, but the symbol still exists, so don't check + // the symbol. + "uname" if freebsd => true, + _ => false, } }); diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 406acd1011..e8f97e4ede 100644 --- a/src/unix/bsd/apple/mod.rs +++ b/src/unix/bsd/apple/mod.rs @@ -242,6 +242,14 @@ s! { pub c_ispeed: ::speed_t, pub c_ospeed: ::speed_t, } + + pub struct flock { + pub l_start: ::off_t, + pub l_len: ::off_t, + pub l_pid: ::pid_t, + pub l_type: ::c_short, + pub l_whence: ::c_short, + } } pub const EXIT_FAILURE: ::c_int = 1; @@ -305,6 +313,9 @@ pub const F_LOCK: ::c_int = 1; pub const F_TEST: ::c_int = 3; pub const F_TLOCK: ::c_int = 2; pub const F_ULOCK: ::c_int = 0; +pub const F_GETLK: ::c_int = 7; +pub const F_SETLK: ::c_int = 8; +pub const F_SETLKW: ::c_int = 9; pub const SIGHUP: ::c_int = 1; pub const SIGINT: ::c_int = 2; pub const SIGQUIT: ::c_int = 3; @@ -803,6 +814,19 @@ pub const NOTE_VM_PRESSURE_SUDDEN_TERMINATE: ::uint32_t = 0x20000000; pub const NOTE_VM_PRESSURE_TERMINATE: ::uint32_t = 0x40000000; pub const NOTE_PCTRLMASK: ::uint32_t = 0xfff00000; +pub const NL0: ::c_int = 0x00000000; +pub const NL1: ::c_int = 0x00000100; +pub const TAB0: ::c_int = 0x00000000; +pub const TAB1: ::c_int = 0x00000400; +pub const TAB2: ::c_int = 0x00000800; +pub const CR0: ::c_int = 0x00000000; +pub const CR1: ::c_int = 0x00001000; +pub const CR2: ::c_int = 0x00002000; +pub const CR3: ::c_int = 0x00003000; +pub const FF0: ::c_int = 0x00000000; +pub const FF1: ::c_int = 0x00004000; +pub const BS0: ::c_int = 0x00000000; +pub const BS1: ::c_int = 0x00008000; pub const TAB3: ::c_int = 0x00000004; pub const VT0: ::c_int = 0x00000000; pub const VT1: ::c_int = 0x00010000; @@ -811,6 +835,9 @@ pub const CRTSCTS: ::tcflag_t = 0x00030000; pub const NI_MAXHOST: ::socklen_t = 1025; +pub const Q_GETQUOTA: ::c_int = 0x300; +pub const Q_SETQUOTA: ::c_int = 0x400; + extern { pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, diff --git a/src/unix/bsd/freebsdlike/dragonfly.rs b/src/unix/bsd/freebsdlike/dragonfly.rs index 6b874f0b1f..0cdc128f49 100644 --- a/src/unix/bsd/freebsdlike/dragonfly.rs +++ b/src/unix/bsd/freebsdlike/dragonfly.rs @@ -1,8 +1,13 @@ +pub type fsblkcnt_t = ::c_uint; +pub type fsfilcnt_t = ::c_uint; + pub const PTHREAD_STACK_MIN: ::size_t = 1024; pub const KERN_PROC_PATHNAME: ::c_int = 9; pub const SIGSTKSZ: ::size_t = 40960; pub const MADV_INVAL: ::c_int = 10; +pub const HW_AVAILCPU: ::c_int = 25; + extern { pub fn __dfly_error() -> *const ::c_int; } diff --git a/src/unix/bsd/freebsdlike/freebsd.rs b/src/unix/bsd/freebsdlike/freebsd.rs index 9e6d985f9d..ab2d6fc6e1 100644 --- a/src/unix/bsd/freebsdlike/freebsd.rs +++ b/src/unix/bsd/freebsdlike/freebsd.rs @@ -1,3 +1,6 @@ +pub type fsblkcnt_t = ::uint64_t; +pub type fsfilcnt_t = ::uint64_t; + pub const PTHREAD_STACK_MIN: ::size_t = 2048; pub const KERN_PROC_PATHNAME: ::c_int = 12; pub const SIGSTKSZ: ::size_t = 34816; diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index d41829ceb2..d7c99ee61f 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -12,8 +12,6 @@ pub type pthread_mutexattr_t = *mut ::c_void; pub type pthread_cond_t = *mut ::c_void; pub type pthread_rwlock_t = *mut ::c_void; pub type pthread_key_t = ::c_int; -pub type fsblkcnt_t = ::c_uint; -pub type fsfilcnt_t = ::c_uint; pub type tcflag_t = ::c_uint; pub type speed_t = ::c_uint; @@ -24,7 +22,7 @@ s! { pub d_fileno: u32, pub d_reclen: u16, pub d_type: u8, - pub d_namelen: u8, + pub d_namlen: u8, pub d_name: [::c_char; 256], } @@ -85,7 +83,7 @@ s! { } pub struct stack_t { - pub ss_sp: *mut ::c_void, + pub ss_sp: *mut ::c_char, pub ss_size: ::size_t, pub ss_flags: ::c_int, } @@ -132,6 +130,15 @@ s! { pub c_ispeed: ::speed_t, pub c_ospeed: ::speed_t, } + + pub struct flock { + pub l_start: ::off_t, + pub l_len: ::off_t, + pub l_pid: ::pid_t, + pub l_type: ::c_short, + pub l_whence: ::c_short, + pub l_sysid: ::c_int, + } } pub const EXIT_FAILURE: ::c_int = 1; @@ -194,6 +201,9 @@ pub const F_TEST: ::c_int = 3; pub const F_TLOCK: ::c_int = 2; pub const F_ULOCK: ::c_int = 0; pub const F_DUPFD_CLOEXEC: ::c_int = 17; +pub const F_GETLK: ::c_int = 11; +pub const F_SETLK: ::c_int = 12; +pub const F_SETLKW: ::c_int = 13; pub const SIGHUP: ::c_int = 1; pub const SIGINT: ::c_int = 2; pub const SIGQUIT: ::c_int = 3; @@ -555,10 +565,11 @@ pub const FD_SETSIZE: usize = 1024; pub const ST_NOSUID: ::c_ulong = 2; -pub const HW_AVAILCPU: ::c_int = 25; - pub const NI_MAXHOST: ::size_t = 1025; +pub const Q_GETQUOTA: ::c_int = 0x700; +pub const Q_SETQUOTA: ::c_int = 0x800; + extern { pub fn getnameinfo(sa: *const ::sockaddr, salen: ::socklen_t, diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 704a7bdb62..027033bcec 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -1,3 +1,5 @@ +use dox::mem; + pub type c_char = i8; pub type wchar_t = i32; pub type off_t = i64; @@ -60,6 +62,11 @@ s! { } pub struct fd_set { + #[cfg(all(target_pointer_width = "64", + target_os = "freebsd"))] + fds_bits: [i64; FD_SETSIZE / 64], + #[cfg(not(all(target_pointer_width = "64", + target_os = "freebsd")))] fds_bits: [i32; FD_SETSIZE / 32], } @@ -95,14 +102,6 @@ s! { pub msg_flags: ::c_int, } - pub struct flock { - pub l_start: ::off_t, - pub l_len: ::off_t, - pub l_pid: ::pid_t, - pub l_type: ::c_short, - pub l_whence: ::c_short, - } - pub struct fsid_t { __fsid_val: [::int32_t; 2], } @@ -185,10 +184,7 @@ pub const O_FSYNC: ::c_int = 0x80; pub const O_NDELAY: ::c_int = 0x4; pub const O_NOFOLLOW: ::c_int = 0x100; -pub const F_GETLK: ::c_int = 7; pub const F_GETOWN: ::c_int = 5; -pub const F_SETLK: ::c_int = 8; -pub const F_SETLKW: ::c_int = 9; pub const F_SETOWN: ::c_int = 6; pub const MNT_FORCE: ::c_int = 0x80000; @@ -196,8 +192,6 @@ pub const MNT_FORCE: ::c_int = 0x80000; pub const Q_SYNC: ::c_int = 0x600; pub const Q_QUOTAON: ::c_int = 0x100; pub const Q_QUOTAOFF: ::c_int = 0x200; -pub const Q_GETQUOTA: ::c_int = 0x300; -pub const Q_SETQUOTA: ::c_int = 0x400; pub const TCIOFF: ::c_int = 3; pub const TCION: ::c_int = 4; @@ -209,19 +203,6 @@ pub const TCIOFLUSH: ::c_int = 3; pub const TCSANOW: ::c_int = 0; pub const TCSADRAIN: ::c_int = 1; pub const TCSAFLUSH: ::c_int = 2; -pub const NL0: ::c_int = 0x00000000; -pub const NL1: ::c_int = 0x00000100; -pub const TAB0: ::c_int = 0x00000000; -pub const TAB1: ::c_int = 0x00000400; -pub const TAB2: ::c_int = 0x00000800; -pub const CR0: ::c_int = 0x00000000; -pub const CR1: ::c_int = 0x00001000; -pub const CR2: ::c_int = 0x00002000; -pub const CR3: ::c_int = 0x00003000; -pub const FF0: ::c_int = 0x00000000; -pub const FF1: ::c_int = 0x00004000; -pub const BS0: ::c_int = 0x00000000; -pub const BS1: ::c_int = 0x00008000; pub const VEOF: usize = 0; pub const VEOL: usize = 1; pub const VEOL2: usize = 2; @@ -284,19 +265,22 @@ pub const WNOHANG: ::c_int = 1; f! { pub fn FD_CLR(fd: ::c_int, set: *mut fd_set) -> () { + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / 32] &= !(1 << (fd % 32)); + (*set).fds_bits[fd / bits] &= !(1 << (fd % bits)); return } pub fn FD_ISSET(fd: ::c_int, set: *mut fd_set) -> bool { + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - return ((*set).fds_bits[fd / 32] & (1 << (fd % 32))) != 0 + return ((*set).fds_bits[fd / bits] & (1 << (fd % bits))) != 0 } pub fn FD_SET(fd: ::c_int, set: *mut fd_set) -> () { + let bits = mem::size_of_val(&(*set).fds_bits[0]) * 8; let fd = fd as usize; - (*set).fds_bits[fd / 32] |= 1 << (fd % 32); + (*set).fds_bits[fd / bits] |= 1 << (fd % bits); return } diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs index 72d681c86d..b1bf2cafe1 100644 --- a/src/unix/bsd/openbsdlike/mod.rs +++ b/src/unix/bsd/openbsdlike/mod.rs @@ -41,6 +41,14 @@ s! { pub c_ispeed: ::c_int, pub c_ospeed: ::c_int, } + + pub struct flock { + pub l_start: ::off_t, + pub l_len: ::off_t, + pub l_pid: ::pid_t, + pub l_type: ::c_short, + pub l_whence: ::c_short, + } } pub const EXIT_FAILURE : ::c_int = 1; @@ -100,6 +108,9 @@ pub const F_LOCK : ::c_int = 1; pub const F_TEST : ::c_int = 3; pub const F_TLOCK : ::c_int = 2; pub const F_ULOCK : ::c_int = 0; +pub const F_GETLK: ::c_int = 7; +pub const F_SETLK: ::c_int = 8; +pub const F_SETLKW: ::c_int = 9; pub const SIGHUP : ::c_int = 1; pub const SIGINT : ::c_int = 2; pub const SIGQUIT : ::c_int = 3; @@ -354,6 +365,9 @@ pub const _SC_FSYNC : ::c_int = 29; pub const KERN_PROC_ARGV: ::c_int = 1; +pub const Q_GETQUOTA: ::c_int = 0x300; +pub const Q_SETQUOTA: ::c_int = 0x400; + extern { pub fn mincore(addr: *mut ::c_void, len: ::size_t, vec: *mut ::c_char) -> ::c_int; -- cgit v1.2.1