Skip to content

Commit

Permalink
[Kernel - Rust] Only set global allocator / panic handler when target…
Browse files Browse the repository at this point in the history
…ing the axle kernel build
  • Loading branch information
codyd51 committed Feb 7, 2024
1 parent 6a1a079 commit bcf6db4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rust_kernel_libs/ffi_bindings/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![no_std]
#![cfg_attr(target_os = "axle_kernel", no_std)]
#![feature(format_args_nl)]
#![feature(core_intrinsics)]
#![feature(panic_info_message)]
Expand Down Expand Up @@ -95,6 +95,7 @@ macro_rules! internal_println {
})
}

#[cfg(target_os = "axle_kernel")]
#[panic_handler]
pub fn panic(panic_info: &PanicInfo<'_>) -> ! {
let msg = match panic_info.message() {
Expand Down Expand Up @@ -125,6 +126,7 @@ pub fn panic(panic_info: &PanicInfo<'_>) -> ! {

pub struct Dummy;

#[cfg(target_os = "axle_kernel")]
unsafe impl GlobalAlloc for Dummy {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
kmalloc(layout.size()) as *mut u8
Expand All @@ -134,6 +136,7 @@ unsafe impl GlobalAlloc for Dummy {
}
}

#[cfg(target_os = "axle_kernel")]
#[global_allocator]
pub static ALLOCATOR: Dummy = Dummy;

Expand Down

0 comments on commit bcf6db4

Please sign in to comment.