From 42c050de29c1a3bee87e17213ac2dc601d78396f Mon Sep 17 00:00:00 2001 From: Jan Michael Auer Date: Tue, 22 May 2018 18:31:40 +0200 Subject: [PATCH] ref(v7): Update to latest mechanism schema (#10) --- src/protocol/v7.rs | 73 ++++++++++++++++++--------------------- tests/test_protocol_v7.rs | 12 +++++-- 2 files changed, 43 insertions(+), 42 deletions(-) diff --git a/src/protocol/v7.rs b/src/protocol/v7.rs index 50498181..86e509c8 100644 --- a/src/protocol/v7.rs +++ b/src/protocol/v7.rs @@ -388,44 +388,30 @@ pub struct Thread { pub current: bool, } -/// Error code used in Windows COM. -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)] -pub struct HResult(pub u32); - -impl_serde_hex!(HResult, u32); - -impl From for HResult { - fn from(hresult: u32) -> HResult { - HResult(hresult) - } -} - -impl Into for HResult { - fn into(self) -> u32 { - self.0 - } +/// POSIX signal with optional extended data. +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] +pub struct CError { + /// The error code as specified by ISO C99, POSIX.1-2001 or POSIX.1-2008. + pub number: i32, + /// Optional name of the errno constant. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, } -/// Error code used for Win32 user space and NTSTATUS kernel errors. -#[derive(Debug, Default, Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Hash)] -pub struct Win32ErrorCode(pub u32); - -impl_serde_hex!(Win32ErrorCode, u32); - -impl From for Win32ErrorCode { - fn from(code: u32) -> Win32ErrorCode { - Win32ErrorCode(code) +impl From for CError { + fn from(number: i32) -> CError { + CError { number, name: None } } } -impl Into for Win32ErrorCode { - fn into(self) -> u32 { - self.0 +impl Into for CError { + fn into(self) -> i32 { + self.number } } /// Mach exception information. -#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] pub struct MachException { /// The mach exception type. #[serde(rename = "exception")] @@ -434,21 +420,35 @@ pub struct MachException { pub code: u64, /// The mach exception subcode. pub subcode: u64, + /// Optional name of the mach exception. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, } /// POSIX signal with optional extended data. -#[derive(Serialize, Deserialize, Debug, Default, Clone, Copy, PartialEq, Eq)] +#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq, Eq)] pub struct PosixSignal { /// The POSIX signal number. pub number: i32, /// An optional signal code present on Apple systems. #[serde(skip_serializing_if = "Option::is_none")] pub code: Option, + /// Optional name of the errno constant. + #[serde(skip_serializing_if = "Option::is_none")] + pub name: Option, + /// Optional name of the errno constant. + #[serde(skip_serializing_if = "Option::is_none")] + pub code_name: Option, } impl From for PosixSignal { fn from(number: i32) -> PosixSignal { - PosixSignal { number, code: None } + PosixSignal { + number, + code: None, + name: None, + code_name: None, + } } } @@ -458,6 +458,8 @@ impl From<(i32, i32)> for PosixSignal { PosixSignal { number, code: Some(code), + name: None, + code_name: None, } } } @@ -473,25 +475,18 @@ impl Into for PosixSignal { pub struct MechanismMeta { /// Optional ISO C standard error code. #[serde(skip_serializing_if = "Option::is_none")] - pub errno: Option, + pub errno: Option, /// Optional POSIX signal number. #[serde(skip_serializing_if = "Option::is_none")] pub signal: Option, /// Optional mach exception information. #[serde(skip_serializing_if = "Option::is_none")] pub mach_exception: Option, - /// Optional Windows COM error code. - #[serde(skip_serializing_if = "Option::is_none")] - pub hresult: Option, - /// Optional Win32 / NTSTATUS error code. - #[serde(skip_serializing_if = "Option::is_none")] - pub seh_code: Option, } impl MechanismMeta { fn is_empty(&self) -> bool { self.errno.is_none() && self.signal.is_none() && self.mach_exception.is_none() - && self.hresult.is_none() && self.seh_code.is_none() } } diff --git a/tests/test_protocol_v7.rs b/tests/test_protocol_v7.rs index e4f2af07..739020a0 100644 --- a/tests/test_protocol_v7.rs +++ b/tests/test_protocol_v7.rs @@ -979,16 +979,22 @@ fn test_exception_mechanism() { map }, meta: v7::MechanismMeta { + errno: Some(v7::CError { + number: 2, + name: None, + }), signal: Some(v7::PosixSignal { number: 11, code: None, + name: None, + code_name: None, }), mach_exception: Some(v7::MachException { ty: 1, code: 1, subcode: 8, + name: None, }), - ..Default::default() }, }), ..Default::default() @@ -1003,8 +1009,8 @@ fn test_exception_mechanism() { "{\"exception\":{\"values\":[{\"type\":\"EXC_BAD_ACCESS\",\"value\":\"Attempted to \ dereference garbage pointer 0x1\",\"mechanism\":{\"type\":\"mach\",\"help_link\":\"\ https://developer.apple.com/library/content/qa/qa1367/_index.html\",\"handled\":false,\"\ - data\":{\"relevant_address\":\"0x1\"},\"meta\":{\"signal\":{\"number\":11},\"mach_exception\ - \":{\"exception\":1,\"code\":1,\"subcode\":8}}}}]}}" + data\":{\"relevant_address\":\"0x1\"},\"meta\":{\"errno\":{\"number\":2},\"signal\":{\"\ + number\":11},\"mach_exception\":{\"exception\":1,\"code\":1,\"subcode\":8}}}}]}}" ); }