Skip to content

Commit 43400f4

Browse files
authored
hotfix(lab1): rm alloc from panic (#58)
* hotfix(lab1): rm std crate alloc * fix: make panic no alloc
1 parent 0ebdb33 commit 43400f4

4 files changed

Lines changed: 14 additions & 18 deletions

File tree

src/0x01/crates/kernel/src/lib.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
#![feature(abi_x86_interrupt)]
33
#![feature(type_alias_impl_trait)]
44

5-
extern crate alloc;
65
#[macro_use]
76
extern crate log;
87
extern crate libm;
@@ -13,8 +12,6 @@ pub use utils::*;
1312

1413
mod drivers;
1514

16-
pub use alloc::format;
17-
1815
use boot::BootInfo;
1916
use uefi::{Status, runtime::ResetType};
2017

src/0x01/crates/kernel/src/utils/macros.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use alloc::string::ToString;
2-
use core::{arch::asm, fmt::*};
1+
use core::{arch::asm, fmt::*, panic::Location};
32

43
use x86_64::instructions::interrupts;
54

@@ -74,20 +73,20 @@ fn panic(info: &core::panic::PanicInfo) -> ! {
7473
// force unlock serial for panic output
7574
unsafe { SERIAL.get().unwrap().force_unlock() };
7675

77-
let location = if let Some(location) = info.location() {
78-
alloc::format!(
79-
"{}:{}:{}",
80-
location.file(),
81-
location.line(),
82-
location.column()
83-
)
84-
} else {
85-
"Unknown location".to_string()
86-
};
76+
struct PanicLocation<'a>(Option<&'a Location<'a>>);
77+
78+
impl Display for PanicLocation<'_> {
79+
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
80+
match self.0 {
81+
Some(loc) => Display::fmt(loc, f),
82+
None => f.write_str("unknown location"),
83+
}
84+
}
85+
}
8786

8887
error!(
8988
"\n\n\rERROR: panicked at {}\n\n\r{}\n",
90-
location,
89+
PanicLocation(info.location()),
9190
info.message()
9291
);
9392

src/0x04/crates/lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![cfg_attr(not(test), no_std)]
22
#![allow(dead_code, unused_imports)]
3-
#![feature(alloc_error_handler)]
3+
#![cfg_attr(not(test), feature(alloc_error_handler))]
44

55
#[macro_use]
66
pub mod macros;

src/0x07/crates/lib/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#![allow(dead_code, unused_imports)]
2-
#![feature(alloc_error_handler)]
2+
#![cfg_attr(not(test), feature(alloc_error_handler))]
33
#![cfg_attr(not(test), no_std)]
44

55
#[macro_use]

0 commit comments

Comments
 (0)