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-07-10 17:52:05 -05:00
|
|
|
//! Runtime calls emitted by the compiler.
|
|
|
|
|
2013-08-03 19:13:14 -05:00
|
|
|
use c_str::ToCStr;
|
2013-01-11 23:01:42 -06:00
|
|
|
use cast::transmute;
|
2013-10-09 12:34:27 -05:00
|
|
|
use libc::{c_char, size_t, uintptr_t};
|
|
|
|
use rt::task;
|
2013-06-22 18:52:40 -05:00
|
|
|
use rt::borrowck;
|
2012-07-10 17:52:05 -05:00
|
|
|
|
2013-01-07 14:21:34 -06:00
|
|
|
#[lang="fail_"]
|
2013-02-27 20:34:04 -06:00
|
|
|
pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
|
2013-10-09 12:34:27 -05:00
|
|
|
task::begin_unwind(expr, file, line);
|
2012-07-10 17:52:05 -05:00
|
|
|
}
|
|
|
|
|
2013-01-07 14:21:34 -06:00
|
|
|
#[lang="fail_bounds_check"]
|
2013-04-09 00:31:23 -05:00
|
|
|
pub fn fail_bounds_check(file: *c_char, line: size_t,
|
2013-05-01 08:14:47 -05:00
|
|
|
index: size_t, len: size_t) {
|
2013-09-27 19:02:31 -05:00
|
|
|
let msg = format!("index out of bounds: the len is {} but the index is {}",
|
2013-10-14 21:43:03 -05:00
|
|
|
len as uint, index as uint);
|
2013-08-14 21:21:59 -05:00
|
|
|
do msg.with_c_str |buf| {
|
2013-07-22 23:45:33 -05:00
|
|
|
fail_(buf, file, line);
|
2012-09-29 06:34:11 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-07 14:21:34 -06:00
|
|
|
#[lang="malloc"]
|
2013-02-27 20:34:04 -06:00
|
|
|
pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
|
2013-10-09 12:34:27 -05:00
|
|
|
::rt::local_heap::local_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.
|
2013-01-07 14:21:34 -06:00
|
|
|
#[lang="free"]
|
2013-02-27 20:34:04 -06:00
|
|
|
pub unsafe fn local_free(ptr: *c_char) {
|
2013-06-22 03:09:06 -05:00
|
|
|
::rt::local_heap::local_free(ptr);
|
2012-07-17 12:48:19 -05:00
|
|
|
}
|
|
|
|
|
2013-05-01 09:29:47 -05:00
|
|
|
#[lang="borrow_as_imm"]
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-05-01 12:48:00 -05:00
|
|
|
pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::borrow_as_imm(a, file, line)
|
2013-05-01 09:29:47 -05:00
|
|
|
}
|
|
|
|
|
2013-05-01 12:48:00 -05:00
|
|
|
#[lang="borrow_as_mut"]
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-05-01 12:48:00 -05:00
|
|
|
pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::borrow_as_mut(a, file, line)
|
2013-05-01 12:48:00 -05:00
|
|
|
}
|
|
|
|
|
2013-05-03 04:42:00 -05:00
|
|
|
#[lang="record_borrow"]
|
|
|
|
pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
|
|
|
|
file: *c_char, line: size_t) {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::record_borrow(a, old_ref_count, file, line)
|
2013-05-03 04:42:00 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
#[lang="unrecord_borrow"]
|
|
|
|
pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
|
|
|
|
file: *c_char, line: size_t) {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::unrecord_borrow(a, old_ref_count, file, line)
|
2013-05-03 04:42:00 -05:00
|
|
|
}
|
|
|
|
|
2013-05-01 12:48:00 -05:00
|
|
|
#[lang="return_to_mut"]
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-05-04 13:25:15 -05:00
|
|
|
pub unsafe fn return_to_mut(a: *u8, orig_ref_count: uint,
|
2013-05-01 20:46:34 -05:00
|
|
|
file: *c_char, line: size_t) {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::return_to_mut(a, orig_ref_count, file, line)
|
2013-05-01 12:48:00 -05:00
|
|
|
}
|
|
|
|
|
2013-05-01 08:14:47 -05:00
|
|
|
#[lang="check_not_borrowed"]
|
2013-06-18 16:45:18 -05:00
|
|
|
#[inline]
|
2013-05-01 08:14:47 -05:00
|
|
|
pub unsafe fn check_not_borrowed(a: *u8,
|
|
|
|
file: *c_char,
|
|
|
|
line: size_t) {
|
2013-06-22 18:52:40 -05:00
|
|
|
borrowck::check_not_borrowed(a, file, line)
|
2013-01-11 23:01:42 -06:00
|
|
|
}
|
|
|
|
|
2013-09-18 03:58:52 -05:00
|
|
|
#[lang="start"]
|
|
|
|
pub fn start(main: *u8, argc: int, argv: **c_char) -> int {
|
|
|
|
use rt;
|
|
|
|
|
|
|
|
unsafe {
|
|
|
|
return do rt::start(argc, argv as **u8) {
|
|
|
|
let main: extern "Rust" fn() = transmute(main);
|
|
|
|
main();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|