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::{Some, None};
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.to_c_str().with_ref |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 match Local::try_unsafe_borrow::<Task>() {
42 (*task).heap.alloc(td as *c_void, size as uint) as *c_char
44 None => rtabort!("local malloc outside of task")
48 // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
49 // inside a landing pad may corrupt the state of the exception handler. If a
50 // problem occurs, call exit instead.
52 pub unsafe fn local_free(ptr: *c_char) {
53 ::rt::local_heap::local_free(ptr);
56 #[lang="borrow_as_imm"]
58 pub unsafe fn borrow_as_imm(a: *u8, file: *c_char, line: size_t) -> uint {
59 borrowck::borrow_as_imm(a, file, line)
62 #[lang="borrow_as_mut"]
64 pub unsafe fn borrow_as_mut(a: *u8, file: *c_char, line: size_t) -> uint {
65 borrowck::borrow_as_mut(a, file, line)
68 #[lang="record_borrow"]
69 pub unsafe fn record_borrow(a: *u8, old_ref_count: uint,
70 file: *c_char, line: size_t) {
71 borrowck::record_borrow(a, old_ref_count, file, line)
74 #[lang="unrecord_borrow"]
75 pub unsafe fn unrecord_borrow(a: *u8, old_ref_count: uint,
76 file: *c_char, line: size_t) {
77 borrowck::unrecord_borrow(a, old_ref_count, file, line)
80 #[lang="return_to_mut"]
82 pub unsafe fn return_to_mut(a: *u8, orig_ref_count: uint,
83 file: *c_char, line: size_t) {
84 borrowck::return_to_mut(a, orig_ref_count, file, line)
87 #[lang="check_not_borrowed"]
89 pub unsafe fn check_not_borrowed(a: *u8,
92 borrowck::check_not_borrowed(a, file, line)
96 pub unsafe fn annihilate() {
97 ::cleanup::annihilate()
101 pub fn start(main: *u8, argc: int, argv: **c_char,
102 crate_map: *u8) -> int {
106 return do rt::start(argc, argv as **u8, crate_map) {
107 let main: extern "Rust" fn() = transmute(main);