-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlkm.c
58 lines (47 loc) · 1.15 KB
/
lkm.c
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
#include <linux/init.h>
#include <linux/module.h>
#include <linux/printk.h>
#include "vmm.h"
#include "cpu.h"
#include "vmcs.h"
#include "intrin.h"
#include "common.h"
#include "hotplug.h"
vmm_ctx *g_vmm_ctx;
static int __init lkm_init (void)
{
LOG_DBG ("module loaded");
if (!cpu_hotplug_register ())
{
return -EPERM;
}
if (!vmm_new ())
{
cpu_hotplug_unregister ();
vmm_del ();
return -ENOMEM;
}
on_each_cpu (cpu_init_pre, NULL, true);
if (g_vmm_ctx->cpu_on != atomic_read (&g_vmm_ctx->cpu_init))
{
LOG_DBG ("cpu_on: %d - cpu_init: %d", g_vmm_ctx->cpu_on, atomic_read(&g_vmm_ctx->cpu_init));
cpu_hotplug_unregister ();
vmm_del ();
return -EPERM;
}
// hypervisor should be up and running now.
LOG_DBG ("all processors were virtualized successfully");
return 0;
}
static void __exit lkm_exit (void)
{
LOG_DBG ("module unloaded");
on_each_cpu (cpu_exit, NULL, true);
cpu_hotplug_unregister ();
vmm_del ();
}
module_init (lkm_init);
module_exit (lkm_exit);
MODULE_AUTHOR ("n1ghtc4ll");
MODULE_DESCRIPTION ("lightweight x86-64 vt-x hypervisor");
MODULE_LICENSE ("GPL");