Skip to content

Commit

Permalink
Remove winapi (#77)
Browse files Browse the repository at this point in the history
* Nuke winapi

* Add ability to specify MinidumpType

* Update crash-context

* Oops

* Fix windows test

* More fixup
  • Loading branch information
Jake-Shadle authored Apr 3, 2023
1 parent 59179c8 commit f132965
Show file tree
Hide file tree
Showing 6 changed files with 465 additions and 93 deletions.
11 changes: 4 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ license = "MIT"
[dependencies]
byteorder = "1.3.2"
cfg-if = "1.0"
crash-context = "0.5"
crash-context = "0.6"
memoffset = "0.8"
minidump-common = "0.15"
scroll = "0.11"
Expand All @@ -31,16 +31,13 @@ nix = { version = "0.26", default-features = false, features = [
"user",
] }

[target.'cfg(target_os = "windows")'.dependencies]
bitflags = "2.0"

[target.'cfg(target_os = "macos")'.dependencies]
# Binds some additional mac specifics not in libc
mach2 = "0.4"

# Additional bindings to Windows specific APIs. Note we don't use windows-sys
# due to massive version churn
[target.'cfg(target_os = "windows")'.dependencies.winapi]
version = "0.3"
features = ["handleapi", "minwindef", "processthreadsapi", "winnt"]

[dev-dependencies]
# Minidump-processor is async so we need an executor
futures = { version = "0.3", features = ["executor"] }
Expand Down
19 changes: 11 additions & 8 deletions src/bin/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,22 +295,25 @@ mod linux {

#[cfg(target_os = "windows")]
mod windows {
use minidump_writer::ffi::{
GetCurrentProcessId, GetCurrentThread, GetCurrentThreadId, GetThreadContext,
EXCEPTION_POINTERS, EXCEPTION_RECORD,
};

use super::*;
use std::mem;

#[link(name = "kernel32")]
extern "system" {
pub fn GetCurrentProcessId() -> u32;
pub fn GetCurrentThreadId() -> u32;
pub fn GetCurrentThread() -> isize;
pub fn GetThreadContext(thread: isize, context: *mut crash_context::CONTEXT) -> i32;
}

#[inline(never)]
pub(super) fn real_main(args: Vec<String>) -> Result<()> {
let exception_code = u32::from_str_radix(&args[0], 16).unwrap();

// Generate the exception and communicate back where the exception pointers
// are
unsafe {
let mut exception_record: EXCEPTION_RECORD = mem::zeroed();
let mut exception_record: crash_context::EXCEPTION_RECORD = mem::zeroed();
let mut exception_context = std::mem::MaybeUninit::uninit();

let pid = GetCurrentProcessId();
Expand All @@ -320,12 +323,12 @@ mod windows {

let mut exception_context = exception_context.assume_init();

let exception_ptrs = EXCEPTION_POINTERS {
let exception_ptrs = crash_context::EXCEPTION_POINTERS {
ExceptionRecord: &mut exception_record,
ContextRecord: &mut exception_context,
};

exception_record.ExceptionCode = exception_code;
exception_record.ExceptionCode = exception_code as _;

let exc_ptr_addr = &exception_ptrs as *const _ as usize;

Expand Down
4 changes: 3 additions & 1 deletion src/windows.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub mod errors;
pub mod ffi;
mod ffi;
pub mod minidump_writer;

pub use ffi::MinidumpType;
Loading

0 comments on commit f132965

Please sign in to comment.