Skip to content

Commit

Permalink
ref(v7): Update to latest mechanism schema (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-auer authored May 22, 2018
1 parent eb38ed7 commit 42c050d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 42 deletions.
73 changes: 34 additions & 39 deletions src/protocol/v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<u32> for HResult {
fn from(hresult: u32) -> HResult {
HResult(hresult)
}
}

impl Into<u32> 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<String>,
}

/// 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<u32> for Win32ErrorCode {
fn from(code: u32) -> Win32ErrorCode {
Win32ErrorCode(code)
impl From<i32> for CError {
fn from(number: i32) -> CError {
CError { number, name: None }
}
}

impl Into<u32> for Win32ErrorCode {
fn into(self) -> u32 {
self.0
impl Into<i32> 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")]
Expand All @@ -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<String>,
}

/// 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<i32>,
/// Optional name of the errno constant.
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
/// Optional name of the errno constant.
#[serde(skip_serializing_if = "Option::is_none")]
pub code_name: Option<String>,
}

impl From<i32> for PosixSignal {
fn from(number: i32) -> PosixSignal {
PosixSignal { number, code: None }
PosixSignal {
number,
code: None,
name: None,
code_name: None,
}
}
}

Expand All @@ -458,6 +458,8 @@ impl From<(i32, i32)> for PosixSignal {
PosixSignal {
number,
code: Some(code),
name: None,
code_name: None,
}
}
}
Expand All @@ -473,25 +475,18 @@ impl Into<i32> for PosixSignal {
pub struct MechanismMeta {
/// Optional ISO C standard error code.
#[serde(skip_serializing_if = "Option::is_none")]
pub errno: Option<i32>,
pub errno: Option<CError>,
/// Optional POSIX signal number.
#[serde(skip_serializing_if = "Option::is_none")]
pub signal: Option<PosixSignal>,
/// Optional mach exception information.
#[serde(skip_serializing_if = "Option::is_none")]
pub mach_exception: Option<MachException>,
/// Optional Windows COM error code.
#[serde(skip_serializing_if = "Option::is_none")]
pub hresult: Option<HResult>,
/// Optional Win32 / NTSTATUS error code.
#[serde(skip_serializing_if = "Option::is_none")]
pub seh_code: Option<Win32ErrorCode>,
}

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()
}
}

Expand Down
12 changes: 9 additions & 3 deletions tests/test_protocol_v7.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}}}}]}}"
);
}

Expand Down

0 comments on commit 42c050d

Please sign in to comment.