2012-12-03 18:48:01 -06:00
|
|
|
// 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.
|
|
|
|
|
2012-11-30 02:47:45 -06:00
|
|
|
#[legacy_exports];
|
|
|
|
|
2012-08-14 18:25:42 -05:00
|
|
|
// NB: transitionary, de-mode-ing.
|
|
|
|
#[forbid(deprecated_mode)];
|
|
|
|
#[forbid(deprecated_pattern)];
|
2012-07-10 17:52:05 -05:00
|
|
|
//! Runtime calls emitted by the compiler.
|
|
|
|
|
2012-12-23 16:41:37 -06:00
|
|
|
use libc::{c_char, c_void, size_t, uintptr_t};
|
|
|
|
use str;
|
|
|
|
use sys;
|
2012-07-10 17:52:05 -05:00
|
|
|
|
2012-09-07 20:08:21 -05:00
|
|
|
use gc::{cleanup_stack_for_failure, gc, Word};
|
2012-07-16 14:28:15 -05:00
|
|
|
|
2012-09-02 17:39:37 -05:00
|
|
|
#[allow(non_camel_case_types)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub type rust_task = c_void;
|
2012-07-10 17:52:05 -05:00
|
|
|
|
|
|
|
extern mod rustrt {
|
2012-07-17 12:48:19 -05:00
|
|
|
#[rust_stack]
|
|
|
|
fn rust_upcall_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char;
|
|
|
|
|
|
|
|
#[rust_stack]
|
|
|
|
fn rust_upcall_exchange_free(ptr: *c_char);
|
|
|
|
|
|
|
|
#[rust_stack]
|
|
|
|
fn rust_upcall_malloc(td: *c_char, size: uintptr_t) -> *c_char;
|
|
|
|
|
|
|
|
#[rust_stack]
|
|
|
|
fn rust_upcall_free(ptr: *c_char);
|
2012-07-10 17:52:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME (#2861): This needs both the attribute, and the name prefixed with
|
|
|
|
// 'rt_', otherwise the compiler won't find it. To fix this, see
|
|
|
|
// gather_rust_rtcalls.
|
2012-09-12 13:51:44 -05:00
|
|
|
#[rt(fail_)]
|
2012-11-27 20:05:20 -06:00
|
|
|
pub fn rt_fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
|
2012-12-10 19:22:10 -06:00
|
|
|
sys::begin_unwind_(expr, file, line);
|
2012-07-10 17:52:05 -05:00
|
|
|
}
|
|
|
|
|
2012-09-29 06:34:11 -05:00
|
|
|
#[rt(fail_bounds_check)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub fn rt_fail_bounds_check(file: *c_char, line: size_t,
|
2012-09-29 06:34:11 -05:00
|
|
|
index: size_t, len: size_t) {
|
|
|
|
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
|
|
|
|
len as int, index as int);
|
|
|
|
do str::as_buf(msg) |p, _len| {
|
|
|
|
rt_fail_(p as *c_char, file, line);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-17 12:48:19 -05:00
|
|
|
#[rt(exchange_malloc)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub fn rt_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
2012-08-01 19:30:05 -05:00
|
|
|
return rustrt::rust_upcall_exchange_malloc(td, size);
|
2012-07-17 12:48:19 -05:00
|
|
|
}
|
|
|
|
|
2012-07-23 18:00:19 -05:00
|
|
|
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
|
|
|
|
// inside a landing pad may corrupt the state of the exception handler. If a
|
|
|
|
// problem occurs, call exit instead.
|
2012-07-17 12:48:19 -05:00
|
|
|
#[rt(exchange_free)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub fn rt_exchange_free(ptr: *c_char) {
|
2012-07-17 12:48:19 -05:00
|
|
|
rustrt::rust_upcall_exchange_free(ptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[rt(malloc)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub fn rt_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
2012-08-01 19:30:05 -05:00
|
|
|
return rustrt::rust_upcall_malloc(td, size);
|
2012-07-17 12:48:19 -05:00
|
|
|
}
|
|
|
|
|
2012-07-23 18:00:19 -05:00
|
|
|
// NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
|
|
|
|
// inside a landing pad may corrupt the state of the exception handler. If a
|
|
|
|
// problem occurs, call exit instead.
|
2012-07-17 12:48:19 -05:00
|
|
|
#[rt(free)]
|
2012-10-02 18:31:52 -05:00
|
|
|
pub fn rt_free(ptr: *c_char) {
|
2012-07-17 12:48:19 -05:00
|
|
|
rustrt::rust_upcall_free(ptr);
|
|
|
|
}
|
|
|
|
|
2012-07-10 17:52:05 -05:00
|
|
|
// Local Variables:
|
|
|
|
// mode: rust;
|
|
|
|
// fill-column: 78;
|
|
|
|
// indent-tabs-mode: nil
|
|
|
|
// c-basic-offset: 4
|
|
|
|
// buffer-file-coding-system: utf-8-unix
|
|
|
|
// End:
|