Skip to content

Commit 1388e2c

Browse files
authored
Merge pull request #7 from Marcondiro/master
Fix windows, fmt, more #[derive(Debug)], Bump to 0.2.0
2 parents a429bec + a290960 commit 1388e2c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+1251
-1013
lines changed

Cargo.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
[package]
22
name = "libipt"
3-
version = "0.2.0-rc.1"
3+
version = "0.2.0"
44
authors = ["sum_catnip <catnip@catnip.fyi>", "Marcondiro"]
55
edition = "2021"
66
license = "MIT"
77
description = "The Intel Processor Trace (Intel PT) Decoder Library is Intel's reference implementation for decoding Intel PT."
88
repository = "https://github.com/sum-catnip/libipt-rs"
99

10-
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
11-
1210
[dependencies]
13-
libipt-sys = "0.2.0-rc.1"
11+
libipt-sys = "0.2.0"
1412
bitflags = "2.4.1"
1513
num_enum = "0.7.1"

src/asid.rs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,44 @@ impl Asid {
8787
/// The CR3 value.
8888
#[inline]
8989
pub fn cr3(self) -> Option<u64> {
90-
match self.0.cr3 { NO_CR3 => None, x => Some(x) }
90+
match self.0.cr3 {
91+
NO_CR3 => None,
92+
x => Some(x),
93+
}
9194
}
9295

9396
/// The CR3 value.
9497
#[inline]
95-
pub fn set_cr3(&mut self, cr3: u64) { self.0.cr3 = cr3 }
98+
pub fn set_cr3(&mut self, cr3: u64) {
99+
self.0.cr3 = cr3
100+
}
96101

97102
/// The VMCS Base address.
98103
#[inline]
99104
pub fn vmcs(self) -> Option<u64> {
100-
match self.0.vmcs { NO_VMCS => None, x => Some(x) }
105+
match self.0.vmcs {
106+
NO_VMCS => None,
107+
x => Some(x),
108+
}
101109
}
102110

103111
/// The VMCS Base address.
104112
#[inline]
105-
pub fn set_vmcs(&mut self, vmcs: u64) { self.0.vmcs = vmcs }
113+
pub fn set_vmcs(&mut self, vmcs: u64) {
114+
self.0.vmcs = vmcs
115+
}
106116
}
107117

108118
impl Default for Asid {
109-
fn default() -> Self { Asid::new(None, None) }
119+
fn default() -> Self {
120+
Asid::new(None, None)
121+
}
110122
}
111123

112124
impl From<pt_asid> for Asid {
113-
fn from(asid: pt_asid) -> Self { Asid(asid) }
125+
fn from(asid: pt_asid) -> Self {
126+
Asid(asid)
127+
}
114128
}
115129

116130
impl PartialEq for Asid {

src/block/block.rs

Lines changed: 46 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
1-
use crate::insn::Class;
21
use crate::event::ExecModeType;
3-
use std::convert::TryFrom;
2+
use crate::insn::Class;
43
use libipt_sys::pt_block;
4+
use std::convert::TryFrom;
55

66
#[cfg(test)]
77
mod test {
88
use super::*;
9-
use libipt_sys::{
10-
pt_exec_mode_ptem_32bit,
11-
pt_insn_class_ptic_error,
12-
};
9+
use libipt_sys::{pt_exec_mode_ptem_32bit, pt_insn_class_ptic_error};
1310

1411
#[test]
1512
fn test_block_props() {
@@ -25,18 +22,18 @@ mod test {
2522
size: 8,
2623
_bitfield_align_1: [],
2724
_bitfield_1: pt_block::new_bitfield_1(0, 1),
28-
__bindgen_padding_0: Default::default()
29-
});
25+
__bindgen_padding_0: Default::default(),
26+
});
3027

31-
assert_eq!(blk.ip(), 1);
32-
assert_eq!(blk.end_ip(), 2);
33-
assert_eq!(blk.isid(), 3);
34-
assert_eq!(blk.mode(), ExecModeType::Bit32);
35-
assert_eq!(blk.class(), Class::Error);
36-
assert_eq!(blk.ninsn(), 4);
37-
assert_eq!(blk.raw(), &data[..8]);
38-
assert!(blk.truncated());
39-
assert!(!blk.speculative());
28+
assert_eq!(blk.ip(), 1);
29+
assert_eq!(blk.end_ip(), 2);
30+
assert_eq!(blk.isid(), 3);
31+
assert_eq!(blk.mode(), ExecModeType::Bit32);
32+
assert_eq!(blk.class(), Class::Error);
33+
assert_eq!(blk.ninsn(), 4);
34+
assert_eq!(blk.raw(), &data[..8]);
35+
assert!(blk.truncated());
36+
assert!(!blk.speculative());
4037
}
4138

4239
#[test]
@@ -53,46 +50,52 @@ mod test {
5350
size: 8,
5451
_bitfield_align_1: [],
5552
_bitfield_1: pt_block::new_bitfield_1(0, 0),
56-
__bindgen_padding_0: Default::default()
57-
});
53+
__bindgen_padding_0: Default::default(),
54+
});
5855

59-
assert_eq!(blk.ip(), 1);
60-
assert_eq!(blk.end_ip(), 2);
61-
assert_eq!(blk.isid(), 3);
62-
assert_eq!(blk.mode(), ExecModeType::Bit32);
63-
assert_eq!(blk.class(), Class::Error);
64-
assert_eq!(blk.ninsn(), 4);
65-
assert!(blk.raw().len() > 0);
66-
assert!(!blk.truncated());
67-
assert!(!blk.speculative());
56+
assert_eq!(blk.ip(), 1);
57+
assert_eq!(blk.end_ip(), 2);
58+
assert_eq!(blk.isid(), 3);
59+
assert_eq!(blk.mode(), ExecModeType::Bit32);
60+
assert_eq!(blk.class(), Class::Error);
61+
assert_eq!(blk.ninsn(), 4);
62+
assert!(blk.raw().len() > 0);
63+
assert!(!blk.truncated());
64+
assert!(!blk.speculative());
6865
}
6966
}
7067

7168
/// A block of instructions.
7269
///
7370
/// Instructions in this block are executed sequentially but are not necessarily
7471
/// contiguous in memory. Users are expected to follow direct branches.
75-
#[derive(Clone, Copy)]
72+
#[derive(Debug, Clone, Copy)]
7673
pub struct Block(pub(super) pt_block);
7774
impl Block {
7875
/// The IP of the first instruction in this block.
79-
pub fn ip(&self) -> u64 { self.0.ip }
76+
pub fn ip(&self) -> u64 {
77+
self.0.ip
78+
}
8079

8180
/// The IP of the last instruction in this block.
8281
///
8382
/// This can be used for error-detection.
84-
pub fn end_ip(&self) -> u64 { self.0.end_ip }
83+
pub fn end_ip(&self) -> u64 {
84+
self.0.end_ip
85+
}
8586

8687
/// The image section that contains the instructions in this block.
8788
///
8889
/// A value of zero means that the section did not have an identifier.
8990
/// The section was not added via an image section cache or the memory
9091
/// was read via the read memory callback.
91-
pub fn isid(&self) -> i32 { self.0.isid }
92+
pub fn isid(&self) -> i32 {
93+
self.0.isid
94+
}
9295

9396
/// The execution mode for all instructions in this block.
9497
pub fn mode(&self) -> ExecModeType {
95-
ExecModeType::try_from(self.0.mode).unwrap()
98+
ExecModeType::try_from(self.0.mode as u32).unwrap()
9699
}
97100

98101
/// The instruction class for the last instruction in this block.
@@ -101,11 +104,13 @@ impl Block {
101104
/// class is not available. The block decoder may choose to not provide
102105
/// the instruction class in some cases for performance reasons.
103106
pub fn class(&self) -> Class {
104-
Class::try_from(self.0.iclass).unwrap()
107+
Class::try_from(self.0.iclass as u32).unwrap()
105108
}
106109

107110
/// The number of instructions in this block.
108-
pub fn ninsn(&self) -> u16 { self.0.ninsn }
111+
pub fn ninsn(&self) -> u16 {
112+
self.0.ninsn
113+
}
109114

110115
/// The raw bytes of the last instruction in this block in case the
111116
/// instruction does not fit entirely into this block's section.
@@ -119,7 +124,9 @@ impl Block {
119124
/// instructions in this block.
120125
///
121126
/// - all instructions in this block were executed speculatively.
122-
pub fn speculative(&self) -> bool { self.0.speculative() > 0 }
127+
pub fn speculative(&self) -> bool {
128+
self.0.speculative() > 0
129+
}
123130

124131
/// A collection of flags giving additional information about the
125132
/// instructions in this block.
@@ -131,5 +138,7 @@ impl Block {
131138
///
132139
/// The raw bytes for the last instruction are provided in \@raw and
133140
/// its size in \@size in this case.
134-
pub fn truncated(&self) -> bool { self.0.truncated() > 0 }
141+
pub fn truncated(&self) -> bool {
142+
self.0.truncated() > 0
143+
}
135144
}

src/block/decoder.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ mod test {
5858
/// The decoder needs to be synchronized before it can be used.
5959
///
6060
/// * `T` - The Callback Closure Type in the Config
61+
#[derive(Debug)]
6162
pub struct BlockDecoder<'a, T>(&'a mut pt_block_decoder, PhantomData<T>);
6263
impl<T> BlockDecoder<'_, T> {
6364
/// Allocate an Intel PT block decoder.

src/block/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ mod block;
22
mod decoder;
33

44
pub use block::*;
5-
pub use decoder::*;
5+
pub use decoder::*;

0 commit comments

Comments
 (0)