Skip to content

Commit

Permalink
Replace winapi with windows-sys in exception handler
Browse files Browse the repository at this point in the history
  • Loading branch information
faern committed Dec 19, 2024
1 parent b49a484 commit eeae8c3
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 0 additions & 1 deletion mullvad-daemon/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ objc = { version = "0.2.7", features = ["exception", "verify_message"] }
[target.'cfg(windows)'.dependencies]
ctrlc = "3.0"
windows-service = "0.6.0"
winapi = { version = "0.3", features = ["winnt", "excpt", "winerror"] }
dirs = "5.0.1"
talpid-windows = { path = "../talpid-windows" }

Expand Down
22 changes: 13 additions & 9 deletions mullvad-daemon/src/exception_logging/win.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use std::{
};
use talpid_types::ErrorExt;
use talpid_windows::process::{ModuleEntry, ProcessSnapshot};
use winapi::vc::excpt::EXCEPTION_EXECUTE_HANDLER;
use windows_sys::Win32::System::Diagnostics::Debug::EXCEPTION_EXECUTE_HANDLER;
use windows_sys::Win32::{
Foundation::HANDLE,
System::{
Expand Down Expand Up @@ -211,11 +211,13 @@ unsafe extern "system" fn logging_exception_filter(info_ptr: *const EXCEPTION_PO

#[cfg(target_arch = "aarch64")]
fn get_context_info(context: &CONTEXT) -> String {
use winapi::um::winnt::{CONTEXT_CONTROL, CONTEXT_FLOATING_POINT, CONTEXT_INTEGER};
use windows_sys::Win32::System::Diagnostics::Debug::{
CONTEXT_CONTROL_ARM64, CONTEXT_FLOATING_POINT_ARM64, CONTEXT_INTEGER_ARM64,
};

let mut context_str = "Context:\n".to_string();

if context.ContextFlags & CONTEXT_CONTROL != 0 {
if context.ContextFlags & CONTEXT_CONTROL_ARM64 != 0 {
writeln!(
&mut context_str,
"\n\tFp: {:#x?}\n \
Expand All @@ -232,7 +234,7 @@ fn get_context_info(context: &CONTEXT) -> String {
.unwrap();
}

if context.ContextFlags & CONTEXT_INTEGER != 0 {
if context.ContextFlags & CONTEXT_INTEGER_ARM64 != 0 {
context_str.push('\n');
for x in 0..=28 {
writeln!(&mut context_str, "\tX{}: {:#x?}", x, unsafe {
Expand All @@ -241,7 +243,7 @@ fn get_context_info(context: &CONTEXT) -> String {
.unwrap();
}
}
if context.ContextFlags & CONTEXT_FLOATING_POINT != 0 {
if context.ContextFlags & CONTEXT_FLOATING_POINT_ARM64 != 0 {
writeln!(
&mut context_str,
"\n\tFpcr: {:#x?}\n \
Expand All @@ -262,11 +264,13 @@ fn get_context_info(context: &CONTEXT) -> String {

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
fn get_context_info(context: &CONTEXT) -> String {
use winapi::um::winnt::{CONTEXT_CONTROL, CONTEXT_INTEGER, CONTEXT_SEGMENTS};
use windows_sys::Win32::System::Diagnostics::Debug::{
CONTEXT_CONTROL_AMD64, CONTEXT_INTEGER_AMD64, CONTEXT_SEGMENTS_AMD64,
};

let mut context_str = "Context:\n".to_string();

if context.ContextFlags & CONTEXT_CONTROL != 0 {
if context.ContextFlags & CONTEXT_CONTROL_AMD64 != 0 {
writeln!(
&mut context_str,
"\n\tSegSs: {:#x?}\n \
Expand All @@ -279,7 +283,7 @@ fn get_context_info(context: &CONTEXT) -> String {
.unwrap();
}

if context.ContextFlags & CONTEXT_INTEGER != 0 {
if context.ContextFlags & CONTEXT_INTEGER_AMD64 != 0 {
writeln!(
&mut context_str,
"\n\tRax: {:#x?}\n \
Expand Down Expand Up @@ -316,7 +320,7 @@ fn get_context_info(context: &CONTEXT) -> String {
.unwrap();
}

if context.ContextFlags & CONTEXT_SEGMENTS != 0 {
if context.ContextFlags & CONTEXT_SEGMENTS_AMD64 != 0 {
writeln!(
&mut context_str,
"\n\tSegDs: {:#x?}\n \
Expand Down

0 comments on commit eeae8c3

Please sign in to comment.