-
Notifications
You must be signed in to change notification settings - Fork 0
/
resubv.c
97 lines (82 loc) · 1.87 KB
/
resubv.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
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
/*
* ksm - a really simple and fast x64 hypervisor
* Copyright (C) 2016, 2017 Ahmed Samy <[email protected]>
*
* Public domain
*/
#ifdef ENABLE_RESUBV
#ifdef __linux__
#include <linux/syscore_ops.h>
#else
#include <ntddk.h>
#endif
#include "ksm.h"
#include "compiler.h"
#ifdef __linux__
static void ksm_resume(void)
{
KSM_DEBUG("in resume: %d\n", ksm_subvert(ksm));
}
static int ksm_suspend(void)
{
KSM_DEBUG("in suspend: %d\n", ksm_unsubvert(ksm));
return 0;
}
static struct syscore_ops syscore_ops = {
.resume = ksm_resume,
.suspend = ksm_suspend,
};
int register_power_callback(void)
{
register_syscore_ops(&syscore_ops);
return 0;
}
void unregister_power_callback(void)
{
unregister_syscore_ops(&syscore_ops);
}
#else
typedef struct _DEV_EXT {
void *CbRegistration;
PCALLBACK_OBJECT CbObject;
} DEV_EXT, *PDEV_EXT;
static DEV_EXT g_dev_ext;
static void power_callback(PDEV_EXT ctx, void *arg0, void *arg1)
{
if (arg0 != (void *)PO_CB_SYSTEM_STATE_LOCK)
return;
if (arg1 == (void *)0)
ksm_unsubvert(ksm);
else if (arg0 == (void *)1)
ksm_subvert(ksm);
}
int register_power_callback(void)
{
OBJECT_ATTRIBUTES obj;
UNICODE_STRING name;
NTSTATUS status;
PDEV_EXT ext = &g_dev_ext;
RtlInitUnicodeString(&name, L"\\Callback\\PowerState");
InitializeObjectAttributes(&obj, &name, OBJ_CASE_INSENSITIVE, NULL, NULL);
status = ExCreateCallback(&ext->CbObject, &obj, FALSE, TRUE);
if (!NT_SUCCESS(status))
return status;
ext->CbRegistration = ExRegisterCallback(ext->CbObject,
(PCALLBACK_FUNCTION)power_callback,
ext);
if (!ext->CbRegistration) {
ObDereferenceObject(ext->CbObject);
return STATUS_UNSUCCESSFUL;
}
return STATUS_SUCCESS;
}
void unregister_power_callback(void)
{
PDEV_EXT ext = &g_dev_ext;
if (ext->CbRegistration)
ExUnregisterCallback(ext->CbRegistration);
if (ext->CbObject)
ObDereferenceObject(ext->CbObject);
}
#endif
#endif