diff options
| author | Alex Crichton <alex@alexcrichton.com> | 2013-10-09 10:34:27 -0700 |
|---|---|---|
| committer | Alex Crichton <alex@alexcrichton.com> | 2013-10-11 06:49:18 -0700 |
| commit | 8b4423b04f519b78e0e9196ae1521531c80c743b (patch) | |
| tree | 713d12f4142749e7699de5c61962ee359a30ca88 /src/libstd/rt | |
| parent | 8015f9c27ec342dbf0b28c9c0c4769d8b3bcfc9f (diff) | |
| download | rust-8b4423b04f519b78e0e9196ae1521531c80c743b.tar.gz rust-8b4423b04f519b78e0e9196ae1521531c80c743b.zip | |
De-pub some private runtime components
This change was waiting for privacy to get sorted out, which should be true now that #8215 has landed. Closes #4427
Diffstat (limited to 'src/libstd/rt')
| -rw-r--r-- | src/libstd/rt/borrowck.rs | 8 | ||||
| -rw-r--r-- | src/libstd/rt/local_heap.rs | 11 | ||||
| -rw-r--r-- | src/libstd/rt/local_ptr.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/macros.rs | 48 | ||||
| -rw-r--r-- | src/libstd/rt/mod.rs | 23 | ||||
| -rw-r--r-- | src/libstd/rt/task.rs | 44 | ||||
| -rw-r--r-- | src/libstd/rt/util.rs | 26 |
7 files changed, 134 insertions, 28 deletions
diff --git a/src/libstd/rt/borrowck.rs b/src/libstd/rt/borrowck.rs index 6be23a983ab..3c2000c522c 100644 --- a/src/libstd/rt/borrowck.rs +++ b/src/libstd/rt/borrowck.rs @@ -15,10 +15,10 @@ use option::{Option, None, Some}; use ptr::RawPtr; use rt::env; use rt::local::Local; +use rt::task; use rt::task::Task; use str::{OwnedStr, StrSlice}; use str; -use sys; use uint; use unstable::raw; use vec::ImmutableVector; @@ -64,7 +64,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) { None => { // not recording borrows let msg = "borrowed"; do msg.with_c_str |msg_p| { - sys::begin_unwind_(msg_p, file, line); + task::begin_unwind(msg_p, file, line); } } Some(borrow_list) => { // recording borrows @@ -80,7 +80,7 @@ unsafe fn fail_borrowed(box: *mut raw::Box<()>, file: *c_char, line: size_t) { } } do msg.with_c_str |msg_p| { - sys::begin_unwind_(msg_p, file, line) + task::begin_unwind(msg_p, file, line) } } } @@ -179,7 +179,7 @@ pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint, if br.box != a || br.file != file || br.line != line { let err = format!("wrong borrow found, br={:?}", br); do err.with_c_str |msg_p| { - sys::begin_unwind_(msg_p, file, line) + task::begin_unwind(msg_p, file, line) } } borrow_list diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs index f863ccacaf5..262da9f3b8e 100644 --- a/src/libstd/rt/local_heap.rs +++ b/src/libstd/rt/local_heap.rs @@ -86,6 +86,17 @@ impl Drop for LocalHeap { } } +pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char { + // XXX: Unsafe borrow for speed. Lame. + let task: Option<*mut Task> = Local::try_unsafe_borrow(); + match task { + Some(task) => { + (*task).heap.alloc(td as *libc::c_void, size as uint) as *libc::c_char + } + None => rtabort!("local malloc outside of task") + } +} + // A little compatibility function pub unsafe fn local_free(ptr: *libc::c_char) { // XXX: Unsafe borrow for speed. Lame. diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs index 33384594c57..c9534413c53 100644 --- a/src/libstd/rt/local_ptr.rs +++ b/src/libstd/rt/local_ptr.rs @@ -178,5 +178,5 @@ pub fn maybe_tls_key() -> Option<tls::Key> { #[inline] #[cfg(test)] pub fn maybe_tls_key() -> Option<tls::Key> { - unsafe { ::cast::transmute(::realstd::rt::local_ptr::maybe_tls_key()) } + unsafe { ::cast::transmute(::realstd::rt::shouldnt_be_public::maybe_tls_key()) } } diff --git a/src/libstd/rt/macros.rs b/src/libstd/rt/macros.rs new file mode 100644 index 00000000000..c6ff3427c15 --- /dev/null +++ b/src/libstd/rt/macros.rs @@ -0,0 +1,48 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +//! Macros used by the runtime. +//! +//! These macros call functions which are only accessible in the `rt` module, so +//! they aren't defined anywhere outside of the `rt` module. + +#[macro_escape]; + +macro_rules! rterrln ( + ($($arg:tt)*) => ( { + format_args!(::rt::util::dumb_println, $($arg)*) + } ) +) + +// Some basic logging. Enabled by passing `--cfg rtdebug` to the libstd build. +macro_rules! rtdebug ( + ($($arg:tt)*) => ( { + if cfg!(rtdebug) { + rterrln!($($arg)*) + } + }) +) + +macro_rules! rtassert ( + ( $arg:expr ) => ( { + if ::rt::util::ENFORCE_SANITY { + if !$arg { + rtabort!("assertion failed: {}", stringify!($arg)); + } + } + } ) +) + + +macro_rules! rtabort ( + ($($msg:tt)*) => ( { + ::rt::util::abort(format!($($msg)*)); + } ) +) diff --git a/src/libstd/rt/mod.rs b/src/libstd/rt/mod.rs index 2db973b602e..78f0bb0a07c 100644 --- a/src/libstd/rt/mod.rs +++ b/src/libstd/rt/mod.rs @@ -76,6 +76,16 @@ use vec::{OwnedVector, MutableVector, ImmutableVector}; use self::thread::Thread; use self::work_queue::WorkQueue; +// the os module needs to reach into this helper, so allow general access +// through this reexport. +pub use self::util::set_exit_status; + +// this is somewhat useful when a program wants to spawn a "reasonable" number +// of workers based on the constraints of the system that it's running on. +// Perhaps this shouldn't be a `pub use` though and there should be another +// method... +pub use self::util::default_sched_threads; + // XXX: these probably shouldn't be public... #[doc(hidden)] pub mod shouldnt_be_public { @@ -86,8 +96,12 @@ pub mod shouldnt_be_public { pub use super::select::SelectInner; pub use super::rtio::EventLoop; pub use super::select::{SelectInner, SelectPortInner}; + pub use super::local_ptr::maybe_tls_key; } +// Internal macros used by the runtime. +mod macros; + /// The global (exchange) heap. pub mod global_heap; @@ -158,17 +172,14 @@ pub mod comm; mod select; -// FIXME #5248 shouldn't be pub /// The runtime needs to be able to put a pointer into thread-local storage. -pub mod local_ptr; +mod local_ptr; -// FIXME #5248: The import in `sched` doesn't resolve unless this is pub! /// Bindings to pthread/windows thread-local storage. -pub mod thread_local_storage; +mod thread_local_storage; -// FIXME #5248 shouldn't be pub /// Just stuff -pub mod util; +mod util; // Global command line argument storage pub mod args; diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs index 71ab3b571c4..d5278975d8d 100644 --- a/src/libstd/rt/task.rs +++ b/src/libstd/rt/task.rs @@ -17,7 +17,7 @@ use borrow; use cast::transmute; use cleanup; use local_data; -use libc::{c_void, uintptr_t}; +use libc::{c_void, uintptr_t, c_char, size_t}; use prelude::*; use option::{Option, Some, None}; use rt::borrowck; @@ -465,6 +465,48 @@ impl Unwinder { } } +/// This is the entry point of unwinding for things like lang items and such. +/// The arguments are normally generated by the compiler. +pub fn begin_unwind(msg: *c_char, file: *c_char, line: size_t) -> ! { + use rt::in_green_task_context; + use rt::task::Task; + use rt::local::Local; + use rt::logging::Logger; + use str::Str; + use c_str::CString; + + unsafe { + let msg = CString::new(msg, false); + let file = CString::new(file, false); + let msg = match msg.as_str() { + Some(s) => s, None => rtabort!("message wasn't utf8?") + }; + let file = match file.as_str() { + Some(s) => s, None => rtabort!("message wasn't utf8?") + }; + + if in_green_task_context() { + // Be careful not to allocate in this block, if we're failing we may + // have been failing due to a lack of memory in the first place... + do Local::borrow |task: &mut Task| { + let n = task.name.as_ref().map(|n| n.as_slice()).unwrap_or("<unnamed>"); + format_args!(|args| { task.logger.log(args) }, + "task '{}' failed at '{}', {}:{}", + n, msg, file, line); + } + } else { + rterrln!("failed in non-task context at '{}', {}:{}", + msg, file, line as int); + } + + let task: *mut Task = Local::unsafe_borrow(); + if (*task).unwinder.unwinding { + rtabort!("unwinding again"); + } + (*task).unwinder.begin_unwind(); + } +} + #[cfg(test)] mod test { use rt::test::*; diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs index 727bdb782d2..647d88c26f2 100644 --- a/src/libstd/rt/util.rs +++ b/src/libstd/rt/util.rs @@ -16,8 +16,6 @@ use option::{Some, None, Option}; use os; use str::StrSlice; use unstable::atomics::{AtomicInt, INIT_ATOMIC_INT, SeqCst}; - -#[cfg(target_os="macos")] use unstable::running_on_valgrind; // Indicates whether we should perform expensive sanity checks, including rtassert! @@ -37,21 +35,17 @@ pub fn num_cpus() -> uint { } } -/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors wired into it; this -/// is a hard limit and requires rebuilding valgrind if you want to go beyond it. Normally this is -/// not a problem, but in some tests, we produce a lot of threads casually. Making lots of threads -/// alone might not be a problem _either_, except on OSX, the segments produced for new threads -/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv schedulers fork off -/// a separate thread for polling fsevents on OSX, we get a perfect storm of creating "too many -/// mappings" for valgrind to handle when running certain stress tests in the runtime. -#[cfg(target_os="macos")] -pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool { - running_on_valgrind() -} - -#[cfg(not(target_os="macos"))] +/// Valgrind has a fixed-sized array (size around 2000) of segment descriptors +/// wired into it; this is a hard limit and requires rebuilding valgrind if you +/// want to go beyond it. Normally this is not a problem, but in some tests, we +/// produce a lot of threads casually. Making lots of threads alone might not +/// be a problem _either_, except on OSX, the segments produced for new threads +/// _take a while_ to get reclaimed by the OS. Combined with the fact that libuv +/// schedulers fork off a separate thread for polling fsevents on OSX, we get a +/// perfect storm of creating "too many mappings" for valgrind to handle when +/// running certain stress tests in the runtime. pub fn limit_thread_creation_due_to_osx_and_valgrind() -> bool { - false + (cfg!(target_os="macos")) && running_on_valgrind() } /// Get's the number of scheduler threads requested by the environment |
