diff --git a/libc-test/build.rs b/libc-test/build.rs index f94f7051faf29..b1f8673075983 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -14,10 +14,11 @@ fn main() { let apple = target.contains("apple"); let musl = target.contains("musl"); let freebsd = target.contains("freebsd"); + let dragonfly = target.contains("dragonfly"); let mips = target.contains("mips"); let netbsd = target.contains("netbsd"); let rumprun = target.contains("rumprun"); - let bsdlike = freebsd || apple || netbsd; + let bsdlike = freebsd || apple || netbsd || dragonfly; let mut cfg = ctest::TestGenerator::new(); // Pull in extra goodies on linux/mingw @@ -96,7 +97,9 @@ fn main() { } else if !windows { cfg.header("glob.h"); cfg.header("ifaddrs.h"); - cfg.header("sys/quota.h"); + if !dragonfly { + cfg.header("sys/quota.h"); + } cfg.header("sys/statvfs.h"); if !musl { @@ -161,6 +164,11 @@ fn main() { cfg.header("sys/ioctl_compat.h"); } + if dragonfly { + cfg.header("pthread_np.h"); + cfg.header("sys/ioctl_compat.h"); + } + cfg.type_name(move |ty, is_struct| { match ty { // Just pass all these through, no need for a "struct" prefix @@ -221,6 +229,9 @@ fn main() { // sighandler_t is crazy across platforms "sighandler_t" => true, + // does not exists on DragonFly + "fflags_t" if dragonfly => true, + _ => false } }); @@ -286,6 +297,18 @@ fn main() { "QFMT_VFS_OLD" | "QFMT_VFS_V0" if mips && linux => true, + "USRQUOTA" | + "GRPQUOTA" | + "Q_SYNC" | + "Q_QUOTAON" | + "Q_QUOTAOFF" | + "Q_GETQUOTA" | + "Q_SETQUOTA" | + "RLIMIT_NPTS" | + "RLIMIT_SWAP" | + "RUSAGE_THREAD" | + "MADV_PROTECT" if dragonfly => true, + _ => false, } }); @@ -303,7 +326,7 @@ fn main() { "strerror_r" if linux => true, // actually xpg-something-or-other // typed 2nd arg on linux and android - "gettimeofday" if linux || android || freebsd => true, + "gettimeofday" if linux || android || freebsd | dragonfly => true, // not declared in newer android toolchains "getdtablesize" if android => true, @@ -333,6 +356,12 @@ fn main() { "ptrace" | "sigaltstack" if rumprun => true, + // uses size_t instead of socklen_t + "getnameinfo" if dragonfly => true, + + // is defined elsewhere + "__dfly_error" if dragonfly => true, + _ => false, } }); diff --git a/src/unix/bsd/apple/mod.rs b/src/unix/bsd/apple/mod.rs index 378fc4b771b55..b0d1d12c79c04 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 utsname { + pub sysname: [::c_char; 256], + pub nodename: [::c_char; 256], + pub release: [::c_char; 256], + pub version: [::c_char; 256], + pub machine: [::c_char; 256], + } } pub const EXIT_FAILURE: ::c_int = 1; diff --git a/src/unix/bsd/freebsdlike/dragonfly.rs b/src/unix/bsd/freebsdlike/dragonfly.rs index 6b874f0b1f67d..cd9bcf9ea317a 100644 --- a/src/unix/bsd/freebsdlike/dragonfly.rs +++ b/src/unix/bsd/freebsdlike/dragonfly.rs @@ -1,8 +1,68 @@ +pub type clock_t = u64; +pub type ino_t = u64; +pub type nlink_t = u32; +pub type blksize_t = u64; + 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; +s!{ + pub struct stat { + pub st_ino: ::ino_t, + pub st_nlink: ::nlink_t, + pub st_dev: ::dev_t, + pub st_mode: ::mode_t, + pub st_padding1: ::uint16_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::int64_t, + pub st_blksize: ::uint32_t, + pub st_flags: ::uint32_t, + pub st_gen: ::uint32_t, + pub st_lspare: ::int32_t, + pub st_qspare1: ::int64_t, + pub st_qspare2: ::int64_t, + } + + pub struct dirent { + pub d_fileno: ::ino_t, + pub d_namlen: u16, + pub d_type: u8, + __unused1: u8, + __unused2: u32, + pub d_name: [::c_char; 256], + } + + pub struct utsname { + pub sysname: [::c_char; 32], + pub nodename: [::c_char; 32], + pub release: [::c_char; 32], + pub version: [::c_char; 32], + pub machine: [::c_char; 32], + } + + pub struct stack_t { + pub ss_sp: *mut ::c_char, + pub ss_size: ::size_t, + pub ss_flags: ::c_int, + } + +} + extern { + pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) + -> ::c_int; + pub fn clock_gettime(clk_id: ::uint64_t, tp: *mut ::timespec) -> ::c_int; + pub fn __dfly_error() -> *const ::c_int; } diff --git a/src/unix/bsd/freebsdlike/freebsd.rs b/src/unix/bsd/freebsdlike/freebsd.rs index 9e6d985f9d7c0..2d3bbd5605cf0 100644 --- a/src/unix/bsd/freebsdlike/freebsd.rs +++ b/src/unix/bsd/freebsdlike/freebsd.rs @@ -1,7 +1,42 @@ +pub type clock_t = i32; +pub type ino_t = u32; +pub type nlink_t = u16; +pub type blksize_t = u32; + pub const PTHREAD_STACK_MIN: ::size_t = 2048; pub const KERN_PROC_PATHNAME: ::c_int = 12; pub const SIGSTKSZ: ::size_t = 34816; +pub const HW_AVAILCPU: ::c_int = 25; + +s! { + pub struct dirent { + pub d_fileno: u32, + pub d_reclen: u16, + pub d_type: u8, + pub d_namelen: u8, + pub d_name: [::c_char; 256], + } + + pub struct utsname { + pub sysname: [::c_char; 256], + pub nodename: [::c_char; 256], + pub release: [::c_char; 256], + pub version: [::c_char; 256], + pub machine: [::c_char; 256], + } + + pub struct stack_t { + pub ss_sp: *mut ::c_void, + pub ss_size: ::size_t, + pub ss_flags: ::c_int, + } +} 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 posix_fallocate(fd: ::c_int, offset: ::off_t, + len: ::off_t) -> ::c_int; pub fn __error() -> *mut ::c_int; } diff --git a/src/unix/bsd/freebsdlike/freebsd_x86.rs b/src/unix/bsd/freebsdlike/freebsd_x86.rs new file mode 100644 index 0000000000000..947dd62611605 --- /dev/null +++ b/src/unix/bsd/freebsdlike/freebsd_x86.rs @@ -0,0 +1,26 @@ +s! { + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: ::uint32_t, + pub st_lspare: ::int32_t, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + __unused: [u8; 8], + } +} diff --git a/src/unix/bsd/freebsdlike/freebsd_x86_64.rs b/src/unix/bsd/freebsdlike/freebsd_x86_64.rs new file mode 100644 index 0000000000000..a152913d61dff --- /dev/null +++ b/src/unix/bsd/freebsdlike/freebsd_x86_64.rs @@ -0,0 +1,25 @@ +s! { + pub struct stat { + pub st_dev: ::dev_t, + pub st_ino: ::ino_t, + pub st_mode: ::mode_t, + pub st_nlink: ::nlink_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + pub st_rdev: ::dev_t, + pub st_atime: ::time_t, + pub st_atime_nsec: ::c_long, + pub st_mtime: ::time_t, + pub st_mtime_nsec: ::c_long, + pub st_ctime: ::time_t, + pub st_ctime_nsec: ::c_long, + pub st_size: ::off_t, + pub st_blocks: ::blkcnt_t, + pub st_blksize: ::blksize_t, + pub st_flags: ::fflags_t, + pub st_gen: ::uint32_t, + pub st_lspare: ::int32_t, + pub st_birthtime: ::time_t, + pub st_birthtime_nsec: ::c_long, + } +} diff --git a/src/unix/bsd/freebsdlike/mod.rs b/src/unix/bsd/freebsdlike/mod.rs index 508fc6b72ce5e..fdcce76df2a28 100644 --- a/src/unix/bsd/freebsdlike/mod.rs +++ b/src/unix/bsd/freebsdlike/mod.rs @@ -1,9 +1,5 @@ -pub type clock_t = i32; pub type dev_t = u32; -pub type ino_t = u32; pub type mode_t = u16; -pub type nlink_t = u16; -pub type blksize_t = u32; pub type fflags_t = u32; pub type pthread_attr_t = *mut ::c_void; pub type rlim_t = i64; @@ -20,14 +16,6 @@ pub type speed_t = ::c_uint; pub enum timezone {} s! { - pub struct dirent { - pub d_fileno: u32, - pub d_reclen: u16, - pub d_type: u8, - pub d_namelen: u8, - pub d_name: [::c_char; 256], - } - pub struct glob_t { pub gl_pathc: ::size_t, __unused1: ::size_t, @@ -84,12 +72,6 @@ s! { pub sa_mask: sigset_t, } - pub struct stack_t { - pub ss_sp: *mut ::c_void, - pub ss_size: ::size_t, - pub ss_flags: ::c_int, - } - pub struct statvfs { pub f_bavail: ::fsblkcnt_t, pub f_bfree: ::fsblkcnt_t, @@ -555,7 +537,6 @@ pub const FD_SETSIZE: usize = 1024; pub const ST_NOSUID: ::c_ulong = 2; -pub const HW_AVAILCPU: ::c_int = 25; extern { pub fn mincore(addr: *const ::c_void, len: ::size_t, @@ -564,8 +545,6 @@ extern { mibp: *mut ::c_int, sizep: *mut ::size_t) -> ::c_int; - pub fn mprotect(addr: *const ::c_void, len: ::size_t, prot: ::c_int) - -> ::c_int; pub fn shm_open(name: *const ::c_char, oflag: ::c_int, mode: ::mode_t) -> ::c_int; pub fn sysctl(name: *const ::c_int, @@ -581,10 +560,7 @@ extern { newp: *const ::c_void, newlen: ::size_t) -> ::c_int; - pub fn clock_gettime(clk_id: ::c_int, tp: *mut ::timespec) -> ::c_int; pub fn pthread_set_name_np(tid: ::pthread_t, name: *const ::c_char); - pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, - len: ::off_t) -> ::c_int; pub fn sched_setscheduler(pid: ::pid_t, policy: ::c_int, param: *const sched_param) -> ::c_int; pub fn sched_getscheduler(pid: ::pid_t) -> ::c_int; pub fn memrchr(cx: *const ::c_void, c: ::c_int, n: ::size_t) -> *mut ::c_void; @@ -602,6 +578,18 @@ cfg_if! { } } +cfg_if! { + if #[cfg(all(target_arch = "x86", target_os = "freebsd"))] { + mod freebsd_x86; + pub use self::freebsd_x86::*; + } else if #[cfg(all(target_arch = "x86_64", target_os = "freebsd"))] { + mod freebsd_x86_64; + pub use self::freebsd_x86_64::*; + } else { + // ... + } +} + cfg_if! { if #[cfg(target_os = "freebsd")] { mod freebsd; diff --git a/src/unix/bsd/freebsdlike/x86.rs b/src/unix/bsd/freebsdlike/x86.rs index 8a5e5f9fb8d28..619cbbd9751e2 100644 --- a/src/unix/bsd/freebsdlike/x86.rs +++ b/src/unix/bsd/freebsdlike/x86.rs @@ -2,30 +2,3 @@ pub type c_long = i32; pub type c_ulong = u32; pub type time_t = i32; pub type suseconds_t = i32; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: ::uint32_t, - pub st_lspare: ::int32_t, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - __unused: [u8; 8], - } -} diff --git a/src/unix/bsd/freebsdlike/x86_64.rs b/src/unix/bsd/freebsdlike/x86_64.rs index a2da8452c4d34..48a590eb377de 100644 --- a/src/unix/bsd/freebsdlike/x86_64.rs +++ b/src/unix/bsd/freebsdlike/x86_64.rs @@ -2,29 +2,3 @@ pub type c_long = i64; pub type c_ulong = u64; pub type time_t = i64; pub type suseconds_t = i64; - -s! { - pub struct stat { - pub st_dev: ::dev_t, - pub st_ino: ::ino_t, - pub st_mode: ::mode_t, - pub st_nlink: ::nlink_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - pub st_rdev: ::dev_t, - pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, - pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, - pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_size: ::off_t, - pub st_blocks: ::blkcnt_t, - pub st_blksize: ::blksize_t, - pub st_flags: ::fflags_t, - pub st_gen: ::uint32_t, - pub st_lspare: ::int32_t, - pub st_birthtime: ::time_t, - pub st_birthtime_nsec: ::c_long, - } -} diff --git a/src/unix/bsd/mod.rs b/src/unix/bsd/mod.rs index 144240d42397c..a0e7af5ec2313 100644 --- a/src/unix/bsd/mod.rs +++ b/src/unix/bsd/mod.rs @@ -75,14 +75,6 @@ s! { pub tm_zone: *mut ::c_char, } - pub struct utsname { - pub sysname: [::c_char; 256], - pub nodename: [::c_char; 256], - pub release: [::c_char; 256], - pub version: [::c_char; 256], - pub machine: [::c_char; 256], - } - pub struct msghdr { pub msg_name: *mut ::c_void, pub msg_namelen: ::socklen_t, diff --git a/src/unix/bsd/openbsdlike/mod.rs b/src/unix/bsd/openbsdlike/mod.rs index 85a77dc96c56d..bbec673b27fa8 100644 --- a/src/unix/bsd/openbsdlike/mod.rs +++ b/src/unix/bsd/openbsdlike/mod.rs @@ -48,6 +48,14 @@ s! { pub c_ispeed: ::c_int, pub c_ospeed: ::c_int, } + + pub struct utsname { + pub sysname: [::c_char; 256], + pub nodename: [::c_char; 256], + pub release: [::c_char; 256], + pub version: [::c_char; 256], + pub machine: [::c_char; 256], + } } pub const EXIT_FAILURE : ::c_int = 1;