Skip to content

Commit

Permalink
Stack unwinding support for cleaning up panicked tasks (#197)
Browse files Browse the repository at this point in the history
* This is a major new feature that allows full and proper recovery from a panic. We now use DWARF debugging information to unwind a task's call stack upon panic. DWARF info is parsed from `.eh_frame` and `.gcc_except_table`.

* Use explicit address ranges in LoadedCrates and Sections, which is clearer and allows faster lockless searching.

* Add support for relocation type R_X86_64_PLT32, which is the same as R_X86_64_PC32.
  • Loading branch information
kevinaboos committed Sep 28, 2019
1 parent 4fc99ff commit d4ca13c
Show file tree
Hide file tree
Showing 24 changed files with 1,839 additions and 456 deletions.
26 changes: 21 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions applications/unwind_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern crate task;


use alloc::vec::Vec;
use alloc::boxed::Box;
use alloc::string::String;


Expand All @@ -20,6 +21,10 @@ impl Drop for MyStruct {

#[inline(never)]
fn foo() {
let _res = task::set_my_panic_handler(Box::new(|info| {
info!("Unwind test caught panic at {}", info);
}));

let _my_struct = MyStruct(10);
panic!("intentional panic in unwind_test::foo()");
}
Expand Down
2 changes: 1 addition & 1 deletion book/src/ch00-00-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ One-line summaries of what each crate includes (may be incomplete):
* `mod_mgmt`: Module management, including parsing, loading, linking, unloading, and metadata management.
* `mouse`: simple PS2 mouse driver.
* `nano-core`: a tiny module that is responsible for bootstrapping the OS at startup.
* `panic_unwind`: Default entry point for panics and unwinding, as required by the Rust compiler.
* `panic_entry`: Default entry point for panics and unwinding, as required by the Rust compiler.
* `panic_wrapper`: Wrapper functions for handling and propagating panics.
* `path`: contains functions for navigating the filesystem / getting pointers to specific directories via the Path struct
* `pci`: Basic PCI support for Theseus, x86 only.
Expand Down
2 changes: 1 addition & 1 deletion cfg/x86_64-theseus.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@
"os": "none",
"features": "-mmx,-sse,+soft-float",
"disable-redzone": true,
"panic": "abort"
"panic": "unwind"
}
2 changes: 1 addition & 1 deletion kernel/_doc_root.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
//! * `mod_mgmt`: Module management, including parsing, loading, linking, unloading, and metadata management.
//! * `mouse`: simple PS2 mouse driver.
//! * `nano-core`: a tiny module that is responsible for bootstrapping the OS at startup.
//! * `panic_unwind`: Default entry point for panics and unwinding, as required by the Rust compiler.
//! * `panic_entry`: Default entry point for panics and unwinding, as required by the Rust compiler.
//! * `panic_wrapper`: Wrapper functions for handling and propagating panics.
//! * `path`: contains functions for navigating the filesystem / getting pointers to specific directories via the Path struct
//! * `pci`: Basic PCI support for Theseus, x86 only.
Expand Down
2 changes: 1 addition & 1 deletion kernel/memory/src/paging/mapper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ impl MappedPages {
let size_in_pages = self.size_in_pages();

use paging::allocate_pages;
let new_pages = allocate_pages(self.size_in_pages()).ok_or_else(|| "Couldn't allocate_pages()")?;
let new_pages = allocate_pages(size_in_pages).ok_or_else(|| "Couldn't allocate_pages()")?;

// we must temporarily map the new pages as Writable, since we're about to copy data into them
let new_flags = new_flags.unwrap_or(self.flags);
Expand Down
4 changes: 0 additions & 4 deletions kernel/mod_mgmt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ qp-trie = "0.7.3"
owning_ref = { git = "https://github.com/kevinaboos/owning-ref-rs" }
cstr_core = "0.1.2"

[dependencies.gimli]
version = "0.19.0"
default-features = false
features = [ "read", "alloc" ]

[dependencies.hashbrown]
version = "0.1.8"
Expand Down

0 comments on commit d4ca13c

Please sign in to comment.