diff --git a/src/unix/mod.rs b/src/unix/mod.rs index d959091846e020f83907433ad0b1da68528f0b8b..32c51eec83e4b7b21029c96db2d8df4110ec03eb 100644 --- a/src/unix/mod.rs +++ b/src/unix/mod.rs @@ -230,8 +230,9 @@ pub const INADDR_BROADCAST: in_addr_t = 4294967295; pub const INADDR_NONE: in_addr_t = 4294967295; cfg_if! { - if #[cfg(dox)] { + if #[cfg(any(dox, target_os = "l4re"))] { // on dox builds don't pull in anything + // L4Re builds pass the required libs using -Z to the compiler. } else if #[cfg(all(not(stdbuild), feature = "use_std"))] { // cargo build, don't pull in anything extra as the libstd dep // already pulls in all libs. diff --git a/src/unix/uclibc/x86_64/l4re.rs b/src/unix/uclibc/x86_64/l4re.rs new file mode 100644 index 0000000000000000000000000000000000000000..06a9f09b142a18e2955d2a2170a0c21bdef3eef9 --- /dev/null +++ b/src/unix/uclibc/x86_64/l4re.rs @@ -0,0 +1,43 @@ +/// L4Re specifics +/// This module contains definitions required by various L4Re libc backends. +/// These are formally not part of the libc, but are a dependency of the libc +/// and hence we should provide them here. + +pub type l4_umword_t = ::c_ulong; // Unsigned machine word. + +s! { + /// CPU sets. + pub struct l4_sched_cpu_set_t { + // from the L4Re docs + /// Combination of granularity and offset. + /// + /// The granularity defines how many CPUs each bit in map describes. + /// The offset is the numer of the first CPU described by the first + /// bit in the bitmap. + /// offset must be a multiple of 2^graularity. + /// + /// | MSB | LSB | + /// | ---------------- | ------------------- | + /// | 8bit granularity | 24bit offset .. | + gran_offset: l4_umword_t , + /// Bitmap of CPUs. + map: l4_umword_t , + } +} + +#[cfg(target_os = "l4re")] +pub struct pthread_attr_t { + pub __detachstate: ::c_int, + pub __schedpolicy: ::c_int, + pub __schedparam: super::__sched_param, + pub __inheritsched: ::c_int, + pub __scope: ::c_int, + pub __guardsize: ::size_t, + pub __stackaddr_set: ::c_int, + pub __stackaddr: *mut ::c_void, // better don't use it + pub __stacksize: ::size_t, + // L4Re specifics + pub affinity: l4_sched_cpu_set_t, + pub create_flags: ::c_uint, +} + diff --git a/src/unix/uclibc/x86_64/mod.rs b/src/unix/uclibc/x86_64/mod.rs index 603efb10fcfa0087943725fefef837ef1a53b5ef..f72acf2bc077aac7e6ab5c8ba895169596349b27 100644 --- a/src/unix/uclibc/x86_64/mod.rs +++ b/src/unix/uclibc/x86_64/mod.rs @@ -1,5 +1,5 @@ -//! Definitions for l4re-uclibc on 64bit systems - +//! Definitions for uclibc on 64bit systems +//! pub type blkcnt_t = i64; pub type blksize_t = i64; pub type clock_t = i64; @@ -14,15 +14,31 @@ pub type nlink_t = ::c_uint; pub type off_t = ::c_long; pub type rlim_t = c_ulong; pub type rlim64_t = u64; +// [uClibc docs] Note stat64 has the same shape as stat for x86-64. +pub type stat64 = stat; pub type suseconds_t = ::c_long; pub type time_t = ::c_int; pub type wchar_t = ::c_int; -// ToDo, used? -//pub type d_ino = ::c_ulong; pub type nfds_t = ::c_ulong; s! { + pub struct dirent { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_name: [::c_char; 256], + } + + pub struct dirent64 { + pub d_ino: ::ino64_t, + pub d_off: ::off64_t, + pub d_reclen: u16, + pub d_type: u8, + pub d_name: [::c_char; 256], + } + pub struct ipc_perm { pub __key: ::key_t, pub uid: ::uid_t, @@ -37,6 +53,23 @@ s! { __unused2: ::c_ulong } + #[cfg(not(target_os = "l4re"))] + pub struct pthread_attr_t { + __detachstate: ::c_int, + __schedpolicy: ::c_int, + __schedparam: __sched_param, + __inheritsched: ::c_int, + __scope: ::c_int, + __guardsize: ::size_t, + __stackaddr_set: ::c_int, + __stackaddr: *mut ::c_void, // better don't use it + __stacksize: ::size_t, + } + + pub struct __sched_param { + __sched_priority: ::c_int, + } + pub struct siginfo_t { si_signo: ::c_int, // signal number si_errno: ::c_int, // if not zero: error value of signal, see errno.h @@ -103,77 +136,33 @@ s! { // __align: [u32; 0], // } - pub struct stat { // ToDo + pub struct stat { pub st_dev: ::c_ulong, - st_pad1: [::c_long; 2], pub st_ino: ::ino_t, - pub st_mode: ::mode_t, + // According to uclibc/libc/sysdeps/linux/x86_64/bits/stat.h, order of nlink and mode are + // swapped on 64 bit systems. pub st_nlink: ::nlink_t, + pub st_mode: ::mode_t, pub st_uid: ::uid_t, pub st_gid: ::gid_t, - pub st_rdev: u64, - pub st_pad2: [u64; 1], - pub st_size: off_t, - st_pad3: ::c_long, + pub st_rdev: ::c_ulong, // dev_t + pub st_size: off_t, // file size + pub st_blksize: ::blksize_t, + pub st_blocks: ::blkcnt_t, pub st_atime: ::time_t, - pub st_atime_nsec: ::c_long, + pub st_atime_nsec: ::c_ulong, pub st_mtime: ::time_t, - pub st_mtime_nsec: ::c_long, + pub st_mtime_nsec: ::c_ulong, pub st_ctime: ::time_t, - pub st_ctime_nsec: ::c_long, - pub st_blksize: ::blksize_t, - st_pad4: ::c_long, - pub st_blocks: ::blkcnt_t, - st_pad5: [::c_long; 7], + pub st_ctime_nsec: ::c_ulong, + st_pad4: [::c_long; 3] } - pub struct statvfs { // ToDo: broken - pub f_bsize: ::c_ulong, - pub f_frsize: ::c_ulong, - pub f_blocks: ::fsblkcnt_t, - pub f_bfree: ::fsblkcnt_t, - pub f_bavail: ::fsblkcnt_t, - pub f_files: ::fsfilcnt_t, - pub f_ffree: ::fsfilcnt_t, - pub f_favail: ::fsfilcnt_t, - #[cfg(target_endian = "little")] - pub f_fsid: ::c_ulong, - #[cfg(target_pointer_width = "32")] - __f_unused: ::c_int, - #[cfg(target_endian = "big")] - pub f_fsid: ::c_ulong, - pub f_flag: ::c_ulong, - pub f_namemax: ::c_ulong, - __f_spare: [::c_int; 6], - } - - pub struct dirent { // Todo - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - d_reclen: u16, - pub d_type: u8, - pub d_name: [i8; 256], - } - - pub struct dirent64 { // - pub d_ino: ::ino64_t, - pub d_off: ::off64_t, - pub d_reclen: u16, - pub d_type: u8, - pub d_name: [i8; 256], - } - - pub struct pthread_attr_t { // ToDo - __size: [u64; 7] - } - - pub struct sigaction { // TODO!! - pub sa_sigaction: ::sighandler_t, + pub struct sigaction { + pub sa_handler: ::sighandler_t, + pub sa_flags: ::c_ulong, + pub sa_restorer: *mut ::c_void, pub sa_mask: ::sigset_t, - #[cfg(target_arch = "sparc64")] - __reserved0: ::c_int, - pub sa_flags: ::c_int, - _restorer: *mut ::c_void, } pub struct stack_t { // ToDo @@ -298,27 +287,6 @@ s! { __unused5: *mut ::c_void, } - pub struct stat64 { // ToDo - 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 rlimit64 { // ToDo pub rlim_cur: rlim64_t, pub rlim_max: rlim64_t, @@ -331,20 +299,32 @@ s! { bits: [u64; 16], } - pub struct timespec { // ToDo - tv_sec: time_t, // seconds - tv_nsec: ::c_ulong, // nanoseconds - } - pub struct fsid_t { // ToDo __val: [::c_int; 2], } } // constants +pub const EADDRINUSE: ::c_int = 98; // Address already in use +pub const EADDRNOTAVAIL: ::c_int = 99; // Cannot assign requested address +pub const ECONNABORTED: ::c_int = 103; // Software caused connection abort +pub const ECONNREFUSED: ::c_int = 111; // Connection refused +pub const ECONNRESET: ::c_int = 104; // Connection reset by peer +pub const EDEADLK: ::c_int = 35; // Resource deadlock would occur +pub const ENOSYS: ::c_int = 38; // Function not implemented +pub const ENOTCONN: ::c_int = 107; // Transport endpoint is not connected +pub const ETIMEDOUT: ::c_int = 110; // connection timed out +pub const O_APPEND: ::c_int = 02000; +pub const O_ACCMODE: ::c_int = 0003; pub const O_CLOEXEC: ::c_int = 0x80000; +pub const O_CREAT: ::c_int = 0100; pub const O_DIRECTORY: ::c_int = 0200000; +pub const O_EXCL: ::c_int = 0200; +pub const O_NONBLOCK: ::c_int = 04000; +pub const O_TRUNC: ::c_int = 01000; pub const NCCS: usize = 32; +pub const PTHREAD_STACK_MIN: usize = 16384; +pub const SIG_SETMASK: ::c_int = 2; // Set the set of blocked signals pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40; pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4; pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0; @@ -359,3 +339,11 @@ pub const __SIZEOF_PTHREAD_RWLOCK_T: usize = 56; extern { pub fn memalign(align: ::size_t, size: ::size_t) -> *mut ::c_void; } + +cfg_if! { + if #[cfg(target_os = "l4re")] { + mod l4re; + pub use self::l4re::*; + } else { } +} +