-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmabi.h
76 lines (65 loc) · 2.51 KB
/
mabi.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
/* SPDX-License-Identifier: (GPL-2.0 WITH Linux-syscall-note) OR MIT */
#ifndef MABI_H
#define MABI_H
/**
* @file mabi.h
* @brief Define memflow kernel module ABI
*
* Provides all structures and ioctls for interacting with memflow's kernel module
*
*/
#include <linux/types.h>
#include <linux/ioctl.h>
/// @brief structure describing a guest to host memory mapping
typedef struct vm_memslot {
/// Base physical address in the guest
__aligned_u64 base;
/// Host virtual address where the guest base resides in
__aligned_u64 host_base;
/// Size of the mapping
__aligned_u64 map_size;
} vm_memslot_t;
/// @brief structure describing the virtual machine
typedef struct vm_info {
/// PID of userspace VM monitor.
__kernel_pid_t userspace_pid;
/// Number of memory slots allocated by userspace. After MEMFLOW_VM_INFO ioctl -
/// number of slots in the VM
__u32 slot_count;
/// The memory slots, sorted by base address
struct vm_memslot *slots;
} vm_info_t;
/// @brief structure describing memory layout of the mapped virtual machine
typedef struct vm_map_info {
/// Number of memory slots that were allocated. After MEMFLOW_MAP_VM ioctl -
/// number of slots that were mapped in the VM
__u32 slot_count;
/// The mapped memory slots, sorted by base address. Slots only include the regions that were mapped in,
/// so the first, and the last slots may not be the full KVM memslots, if not everything is mapped in
struct vm_memslot *slots;
} vm_map_info_t;
#define MEMFLOW_IOCTL_MAGIC 0x6d
/**
* @brief Get a file descriptor to KVM based virtual machine
*
* Returns a file descriptor to KVM VMM in the given process. If the pid is 0, handle from any VMM is returned.
* If the process does not have a KVM instance, -1 is returned.
*
* The KVM instance will not be freed until the returned fd is closed.
*/
#define MEMFLOW_OPEN_VM _IOR(MEMFLOW_IOCTL_MAGIC, 0, __kernel_pid_t)
/**
* @brief Describe the virtual machine
*
* Fills `vm_info_t` structure that describes the virtual machine. Note that the memory layout of the VM may
* change before it gets mapped in, so it is advised to use MEMFLOW_VM_MAP_INFO after mapping the VM in.
*/
#define MEMFLOW_VM_INFO _IOWR(MEMFLOW_IOCTL_MAGIC, 1, vm_info_t)
/**
* @brief Map the VM and retrieve its memory layout
*
* Fills `vm_map_info_t` structure that describes the memory layout of the mapped VM. Returns a file descriptor
* to the memory mapping handle. The VM memory stays mapped in, until the fd gets closed.
*/
#define MEMFLOW_MAP_VM _IOWR(MEMFLOW_IOCTL_MAGIC, 2, vm_map_info_t)
#endif