Skip to content

Commit 798e695

Browse files
committed
Fix windows
1 parent a429bec commit 798e695

File tree

8 files changed

+65
-52
lines changed

8 files changed

+65
-52
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "libipt"
3-
version = "0.2.0-rc.1"
3+
version = "0.2.0-rc.2"
44
authors = ["sum_catnip <catnip@catnip.fyi>", "Marcondiro"]
55
edition = "2021"
66
license = "MIT"

src/block/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl Block {
9292

9393
/// The execution mode for all instructions in this block.
9494
pub fn mode(&self) -> ExecModeType {
95-
ExecModeType::try_from(self.0.mode).unwrap()
95+
ExecModeType::try_from(self.0.mode as u32).unwrap()
9696
}
9797

9898
/// The instruction class for the last instruction in this block.
@@ -101,7 +101,7 @@ impl Block {
101101
/// class is not available. The block decoder may choose to not provide
102102
/// the instruction class in some cases for performance reasons.
103103
pub fn class(&self) -> Class {
104-
Class::try_from(self.0.iclass).unwrap()
104+
Class::try_from(self.0.iclass as u32).unwrap()
105105
}
106106

107107
/// The number of instructions in this block.

src/config/cpu.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
use libipt_sys::{
2-
pt_cpu,
3-
pt_cpu_vendor_pcv_intel,
4-
pt_cpu_vendor_pcv_unknown,
5-
pt_errata,
6-
pt_cpu_errata,
7-
};
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
4+
use libipt_sys::{pt_cpu, pt_cpu_vendor_pcv_intel, pt_cpu_vendor_pcv_unknown, pt_errata, pt_cpu_errata, pt_cpu_vendor};
85

96
use bitflags::bitflags;
107

@@ -43,8 +40,8 @@ mod test {
4340
bitflags! {
4441
/// i suppose this is relevant when/if amd finally gets intelpt support?
4542
pub struct CpuVendor: u32 {
46-
const INTEL = pt_cpu_vendor_pcv_intel;
47-
const UNKNOWN = pt_cpu_vendor_pcv_unknown;
43+
const INTEL = pt_cpu_vendor_pcv_intel as u32;
44+
const UNKNOWN = pt_cpu_vendor_pcv_unknown as u32;
4845
}
4946
}
5047

@@ -53,7 +50,7 @@ bitflags! {
5350
pub struct Cpu (pub(super) pt_cpu);
5451
impl Cpu {
5552
pub fn new(vendor: CpuVendor, family: u16, model: u8, stepping: u8) -> Self {
56-
Cpu(pt_cpu{ vendor: vendor.bits(), family, model, stepping })
53+
Cpu(pt_cpu{ vendor: vendor.bits() as pt_cpu_vendor, family, model, stepping })
5754
}
5855

5956
/// A shortcut for creating an intel Cpu instance

src/event/exec_mode.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
14
use std::convert::TryFrom;
25
use libipt_sys::{
36
pt_event__bindgen_ty_1__bindgen_ty_8,
@@ -39,10 +42,10 @@ mod test {
3942
#[derive(Clone, Copy, TryFromPrimitive, Debug, PartialEq)]
4043
#[repr(u32)]
4144
pub enum ExecModeType {
42-
Bit16 = pt_exec_mode_ptem_16bit,
43-
Bit32 = pt_exec_mode_ptem_32bit,
44-
Bit64 = pt_exec_mode_ptem_64bit,
45-
Unknown = pt_exec_mode_ptem_unknown
45+
Bit16 = pt_exec_mode_ptem_16bit as u32,
46+
Bit32 = pt_exec_mode_ptem_32bit as u32,
47+
Bit64 = pt_exec_mode_ptem_64bit as u32,
48+
Unknown = pt_exec_mode_ptem_unknown as u32
4649
}
4750

4851
/// An execution mode change
@@ -52,5 +55,5 @@ impl ExecMode {
5255
/// The address at which the event is effective
5356
pub fn ip(self) -> u64 { self.0.ip }
5457
/// The execution mode
55-
pub fn mode(self) -> ExecModeType { ExecModeType::try_from(self.0.mode).unwrap() }
58+
pub fn mode(self) -> ExecModeType { ExecModeType::try_from(self.0.mode as u32).unwrap() }
5659
}

src/flags.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
14
use libipt_sys::{
25
pt_status_flag_pts_eos,
36
pt_status_flag_pts_event_pending,
@@ -9,11 +12,11 @@ bitflags! {
912
/// Status flags for various IntelPT actions
1013
pub struct Status: u32 {
1114
/// There is no more trace data available.
12-
const EOS = pt_status_flag_pts_eos;
15+
const EOS = pt_status_flag_pts_eos as u32;
1316
/// There is an event pending.
14-
const EVENT_PENDING = pt_status_flag_pts_event_pending;
17+
const EVENT_PENDING = pt_status_flag_pts_event_pending as u32;
1518
/// The address has been suppressed.
16-
const IP_SUPRESSED = pt_status_flag_pts_ip_suppressed;
19+
const IP_SUPRESSED = pt_status_flag_pts_ip_suppressed as u32;
1720
}
1821
}
1922

src/insn/class.rs

+13-10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
14
use num_enum::TryFromPrimitive;
25
use libipt_sys::{
36
pt_insn_class_ptic_call,
@@ -20,26 +23,26 @@ use libipt_sys::{
2023
#[repr(u32)]
2124
pub enum Class {
2225
/// The instruction is a near (function) call.
23-
Call = pt_insn_class_ptic_call,
26+
Call = pt_insn_class_ptic_call as u32,
2427
/// The instruction is a near conditional jump.
25-
CondJump = pt_insn_class_ptic_cond_jump,
28+
CondJump = pt_insn_class_ptic_cond_jump as u32,
2629
/// The instruction could not be classified.
27-
Error = pt_insn_class_ptic_error,
30+
Error = pt_insn_class_ptic_error as u32,
2831
/// The instruction is a call-like far transfer.
2932
/// E.g. SYSCALL, SYSENTER, or FAR CALL.
30-
FarCall = pt_insn_class_ptic_far_call,
33+
FarCall = pt_insn_class_ptic_far_call as u32,
3134
/// The instruction is a jump-like far transfer.
3235
/// E.g. FAR JMP.
33-
FarJump = pt_insn_class_ptic_far_jump,
36+
FarJump = pt_insn_class_ptic_far_jump as u32,
3437
/// The instruction is a return-like far transfer.
3538
/// E.g. SYSRET, SYSEXIT, IRET, or FAR RET.
36-
FarReturn = pt_insn_class_ptic_far_return,
39+
FarReturn = pt_insn_class_ptic_far_return as u32,
3740
/// The instruction is a near unconditional jump.
38-
Jump = pt_insn_class_ptic_jump,
41+
Jump = pt_insn_class_ptic_jump as u32,
3942
/// The instruction is something not listed below.
40-
Other = pt_insn_class_ptic_other,
43+
Other = pt_insn_class_ptic_other as u32,
4144
/// The instruction is a PTWRITE.
42-
Ptwrite = pt_insn_class_ptic_ptwrite,
45+
Ptwrite = pt_insn_class_ptic_ptwrite as u32,
4346
/// The instruction is a near (function) return.
44-
Return = pt_insn_class_ptic_return
47+
Return = pt_insn_class_ptic_return as u32,
4548
}

src/insn/insn.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
14
use crate::event::ExecModeType;
25
use super::Class;
36

@@ -50,14 +53,14 @@ impl Insn {
5053

5154
/// The execution mode.
5255
pub fn mode(self) -> ExecModeType {
53-
ExecModeType::try_from(self.0.mode)
56+
ExecModeType::try_from(self.0.mode as u32)
5457
.expect(concat!("unmatched ExecModeType enum value, ",
5558
"this is a bug in either libipt or the bindings"))
5659
}
5760

5861
/// A coarse classification.
5962
pub fn class(self) -> Class {
60-
Class::try_from(self.0.iclass)
63+
Class::try_from(self.0.iclass as u32)
6164
.expect(concat!("unmatched Class enum value, ",
6265
"this is a bug in either libipt or the bindings"))
6366
}

src/packet/ip.rs

+23-19
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Certain casts are required only on Windows. Inform Clippy to ignore them.
2+
#![allow(clippy::unnecessary_cast)]
3+
14
use std::convert::TryFrom;
25
use num_enum::{TryFromPrimitive, IntoPrimitive};
36
use libipt_sys::{
@@ -6,35 +9,36 @@ use libipt_sys::{
69
pt_packet_type_ppt_fup,
710
pt_packet_type_ppt_tip_pge,
811
pt_packet_type_ppt_tip_pgd,
12+
pt_ip_compression,
913
pt_ip_compression_pt_ipc_full,
1014
pt_ip_compression_pt_ipc_sext_48,
1115
pt_ip_compression_pt_ipc_suppressed,
1216
pt_ip_compression_pt_ipc_update_16,
1317
pt_ip_compression_pt_ipc_update_32,
14-
pt_ip_compression_pt_ipc_update_48
18+
pt_ip_compression_pt_ipc_update_48,
1519
};
1620

1721
/// The IP compression
1822
#[derive(Clone, Copy, Debug, TryFromPrimitive, IntoPrimitive)]
1923
#[repr(u32)]
2024
pub enum Compression {
2125
/// No payload. The IP has been suppressed
22-
Suppressed = pt_ip_compression_pt_ipc_suppressed,
26+
Suppressed = pt_ip_compression_pt_ipc_suppressed as u32,
2327

2428
/// Payload: 16 bits. Update last IP
25-
Update16 = pt_ip_compression_pt_ipc_update_16,
29+
Update16 = pt_ip_compression_pt_ipc_update_16 as u32,
2630

2731
/// Payload: 32 bits. Update last IP
28-
Update32 = pt_ip_compression_pt_ipc_update_32,
32+
Update32 = pt_ip_compression_pt_ipc_update_32 as u32,
2933

3034
/// Payload: 48 bits. Sign extend to full address
31-
Sext48 = pt_ip_compression_pt_ipc_sext_48,
35+
Sext48 = pt_ip_compression_pt_ipc_sext_48 as u32,
3236

3337
/// Payload: 48 bits. Update last IP
34-
Update48 = pt_ip_compression_pt_ipc_update_48,
38+
Update48 = pt_ip_compression_pt_ipc_update_48 as u32,
3539

3640
/// Payload: 64 bits. Full address
37-
Full = pt_ip_compression_pt_ipc_full
41+
Full = pt_ip_compression_pt_ipc_full as u32,
3842
}
3943

4044
/// A packet with IP payload.
@@ -44,7 +48,7 @@ pub struct Tip (pt_packet_ip);
4448
impl Tip {
4549
#[inline]
4650
pub fn new(tip: u64, compression: Compression) -> Self {
47-
Tip (pt_packet_ip { ip: tip, ipc: compression.into() })
51+
Tip (pt_packet_ip { ip: tip, ipc: u32::from(compression) as pt_ip_compression })
4852
}
4953

5054
/// Zero-extended payload ip
@@ -59,13 +63,13 @@ impl Tip {
5963
pub fn compression(self) -> Compression {
6064
// if this tryfrom panics, there is a bug
6165
// in either libipt or this crate.
62-
Compression::try_from(self.0.ipc).unwrap()
66+
Compression::try_from(self.0.ipc as u32).unwrap()
6367
}
6468

6569
/// IP compression
6670
#[inline]
6771
pub fn set_compression(&mut self, compression: Compression) {
68-
self.0.ipc = compression.into()
72+
self.0.ipc = u32::from(compression) as pt_ip_compression
6973
}
7074
}
7175

@@ -76,7 +80,7 @@ pub struct Fup (pt_packet_ip);
7680
impl Fup {
7781
#[inline]
7882
pub fn new(fup: u64, compression: Compression) -> Self {
79-
Fup (pt_packet_ip { ip: fup, ipc: compression.into() })
83+
Fup (pt_packet_ip { ip: fup, ipc: u32::from(compression) as pt_ip_compression })
8084
}
8185

8286
/// Zero-extended payload ip
@@ -91,13 +95,13 @@ impl Fup {
9195
pub fn compression(self) -> Compression {
9296
// if this tryfrom panics, there is a bug
9397
// in either libipt or this crate.
94-
Compression::try_from(self.0.ipc).unwrap()
98+
Compression::try_from(self.0.ipc as u32).unwrap()
9599
}
96100

97101
/// IP compression
98102
#[inline]
99103
pub fn set_compression(&mut self, compression: Compression) {
100-
self.0.ipc = compression.into()
104+
self.0.ipc = u32::from(compression) as pt_ip_compression;
101105
}
102106
}
103107

@@ -108,7 +112,7 @@ pub struct TipPge (pt_packet_ip);
108112
impl TipPge {
109113
#[inline]
110114
pub fn new(tippge: u64, compression: Compression) -> Self {
111-
TipPge (pt_packet_ip { ip: tippge, ipc: compression.into() })
115+
TipPge (pt_packet_ip { ip: tippge, ipc: u32::from(compression) as pt_ip_compression })
112116
}
113117

114118
/// Zero-extended payload ip
@@ -123,13 +127,13 @@ impl TipPge {
123127
pub fn compression(self) -> Compression {
124128
// if this tryfrom panics, there is a bug
125129
// in either libipt or this crate.
126-
Compression::try_from(self.0.ipc).unwrap()
130+
Compression::try_from(self.0.ipc as u32).unwrap()
127131
}
128132

129133
/// IP compression
130134
#[inline]
131135
pub fn set_compression(&mut self, compression: Compression) {
132-
self.0.ipc = compression.into()
136+
self.0.ipc = u32::from(compression) as pt_ip_compression
133137
}
134138
}
135139

@@ -140,7 +144,7 @@ pub struct TipPgd (pt_packet_ip);
140144
impl TipPgd {
141145
#[inline]
142146
pub fn new(tippgd: u64, compression: Compression) -> Self {
143-
TipPgd (pt_packet_ip { ip: tippgd, ipc: compression.into() })
147+
TipPgd (pt_packet_ip { ip: tippgd, ipc: u32::from(compression) as pt_ip_compression })
144148
}
145149

146150
/// Zero-extended payload ip
@@ -155,13 +159,13 @@ impl TipPgd {
155159
pub fn compression(self) -> Compression {
156160
// if this tryfrom panics, there is a bug
157161
// in either libipt or this crate.
158-
Compression::try_from(self.0.ipc).unwrap()
162+
Compression::try_from(self.0.ipc as u32).unwrap()
159163
}
160164

161165
/// IP compression
162166
#[inline]
163167
pub fn set_compression(&mut self, compression: Compression) {
164-
self.0.ipc = compression.into()
168+
self.0.ipc = u32::from(compression) as pt_ip_compression
165169
}
166170
}
167171

0 commit comments

Comments
 (0)