1use serde::{Deserialize, Serialize};
2
3use super::VmiOs;
4use crate::{Va, VmiDriver, VmiError, VmiVa};
5
6#[derive(
8 Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
9)]
10pub struct ThreadId(pub u32);
11
12impl From<u32> for ThreadId {
13 fn from(value: u32) -> Self {
14 Self(value)
15 }
16}
17
18impl From<ThreadId> for u32 {
19 fn from(value: ThreadId) -> Self {
20 value.0
21 }
22}
23
24impl std::fmt::Display for ThreadId {
25 fn fmt(&self, f: &mut std::fmt::Formatter) -> ::std::fmt::Result {
26 write!(f, "{}", self.0)
27 }
28}
29
30#[derive(
34 Debug, Default, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
35)]
36pub struct ThreadObject(pub Va);
37
38impl ThreadObject {
39 pub fn is_null(&self) -> bool {
41 self.0.0 == 0
42 }
43
44 pub fn to_u64(&self) -> u64 {
46 self.0.0
47 }
48}
49
50impl From<Va> for ThreadObject {
51 fn from(value: Va) -> Self {
52 Self(value)
53 }
54}
55
56impl From<ThreadObject> for Va {
57 fn from(value: ThreadObject) -> Self {
58 value.0
59 }
60}
61
62impl std::fmt::Display for ThreadObject {
63 fn fmt(&self, f: &mut std::fmt::Formatter) -> ::std::fmt::Result {
64 write!(f, "{}", self.0)
65 }
66}
67
68pub trait VmiOsThread<'a, Driver>: VmiVa + 'a
72where
73 Driver: VmiDriver,
74{
75 type Os: VmiOs<Driver>;
77
78 fn id(&self) -> Result<ThreadId, VmiError>;
80
81 fn object(&self) -> Result<ThreadObject, VmiError>;
83}