提交 07e52eb7 编写于 作者: B Brian Anderson

std: Make os::set_exit_status work with newsched

上级 ec6d4a17
......@@ -1134,8 +1134,15 @@ unsafe fn FormatMessageA(flags: DWORD, lpSrc: LPVOID,
* ignored and the process exits with the default failure status
*/
pub fn set_exit_status(code: int) {
unsafe {
rustrt::rust_set_exit_status(code as libc::intptr_t);
use rt;
use rt::OldTaskContext;
if rt::context() == OldTaskContext {
unsafe {
rustrt::rust_set_exit_status(code as libc::intptr_t);
}
} else {
rt::util::set_exit_status(code);
}
}
......
......@@ -260,7 +260,15 @@ pub fn run(main: ~fn()) -> int {
}
unsafe {
let exit_code = if exit_success { 0 } else { DEFAULT_ERROR_CODE };
let exit_code = if exit_success {
use rt::util;
// If we're exiting successfully, then return the global
// exit status, which can be set programmatically.
util::get_exit_status()
} else {
DEFAULT_ERROR_CODE
};
(*exit_code_clone.get()).store(exit_code, SeqCst);
}
};
......
......@@ -97,3 +97,25 @@ pub fn abort(msg: &str) -> ! {
unsafe { libc::abort(); }
}
pub fn set_exit_status(code: int) {
unsafe {
return rust_set_exit_status_newrt(code as libc::uintptr_t);
}
extern {
fn rust_set_exit_status_newrt(code: libc::uintptr_t);
}
}
pub fn get_exit_status() -> int {
unsafe {
return rust_get_exit_status_newrt() as int;
}
extern {
fn rust_get_exit_status_newrt() -> libc::uintptr_t;
}
}
\ No newline at end of file
......@@ -960,6 +960,21 @@ rust_get_global_args_ptr() {
return &global_args_ptr;
}
static lock_and_signal exit_status_lock;
static uintptr_t exit_status = 0;
extern "C" CDECL void
rust_set_exit_status_newrt(uintptr_t code) {
scoped_lock with(exit_status_lock);
exit_status = code;
}
extern "C" CDECL uintptr_t
rust_get_exit_status_newrt() {
scoped_lock with(exit_status_lock);
return exit_status;
}
//
// Local Variables:
// mode: C++
......
......@@ -270,3 +270,5 @@ rust_get_global_args_ptr
rust_current_boxed_region
rust_take_global_args_lock
rust_drop_global_args_lock
rust_set_exit_status_newrt
rust_get_exit_status_newrt
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册