diff --git a/libc-test/build.rs b/libc-test/build.rs index f94f7051faf29..91cc69e82a201 100644 --- a/libc-test/build.rs +++ b/libc-test/build.rs @@ -364,7 +364,9 @@ fn main() { // just insert some padding. (struct_ == "siginfo_t" && field == "_pad") || // musl names this __dummy1 but it's still there - (musl && struct_ == "glob_t" && field == "gl_flags") + (musl && struct_ == "glob_t" && field == "gl_flags") || + // musl seems to define this as an *anonymous* bitfield + (musl && struct_ == "statvfs" && field == "__f_unused") }); cfg.fn_cname(move |name, cname| { diff --git a/src/unix/notbsd/linux/mips.rs b/src/unix/notbsd/linux/mips.rs index 41f173687ada6..f9a6cd25e95cb 100644 --- a/src/unix/notbsd/linux/mips.rs +++ b/src/unix/notbsd/linux/mips.rs @@ -10,6 +10,8 @@ pub type ino_t = u32; pub type blkcnt_t = i32; pub type blksize_t = i32; pub type nlink_t = u32; +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; s! { pub struct stat { diff --git a/src/unix/notbsd/linux/mod.rs b/src/unix/notbsd/linux/mod.rs index 512d5adc3879a..ac426fa232c7f 100644 --- a/src/unix/notbsd/linux/mod.rs +++ b/src/unix/notbsd/linux/mod.rs @@ -9,8 +9,6 @@ pub type ino64_t = u64; pub type off64_t = i64; pub type blkcnt64_t = i64; pub type rlim64_t = u64; -pub type fsblkcnt_t = ::c_ulong; -pub type fsfilcnt_t = ::c_ulong; pub type key_t = ::c_int; pub type shmatt_t = ::c_ulong; pub type mqd_t = ::c_int; diff --git a/src/unix/notbsd/linux/musl/b32.rs b/src/unix/notbsd/linux/musl/b32.rs new file mode 100644 index 0000000000000..9541ff191c922 --- /dev/null +++ b/src/unix/notbsd/linux/musl/b32.rs @@ -0,0 +1,73 @@ +s! { + pub struct stat { + pub st_dev: ::dev_t, + __st_dev_padding: ::c_int, + __st_ino_truncated: ::c_long, + 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, + __st_rdev_padding: ::c_int, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_atim: ::timespec, + pub st_mtim: ::timespec, + pub st_ctim: ::timespec, + pub st_ino: ::ino_t, + } + + pub struct stat64 { + pub st_dev: ::dev_t, + __st_dev_padding: ::c_int, + __st_ino_truncated: ::c_long, + 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, + __st_rdev_padding: ::c_int, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, + pub st_atim: ::timespec, + pub st_mtim: ::timespec, + pub st_ctim: ::timespec, + pub st_ino: ::ino_t, + } + + pub struct pthread_attr_t { + __size: [u32; 9] + } + + pub struct sigset_t { + __val: [::c_ulong; 32], + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + __unused1: ::c_int, + pub shm_dtime: ::time_t, + __unused2: ::c_int, + pub shm_ctime: ::time_t, + __unused3: ::c_int, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::c_ulong, + __pad1: ::c_ulong, + __pad2: ::c_ulong, + } + + pub struct msghdr { + pub msg_name: *mut ::c_void, + pub msg_namelen: ::socklen_t, + pub msg_iov: *mut ::iovec, + pub msg_iovlen: ::c_int, + pub msg_control: *mut ::c_void, + pub msg_controllen: ::socklen_t, + pub msg_flags: ::c_int, + } +} diff --git a/src/unix/notbsd/linux/musl/b64.rs b/src/unix/notbsd/linux/musl/b64.rs new file mode 100644 index 0000000000000..880918ebccb10 --- /dev/null +++ b/src/unix/notbsd/linux/musl/b64.rs @@ -0,0 +1,76 @@ +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_uid: ::uid_t, + pub st_gid: ::gid_t, + __pad0: ::c_int, + pub st_rdev: ::dev_t, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_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, + __unused: [::c_long; 3], + } + + pub struct stat64 { + pub st_dev: ::dev_t, + pub st_ino: ::ino64_t, + pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, + pub st_uid: ::uid_t, + pub st_gid: ::gid_t, + __pad0: ::c_int, + pub st_rdev: ::dev_t, + pub st_size: ::off_t, + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt64_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, + __reserved: [::c_long; 3], + } + + pub struct pthread_attr_t { + __size: [u64; 7] + } + + pub struct sigset_t { + __val: [::c_ulong; 16], + } + + pub struct shmid_ds { + pub shm_perm: ::ipc_perm, + pub shm_segsz: ::size_t, + pub shm_atime: ::time_t, + pub shm_dtime: ::time_t, + pub shm_ctime: ::time_t, + pub shm_cpid: ::pid_t, + pub shm_lpid: ::pid_t, + pub shm_nattch: ::c_ulong, + __pad1: ::c_ulong, + __pad2: ::c_ulong, + } + + pub struct msghdr { + pub msg_name: *mut ::c_void, + pub msg_namelen: ::socklen_t, + pub msg_iov: *mut ::iovec, + pub msg_iovlen: ::c_int, + __pad1: ::c_int, + pub msg_control: *mut ::c_void, + pub msg_controllen: ::socklen_t, + __pad2: ::socklen_t, + pub msg_flags: ::c_int, + } +} diff --git a/src/unix/notbsd/linux/musl.rs b/src/unix/notbsd/linux/musl/mod.rs similarity index 83% rename from src/unix/notbsd/linux/musl.rs rename to src/unix/notbsd/linux/musl/mod.rs index 7a244e49c4230..7e2f8de3f8ac8 100644 --- a/src/unix/notbsd/linux/musl.rs +++ b/src/unix/notbsd/linux/musl/mod.rs @@ -1,67 +1,49 @@ +#[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] +pub type c_long = i32; +#[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] +pub type c_ulong = u32; +#[cfg(any(target_arch = "x86_64"))] pub type c_long = i64; +#[cfg(any(target_arch = "x86_64"))] pub type c_ulong = u64; -pub type clock_t = i64; -pub type time_t = i64; -pub type suseconds_t = i64; + +pub type clock_t = c_long; +pub type time_t = c_long; +pub type suseconds_t = c_long; pub type ino_t = u64; pub type off_t = i64; pub type blkcnt_t = i64; + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub type c_char = i8; + +#[cfg(any(target_arch = "arm", + target_arch = "asmjs"))] +pub type c_char = u8; + +#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] pub type wchar_t = i32; -pub type nlink_t = u64; -pub type blksize_t = i64; -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_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt_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, - __unused: [::c_long; 3], - } +#[cfg(any(target_arch = "arm", + target_arch = "asmjs"))] +pub type wchar_t = u32; - pub struct stat64 { - pub st_dev: ::dev_t, - pub st_ino: ::ino64_t, - pub st_nlink: ::nlink_t, - pub st_mode: ::mode_t, - pub st_uid: ::uid_t, - pub st_gid: ::gid_t, - __pad0: ::c_int, - pub st_rdev: ::dev_t, - pub st_size: ::off_t, - pub st_blksize: ::blksize_t, - pub st_blocks: ::blkcnt64_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, - __reserved: [::c_long; 3], - } +// This definition is slightly different on aarch64 +#[cfg(not(target_arch = "aarch64"))] +pub type nlink_t = usize; - pub struct pthread_attr_t { - __size: [u64; 7] - } +// This definition is slightly different on aarch64 +#[cfg(not(target_arch = "aarch64"))] +pub type blksize_t = c_long; - pub struct sigset_t { - __val: [::c_ulong; 16], - } +pub type fsblkcnt_t = ::c_ulonglong; +pub type fsfilcnt_t = ::c_ulonglong; +s! { pub struct sigaction { pub sa_sigaction: ::sighandler_t, pub sa_mask: ::sigset_t, @@ -95,19 +77,6 @@ s! { __unused2: ::c_long } - pub struct shmid_ds { - pub shm_perm: ::ipc_perm, - pub shm_segsz: ::size_t, - pub shm_atime: ::time_t, - pub shm_dtime: ::time_t, - pub shm_ctime: ::time_t, - pub shm_cpid: ::pid_t, - pub shm_lpid: ::pid_t, - pub shm_nattch: ::c_ulong, - __pad1: ::c_ulong, - __pad2: ::c_ulong, - } - pub struct statfs { pub f_type: ::c_ulong, pub f_bsize: ::c_ulong, @@ -123,18 +92,6 @@ s! { pub f_spare: [::c_ulong; 4], } - pub struct msghdr { - pub msg_name: *mut ::c_void, - pub msg_namelen: ::socklen_t, - pub msg_iov: *mut ::iovec, - pub msg_iovlen: ::c_int, - __pad1: ::c_int, - pub msg_control: *mut ::c_void, - pub msg_controllen: ::socklen_t, - __pad2: ::socklen_t, - pub msg_flags: ::c_int, - } - pub struct termios { pub c_iflag: ::tcflag_t, pub c_oflag: ::tcflag_t, @@ -351,10 +308,18 @@ pub const SIG_UNBLOCK: ::c_int = 0x01; pub const FALLOC_FL_KEEP_SIZE: ::c_int = 0x01; pub const FALLOC_FL_PUNCH_HOLE: ::c_int = 0x02; -pub const _SC_2_C_VERSION: ::c_int = 96; - +#[cfg(any(target_arch = "x86_64"))] pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; +#[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] +pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32; +#[cfg(any(target_arch = "x86_64"))] pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; +#[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] +pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24; pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; pub const CPU_SETSIZE: ::c_int = 128; @@ -408,7 +373,12 @@ pub const PTRACE_SETREGS: ::c_uint = 13; pub const EFD_NONBLOCK: ::c_int = 0x800; +#[cfg(any(target_arch = "x86_64"))] pub const F_GETLK: ::c_int = 5; +#[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] +pub const F_GETLK: ::c_int = 12; pub const F_GETOWN: ::c_int = 9; pub const F_SETOWN: ::c_int = 8; @@ -438,3 +408,15 @@ extern { pub fn eventfd(init: ::c_uint, flags: ::c_int) -> ::c_int; pub fn ptrace(request: ::c_int, ...) -> ::c_long; } + +cfg_if! { + if #[cfg(any(target_arch = "x86_64"))] { + mod b64; + pub use self::b64::*; + } else if #[cfg(any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))] { + mod b32; + pub use self::b32::*; + } else { } +} diff --git a/src/unix/notbsd/linux/other/mod.rs b/src/unix/notbsd/linux/other/mod.rs index b2d9643812d17..f9db93dc52443 100644 --- a/src/unix/notbsd/linux/other/mod.rs +++ b/src/unix/notbsd/linux/other/mod.rs @@ -1,3 +1,6 @@ +pub type fsblkcnt_t = ::c_ulong; +pub type fsfilcnt_t = ::c_ulong; + s! { pub struct sigaction { pub sa_sigaction: ::sighandler_t, diff --git a/src/unix/notbsd/mod.rs b/src/unix/notbsd/mod.rs index 5d18853c007d1..0c462eacce0be 100644 --- a/src/unix/notbsd/mod.rs +++ b/src/unix/notbsd/mod.rs @@ -1,6 +1,9 @@ use dox::mem; +#[cfg(not(target_env = "musl"))] pub type rlim_t = c_ulong; +#[cfg(target_env = "musl")] +pub type rlim_t = ::c_ulonglong; pub type sa_family_t = u16; pub type pthread_key_t = ::c_uint; pub type speed_t = ::c_uint; @@ -108,7 +111,8 @@ s! { pub dli_saddr: *mut ::c_void, } - #[cfg_attr(any(target_arch = "x86", target_arch = "x86_64"), + #[cfg_attr(any(all(target_arch = "x86", not(target_env = "musl")), + target_arch = "x86_64"), repr(packed))] pub struct epoll_event { pub events: ::uint32_t, @@ -420,9 +424,28 @@ pub const CBAUD: ::tcflag_t = 0o0010017; pub const EFD_CLOEXEC: ::c_int = 0x80000; +#[cfg(not(all(target_env = "musl", + any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))))] pub const F_SETLK: ::c_int = 6; +#[cfg(not(all(target_env = "musl", + any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs"))))] pub const F_SETLKW: ::c_int = 7; +#[cfg(all(target_env = "musl", + any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs")))] +pub const F_SETLK: ::c_int = 13; +#[cfg(all(target_env = "musl", + any(target_arch = "x86", + target_arch = "arm", + target_arch = "asmjs")))] +pub const F_SETLKW: ::c_int = 14; + pub const MNT_FORCE: ::c_int = 0x1; pub const Q_SYNC: ::c_int = 0x800001;