Skip to content

L4Re improvements #734

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

Merged
merged 12 commits into from
Aug 19, 2017
2 changes: 2 additions & 0 deletions src/unix/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ pub const INADDR_NONE: in_addr_t = 4294967295;
cfg_if! {
if #[cfg(dox)] {
// on dox builds don't pull in anything
} else if #[cfg(target_os = "l4re")] {
// required libraries for L4Re are linked externally, ATM
} 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.
Expand Down
46 changes: 46 additions & 0 deletions src/unix/uclibc/x86_64/l4re.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/// L4Re specifics
/// This module contains definitions required by various L4Re libc backends.
/// Some of them 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,
}

// L4Re requires a min stack size of 64k; that isn't defined in uClibc, but
// somewhere in the core libraries. uClibc wants 16k, but that's not enough.
pub const PTHREAD_STACK_MIN: usize = 65536;
168 changes: 78 additions & 90 deletions src/unix/uclibc/x86_64/mod.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand All @@ -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 SIG_SETMASK: ::c_int = 2; // Set the set of blocked signals
pub const PTHREAD_STACK_MIN: usize = 16384;
pub const __SIZEOF_PTHREAD_MUTEX_T: usize = 40;
pub const __SIZEOF_PTHREAD_MUTEXATTR_T: usize = 4;
pub const PTHREAD_MUTEX_NORMAL: ::c_int = 0;
Expand All @@ -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 { }
}