1 // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
11 //! Runtime calls emitted by the compiler.
15 use libc::{c_char, c_void, size_t, uintptr_t};
16 use option::{Option, None, Some};
23 pub fn fail_(expr: *c_char, file: *c_char, line: size_t) -> ! {
24 sys::begin_unwind_(expr, file, line);
27 #[lang="fail_bounds_check"]
28 pub fn fail_bounds_check(file: *c_char, line: size_t,
29 index: size_t, len: size_t) {
30 let msg = fmt!("index out of bounds: the len is %d but the index is %d",
31 len as int, index as int);
32 do msg.with_c_str |buf| {
33 fail_(buf, file, line);
38 pub unsafe fn local_malloc(td: *c_char, size: uintptr_t) -> *c_char {
39 // XXX: Unsafe borrow for speed. Lame.
40 let task: Option<*mut Task> = Local::try_unsafe_borrow();
43 (*task).heap.alloc(td as *c_void, size as uint) as *c_char
45 None => rtabort!("local malloc outside of task")
49 // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
50 // inside a landing pad may corrupt the state of the exception handler. If a
51 // problem occurs, call exit instead.
53 pub unsafe fn local_free(ptr: *c_char) {
54 ::rt::local_heap::local_free(ptr);
57 #[lang="borrow_as_imm"]
59 pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
60 borrowck::borrow_as_imm(a, file, line)
63 #[lang="borrow_as_mut"]
65 pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
66 borrowck::borrow_as_mut(a, file, line)
69 #[lang="record_borrow"]
70 pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
71 file: *c_char, line: size_t) {
72 borrowck::record_borrow(a, old_ref_count, file, line)
75 #[lang="unrecord_borrow"]
76 pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
77 file: *c_char, line: size_t) {
78 borrowck::unrecord_borrow(a, old_ref_count, file, line)
81 #[lang="return_to_mut"]
83 pub unsafe fn return_to_mut(a: *u8, orig_ref_count: uint,
84 file: *c_char, line: size_t) {
85 borrowck::return_to_mut(a, orig_ref_count, file, line)
88 #[lang="check_not_borrowed"]
90 pub unsafe fn check_not_borrowed(a: *u8,
93 borrowck::check_not_borrowed(a, file, line)
98 pub fn start(main: *u8, argc: int, argv: **c_char,
99 crate_map: *u8) -> int {
103 return do rt::start(argc, argv as **u8, crate_map) {
104 let main: extern "Rust" fn() = transmute(main);
112 pub fn start(main: *u8, argc: int, argv: **c_char) -> int {
116 return do rt::start(argc, argv as **u8) {
117 let main: extern "Rust" fn() = transmute(main);