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

Steps towards support for musl-unknown-linux-uclibc #578

Merged
merged 18 commits into from
May 8, 2017
Merged
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
34 changes: 30 additions & 4 deletions libc-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ fn main() {
let android = target.contains("android");
let apple = target.contains("apple");
let musl = target.contains("musl");
let uclibc = target.contains("uclibc");
let freebsd = target.contains("freebsd");
let dragonfly = target.contains("dragonfly");
let mips = target.contains("mips");
Expand Down Expand Up @@ -126,8 +127,10 @@ fn main() {

if !musl {
cfg.header("sys/sysctl.h");
}
if !musl && !uclibc {

if !netbsd && !openbsd {
if !netbsd && !openbsd && !uclibc {
cfg.header("execinfo.h");
cfg.header("xlocale.h");
}
Expand Down Expand Up @@ -164,7 +167,10 @@ fn main() {
cfg.header("mqueue.h");
cfg.header("ucontext.h");
cfg.header("sys/signalfd.h");
cfg.header("sys/xattr.h");
if !uclibc {
// optionally included in uclibc
cfg.header("sys/xattr.h");
}
cfg.header("sys/ipc.h");
cfg.header("sys/msg.h");
cfg.header("sys/shm.h");
Expand All @@ -184,7 +190,9 @@ fn main() {
cfg.header("sys/sendfile.h");
cfg.header("sys/vfs.h");
cfg.header("sys/syscall.h");
cfg.header("sys/sysinfo.h");
if !uclibc {
cfg.header("sys/sysinfo.h");
}
cfg.header("sys/reboot.h");
if !musl {
cfg.header("linux/netlink.h");
Expand Down Expand Up @@ -226,7 +234,9 @@ fn main() {
}

if linux || freebsd || dragonfly || netbsd || apple {
cfg.header("aio.h");
if !uclibc {
cfg.header("aio.h");
}
}

cfg.type_name(move |ty, is_struct| {
Expand Down Expand Up @@ -388,6 +398,11 @@ fn main() {
"KERN_KDENABLE_BG_TRACE" if apple => true,
"KERN_KDDISABLE_BG_TRACE" if apple => true,

// These are either unimplemented or optionally built into uClibc
"LC_CTYPE_MASK" | "LC_NUMERIC_MASK" | "LC_TIME_MASK" | "LC_COLLATE_MASK" | "LC_MONETARY_MASK" | "LC_MESSAGES_MASK" |
"MADV_MERGEABLE" | "MADV_UNMERGEABLE" | "MADV_HWPOISON" | "IPV6_ADD_MEMBERSHIP" | "IPV6_DROP_MEMBERSHIP" | "IPV6_MULTICAST_LOOP" | "IPV6_V6ONLY" |
"MAP_STACK" | "RTLD_DEEPBIND" | "SOL_IPV6" | "SOL_ICMPV6" if uclibc => true,

_ => false,
}
});
Expand Down Expand Up @@ -474,6 +489,17 @@ fn main() {
// it's in a header file?
"endpwent" if android => true,


// These are either unimplemented or optionally built into uClibc
// or "sysinfo", where it's defined but the structs in linux/sysinfo.h and sys/sysinfo.h
// clash so it can't be tested
"getxattr" | "lgetxattr" | "fgetxattr" | "setxattr" | "lsetxattr" | "fsetxattr" |
"listxattr" | "llistxattr" | "flistxattr" | "removexattr" | "lremovexattr" |
"fremovexattr" |
"backtrace" |
"sysinfo" | "newlocale" | "duplocale" | "freelocale" | "uselocale" |
"nl_langinfo_l" | "wcslen" | "wcstombs" if uclibc => true,

// Apparently res_init exists on Android, but isn't defined in a header:
// https://mail.gnome.org/archives/commits-list/2013-May/msg01329.html
"res_init" if android => true,
Expand Down
11 changes: 7 additions & 4 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,13 @@ extern {
}

cfg_if! {
if #[cfg(any(target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia"))] {
if #[cfg(target_env = "uclibc")] {
mod uclibc;
pub use self::uclibc::*;
} else if #[cfg(any(target_os = "linux",
target_os = "android",
target_os = "emscripten",
target_os = "fuchsia"))] {
mod notbsd;
pub use self::notbsd::*;
} else if #[cfg(any(target_os = "macos",
Expand Down
269 changes: 269 additions & 0 deletions src/unix/uclibc/mips/mips32.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,269 @@
pub type c_char = i8;
pub type c_long = i32;
pub type c_ulong = u32;
pub type clock_t = i32;
pub type time_t = i32;
pub type suseconds_t = i32;
pub type wchar_t = i32;
pub type off_t = i32;
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;
pub type rlim_t = c_ulong;

s! {
pub struct stat {
pub st_dev: ::dev_t,
st_pad1: [::c_long; 2],
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_pad2: [::c_long; 1],
pub st_size: ::off_t,
st_pad3: ::c_long,
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_blksize: ::blksize_t,
pub st_blocks: ::blkcnt_t,
st_pad5: [::c_long; 14],
}

pub struct stat64 {
pub st_dev: ::dev_t,
st_pad1: [::c_long; 2],
pub st_ino: ::ino64_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,
st_pad2: [::c_long; 2],
pub st_size: ::off64_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_blksize: ::blksize_t,
st_pad3: ::c_long,
pub st_blocks: ::blkcnt64_t,
st_pad5: [::c_long; 14],
}

pub struct pthread_attr_t {
__size: [u32; 9]
}

pub struct sigaction {
pub sa_flags: ::c_uint,
pub sa_sigaction: ::sighandler_t,
pub sa_mask: sigset_t,
_restorer: *mut ::c_void,
}

pub struct stack_t {
pub ss_sp: *mut ::c_void,
pub ss_size: ::size_t,
pub ss_flags: ::c_int,
}

pub struct sigset_t {
__val: [::c_ulong; 4],
}

pub struct siginfo_t {
pub si_signo: ::c_int,
pub si_code: ::c_int,
pub si_errno: ::c_int,
pub _pad: [::c_int; 29],
}

pub struct glob64_t {
pub gl_pathc: ::size_t,
pub gl_pathv: *mut *mut ::c_char,
pub gl_offs: ::size_t,
pub gl_flags: ::c_int,

__unused1: *mut ::c_void,
__unused2: *mut ::c_void,
__unused3: *mut ::c_void,
__unused4: *mut ::c_void,
__unused5: *mut ::c_void,
}

pub struct ipc_perm {
pub __key: ::key_t,
pub uid: ::uid_t,
pub gid: ::gid_t,
pub cuid: ::uid_t,
pub cgid: ::gid_t,
pub mode: ::c_uint,
pub __seq: ::c_ushort,
__pad1: ::c_ushort,
__unused1: ::c_ulong,
__unused2: ::c_ulong
}

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: ::shmatt_t,
__unused4: ::c_ulong,
__unused5: ::c_ulong
}

pub struct msqid_ds {
pub msg_perm: ::ipc_perm,
#[cfg(target_endian = "big")]
__glibc_reserved1: ::c_ulong,
pub msg_stime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved1: ::c_ulong,
#[cfg(target_endian = "big")]
__glibc_reserved2: ::c_ulong,
pub msg_rtime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved2: ::c_ulong,
#[cfg(target_endian = "big")]
__glibc_reserved3: ::c_ulong,
pub msg_ctime: ::time_t,
#[cfg(target_endian = "little")]
__glibc_reserved3: ::c_ulong,
__msg_cbytes: ::c_ulong,
pub msg_qnum: ::msgqnum_t,
pub msg_qbytes: ::msglen_t,
pub msg_lspid: ::pid_t,
pub msg_lrpid: ::pid_t,
__glibc_reserved4: ::c_ulong,
__glibc_reserved5: ::c_ulong,
}

pub struct statfs {
pub f_type: ::c_long,
pub f_bsize: ::c_long,
pub f_frsize: ::c_long,
pub f_blocks: ::fsblkcnt_t,
pub f_bfree: ::fsblkcnt_t,
pub f_files: ::fsblkcnt_t,
pub f_ffree: ::fsblkcnt_t,
pub f_bavail: ::fsblkcnt_t,
pub f_fsid: ::fsid_t,

pub f_namelen: ::c_long,
f_spare: [::c_long; 6],
}

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: ::size_t,
pub msg_flags: ::c_int,
}

pub struct cmsghdr {
pub cmsg_len: ::size_t,
pub cmsg_level: ::c_int,
pub cmsg_type: ::c_int,
}

pub struct termios {
pub c_iflag: ::tcflag_t,
pub c_oflag: ::tcflag_t,
pub c_cflag: ::tcflag_t,
pub c_lflag: ::tcflag_t,
pub c_line: ::cc_t,
pub c_cc: [::cc_t; ::NCCS],
}

pub struct flock {
pub l_type: ::c_short,
pub l_whence: ::c_short,
pub l_start: ::off_t,
pub l_len: ::off_t,
pub l_sysid: ::c_long,
pub l_pid: ::pid_t,
pad: [::c_long; 4],
}

pub struct sysinfo {
pub uptime: ::c_long,
pub loads: [::c_ulong; 3],
pub totalram: ::c_ulong,
pub freeram: ::c_ulong,
pub sharedram: ::c_ulong,
pub bufferram: ::c_ulong,
pub totalswap: ::c_ulong,
pub freeswap: ::c_ulong,
pub procs: ::c_ushort,
pub pad: ::c_ushort,
pub totalhigh: ::c_ulong,
pub freehigh: ::c_ulong,
pub mem_unit: ::c_uint,
pub _f: [::c_char; 8],
}

// FIXME this is actually a union
pub struct sem_t {
#[cfg(target_pointer_width = "32")]
__size: [::c_char; 16],
#[cfg(target_pointer_width = "64")]
__size: [::c_char; 32],
__align: [::c_long; 0],
}
}

pub const __SIZEOF_PTHREAD_CONDATTR_T: usize = 4;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 24;
pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 32;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;

pub const RLIM_INFINITY: ::rlim_t = 0x7fffffff;

pub const SYS_gettid: ::c_long = 4222; // Valid for O32

#[link(name = "util")]
extern {
pub fn sysctl(name: *mut ::c_int,
namelen: ::c_int,
oldp: *mut ::c_void,
oldlenp: *mut ::size_t,
newp: *mut ::c_void,
newlen: ::size_t)
-> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
pub fn backtrace(buf: *mut *mut ::c_void,
sz: ::c_int) -> ::c_int;
pub fn glob64(pattern: *const ::c_char,
flags: ::c_int,
errfunc: ::dox::Option<extern fn(epath: *const ::c_char,
errno: ::c_int)
-> ::c_int>,
pglob: *mut glob64_t) -> ::c_int;
pub fn globfree64(pglob: *mut glob64_t);
pub fn ptrace(request: ::c_uint, ...) -> ::c_long;
pub fn pthread_attr_getaffinity_np(attr: *const ::pthread_attr_t,
cpusetsize: ::size_t,
cpuset: *mut ::cpu_set_t) -> ::c_int;
pub fn pthread_attr_setaffinity_np(attr: *mut ::pthread_attr_t,
cpusetsize: ::size_t,
cpuset: *const ::cpu_set_t) -> ::c_int;
}
Loading