diff options
Diffstat (limited to 'src/libstd/sys')
| -rw-r--r-- | src/libstd/sys/unix/mod.rs | 53 | ||||
| -rw-r--r-- | src/libstd/sys/unix/stack_overflow.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/unix/thread.rs | 19 | ||||
| -rw-r--r-- | src/libstd/sys/windows/fs.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 42 | ||||
| -rw-r--r-- | src/libstd/sys/windows/process.rs | 1 | ||||
| -rw-r--r-- | src/libstd/sys/windows/stack_overflow.rs | 2 | ||||
| -rw-r--r-- | src/libstd/sys/windows/thread.rs | 1 |
8 files changed, 61 insertions, 62 deletions
diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 9771b057d8d..2e89becfa67 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -8,14 +8,12 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(missing_docs)] -#![allow(non_camel_case_types)] +#![allow(missing_docs, bad_style)] use io::{self, ErrorKind}; use libc; use num::One; use ops::Neg; -use alloc::oom; #[cfg(target_os = "android")] pub use os::android as platform; #[cfg(target_os = "bitrig")] pub use os::bitrig as platform; @@ -46,25 +44,10 @@ pub mod thread_local; pub mod time; pub mod stdio; -// A nicer handler for out-of-memory situations than the default one. This one -// prints a message to stderr before aborting. It is critical that this code -// does not allocate any memory since we are in an OOM situation. Any errors are -// ignored while printing since there's nothing we can do about them and we are -// about to exit anyways. -fn oom_handler() -> ! { - use intrinsics; - let msg = "fatal runtime error: out of memory\n"; - unsafe { - libc::write(libc::STDERR_FILENO, - msg.as_ptr() as *const libc::c_void, - msg.len() as libc::size_t); - intrinsics::abort(); - } -} - -#[cfg(not(any(target_os = "nacl", test)))] +#[cfg(not(test))] pub fn init() { - use libc::signal; + use alloc::oom; + // By default, some platforms will send a *signal* when an EPIPE error // would otherwise be delivered. This runtime doesn't install a SIGPIPE // handler, causing it to kill the program, which isn't exactly what we @@ -73,15 +56,33 @@ pub fn init() { // Hence, we set SIGPIPE to ignore when the program starts up in order // to prevent this problem. unsafe { - assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != !0); + reset_sigpipe(); } oom::set_oom_handler(oom_handler); -} -#[cfg(all(target_os = "nacl", not(test)))] -pub fn init() { - oom::set_oom_handler(oom_handler); + // A nicer handler for out-of-memory situations than the default one. This + // one prints a message to stderr before aborting. It is critical that this + // code does not allocate any memory since we are in an OOM situation. Any + // errors are ignored while printing since there's nothing we can do about + // them and we are about to exit anyways. + fn oom_handler() -> ! { + use intrinsics; + let msg = "fatal runtime error: out of memory\n"; + unsafe { + libc::write(libc::STDERR_FILENO, + msg.as_ptr() as *const libc::c_void, + msg.len() as libc::size_t); + intrinsics::abort(); + } + } + + #[cfg(not(target_os = "nacl"))] + unsafe fn reset_sigpipe() { + assert!(libc::signal(libc::SIGPIPE, libc::SIG_IGN) != !0); + } + #[cfg(target_os = "nacl")] + unsafe fn reset_sigpipe() {} } pub fn decode_error_kind(errno: i32) -> ErrorKind { diff --git a/src/libstd/sys/unix/stack_overflow.rs b/src/libstd/sys/unix/stack_overflow.rs index fc49f4257be..c7614db3299 100644 --- a/src/libstd/sys/unix/stack_overflow.rs +++ b/src/libstd/sys/unix/stack_overflow.rs @@ -7,6 +7,7 @@ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your // option. This file may not be copied, modified, or distributed // except according to those terms. + #![cfg_attr(test, allow(dead_code))] use libc; diff --git a/src/libstd/sys/unix/thread.rs b/src/libstd/sys/unix/thread.rs index 4d715b579c6..9e28cf06d61 100644 --- a/src/libstd/sys/unix/thread.rs +++ b/src/libstd/sys/unix/thread.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(dead_code)] - use prelude::v1::*; use alloc::boxed::FnBox; @@ -174,6 +172,7 @@ impl Drop for Thread { not(target_os = "bitrig"), not(all(target_os = "netbsd", not(target_vendor = "rumprun"))), not(target_os = "openbsd")))] +#[cfg_attr(test, allow(dead_code))] pub mod guard { pub unsafe fn current() -> Option<usize> { None } pub unsafe fn init() -> Option<usize> { None } @@ -185,15 +184,13 @@ pub mod guard { target_os = "bitrig", all(target_os = "netbsd", not(target_vendor = "rumprun")), target_os = "openbsd"))] -#[allow(unused_imports)] +#[cfg_attr(test, allow(dead_code))] pub mod guard { use prelude::v1::*; - use libc::{self, pthread_t}; + use libc; use libc::mmap; use libc::{PROT_NONE, MAP_PRIVATE, MAP_ANON, MAP_FAILED, MAP_FIXED}; - use mem; - use ptr; use sys::os; #[cfg(any(target_os = "macos", @@ -206,10 +203,10 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] unsafe fn get_stack_start() -> Option<*mut libc::c_void> { let mut ret = None; - let mut attr: libc::pthread_attr_t = mem::zeroed(); + let mut attr: libc::pthread_attr_t = ::mem::zeroed(); assert_eq!(libc::pthread_attr_init(&mut attr), 0); if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 { - let mut stackaddr = ptr::null_mut(); + let mut stackaddr = ::ptr::null_mut(); let mut stacksize = 0; assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut stacksize), 0); @@ -265,7 +262,7 @@ pub mod guard { #[cfg(any(target_os = "openbsd", target_os = "bitrig"))] pub unsafe fn current() -> Option<usize> { - let mut current_stack: libc::stack_t = mem::zeroed(); + let mut current_stack: libc::stack_t = ::mem::zeroed(); assert_eq!(libc::pthread_stackseg_np(libc::pthread_self(), &mut current_stack), 0); @@ -282,7 +279,7 @@ pub mod guard { #[cfg(any(target_os = "linux", target_os = "android", target_os = "netbsd"))] pub unsafe fn current() -> Option<usize> { let mut ret = None; - let mut attr: libc::pthread_attr_t = mem::zeroed(); + let mut attr: libc::pthread_attr_t = ::mem::zeroed(); assert_eq!(libc::pthread_attr_init(&mut attr), 0); if libc::pthread_getattr_np(libc::pthread_self(), &mut attr) == 0 { let mut guardsize = 0; @@ -290,7 +287,7 @@ pub mod guard { if guardsize == 0 { panic!("there is no guard page"); } - let mut stackaddr = ptr::null_mut(); + let mut stackaddr = ::ptr::null_mut(); let mut size = 0; assert_eq!(libc::pthread_attr_getstack(&attr, &mut stackaddr, &mut size), 0); diff --git a/src/libstd/sys/windows/fs.rs b/src/libstd/sys/windows/fs.rs index 60e3f7c22bd..a8b82ef5f29 100644 --- a/src/libstd/sys/windows/fs.rs +++ b/src/libstd/sys/windows/fs.rs @@ -639,7 +639,7 @@ pub fn copy(from: &Path, to: &Path) -> io::Result<u64> { fn directory_junctions_are_directories() { use ffi::OsStr; use env; - use rand::{self, StdRng, Rng}; + use rand::{self, Rng}; use vec::Vec; macro_rules! t { @@ -683,7 +683,7 @@ fn directory_junctions_are_directories() { let mut data = [0u8; c::MAXIMUM_REPARSE_DATA_BUFFER_SIZE]; let mut db = data.as_mut_ptr() as *mut c::REPARSE_MOUNTPOINT_DATA_BUFFER; - let mut buf = &mut (*db).ReparseTarget as *mut _; + let buf = &mut (*db).ReparseTarget as *mut _; let mut i = 0; let v = br"\??\"; let v = v.iter().map(|x| *x as u16); diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 16c4ae8257c..9ecef5ee92c 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -8,9 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![allow(missing_docs)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] +#![allow(missing_docs, bad_style)] use prelude::v1::*; @@ -20,7 +18,6 @@ use num::Zero; use os::windows::ffi::{OsStrExt, OsStringExt}; use path::PathBuf; use time::Duration; -use alloc::oom; #[macro_use] pub mod compat; @@ -43,25 +40,26 @@ pub mod thread_local; pub mod time; pub mod stdio; -// See comment in sys/unix/mod.rs -fn oom_handler() -> ! { - use intrinsics; - use ptr; - let msg = "fatal runtime error: out of memory\n"; - unsafe { - // WriteFile silently fails if it is passed an invalid handle, so there - // is no need to check the result of GetStdHandle. - c::WriteFile(c::GetStdHandle(c::STD_ERROR_HANDLE), - msg.as_ptr() as c::LPVOID, - msg.len() as c::DWORD, - ptr::null_mut(), - ptr::null_mut()); - intrinsics::abort(); - } -} - +#[cfg(not(test))] pub fn init() { - oom::set_oom_handler(oom_handler); + ::alloc::oom::set_oom_handler(oom_handler); + + // See comment in sys/unix/mod.rs + fn oom_handler() -> ! { + use intrinsics; + use ptr; + let msg = "fatal runtime error: out of memory\n"; + unsafe { + // WriteFile silently fails if it is passed an invalid handle, so + // there is no need to check the result of GetStdHandle. + c::WriteFile(c::GetStdHandle(c::STD_ERROR_HANDLE), + msg.as_ptr() as c::LPVOID, + msg.len() as c::DWORD, + ptr::null_mut(), + ptr::null_mut()); + intrinsics::abort(); + } + } } pub fn decode_error_kind(errno: i32) -> ErrorKind { diff --git a/src/libstd/sys/windows/process.rs b/src/libstd/sys/windows/process.rs index e0f8d6f9df9..4ab9f678d06 100644 --- a/src/libstd/sys/windows/process.rs +++ b/src/libstd/sys/windows/process.rs @@ -386,7 +386,6 @@ impl Stdio { #[cfg(test)] mod tests { use prelude::v1::*; - use str; use ffi::{OsStr, OsString}; use super::make_command_line; diff --git a/src/libstd/sys/windows/stack_overflow.rs b/src/libstd/sys/windows/stack_overflow.rs index 01317bec0de..4a406d70e63 100644 --- a/src/libstd/sys/windows/stack_overflow.rs +++ b/src/libstd/sys/windows/stack_overflow.rs @@ -8,6 +8,8 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(test, allow(dead_code))] + use sys_common::util::report_overflow; use sys::c; diff --git a/src/libstd/sys/windows/thread.rs b/src/libstd/sys/windows/thread.rs index 1ba85867563..b18772c0c24 100644 --- a/src/libstd/sys/windows/thread.rs +++ b/src/libstd/sys/windows/thread.rs @@ -83,6 +83,7 @@ impl Thread { pub fn into_handle(self) -> Handle { self.handle } } +#[cfg_attr(test, allow(dead_code))] pub mod guard { pub unsafe fn current() -> Option<usize> { None } pub unsafe fn init() -> Option<usize> { None } |
