Skip to content

Commit

Permalink
Add modifications needed for L4re in libstd
Browse files Browse the repository at this point in the history
This commit adds the needed modifications to compile the std crate
for the L4 Runtime environment (L4Re).

A target for the L4Re was introduced in commit:
c151220

In many aspects implementations for linux also apply for the L4Re
microkernel.

Two uncommon characteristics had to be resolved:
* L4Re has no network funktionality
* L4Re has a maximum stacksize of 1Mb for threads

Co-authored-by: Sebastian Humenda <sebastian.humenda@tu-dresden.de>
  • Loading branch information
Tobias Schaffner and Sebastian Humenda committed Sep 8, 2017
1 parent 2cf0a4a commit 9bbc6db
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/libstd/lib.rs
Expand Up @@ -466,6 +466,7 @@ pub mod error;
pub mod ffi;
pub mod fs;
pub mod io;
#[cfg(not(target_os = "l4re"))]
pub mod net;
pub mod num;
pub mod os;
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/os/mod.rs
Expand Up @@ -27,7 +27,7 @@ pub use sys::unix_ext as unix;
#[stable(feature = "rust1", since = "1.0.0")]
pub use sys::windows_ext as windows;

#[cfg(any(dox, target_os = "linux"))]
#[cfg(any(dox, target_os = "linux", target_os = "l4re"))]
#[doc(cfg(target_os = "linux"))]
pub mod linux;

Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/args.rs
Expand Up @@ -65,6 +65,7 @@ impl DoubleEndedIterator for Args {
target_os = "solaris",
target_os = "emscripten",
target_os = "haiku",
target_os = "l4re",
target_os = "fuchsia"))]
mod imp {
use os::unix::prelude::*;
Expand Down
10 changes: 8 additions & 2 deletions src/libstd/sys/unix/condvar.rs
Expand Up @@ -38,10 +38,16 @@ impl Condvar {
Condvar { inner: UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER) }
}

#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
#[cfg(any(target_os = "macos",
target_os = "ios",
target_os = "l4re",
target_os = "android"))]
pub unsafe fn init(&mut self) {}

#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
#[cfg(not(any(target_os = "macos",
target_os = "ios",
target_os = "l4re",
target_os = "android")))]
pub unsafe fn init(&mut self) {
use mem;
let mut attr: libc::pthread_condattr_t = mem::uninitialized();
Expand Down
11 changes: 11 additions & 0 deletions src/libstd/sys/unix/env.rs
Expand Up @@ -182,3 +182,14 @@ pub mod os {
pub const EXE_SUFFIX: &'static str = "";
pub const EXE_EXTENSION: &'static str = "";
}

#[cfg(target_os = "l4re")]
pub mod os {
pub const FAMILY: &'static str = "unix";
pub const OS: &'static str = "l4re";
pub const DLL_PREFIX: &'static str = "lib";
pub const DLL_SUFFIX: &'static str = ".so";
pub const DLL_EXTENSION: &'static str = "so";
pub const EXE_SUFFIX: &'static str = "";
pub const EXE_EXTENSION: &'static str = "";
}
2 changes: 2 additions & 0 deletions src/libstd/sys/unix/fd.rs
Expand Up @@ -144,6 +144,7 @@ impl FileDesc {
target_os = "solaris",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "l4re",
target_os = "haiku")))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand All @@ -155,6 +156,7 @@ impl FileDesc {
target_os = "solaris",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "l4re",
target_os = "haiku"))]
pub fn set_cloexec(&self) -> io::Result<()> {
unsafe {
Expand Down
6 changes: 5 additions & 1 deletion src/libstd/sys/unix/fs.rs
Expand Up @@ -23,19 +23,21 @@ use sys::time::SystemTime;
use sys::{cvt, cvt_r};
use sys_common::{AsInner, FromInner};

#[cfg(any(target_os = "linux", target_os = "emscripten"))]
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
#[cfg(target_os = "android")]
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, lseek64,
dirent as dirent64, open as open64};
#[cfg(not(any(target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "android")))]
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t,
ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64};
#[cfg(not(any(target_os = "linux",
target_os = "emscripten",
target_os = "solaris",
target_os = "l4re",
target_os = "fuchsia")))]
use libc::{readdir_r as readdir64_r};

Expand Down Expand Up @@ -316,6 +318,7 @@ impl DirEntry {
target_os = "android",
target_os = "solaris",
target_os = "haiku",
target_os = "l4re",
target_os = "fuchsia"))]
pub fn ino(&self) -> u64 {
self.entry.d_ino as u64
Expand Down Expand Up @@ -346,6 +349,7 @@ impl DirEntry {
#[cfg(any(target_os = "android",
target_os = "linux",
target_os = "emscripten",
target_os = "l4re",
target_os = "haiku"))]
fn name_bytes(&self) -> &[u8] {
unsafe {
Expand Down
1 change: 1 addition & 0 deletions src/libstd/sys/unix/mod.rs
Expand Up @@ -28,6 +28,7 @@ use libc;
#[cfg(all(not(dox), target_os = "solaris"))] pub use os::solaris as platform;
#[cfg(all(not(dox), target_os = "emscripten"))] pub use os::emscripten as platform;
#[cfg(all(not(dox), target_os = "fuchsia"))] pub use os::fuchsia as platform;
#[cfg(all(not(dox), target_os = "l4re"))] pub use os::linux as platform;

#[macro_use]
pub mod weak;
Expand Down
9 changes: 6 additions & 3 deletions src/libstd/sys/unix/os.rs
Expand Up @@ -38,7 +38,10 @@ static ENV_LOCK: Mutex = Mutex::new();

extern {
#[cfg(not(target_os = "dragonfly"))]
#[cfg_attr(any(target_os = "linux", target_os = "emscripten", target_os = "fuchsia"),
#[cfg_attr(any(target_os = "linux",
target_os = "emscripten",
target_os = "fuchsia",
target_os = "l4re"),
link_name = "__errno_location")]
#[cfg_attr(any(target_os = "bitrig",
target_os = "netbsd",
Expand Down Expand Up @@ -346,10 +349,10 @@ pub fn current_exe() -> io::Result<PathBuf> {
}
}

#[cfg(target_os = "fuchsia")]
#[cfg(any(target_os = "fuchsia", target_os = "l4re"))]
pub fn current_exe() -> io::Result<PathBuf> {
use io::ErrorKind;
Err(io::Error::new(ErrorKind::Other, "Not yet implemented on fuchsia"))
Err(io::Error::new(ErrorKind::Other, "Not yet implemented!"))
}

pub struct Env {
Expand Down
10 changes: 8 additions & 2 deletions src/libstd/sys/unix/thread.rs
Expand Up @@ -52,6 +52,11 @@ impl Thread {
assert_eq!(libc::pthread_attr_init(&mut attr), 0);

let stack_size = cmp::max(stack, min_stack_size(&attr));

// L4Re only supports a maximum of 1Mb per default.
#[cfg(target_os = "l4re")]
let stack_size = cmp::min(stack_size, 1024 * 1024);

match pthread_attr_setstacksize(&mut attr,
stack_size) {
0 => {}
Expand Down Expand Up @@ -131,6 +136,7 @@ impl Thread {
#[cfg(any(target_env = "newlib",
target_os = "solaris",
target_os = "haiku",
target_os = "l4re",
target_os = "emscripten"))]
pub fn set_name(_name: &CStr) {
// Newlib, Illumos, Haiku, and Emscripten have no way to set a thread name.
Expand Down Expand Up @@ -226,7 +232,7 @@ pub mod guard {
}

#[cfg(any(target_os = "android", target_os = "freebsd",
target_os = "linux", target_os = "netbsd"))]
target_os = "linux", target_os = "netbsd", target_os = "l4re"))]
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
let mut ret = None;
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
Expand Down Expand Up @@ -328,7 +334,7 @@ pub mod guard {
}

#[cfg(any(target_os = "android", target_os = "freebsd",
target_os = "linux", target_os = "netbsd"))]
target_os = "linux", target_os = "netbsd", target_os = "l4re"))]
pub unsafe fn current() -> Option<usize> {
let mut ret = None;
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys_common/mod.rs
Expand Up @@ -47,7 +47,7 @@ pub mod wtf8;
#[cfg(target_os = "redox")]
pub use sys::net;

#[cfg(not(target_os = "redox"))]
#[cfg(not(any(target_os = "redox", target_os = "l4re")))]
pub mod net;

#[cfg(feature = "backtrace")]
Expand Down

0 comments on commit 9bbc6db

Please sign in to comment.