Permalink
Checking mergeability…
Don’t worry, you can still create the pull request.
Comparing changes
Open a pull request
- 12 commits
- 17 files changed
- 0 commit comments
- 4 contributors
Unified
Split
Showing
with
377 additions
and 87 deletions.
- +3 −3 .gitmodules
- +30 −0 src/librustc_target/spec/aarch64_unknown_redox.rs
- +1 −0 src/librustc_target/spec/mod.rs
- +1 −1 src/librustc_target/spec/redox_base.rs
- +7 −13 src/libstd/path.rs
- +23 −0 src/libstd/sys/redox/mod.rs
- +77 −33 src/libstd/sys/redox/os.rs
- +2 −3 src/libstd/sys/redox/path.rs
- +101 −21 src/libstd/sys/redox/process.rs
- +77 −0 src/libstd/sys/redox/syscall/arch/aarch64.rs
- +4 −9 src/libstd/sys/redox/syscall/call.rs
- +43 −1 src/libstd/sys/redox/syscall/flag.rs
- +4 −0 src/libstd/sys/redox/syscall/mod.rs
- +1 −1 src/libstd/sys/redox/syscall/number.rs
- +1 −1 src/llvm
- +1 −1 src/rustc/compiler_builtins_shim/Cargo.toml
- +1 −0 src/tools/build-manifest/src/main.rs
| @@ -1,13 +1,13 @@ | |||
| [submodule "src/llvm"] | |||
| path = src/llvm | |||
| url = https://github.com/rust-lang/llvm.git | |||
| branch = master | |||
| url = https://gitlab.redox-os.org/redox-os/llvm.git | |||
| branch = aarch64 | |||
| [submodule "src/rust-installer"] | |||
| path = src/tools/rust-installer | |||
| url = https://github.com/rust-lang/rust-installer.git | |||
| [submodule "src/liblibc"] | |||
| path = src/liblibc | |||
| url = https://github.com/rust-lang/libc.git | |||
| url = https://gitlab.redox-os.org/redox-os/liblibc.git | |||
| [submodule "src/doc/nomicon"] | |||
| path = src/doc/nomicon | |||
| url = https://github.com/rust-lang-nursery/nomicon.git | |||
| @@ -0,0 +1,30 @@ | |||
| // Copyright 2016 The Rust Project Developers. See the COPYRIGHT | |||
| // file at the top-level directory of this distribution and at | |||
| // http://rust-lang.org/COPYRIGHT. | |||
| // | |||
| // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |||
| // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |||
| // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |||
| // option. This file may not be copied, modified, or distributed | |||
| // except according to those terms. | |||
|
|
|||
| use spec::{LinkerFlavor, Target, TargetResult}; | |||
|
|
|||
| pub fn target() -> TargetResult { | |||
| let mut base = super::redox_base::opts(); | |||
| base.max_atomic_width = Some(128); | |||
|
|
|||
| Ok(Target { | |||
| llvm_target: "aarch64-unknown-redox".to_string(), | |||
| target_endian: "little".to_string(), | |||
| target_pointer_width: "64".to_string(), | |||
| target_c_int_width: "32".to_string(), | |||
| data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), | |||
| arch: "aarch64".to_string(), | |||
| target_os: "redox".to_string(), | |||
| target_env: "".to_string(), | |||
| target_vendor: "unknown".to_string(), | |||
| linker_flavor: LinkerFlavor::Gcc, | |||
| options: base, | |||
| }) | |||
| } | |||
| @@ -363,6 +363,7 @@ supported_targets! { | |||
|
|
|||
| ("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc), | |||
|
|
|||
| ("aarch64-unknown-redox", aarch64_unknown_redox), | |||
| ("x86_64-unknown-redox", x86_64_unknown_redox), | |||
|
|
|||
| ("i386-apple-ios", i386_apple_ios), | |||
| @@ -33,7 +33,7 @@ pub fn opts() -> TargetOptions { | |||
| relocation_model: "static".to_string(), | |||
| disable_redzone: true, | |||
| eliminate_frame_pointer: false, | |||
| target_family: None, | |||
| target_family: Some("redox".to_string()), | |||
| linker_is_gnu: true, | |||
| has_elf_tls: true, | |||
| .. Default::default() | |||
| @@ -193,6 +193,10 @@ pub enum Prefix<'a> { | |||
| /// Prefix `C:` for the given disk drive. | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| Disk(#[stable(feature = "rust1", since = "1.0.0")] u8), | |||
|
|
|||
| /// Scheme `file:` used on Redox | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| Scheme(#[stable(feature = "rust1", since = "1.0.0")] &'a OsStr), | |||
| } | |||
|
|
|||
| impl<'a> Prefix<'a> { | |||
| @@ -223,6 +227,7 @@ impl<'a> Prefix<'a> { | |||
| }, | |||
| DeviceNS(x) => 4 + os_str_len(x), | |||
| Disk(_) => 2, | |||
| Scheme(x) => 1 + os_str_len(x), | |||
| } | |||
|
|
|||
| } | |||
| @@ -324,11 +329,6 @@ unsafe fn u8_slice_as_os_str(s: &[u8]) -> &OsStr { | |||
| &*(s as *const [u8] as *const OsStr) | |||
| } | |||
|
|
|||
| // Detect scheme on Redox | |||
| fn has_redox_scheme(s: &[u8]) -> bool { | |||
| cfg!(target_os = "redox") && s.split(|b| *b == b'/').next().unwrap_or(b"").contains(&b':') | |||
| } | |||
|
|
|||
| //////////////////////////////////////////////////////////////////////////////// | |||
| // Cross-platform, iterator-independent parsing | |||
| //////////////////////////////////////////////////////////////////////////////// | |||
| @@ -1811,12 +1811,7 @@ impl Path { | |||
| #[stable(feature = "rust1", since = "1.0.0")] | |||
| #[allow(deprecated)] | |||
| pub fn is_absolute(&self) -> bool { | |||
| if cfg!(target_os = "redox") { | |||
| // FIXME: Allow Redox prefixes | |||
| self.has_root() || has_redox_scheme(self.as_u8_slice()) | |||
| } else { | |||
| self.has_root() && (cfg!(unix) || self.prefix().is_some()) | |||
| } | |||
| self.has_root() && (cfg!(unix) || self.prefix().is_some()) | |||
| } | |||
|
|
|||
| /// Returns `true` if the `Path` is relative, i.e. not absolute. | |||
| @@ -2219,8 +2214,7 @@ impl Path { | |||
| Components { | |||
| path: self.as_u8_slice(), | |||
| prefix, | |||
| has_physical_root: has_physical_root(self.as_u8_slice(), prefix) || | |||
| has_redox_scheme(self.as_u8_slice()), | |||
| has_physical_root: has_physical_root(self.as_u8_slice(), prefix), | |||
| front: State::Prefix, | |||
| back: State::Body, | |||
| } | |||
| @@ -75,6 +75,29 @@ pub fn cvt(result: Result<usize, syscall::Error>) -> io::Result<usize> { | |||
| result.map_err(|err| io::Error::from_raw_os_error(err.errno)) | |||
| } | |||
|
|
|||
| #[doc(hidden)] | |||
| pub trait IsMinusOne { | |||
| fn is_minus_one(&self) -> bool; | |||
| } | |||
|
|
|||
| macro_rules! impl_is_minus_one { | |||
| ($($t:ident)*) => ($(impl IsMinusOne for $t { | |||
| fn is_minus_one(&self) -> bool { | |||
| *self == -1 | |||
| } | |||
| })*) | |||
| } | |||
|
|
|||
| impl_is_minus_one! { i8 i16 i32 i64 isize } | |||
|
|
|||
| pub fn cvt_libc<T: IsMinusOne>(t: T) -> io::Result<T> { | |||
| if t.is_minus_one() { | |||
| Err(io::Error::last_os_error()) | |||
| } else { | |||
| Ok(t) | |||
| } | |||
| } | |||
|
|
|||
| /// On Redox, use an illegal instruction to abort | |||
| pub unsafe fn abort_internal() -> ! { | |||
| ::core::intrinsics::abort(); | |||
| @@ -12,10 +12,12 @@ | |||
|
|
|||
| #![allow(unused_imports)] // lots of cfg code here | |||
|
|
|||
| use libc::{self, c_char}; | |||
|
|
|||
| use os::unix::prelude::*; | |||
|
|
|||
| use error::Error as StdError; | |||
| use ffi::{OsString, OsStr}; | |||
| use ffi::{CStr, CString, OsStr, OsString}; | |||
| use fmt; | |||
| use io::{self, Read, Write}; | |||
| use iter; | |||
| @@ -27,7 +29,7 @@ use ptr; | |||
| use slice; | |||
| use str; | |||
| use sys_common::mutex::Mutex; | |||
| use sys::{cvt, fd, syscall}; | |||
| use sys::{cvt, cvt_libc, fd, syscall}; | |||
| use vec; | |||
|
|
|||
| extern { | |||
| @@ -129,6 +131,8 @@ pub fn current_exe() -> io::Result<PathBuf> { | |||
| Ok(PathBuf::from(path)) | |||
| } | |||
|
|
|||
| pub static ENV_LOCK: Mutex = Mutex::new(); | |||
|
|
|||
| pub struct Env { | |||
| iter: vec::IntoIter<(OsString, OsString)>, | |||
| _dont_send_or_sync_me: PhantomData<*mut ()>, | |||
| @@ -140,52 +144,92 @@ impl Iterator for Env { | |||
| fn size_hint(&self) -> (usize, Option<usize>) { self.iter.size_hint() } | |||
| } | |||
|
|
|||
| pub unsafe fn environ() -> *mut *const *const c_char { | |||
| extern { static mut environ: *const *const c_char; } | |||
| &mut environ | |||
| } | |||
|
|
|||
| /// Returns a vector of (variable, value) byte-vector pairs for all the | |||
| /// environment variables of the current process. | |||
| pub fn env() -> Env { | |||
| let mut variables: Vec<(OsString, OsString)> = Vec::new(); | |||
| if let Ok(mut file) = ::fs::File::open("env:") { | |||
| let mut string = String::new(); | |||
| if file.read_to_string(&mut string).is_ok() { | |||
| for line in string.lines() { | |||
| let mut parts = line.splitn(2, '='); | |||
| if let Some(name) = parts.next() { | |||
| let value = parts.next().unwrap_or(""); | |||
| variables.push((OsString::from(name.to_string()), | |||
| OsString::from(value.to_string()))); | |||
| } | |||
| unsafe { | |||
| let _guard = ENV_LOCK.lock(); | |||
| let mut environ = *environ(); | |||
| if environ == ptr::null() { | |||
| panic!("os::env() failure getting env string from OS: {}", | |||
| io::Error::last_os_error()); | |||
| } | |||
| let mut result = Vec::new(); | |||
| while *environ != ptr::null() { | |||
| if let Some(key_value) = parse(CStr::from_ptr(*environ).to_bytes()) { | |||
| result.push(key_value); | |||
| } | |||
| environ = environ.offset(1); | |||
| } | |||
| return Env { | |||
| iter: result.into_iter(), | |||
| _dont_send_or_sync_me: PhantomData, | |||
| } | |||
| } | |||
| Env { iter: variables.into_iter(), _dont_send_or_sync_me: PhantomData } | |||
|
|
|||
| fn parse(input: &[u8]) -> Option<(OsString, OsString)> { | |||
| // Strategy (copied from glibc): Variable name and value are separated | |||
| // by an ASCII equals sign '='. Since a variable name must not be | |||
| // empty, allow variable names starting with an equals sign. Skip all | |||
| // malformed lines. | |||
| if input.is_empty() { | |||
| return None; | |||
| } | |||
| let pos = memchr::memchr(b'=', &input[1..]).map(|p| p + 1); | |||
| pos.map(|p| ( | |||
| OsStringExt::from_vec(input[..p].to_vec()), | |||
| OsStringExt::from_vec(input[p+1..].to_vec()), | |||
| )) | |||
| } | |||
| } | |||
|
|
|||
| pub fn getenv(key: &OsStr) -> io::Result<Option<OsString>> { | |||
| if ! key.is_empty() { | |||
| if let Ok(mut file) = ::fs::File::open(&("env:".to_owned() + key.to_str().unwrap())) { | |||
| let mut string = String::new(); | |||
| file.read_to_string(&mut string)?; | |||
| Ok(Some(OsString::from(string))) | |||
| pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { | |||
| // environment variables with a nul byte can't be set, so their value is | |||
| // always None as well | |||
| let k = CString::new(k.as_bytes())?; | |||
| unsafe { | |||
| let _guard = ENV_LOCK.lock(); | |||
| let s = libc::getenv(k.as_ptr()) as *const libc::c_char; | |||
| let ret = if s.is_null() { | |||
| None | |||
| } else { | |||
| Ok(None) | |||
| } | |||
| } else { | |||
| Ok(None) | |||
| Some(OsStringExt::from_vec(CStr::from_ptr(s).to_bytes().to_vec())) | |||
| }; | |||
| Ok(ret) | |||
| } | |||
| } | |||
|
|
|||
| pub fn setenv(key: &OsStr, value: &OsStr) -> io::Result<()> { | |||
| if ! key.is_empty() { | |||
| let mut file = ::fs::File::create(&("env:".to_owned() + key.to_str().unwrap()))?; | |||
| file.write_all(value.as_bytes())?; | |||
| file.set_len(value.len() as u64)?; | |||
| pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { | |||
| extern "C" { | |||
| fn setenv(name: *const c_char, val: *const c_char, | |||
| overwrite: libc::c_int) -> libc::c_int; | |||
| } | |||
|
|
|||
| let k = CString::new(k.as_bytes())?; | |||
| let v = CString::new(v.as_bytes())?; | |||
|
|
|||
| unsafe { | |||
| let _guard = ENV_LOCK.lock(); | |||
| cvt_libc(setenv(k.as_ptr(), v.as_ptr(), 1)).map(|_| ()) | |||
| } | |||
| Ok(()) | |||
| } | |||
|
|
|||
| pub fn unsetenv(key: &OsStr) -> io::Result<()> { | |||
| ::fs::remove_file(&("env:".to_owned() + key.to_str().unwrap()))?; | |||
| Ok(()) | |||
| pub fn unsetenv(n: &OsStr) -> io::Result<()> { | |||
| extern "C" { | |||
| fn unsetenv(name: *const c_char) -> libc::c_int; | |||
| } | |||
|
|
|||
| let nbuf = CString::new(n.as_bytes())?; | |||
|
|
|||
| unsafe { | |||
| let _guard = ENV_LOCK.lock(); | |||
| cvt_libc(unsetenv(nbuf.as_ptr())).map(|_| ()) | |||
| } | |||
| } | |||
|
|
|||
| pub fn page_size() -> usize { | |||
| @@ -23,10 +23,9 @@ pub fn is_verbatim_sep(b: u8) -> bool { | |||
|
|
|||
| pub fn parse_prefix(path: &OsStr) -> Option<Prefix> { | |||
| if let Some(path_str) = path.to_str() { | |||
| if let Some(_i) = path_str.find(':') { | |||
| if let Some(i) = path_str.find(':') { | |||
| // FIXME: Redox specific prefix | |||
| // Some(Prefix::Verbatim(OsStr::new(&path_str[..i]))) | |||
| None | |||
| Some(Prefix::Scheme(OsStr::new(&path_str[..i]))) | |||
| } else { | |||
| None | |||
| } | |||
Oops, something went wrong.