Skip to content
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

freebsd: Add support for FreeBSD 12.x ABI #721

Closed
wants to merge 1 commit 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
41 changes: 41 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
use std::process::Command;

#[cfg(not(target_os = "freebsd"))]
fn detect_freebsd_abi_changes() {}

#[cfg(target_os = "freebsd")]
fn detect_freebsd_abi_changes() {
// We use freebsd-version(1). We could use `uname -k` to get the
// version of the kernel, but it wouldn't reflect the version of the
// userland (in case we are in a jail).
//
// freebsd-version(1) appeared in FreeBSD 10.0, so it's good enough.

let _ = Command::new("freebsd-version").arg("-u")
.output()
.and_then(
|output| {
assert!(output.status.success());

let full_version_string = String::from_utf8_lossy(&output.stdout);
let split_version: Vec<&str> = full_version_string
.trim()
.splitn(2, '.').collect();

assert!(split_version.len() >= 1);

let version: u32 = split_version[0]
.parse().unwrap();

// FreeBSD kernel versions are published in the following document:
// https://www.freebsd.org/doc/en/books/porters-handbook/versions.html

if version >= 12 { println!("cargo:rustc-cfg=freebsd12_abi"); }

Ok(())
});
}

fn main() {
detect_freebsd_abi_changes();
}
10 changes: 10 additions & 0 deletions src/unix/bsd/freebsdlike/dragonfly/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pub type clock_t = u64;
pub type dev_t = u32;
pub type ino_t = u64;
pub type nlink_t = u32;
pub type blksize_t = i64;
Expand Down Expand Up @@ -168,6 +169,15 @@ s! {
pub ifm_index: ::c_ushort,
pub ifm_data: if_data,
}

pub struct kevent {
pub ident: ::uintptr_t,
pub filter: ::c_short,
pub flags: ::c_ushort,
pub fflags: ::c_uint,
pub data: ::intptr_t,
pub udata: *mut ::c_void,
}
}

pub const RAND_MAX: ::c_int = 0x7fff_ffff;
Expand Down
26 changes: 0 additions & 26 deletions src/unix/bsd/freebsdlike/freebsd/aarch64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
52 changes: 52 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/freebsd11.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pub type dev_t = u32;
pub type ino_t = u32;
pub type nlink_t = u16;

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,

#[cfg(target_arch = "x86")]
__unused: [u8; 8],
}

pub struct dirent {
pub d_fileno: u32,
pub d_reclen: u16,
pub d_type: u8,
pub d_namlen: u8,
pub d_name: [::c_char; 256],
}

pub struct kevent {
pub ident: ::uintptr_t,
pub filter: ::c_short,
pub flags: ::c_ushort,
pub fflags: ::c_uint,
pub data: ::intptr_t,
pub udata: *mut ::c_void,
pub ext: [::uint64_t; 0],
}
}

pub const KEVENT_EXT_ZEROED: [::uint64_t; 0] = [0; 0];
70 changes: 70 additions & 0 deletions src/unix/bsd/freebsdlike/freebsd/freebsd12.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
pub type dev_t = u64;
pub type ino_t = u64;
pub type nlink_t = u64;

s! {
pub struct stat {
pub st_dev: ::dev_t,
pub st_ino: ::ino_t,
pub st_nlink: ::nlink_t,
pub st_mode: ::mode_t,
pub st_pad0: ::uint16_t,
pub st_uid: ::uid_t,
pub st_gid: ::gid_t,
pub st_pad1: ::uint32_t,
pub st_rdev: ::dev_t,

#[cfg(target_arch = "x86")]
pub st_atime_ext: ::int32_t,

pub st_atime: ::time_t,
pub st_atime_nsec: ::c_long,

#[cfg(target_arch = "x86")]
pub st_mtime_ext: i32,

pub st_mtime: ::time_t,
pub st_mtime_nsec: ::c_long,

#[cfg(target_arch = "x86")]
pub st_ctime_ext: ::int32_t,

pub st_ctime: ::time_t,
pub st_ctime_nsec: ::c_long,

#[cfg(target_arch = "x86")]
pub st_birthtime_ext: ::int32_t,

pub st_birthtime: ::time_t,
pub st_birthtime_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: ::uint64_t,
pub st_spare: [::uint64_t; 10],
}

pub struct dirent {
pub d_fileno: u64,
pub d_off: u64,
pub d_reclen: u16,
pub d_type: u8,
pub d_pad0: u8,
pub d_namlen: u16,
pub d_pad1: u16,
pub d_name: [::c_char; 256],
}

pub struct kevent {
pub ident: ::uintptr_t,
pub filter: ::c_short,
pub flags: ::c_ushort,
pub fflags: ::c_uint,
pub data: ::int64_t,
pub udata: *mut ::c_void,
pub ext: [::uint64_t; 4],
}
}

pub const KEVENT_EXT_ZEROED: [::uint64_t; 4] = [0; 4];
23 changes: 13 additions & 10 deletions src/unix/bsd/freebsdlike/freebsd/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
pub type fflags_t = u32;
pub type clock_t = i32;
pub type ino_t = u32;
pub type lwpid_t = i32;
pub type nlink_t = u16;
pub type blksize_t = u32;
pub type clockid_t = ::c_int;
pub type sem_t = _sem;
Expand Down Expand Up @@ -43,14 +41,6 @@ s! {
pub aio_sigevent: sigevent
}

pub struct dirent {
pub d_fileno: u32,
pub d_reclen: u16,
pub d_type: u8,
pub d_namlen: u8,
pub d_name: [::c_char; 256],
}

pub struct jail {
pub version: u32,
pub path: *mut ::c_char,
Expand Down Expand Up @@ -595,3 +585,16 @@ cfg_if! {
// Unknown target_arch
}
}

cfg_if! {
if #[cfg(freebsd12_abi)] {
// Starting with FreeBSD 12.0-RELEASE, the kernel uses 64-bit
// ino_t. This affects `struct stat` and `struct dirent_t` as
// well as a few types above.
mod freebsd12;
pub use self::freebsd12::*;
} else {
mod freebsd11;
pub use self::freebsd11::*;
}
}
27 changes: 0 additions & 27 deletions src/unix/bsd/freebsdlike/freebsd/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],
}
}
26 changes: 0 additions & 26 deletions src/unix/bsd/freebsdlike/freebsd/x86_64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
10 changes: 0 additions & 10 deletions src/unix/bsd/freebsdlike/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
pub type dev_t = u32;
pub type mode_t = u16;
pub type pthread_attr_t = *mut ::c_void;
pub type rlim_t = i64;
Expand Down Expand Up @@ -31,15 +30,6 @@ s! {
__unused8: *mut ::c_void,
}

pub struct kevent {
pub ident: ::uintptr_t,
pub filter: ::c_short,
pub flags: ::c_ushort,
pub fflags: ::c_uint,
pub data: ::intptr_t,
pub udata: *mut ::c_void,
}

pub struct sockaddr_storage {
pub ss_len: u8,
pub ss_family: ::sa_family_t,
Expand Down