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-08-11 02:17:01 -05:00
|
|
|
use libc::{c_char, c_void, size_t, uintptr_t};
|
2012-12-23 16:41:37 -06:00
|
|
|
use sys;
|
2013-05-19 18:50:21 -05:00
|
|
|
use rt::task::Task;
|
|
|
|
use rt::local::Local;
|
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) -> ! {
|
2012-12-10 19:22:10 -06:00
|
|
|
sys::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) {
|
2012-09-29 06:34:11 -05:00
|
|
|
let msg = fmt!("index out of bounds: the len is %d but the index is %d",
|
|
|
|
len as int, index as int);
|
2013-08-03 19:13:14 -05:00
|
|
|
do msg.to_c_str().with_ref |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-08-01 01:12:20 -05:00
|
|
|
let mut alloc = ::ptr::null();
|
|
|
|
do Local::borrow::<Task,()> |task| {
|
|
|
|
rtdebug!("task pointer: %x, heap pointer: %x",
|
|
|
|
::borrow::to_uint(task),
|
|
|
|
::borrow::to_uint(&task.heap));
|
|
|
|
alloc = task.heap.alloc(td as *c_void, size as uint) as *c_char;
|
2013-04-21 21:03:52 -05:00
|
|
|
}
|
2013-08-01 01:12:20 -05:00
|
|
|
return alloc;
|
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-06-22 03:09:06 -05:00
|
|
|
#[lang="annihilate"]
|
|
|
|
pub unsafe fn annihilate() {
|
|
|
|
::cleanup::annihilate()
|
|
|
|
}
|
|
|
|
|
2013-02-26 21:40:39 -06:00
|
|
|
#[lang="start"]
|
2013-03-30 21:59:21 -05:00
|
|
|
pub fn start(main: *u8, argc: int, argv: **c_char,
|
|
|
|
crate_map: *u8) -> int {
|
2013-05-08 16:52:30 -05:00
|
|
|
use rt;
|
2013-03-30 21:59:21 -05:00
|
|
|
|
|
|
|
unsafe {
|
2013-08-01 01:12:20 -05:00
|
|
|
return do rt::start(argc, argv as **u8, crate_map) {
|
|
|
|
let main: extern "Rust" fn() = transmute(main);
|
|
|
|
main();
|
|
|
|
};
|
2013-03-30 21:59:21 -05:00
|
|
|
}
|
|
|
|
}
|