driver_entry_interface.h
Go to the documentation of this file.
1 /*
2  * Bareflank Hypervisor
3  *
4  * Copyright (C) 2015 Assured Information Security, Inc.
5  * Author: Rian Quinn <quinnr@ainfosec.com>
6  * Author: Brendan Kerrigan <kerriganb@ainfosec.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #ifndef DRIVER_ENTRY_INTERFACE_H
24 #define DRIVER_ENTRY_INTERFACE_H
25 
26 #include <types.h>
27 #include <debug_ring_interface.h>
28 
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32 
33 /* -------------------------------------------------------------------------- */
34 /* Common */
35 /* -------------------------------------------------------------------------- */
36 
37 /*
38  * Driver Entry State Machine
39  *
40  * The driver entry has three major states that it could end up in. When the
41  * driver entry is unloaded, it means that the VMM has not been placed in
42  * memory. The loaded state means that the VMM is in memory, and relocated.
43  * In this state, symbol lookups are possible, and thus things like the VMM
44  * dump command work. The running state means that the VMM is actually running.
45  * The goal of the state machine is to ensure that the driver keeps track of
46  * the state of the VMM, and handles its transition properly.
47  */
48 #define VMM_UNLOADED 10
49 #define VMM_LOADED 11
50 #define VMM_RUNNING 12
51 #define VMM_CORRUPT 100
52 
53 #ifndef BAREFLANK_NAME
54 #define BAREFLANK_NAME "bareflank"
55 #endif
56 
57 #ifndef BAREFLANK_MAJOR
58 #define BAREFLANK_MAJOR 150
59 #endif
60 
61 #ifndef BAREFLANK_DEVICETYPE
62 #define BAREFLANK_DEVICETYPE 0xF00D
63 #endif
64 
65 #define IOCTL_ADD_MODULE_LENGTH_CMD 0x801
66 #define IOCTL_ADD_MODULE_CMD 0x802
67 #define IOCTL_LOAD_VMM_CMD 0x803
68 #define IOCTL_UNLOAD_VMM_CMD 0x804
69 #define IOCTL_START_VMM_CMD 0x805
70 #define IOCTL_STOP_VMM_CMD 0x806
71 #define IOCTL_DUMP_VMM_CMD 0x807
72 #define IOCTL_VMM_STATUS_CMD 0x808
73 #define IOCTL_SET_CPUID_CMD 0x809
74 #define IOCTL_SET_VCPUID_CMD 0x80A
75 #define IOCTL_VMCALL_CMD 0x80B
76 
77 /* -------------------------------------------------------------------------- */
78 /* Linux Interfaces */
79 /* -------------------------------------------------------------------------- */
80 
81 #ifdef __linux__
82 
91 #define IOCTL_ADD_MODULE_LENGTH _IOW(BAREFLANK_MAJOR, IOCTL_ADD_MODULE_LENGTH_CMD, uint64_t *)
92 
104 #define IOCTL_ADD_MODULE _IOW(BAREFLANK_MAJOR, IOCTL_ADD_MODULE_CMD, char *)
105 
113 #define IOCTL_LOAD_VMM _IO(BAREFLANK_MAJOR, IOCTL_LOAD_VMM_CMD)
114 
124 #define IOCTL_UNLOAD_VMM _IO(BAREFLANK_MAJOR, IOCTL_UNLOAD_VMM_CMD)
125 
134 #define IOCTL_START_VMM _IO(BAREFLANK_MAJOR, IOCTL_START_VMM_CMD)
135 
142 #define IOCTL_STOP_VMM _IO(BAREFLANK_MAJOR, IOCTL_STOP_VMM_CMD)
143 
151 #define IOCTL_DUMP_VMM _IOR(BAREFLANK_MAJOR, IOCTL_DUMP_VMM_CMD, struct debug_ring_resources_t *)
152 
159 #define IOCTL_VMM_STATUS _IOR(BAREFLANK_MAJOR, IOCTL_VMM_STATUS_CMD, int64_t *)
160 
169 #define IOCTL_SET_CPUID _IOW(BAREFLANK_MAJOR, IOCTL_SET_CPUID_CMD, uint64_t *)
170 
179 #define IOCTL_SET_VCPUID _IOW(BAREFLANK_MAJOR, IOCTL_SET_VCPUID_CMD, uint64_t *)
180 
188 #define IOCTL_VMCALL _IOW(BAREFLANK_MAJOR, IOCTL_VMCALL_CMD, struct vmcall_registers_t *)
189 
190 #endif
191 
192 /* -------------------------------------------------------------------------- */
193 /* Windows Interfaces */
194 /* -------------------------------------------------------------------------- */
195 
196 #if defined(_WIN32) || defined(__CYGWIN__)
197 
198 #include <initguid.h>
199 
200 DEFINE_GUID(GUID_DEVINTERFACE_bareflank,
201  0x1d9c9218, 0x3c88, 0x4b81, 0x8e, 0x81, 0xb4, 0x62, 0x2a, 0x4d, 0xcb, 0x44);
202 
214 #define IOCTL_ADD_MODULE CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_ADD_MODULE_CMD, METHOD_IN_DIRECT, FILE_WRITE_DATA)
215 
223 #define IOCTL_LOAD_VMM CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_LOAD_VMM_CMD, METHOD_BUFFERED, 0)
224 
234 #define IOCTL_UNLOAD_VMM CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_UNLOAD_VMM_CMD, METHOD_BUFFERED, 0)
235 
244 #define IOCTL_START_VMM CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_START_VMM_CMD, METHOD_BUFFERED, 0)
245 
252 #define IOCTL_STOP_VMM CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_STOP_VMM_CMD, METHOD_BUFFERED, 0)
253 
261 #define IOCTL_DUMP_VMM CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_DUMP_VMM_CMD, METHOD_OUT_DIRECT, FILE_READ_DATA)
262 
269 #define IOCTL_VMM_STATUS CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_VMM_STATUS_CMD, METHOD_BUFFERED, FILE_READ_DATA)
270 
279 #define IOCTL_SET_CPUID CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_SET_CPUID_CMD, METHOD_IN_DIRECT, FILE_WRITE_DATA)
280 
289 #define IOCTL_SET_VCPUID CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_SET_VCPUID_CMD, METHOD_IN_DIRECT, FILE_WRITE_DATA)
290 
298 #define IOCTL_VMCALL CTL_CODE(BAREFLANK_DEVICETYPE, IOCTL_VMCALL_CMD, METHOD_IN_DIRECT, FILE_WRITE_DATA)
299 
300 #endif
301 
302 /* -------------------------------------------------------------------------- */
303 /* OSX Interfaces */
304 /* -------------------------------------------------------------------------- */
305 
306 #ifdef __APPLE__
307 
308 typedef struct bf_ioctl
309 {
310  uint32_t command;
311  uint32_t size;
312  void *addr;
313 } bf_ioctl_t;
314 
315 #define IOCTL_ADD_MODULE_LENGTH IOCTL_ADD_MODULE_LENGTH_CMD
316 #define IOCTL_ADD_MODULE IOCTL_ADD_MODULE_CMD
317 #define IOCTL_LOAD_VMM IOCTL_LOAD_VMM_CMD
318 #define IOCTL_UNLOAD_VMM IOCTL_UNLOAD_VMM_CMD
319 #define IOCTL_START_VMM IOCTL_START_VMM_CMD
320 #define IOCTL_STOP_VMM IOCTL_STOP_VMM_CMD
321 #define IOCTL_DUMP_VMM IOCTL_DUMP_VMM_CMD
322 #define IOCTL_VMM_STATUS IOCTL_VMM_STATUS_CMD
323 #define IOCTL_SET_VCPUID IOCTL_SET_VCPUID_CMD
324 
325 #endif
326 
327 #ifdef __cplusplus
328 }
329 #endif
330 
331 #endif
constexpr const auto size
constexpr const auto addr
Definition: cpuid_x64.h:80