diff --git a/Makefile b/Makefile index 8ffd601d91..39d1183a56 100644 --- a/Makefile +++ b/Makefile @@ -7,11 +7,11 @@ ifneq ($(TARGET),) endif ifeq ($(TARGET),aarch64-unknown-linux-gnu) - CC="aarch64-linux-gnu-gcc" + CC=aarch64-linux-gnu-gcc endif ifeq ($(TARGET),x86_64-unknown-redox) - CC="x86_64-unknown-redox-gcc" + CC=x86_64-unknown-redox-gcc endif SRC=\ diff --git a/src/lib.rs b/src/lib.rs index 7c9f060b59..66b4d88090 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,7 +31,7 @@ pub extern crate time; pub extern crate unistd; pub extern crate wctype; -#[cfg(not(test))] +#[cfg(not(any(test, target_os = "redox")))] #[panic_implementation] #[linkage = "weak"] #[no_mangle] @@ -50,7 +50,7 @@ pub extern "C" fn rust_begin_unwind(pi: &::core::panic::PanicInfo) -> ! { #[linkage = "weak"] pub extern "C" fn rust_eh_personality() {} -#[cfg(not(test))] +#[cfg(not(any(test, target_os = "redox")))] #[lang = "oom"] #[linkage = "weak"] #[no_mangle] diff --git a/src/unistd/src/lib.rs b/src/unistd/src/lib.rs index c6a85a53a5..b673671f8d 100644 --- a/src/unistd/src/lib.rs +++ b/src/unistd/src/lib.rs @@ -1,7 +1,9 @@ //! unistd implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/unistd.h.html #![no_std] +#![cfg_attr(target_os = "redox", feature(alloc))] +#[cfg(target_os = "redox")] extern crate alloc; extern crate platform; extern crate stdio; extern crate string; @@ -134,6 +136,10 @@ pub unsafe extern "C" fn execve( platform::execve(path, argv, envp) } #[cfg(target_os = "redox")] { + use alloc::Vec; + use platform::{c_str, e}; + use platform::syscall::flag::*; + let mut env = envp; while !(*env).is_null() { let slice = c_str(*env); @@ -149,7 +155,7 @@ pub unsafe extern "C" fn execve( // If the environment variable has no value, there // is no need to write anything to the env scheme. if sep + 1 < slice.len() { - let n = match syscall::write(fd, &slice[sep + 1..]) { + let n = match platform::syscall::write(fd, &slice[sep + 1..]) { Ok(n) => n, err => { return e(err) as c_int; @@ -175,13 +181,13 @@ pub unsafe extern "C" fn execve( let mut len = 0; for i in 0.. { - if (*arg.offset(i)).is_null() { + if (*argv.offset(i)).is_null() { len = i; break; } } - let mut args: Vec<[usize; 2]> = Vec::with_capacity(len); + let mut args: Vec<[usize; 2]> = Vec::with_capacity(len as usize); let mut arg = argv; while !(*arg).is_null() { args.push([*arg as usize, c_str(*arg).len()]); @@ -294,25 +300,25 @@ pub unsafe extern "C" fn gethostname(mut name: *mut c_char, len: size_t) -> c_in name = name.offset(1); } - 0 } #[cfg(target_os = "redox")] { - use platform::{FileReader, Read}; + use platform::{e, FileReader, Read}; use platform::syscall::flag::*; - let fd = platform::open("/etc/hostname\0",as_ptr(), 0, O_RDONLY); + let fd = e(platform::syscall::open("/etc/hostname", O_RDONLY)) as i32; if fd < 0 { return fd; } - let reader = FileReader(fd); + let mut reader = FileReader(fd); for _ in 0..len { - if !reader.read_u8(&mut *name) { + if !reader.read_u8(&mut *(name as *mut u8)) { *name = 0; break; } name = name.offset(1); } } + 0 } #[no_mangle]