From 341d2d192397de0f999a5b1783068622c0607686 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Dec 2016 19:53:51 -0700 Subject: [PATCH 01/27] Add redox target --- src/librustc_back/target/mod.rs | 3 ++ src/librustc_back/target/redox_base.rs | 45 +++++++++++++++++++ .../target/x86_64_unknown_redox.rs | 30 +++++++++++++ 3 files changed, 78 insertions(+) create mode 100644 src/librustc_back/target/redox_base.rs create mode 100644 src/librustc_back/target/x86_64_unknown_redox.rs diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index 351d469ea2809..4dec2ab7d5460 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -69,6 +69,7 @@ mod windows_base; mod windows_msvc_base; mod thumb_base; mod fuchsia_base; +mod redox_base; pub type TargetResult = Result; @@ -184,6 +185,8 @@ supported_targets! { ("aarch64-unknown-fuchsia", aarch64_unknown_fuchsia), ("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia), + ("x86_64-unknown-redox", x86_64_unknown_redox), + ("i386-apple-ios", i386_apple_ios), ("x86_64-apple-ios", x86_64_apple_ios), ("aarch64-apple-ios", aarch64_apple_ios), diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs new file mode 100644 index 0000000000000..cd962e4c2163f --- /dev/null +++ b/src/librustc_back/target/redox_base.rs @@ -0,0 +1,45 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use target::TargetOptions; +use std::default::Default; + +pub fn opts() -> TargetOptions { + TargetOptions { + pre_link_args: vec![ + // We want to be able to strip as much executable code as possible + // from the linker command line, and this flag indicates to the + // linker that it can avoid linking in dynamic libraries that don't + // actually satisfy any symbols up to that point (as with many other + // resolutions the linker does). This option only applies to all + // following libraries so we're sure to pass it as one of the first + // arguments. + "-Wl,--as-needed".to_string(), + + // Always enable NX protection when it is available + "-Wl,-z,noexecstack".to_string(), + + // Do not link libc + "-nostdlib".to_string(), + + // Static link + "-static".to_string() + ], + executables: true, + relocation_modal: "static".to_string(), + disable_redzone: true, + eliminate_frame_pointer: false, + linker_is_gnu: true, + no_compiler_rt: true, + no_default_libraries: true, + has_elf_tls: true, + .. Default::default() + } +} diff --git a/src/librustc_back/target/x86_64_unknown_redox.rs b/src/librustc_back/target/x86_64_unknown_redox.rs new file mode 100644 index 0000000000000..cecac06b23527 --- /dev/null +++ b/src/librustc_back/target/x86_64_unknown_redox.rs @@ -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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +use target::{Target, TargetResult}; + +pub fn target() -> TargetResult { + let mut base = super::redox_base::opts(); + base.cpu = "x86-64".to_string(); + base.max_atomic_width = Some(64); + base.pre_link_args.push("-m64".to_string()); + + Ok(Target { + llvm_target: "x86_64-unknown-redox".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + data_layout: "e-m:e-i64:64-f80:128-n8:16:32:64-S128".to_string(), + arch: "x86_64".to_string(), + target_os: "redox".to_string(), + target_env: "".to_string(), + target_vendor: "unknown".to_string(), + options: base, + }) +} From c7aa2843b30af8a2344664108babe2e244269f8e Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Dec 2016 20:07:35 -0700 Subject: [PATCH 02/27] Fix typo --- src/librustc_back/target/redox_base.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index cd962e4c2163f..d06d3ae0657e3 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -33,11 +33,10 @@ pub fn opts() -> TargetOptions { "-static".to_string() ], executables: true, - relocation_modal: "static".to_string(), + relocation_model: "static".to_string(), disable_redzone: true, eliminate_frame_pointer: false, linker_is_gnu: true, - no_compiler_rt: true, no_default_libraries: true, has_elf_tls: true, .. Default::default() From a621d1270ba97b16e90723c4e236b679f0222367 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Dec 2016 21:16:42 -0700 Subject: [PATCH 03/27] Fix issue with setting cfg(unix) --- src/librustc_back/target/redox_base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index d06d3ae0657e3..e7445dcc7ea7b 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -36,6 +36,7 @@ pub fn opts() -> TargetOptions { relocation_model: "static".to_string(), disable_redzone: true, eliminate_frame_pointer: false, + target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, has_elf_tls: true, From d2707aa1b9b20dbe9d2385c96249af3be496fc88 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Dec 2016 21:20:45 -0700 Subject: [PATCH 04/27] Use panic abort by default --- src/librustc_back/target/redox_base.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index e7445dcc7ea7b..656eacb3b7065 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -8,6 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +use PanicStrategy; use target::TargetOptions; use std::default::Default; @@ -40,6 +41,7 @@ pub fn opts() -> TargetOptions { linker_is_gnu: true, no_default_libraries: true, has_elf_tls: true, + panic_strategy: PanicStrategy::Abort, .. Default::default() } } From ece703a192495a1ce1239030ca828bd11c50be1a Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Mon, 12 Dec 2016 21:24:41 -0700 Subject: [PATCH 05/27] Add Redox make config --- mk/cfg/x86_64-unknown-redox.mk | 1 + 1 file changed, 1 insertion(+) create mode 100644 mk/cfg/x86_64-unknown-redox.mk diff --git a/mk/cfg/x86_64-unknown-redox.mk b/mk/cfg/x86_64-unknown-redox.mk new file mode 100644 index 0000000000000..34aee77ae2107 --- /dev/null +++ b/mk/cfg/x86_64-unknown-redox.mk @@ -0,0 +1 @@ +# rustbuild-only target From f86e01462781705798adaccbcc3dceb0ecff239b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 13 Dec 2016 18:02:46 -0700 Subject: [PATCH 06/27] Use alloc_system as default allocation crate --- src/librustc_back/target/redox_base.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index 656eacb3b7065..a04ec81e973ba 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -40,6 +40,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, + lib_allocation_crate: "alloc_system".to_string(), + exe_allocation_crate: "alloc_system".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() From 3e7543a16ec6450b8fe0c3d50bc341b5f143cc54 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Dec 2016 08:23:33 -0700 Subject: [PATCH 07/27] WIP: Cross-compilation for Redox target --- src/liballoc_jemalloc/build.rs | 3 +- src/liballoc_system/lib.rs | 45 +++- src/libstd/Cargo.toml | 3 + src/libstd/build.rs | 2 +- src/libstd/lib.rs | 1 + src/libstd/sys/redox/mod.rs | 4 +- src/libstd/sys/redox/net/mod.rs | 3 +- src/libstd/sys/redox/net/netc.rs | 47 ++++ src/libstd/sys/redox/rand.rs | 25 +- src/libstd/sys/redox/start.rs | 43 ++++ src/libstd/sys/redox/syscall/call.rs | 287 ++++++++++++++++++++++ src/libstd/sys/redox/syscall/data.rs | 127 ++++++++++ src/libstd/sys/redox/syscall/error.rs | 315 +++++++++++++++++++++++++ src/libstd/sys/redox/syscall/flag.rs | 84 +++++++ src/libstd/sys/redox/syscall/mod.rs | 33 +++ src/libstd/sys/redox/syscall/number.rs | 63 +++++ src/libstd/sys/redox/syscall/scheme.rs | 232 ++++++++++++++++++ src/libstd/sys/redox/syscall/x86.rs | 72 ++++++ src/libstd/sys/redox/syscall/x86_64.rs | 72 ++++++ src/libtest/lib.rs | 11 + 20 files changed, 1462 insertions(+), 10 deletions(-) create mode 100644 src/libstd/sys/redox/net/netc.rs create mode 100644 src/libstd/sys/redox/start.rs create mode 100644 src/libstd/sys/redox/syscall/call.rs create mode 100644 src/libstd/sys/redox/syscall/data.rs create mode 100644 src/libstd/sys/redox/syscall/error.rs create mode 100644 src/libstd/sys/redox/syscall/flag.rs create mode 100644 src/libstd/sys/redox/syscall/mod.rs create mode 100644 src/libstd/sys/redox/syscall/number.rs create mode 100644 src/libstd/sys/redox/syscall/scheme.rs create mode 100644 src/libstd/sys/redox/syscall/x86.rs create mode 100644 src/libstd/sys/redox/syscall/x86_64.rs diff --git a/src/liballoc_jemalloc/build.rs b/src/liballoc_jemalloc/build.rs index fc849e7a50cc4..e0763276113f2 100644 --- a/src/liballoc_jemalloc/build.rs +++ b/src/liballoc_jemalloc/build.rs @@ -36,7 +36,8 @@ fn main() { // targets, which means we have to build the alloc_jemalloc crate // for targets like emscripten, even if we don't use it. if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") || - target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") { + target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") || + target.contains("redox") { println!("cargo:rustc-cfg=dummy_jemalloc"); return; } diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index a4fabb5a2c96d..487e8e8e6ec39 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -19,6 +19,7 @@ issue = "27783")] #![feature(allocator)] #![feature(staged_api)] +#![cfg_attr(target_os = "redox", feature(libc))] #![cfg_attr(unix, feature(libc))] // The minimum alignment guaranteed by the architecture. This value is used to @@ -71,7 +72,49 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { imp::usable_size(size, align) } -#[cfg(unix)] +#[cfg(target_os = "redox")] +mod imp { + extern crate libc; + + use core::cmp; + use core::ptr; + use MIN_ALIGN; + + pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { + libc::malloc(size as libc::size_t) as *mut u8 + } + + pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { + if align <= MIN_ALIGN { + libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 + } else { + let new_ptr = allocate(size, align); + if !new_ptr.is_null() { + ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); + deallocate(ptr, old_size, align); + } + new_ptr + } + } + + pub unsafe fn reallocate_inplace(_ptr: *mut u8, + old_size: usize, + _size: usize, + _align: usize) + -> usize { + old_size + } + + pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { + libc::free(ptr as *mut libc::c_void) + } + + pub fn usable_size(size: usize, _align: usize) -> usize { + size + } +} + +#[cfg(any(unix))] mod imp { extern crate libc; diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index fcf84cb716917..0384c6666e3bb 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -23,6 +23,9 @@ compiler_builtins = { path = "../libcompiler_builtins" } std_unicode = { path = "../libstd_unicode" } unwind = { path = "../libunwind" } +[replace] +"core:0.0.0" = { path = "../libcore" } + [build-dependencies] build_helper = { path = "../build_helper" } gcc = "0.3.27" diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 1087d1f24471b..535cb7e136ce4 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -26,7 +26,7 @@ fn main() { let target = env::var("TARGET").expect("TARGET was not set"); let host = env::var("HOST").expect("HOST was not set"); if cfg!(feature = "backtrace") && !target.contains("apple") && !target.contains("msvc") && - !target.contains("emscripten") && !target.contains("fuchsia") { + !target.contains("emscripten") && !target.contains("fuchsia") && !target.contains("redox") { build_libbacktrace(&host, &target); } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 414f25fa5eb33..3c9e66a469cd8 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -299,6 +299,7 @@ #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(zero_one)] +#![cfg_attr(target_os = "redox", feature(naked_functions))] #![cfg_attr(test, feature(update_panic_count))] // Explicitly import the prelude. The compiler uses this same unstable attribute diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index 96efa27c0d34b..fce1cb364fa6c 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -10,8 +10,6 @@ #![allow(dead_code, missing_docs, bad_style)] -pub extern crate syscall; - use io::{self, ErrorKind}; pub mod args; @@ -33,7 +31,9 @@ pub mod process; pub mod rand; pub mod rwlock; pub mod stack_overflow; +pub mod start; pub mod stdio; +pub mod syscall; pub mod thread; pub mod thread_local; pub mod time; diff --git a/src/libstd/sys/redox/net/mod.rs b/src/libstd/sys/redox/net/mod.rs index 334c5e51c39b4..3fdf61cfed83c 100644 --- a/src/libstd/sys/redox/net/mod.rs +++ b/src/libstd/sys/redox/net/mod.rs @@ -20,10 +20,11 @@ use vec::{IntoIter, Vec}; use self::dns::{Dns, DnsQuery}; -pub extern crate libc as netc; pub use self::tcp::{TcpStream, TcpListener}; pub use self::udp::UdpSocket; +pub mod netc; + mod dns; mod tcp; mod udp; diff --git a/src/libstd/sys/redox/net/netc.rs b/src/libstd/sys/redox/net/netc.rs new file mode 100644 index 0000000000000..78045c54fb207 --- /dev/null +++ b/src/libstd/sys/redox/net/netc.rs @@ -0,0 +1,47 @@ +pub type in_addr_t = u32; +pub type in_port_t = u16; + +pub type socklen_t = u32; +pub type sa_family_t = u16; + +pub const AF_INET: sa_family_t = 1; +pub const AF_INET6: sa_family_t = 2; + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct in_addr { + pub s_addr: in_addr_t, +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct in6_addr { + pub s6_addr: [u8; 16], + __align: [u32; 0], +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct sockaddr { + pub sa_family: sa_family_t, + pub sa_data: [u8; 14], +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct sockaddr_in { + pub sin_family: sa_family_t, + pub sin_port: in_port_t, + pub sin_addr: in_addr, + pub sin_zero: [u8; 8], +} + +#[derive(Copy, Clone)] +#[repr(C)] +pub struct sockaddr_in6 { + pub sin6_family: sa_family_t, + pub sin6_port: in_port_t, + pub sin6_flowinfo: u32, + pub sin6_addr: in6_addr, + pub sin6_scope_id: u32, +} diff --git a/src/libstd/sys/redox/rand.rs b/src/libstd/sys/redox/rand.rs index d7e4d09a9d636..eb28eca38bcd9 100644 --- a/src/libstd/sys/redox/rand.rs +++ b/src/libstd/sys/redox/rand.rs @@ -9,15 +9,19 @@ // except according to those terms. use io; -use libc; use rand::Rng; -pub struct OsRng; +// FIXME: Use rand: +pub struct OsRng { + state: [u64; 2] +} impl OsRng { /// Create a new `OsRng`. pub fn new() -> io::Result { - Ok(OsRng) + Ok(OsRng { + state: [0xBADF00D1, 0xDEADBEEF] + }) } } @@ -26,7 +30,20 @@ impl Rng for OsRng { self.next_u64() as u32 } fn next_u64(&mut self) -> u64 { - unsafe { libc::random() } + // Store the first and second part. + let mut x = self.state[0]; + let y = self.state[1]; + + // Put the second part into the first slot. + self.state[0] = y; + // Twist the first slot. + x ^= x << 23; + // Update the second slot. + self.state[1] = x ^ y ^ (x >> 17) ^ (y >> 26); + + // Generate the final integer. + self.state[1].wrapping_add(y) + } fn fill_bytes(&mut self, buf: &mut [u8]) { for chunk in buf.chunks_mut(8) { diff --git a/src/libstd/sys/redox/start.rs b/src/libstd/sys/redox/start.rs new file mode 100644 index 0000000000000..b689be1cf4d25 --- /dev/null +++ b/src/libstd/sys/redox/start.rs @@ -0,0 +1,43 @@ +use sys::syscall::exit; + +#[allow(private_no_mangle_fns)] +#[no_mangle] +#[naked] +#[cfg(target_arch = "x86")] +pub unsafe fn _start() { + asm!("push esp + call _start_stack + pop esp" + : + : + : "memory" + : "intel", "volatile"); + let _ = exit(0); +} + +#[allow(private_no_mangle_fns)] +#[no_mangle] +#[naked] +#[cfg(target_arch = "x86_64")] +pub unsafe fn _start() { + asm!("mov rdi, rsp + and rsp, 0xFFFFFFFFFFFFFFF0 + call _start_stack" + : + : + : "memory" + : "intel", "volatile"); + let _ = exit(0); +} + +#[allow(private_no_mangle_fns)] +#[no_mangle] +pub unsafe extern "C" fn _start_stack(stack: *const usize){ + extern "C" { + fn main(argc: usize, argv: *const *const u8) -> usize; + } + + let argc = *stack as usize; + let argv = stack.offset(1) as *const *const u8; + let _ = exit(main(argc, argv)); +} diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs new file mode 100644 index 0000000000000..939ebf510725d --- /dev/null +++ b/src/libstd/sys/redox/syscall/call.rs @@ -0,0 +1,287 @@ +use super::arch::*; +use super::data::{Stat, StatVfs, TimeSpec}; +use super::error::Result; +use super::number::*; + +use core::mem; + +/// Set the end of the process's heap +/// +/// When `addr` is `0`, this function will return the current break. +/// +/// When `addr` is nonzero, this function will attempt to set the end of the process's +/// heap to `addr` and return the new program break. The new program break should be +/// checked by the allocator, it may not be exactly `addr`, as it may be aligned to a page +/// boundary. +/// +/// On error, `Err(ENOMEM)` will be returned indicating that no memory is available +pub unsafe fn brk(addr: usize) -> Result { + syscall1(SYS_BRK, addr) +} + +/// Change the process's working directory +/// +/// This function will attempt to set the process's working directory to `path`, which can be +/// either a relative, scheme relative, or absolute path. +/// +/// On success, `Ok(0)` will be returned. On error, one of the following errors will be returned. +/// +/// # Errors +/// +/// * `EACCES` - permission is denied for one of the components of `path`, or `path` +/// * `EFAULT` - `path` does not point to the process's addressible memory +/// * `EIO` - an I/O error occured +/// * `ENOENT` - `path` does not exit +/// * `ENOTDIR` - `path` is not a directory +pub fn chdir(path: &str) -> Result { + unsafe { syscall2(SYS_CHDIR, path.as_ptr() as usize, path.len()) } +} + +pub fn chmod(path: &str, mode: usize) -> Result { + unsafe { syscall3(SYS_CHMOD, path.as_ptr() as usize, path.len(), mode) } +} + +/// Produce a fork of the current process, or a new process thread +pub unsafe fn clone(flags: usize) -> Result { + syscall1_clobber(SYS_CLONE, flags) +} + +/// Close a file +pub fn close(fd: usize) -> Result { + unsafe { syscall1(SYS_CLOSE, fd) } +} + +/// Get the current system time +pub fn clock_gettime(clock: usize, tp: &mut TimeSpec) -> Result { + unsafe { syscall2(SYS_CLOCK_GETTIME, clock, tp as *mut TimeSpec as usize) } +} + +/// Copy and transform a file descriptor +pub fn dup(fd: usize, buf: &[u8]) -> Result { + unsafe { syscall3(SYS_DUP, fd, buf.as_ptr() as usize, buf.len()) } +} + +/// Replace the current process with a new executable +pub fn execve(path: &str, args: &[[usize; 2]]) -> Result { + unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(), args.as_ptr() as usize, args.len()) } +} + +/// Exit the current process +pub fn exit(status: usize) -> Result { + unsafe { syscall1(SYS_EXIT, status) } +} + +/// Register a file for event-based I/O +pub fn fcntl(fd: usize, cmd: usize, arg: usize) -> Result { + unsafe { syscall3(SYS_FCNTL, fd, cmd, arg) } +} + +/// Register a file for event-based I/O +pub fn fevent(fd: usize, flags: usize) -> Result { + unsafe { syscall2(SYS_FEVENT, fd, flags) } +} + +/// Map a file into memory +pub unsafe fn fmap(fd: usize, offset: usize, size: usize) -> Result { + syscall3(SYS_FMAP, fd, offset, size) +} + +/// Unmap a memory-mapped file +pub unsafe fn funmap(addr: usize) -> Result { + syscall1(SYS_FUNMAP, addr) +} + +/// Retrieve the canonical path of a file +pub fn fpath(fd: usize, buf: &mut [u8]) -> Result { + unsafe { syscall3(SYS_FPATH, fd, buf.as_mut_ptr() as usize, buf.len()) } +} + +/// Get metadata about a file +pub fn fstat(fd: usize, stat: &mut Stat) -> Result { + unsafe { syscall3(SYS_FSTAT, fd, stat as *mut Stat as usize, mem::size_of::()) } +} + +/// Get metadata about a filesystem +pub fn fstatvfs(fd: usize, stat: &mut StatVfs) -> Result { + unsafe { syscall3(SYS_FSTATVFS, fd, stat as *mut StatVfs as usize, mem::size_of::()) } +} + +/// Sync a file descriptor to its underlying medium +pub fn fsync(fd: usize) -> Result { + unsafe { syscall1(SYS_FSYNC, fd) } +} + +/// Truncate or extend a file to a specified length +pub fn ftruncate(fd: usize, len: usize) -> Result { + unsafe { syscall2(SYS_FTRUNCATE, fd, len) } +} + +/// Fast userspace mutex - TODO: Document +pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result { + syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize) +} + +/// Get the current working directory +pub fn getcwd(buf: &mut [u8]) -> Result { + unsafe { syscall2(SYS_GETCWD, buf.as_mut_ptr() as usize, buf.len()) } +} + +/// Get the effective group ID +pub fn getegid() -> Result { + unsafe { syscall0(SYS_GETEGID) } +} + +/// Get the effective namespace +pub fn getens() -> Result { + unsafe { syscall0(SYS_GETENS) } +} + +/// Get the effective user ID +pub fn geteuid() -> Result { + unsafe { syscall0(SYS_GETEUID) } +} + +/// Get the current group ID +pub fn getgid() -> Result { + unsafe { syscall0(SYS_GETGID) } +} + +/// Get the current namespace +pub fn getns() -> Result { + unsafe { syscall0(SYS_GETNS) } +} + +/// Get the current process ID +pub fn getpid() -> Result { + unsafe { syscall0(SYS_GETPID) } +} + +/// Get the current user ID +pub fn getuid() -> Result { + unsafe { syscall0(SYS_GETUID) } +} + +/// Set the I/O privilege level +pub unsafe fn iopl(level: usize) -> Result { + syscall1(SYS_IOPL, level) +} + +/// Send a signal `sig` to the process identified by `pid` +pub fn kill(pid: usize, sig: usize) -> Result { + unsafe { syscall2(SYS_KILL, pid, sig) } +} + +/// Create a link to a file +pub unsafe fn link(old: *const u8, new: *const u8) -> Result { + syscall2(SYS_LINK, old as usize, new as usize) +} + +/// Seek to `offset` bytes in a file descriptor +pub fn lseek(fd: usize, offset: isize, whence: usize) -> Result { + unsafe { syscall3(SYS_LSEEK, fd, offset as usize, whence) } +} + +/// Make a new scheme namespace +pub fn mkns(schemes: &[[usize; 2]]) -> Result { + unsafe { syscall2(SYS_MKNS, schemes.as_ptr() as usize, schemes.len()) } +} + +/// Sleep for the time specified in `req` +pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { + unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, rem as *mut TimeSpec as usize) } +} + +/// Open a file +pub fn open(path: &str, flags: usize) -> Result { + unsafe { syscall3(SYS_OPEN, path.as_ptr() as usize, path.len(), flags) } +} + +/// Allocate pages, linearly in physical memory +pub unsafe fn physalloc(size: usize) -> Result { + syscall1(SYS_PHYSALLOC, size) +} + +/// Free physically allocated pages +pub unsafe fn physfree(physical_address: usize, size: usize) -> Result { + syscall2(SYS_PHYSFREE, physical_address, size) +} + +/// Map physical memory to virtual memory +pub unsafe fn physmap(physical_address: usize, size: usize, flags: usize) -> Result { + syscall3(SYS_PHYSMAP, physical_address, size, flags) +} + +/// Unmap previously mapped physical memory +pub unsafe fn physunmap(virtual_address: usize) -> Result { + syscall1(SYS_PHYSUNMAP, virtual_address) +} + +/// Create a pair of file descriptors referencing the read and write ends of a pipe +pub fn pipe2(fds: &mut [usize; 2], flags: usize) -> Result { + unsafe { syscall2(SYS_PIPE2, fds.as_ptr() as usize, flags) } +} + +/// Read from a file descriptor into a buffer +pub fn read(fd: usize, buf: &mut [u8]) -> Result { + unsafe { syscall3(SYS_READ, fd, buf.as_mut_ptr() as usize, buf.len()) } +} + +/// Remove a directory +pub fn rmdir(path: &str) -> Result { + unsafe { syscall2(SYS_RMDIR, path.as_ptr() as usize, path.len()) } +} + +/// Set the current process group IDs +pub fn setregid(rgid: usize, egid: usize) -> Result { + unsafe { syscall2(SYS_SETREGID, rgid, egid) } +} + +/// Make a new scheme namespace +pub fn setrens(rns: usize, ens: usize) -> Result { + unsafe { syscall2(SYS_SETRENS, rns, ens) } +} + +/// Set the current process user IDs +pub fn setreuid(ruid: usize, euid: usize) -> Result { + unsafe { syscall2(SYS_SETREUID, ruid, euid) } +} + +/// Remove a file +pub fn unlink(path: &str) -> Result { + unsafe { syscall2(SYS_UNLINK, path.as_ptr() as usize, path.len()) } +} + +/// Convert a virtual address to a physical one +pub unsafe fn virttophys(virtual_address: usize) -> Result { + syscall1(SYS_VIRTTOPHYS, virtual_address) +} + +/// Check if a child process has exited or received a signal +pub fn waitpid(pid: usize, status: &mut usize, options: usize) -> Result { + unsafe { syscall3(SYS_WAITPID, pid, status as *mut usize as usize, options) } +} + +/// Write a buffer to a file descriptor +/// +/// The kernel will attempt to write the bytes in `buf` to the file descriptor `fd`, returning +/// either an `Err`, explained below, or `Ok(count)` where `count` is the number of bytes which +/// were written. +/// +/// # Errors +/// +/// * `EAGAIN` - the file descriptor was opened with `O_NONBLOCK` and writing would block +/// * `EBADF` - the file descriptor is not valid or is not open for writing +/// * `EFAULT` - `buf` does not point to the process's addressible memory +/// * `EIO` - an I/O error occured +/// * `ENOSPC` - the device containing the file descriptor has no room for data +/// * `EPIPE` - the file descriptor refers to a pipe or socket whose reading end is closed +pub fn write(fd: usize, buf: &[u8]) -> Result { + unsafe { syscall3(SYS_WRITE, fd, buf.as_ptr() as usize, buf.len()) } +} + +/// Yield the process's time slice to the kernel +/// +/// This function will return Ok(0) on success +pub fn sched_yield() -> Result { + unsafe { syscall0(SYS_YIELD) } +} diff --git a/src/libstd/sys/redox/syscall/data.rs b/src/libstd/sys/redox/syscall/data.rs new file mode 100644 index 0000000000000..240690befde1d --- /dev/null +++ b/src/libstd/sys/redox/syscall/data.rs @@ -0,0 +1,127 @@ +use core::ops::{Deref, DerefMut}; +use core::{mem, slice}; + +#[derive(Copy, Clone, Debug, Default)] +pub struct Event { + pub id: usize, + pub flags: usize, + pub data: usize +} + +impl Deref for Event { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::()) as &[u8] + } + } +} + +impl DerefMut for Event { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::()) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +pub struct Packet { + pub id: u64, + pub pid: usize, + pub uid: u32, + pub gid: u32, + pub a: usize, + pub b: usize, + pub c: usize, + pub d: usize +} + +impl Deref for Packet { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::()) as &[u8] + } + } +} + +impl DerefMut for Packet { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::()) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +pub struct Stat { + pub st_dev: u64, + pub st_ino: u64, + pub st_mode: u16, + pub st_nlink: u32, + pub st_uid: u32, + pub st_gid: u32, + pub st_size: u64, + pub st_blksize: u32, + pub st_blocks: u64, + pub st_mtime: u64, + pub st_mtime_nsec: u32, + pub st_atime: u64, + pub st_atime_nsec: u32, + pub st_ctime: u64, + pub st_ctime_nsec: u32, +} + +impl Deref for Stat { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const Stat as *const u8, mem::size_of::()) as &[u8] + } + } +} + +impl DerefMut for Stat { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut Stat as *mut u8, mem::size_of::()) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +pub struct StatVfs { + pub f_bsize: u32, + pub f_blocks: u64, + pub f_bfree: u64, + pub f_bavail: u64, + //TODO: More fields https://linux.die.net/man/2/statvfs +} + +impl Deref for StatVfs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::()) as &[u8] + } + } +} + +impl DerefMut for StatVfs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::()) as &mut [u8] + } + } +} + +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +pub struct TimeSpec { + pub tv_sec: i64, + pub tv_nsec: i32, +} diff --git a/src/libstd/sys/redox/syscall/error.rs b/src/libstd/sys/redox/syscall/error.rs new file mode 100644 index 0000000000000..7cbcbe98765ed --- /dev/null +++ b/src/libstd/sys/redox/syscall/error.rs @@ -0,0 +1,315 @@ +use core::{fmt, result}; + +#[derive(Eq, PartialEq)] +pub struct Error { + pub errno: i32, +} + +pub type Result = result::Result; + +impl Error { + pub fn new(errno: i32) -> Error { + Error { errno: errno } + } + + pub fn mux(result: Result) -> usize { + match result { + Ok(value) => value, + Err(error) => -error.errno as usize, + } + } + + pub fn demux(value: usize) -> Result { + let errno = -(value as i32); + if errno >= 1 && errno < STR_ERROR.len() as i32 { + Err(Error::new(errno)) + } else { + Ok(value) + } + } + + pub fn text(&self) -> &str { + if let Some(description) = STR_ERROR.get(self.errno as usize) { + description + } else { + "Unknown Error" + } + } +} + +impl fmt::Debug for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.write_str(self.text()) + } +} + +impl fmt::Display for Error { + fn fmt(&self, f: &mut fmt::Formatter) -> result::Result<(), fmt::Error> { + f.write_str(self.text()) + } +} + +pub const EPERM: i32 = 1; /* Operation not permitted */ +pub const ENOENT: i32 = 2; /* No such file or directory */ +pub const ESRCH: i32 = 3; /* No such process */ +pub const EINTR: i32 = 4; /* Interrupted system call */ +pub const EIO: i32 = 5; /* I/O error */ +pub const ENXIO: i32 = 6; /* No such device or address */ +pub const E2BIG: i32 = 7; /* Argument list too long */ +pub const ENOEXEC: i32 = 8; /* Exec format error */ +pub const EBADF: i32 = 9; /* Bad file number */ +pub const ECHILD: i32 = 10; /* No child processes */ +pub const EAGAIN: i32 = 11; /* Try again */ +pub const ENOMEM: i32 = 12; /* Out of memory */ +pub const EACCES: i32 = 13; /* Permission denied */ +pub const EFAULT: i32 = 14; /* Bad address */ +pub const ENOTBLK: i32 = 15; /* Block device required */ +pub const EBUSY: i32 = 16; /* Device or resource busy */ +pub const EEXIST: i32 = 17; /* File exists */ +pub const EXDEV: i32 = 18; /* Cross-device link */ +pub const ENODEV: i32 = 19; /* No such device */ +pub const ENOTDIR: i32 = 20; /* Not a directory */ +pub const EISDIR: i32 = 21; /* Is a directory */ +pub const EINVAL: i32 = 22; /* Invalid argument */ +pub const ENFILE: i32 = 23; /* File table overflow */ +pub const EMFILE: i32 = 24; /* Too many open files */ +pub const ENOTTY: i32 = 25; /* Not a typewriter */ +pub const ETXTBSY: i32 = 26; /* Text file busy */ +pub const EFBIG: i32 = 27; /* File too large */ +pub const ENOSPC: i32 = 28; /* No space left on device */ +pub const ESPIPE: i32 = 29; /* Illegal seek */ +pub const EROFS: i32 = 30; /* Read-only file system */ +pub const EMLINK: i32 = 31; /* Too many links */ +pub const EPIPE: i32 = 32; /* Broken pipe */ +pub const EDOM: i32 = 33; /* Math argument out of domain of func */ +pub const ERANGE: i32 = 34; /* Math result not representable */ +pub const EDEADLK: i32 = 35; /* Resource deadlock would occur */ +pub const ENAMETOOLONG: i32 = 36; /* File name too long */ +pub const ENOLCK: i32 = 37; /* No record locks available */ +pub const ENOSYS: i32 = 38; /* Function not implemented */ +pub const ENOTEMPTY: i32 = 39; /* Directory not empty */ +pub const ELOOP: i32 = 40; /* Too many symbolic links encountered */ +pub const EWOULDBLOCK: i32 = 41; /* Operation would block */ +pub const ENOMSG: i32 = 42; /* No message of desired type */ +pub const EIDRM: i32 = 43; /* Identifier removed */ +pub const ECHRNG: i32 = 44; /* Channel number out of range */ +pub const EL2NSYNC: i32 = 45; /* Level 2 not synchronized */ +pub const EL3HLT: i32 = 46; /* Level 3 halted */ +pub const EL3RST: i32 = 47; /* Level 3 reset */ +pub const ELNRNG: i32 = 48; /* Link number out of range */ +pub const EUNATCH: i32 = 49; /* Protocol driver not attached */ +pub const ENOCSI: i32 = 50; /* No CSI structure available */ +pub const EL2HLT: i32 = 51; /* Level 2 halted */ +pub const EBADE: i32 = 52; /* Invalid exchange */ +pub const EBADR: i32 = 53; /* Invalid request descriptor */ +pub const EXFULL: i32 = 54; /* Exchange full */ +pub const ENOANO: i32 = 55; /* No anode */ +pub const EBADRQC: i32 = 56; /* Invalid request code */ +pub const EBADSLT: i32 = 57; /* Invalid slot */ +pub const EDEADLOCK: i32 = 58; /* Resource deadlock would occur */ +pub const EBFONT: i32 = 59; /* Bad font file format */ +pub const ENOSTR: i32 = 60; /* Device not a stream */ +pub const ENODATA: i32 = 61; /* No data available */ +pub const ETIME: i32 = 62; /* Timer expired */ +pub const ENOSR: i32 = 63; /* Out of streams resources */ +pub const ENONET: i32 = 64; /* Machine is not on the network */ +pub const ENOPKG: i32 = 65; /* Package not installed */ +pub const EREMOTE: i32 = 66; /* Object is remote */ +pub const ENOLINK: i32 = 67; /* Link has been severed */ +pub const EADV: i32 = 68; /* Advertise error */ +pub const ESRMNT: i32 = 69; /* Srmount error */ +pub const ECOMM: i32 = 70; /* Communication error on send */ +pub const EPROTO: i32 = 71; /* Protocol error */ +pub const EMULTIHOP: i32 = 72; /* Multihop attempted */ +pub const EDOTDOT: i32 = 73; /* RFS specific error */ +pub const EBADMSG: i32 = 74; /* Not a data message */ +pub const EOVERFLOW: i32 = 75; /* Value too large for defined data type */ +pub const ENOTUNIQ: i32 = 76; /* Name not unique on network */ +pub const EBADFD: i32 = 77; /* File descriptor in bad state */ +pub const EREMCHG: i32 = 78; /* Remote address changed */ +pub const ELIBACC: i32 = 79; /* Can not access a needed shared library */ +pub const ELIBBAD: i32 = 80; /* Accessing a corrupted shared library */ +pub const ELIBSCN: i32 = 81; /* .lib section in a.out corrupted */ +pub const ELIBMAX: i32 = 82; /* Attempting to link in too many shared libraries */ +pub const ELIBEXEC: i32 = 83; /* Cannot exec a shared library directly */ +pub const EILSEQ: i32 = 84; /* Illegal byte sequence */ +pub const ERESTART: i32 = 85; /* Interrupted system call should be restarted */ +pub const ESTRPIPE: i32 = 86; /* Streams pipe error */ +pub const EUSERS: i32 = 87; /* Too many users */ +pub const ENOTSOCK: i32 = 88; /* Socket operation on non-socket */ +pub const EDESTADDRREQ: i32 = 89; /* Destination address required */ +pub const EMSGSIZE: i32 = 90; /* Message too long */ +pub const EPROTOTYPE: i32 = 91; /* Protocol wrong type for socket */ +pub const ENOPROTOOPT: i32 = 92; /* Protocol not available */ +pub const EPROTONOSUPPORT: i32 = 93; /* Protocol not supported */ +pub const ESOCKTNOSUPPORT: i32 = 94; /* Socket type not supported */ +pub const EOPNOTSUPP: i32 = 95; /* Operation not supported on transport endpoint */ +pub const EPFNOSUPPORT: i32 = 96; /* Protocol family not supported */ +pub const EAFNOSUPPORT: i32 = 97; /* Address family not supported by protocol */ +pub const EADDRINUSE: i32 = 98; /* Address already in use */ +pub const EADDRNOTAVAIL: i32 = 99; /* Cannot assign requested address */ +pub const ENETDOWN: i32 = 100; /* Network is down */ +pub const ENETUNREACH: i32 = 101; /* Network is unreachable */ +pub const ENETRESET: i32 = 102; /* Network dropped connection because of reset */ +pub const ECONNABORTED: i32 = 103; /* Software caused connection abort */ +pub const ECONNRESET: i32 = 104; /* Connection reset by peer */ +pub const ENOBUFS: i32 = 105; /* No buffer space available */ +pub const EISCONN: i32 = 106; /* Transport endpoint is already connected */ +pub const ENOTCONN: i32 = 107; /* Transport endpoint is not connected */ +pub const ESHUTDOWN: i32 = 108; /* Cannot send after transport endpoint shutdown */ +pub const ETOOMANYREFS: i32 = 109; /* Too many references: cannot splice */ +pub const ETIMEDOUT: i32 = 110; /* Connection timed out */ +pub const ECONNREFUSED: i32 = 111; /* Connection refused */ +pub const EHOSTDOWN: i32 = 112; /* Host is down */ +pub const EHOSTUNREACH: i32 = 113; /* No route to host */ +pub const EALREADY: i32 = 114; /* Operation already in progress */ +pub const EINPROGRESS: i32 = 115; /* Operation now in progress */ +pub const ESTALE: i32 = 116; /* Stale NFS file handle */ +pub const EUCLEAN: i32 = 117; /* Structure needs cleaning */ +pub const ENOTNAM: i32 = 118; /* Not a XENIX named type file */ +pub const ENAVAIL: i32 = 119; /* No XENIX semaphores available */ +pub const EISNAM: i32 = 120; /* Is a named type file */ +pub const EREMOTEIO: i32 = 121; /* Remote I/O error */ +pub const EDQUOT: i32 = 122; /* Quota exceeded */ +pub const ENOMEDIUM: i32 = 123; /* No medium found */ +pub const EMEDIUMTYPE: i32 = 124; /* Wrong medium type */ +pub const ECANCELED: i32 = 125; /* Operation Canceled */ +pub const ENOKEY: i32 = 126; /* Required key not available */ +pub const EKEYEXPIRED: i32 = 127; /* Key has expired */ +pub const EKEYREVOKED: i32 = 128; /* Key has been revoked */ +pub const EKEYREJECTED: i32 = 129; /* Key was rejected by service */ +pub const EOWNERDEAD: i32 = 130; /* Owner died */ +pub const ENOTRECOVERABLE: i32 = 131; /* State not recoverable */ + +pub static STR_ERROR: [&'static str; 132] = ["Success", + "Operation not permitted", + "No such file or directory", + "No such process", + "Interrupted system call", + "I/O error", + "No such device or address", + "Argument list too long", + "Exec format error", + "Bad file number", + "No child processes", + "Try again", + "Out of memory", + "Permission denied", + "Bad address", + "Block device required", + "Device or resource busy", + "File exists", + "Cross-device link", + "No such device", + "Not a directory", + "Is a directory", + "Invalid argument", + "File table overflow", + "Too many open files", + "Not a typewriter", + "Text file busy", + "File too large", + "No space left on device", + "Illegal seek", + "Read-only file system", + "Too many links", + "Broken pipe", + "Math argument out of domain of func", + "Math result not representable", + "Resource deadlock would occur", + "File name too long", + "No record locks available", + "Function not implemented", + "Directory not empty", + "Too many symbolic links encountered", + "Operation would block", + "No message of desired type", + "Identifier removed", + "Channel number out of range", + "Level 2 not synchronized", + "Level 3 halted", + "Level 3 reset", + "Link number out of range", + "Protocol driver not attached", + "No CSI structure available", + "Level 2 halted", + "Invalid exchange", + "Invalid request descriptor", + "Exchange full", + "No anode", + "Invalid request code", + "Invalid slot", + "Resource deadlock would occur", + "Bad font file format", + "Device not a stream", + "No data available", + "Timer expired", + "Out of streams resources", + "Machine is not on the network", + "Package not installed", + "Object is remote", + "Link has been severed", + "Advertise error", + "Srmount error", + "Communication error on send", + "Protocol error", + "Multihop attempted", + "RFS specific error", + "Not a data message", + "Value too large for defined data type", + "Name not unique on network", + "File descriptor in bad state", + "Remote address changed", + "Can not access a needed shared library", + "Accessing a corrupted shared library", + ".lib section in a.out corrupted", + "Attempting to link in too many shared libraries", + "Cannot exec a shared library directly", + "Illegal byte sequence", + "Interrupted system call should be restarted", + "Streams pipe error", + "Too many users", + "Socket operation on non-socket", + "Destination address required", + "Message too long", + "Protocol wrong type for socket", + "Protocol not available", + "Protocol not supported", + "Socket type not supported", + "Operation not supported on transport endpoint", + "Protocol family not supported", + "Address family not supported by protocol", + "Address already in use", + "Cannot assign requested address", + "Network is down", + "Network is unreachable", + "Network dropped connection because of reset", + "Software caused connection abort", + "Connection reset by peer", + "No buffer space available", + "Transport endpoint is already connected", + "Transport endpoint is not connected", + "Cannot send after transport endpoint shutdown", + "Too many references: cannot splice", + "Connection timed out", + "Connection refused", + "Host is down", + "No route to host", + "Operation already in progress", + "Operation now in progress", + "Stale NFS file handle", + "Structure needs cleaning", + "Not a XENIX named type file", + "No XENIX semaphores available", + "Is a named type file", + "Remote I/O error", + "Quota exceeded", + "No medium found", + "Wrong medium type", + "Operation Canceled", + "Required key not available", + "Key has expired", + "Key has been revoked", + "Key was rejected by service", + "Owner died", + "State not recoverable"]; diff --git a/src/libstd/sys/redox/syscall/flag.rs b/src/libstd/sys/redox/syscall/flag.rs new file mode 100644 index 0000000000000..97ff8e2d79ae7 --- /dev/null +++ b/src/libstd/sys/redox/syscall/flag.rs @@ -0,0 +1,84 @@ +pub const CLONE_VM: usize = 0x100; +pub const CLONE_FS: usize = 0x200; +pub const CLONE_FILES: usize = 0x400; +pub const CLONE_VFORK: usize = 0x4000; + +pub const CLOCK_REALTIME: usize = 1; +pub const CLOCK_MONOTONIC: usize = 4; + +pub const EVENT_NONE: usize = 0; +pub const EVENT_READ: usize = 1; +pub const EVENT_WRITE: usize = 2; + +pub const F_GETFL: usize = 1; +pub const F_SETFL: usize = 2; + +pub const FUTEX_WAIT: usize = 0; +pub const FUTEX_WAKE: usize = 1; +pub const FUTEX_REQUEUE: usize = 2; + +pub const MAP_WRITE: usize = 1; +pub const MAP_WRITE_COMBINE: usize = 2; + +pub const MODE_TYPE: u16 = 0xF000; +pub const MODE_DIR: u16 = 0x4000; +pub const MODE_FILE: u16 = 0x8000; + +pub const MODE_PERM: u16 = 0x0FFF; +pub const MODE_SETUID: u16 = 0o4000; +pub const MODE_SETGID: u16 = 0o2000; + +pub const O_RDONLY: usize = 0x0001_0000; +pub const O_WRONLY: usize = 0x0002_0000; +pub const O_RDWR: usize = 0x0003_0000; +pub const O_NONBLOCK: usize = 0x0004_0000; +pub const O_APPEND: usize = 0x0008_0000; +pub const O_SHLOCK: usize = 0x0010_0000; +pub const O_EXLOCK: usize = 0x0020_0000; +pub const O_ASYNC: usize = 0x0040_0000; +pub const O_FSYNC: usize = 0x0080_0000; +pub const O_CLOEXEC: usize = 0x0100_0000; +pub const O_CREAT: usize = 0x0200_0000; +pub const O_TRUNC: usize = 0x0400_0000; +pub const O_EXCL: usize = 0x0800_0000; +pub const O_DIRECTORY: usize = 0x1000_0000; +pub const O_STAT: usize = 0x2000_0000; +pub const O_ACCMODE: usize = O_RDONLY | O_WRONLY | O_RDWR; + +pub const SEEK_SET: usize = 0; +pub const SEEK_CUR: usize = 1; +pub const SEEK_END: usize = 2; + +pub const SIGHUP: usize = 1; +pub const SIGINT: usize = 2; +pub const SIGQUIT: usize = 3; +pub const SIGILL: usize = 4; +pub const SIGTRAP: usize = 5; +pub const SIGABRT: usize = 6; +pub const SIGBUS: usize = 7; +pub const SIGFPE: usize = 8; +pub const SIGKILL: usize = 9; +pub const SIGUSR1: usize = 10; +pub const SIGSEGV: usize = 11; +pub const SIGUSR2: usize = 12; +pub const SIGPIPE: usize = 13; +pub const SIGALRM: usize = 14; +pub const SIGTERM: usize = 15; +pub const SIGSTKFLT: usize= 16; +pub const SIGCHLD: usize = 17; +pub const SIGCONT: usize = 18; +pub const SIGSTOP: usize = 19; +pub const SIGTSTP: usize = 20; +pub const SIGTTIN: usize = 21; +pub const SIGTTOU: usize = 22; +pub const SIGURG: usize = 23; +pub const SIGXCPU: usize = 24; +pub const SIGXFSZ: usize = 25; +pub const SIGVTALRM: usize= 26; +pub const SIGPROF: usize = 27; +pub const SIGWINCH: usize = 28; +pub const SIGIO: usize = 29; +pub const SIGPWR: usize = 30; +pub const SIGSYS: usize = 31; + +pub const WNOHANG: usize = 1; diff --git a/src/libstd/sys/redox/syscall/mod.rs b/src/libstd/sys/redox/syscall/mod.rs new file mode 100644 index 0000000000000..77f98d5b36bf4 --- /dev/null +++ b/src/libstd/sys/redox/syscall/mod.rs @@ -0,0 +1,33 @@ +pub use self::arch::*; +pub use self::call::*; +pub use self::data::*; +pub use self::error::*; +pub use self::flag::*; +pub use self::number::*; +pub use self::scheme::*; + +#[cfg(target_arch = "x86")] +#[path="x86.rs"] +mod arch; + +#[cfg(target_arch = "x86_64")] +#[path="x86_64.rs"] +mod arch; + +/// Function definitions +pub mod call; + +/// Complex structures that are used for some system calls +pub mod data; + +/// All errors that can be generated by a system call +pub mod error; + +/// Flags used as an argument to many system calls +pub mod flag; + +/// Call numbers used by each system call +pub mod number; + +/// A trait useful for scheme handlers +pub mod scheme; diff --git a/src/libstd/sys/redox/syscall/number.rs b/src/libstd/sys/redox/syscall/number.rs new file mode 100644 index 0000000000000..719c8af218fd8 --- /dev/null +++ b/src/libstd/sys/redox/syscall/number.rs @@ -0,0 +1,63 @@ +pub const SYS_CLASS: usize = 0xF000_0000; +pub const SYS_CLASS_PATH: usize=0x1000_0000; +pub const SYS_CLASS_FILE: usize=0x2000_0000; + +pub const SYS_ARG: usize = 0x0F00_0000; +pub const SYS_ARG_SLICE: usize =0x0100_0000; +pub const SYS_ARG_MSLICE: usize=0x0200_0000; +pub const SYS_ARG_PATH: usize = 0x0300_0000; + +pub const SYS_RET: usize = 0x00F0_0000; +pub const SYS_RET_FILE: usize = 0x0010_0000; + +pub const SYS_LINK: usize = SYS_CLASS_PATH | SYS_ARG_PATH | 9; +pub const SYS_OPEN: usize = SYS_CLASS_PATH | SYS_RET_FILE | 5; +pub const SYS_CHMOD: usize = SYS_CLASS_PATH | 15; +pub const SYS_RMDIR: usize = SYS_CLASS_PATH | 84; +pub const SYS_UNLINK: usize = SYS_CLASS_PATH | 10; + +pub const SYS_CLOSE: usize = SYS_CLASS_FILE | 6; +pub const SYS_DUP: usize = SYS_CLASS_FILE | SYS_RET_FILE | 41; +pub const SYS_READ: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 3; +pub const SYS_WRITE: usize = SYS_CLASS_FILE | SYS_ARG_SLICE | 4; +pub const SYS_LSEEK: usize = SYS_CLASS_FILE | 19; +pub const SYS_FCNTL: usize = SYS_CLASS_FILE | 55; +pub const SYS_FEVENT: usize = SYS_CLASS_FILE | 927; +pub const SYS_FMAP: usize = SYS_CLASS_FILE | 90; +pub const SYS_FUNMAP: usize = SYS_CLASS_FILE | 91; +pub const SYS_FPATH: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 928; +pub const SYS_FSTAT: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 28; +pub const SYS_FSTATVFS: usize = SYS_CLASS_FILE | SYS_ARG_MSLICE | 100; +pub const SYS_FSYNC: usize = SYS_CLASS_FILE | 118; +pub const SYS_FTRUNCATE: usize =SYS_CLASS_FILE | 93; + +pub const SYS_BRK: usize = 45; +pub const SYS_CHDIR: usize = 12; +pub const SYS_CLOCK_GETTIME: usize = 265; +pub const SYS_CLONE: usize = 120; +pub const SYS_EXECVE: usize = 11; +pub const SYS_EXIT: usize = 1; +pub const SYS_FUTEX: usize = 240; +pub const SYS_GETCWD: usize = 183; +pub const SYS_GETEGID: usize = 202; +pub const SYS_GETENS: usize = 951; +pub const SYS_GETEUID: usize = 201; +pub const SYS_GETGID: usize = 200; +pub const SYS_GETNS: usize = 950; +pub const SYS_GETPID: usize = 20; +pub const SYS_GETUID: usize = 199; +pub const SYS_IOPL: usize = 110; +pub const SYS_KILL: usize = 37; +pub const SYS_MKNS: usize = 984; +pub const SYS_NANOSLEEP: usize =162; +pub const SYS_PHYSALLOC: usize =945; +pub const SYS_PHYSFREE: usize = 946; +pub const SYS_PHYSMAP: usize = 947; +pub const SYS_PHYSUNMAP: usize =948; +pub const SYS_VIRTTOPHYS: usize=949; +pub const SYS_PIPE2: usize = 331; +pub const SYS_SETREGID: usize = 204; +pub const SYS_SETRENS: usize = 952; +pub const SYS_SETREUID: usize = 203; +pub const SYS_WAITPID: usize = 7; +pub const SYS_YIELD: usize = 158; diff --git a/src/libstd/sys/redox/syscall/scheme.rs b/src/libstd/sys/redox/syscall/scheme.rs new file mode 100644 index 0000000000000..d322f0b5a9c8c --- /dev/null +++ b/src/libstd/sys/redox/syscall/scheme.rs @@ -0,0 +1,232 @@ +use core::{mem, slice}; + +use super::*; + +pub trait Scheme { + fn handle(&self, packet: &mut Packet) { + packet.a = Error::mux(match packet.a { + SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid), + SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid), + SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), + SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), + + SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), + SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), + SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), + SYS_LSEEK => self.seek(packet.b, packet.c, packet.d), + SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), + SYS_FEVENT => self.fevent(packet.b, packet.c), + SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), + SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), + SYS_FSTAT => if packet.d >= mem::size_of::() { self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) } else { Err(Error::new(EFAULT)) }, + SYS_FSTATVFS => if packet.d >= mem::size_of::() { self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) } else { Err(Error::new(EFAULT)) }, + SYS_FSYNC => self.fsync(packet.b), + SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), + SYS_CLOSE => self.close(packet.b), + + _ => Err(Error::new(ENOSYS)) + }); + } + + /* Scheme operations */ + + #[allow(unused_variables)] + fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + /* Resource operations */ + #[allow(unused_variables)] + fn dup(&self, old_id: usize, buf: &[u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn read(&self, id: usize, buf: &mut [u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn write(&self, id: usize, buf: &[u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn seek(&self, id: usize, pos: usize, whence: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fevent(&self, id: usize, flags: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fmap(&self, id: usize, offset: usize, size: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fpath(&self, id: usize, buf: &mut [u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fstat(&self, id: usize, stat: &mut Stat) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fsync(&self, id: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn ftruncate(&self, id: usize, len: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn close(&self, id: usize) -> Result { + Err(Error::new(EBADF)) + } +} + +pub trait SchemeMut { + fn handle(&mut self, packet: &mut Packet) { + packet.a = Error::mux(match packet.a { + SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid), + SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid), + SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), + SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), + + SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), + SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), + SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), + SYS_LSEEK => self.seek(packet.b, packet.c, packet.d), + SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), + SYS_FEVENT => self.fevent(packet.b, packet.c), + SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), + SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), + SYS_FSTAT => if packet.d >= mem::size_of::() { self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) } else { Err(Error::new(EFAULT)) }, + SYS_FSTATVFS => if packet.d >= mem::size_of::() { self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) } else { Err(Error::new(EFAULT)) }, + SYS_FSYNC => self.fsync(packet.b), + SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), + SYS_CLOSE => self.close(packet.b), + + _ => Err(Error::new(ENOSYS)) + }); + } + + /* Scheme operations */ + #[allow(unused_variables)] + fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + #[allow(unused_variables)] + fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result { + Err(Error::new(ENOENT)) + } + + /* Resource operations */ + #[allow(unused_variables)] + fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn read(&mut self, id: usize, buf: &mut [u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn write(&mut self, id: usize, buf: &[u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn seek(&mut self, id: usize, pos: usize, whence: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fevent(&mut self, id: usize, flags: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn fsync(&mut self, id: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn ftruncate(&mut self, id: usize, len: usize) -> Result { + Err(Error::new(EBADF)) + } + + #[allow(unused_variables)] + fn close(&mut self, id: usize) -> Result { + Err(Error::new(EBADF)) + } +} diff --git a/src/libstd/sys/redox/syscall/x86.rs b/src/libstd/sys/redox/syscall/x86.rs new file mode 100644 index 0000000000000..4bb6060c43e06 --- /dev/null +++ b/src/libstd/sys/redox/syscall/x86.rs @@ -0,0 +1,72 @@ +use super::error::{Error, Result}; + +pub unsafe fn syscall0(mut a: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +// Clobbers all registers - special for clone +pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b) + : "memory", "ebx", "ecx", "edx", "esi", "edi" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b), "{ecx}"(c) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { + asm!("int 0x80" + : "={eax}"(a) + : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} diff --git a/src/libstd/sys/redox/syscall/x86_64.rs b/src/libstd/sys/redox/syscall/x86_64.rs new file mode 100644 index 0000000000000..6c1f96adef925 --- /dev/null +++ b/src/libstd/sys/redox/syscall/x86_64.rs @@ -0,0 +1,72 @@ +use super::error::{Error, Result}; + +pub unsafe fn syscall0(mut a: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +// Clobbers all registers - special for clone +pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b) + : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b), "{rcx}"(c) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { + asm!("int 0x80" + : "={rax}"(a) + : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f) + : "memory" + : "intel", "volatile"); + + Error::demux(a) +} diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index f5546b6aac4f5..82acbf934881d 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -914,6 +914,11 @@ fn use_color(opts: &TestOpts) -> bool { } } +#[cfg(target_os = "redox")] +fn stdout_isatty() -> bool { + // FIXME: Implement isatty on Redox + false +} #[cfg(unix)] fn stdout_isatty() -> bool { unsafe { libc::isatty(libc::STDOUT_FILENO) != 0 } @@ -1103,6 +1108,12 @@ fn get_concurrency() -> usize { } } + #[cfg(target_os = "redox")] + fn num_cpus() -> usize { + // FIXME: Implement num_cpus on Redox + 1 + } + #[cfg(any(target_os = "linux", target_os = "macos", target_os = "ios", From 773a0a2edb9a79733aca9f07f1fa8d7d155c4abc Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Dec 2016 13:10:37 -0700 Subject: [PATCH 08/27] Add start functions, switch allocation crate to ralloc --- src/librustc_back/target/redox_base.rs | 4 +- src/libstd/lib.rs | 5 ++ src/libstd/sys/redox/start.rs | 81 +++++++++++++++++++++++++- 3 files changed, 85 insertions(+), 5 deletions(-) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index a04ec81e973ba..fc4c68276b651 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, - lib_allocation_crate: "alloc_system".to_string(), - exe_allocation_crate: "alloc_system".to_string(), + lib_allocation_crate: "ralloc".to_string(), + exe_allocation_crate: "ralloc".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 3c9e66a469cd8..6a1bb1268d715 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -423,6 +423,11 @@ pub use core_collections::vec; #[stable(feature = "rust1", since = "1.0.0")] pub use std_unicode::char; +// Reexport the start module on platforms that provide it +#[unstable(feature = "start_fn", issue="0")] +#[cfg(target_os = "redox")] +pub use sys::start::*; + pub mod f32; pub mod f64; diff --git a/src/libstd/sys/redox/start.rs b/src/libstd/sys/redox/start.rs index b689be1cf4d25..87f58a4773c4d 100644 --- a/src/libstd/sys/redox/start.rs +++ b/src/libstd/sys/redox/start.rs @@ -1,6 +1,6 @@ use sys::syscall::exit; -#[allow(private_no_mangle_fns)] +#[unstable(feature = "start_fn", issue = "0")] #[no_mangle] #[naked] #[cfg(target_arch = "x86")] @@ -15,7 +15,7 @@ pub unsafe fn _start() { let _ = exit(0); } -#[allow(private_no_mangle_fns)] +#[unstable(feature = "start_fn", issue = "0")] #[no_mangle] #[naked] #[cfg(target_arch = "x86_64")] @@ -30,7 +30,7 @@ pub unsafe fn _start() { let _ = exit(0); } -#[allow(private_no_mangle_fns)] +#[unstable(feature = "start_fn", issue = "0")] #[no_mangle] pub unsafe extern "C" fn _start_stack(stack: *const usize){ extern "C" { @@ -41,3 +41,78 @@ pub unsafe extern "C" fn _start_stack(stack: *const usize){ let argv = stack.offset(1) as *const *const u8; let _ = exit(main(argc, argv)); } + +/// Memcpy +/// +/// Copy N bytes of memory from one location to another. +#[unstable(feature = "start_fn", issue = "0")] +#[no_mangle] +pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8, + n: usize) -> *mut u8 { + let mut i = 0; + while i < n { + *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); + i += 1; + } + + dest +} + +/// Memmove +/// +/// Copy N bytes of memory from src to dest. The memory areas may overlap. +#[unstable(feature = "start_fn", issue = "0")] +#[no_mangle] +pub unsafe extern fn memmove(dest: *mut u8, src: *const u8, + n: usize) -> *mut u8 { + if src < dest as *const u8 { + let mut i = n; + while i != 0 { + i -= 1; + *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); + } + } else { + let mut i = 0; + while i < n { + *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); + i += 1; + } + } + + dest +} + +/// Memset +/// +/// Fill a block of memory with a specified value. +#[unstable(feature = "start_fn", issue = "0")] +#[no_mangle] +pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 { + let mut i = 0; + while i < n { + *((dest as usize + i) as *mut u8) = c as u8; + i += 1; + } + + dest +} + +/// Memcmp +/// +/// Compare two blocks of memory. +#[unstable(feature = "start_fn", issue = "0")] +#[no_mangle] +pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { + let mut i = 0; + + while i < n { + let a = *((s1 as usize + i) as *const u8); + let b = *((s2 as usize + i) as *const u8); + if a != b { + return a as i32 - b as i32 + } + i += 1; + } + + 0 +} From 07e313de2c4ca3c0c8cfd19bf7b7930763629da6 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Dec 2016 15:30:50 -0700 Subject: [PATCH 09/27] Add openlibm to redox --- src/librustc_back/target/redox_base.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index fc4c68276b651..d8c83b39d8ef0 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -33,6 +33,10 @@ pub fn opts() -> TargetOptions { // Static link "-static".to_string() ], + late_link_args: vec![ + // Link to openlibm for math functions + "-lopenlibm".to_string() + ], executables: true, relocation_model: "static".to_string(), disable_redzone: true, From 6d7c2ecf2e7b73f067c093ce9770ec187f9b3ea1 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 15 Dec 2016 16:35:06 -0700 Subject: [PATCH 10/27] Revert libstd/Cargo.toml to master --- src/libstd/Cargo.toml | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index 0384c6666e3bb..fcf84cb716917 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -23,9 +23,6 @@ compiler_builtins = { path = "../libcompiler_builtins" } std_unicode = { path = "../libstd_unicode" } unwind = { path = "../libunwind" } -[replace] -"core:0.0.0" = { path = "../libcore" } - [build-dependencies] build_helper = { path = "../build_helper" } gcc = "0.3.27" From 57bc1a982e20524bbaac892c04e537c8f714dce6 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 11:17:09 -0700 Subject: [PATCH 11/27] Add arm syscalls --- src/libstd/sys/redox/syscall/arch/arm.rs | 72 +++++++++++++++++++ .../sys/redox/syscall/{ => arch}/x86.rs | 0 .../sys/redox/syscall/{ => arch}/x86_64.rs | 0 src/libstd/sys/redox/syscall/mod.rs | 8 ++- 4 files changed, 78 insertions(+), 2 deletions(-) create mode 100644 src/libstd/sys/redox/syscall/arch/arm.rs rename src/libstd/sys/redox/syscall/{ => arch}/x86.rs (100%) rename src/libstd/sys/redox/syscall/{ => arch}/x86_64.rs (100%) diff --git a/src/libstd/sys/redox/syscall/arch/arm.rs b/src/libstd/sys/redox/syscall/arch/arm.rs new file mode 100644 index 0000000000000..6e8bc2c0e6365 --- /dev/null +++ b/src/libstd/sys/redox/syscall/arch/arm.rs @@ -0,0 +1,72 @@ +use super::error::{Error, Result}; + +pub unsafe fn syscall0(mut a: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a) + : "memory" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall1(mut a: usize, b: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b) + : "memory" + : "volatile"); + + Error::demux(a) +} + +// Clobbers all registers - special for clone +pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b) + : "memory", "r0", "r1", "r2", "r3", "r4" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall2(mut a: usize, b: usize, c: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b), "{r1}"(c) + : "memory" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall3(mut a: usize, b: usize, c: usize, d: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d) + : "memory" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e) + : "memory" + : "volatile"); + + Error::demux(a) +} + +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { + asm!("swi $$0" + : "={r0}"(a) + : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f) + : "memory" + : "volatile"); + + Error::demux(a) +} diff --git a/src/libstd/sys/redox/syscall/x86.rs b/src/libstd/sys/redox/syscall/arch/x86.rs similarity index 100% rename from src/libstd/sys/redox/syscall/x86.rs rename to src/libstd/sys/redox/syscall/arch/x86.rs diff --git a/src/libstd/sys/redox/syscall/x86_64.rs b/src/libstd/sys/redox/syscall/arch/x86_64.rs similarity index 100% rename from src/libstd/sys/redox/syscall/x86_64.rs rename to src/libstd/sys/redox/syscall/arch/x86_64.rs diff --git a/src/libstd/sys/redox/syscall/mod.rs b/src/libstd/sys/redox/syscall/mod.rs index 77f98d5b36bf4..34a35b967b1bb 100644 --- a/src/libstd/sys/redox/syscall/mod.rs +++ b/src/libstd/sys/redox/syscall/mod.rs @@ -6,12 +6,16 @@ pub use self::flag::*; pub use self::number::*; pub use self::scheme::*; +#[cfg(target_arch = "arm")] +#[path="arch/arm.rs"] +mod arch; + #[cfg(target_arch = "x86")] -#[path="x86.rs"] +#[path="arch/x86.rs"] mod arch; #[cfg(target_arch = "x86_64")] -#[path="x86_64.rs"] +#[path="arch/x86_64.rs"] mod arch; /// Function definitions From 86f85c13994ab5bb17291140f8274b6529da95cf Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 12:41:33 -0700 Subject: [PATCH 12/27] Move start functions into libstd/rt --- src/libstd/lib.rs | 5 ----- src/libstd/rt.rs | 7 +++++-- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 6a1bb1268d715..3c9e66a469cd8 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -423,11 +423,6 @@ pub use core_collections::vec; #[stable(feature = "rust1", since = "1.0.0")] pub use std_unicode::char; -// Reexport the start module on platforms that provide it -#[unstable(feature = "start_fn", issue="0")] -#[cfg(target_os = "redox")] -pub use sys::start::*; - pub mod f32; pub mod f64; diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 78d5aa597ba0d..abaa635864510 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -22,11 +22,14 @@ issue = "0")] #![doc(hidden)] - - // Reexport some of our utilities which are expected by other crates. pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; +// Reexport the start module on platforms that provide it +#[unstable(feature = "start_fn", issue="0")] +#[cfg(target_os = "redox")] +pub use sys::start::*; + #[cfg(not(test))] #[lang = "start"] fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { From 01157e6b3cf3acd2c555d36e272c7ad05d837868 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 14:30:27 -0700 Subject: [PATCH 13/27] Link openlibm only in libstd --- src/librustc_back/target/redox_base.rs | 4 ---- src/libstd/build.rs | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index d8c83b39d8ef0..fc4c68276b651 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -33,10 +33,6 @@ pub fn opts() -> TargetOptions { // Static link "-static".to_string() ], - late_link_args: vec![ - // Link to openlibm for math functions - "-lopenlibm".to_string() - ], executables: true, relocation_model: "static".to_string(), disable_redzone: true, diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 535cb7e136ce4..b8f9b51172ade 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -62,6 +62,8 @@ fn main() { println!("cargo:rustc-link-lib=magenta"); println!("cargo:rustc-link-lib=mxio"); println!("cargo:rustc-link-lib=launchpad"); // for std::process + } else if target.contains("redox") { + println!("cargo:rustc-link-lib=openlibm"); } } From e55596fa2011254fc29e7b386fb36416c79cf17f Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 15:26:58 -0700 Subject: [PATCH 14/27] Move rt into sys::rt, fix tidy --- src/libstd/rt.rs | 5 +- src/libstd/sys/redox/mod.rs | 2 +- src/libstd/sys/redox/net/netc.rs | 10 + src/libstd/sys/redox/{start.rs => rt.rs} | 26 ++- src/libstd/sys/redox/syscall/arch/arm.rs | 13 +- src/libstd/sys/redox/syscall/arch/x86.rs | 13 +- src/libstd/sys/redox/syscall/arch/x86_64.rs | 16 +- src/libstd/sys/redox/syscall/call.rs | 21 +- src/libstd/sys/redox/syscall/data.rs | 94 +------- src/libstd/sys/redox/syscall/error.rs | 10 + src/libstd/sys/redox/syscall/flag.rs | 10 + src/libstd/sys/redox/syscall/mod.rs | 14 +- src/libstd/sys/redox/syscall/number.rs | 10 + src/libstd/sys/redox/syscall/scheme.rs | 232 -------------------- src/libstd/sys/unix/mod.rs | 1 + src/libstd/sys/unix/rt.rs | 11 + src/libstd/sys/windows/mod.rs | 1 + src/libstd/sys/windows/rt.rs | 11 + 18 files changed, 163 insertions(+), 337 deletions(-) rename src/libstd/sys/redox/{start.rs => rt.rs} (74%) delete mode 100644 src/libstd/sys/redox/syscall/scheme.rs create mode 100644 src/libstd/sys/unix/rt.rs create mode 100644 src/libstd/sys/windows/rt.rs diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index abaa635864510..1f2b94239a86b 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -26,9 +26,8 @@ pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; // Reexport the start module on platforms that provide it -#[unstable(feature = "start_fn", issue="0")] -#[cfg(target_os = "redox")] -pub use sys::start::*; +#[unstable(feature = "sys_rt", issue="0")] +pub use sys::rt::*; #[cfg(not(test))] #[lang = "start"] diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index fce1cb364fa6c..d4811a3444fd3 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -29,9 +29,9 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; +pub mod rt; pub mod rwlock; pub mod stack_overflow; -pub mod start; pub mod stdio; pub mod syscall; pub mod thread; diff --git a/src/libstd/sys/redox/net/netc.rs b/src/libstd/sys/redox/net/netc.rs index 78045c54fb207..03e1c9fffa4d0 100644 --- a/src/libstd/sys/redox/net/netc.rs +++ b/src/libstd/sys/redox/net/netc.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + pub type in_addr_t = u32; pub type in_port_t = u16; diff --git a/src/libstd/sys/redox/start.rs b/src/libstd/sys/redox/rt.rs similarity index 74% rename from src/libstd/sys/redox/start.rs rename to src/libstd/sys/redox/rt.rs index 87f58a4773c4d..0e854989c125c 100644 --- a/src/libstd/sys/redox/start.rs +++ b/src/libstd/sys/redox/rt.rs @@ -1,6 +1,18 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Defintion of functions like _start for the linker + use sys::syscall::exit; -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] #[naked] #[cfg(target_arch = "x86")] @@ -15,7 +27,7 @@ pub unsafe fn _start() { let _ = exit(0); } -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] #[naked] #[cfg(target_arch = "x86_64")] @@ -30,7 +42,7 @@ pub unsafe fn _start() { let _ = exit(0); } -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] pub unsafe extern "C" fn _start_stack(stack: *const usize){ extern "C" { @@ -45,7 +57,7 @@ pub unsafe extern "C" fn _start_stack(stack: *const usize){ /// Memcpy /// /// Copy N bytes of memory from one location to another. -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { @@ -61,7 +73,7 @@ pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8, /// Memmove /// /// Copy N bytes of memory from src to dest. The memory areas may overlap. -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] pub unsafe extern fn memmove(dest: *mut u8, src: *const u8, n: usize) -> *mut u8 { @@ -85,7 +97,7 @@ pub unsafe extern fn memmove(dest: *mut u8, src: *const u8, /// Memset /// /// Fill a block of memory with a specified value. -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 { let mut i = 0; @@ -100,7 +112,7 @@ pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 { /// Memcmp /// /// Compare two blocks of memory. -#[unstable(feature = "start_fn", issue = "0")] +#[unstable(feature = "sys_rt", issue = "0")] #[no_mangle] pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { let mut i = 0; diff --git a/src/libstd/sys/redox/syscall/arch/arm.rs b/src/libstd/sys/redox/syscall/arch/arm.rs index 6e8bc2c0e6365..9fb3961486df2 100644 --- a/src/libstd/sys/redox/syscall/arch/arm.rs +++ b/src/libstd/sys/redox/syscall/arch/arm.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { @@ -61,7 +71,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("swi $$0" : "={r0}"(a) : "{r7}"(a), "{r0}"(b), "{r1}"(c), "{r2}"(d), "{r3}"(e), "{r4}"(f) diff --git a/src/libstd/sys/redox/syscall/arch/x86.rs b/src/libstd/sys/redox/syscall/arch/x86.rs index 4bb6060c43e06..724a6b927f43a 100644 --- a/src/libstd/sys/redox/syscall/arch/x86.rs +++ b/src/libstd/sys/redox/syscall/arch/x86.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { @@ -61,7 +71,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("int 0x80" : "={eax}"(a) : "{eax}"(a), "{ebx}"(b), "{ecx}"(c), "{edx}"(d), "{esi}"(e), "{edi}"(f) diff --git a/src/libstd/sys/redox/syscall/arch/x86_64.rs b/src/libstd/sys/redox/syscall/arch/x86_64.rs index 6c1f96adef925..a321c31f207d0 100644 --- a/src/libstd/sys/redox/syscall/arch/x86_64.rs +++ b/src/libstd/sys/redox/syscall/arch/x86_64.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use super::error::{Error, Result}; pub unsafe fn syscall0(mut a: usize) -> Result { @@ -25,7 +35,8 @@ pub unsafe fn syscall1_clobber(mut a: usize, b: usize) -> Result { asm!("int 0x80" : "={rax}"(a) : "{rax}"(a), "{rbx}"(b) - : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15" + : "memory", "rbx", "rcx", "rdx", "rsi", "rdi", "r8", + "r9", "r10", "r11", "r12", "r13", "r14", "r15" : "intel", "volatile"); Error::demux(a) @@ -61,7 +72,8 @@ pub unsafe fn syscall4(mut a: usize, b: usize, c: usize, d: usize, e: usize) -> Error::demux(a) } -pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) -> Result { +pub unsafe fn syscall5(mut a: usize, b: usize, c: usize, d: usize, e: usize, f: usize) + -> Result { asm!("int 0x80" : "={rax}"(a) : "{rax}"(a), "{rbx}"(b), "{rcx}"(c), "{rdx}"(d), "{rsi}"(e), "{rdi}"(f) diff --git a/src/libstd/sys/redox/syscall/call.rs b/src/libstd/sys/redox/syscall/call.rs index 939ebf510725d..f58c240f31e65 100644 --- a/src/libstd/sys/redox/syscall/call.rs +++ b/src/libstd/sys/redox/syscall/call.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use super::arch::*; use super::data::{Stat, StatVfs, TimeSpec}; use super::error::Result; @@ -63,7 +73,8 @@ pub fn dup(fd: usize, buf: &[u8]) -> Result { /// Replace the current process with a new executable pub fn execve(path: &str, args: &[[usize; 2]]) -> Result { - unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(), args.as_ptr() as usize, args.len()) } + unsafe { syscall4(SYS_EXECVE, path.as_ptr() as usize, path.len(), + args.as_ptr() as usize, args.len()) } } /// Exit the current process @@ -116,8 +127,9 @@ pub fn ftruncate(fd: usize, len: usize) -> Result { unsafe { syscall2(SYS_FTRUNCATE, fd, len) } } -/// Fast userspace mutex - TODO: Document -pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) -> Result { +/// Fast userspace mutex +pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32) + -> Result { syscall5(SYS_FUTEX, addr as usize, op, (val as isize) as usize, val2, addr2 as usize) } @@ -188,7 +200,8 @@ pub fn mkns(schemes: &[[usize; 2]]) -> Result { /// Sleep for the time specified in `req` pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result { - unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, rem as *mut TimeSpec as usize) } + unsafe { syscall2(SYS_NANOSLEEP, req as *const TimeSpec as usize, + rem as *mut TimeSpec as usize) } } /// Open a file diff --git a/src/libstd/sys/redox/syscall/data.rs b/src/libstd/sys/redox/syscall/data.rs index 240690befde1d..223167d6bf75d 100644 --- a/src/libstd/sys/redox/syscall/data.rs +++ b/src/libstd/sys/redox/syscall/data.rs @@ -1,60 +1,16 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use core::ops::{Deref, DerefMut}; use core::{mem, slice}; -#[derive(Copy, Clone, Debug, Default)] -pub struct Event { - pub id: usize, - pub flags: usize, - pub data: usize -} - -impl Deref for Event { - type Target = [u8]; - fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const Event as *const u8, mem::size_of::()) as &[u8] - } - } -} - -impl DerefMut for Event { - fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut Event as *mut u8, mem::size_of::()) as &mut [u8] - } - } -} - -#[derive(Copy, Clone, Debug, Default)] -#[repr(packed)] -pub struct Packet { - pub id: u64, - pub pid: usize, - pub uid: u32, - pub gid: u32, - pub a: usize, - pub b: usize, - pub c: usize, - pub d: usize -} - -impl Deref for Packet { - type Target = [u8]; - fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const Packet as *const u8, mem::size_of::()) as &[u8] - } - } -} - -impl DerefMut for Packet { - fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut Packet as *mut u8, mem::size_of::()) as &mut [u8] - } - } -} - #[derive(Copy, Clone, Debug, Default)] #[repr(packed)] pub struct Stat { @@ -87,34 +43,8 @@ impl Deref for Stat { impl DerefMut for Stat { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut Stat as *mut u8, mem::size_of::()) as &mut [u8] - } - } -} - -#[derive(Copy, Clone, Debug, Default)] -#[repr(packed)] -pub struct StatVfs { - pub f_bsize: u32, - pub f_blocks: u64, - pub f_bfree: u64, - pub f_bavail: u64, - //TODO: More fields https://linux.die.net/man/2/statvfs -} - -impl Deref for StatVfs { - type Target = [u8]; - fn deref(&self) -> &[u8] { - unsafe { - slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::()) as &[u8] - } - } -} - -impl DerefMut for StatVfs { - fn deref_mut(&mut self) -> &mut [u8] { - unsafe { - slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::()) as &mut [u8] + slice::from_raw_parts_mut(self as *mut Stat as *mut u8, + mem::size_of::()) as &mut [u8] } } } diff --git a/src/libstd/sys/redox/syscall/error.rs b/src/libstd/sys/redox/syscall/error.rs index 7cbcbe98765ed..d8d78d550162a 100644 --- a/src/libstd/sys/redox/syscall/error.rs +++ b/src/libstd/sys/redox/syscall/error.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + use core::{fmt, result}; #[derive(Eq, PartialEq)] diff --git a/src/libstd/sys/redox/syscall/flag.rs b/src/libstd/sys/redox/syscall/flag.rs index 97ff8e2d79ae7..9f0d3e6f77955 100644 --- a/src/libstd/sys/redox/syscall/flag.rs +++ b/src/libstd/sys/redox/syscall/flag.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + pub const CLONE_VM: usize = 0x100; pub const CLONE_FS: usize = 0x200; pub const CLONE_FILES: usize = 0x400; diff --git a/src/libstd/sys/redox/syscall/mod.rs b/src/libstd/sys/redox/syscall/mod.rs index 34a35b967b1bb..ce789c269a7e0 100644 --- a/src/libstd/sys/redox/syscall/mod.rs +++ b/src/libstd/sys/redox/syscall/mod.rs @@ -1,10 +1,19 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + pub use self::arch::*; pub use self::call::*; pub use self::data::*; pub use self::error::*; pub use self::flag::*; pub use self::number::*; -pub use self::scheme::*; #[cfg(target_arch = "arm")] #[path="arch/arm.rs"] @@ -32,6 +41,3 @@ pub mod flag; /// Call numbers used by each system call pub mod number; - -/// A trait useful for scheme handlers -pub mod scheme; diff --git a/src/libstd/sys/redox/syscall/number.rs b/src/libstd/sys/redox/syscall/number.rs index 719c8af218fd8..358746cd20a23 100644 --- a/src/libstd/sys/redox/syscall/number.rs +++ b/src/libstd/sys/redox/syscall/number.rs @@ -1,3 +1,13 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + pub const SYS_CLASS: usize = 0xF000_0000; pub const SYS_CLASS_PATH: usize=0x1000_0000; pub const SYS_CLASS_FILE: usize=0x2000_0000; diff --git a/src/libstd/sys/redox/syscall/scheme.rs b/src/libstd/sys/redox/syscall/scheme.rs deleted file mode 100644 index d322f0b5a9c8c..0000000000000 --- a/src/libstd/sys/redox/syscall/scheme.rs +++ /dev/null @@ -1,232 +0,0 @@ -use core::{mem, slice}; - -use super::*; - -pub trait Scheme { - fn handle(&self, packet: &mut Packet) { - packet.a = Error::mux(match packet.a { - SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid), - SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid), - SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), - SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), - - SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c, packet.d), - SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, packet.c), - SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FSTAT => if packet.d >= mem::size_of::() { self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) } else { Err(Error::new(EFAULT)) }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) } else { Err(Error::new(EFAULT)) }, - SYS_FSYNC => self.fsync(packet.b), - SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_CLOSE => self.close(packet.b), - - _ => Err(Error::new(ENOSYS)) - }); - } - - /* Scheme operations */ - - #[allow(unused_variables)] - fn open(&self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn rmdir(&self, path: &[u8], uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn unlink(&self, path: &[u8], uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - /* Resource operations */ - #[allow(unused_variables)] - fn dup(&self, old_id: usize, buf: &[u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn read(&self, id: usize, buf: &mut [u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn write(&self, id: usize, buf: &[u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn seek(&self, id: usize, pos: usize, whence: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fcntl(&self, id: usize, cmd: usize, arg: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fevent(&self, id: usize, flags: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fmap(&self, id: usize, offset: usize, size: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fpath(&self, id: usize, buf: &mut [u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fstat(&self, id: usize, stat: &mut Stat) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fsync(&self, id: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn ftruncate(&self, id: usize, len: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn close(&self, id: usize) -> Result { - Err(Error::new(EBADF)) - } -} - -pub trait SchemeMut { - fn handle(&mut self, packet: &mut Packet) { - packet.a = Error::mux(match packet.a { - SYS_OPEN => self.open(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d, packet.uid, packet.gid), - SYS_CHMOD => self.chmod(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.d as u16, packet.uid, packet.gid), - SYS_RMDIR => self.rmdir(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), - SYS_UNLINK => self.unlink(unsafe { slice::from_raw_parts(packet.b as *const u8, packet.c) }, packet.uid, packet.gid), - - SYS_DUP => self.dup(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_READ => self.read(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_WRITE => self.write(packet.b, unsafe { slice::from_raw_parts(packet.c as *const u8, packet.d) }), - SYS_LSEEK => self.seek(packet.b, packet.c, packet.d), - SYS_FCNTL => self.fcntl(packet.b, packet.c, packet.d), - SYS_FEVENT => self.fevent(packet.b, packet.c), - SYS_FMAP => self.fmap(packet.b, packet.c, packet.d), - SYS_FPATH => self.fpath(packet.b, unsafe { slice::from_raw_parts_mut(packet.c as *mut u8, packet.d) }), - SYS_FSTAT => if packet.d >= mem::size_of::() { self.fstat(packet.b, unsafe { &mut *(packet.c as *mut Stat) }) } else { Err(Error::new(EFAULT)) }, - SYS_FSTATVFS => if packet.d >= mem::size_of::() { self.fstatvfs(packet.b, unsafe { &mut *(packet.c as *mut StatVfs) }) } else { Err(Error::new(EFAULT)) }, - SYS_FSYNC => self.fsync(packet.b), - SYS_FTRUNCATE => self.ftruncate(packet.b, packet.c), - SYS_CLOSE => self.close(packet.b), - - _ => Err(Error::new(ENOSYS)) - }); - } - - /* Scheme operations */ - #[allow(unused_variables)] - fn open(&mut self, path: &[u8], flags: usize, uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn chmod(&self, path: &[u8], mode: u16, uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn rmdir(&mut self, path: &[u8], uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - #[allow(unused_variables)] - fn unlink(&mut self, path: &[u8], uid: u32, gid: u32) -> Result { - Err(Error::new(ENOENT)) - } - - /* Resource operations */ - #[allow(unused_variables)] - fn dup(&mut self, old_id: usize, buf: &[u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn read(&mut self, id: usize, buf: &mut [u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn write(&mut self, id: usize, buf: &[u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn seek(&mut self, id: usize, pos: usize, whence: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fcntl(&mut self, id: usize, cmd: usize, arg: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fevent(&mut self, id: usize, flags: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fmap(&mut self, id: usize, offset: usize, size: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fpath(&mut self, id: usize, buf: &mut [u8]) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fstat(&mut self, id: usize, stat: &mut Stat) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fstatvfs(&self, id: usize, stat: &mut StatVfs) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn fsync(&mut self, id: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn ftruncate(&mut self, id: usize, len: usize) -> Result { - Err(Error::new(EBADF)) - } - - #[allow(unused_variables)] - fn close(&mut self, id: usize) -> Result { - Err(Error::new(EBADF)) - } -} diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index fd7dc17cccd8c..5e14b392bdc2c 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -50,6 +50,7 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; +pub mod rt; pub mod rwlock; pub mod stack_overflow; pub mod thread; diff --git a/src/libstd/sys/unix/rt.rs b/src/libstd/sys/unix/rt.rs new file mode 100644 index 0000000000000..188e31cb5d7b2 --- /dev/null +++ b/src/libstd/sys/unix/rt.rs @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Stub for placing functions like _start for the linker diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index defc41c5f46a3..52d256630a5e9 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -36,6 +36,7 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; +pub mod rt; pub mod rwlock; pub mod stack_overflow; pub mod thread; diff --git a/src/libstd/sys/windows/rt.rs b/src/libstd/sys/windows/rt.rs new file mode 100644 index 0000000000000..188e31cb5d7b2 --- /dev/null +++ b/src/libstd/sys/windows/rt.rs @@ -0,0 +1,11 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Stub for placing functions like _start for the linker From 65eecf8bb311efe4174cb7a90271344b72371884 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 16:12:36 -0700 Subject: [PATCH 15/27] Readd statvfs --- src/libstd/sys/redox/syscall/data.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/libstd/sys/redox/syscall/data.rs b/src/libstd/sys/redox/syscall/data.rs index 223167d6bf75d..11f007c52abfa 100644 --- a/src/libstd/sys/redox/syscall/data.rs +++ b/src/libstd/sys/redox/syscall/data.rs @@ -49,6 +49,32 @@ impl DerefMut for Stat { } } +#[derive(Copy, Clone, Debug, Default)] +#[repr(packed)] +pub struct StatVfs { + pub f_bsize: u32, + pub f_blocks: u64, + pub f_bfree: u64, + pub f_bavail: u64, +} + +impl Deref for StatVfs { + type Target = [u8]; + fn deref(&self) -> &[u8] { + unsafe { + slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::()) as &[u8] + } + } +} + +impl DerefMut for StatVfs { + fn deref_mut(&mut self) -> &mut [u8] { + unsafe { + slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::()) as &mut [u8] + } + } +} + #[derive(Copy, Clone, Debug, Default)] #[repr(packed)] pub struct TimeSpec { From fd4bc88880bd7aeb2a1a5cb56fbfea639bc6f2e7 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 17:52:47 -0700 Subject: [PATCH 16/27] Fix building without backtrace --- src/libstd/sys/redox/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index d4811a3444fd3..a8dbac28fb655 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -13,6 +13,7 @@ use io::{self, ErrorKind}; pub mod args; +#[cfg(any(not(cargobuild), feature = "backtrace"))] pub mod backtrace; pub mod condvar; pub mod env; From 7697c7277ea35e215c412b8d1216ca75bd1a6a45 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 18:03:30 -0700 Subject: [PATCH 17/27] Static link openlibm --- src/libstd/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libstd/build.rs b/src/libstd/build.rs index b8f9b51172ade..34ec1651326ca 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -63,7 +63,7 @@ fn main() { println!("cargo:rustc-link-lib=mxio"); println!("cargo:rustc-link-lib=launchpad"); // for std::process } else if target.contains("redox") { - println!("cargo:rustc-link-lib=openlibm"); + println!("cargo:rustc-link-lib=static=openlibm"); } } From 2ca1f0b3b30208695529e227cda6ba0ad8a5ec60 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 18:09:19 -0700 Subject: [PATCH 18/27] Switch back to alloc_system --- src/liballoc_system/lib.rs | 51 ++------------------------ src/librustc_back/target/redox_base.rs | 4 +- 2 files changed, 6 insertions(+), 49 deletions(-) diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs index 487e8e8e6ec39..4daa6cbb8465e 100644 --- a/src/liballoc_system/lib.rs +++ b/src/liballoc_system/lib.rs @@ -19,8 +19,7 @@ issue = "27783")] #![feature(allocator)] #![feature(staged_api)] -#![cfg_attr(target_os = "redox", feature(libc))] -#![cfg_attr(unix, feature(libc))] +#![cfg_attr(any(unix, target_os = "redox"), feature(libc))] // The minimum alignment guaranteed by the architecture. This value is used to // add fast paths for low alignment values. In practice, the alignment is a @@ -72,49 +71,7 @@ pub extern "C" fn __rust_usable_size(size: usize, align: usize) -> usize { imp::usable_size(size, align) } -#[cfg(target_os = "redox")] -mod imp { - extern crate libc; - - use core::cmp; - use core::ptr; - use MIN_ALIGN; - - pub unsafe fn allocate(size: usize, _align: usize) -> *mut u8 { - libc::malloc(size as libc::size_t) as *mut u8 - } - - pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 { - if align <= MIN_ALIGN { - libc::realloc(ptr as *mut libc::c_void, size as libc::size_t) as *mut u8 - } else { - let new_ptr = allocate(size, align); - if !new_ptr.is_null() { - ptr::copy(ptr, new_ptr, cmp::min(size, old_size)); - deallocate(ptr, old_size, align); - } - new_ptr - } - } - - pub unsafe fn reallocate_inplace(_ptr: *mut u8, - old_size: usize, - _size: usize, - _align: usize) - -> usize { - old_size - } - - pub unsafe fn deallocate(ptr: *mut u8, _old_size: usize, _align: usize) { - libc::free(ptr as *mut libc::c_void) - } - - pub fn usable_size(size: usize, _align: usize) -> usize { - size - } -} - -#[cfg(any(unix))] +#[cfg(any(unix, target_os = "redox"))] mod imp { extern crate libc; @@ -130,7 +87,7 @@ mod imp { } } - #[cfg(target_os = "android")] + #[cfg(any(target_os = "android", target_os = "redox"))] unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { // On android we currently target API level 9 which unfortunately // doesn't have the `posix_memalign` API used below. Instead we use @@ -152,7 +109,7 @@ mod imp { libc::memalign(align as libc::size_t, size as libc::size_t) as *mut u8 } - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_os = "redox")))] unsafe fn aligned_malloc(size: usize, align: usize) -> *mut u8 { let mut out = ptr::null_mut(); let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t); diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index fc4c68276b651..a04ec81e973ba 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, - lib_allocation_crate: "ralloc".to_string(), - exe_allocation_crate: "ralloc".to_string(), + lib_allocation_crate: "alloc_system".to_string(), + exe_allocation_crate: "alloc_system".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() From bf50acbc09fe1acd627b8d4879e26b07d89e31e2 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Tue, 20 Dec 2016 21:29:42 -0700 Subject: [PATCH 19/27] Fix tidy --- src/libstd/sys/redox/syscall/data.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/libstd/sys/redox/syscall/data.rs b/src/libstd/sys/redox/syscall/data.rs index 11f007c52abfa..ac3946672a3dd 100644 --- a/src/libstd/sys/redox/syscall/data.rs +++ b/src/libstd/sys/redox/syscall/data.rs @@ -35,7 +35,8 @@ impl Deref for Stat { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const Stat as *const u8, mem::size_of::()) as &[u8] + slice::from_raw_parts(self as *const Stat as *const u8, + mem::size_of::()) as &[u8] } } } @@ -62,7 +63,8 @@ impl Deref for StatVfs { type Target = [u8]; fn deref(&self) -> &[u8] { unsafe { - slice::from_raw_parts(self as *const StatVfs as *const u8, mem::size_of::()) as &[u8] + slice::from_raw_parts(self as *const StatVfs as *const u8, + mem::size_of::()) as &[u8] } } } @@ -70,7 +72,8 @@ impl Deref for StatVfs { impl DerefMut for StatVfs { fn deref_mut(&mut self) -> &mut [u8] { unsafe { - slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, mem::size_of::()) as &mut [u8] + slice::from_raw_parts_mut(self as *mut StatVfs as *mut u8, + mem::size_of::()) as &mut [u8] } } } From e909e431d5c2c95d51acaf2209757bd98e488f79 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 21 Dec 2016 11:38:04 -0700 Subject: [PATCH 20/27] Update liblibc, go back to lazy linking openlibm --- src/liblibc | 2 +- src/libstd/build.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liblibc b/src/liblibc index 0ac39c5ccf6a0..e49e9bb7c3d9c 160000 --- a/src/liblibc +++ b/src/liblibc @@ -1 +1 @@ -Subproject commit 0ac39c5ccf6a04395b7c40dd62321cb91f63f160 +Subproject commit e49e9bb7c3d9c7f2fd893f0ee0db81617b8db21f diff --git a/src/libstd/build.rs b/src/libstd/build.rs index 34ec1651326ca..b8f9b51172ade 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -63,7 +63,7 @@ fn main() { println!("cargo:rustc-link-lib=mxio"); println!("cargo:rustc-link-lib=launchpad"); // for std::process } else if target.contains("redox") { - println!("cargo:rustc-link-lib=static=openlibm"); + println!("cargo:rustc-link-lib=openlibm"); } } From 7d3ae874534421e3cca560f33175e61cb2262fd0 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 21 Dec 2016 20:19:19 -0700 Subject: [PATCH 21/27] Add RawFd traits for net --- src/libstd/sys/redox/ext/io.rs | 35 +++++++++++++++++++-------------- src/libstd/sys/redox/net/tcp.rs | 29 +++++++++++++++++++++++++++ src/libstd/sys/redox/net/udp.rs | 15 ++++++++++++++ 3 files changed, 64 insertions(+), 15 deletions(-) diff --git a/src/libstd/sys/redox/ext/io.rs b/src/libstd/sys/redox/ext/io.rs index 135e31fae1e68..8e7cc593dbded 100644 --- a/src/libstd/sys/redox/ext/io.rs +++ b/src/libstd/sys/redox/ext/io.rs @@ -13,8 +13,9 @@ #![stable(feature = "rust1", since = "1.0.0")] use fs; +use net; use sys; -use sys_common::{AsInner, FromInner, IntoInner}; +use sys_common::{self, AsInner, FromInner, IntoInner}; /// Raw file descriptors. #[stable(feature = "rust1", since = "1.0.0")] @@ -89,58 +90,62 @@ impl IntoRawFd for fs::File { } } -/* #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::TcpStream { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + self.as_inner().as_inner().fd().raw() + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::TcpListener { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + self.as_inner().as_inner().fd().raw() + } } #[stable(feature = "rust1", since = "1.0.0")] impl AsRawFd for net::UdpSocket { - fn as_raw_fd(&self) -> RawFd { *self.as_inner().socket().as_inner() } + fn as_raw_fd(&self) -> RawFd { + self.as_inner().as_inner().fd().raw() + } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawFd for net::TcpStream { unsafe fn from_raw_fd(fd: RawFd) -> net::TcpStream { - let socket = sys::net::Socket::from_inner(fd); - net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(socket)) + let file = sys::fs::File::from_inner(fd); + net::TcpStream::from_inner(sys_common::net::TcpStream::from_inner(file)) } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawFd for net::TcpListener { unsafe fn from_raw_fd(fd: RawFd) -> net::TcpListener { - let socket = sys::net::Socket::from_inner(fd); - net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(socket)) + let file = sys::fs::File::from_inner(fd); + net::TcpListener::from_inner(sys_common::net::TcpListener::from_inner(file)) } } #[stable(feature = "from_raw_os", since = "1.1.0")] impl FromRawFd for net::UdpSocket { unsafe fn from_raw_fd(fd: RawFd) -> net::UdpSocket { - let socket = sys::net::Socket::from_inner(fd); - net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(socket)) + let file = sys::fs::File::from_inner(fd); + net::UdpSocket::from_inner(sys_common::net::UdpSocket::from_inner(file)) } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for net::TcpStream { fn into_raw_fd(self) -> RawFd { - self.into_inner().into_socket().into_inner() + self.into_inner().into_inner().into_fd().into_raw() } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for net::TcpListener { fn into_raw_fd(self) -> RawFd { - self.into_inner().into_socket().into_inner() + self.into_inner().into_inner().into_fd().into_raw() } } #[stable(feature = "into_raw_os", since = "1.4.0")] impl IntoRawFd for net::UdpSocket { fn into_raw_fd(self) -> RawFd { - self.into_inner().into_socket().into_inner() + self.into_inner().into_inner().into_fd().into_raw() } } -*/ diff --git a/src/libstd/sys/redox/net/tcp.rs b/src/libstd/sys/redox/net/tcp.rs index 1bfec2e861a68..d5362c9f131f6 100644 --- a/src/libstd/sys/redox/net/tcp.rs +++ b/src/libstd/sys/redox/net/tcp.rs @@ -12,6 +12,7 @@ use io::{Error, ErrorKind, Result}; use net::{SocketAddr, Shutdown}; use path::Path; use sys::fs::{File, OpenOptions}; +use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; use vec::Vec; @@ -112,6 +113,20 @@ impl TcpStream { } } +impl AsInner for TcpStream { + fn as_inner(&self) -> &File { &self.0 } +} + +impl FromInner for TcpStream { + fn from_inner(file: File) -> TcpStream { + TcpStream(file) + } +} + +impl IntoInner for TcpStream { + fn into_inner(self) -> File { self.0 } +} + #[derive(Debug)] pub struct TcpListener(File); @@ -168,3 +183,17 @@ impl TcpListener { Err(Error::new(ErrorKind::Other, "TcpListener::set_ttl not implemented")) } } + +impl AsInner for TcpListener { + fn as_inner(&self) -> &File { &self.0 } +} + +impl FromInner for TcpListener { + fn from_inner(file: File) -> TcpListener { + TcpListener(file) + } +} + +impl IntoInner for TcpListener { + fn into_inner(self) -> File { self.0 } +} diff --git a/src/libstd/sys/redox/net/udp.rs b/src/libstd/sys/redox/net/udp.rs index b81508e8f0de1..607c66c2ba70e 100644 --- a/src/libstd/sys/redox/net/udp.rs +++ b/src/libstd/sys/redox/net/udp.rs @@ -13,6 +13,7 @@ use io::{Error, ErrorKind, Result}; use net::{SocketAddr, Ipv4Addr, Ipv6Addr}; use path::Path; use sys::fs::{File, OpenOptions}; +use sys_common::{AsInner, FromInner, IntoInner}; use time::Duration; use super::{path_to_peer_addr, path_to_local_addr}; @@ -171,3 +172,17 @@ impl UdpSocket { Err(Error::new(ErrorKind::Other, "UdpSocket::leave_multicast_v6 not implemented")) } } + +impl AsInner for UdpSocket { + fn as_inner(&self) -> &File { &self.0 } +} + +impl FromInner for UdpSocket { + fn from_inner(file: File) -> UdpSocket { + UdpSocket(file, UnsafeCell::new(None)) + } +} + +impl IntoInner for UdpSocket { + fn into_inner(self) -> File { self.0 } +} From e7b006d3dde2d8c75edbf55082c40ecbb9867950 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Wed, 21 Dec 2016 21:57:43 -0700 Subject: [PATCH 22/27] In order to successfully build, go back to ralloc --- src/librustc_back/target/redox_base.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index a04ec81e973ba..fc4c68276b651 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -40,8 +40,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, - lib_allocation_crate: "alloc_system".to_string(), - exe_allocation_crate: "alloc_system".to_string(), + lib_allocation_crate: "ralloc".to_string(), + exe_allocation_crate: "ralloc".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() From 1eb6c44b1c21483dbab25d8ca23d616b34f4cf4d Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Dec 2016 16:13:14 -0700 Subject: [PATCH 23/27] Remove start functions, use newlib instead of openlibm + ralloc --- src/librustc_back/target/redox_base.rs | 11 ++- src/libstd/build.rs | 2 - src/libstd/lib.rs | 1 - src/libstd/rt.rs | 4 - src/libstd/sys/redox/mod.rs | 1 - src/libstd/sys/redox/rt.rs | 130 ------------------------- src/libstd/sys/unix/mod.rs | 1 - src/libstd/sys/unix/rt.rs | 11 --- src/libstd/sys/windows/mod.rs | 1 - src/libstd/sys/windows/rt.rs | 11 --- 10 files changed, 6 insertions(+), 167 deletions(-) delete mode 100644 src/libstd/sys/redox/rt.rs delete mode 100644 src/libstd/sys/unix/rt.rs delete mode 100644 src/libstd/sys/windows/rt.rs diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index fc4c68276b651..c804d283ba757 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -27,12 +27,13 @@ pub fn opts() -> TargetOptions { // Always enable NX protection when it is available "-Wl,-z,noexecstack".to_string(), - // Do not link libc - "-nostdlib".to_string(), - // Static link "-static".to_string() ], + late_link_args: vec![ + "-lc".to_string(), + "-lm".to_string() + ], executables: true, relocation_model: "static".to_string(), disable_redzone: true, @@ -40,8 +41,8 @@ pub fn opts() -> TargetOptions { target_family: Some("redox".to_string()), linker_is_gnu: true, no_default_libraries: true, - lib_allocation_crate: "ralloc".to_string(), - exe_allocation_crate: "ralloc".to_string(), + lib_allocation_crate: "alloc_system".to_string(), + exe_allocation_crate: "alloc_system".to_string(), has_elf_tls: true, panic_strategy: PanicStrategy::Abort, .. Default::default() diff --git a/src/libstd/build.rs b/src/libstd/build.rs index b8f9b51172ade..535cb7e136ce4 100644 --- a/src/libstd/build.rs +++ b/src/libstd/build.rs @@ -62,8 +62,6 @@ fn main() { println!("cargo:rustc-link-lib=magenta"); println!("cargo:rustc-link-lib=mxio"); println!("cargo:rustc-link-lib=launchpad"); // for std::process - } else if target.contains("redox") { - println!("cargo:rustc-link-lib=openlibm"); } } diff --git a/src/libstd/lib.rs b/src/libstd/lib.rs index 3c9e66a469cd8..414f25fa5eb33 100644 --- a/src/libstd/lib.rs +++ b/src/libstd/lib.rs @@ -299,7 +299,6 @@ #![feature(unwind_attributes)] #![feature(vec_push_all)] #![feature(zero_one)] -#![cfg_attr(target_os = "redox", feature(naked_functions))] #![cfg_attr(test, feature(update_panic_count))] // Explicitly import the prelude. The compiler uses this same unstable attribute diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 1f2b94239a86b..185b7bbd73633 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -25,10 +25,6 @@ // Reexport some of our utilities which are expected by other crates. pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; -// Reexport the start module on platforms that provide it -#[unstable(feature = "sys_rt", issue="0")] -pub use sys::rt::*; - #[cfg(not(test))] #[lang = "start"] fn lang_start(main: *const u8, argc: isize, argv: *const *const u8) -> isize { diff --git a/src/libstd/sys/redox/mod.rs b/src/libstd/sys/redox/mod.rs index a8dbac28fb655..5982bdd6549ca 100644 --- a/src/libstd/sys/redox/mod.rs +++ b/src/libstd/sys/redox/mod.rs @@ -30,7 +30,6 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; -pub mod rt; pub mod rwlock; pub mod stack_overflow; pub mod stdio; diff --git a/src/libstd/sys/redox/rt.rs b/src/libstd/sys/redox/rt.rs deleted file mode 100644 index 0e854989c125c..0000000000000 --- a/src/libstd/sys/redox/rt.rs +++ /dev/null @@ -1,130 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Defintion of functions like _start for the linker - -use sys::syscall::exit; - -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -#[naked] -#[cfg(target_arch = "x86")] -pub unsafe fn _start() { - asm!("push esp - call _start_stack - pop esp" - : - : - : "memory" - : "intel", "volatile"); - let _ = exit(0); -} - -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -#[naked] -#[cfg(target_arch = "x86_64")] -pub unsafe fn _start() { - asm!("mov rdi, rsp - and rsp, 0xFFFFFFFFFFFFFFF0 - call _start_stack" - : - : - : "memory" - : "intel", "volatile"); - let _ = exit(0); -} - -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -pub unsafe extern "C" fn _start_stack(stack: *const usize){ - extern "C" { - fn main(argc: usize, argv: *const *const u8) -> usize; - } - - let argc = *stack as usize; - let argv = stack.offset(1) as *const *const u8; - let _ = exit(main(argc, argv)); -} - -/// Memcpy -/// -/// Copy N bytes of memory from one location to another. -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8, - n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); - i += 1; - } - - dest -} - -/// Memmove -/// -/// Copy N bytes of memory from src to dest. The memory areas may overlap. -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -pub unsafe extern fn memmove(dest: *mut u8, src: *const u8, - n: usize) -> *mut u8 { - if src < dest as *const u8 { - let mut i = n; - while i != 0 { - i -= 1; - *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); - } - } else { - let mut i = 0; - while i < n { - *((dest as usize + i) as *mut u8) = *((src as usize + i) as *const u8); - i += 1; - } - } - - dest -} - -/// Memset -/// -/// Fill a block of memory with a specified value. -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -pub unsafe extern fn memset(dest: *mut u8, c: i32, n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *((dest as usize + i) as *mut u8) = c as u8; - i += 1; - } - - dest -} - -/// Memcmp -/// -/// Compare two blocks of memory. -#[unstable(feature = "sys_rt", issue = "0")] -#[no_mangle] -pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { - let mut i = 0; - - while i < n { - let a = *((s1 as usize + i) as *const u8); - let b = *((s2 as usize + i) as *const u8); - if a != b { - return a as i32 - b as i32 - } - i += 1; - } - - 0 -} diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 5e14b392bdc2c..fd7dc17cccd8c 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -50,7 +50,6 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; -pub mod rt; pub mod rwlock; pub mod stack_overflow; pub mod thread; diff --git a/src/libstd/sys/unix/rt.rs b/src/libstd/sys/unix/rt.rs deleted file mode 100644 index 188e31cb5d7b2..0000000000000 --- a/src/libstd/sys/unix/rt.rs +++ /dev/null @@ -1,11 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Stub for placing functions like _start for the linker diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 52d256630a5e9..defc41c5f46a3 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -36,7 +36,6 @@ pub mod path; pub mod pipe; pub mod process; pub mod rand; -pub mod rt; pub mod rwlock; pub mod stack_overflow; pub mod thread; diff --git a/src/libstd/sys/windows/rt.rs b/src/libstd/sys/windows/rt.rs deleted file mode 100644 index 188e31cb5d7b2..0000000000000 --- a/src/libstd/sys/windows/rt.rs +++ /dev/null @@ -1,11 +0,0 @@ -// 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 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Stub for placing functions like _start for the linker From 2ddd11788bef1622833fed64726345222cd9f708 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Dec 2016 16:19:05 -0700 Subject: [PATCH 24/27] Revert rt.rs --- src/libstd/rt.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/libstd/rt.rs b/src/libstd/rt.rs index 185b7bbd73633..78d5aa597ba0d 100644 --- a/src/libstd/rt.rs +++ b/src/libstd/rt.rs @@ -22,6 +22,8 @@ issue = "0")] #![doc(hidden)] + + // Reexport some of our utilities which are expected by other crates. pub use panicking::{begin_panic, begin_panic_fmt, update_panic_count}; From 474eb6223bcb50960048cce05ede8ab1e36ea8ca Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Dec 2016 22:01:15 -0700 Subject: [PATCH 25/27] Do not build emutls on Redox --- src/libcompiler_builtins/build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libcompiler_builtins/build.rs b/src/libcompiler_builtins/build.rs index f61e2281a5c30..44aa08e245873 100644 --- a/src/libcompiler_builtins/build.rs +++ b/src/libcompiler_builtins/build.rs @@ -242,7 +242,7 @@ fn main() { "atomic_thread_fence.c"]); } - if !target.contains("windows") { + if !target.contains("redox") && !target.contains("windows") { sources.extend(&["emutls.c"]); } From c59bb4979c6d2e994b01d6ed9e005f8881a36935 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Dec 2016 22:20:47 -0700 Subject: [PATCH 26/27] Correct target_family mess --- src/librustc/session/config.rs | 18 ++++++------------ src/librustc_back/target/apple_base.rs | 1 + src/librustc_back/target/bitrig_base.rs | 1 + src/librustc_back/target/dragonfly_base.rs | 1 + src/librustc_back/target/freebsd_base.rs | 1 + src/librustc_back/target/fuchsia_base.rs | 1 + src/librustc_back/target/haiku_base.rs | 1 + src/librustc_back/target/linux_base.rs | 1 + src/librustc_back/target/netbsd_base.rs | 1 + src/librustc_back/target/openbsd_base.rs | 1 + src/librustc_back/target/redox_base.rs | 2 +- src/librustc_back/target/solaris_base.rs | 1 + src/librustc_back/target/windows_base.rs | 1 + src/librustc_back/target/windows_msvc_base.rs | 1 + 14 files changed, 19 insertions(+), 13 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index e500c08ce6e32..17b5199e7ed3b 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -943,26 +943,20 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { let vendor = &sess.target.target.target_vendor; let max_atomic_width = sess.target.target.max_atomic_width(); - let fam = if let Some(ref fam) = sess.target.target.options.target_family { - Symbol::intern(fam) - } else if sess.target.target.options.is_like_windows { - Symbol::intern("windows") - } else { - Symbol::intern("unix") - }; - let mut ret = HashSet::new(); // Target bindings. ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os)))); - ret.insert((Symbol::intern("target_family"), Some(fam))); + if let Some(fam) = sess.target.target.options.target_family { + ret.insert((Symbol::intern("target_family"), Some(fam))); + if fam == "windows" || fam == "unix" { + ret.insert((fam, None)); + } + } ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch)))); ret.insert((Symbol::intern("target_endian"), Some(Symbol::intern(end)))); ret.insert((Symbol::intern("target_pointer_width"), Some(Symbol::intern(wordsz)))); ret.insert((Symbol::intern("target_env"), Some(Symbol::intern(env)))); ret.insert((Symbol::intern("target_vendor"), Some(Symbol::intern(vendor)))); - if fam == "windows" || fam == "unix" { - ret.insert((fam, None)); - } if sess.target.target.options.has_elf_tls { ret.insert((Symbol::intern("target_thread_local"), None)); } diff --git a/src/librustc_back/target/apple_base.rs b/src/librustc_back/target/apple_base.rs index 70c7ea99e13d1..21a2d4293df77 100644 --- a/src/librustc_back/target/apple_base.rs +++ b/src/librustc_back/target/apple_base.rs @@ -37,6 +37,7 @@ pub fn opts() -> TargetOptions { function_sections: false, dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), is_like_osx: true, has_rpath: true, dll_prefix: "lib".to_string(), diff --git a/src/librustc_back/target/bitrig_base.rs b/src/librustc_back/target/bitrig_base.rs index 7baf80066b274..62418e68d4341 100644 --- a/src/librustc_back/target/bitrig_base.rs +++ b/src/librustc_back/target/bitrig_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, position_independent_executables: true, diff --git a/src/librustc_back/target/dragonfly_base.rs b/src/librustc_back/target/dragonfly_base.rs index 7555181a15cf2..dca33e45af7c7 100644 --- a/src/librustc_back/target/dragonfly_base.rs +++ b/src/librustc_back/target/dragonfly_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, pre_link_args: vec![ diff --git a/src/librustc_back/target/freebsd_base.rs b/src/librustc_back/target/freebsd_base.rs index 7555181a15cf2..dca33e45af7c7 100644 --- a/src/librustc_back/target/freebsd_base.rs +++ b/src/librustc_back/target/freebsd_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, pre_link_args: vec![ diff --git a/src/librustc_back/target/fuchsia_base.rs b/src/librustc_back/target/fuchsia_base.rs index 69546684cb70b..8c517224201b2 100644 --- a/src/librustc_back/target/fuchsia_base.rs +++ b/src/librustc_back/target/fuchsia_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, pre_link_args: vec![ diff --git a/src/librustc_back/target/haiku_base.rs b/src/librustc_back/target/haiku_base.rs index 5e319ba1838a0..bfdc9faaa8a73 100644 --- a/src/librustc_back/target/haiku_base.rs +++ b/src/librustc_back/target/haiku_base.rs @@ -17,6 +17,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, .. Default::default() } diff --git a/src/librustc_back/target/linux_base.rs b/src/librustc_back/target/linux_base.rs index d1ab71e41404e..4b2ae9c8e699c 100644 --- a/src/librustc_back/target/linux_base.rs +++ b/src/librustc_back/target/linux_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, pre_link_args: vec![ diff --git a/src/librustc_back/target/netbsd_base.rs b/src/librustc_back/target/netbsd_base.rs index 6e038a7ed56ee..57179a68afd8e 100644 --- a/src/librustc_back/target/netbsd_base.rs +++ b/src/librustc_back/target/netbsd_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, pre_link_args: vec![ diff --git a/src/librustc_back/target/openbsd_base.rs b/src/librustc_back/target/openbsd_base.rs index 1f74170e39989..12b8e8bdc88fd 100644 --- a/src/librustc_back/target/openbsd_base.rs +++ b/src/librustc_back/target/openbsd_base.rs @@ -15,6 +15,7 @@ pub fn opts() -> TargetOptions { TargetOptions { dynamic_linking: true, executables: true, + target_family: Some("unix".to_string()), linker_is_gnu: true, has_rpath: true, is_like_openbsd: true, diff --git a/src/librustc_back/target/redox_base.rs b/src/librustc_back/target/redox_base.rs index c804d283ba757..1dffff598096b 100644 --- a/src/librustc_back/target/redox_base.rs +++ b/src/librustc_back/target/redox_base.rs @@ -38,7 +38,7 @@ pub fn opts() -> TargetOptions { relocation_model: "static".to_string(), disable_redzone: true, eliminate_frame_pointer: false, - target_family: Some("redox".to_string()), + target_family: None, linker_is_gnu: true, no_default_libraries: true, lib_allocation_crate: "alloc_system".to_string(), diff --git a/src/librustc_back/target/solaris_base.rs b/src/librustc_back/target/solaris_base.rs index a7af0462e570f..41323c9c26ba7 100644 --- a/src/librustc_back/target/solaris_base.rs +++ b/src/librustc_back/target/solaris_base.rs @@ -16,6 +16,7 @@ pub fn opts() -> TargetOptions { dynamic_linking: true, executables: true, has_rpath: true, + target_family: Some("unix".to_string()), is_like_solaris: true, exe_allocation_crate: super::maybe_jemalloc(), diff --git a/src/librustc_back/target/windows_base.rs b/src/librustc_back/target/windows_base.rs index 19ca0df51b9dc..db02e142fcc8e 100644 --- a/src/librustc_back/target/windows_base.rs +++ b/src/librustc_back/target/windows_base.rs @@ -24,6 +24,7 @@ pub fn opts() -> TargetOptions { staticlib_prefix: "".to_string(), staticlib_suffix: ".lib".to_string(), no_default_libraries: true, + target_family: Some("windows".to_string()), is_like_windows: true, allows_weak_linkage: false, pre_link_args: vec![ diff --git a/src/librustc_back/target/windows_msvc_base.rs b/src/librustc_back/target/windows_msvc_base.rs index 84e22e84fdb58..efa215b419d70 100644 --- a/src/librustc_back/target/windows_msvc_base.rs +++ b/src/librustc_back/target/windows_msvc_base.rs @@ -53,6 +53,7 @@ pub fn opts() -> TargetOptions { exe_suffix: ".exe".to_string(), staticlib_prefix: "".to_string(), staticlib_suffix: ".lib".to_string(), + target_family: Some("windows".to_string()), is_like_windows: true, is_like_msvc: true, pre_link_args: vec![ From 4dcb86767111149bcd233d6ac5c782d345d1e10b Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 22 Dec 2016 22:29:33 -0700 Subject: [PATCH 27/27] Convert fam to Symbol --- src/librustc/session/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 17b5199e7ed3b..7ae063c8c2793 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -946,10 +946,10 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { let mut ret = HashSet::new(); // Target bindings. ret.insert((Symbol::intern("target_os"), Some(Symbol::intern(os)))); - if let Some(fam) = sess.target.target.options.target_family { - ret.insert((Symbol::intern("target_family"), Some(fam))); + if let Some(ref fam) = sess.target.target.options.target_family { + ret.insert((Symbol::intern("target_family"), Some(Symbol::intern(fam)))); if fam == "windows" || fam == "unix" { - ret.insert((fam, None)); + ret.insert((Symbol::intern(fam), None)); } } ret.insert((Symbol::intern("target_arch"), Some(Symbol::intern(arch))));