2013-06-17 22:17:51 -07:00
|
|
|
// Copyright 2013 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.
|
2014-11-23 19:21:17 -08:00
|
|
|
|
2014-12-10 19:46:38 -08:00
|
|
|
use fmt;
|
2015-09-08 15:53:46 -07:00
|
|
|
use io::prelude::*;
|
2015-03-11 15:24:14 -07:00
|
|
|
use sys::stdio::Stderr;
|
2015-09-08 15:53:46 -07:00
|
|
|
use thread;
|
2013-08-16 23:14:55 -07:00
|
|
|
|
2014-12-27 23:57:43 +02:00
|
|
|
pub fn dumb_print(args: fmt::Arguments) {
|
2015-06-09 21:39:36 -07:00
|
|
|
let _ = Stderr::new().map(|mut stderr| stderr.write_fmt(args));
|
2014-12-27 23:57:43 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-23 00:16:26 -04:00
|
|
|
// Other platforms should use the appropriate platform-specific mechanism for
|
|
|
|
|
// aborting the process. If no platform-specific mechanism is available,
|
|
|
|
|
// ::intrinsics::abort() may be used instead. The above implementations cover
|
|
|
|
|
// all targets currently supported by libstd.
|
|
|
|
|
|
2014-12-29 19:40:57 -08:00
|
|
|
pub fn abort(args: fmt::Arguments) -> ! {
|
2016-01-09 19:19:56 +00:00
|
|
|
dumb_print(format_args!("fatal runtime error: {}\n", args));
|
2016-09-30 23:07:04 +00:00
|
|
|
unsafe { ::sys::abort_internal(); }
|
2014-11-23 19:21:17 -08:00
|
|
|
}
|
|
|
|
|
|
2015-09-08 15:53:46 -07:00
|
|
|
#[allow(dead_code)] // stack overflow detection not enabled on all platforms
|
2014-11-23 19:21:17 -08:00
|
|
|
pub unsafe fn report_overflow() {
|
2016-01-09 19:19:56 +00:00
|
|
|
dumb_print(format_args!("\nthread '{}' has overflowed its stack\n",
|
2015-09-08 15:53:46 -07:00
|
|
|
thread::current().name().unwrap_or("<unknown>")));
|
2014-11-23 19:21:17 -08:00
|
|
|
}
|