Skip to content

Commit

Permalink
Add musl definitions for x86, arm and asmjs
Browse files Browse the repository at this point in the history
I've tested x86 against C locally, but not arm or asmjs.
I added the arm definitions because asmjs's C is derived from arms.

Mysteriously, my locally-built musl does not contain a
definition for _SC_2_C_VERSION, so I just removed it.
  • Loading branch information
brson committed Jan 5, 2016
1 parent 2522ecd commit 6d132c4
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 83 deletions.
4 changes: 3 additions & 1 deletion libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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| {
Expand Down
2 changes: 2 additions & 0 deletions src/unix/notbsd/linux/mips.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions src/unix/notbsd/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
73 changes: 73 additions & 0 deletions src/unix/notbsd/linux/musl/b32.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
76 changes: 76 additions & 0 deletions src/unix/notbsd/linux/musl/b64.rs
Original file line number Diff line number Diff line change
@@ -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,
}
}
140 changes: 61 additions & 79 deletions src/unix/notbsd/linux/musl.rs → src/unix/notbsd/linux/musl/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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 { }
}
3 changes: 3 additions & 0 deletions src/unix/notbsd/linux/other/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Loading

0 comments on commit 6d132c4

Please sign in to comment.