Skip to content

Commit 5089909

Browse files
Tobias SchaffnerSebastian Humenda
Tobias Schaffner
and
Sebastian Humenda
committed
Add modifications needed for L4re in libstd
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>
1 parent 069a43a commit 5089909

File tree

11 files changed

+45
-10
lines changed

11 files changed

+45
-10
lines changed

src/libstd/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -469,6 +469,7 @@ pub mod error;
469469
pub mod ffi;
470470
pub mod fs;
471471
pub mod io;
472+
#[cfg(not(target_os = "l4re"))]
472473
pub mod net;
473474
pub mod num;
474475
pub mod os;

src/libstd/os/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub use sys::unix_ext as unix;
2727
#[stable(feature = "rust1", since = "1.0.0")]
2828
pub use sys::windows_ext as windows;
2929

30-
#[cfg(any(dox, target_os = "linux"))]
30+
#[cfg(any(dox, target_os = "linux", target_os = "l4re"))]
3131
#[doc(cfg(target_os = "linux"))]
3232
pub mod linux;
3333

src/libstd/sys/unix/args.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ impl DoubleEndedIterator for Args {
6565
target_os = "solaris",
6666
target_os = "emscripten",
6767
target_os = "haiku",
68+
target_os = "l4re",
6869
target_os = "fuchsia"))]
6970
mod imp {
7071
use os::unix::prelude::*;

src/libstd/sys/unix/condvar.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,16 @@ impl Condvar {
3838
Condvar { inner: UnsafeCell::new(libc::PTHREAD_COND_INITIALIZER) }
3939
}
4040

41-
#[cfg(any(target_os = "macos", target_os = "ios", target_os = "android"))]
41+
#[cfg(any(target_os = "macos",
42+
target_os = "ios",
43+
target_os = "l4re",
44+
target_os = "android"))]
4245
pub unsafe fn init(&mut self) {}
4346

44-
#[cfg(not(any(target_os = "macos", target_os = "ios", target_os = "android")))]
47+
#[cfg(not(any(target_os = "macos",
48+
target_os = "ios",
49+
target_os = "l4re",
50+
target_os = "android")))]
4551
pub unsafe fn init(&mut self) {
4652
use mem;
4753
let mut attr: libc::pthread_condattr_t = mem::uninitialized();

src/libstd/sys/unix/env.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,14 @@ pub mod os {
182182
pub const EXE_SUFFIX: &'static str = "";
183183
pub const EXE_EXTENSION: &'static str = "";
184184
}
185+
186+
#[cfg(target_os = "l4re")]
187+
pub mod os {
188+
pub const FAMILY: &'static str = "unix";
189+
pub const OS: &'static str = "l4re";
190+
pub const DLL_PREFIX: &'static str = "lib";
191+
pub const DLL_SUFFIX: &'static str = ".so";
192+
pub const DLL_EXTENSION: &'static str = "so";
193+
pub const EXE_SUFFIX: &'static str = "";
194+
pub const EXE_EXTENSION: &'static str = "";
195+
}

src/libstd/sys/unix/fd.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ impl FileDesc {
128128
target_os = "solaris",
129129
target_os = "emscripten",
130130
target_os = "fuchsia",
131+
target_os = "l4re",
131132
target_os = "haiku")))]
132133
pub fn set_cloexec(&self) -> io::Result<()> {
133134
unsafe {
@@ -139,6 +140,7 @@ impl FileDesc {
139140
target_os = "solaris",
140141
target_os = "emscripten",
141142
target_os = "fuchsia",
143+
target_os = "l4re",
142144
target_os = "haiku"))]
143145
pub fn set_cloexec(&self) -> io::Result<()> {
144146
unsafe {

src/libstd/sys/unix/fs.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,21 @@ use sys::time::SystemTime;
2323
use sys::{cvt, cvt_r};
2424
use sys_common::{AsInner, FromInner};
2525

26-
#[cfg(any(target_os = "linux", target_os = "emscripten"))]
26+
#[cfg(any(target_os = "linux", target_os = "emscripten", target_os = "l4re"))]
2727
use libc::{stat64, fstat64, lstat64, off64_t, ftruncate64, lseek64, dirent64, readdir64_r, open64};
2828
#[cfg(target_os = "android")]
2929
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, lseek64,
3030
dirent as dirent64, open as open64};
3131
#[cfg(not(any(target_os = "linux",
3232
target_os = "emscripten",
33+
target_os = "l4re",
3334
target_os = "android")))]
3435
use libc::{stat as stat64, fstat as fstat64, lstat as lstat64, off_t as off64_t,
3536
ftruncate as ftruncate64, lseek as lseek64, dirent as dirent64, open as open64};
3637
#[cfg(not(any(target_os = "linux",
3738
target_os = "emscripten",
3839
target_os = "solaris",
40+
target_os = "l4re",
3941
target_os = "fuchsia")))]
4042
use libc::{readdir_r as readdir64_r};
4143

@@ -316,6 +318,7 @@ impl DirEntry {
316318
target_os = "android",
317319
target_os = "solaris",
318320
target_os = "haiku",
321+
target_os = "l4re",
319322
target_os = "fuchsia"))]
320323
pub fn ino(&self) -> u64 {
321324
self.entry.d_ino as u64
@@ -346,6 +349,7 @@ impl DirEntry {
346349
#[cfg(any(target_os = "android",
347350
target_os = "linux",
348351
target_os = "emscripten",
352+
target_os = "l4re",
349353
target_os = "haiku"))]
350354
fn name_bytes(&self) -> &[u8] {
351355
unsafe {

src/libstd/sys/unix/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use libc;
2828
#[cfg(all(not(dox), target_os = "solaris"))] pub use os::solaris as platform;
2929
#[cfg(all(not(dox), target_os = "emscripten"))] pub use os::emscripten as platform;
3030
#[cfg(all(not(dox), target_os = "fuchsia"))] pub use os::fuchsia as platform;
31+
#[cfg(all(not(dox), target_os = "l4re"))] pub use os::linux as platform;
3132

3233
#[macro_use]
3334
pub mod weak;

src/libstd/sys/unix/os.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,10 @@ static ENV_LOCK: Mutex = Mutex::new();
3838

3939
extern {
4040
#[cfg(not(target_os = "dragonfly"))]
41-
#[cfg_attr(any(target_os = "linux", target_os = "emscripten", target_os = "fuchsia"),
41+
#[cfg_attr(any(target_os = "linux",
42+
target_os = "emscripten",
43+
target_os = "fuchsia",
44+
target_os = "l4re"),
4245
link_name = "__errno_location")]
4346
#[cfg_attr(any(target_os = "bitrig",
4447
target_os = "netbsd",
@@ -346,10 +349,10 @@ pub fn current_exe() -> io::Result<PathBuf> {
346349
}
347350
}
348351

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

355358
pub struct Env {

src/libstd/sys/unix/thread.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ impl Thread {
5252
assert_eq!(libc::pthread_attr_init(&mut attr), 0);
5353

5454
let stack_size = cmp::max(stack, min_stack_size(&attr));
55+
56+
// L4Re only supports a maximum of 1Mb per default.
57+
#[cfg(target_os = "l4re")]
58+
let stack_size = cmp::min(stack_size, 1024 * 1024);
59+
5560
match pthread_attr_setstacksize(&mut attr,
5661
stack_size) {
5762
0 => {}
@@ -131,6 +136,7 @@ impl Thread {
131136
#[cfg(any(target_env = "newlib",
132137
target_os = "solaris",
133138
target_os = "haiku",
139+
target_os = "l4re",
134140
target_os = "emscripten"))]
135141
pub fn set_name(_name: &CStr) {
136142
// Newlib, Illumos, Haiku, and Emscripten have no way to set a thread name.
@@ -225,7 +231,7 @@ pub mod guard {
225231
}
226232

227233
#[cfg(any(target_os = "android", target_os = "freebsd",
228-
target_os = "linux", target_os = "netbsd"))]
234+
target_os = "linux", target_os = "netbsd", target_os = "l4re"))]
229235
unsafe fn get_stack_start() -> Option<*mut libc::c_void> {
230236
let mut ret = None;
231237
let mut attr: libc::pthread_attr_t = ::mem::zeroed();
@@ -327,7 +333,7 @@ pub mod guard {
327333
}
328334

329335
#[cfg(any(target_os = "android", target_os = "freebsd",
330-
target_os = "linux", target_os = "netbsd"))]
336+
target_os = "linux", target_os = "netbsd", target_os = "l4re"))]
331337
pub unsafe fn current() -> Option<usize> {
332338
let mut ret = None;
333339
let mut attr: libc::pthread_attr_t = ::mem::zeroed();

src/libstd/sys_common/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub mod wtf8;
4747
#[cfg(target_os = "redox")]
4848
pub use sys::net;
4949

50-
#[cfg(not(target_os = "redox"))]
50+
#[cfg(not(any(target_os = "redox", target_os = "l4re")))]
5151
pub mod net;
5252

5353
#[cfg(feature = "backtrace")]

0 commit comments

Comments
 (0)