Skip to content

Commit

Permalink
Move musl-exclusions to cfg_if blocks and alias types on Musl too
Browse files Browse the repository at this point in the history
  • Loading branch information
bossmc committed Oct 2, 2022
1 parent 6280e51 commit 328ec95
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 136 deletions.
5 changes: 4 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2941,8 +2941,11 @@ fn test_linux(target: &str) {

t if t.ends_with("_t") => t.to_string(),

// In MUSL `flock64` is a typedef to `flock`.
// In MUSL `xxx64` is a typedef to `xxx`.
"flock64" if musl => format!("struct {}", ty),
"dirent64" if musl => format!("struct {}", ty),
"rlimit64" if musl => format!("struct {}", ty),
"fpos64_t" if musl => format!("struct {}", ty),

// put `struct` in front of all structs:.
t if is_struct => format!("struct {}", t),
Expand Down
112 changes: 64 additions & 48 deletions src/unix/linux_like/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,20 @@ pub type name_t = u64;

pub type iconv_t = *mut ::c_void;

#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum fpos64_t {} // FIXME: fill this out with a struct
impl ::Copy for fpos64_t {}
impl ::Clone for fpos64_t {
fn clone(&self) -> fpos64_t {
*self
cfg_if! {
if #[cfg(not(target_env = "musl"))] {
#[cfg_attr(feature = "extra_traits", derive(Debug))]
pub enum fpos64_t {} // FIXME: fill this out with a struct
impl ::Copy for fpos64_t {}
impl ::Clone for fpos64_t {
fn clone(&self) -> fpos64_t {
*self
}
}
}
}

s! {
pub struct rlimit64 {
pub rlim_cur: rlim64_t,
pub rlim_max: rlim64_t,
}

pub struct glob_t {
pub gl_pathc: ::size_t,
pub gl_pathv: *mut *mut c_char,
Expand Down Expand Up @@ -605,6 +604,17 @@ s! {
}
}

cfg_if! {
if #[cfg(not(target_env = "musl"))] {
s! {
pub struct rlimit64 {
pub rlim_cur: rlim64_t,
pub rlim_max: rlim64_t,
}
}
}
}

s_no_extra_traits! {
pub struct sockaddr_nl {
pub nl_family: ::sa_family_t,
Expand All @@ -621,14 +631,6 @@ s_no_extra_traits! {
pub d_name: [::c_char; 256],
}

pub struct dirent64 {
pub d_ino: ::ino64_t,
pub d_off: ::off64_t,
pub d_reclen: ::c_ushort,
pub d_type: ::c_uchar,
pub d_name: [::c_char; 256],
}

pub struct sockaddr_alg {
pub salg_family: ::sa_family_t,
pub salg_type: [::c_uchar; 14],
Expand Down Expand Up @@ -692,6 +694,20 @@ s_no_extra_traits! {
}
}

cfg_if! {
if #[cfg(not(target_env = "musl"))] {
s_no_extra_traits! {
pub struct dirent64 {
pub d_ino: ::ino64_t,
pub d_off: ::off64_t,
pub d_reclen: ::c_ushort,
pub d_type: ::c_uchar,
pub d_name: [::c_char; 256],
}
}
}
}

s_no_extra_traits! {
// linux/net_tstamp.h
#[allow(missing_debug_implementations)]
Expand Down Expand Up @@ -3764,30 +3780,8 @@ extern "C" {
pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
pub fn __errno_location() -> *mut ::c_int;

#[cfg(not(target_env = "musl"))]
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
#[cfg(not(target_env = "musl"))]
pub fn freopen64(
filename: *const c_char,
mode: *const c_char,
file: *mut ::FILE,
) -> *mut ::FILE;
#[cfg(not(target_env = "musl"))]
pub fn tmpfile64() -> *mut ::FILE;
#[cfg(not(target_env = "musl"))]
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
#[cfg(not(target_env = "musl"))]
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
#[cfg(not(target_env = "musl"))]
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
#[cfg(not(target_env = "musl"))]
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
pub fn fallocate(fd: ::c_int, mode: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
#[cfg(not(target_env = "musl"))]
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn posix_fallocate(fd: ::c_int, offset: ::off_t, len: ::off_t) -> ::c_int;
#[cfg(not(target_env = "musl"))]
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn readahead(fd: ::c_int, offset: ::off64_t, count: ::size_t) -> ::ssize_t;
pub fn getxattr(
path: *const c_char,
Expand Down Expand Up @@ -4104,13 +4098,6 @@ extern "C" {
offset: *mut off_t,
count: ::size_t,
) -> ::ssize_t;
#[cfg(not(target_env = "musl"))]
pub fn sendfile64(
out_fd: ::c_int,
in_fd: ::c_int,
offset: *mut off64_t,
count: ::size_t,
) -> ::ssize_t;
pub fn sigsuspend(mask: *const ::sigset_t) -> ::c_int;
pub fn getgrgid_r(
gid: ::gid_t,
Expand Down Expand Up @@ -4355,6 +4342,35 @@ extern "C" {
pub fn pthread_setname_np(thread: ::pthread_t, name: *const ::c_char) -> ::c_int;
}

// LFS64 extensions
//
// * musl has 64-bit versions only so aliases the LFS64 symbols to the standard ones
cfg_if! {
if #[cfg(not(target_env = "musl"))] {
extern "C" {
pub fn fallocate64(fd: ::c_int, mode: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn fgetpos64(stream: *mut ::FILE, ptr: *mut fpos64_t) -> ::c_int;
pub fn fopen64(filename: *const c_char, mode: *const c_char) -> *mut ::FILE;
pub fn freopen64(
filename: *const c_char,
mode: *const c_char,
file: *mut ::FILE,
) -> *mut ::FILE;
pub fn fseeko64(stream: *mut ::FILE, offset: ::off64_t, whence: ::c_int) -> ::c_int;
pub fn fsetpos64(stream: *mut ::FILE, ptr: *const fpos64_t) -> ::c_int;
pub fn ftello64(stream: *mut ::FILE) -> ::off64_t;
pub fn posix_fallocate64(fd: ::c_int, offset: ::off64_t, len: ::off64_t) -> ::c_int;
pub fn sendfile64(
out_fd: ::c_int,
in_fd: ::c_int,
offset: *mut off64_t,
count: ::size_t,
) -> ::ssize_t;
pub fn tmpfile64() -> *mut ::FILE;
}
}
}

cfg_if! {
if #[cfg(target_env = "uclibc")] {
mod uclibc;
Expand Down
67 changes: 47 additions & 20 deletions src/unix/linux_like/linux/musl/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ pub type fsblkcnt_t = ::c_ulonglong;
pub type fsfilcnt_t = ::c_ulonglong;
pub type rlim_t = ::c_ulonglong;

pub type flock64 = flock;

cfg_if! {
if #[cfg(doc)] {
// Used in `linux::arch` to define ioctl constants.
Expand Down Expand Up @@ -707,8 +705,6 @@ extern "C" {
timeout: *mut ::timespec,
) -> ::c_int;

pub fn getrlimit64(resource: ::c_int, rlim: *mut ::rlimit64) -> ::c_int;
pub fn setrlimit64(resource: ::c_int, rlim: *const ::rlimit64) -> ::c_int;
pub fn getrlimit(resource: ::c_int, rlim: *mut ::rlimit) -> ::c_int;
pub fn setrlimit(resource: ::c_int, rlim: *const ::rlimit) -> ::c_int;
pub fn prlimit(
Expand All @@ -717,13 +713,6 @@ extern "C" {
new_limit: *const ::rlimit,
old_limit: *mut ::rlimit,
) -> ::c_int;
pub fn prlimit64(
pid: ::pid_t,
resource: ::c_int,
new_limit: *const ::rlimit64,
old_limit: *mut ::rlimit64,
) -> ::c_int;

pub fn ioctl(fd: ::c_int, request: ::c_int, ...) -> ::c_int;
pub fn gettimeofday(tp: *mut ::timeval, tz: *mut ::c_void) -> ::c_int;
pub fn ptrace(request: ::c_int, ...) -> ::c_long;
Expand Down Expand Up @@ -756,33 +745,71 @@ extern "C" {
pub fn malloc_usable_size(ptr: *mut ::c_void) -> ::size_t;
}

pub use tmpfile as tmpfile64;
// Musl's standard entrypoints are already LFS64 compatible, historically the library aliased
// these together in header files (as `#define`s) _and_ in the library with weak symbol aliases.
//
// Since <version> these aliases were removed from the library (both in the API and the ABI) so we
// alias them here to keep the crate API stable.
#[allow(dead_code)]
fn check_type_aliases(
dirent: ::dirent,
ino: ::ino_t,
flock: ::flock,
off: ::off_t,
pos: ::fpos_t,
rlimit: ::rlimit,
stat: ::stat,
statfs: ::statfs,
statvfs: ::statvfs,
) {
let _dirent: ::dirent64 = dirent;
let _ino: ::ino64_t = ino;
let _flock: ::flock64 = flock;
let _off: ::off64_t = off;
let _pos: ::fpos64_t = pos;
let _rlimit: ::rlimit64 = rlimit;
let _stat: ::stat64 = stat;
let _statfs: ::statfs64 = statfs;
let _statvfs: ::statvfs64 = statvfs;
}
pub type dirent64 = ::dirent;
pub type fpos64_t = ::fpos_t;
pub type rlimit64 = ::rlimit;
pub type flock64 = ::flock;
pub use creat as creat64;
pub use fallocate as fallocate64;
pub use fgetpos as fgetpos64;
pub use fopen as fopen64;
pub use freopen as freopen64;
pub use fseeko as fseeko64;
pub use fsetpos as fsetpos64;
pub use ftello as ftello64;
pub use posix_fallocate as posix_fallocate64;
pub use sendfile as sendfile64;
pub use statfs as statfs64;
pub use fstatfs as fstatfs64;
pub use statvfs as statvfs64;
pub use fstatvfs as fstatvfs64;
pub use creat as creat64;
pub use fstat as fstat64;
pub use fstatat as fstatat64;
pub use fstatfs as fstatfs64;
pub use fstatvfs as fstatvfs64;
pub use ftello as ftello64;
pub use ftruncate as ftruncate64;
pub use getrlimit as getrlimit64;
pub use lseek as lseek64;
pub use lstat as lstat64;
pub use mmap as mmap64;
pub use open as open64;
pub use openat as openat64;
pub use posix_fadvise as posix_fadvise64;
pub use posix_fallocate as posix_fallocate64;
pub use pread as pread64;
pub use preadv as preadv64;
pub use prlimit as prlimit64;
pub use pwrite as pwrite64;
pub use pwritev as pwritev64;
pub use readdir as readdir64;
pub use readdir_r as readdir64_r;
pub use sendfile as sendfile64;
pub use setrlimit as setrlimit64;
pub use stat as stat64;
pub use statfs as statfs64;
pub use statvfs as statvfs64;
pub use tmpfile as tmpfile64;
pub use truncate as truncate64;

cfg_if! {
Expand Down
Loading

0 comments on commit 328ec95

Please sign in to comment.