forked from ionescu007/SimpleVisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shv.h
184 lines (146 loc) · 2.62 KB
/
shv.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*++
Copyright (c) Alex Ionescu. All rights reserved.
Header Name:
shv.h
Abstract:
This header defines the structures and functions of the Simple Hyper Visor.
Author:
Alex Ionescu (@aionescu) 14-Mar-2016 - Initial version
Environment:
Kernel mode only.
--*/
#pragma once
#pragma warning(disable:4201)
#pragma warning(disable:4214)
#ifndef __BASE_H__
#include <basetsd.h>
#endif
#define _INC_MALLOC
#include <intrin.h>
#include "ntint.h"
#include "shv_x.h"
typedef struct _SHV_VP_STATE
{
PCONTEXT VpRegs;
uintptr_t GuestRip;
uintptr_t GuestRsp;
uintptr_t GuestEFlags;
UINT16 ExitReason;
UINT8 ExitVm;
} SHV_VP_STATE, *PSHV_VP_STATE;
typedef struct _SHV_CALLBACK_CONTEXT
{
UINT64 Cr3;
volatile long InitCount;
INT32 FailedCpu;
INT32 FailureStatus;
} SHV_CALLBACK_CONTEXT, *PSHV_CALLBACK_CONTEXT;
SHV_CPU_CALLBACK ShvVpLoadCallback;
SHV_CPU_CALLBACK ShvVpUnloadCallback;
VOID
ShvVmxEntry (
VOID
);
INT32
ShvVmxLaunchOnVp (
_In_ PSHV_VP_DATA VpData
);
VOID
ShvUtilConvertGdtEntry (
_In_ VOID* GdtBase,
_In_ UINT16 Offset,
_Out_ PVMX_GDTENTRY64 VmxGdtEntry
);
UINT32
ShvUtilAdjustMsr (
_In_ LARGE_INTEGER ControlValue,
_In_ UINT32 DesiredValue
);
PSHV_VP_DATA
ShvVpAllocateData (
_In_ UINT32 CpuCount
);
VOID
ShvVpFreeData (
_In_ PSHV_VP_DATA Data,
_In_ UINT32 CpuCount
);
INT32
ShvVmxLaunch (
VOID
);
UINT8
ShvVmxProbe (
VOID
);
VOID
ShvVmxEptInitialize (
_In_ PSHV_VP_DATA VpData
);
DECLSPEC_NORETURN
VOID
ShvVpRestoreAfterLaunch (
VOID
);
//
// OS Layer
//
DECLSPEC_NORETURN
VOID
__cdecl
ShvOsRestoreContext (
_In_ PCONTEXT ContextRecord
);
VOID
ShvOsCaptureContext (
_In_ PCONTEXT ContextRecord
);
VOID
ShvOsUnprepareProcessor (
_In_ PSHV_VP_DATA VpData
);
INT32
ShvOsPrepareProcessor (
_In_ PSHV_VP_DATA VpData
);
INT32
ShvOsGetActiveProcessorCount (
VOID
);
INT32
ShvOsGetCurrentProcessorNumber (
VOID
);
VOID
ShvOsFreeContiguousAlignedMemory (
_In_ VOID* BaseAddress,
_In_ size_t Size
);
VOID*
ShvOsAllocateContigousAlignedMemory (
_In_ size_t Size
);
UINT64
ShvOsGetPhysicalAddress (
_In_ VOID* BaseAddress
);
#ifndef __BASE_H__
VOID
ShvOsDebugPrint (
_In_ const char* Format,
...
);
#else
VOID
ShvOsDebugPrintWide (
_In_ const CHAR16* Format,
...
);
#define ShvOsDebugPrint(format, ...) ShvOsDebugPrintWide(_CRT_WIDE(format), __VA_ARGS__)
#endif
VOID
ShvOsRunCallbackOnProcessors (
_In_ PSHV_CPU_CALLBACK Routine,
_In_opt_ VOID* Context
);
extern PSHV_VP_DATA* ShvGlobalData;