-
Notifications
You must be signed in to change notification settings - Fork 0
/
kvm.h
101 lines (81 loc) · 2.16 KB
/
kvm.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
// This file is part of KEmuFuzzer.
//
// KEmuFuzzer is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// KEmuFuzzer is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
// details.
//
// You should have received a copy of the GNU General Public License along with
// KEmuFuzzer. If not, see <http://www.gnu.org/licenses/>.
#ifndef KVM_H
#define KVM_H
#include <stdint.h>
#include <x86.h>
#define EXPECTED_KVM_API_VERSION 12
#define MAXCPUS 4
#include <linux/kvm.h>
#if KVM_API_VERSION != EXPECTED_KVM_API_VERSION
#error "Wrong API version"
#endif
#include "x86_cpustate.h"
class KVM;
class VCPU {
private:
int slot;
int cpu_fd;
int exception;
KVM *kvm;
struct kvm_run *run;
friend class KVM;
public:
VCPU(KVM *, int);
~VCPU();
void SetRegs(struct kvm_regs *);
void GetRegs(struct kvm_regs *);
void SetSregs(struct kvm_sregs *);
void GetSregs(struct kvm_sregs *);
void SetFPU(struct kvm_fpu *);
void GetFPU(struct kvm_fpu *);
void SetMSRs(struct kvm_msr_entry *msrs, int n);
void GetMSRs(struct kvm_msr_entry *msrs, int *n);
struct kvm_run *Run();
int Bits();
int GetMem(void *, unsigned int, uint8_t *);
int SetMem(void *, unsigned int, uint8_t *);
void Disasm(void *, FILE *);
void DumpMem(void *, int, FILE *, bool = false);
void SetException(int);
};
class KVM {
private:
void *vm_mem;
unsigned int vm_mem_size;
VCPU *vcpus[MAXCPUS];
int cpusno;
type_t state_type;
uint8_t ioports[2];
friend class VCPU;
void Init(int, unsigned int);
protected:
int fd;
int vm_fd;
public:
KVM(int, unsigned int);
KVM(const char *);
~KVM();
VCPU *Cpu(int = 0);
void *Mem();
void Load(const char *);
void Save(const char *);
void Print(FILE *);
void SetIoPort(int, uint8_t);
uint8_t GetIoPort(int);
void SetStateType(type_t);
type_t GetStateType();
};
#endif