Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 5 pull requests #44707

Merged
merged 12 commits into from
Sep 20, 2017
2 changes: 1 addition & 1 deletion src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1332,7 +1332,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
print on stdout",
"[crate-name|file-names|sysroot|cfg|target-list|\
target-cpus|target-features|relocation-models|\
code-models|target-spec-json|native-static-deps]"),
code-models|target-spec-json|native-static-libs]"),
opt::flagmulti_s("g", "", "Equivalent to -C debuginfo=2"),
opt::flagmulti_s("O", "", "Equivalent to -C opt-level=2"),
opt::opt_s("o", "", "Write output to <filename>", "FILENAME"),
Expand Down
12 changes: 12 additions & 0 deletions src/librustc_trans/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,18 @@ impl<'a> Linker for MsvcLinker<'a> {
let sysroot = self.sess.sysroot();
let natvis_dir_path = sysroot.join("lib\\rustlib\\etc");
if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
// LLVM 5.0.0's lld-link frontend doesn't yet recognize, and chokes
// on, the /NATVIS:... flags. LLVM 6 (or earlier) should at worst ignore
// them, eventually mooting this workaround, per this landed patch:
// https://github.com/llvm-mirror/lld/commit/27b9c4285364d8d76bb43839daa100
if let Some(ref linker_path) = self.sess.opts.cg.linker {
if let Some(linker_name) = Path::new(&linker_path).file_stem() {
if linker_name.to_str().unwrap().to_lowercase() == "lld-link" {
self.sess.warn("not embedding natvis: lld-link may not support the flag");
return;
}
}
}
for entry in natvis_dir {
match entry {
Ok(entry) => {
Expand Down
10 changes: 6 additions & 4 deletions src/libstd/io/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ pub fn copy<R: ?Sized, W: ?Sized>(reader: &mut R, writer: &mut W) -> io::Result<

/// A reader which is always at EOF.
///
/// This struct is generally created by calling [`empty`][empty]. Please see
/// the documentation of `empty()` for more details.
/// This struct is generally created by calling [`empty`]. Please see
/// the documentation of [`empty()`][`empty`] for more details.
///
/// [empty]: fn.empty.html
/// [`empty`]: fn.empty.html
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Empty { _priv: () }

/// Constructs a new handle to an empty reader.
///
/// All reads from the returned reader will return `Ok(0)`.
/// All reads from the returned reader will return [`Ok`]`(0)`.
///
/// [`Ok`]: ../result/enum.Result.html#variant.Ok
///
/// # Examples
///
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/redox/net/netc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ 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;
pub const AF_INET: sa_family_t = 2;
pub const AF_INET6: sa_family_t = 23;

#[derive(Copy, Clone)]
#[repr(C)]
Expand Down
65 changes: 53 additions & 12 deletions src/libstd/sys/redox/syscall/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,17 @@
// except according to those terms.

use super::arch::*;
use super::data::{Stat, StatVfs, TimeSpec};
use super::data::{SigAction, Stat, StatVfs, TimeSpec};
use super::error::Result;
use super::number::*;

use core::mem;
use core::{mem, ptr};

// Signal restorer
extern "C" fn restorer() -> ! {
sigreturn().unwrap();
unreachable!();
}

/// Set the end of the process's heap
///
Expand Down Expand Up @@ -43,12 +49,12 @@ pub unsafe fn brk(addr: usize) -> Result<usize> {
/// * `EIO` - an I/O error occurred
/// * `ENOENT` - `path` does not exit
/// * `ENOTDIR` - `path` is not a directory
pub fn chdir(path: &str) -> Result<usize> {
unsafe { syscall2(SYS_CHDIR, path.as_ptr() as usize, path.len()) }
pub fn chdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_CHDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}

pub fn chmod(path: &str, mode: usize) -> Result<usize> {
unsafe { syscall3(SYS_CHMOD, path.as_ptr() as usize, path.len(), mode) }
pub fn chmod<T: AsRef<[u8]>>(path: T, mode: usize) -> Result<usize> {
unsafe { syscall3(SYS_CHMOD, path.as_ref().as_ptr() as usize, path.as_ref().len(), mode) }
}

/// Produce a fork of the current process, or a new process thread
Expand Down Expand Up @@ -132,6 +138,12 @@ pub fn ftruncate(fd: usize, len: usize) -> Result<usize> {
unsafe { syscall2(SYS_FTRUNCATE, fd, len) }
}

// Change modify and/or access times
pub fn futimens(fd: usize, times: &[TimeSpec]) -> Result<usize> {
unsafe { syscall3(SYS_FUTIMENS, fd, times.as_ptr() as usize,
times.len() * mem::size_of::<TimeSpec>()) }
}

/// Fast userspace mutex
pub unsafe fn futex(addr: *mut i32, op: usize, val: i32, val2: usize, addr2: *mut i32)
-> Result<usize> {
Expand Down Expand Up @@ -173,6 +185,16 @@ pub fn getpid() -> Result<usize> {
unsafe { syscall0(SYS_GETPID) }
}

/// Get the process group ID
pub fn getpgid(pid: usize) -> Result<usize> {
unsafe { syscall1(SYS_GETPGID, pid) }
}

/// Get the parent process ID
pub fn getppid() -> Result<usize> {
unsafe { syscall0(SYS_GETPPID) }
}

/// Get the current user ID
pub fn getuid() -> Result<usize> {
unsafe { syscall0(SYS_GETUID) }
Expand Down Expand Up @@ -210,8 +232,8 @@ pub fn nanosleep(req: &TimeSpec, rem: &mut TimeSpec) -> Result<usize> {
}

/// Open a file
pub fn open(path: &str, flags: usize) -> Result<usize> {
unsafe { syscall3(SYS_OPEN, path.as_ptr() as usize, path.len(), flags) }
pub fn open<T: AsRef<[u8]>>(path: T, flags: usize) -> Result<usize> {
unsafe { syscall3(SYS_OPEN, path.as_ref().as_ptr() as usize, path.as_ref().len(), flags) }
}

/// Allocate pages, linearly in physical memory
Expand Down Expand Up @@ -245,8 +267,13 @@ pub fn read(fd: usize, buf: &mut [u8]) -> Result<usize> {
}

/// Remove a directory
pub fn rmdir(path: &str) -> Result<usize> {
unsafe { syscall2(SYS_RMDIR, path.as_ptr() as usize, path.len()) }
pub fn rmdir<T: AsRef<[u8]>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_RMDIR, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}

/// Set the process group ID
pub fn setpgid(pid: usize, pgid: usize) -> Result<usize> {
unsafe { syscall2(SYS_SETPGID, pid, pgid) }
}

/// Set the current process group IDs
Expand All @@ -264,9 +291,23 @@ pub fn setreuid(ruid: usize, euid: usize) -> Result<usize> {
unsafe { syscall2(SYS_SETREUID, ruid, euid) }
}

/// Set up a signal handler
pub fn sigaction(sig: usize, act: Option<&SigAction>, oldact: Option<&mut SigAction>)
-> Result<usize> {
unsafe { syscall4(SYS_SIGACTION, sig,
act.map(|x| x as *const _).unwrap_or_else(ptr::null) as usize,
oldact.map(|x| x as *mut _).unwrap_or_else(ptr::null_mut) as usize,
restorer as usize) }
}

// Return from signal handler
pub fn sigreturn() -> Result<usize> {
unsafe { syscall0(SYS_SIGRETURN) }
}

/// Remove a file
pub fn unlink(path: &str) -> Result<usize> {
unsafe { syscall2(SYS_UNLINK, path.as_ptr() as usize, path.len()) }
pub fn unlink<T: AsRef<[u8]>>(path: T) -> Result<usize> {
unsafe { syscall2(SYS_UNLINK, path.as_ref().as_ptr() as usize, path.as_ref().len()) }
}

/// Convert a virtual address to a physical one
Expand Down
120 changes: 108 additions & 12 deletions src/libstd/sys/redox/syscall/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,90 @@
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::<Event>()
) 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::<Event>()
) as &mut [u8]
}
}
}

#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
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::<Packet>()
) 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::<Packet>()
) as &mut [u8]
}
}
}

#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct SigAction {
pub sa_handler: extern "C" fn(usize),
pub sa_mask: [u64; 2],
pub sa_flags: usize,
}

impl Default for SigAction {
fn default() -> Self {
Self {
sa_handler: unsafe { mem::transmute(0usize) },
sa_mask: [0; 2],
sa_flags: 0,
}
}
}

#[derive(Copy, Clone, Debug, Default)]
#[repr(C)]
pub struct Stat {
Expand All @@ -35,17 +119,21 @@ 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::<Stat>()) as &[u8]
slice::from_raw_parts(
self as *const Stat as *const u8,
mem::size_of::<Stat>()
) 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::<Stat>()) as &mut [u8]
slice::from_raw_parts_mut(
self as *mut Stat as *mut u8,
mem::size_of::<Stat>()
) as &mut [u8]
}
}
}
Expand All @@ -63,17 +151,21 @@ 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::<StatVfs>()) as &[u8]
slice::from_raw_parts(
self as *const StatVfs as *const u8,
mem::size_of::<StatVfs>()
) 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::<StatVfs>()) as &mut [u8]
slice::from_raw_parts_mut(
self as *mut StatVfs as *mut u8,
mem::size_of::<StatVfs>()
) as &mut [u8]
}
}
}
Expand All @@ -89,17 +181,21 @@ impl Deref for TimeSpec {
type Target = [u8];
fn deref(&self) -> &[u8] {
unsafe {
slice::from_raw_parts(self as *const TimeSpec as *const u8,
mem::size_of::<TimeSpec>()) as &[u8]
slice::from_raw_parts(
self as *const TimeSpec as *const u8,
mem::size_of::<TimeSpec>()
) as &[u8]
}
}
}

impl DerefMut for TimeSpec {
fn deref_mut(&mut self) -> &mut [u8] {
unsafe {
slice::from_raw_parts_mut(self as *mut TimeSpec as *mut u8,
mem::size_of::<TimeSpec>()) as &mut [u8]
slice::from_raw_parts_mut(
self as *mut TimeSpec as *mut u8,
mem::size_of::<TimeSpec>()
) as &mut [u8]
}
}
}
17 changes: 17 additions & 0 deletions src/libstd/sys/redox/syscall/flag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
pub const CLONE_VM: usize = 0x100;
pub const CLONE_FS: usize = 0x200;
pub const CLONE_FILES: usize = 0x400;
pub const CLONE_SIGHAND: usize = 0x800;
pub const CLONE_VFORK: usize = 0x4000;
pub const CLONE_THREAD: usize = 0x10000;

pub const CLOCK_REALTIME: usize = 1;
pub const CLOCK_MONOTONIC: usize = 4;
Expand All @@ -20,6 +22,7 @@ pub const EVENT_NONE: usize = 0;
pub const EVENT_READ: usize = 1;
pub const EVENT_WRITE: usize = 2;

pub const F_DUPFD: usize = 0;
pub const F_GETFD: usize = 1;
pub const F_SETFD: usize = 2;
pub const F_GETFL: usize = 3;
Expand All @@ -36,6 +39,8 @@ pub const MODE_TYPE: u16 = 0xF000;
pub const MODE_DIR: u16 = 0x4000;
pub const MODE_FILE: u16 = 0x8000;
pub const MODE_SYMLINK: u16 = 0xA000;
pub const MODE_FIFO: u16 = 0x1000;
pub const MODE_CHR: u16 = 0x2000;

pub const MODE_PERM: u16 = 0x0FFF;
pub const MODE_SETUID: u16 = 0o4000;
Expand Down Expand Up @@ -96,4 +101,16 @@ pub const SIGIO: usize = 29;
pub const SIGPWR: usize = 30;
pub const SIGSYS: usize = 31;

pub const SIG_DFL: usize = 0;
pub const SIG_IGN: usize = 1;

pub const SA_NOCLDSTOP: usize = 0x00000001;
pub const SA_NOCLDWAIT: usize = 0x00000002;
pub const SA_SIGINFO: usize = 0x00000004;
pub const SA_RESTORER: usize = 0x04000000;
pub const SA_ONSTACK: usize = 0x08000000;
pub const SA_RESTART: usize = 0x10000000;
pub const SA_NODEFER: usize = 0x40000000;
pub const SA_RESETHAND: usize = 0x80000000;

pub const WNOHANG: usize = 1;
Loading