Skip to main content

vmi_core/os/
thread.rs

1use super::{VmiOs, impl_ops};
2use crate::{Va, VmiDriver, VmiError, VmiVa};
3
4impl_ops! {
5    /// A thread ID within a system.
6    ThreadId, u32
7}
8
9impl_ops! {
10    /// A thread object within a system.
11    ///
12    /// Equivalent to `ETHREAD*` on Windows.
13    ThreadObject, Va
14}
15
16impl VmiVa for ThreadObject {
17    fn va(&self) -> Va {
18        self.0
19    }
20}
21
22impl ThreadObject {
23    /// Checks if the thread object is a null reference.
24    pub fn is_null(&self) -> bool {
25        self.0.0 == 0
26    }
27
28    /// Converts the thread object to a 64-bit unsigned integer.
29    pub fn to_u64(&self) -> u64 {
30        self.0.0
31    }
32}
33
34/// A trait for thread objects.
35///
36/// This trait provides an abstraction over threads within a guest OS.
37pub trait VmiOsThread<'a, Driver>: VmiVa + 'a
38where
39    Driver: VmiDriver,
40{
41    /// The VMI OS type.
42    type Os: VmiOs<Driver = Driver>;
43
44    /// Returns the thread ID.
45    fn id(&self) -> Result<ThreadId, VmiError>;
46
47    /// Returns the thread object.
48    fn object(&self) -> Result<ThreadObject, VmiError>;
49}