From 8c0be73224731eb217e1bc7a8c3c606eb918635f Mon Sep 17 00:00:00 2001
From: bjorn3 <17426603+bjorn3@users.noreply.github.com>
Date: Tue, 4 Jul 2023 15:12:12 +0200
Subject: [PATCH] Build the kernel with panic=abort

This reduces the kernel size and avoids the need to define the
eh_personality lang item.
---
 .cargo/config |  1 -
 Cargo.toml    |  6 ++++++
 src/lib.rs    |  1 -
 src/panic.rs  | 13 -------------
 4 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/.cargo/config b/.cargo/config
index 20ee1ec9..d51b0f55 100644
--- a/.cargo/config
+++ b/.cargo/config
@@ -6,4 +6,3 @@ rustflags = [
 
 [unstable]
 build-std = ["core", "alloc", "compiler_builtins"]
-build-std-features = ["panic-unwind"]
diff --git a/Cargo.toml b/Cargo.toml
index 1a443a1d..f2a5c2c8 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -61,8 +61,14 @@ slab = ["slab_allocator"]
 x86_fsgsbase = []
 
 [profile.dev]
+# Avoids having to define the eh_personality lang item and reduces kernel size
+panic = "abort"
+
 # Kernel doesn't yet work great with debug mode :(
 opt-level = 3
 
 [profile.release]
+# Avoids having to define the eh_personality lang item and reduces kernel size
+panic = "abort"
+
 lto = true
diff --git a/src/lib.rs b/src/lib.rs
index 1e941301..5bde061a 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -50,7 +50,6 @@
 #![feature(concat_idents)]
 #![feature(core_intrinsics)]
 #![feature(integer_atomics)]
-#![feature(lang_items)]
 #![feature(naked_functions)]
 #![feature(ptr_internals)]
 #![feature(slice_ptr_get, slice_ptr_len)]
diff --git a/src/panic.rs b/src/panic.rs
index 3655327f..e7eb44b4 100644
--- a/src/panic.rs
+++ b/src/panic.rs
@@ -5,10 +5,6 @@ use core::panic::PanicInfo;
 
 use crate::{cpu_id, context, interrupt, syscall};
 
-#[lang = "eh_personality"]
-#[no_mangle]
-pub extern "C" fn rust_eh_personality() {}
-
 /// Required to handle panics
 #[panic_handler]
 #[no_mangle]
@@ -44,12 +40,3 @@ pub extern "C" fn rust_begin_unwind(info: &PanicInfo) -> ! {
 pub extern fn rust_oom(_layout: Layout) -> ! {
     panic!("kernel memory allocation failed");
 }
-
-#[allow(non_snake_case)]
-#[no_mangle]
-/// Required to handle panics
-pub extern "C" fn _Unwind_Resume() -> ! {
-    loop {
-        unsafe { interrupt::halt(); }
-    }
-}
-- 
GitLab