Skip to content

Commit a429bec

Browse files
authored
Merge pull request #5 from Marcondiro/master
Bump libipt to 2.1.1
2 parents ecb2c99 + 72836e5 commit a429bec

39 files changed

+152
-92
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/target
2+
/.idea
23
**/*.rs.bk
34
Cargo.lock
45
.vscode/

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "libipt"
3-
version = "0.2.0"
4-
authors = ["sum_catnip <catnip@catnip.fyi>"]
3+
version = "0.2.0-rc.1"
4+
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."
@@ -10,6 +10,6 @@ repository = "https://github.com/sum-catnip/libipt-rs"
1010
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1111

1212
[dependencies]
13-
libipt-sys = { git = "https://github.com/sum-catnip/libipt-sys" }
13+
libipt-sys = "0.2.0-rc.1"
1414
bitflags = "2.4.1"
1515
num_enum = "0.7.1"

readme.md renamed to README.md

File renamed without changes.

src/block/block.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ mod test {
2323
ninsn: 4,
2424
raw: data,
2525
size: 8,
26+
_bitfield_align_1: [],
2627
_bitfield_1: pt_block::new_bitfield_1(0, 1),
2728
__bindgen_padding_0: Default::default()
2829
});
@@ -50,6 +51,7 @@ mod test {
5051
ninsn: 4,
5152
raw: data,
5253
size: 8,
54+
_bitfield_align_1: [],
5355
_bitfield_1: pt_block::new_bitfield_1(0, 0),
5456
__bindgen_padding_0: Default::default()
5557
});

src/block/decoder.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ mod test {
5959
///
6060
/// * `T` - The Callback Closure Type in the Config
6161
pub struct BlockDecoder<'a, T>(&'a mut pt_block_decoder, PhantomData<T>);
62-
impl<'a, T> BlockDecoder<'a, T> {
62+
impl<T> BlockDecoder<'_, T> {
6363
/// Allocate an Intel PT block decoder.
6464
///
6565
/// The decoder will work on the buffer defined in @config,
@@ -217,7 +217,7 @@ impl<'a, T> BlockDecoder<'a, T> {
217217
}
218218
}
219219

220-
impl<'a, T> Iterator for BlockDecoder<'a, T> {
220+
impl<T> Iterator for BlockDecoder<'_, T> {
221221
type Item = Result<(Block, Status), PtError>;
222222

223223
fn next(&mut self) -> Option<Result<(Block, Status), PtError>> {
@@ -229,7 +229,7 @@ impl<'a, T> Iterator for BlockDecoder<'a, T> {
229229
}
230230
}
231231

232-
impl<'a, T> Drop for BlockDecoder<'a, T> {
232+
impl<T> Drop for BlockDecoder<'_, T> {
233233
fn drop(&mut self) {
234234
unsafe { pt_blk_free_decoder(self.0) }
235235
}

src/config/config.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@ mod test {
130130
for _ in 0..10 { assert!(check_callback(&mut cfg, 13, 17)) }
131131
}
132132

133+
// FIXME
134+
#[ignore]
133135
#[test]
134136
#[should_panic]
135137
fn test_config_callback_out_of_bounds() {
@@ -194,13 +196,13 @@ impl<'a, T> ConfigBuilder<'a, T> {
194196
where F: FnMut(&Config<T>, &[u8]) -> (Unknown<T>, u32),
195197
F: 'a {
196198
// yeah.. libipt doesnt handle this -_-
197-
if buf.len() < 1 { return Err(
199+
if buf.is_empty() { return Err(
198200
PtError::new(PtErrorCode::Invalid, "buffer cant be empty!")
199201
)}
200202
let mut cfg: pt_config = unsafe { mem::zeroed() };
201203
cfg.size = mem::size_of::<pt_config>();
202204
cfg.begin = buf.as_mut_ptr();
203-
cfg.end = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
205+
cfg.end = unsafe { buf.as_mut_ptr().add(buf.len()) };
204206
cfg.decode.callback = Some(decode_callback::<F, T>);
205207
cfg.decode.context = &mut cb as *mut _ as *mut c_void;
206208
Ok(ConfigBuilder::<T>(cfg, PhantomData))
@@ -249,14 +251,14 @@ impl<'a> ConfigBuilder<'a, ()> {
249251
/// If you want to use a decoder callback,
250252
/// use the `with_callback` function
251253
/// returns `Invalid` when buf is empty
252-
pub fn new(buf: &'a mut [u8]) -> Result<ConfigBuilder<()>, PtError> {
253-
if buf.len() < 1 { return Err(
254+
pub fn new(buf: &'a mut [u8]) -> Result<ConfigBuilder<'a, ()>, PtError> {
255+
if buf.is_empty() { return Err(
254256
PtError::new(PtErrorCode::Invalid, "buffer cant be empty!")
255257
)}
256258
let mut cfg: pt_config = unsafe { mem::zeroed() };
257259
cfg.size = mem::size_of::<pt_config>();
258260
cfg.begin = buf.as_mut_ptr();
259-
cfg.end = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) };
261+
cfg.end = unsafe { buf.as_mut_ptr().add(buf.len()) };
260262
Ok(ConfigBuilder::<()>(cfg, PhantomData))
261263
}
262264
}

src/config/cpu.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ mod test {
4242

4343
bitflags! {
4444
/// i suppose this is relevant when/if amd finally gets intelpt support?
45-
pub struct CpuVendor: i32 {
45+
pub struct CpuVendor: u32 {
4646
const INTEL = pt_cpu_vendor_pcv_intel;
4747
const UNKNOWN = pt_cpu_vendor_pcv_unknown;
4848
}
@@ -64,6 +64,7 @@ impl Cpu {
6464
/// determines processor specific workarounds
6565
pub(super) fn determine_errata(self) -> pt_errata {
6666
let mut errata = pt_errata {
67+
_bitfield_align_1: [],
6768
_bitfield_1: Default::default(),
6869
reserved: Default::default()
6970
};

src/config/filter.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ impl AddrFilter {
115115
}
116116

117117
pub struct AddrFilterBuilder (pub(super) pt_conf_addr_filter);
118+
impl Default for AddrFilterBuilder {
119+
fn default() -> Self {
120+
Self::new()
121+
}
122+
}
123+
118124
impl AddrFilterBuilder {
119125
pub fn new() -> Self { unsafe { mem::zeroed() }}
120126

src/config/flags.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ bitflags! {
106106

107107
impl From<BlockFlags> for pt_conf_flags {
108108
fn from(flags: BlockFlags) -> Self {
109-
pt_conf_flags {
109+
Self {
110110
variant: pt_conf_flags__bindgen_ty_1 {
111111
block: pt_conf_flags__bindgen_ty_1__bindgen_ty_1 {
112+
_bitfield_align_1: [],
112113
_bitfield_1: __BindgenBitfieldUnit::new([flags.bits()]),
113114
__bindgen_padding_0: Default::default() }}}
114115
}
@@ -119,6 +120,7 @@ impl From<InsnFlags> for pt_conf_flags {
119120
pt_conf_flags {
120121
variant: pt_conf_flags__bindgen_ty_1 {
121122
insn: pt_conf_flags__bindgen_ty_1__bindgen_ty_2 {
123+
_bitfield_align_1: [],
122124
_bitfield_1: __BindgenBitfieldUnit::new([flags.bits()]),
123125
__bindgen_padding_0: Default::default() }}}
124126
}
@@ -129,6 +131,7 @@ impl From<QueryFlags> for pt_conf_flags {
129131
pt_conf_flags {
130132
variant: pt_conf_flags__bindgen_ty_1 {
131133
query: pt_conf_flags__bindgen_ty_1__bindgen_ty_3 {
134+
_bitfield_align_1: [],
132135
_bitfield_1: __BindgenBitfieldUnit::new([flags.bits()]),
133136
__bindgen_padding_0: Default::default() }}}
134137
}

src/error.rs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::ffi::CStr;
44
use std::fmt::{Display, Formatter};
55
use std::error::Error;
66

7-
use libipt_sys::pt_errstr;
7+
use libipt_sys::{pt_error_code, pt_errstr};
88
use libipt_sys::{
99
pt_error_code_pte_ok,
1010
pt_error_code_pte_internal,
@@ -40,61 +40,61 @@ use libipt_sys::{
4040
#[repr(i32)]
4141
pub enum PtErrorCode {
4242
/// No error. Everything is OK
43-
Ok = pt_error_code_pte_ok,
43+
Ok = pt_error_code_pte_ok as i32,
4444
/// Internal decoder error
45-
Internal = pt_error_code_pte_internal,
45+
Internal = pt_error_code_pte_internal as i32,
4646
/// Invalid argument
47-
Invalid = pt_error_code_pte_invalid,
47+
Invalid = pt_error_code_pte_invalid as i32,
4848
/// Decoder out of sync
49-
Nosync = pt_error_code_pte_nosync,
49+
Nosync = pt_error_code_pte_nosync as i32,
5050
/// Unknown opcode
51-
BadOpc = pt_error_code_pte_bad_opc,
51+
BadOpc = pt_error_code_pte_bad_opc as i32,
5252
/// Unknown payload
53-
BadPacket = pt_error_code_pte_bad_packet,
53+
BadPacket = pt_error_code_pte_bad_packet as i32,
5454
/// Unexpected packet context
55-
BadContext = pt_error_code_pte_bad_context,
55+
BadContext = pt_error_code_pte_bad_context as i32,
5656
/// Decoder reached end of trace stream
57-
Eos = pt_error_code_pte_eos,
57+
Eos = pt_error_code_pte_eos as i32,
5858
/// No packet matching the query to be found
59-
BadQuery = pt_error_code_pte_bad_query,
59+
BadQuery = pt_error_code_pte_bad_query as i32,
6060
/// Decoder out of memory
61-
Nomem = pt_error_code_pte_nomem,
61+
Nomem = pt_error_code_pte_nomem as i32,
6262
/// Bad configuration
63-
BadConfig = pt_error_code_pte_bad_config,
63+
BadConfig = pt_error_code_pte_bad_config as i32,
6464
/// There is no IP
65-
Noip = pt_error_code_pte_noip,
65+
Noip = pt_error_code_pte_noip as i32,
6666
/// The IP has been suppressed
67-
IpSuppressed = pt_error_code_pte_ip_suppressed,
67+
IpSuppressed = pt_error_code_pte_ip_suppressed as i32,
6868
/// There is no memory mapped at the requested address
69-
Nomap = pt_error_code_pte_nomap,
69+
Nomap = pt_error_code_pte_nomap as i32,
7070
/// An instruction could not be decoded
71-
BadInsn = pt_error_code_pte_bad_insn,
71+
BadInsn = pt_error_code_pte_bad_insn as i32,
7272
/// No wall-clock time is available
73-
NoTime = pt_error_code_pte_no_time,
73+
NoTime = pt_error_code_pte_no_time as i32,
7474
/// No core:bus ratio available
75-
NoCbr = pt_error_code_pte_no_cbr,
75+
NoCbr = pt_error_code_pte_no_cbr as i32,
7676
/// Bad traced image
77-
BadImage = pt_error_code_pte_bad_image,
77+
BadImage = pt_error_code_pte_bad_image as i32,
7878
/// A locking error
79-
BadLock = pt_error_code_pte_bad_lock,
79+
BadLock = pt_error_code_pte_bad_lock as i32,
8080
/// The requested feature is not supported
81-
NotSupported = pt_error_code_pte_not_supported,
81+
NotSupported = pt_error_code_pte_not_supported as i32,
8282
/// The return address stack is empty
83-
RetstackEmpty = pt_error_code_pte_retstack_empty,
83+
RetstackEmpty = pt_error_code_pte_retstack_empty as i32,
8484
/// A compressed return is not indicated correctly by a taken branch
85-
BadRetcomp = pt_error_code_pte_bad_retcomp,
85+
BadRetcomp = pt_error_code_pte_bad_retcomp as i32,
8686
/// The current decoder state does not match the state in the trace
87-
BadStatusUpdate = pt_error_code_pte_bad_status_update,
87+
BadStatusUpdate = pt_error_code_pte_bad_status_update as i32,
8888
/// The trace did not contain an expected enabled event
89-
NoEnable = pt_error_code_pte_no_enable,
89+
NoEnable = pt_error_code_pte_no_enable as i32,
9090
/// An event was ignored
91-
EventIgnored = pt_error_code_pte_event_ignored,
91+
EventIgnored = pt_error_code_pte_event_ignored as i32,
9292
/// Something overflowed
93-
Overflow = pt_error_code_pte_overflow,
93+
Overflow = pt_error_code_pte_overflow as i32,
9494
/// A file handling error
95-
BadFile = pt_error_code_pte_bad_file,
95+
BadFile = pt_error_code_pte_bad_file as i32,
9696
/// Unknown cpu
97-
BadCpu = pt_error_code_pte_bad_cpu,
97+
BadCpu = pt_error_code_pte_bad_cpu as i32,
9898

9999
/// No Error Information available
100100
NoInfo = -1
@@ -118,12 +118,12 @@ impl PtError {
118118
/// *error codes not included in the pt_error enum will panic!*
119119
#[inline]
120120
pub(crate) fn from_code(code: i32) -> Self {
121-
// panicing here is fine since this should only be called
121+
// panicking here is fine since this should only be called
122122
// for return values of libipt functions
123123
// so invalid returns = bug in libipt or the bindings
124124
PtError::new(
125125
PtErrorCode::try_from(-code).unwrap(),
126-
unsafe { CStr::from_ptr(pt_errstr(-code)).to_str().unwrap() }
126+
unsafe { CStr::from_ptr(pt_errstr(-code as pt_error_code)).to_str().unwrap() }
127127
)
128128
}
129129

0 commit comments

Comments
 (0)