1use super::{VmiOsState, state::VmiState};
2use crate::{VmiCore, VmiEvent, VmiOs};
3
4pub struct VmiContext<'a, Os>
16where
17 Os: VmiOs,
18{
19 state: &'a VmiState<'a, Os>,
21
22 event: &'a VmiEvent<Os::Architecture>,
24}
25
26impl<Os> Clone for VmiContext<'_, Os>
27where
28 Os: VmiOs,
29{
30 fn clone(&self) -> Self {
31 *self
32 }
33}
34
35impl<Os> Copy for VmiContext<'_, Os> where Os: VmiOs {}
36
37impl<'a, Os> std::ops::Deref for VmiContext<'a, Os>
38where
39 Os: VmiOs,
40{
41 type Target = VmiState<'a, Os>;
42
43 fn deref(&self) -> &Self::Target {
44 self.state
45 }
46}
47
48impl<'a, Os> VmiContext<'a, Os>
49where
50 Os: VmiOs,
51{
52 pub fn new(state: &'a VmiState<'a, Os>, event: &'a VmiEvent<Os::Architecture>) -> Self {
54 debug_assert_eq!(state.registers() as *const _, event.registers() as *const _);
55
56 Self { state, event }
57 }
58
59 pub fn state(&self) -> VmiState<'a, Os> {
64 *self.state
65 }
66
67 pub fn event(&self) -> &VmiEvent<Os::Architecture> {
69 self.event
70 }
71
72 pub fn os(&self) -> VmiOsContext<'_, Os> {
74 VmiOsContext {
75 state: self.state.os(),
76 event: self.event,
77 }
78 }
79}
80
81pub struct VmiOsContext<'a, Os>
83where
84 Os: VmiOs,
85{
86 state: VmiOsState<'a, Os>,
88
89 event: &'a VmiEvent<Os::Architecture>,
91}
92
93impl<'a, Os> std::ops::Deref for VmiOsContext<'a, Os>
94where
95 Os: VmiOs,
96{
97 type Target = VmiOsState<'a, Os>;
98
99 fn deref(&self) -> &Self::Target {
100 &self.state
101 }
102}
103
104impl<Os> VmiOsContext<'_, Os>
105where
106 Os: VmiOs,
107{
108 pub fn core(&self) -> &VmiCore<Os::Driver> {
110 self.state.core()
111 }
112
113 pub fn underlying_os(&self) -> &Os {
115 self.state.underlying_os()
116 }
117
118 pub fn event(&self) -> &VmiEvent<Os::Architecture> {
120 self.event
121 }
122}