Skip to content

DragonFly has different stat, dirent, clock_t, ino_t, nlink_t, blksize_t #117

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 3 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps this could just be removed from the dragonfly definitions? It should be fine to push the typedef down lower into each respective module.


_ => 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come these are ignored? Are they not defined on dragonfly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The quota's exist. The others not. I will add those that exist.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, feel free to just delete any constants from the libc crate on dragonfly that aren't actually present in the dragonfly libc


_ => 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,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm this seems worrisome, shouldn't this be fixed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have to check this. DragonFly uses socklen_t, which probably is the same as size_t.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is already addressed by #110. OpenBSD had same problem and I splitted getnameinfo implementations with size_t and socklen_t


// is defined elsewhere
"__dfly_error" if dragonfly => true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wow, there's no C header file that returns this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or wait, wasn't this part of rust_builtin which has since been removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

exactly :). I am working on a patch to support thread-local externs, so that we don't need that anymore.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok, in that case this function should actually be removed from libc


_ => 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
8 changes: 0 additions & 8 deletions src/unix/bsd/freebsdlike/dragonfly.rs

This file was deleted.

8 changes: 8 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cfg_if! {
if #[cfg(target_arch = "x86_64")] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can feel free to inline everything in this file if there's only one definition, but either way works for me

mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}
72 changes: 72 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/x86_64.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
pub type c_long = i64;
pub type c_ulong = u64;
pub type time_t = i64;
pub type suseconds_t = i64;

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;
}
7 changes: 0 additions & 7 deletions src/unix/bsd/freebsdlike/freebsd.rs

This file was deleted.

54 changes: 54 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
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;
}

cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use self::x86::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}
36 changes: 0 additions & 36 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,27 +560,12 @@ 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;
}

cfg_if! {
if #[cfg(target_arch = "x86")] {
mod x86;
pub use self::x86::*;
} else if #[cfg(target_arch = "x86_64")] {
mod x86_64;
pub use self::x86_64::*;
} else {
// ...
}
}

cfg_if! {
if #[cfg(target_os = "freebsd")] {
mod freebsd;
Expand Down
8 changes: 0 additions & 8 deletions src/unix/bsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
8 changes: 8 additions & 0 deletions src/unix/bsd/openbsdlike/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down