-
Notifications
You must be signed in to change notification settings - Fork 83
/
runtime_glue.rs
59 lines (48 loc) · 1.6 KB
/
runtime_glue.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Copyright (c) 2017 Stefan Lankes, RWTH Aachen University
// 2018 Colin Finck, RWTH Aachen University
//
// Licensed under the Apache License, Version 2.0, <LICENSE-APACHE or
// http://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.
//! Minor functions that Rust really expects to be defined by the compiler,
//! but which we need to provide manually because we're on bare metal.
use crate::arch::kernel::processor::run_on_hypervisor;
use crate::{__sys_shutdown, arch};
use alloc::alloc::Layout;
use core::panic::PanicInfo;
// see https://users.rust-lang.org/t/psa-breaking-change-panic-fmt-language-item-removed-in-favor-of-panic-implementation/17875
#[cfg(target_os = "hermit")]
#[panic_handler]
fn panic(info: &PanicInfo<'_>) -> ! {
print!("[{}][!!!PANIC!!!] ", arch::percore::core_id());
if let Some(location) = info.location() {
print!("{}:{}: ", location.file(), location.line());
}
if let Some(message) = info.message() {
print!("{}", message);
}
println!();
if run_on_hypervisor() {
__sys_shutdown(1);
}
loop {
arch::processor::halt();
}
}
#[alloc_error_handler]
fn rust_oom(layout: Layout) -> ! {
println!(
"[{}][!!!OOM!!!] Memory allocation of {} bytes failed",
arch::percore::core_id(),
layout.size()
);
loop {
arch::processor::halt();
}
}
#[no_mangle]
pub unsafe extern "C" fn __rg_oom(size: usize, align: usize) -> ! {
let layout = Layout::from_size_align_unchecked(size, align);
rust_oom(layout)
}