Skip to content

Dragonfly more fixes #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
});
Expand Down Expand Up @@ -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,
}
});
Expand All @@ -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,
Expand Down Expand Up @@ -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,
}
});
Expand Down
8 changes: 8 additions & 0 deletions src/unix/bsd/apple/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
60 changes: 60 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly.rs
Original file line number Diff line number Diff line change
@@ -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;
}
35 changes: 35 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd.rs
Original file line number Diff line number Diff line change
@@ -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;
}
26 changes: 26 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd_x86.rs
Original file line number Diff line number Diff line change
@@ -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],
}
}
25 changes: 25 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd_x86_64.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
36 changes: 12 additions & 24 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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;
Expand All @@ -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;
Expand Down
27 changes: 0 additions & 27 deletions src/unix/bsd/freebsdlike/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
}
}
Loading