Skip to content

Commit 7ac45a6

Browse files
authored
Safer libipt-rs 0.3.0-beta.1 (#10)
* AddrFilter builder() * Add comments about possibly very unsafe stuff * Allow casts marked unnecessary by clippy bc platform dependent * WIP: no references from FFI C pointers * PtEncoderDecoder trait and EncoderDecoderBuilder * Updaate tests * Clippy * Fix block decoder get image * Move tests at the bottom * Safer iscache * Nuke deref_ptresult_mut * Restore decoder get config, now: used_builder * Safer Image * Tests at the bottom * Clippy * Add CHANGELOG.md * Lints * Block/Insn decoder `to_owned_image(self) -> Image` * doc.rs works now * Remove decoder callback generic * used_builder for packet decoder * Fix block_decoder core_bus_ratio * cfilename use fn instead of repeat code * Clippy * into_owned_image * decoder takes mut ref to image * decoder takes mut ref to image * insn decoder takes mut ref to image * Simpler config flags API * Fix flags tests * rename status mod * Easy const * Easy const pt2 * Lints
1 parent b312bc7 commit 7ac45a6

Some content is hidden

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

62 files changed

+2385
-1906
lines changed

CHANGELOG.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Changelog
2+
3+
_This changelog documents only changes relevant to users, internal changes might be omitted._
4+
5+
## [0.3.0] 2025/01
6+
7+
### Added
8+
9+
- This [CHANGELOG](./CHANGELOG.md) 🎉
10+
- Explicit [MSRV](Cargo.toml)
11+
12+
### Changed
13+
14+
- `ConfigBuilder` and `Config` have been replaced by `EncoderDecoderBuilder`
15+
- Decoders/Encoder `::new()` have been replaced by `EncoderDecoderBuilder.build()`
16+
- Decoders/Encoder `.get_config()` have been replaced by `.used_builder()`
17+
- Block/Insn decoders `.image()` now returns `&mut Image` instead of `Result<Image,...>`
18+
- `Image.copy()` has been replaced by `Image.extend()`
19+
- `Image.add_cached()` now takes a `Rc<SectionCache>` instead of `&mut SectionCache` to ensure that the cache outlives the `Image`.
20+
- Many packet/event types methods now take a `&self` instead of consuming `self`
21+
22+
### Removed
23+
24+
- `From<&mut pt_image> for Image`
25+
- Decoders/Encoder callback due to [UB issues](https://github.com/sum-catnip/libipt-rs/issues/9) (PRs are welcome)
26+
27+
### Fixed
28+
29+
- Some safety issues: __do not cast raw pointers to references with `ptr.as_mut()` with FFI pointers.__
30+
`as_mut()` [requires](https://doc.rust-lang.org/std/ptr/index.html#pointer-to-reference-conversion) the pointer to be convertible to a reference.
31+
This is not true in many cases for FFI pointers: when creating a mutable reference, the referenced memory must not get accessed (read or written) through any other pointer or reference not derived from this reference.
32+
In many cases, we cannot ensure that `libipt` does not access the pointed data internally.
33+
34+
## [0.2.x]
35+
36+
_No changelog provided_

Cargo.toml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
[package]
22
name = "libipt"
3-
version = "0.2.1-beta.1"
4-
authors = ["sum_catnip <[email protected]>", "Marcondiro"]
3+
version = "0.3.0-beta.1"
4+
authors = ["sum_catnip <[email protected]>", "Marcondiro <[email protected]>"]
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."
8+
categories = ["development-tools::debugging", "development-tools::profiling"]
89
repository = "https://github.com/sum-catnip/libipt-rs"
10+
keywords = ["IntelPT", "ProcessorTrace", "libipt"]
11+
rust-version = "1.82.0"
912

1013
[features]
1114
libipt_master = ["libipt-sys/libipt_master"]
1215

1316
[dependencies]
14-
libipt-sys = "0.2.1-beta.1"
17+
libipt-sys = "0.2.1-beta.3"
1518
bitflags = "2.4.1"
1619
num_enum = "0.7.1"

README.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ Contributions are also appreciated.
2222
I did my best to provide useful documentation for most of the library.
2323
If you see any missing or weird documentation feel free to open an issue or pull request.
2424

25-
docs.rs is sadly unable to build the project because of a header file which needs to be copied out of the build dir.
26-
Ill need to get the sorted out somehow.
27-
2825
# Unit Tests
2926
- block: ✔️
3027
- config: ✔️

src/asid.rs

Lines changed: 68 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,72 @@
11
use libipt_sys::{pt_asid, pt_asid_no_cr3 as NO_CR3, pt_asid_no_vmcs as NO_VMCS};
2-
use std::mem;
2+
3+
/// An Intel PT address space identifier.
4+
///
5+
/// This identifies a particular address space when adding file sections or
6+
/// when reading memory.
7+
#[derive(Clone, Copy, Debug)]
8+
pub struct Asid(pub(crate) pt_asid);
9+
impl Asid {
10+
#[inline]
11+
#[must_use]
12+
pub fn new(cr3: Option<u64>, vmcs: Option<u64>) -> Self {
13+
Asid(pt_asid {
14+
size: size_of::<pt_asid>(),
15+
cr3: cr3.unwrap_or(NO_CR3),
16+
vmcs: vmcs.unwrap_or(NO_VMCS),
17+
})
18+
}
19+
20+
/// The CR3 value.
21+
#[inline]
22+
#[must_use]
23+
pub const fn cr3(self) -> Option<u64> {
24+
match self.0.cr3 {
25+
NO_CR3 => None,
26+
x => Some(x),
27+
}
28+
}
29+
30+
/// The CR3 value.
31+
#[inline]
32+
pub fn set_cr3(&mut self, cr3: u64) {
33+
self.0.cr3 = cr3;
34+
}
35+
36+
/// The VMCS Base address.
37+
#[inline]
38+
#[must_use]
39+
pub const fn vmcs(self) -> Option<u64> {
40+
match self.0.vmcs {
41+
NO_VMCS => None,
42+
x => Some(x),
43+
}
44+
}
45+
46+
/// The VMCS Base address.
47+
#[inline]
48+
pub fn set_vmcs(&mut self, vmcs: u64) {
49+
self.0.vmcs = vmcs;
50+
}
51+
}
52+
53+
impl Default for Asid {
54+
fn default() -> Self {
55+
Asid::new(None, None)
56+
}
57+
}
58+
59+
impl From<pt_asid> for Asid {
60+
fn from(asid: pt_asid) -> Self {
61+
Asid(asid)
62+
}
63+
}
64+
65+
impl PartialEq for Asid {
66+
fn eq(&self, other: &Self) -> bool {
67+
self.cr3() == other.cr3() && self.vmcs() == other.vmcs()
68+
}
69+
}
370

471
#[cfg(test)]
572
mod test {
@@ -67,68 +134,3 @@ mod test {
67134
assert_eq!(raw.cr3, NO_CR3);
68135
}
69136
}
70-
71-
/// An Intel PT address space identifier.
72-
///
73-
/// This identifies a particular address space when adding file sections or
74-
/// when reading memory.
75-
#[derive(Clone, Copy, Debug)]
76-
pub struct Asid(pub(crate) pt_asid);
77-
impl Asid {
78-
#[inline]
79-
pub fn new(cr3: Option<u64>, vmcs: Option<u64>) -> Self {
80-
Asid(pt_asid {
81-
size: mem::size_of::<pt_asid>(),
82-
cr3: cr3.unwrap_or(NO_CR3),
83-
vmcs: vmcs.unwrap_or(NO_VMCS),
84-
})
85-
}
86-
87-
/// The CR3 value.
88-
#[inline]
89-
pub fn cr3(self) -> Option<u64> {
90-
match self.0.cr3 {
91-
NO_CR3 => None,
92-
x => Some(x),
93-
}
94-
}
95-
96-
/// The CR3 value.
97-
#[inline]
98-
pub fn set_cr3(&mut self, cr3: u64) {
99-
self.0.cr3 = cr3
100-
}
101-
102-
/// The VMCS Base address.
103-
#[inline]
104-
pub fn vmcs(self) -> Option<u64> {
105-
match self.0.vmcs {
106-
NO_VMCS => None,
107-
x => Some(x),
108-
}
109-
}
110-
111-
/// The VMCS Base address.
112-
#[inline]
113-
pub fn set_vmcs(&mut self, vmcs: u64) {
114-
self.0.vmcs = vmcs
115-
}
116-
}
117-
118-
impl Default for Asid {
119-
fn default() -> Self {
120-
Asid::new(None, None)
121-
}
122-
}
123-
124-
impl From<pt_asid> for Asid {
125-
fn from(asid: pt_asid) -> Self {
126-
Asid(asid)
127-
}
128-
}
129-
130-
impl PartialEq for Asid {
131-
fn eq(&self, other: &Self) -> bool {
132-
self.cr3() == other.cr3() && self.vmcs() == other.vmcs()
133-
}
134-
}

0 commit comments

Comments
 (0)