Skip to content

Commit

Permalink
Add heap corruption exception handling (#86)
Browse files Browse the repository at this point in the history
* Add heap corruption exception handling

* Fix naming

* Fix lints

* Update minidump/fix deny

* More lint fixes, bump MSRV

* And again

---------

Co-authored-by: Tomasz Stachowiak <h3@h3.gd>
  • Loading branch information
Jake-Shadle and h3r2tic authored Jun 8, 2024
1 parent 065f3dd commit e524a89
Show file tree
Hide file tree
Showing 13 changed files with 75 additions and 175 deletions.
162 changes: 13 additions & 149 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion crash-context/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ documentation = "https://docs.rs/crash-context"
homepage = "https://github.com/EmbarkStudios/crash-handling/tree/main/crash-context"
categories = ["external-ffi-bindings"]
keywords = ["crash", "libc", "getcontext"]
rust-version = "1.59.0" # We use `global_asm!`
rust-version = "1.62.0" # We use `global_asm!`

[dependencies]
# Nicer cfg handling
Expand Down
2 changes: 1 addition & 1 deletion crash-context/src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct CrashContext {
///
/// Note that we use [`crate::ucontext_t`] instead of [`libc::ucontext_t`]
/// as libc's differs between glibc and musl <https://github.com/rust-lang/libc/pull/1646>
/// even though the ucontext_t received from a signal will be the same
/// even though the `ucontext_t` received from a signal will be the same
/// regardless of the libc implementation used as it is only arch specific
/// and not libc specific
///
Expand Down
4 changes: 2 additions & 2 deletions crash-context/src/mac/resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub enum ResourceException {
Cpu(CpuResourceException),
/// This is sent by the kernel when the platform idle wakeups monitor is tripped. Possibly fatal.
Wakeups(WakeupsResourceException),
/// This is sent by the kernel when a task crosses its high watermark memory limit. Never fatal at least on current MacOS versions.
/// This is sent by the kernel when a task crosses its high watermark memory limit. Never fatal at least on current `MacOS` versions.
Memory(MemoryResourceException),
/// This is sent by the kernel when a task crosses its I/O limits. Never fatal.
Io(IoResourceException),
Expand All @@ -27,7 +27,7 @@ pub enum ResourceException {
/// filled its port space. Always fatal.
Ports(PortsResourceException),
/// An unknown resource kind due to an addition to the set of possible
/// resource exception kinds in exc_resource.h
/// resource exception kinds in `exc_resource.h`
Unknown { kind: u8, flavor: u8 },
}

Expand Down
2 changes: 1 addition & 1 deletion crash-context/src/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ pub struct CrashContext {
/// Note that this is a pointer into the actual memory of the crashed process,
/// and is a pointer to an [EXCEPTION_POINTERS](https://learn.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-exception_pointers)
pub exception_pointers: *const EXCEPTION_POINTERS,
/// The top level exception code from the exception_pointers. This is provided
/// The top level exception code from the `exception_pointers`. This is provided
/// so that external processes don't need to use `ReadProcessMemory` to inspect
/// the exception code
pub exception_code: i32,
Expand Down
2 changes: 1 addition & 1 deletion crash-handler/src/mac/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ enum MessageIds {
SignalCrash = 0,
/// Message ID telling the handler thread to quit.
Shutdown = 2,
/// Taken from mach_exc in /usr/include/mach/exc.defs.
/// Taken from `mach_exc` in `/usr/include/mach/exc.defs`.
Exception = 2405,
ExceptionStateIdentity = 2407,
}
Expand Down
5 changes: 4 additions & 1 deletion crash-handler/src/unix/pthread_interpose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,10 @@ pub extern "C" fn pthread_create(
REAL_PTHREAD_CREATE = Some(std::mem::transmute(ptr));
}

libc::pthread_key_create(&mut THREAD_DESTRUCTOR_KEY, Some(uninstall_sig_alt_stack));
libc::pthread_key_create(
std::ptr::addr_of_mut!(THREAD_DESTRUCTOR_KEY),
Some(uninstall_sig_alt_stack),
);
});

let real_pthread_create = unsafe { REAL_PTHREAD_CREATE.as_ref() }.expect("pthread_create() intercept failed but the intercept function is still being called, this won't work");
Expand Down
Loading

0 comments on commit e524a89

Please sign in to comment.