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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
use winapi::shared::ntdef::{
BOOLEAN, HANDLE, LONG, NTSTATUS, PLONG, PUNICODE_STRING, PVOID, UCHAR, ULONG, UNICODE_STRING,
USHORT,
};
use winapi::um::winnt::{
DEVICE_POWER_STATE, EXECUTION_STATE, LATENCY_TIME, PDEVICE_POWER_STATE, PEXECUTION_STATE,
POWER_ACTION, POWER_INFORMATION_LEVEL, SYSTEM_POWER_STATE,
};
UNION!{union POWER_STATE {
SystemState: SYSTEM_POWER_STATE,
DeviceState: DEVICE_POWER_STATE,
}}
pub type PPOWER_STATE = *mut POWER_STATE;
ENUM!{enum POWER_STATE_TYPE {
SystemPowerState = 0,
DevicePowerState = 1,
}}
pub type PPOWER_STATE_TYPE = *mut POWER_STATE_TYPE;
STRUCT!{struct SYSTEM_POWER_STATE_CONTEXT {
ContextAsUlong: ULONG,
}}
BITFIELD!{SYSTEM_POWER_STATE_CONTEXT ContextAsUlong: ULONG [
Reserved1 set_Reserved1[0..8],
TargetSystemState set_TargetSystemState[8..12],
EffectiveSystemState set_EffectiveSystemState[12..16],
CurrentSystemState set_CurrentSystemState[16..20],
IgnoreHibernationPath set_IgnoreHibernationPath[20..21],
PseudoTransition set_PseudoTransition[21..22],
Reserved2 set_Reserved2[22..32],
]}
pub type PSYSTEM_POWER_STATE_CONTEXT = *mut SYSTEM_POWER_STATE_CONTEXT;
STRUCT!{struct COUNTED_REASON_CONTEXT_u_s {
ResourceFileName: UNICODE_STRING,
ResourceReasonId: USHORT,
StringCount: ULONG,
ReasonStrings: PUNICODE_STRING,
}}
UNION!{union COUNTED_REASON_CONTEXT_u {
s: COUNTED_REASON_CONTEXT_u_s,
SimpleString: UNICODE_STRING,
}}
STRUCT!{struct COUNTED_REASON_CONTEXT {
Version: ULONG,
Flags: ULONG,
u: COUNTED_REASON_CONTEXT_u,
}}
pub type PCOUNTED_REASON_CONTEXT = *mut COUNTED_REASON_CONTEXT;
ENUM!{enum POWER_STATE_HANDLER_TYPE {
PowerStateSleeping1 = 0,
PowerStateSleeping2 = 1,
PowerStateSleeping3 = 2,
PowerStateSleeping4 = 3,
PowerStateShutdownOff = 4,
PowerStateShutdownReset = 5,
PowerStateSleeping4Firmware = 6,
PowerStateMaximum = 7,
}}
pub type PPOWER_STATE_HANDLER_TYPE = *mut POWER_STATE_HANDLER_TYPE;
FN!{stdcall PENTER_STATE_SYSTEM_HANDLER(
SystemContext: PVOID,
) -> NTSTATUS}
FN!{stdcall PENTER_STATE_HANDLER(
Context: PVOID,
SystemHandler: PENTER_STATE_SYSTEM_HANDLER,
SystemContext: PVOID,
NumberProcessors: LONG,
Number: PLONG,
) -> NTSTATUS}
STRUCT!{struct POWER_STATE_HANDLER {
Type: POWER_STATE_HANDLER_TYPE,
RtcWake: BOOLEAN,
Spare: [UCHAR; 3],
Handler: PENTER_STATE_HANDLER,
Context: PVOID,
}}
pub type PPOWER_STATE_HANDLER = *mut POWER_STATE_HANDLER;
FN!{stdcall PENTER_STATE_NOTIFY_HANDLER(
State: POWER_STATE_HANDLER_TYPE,
Context: PVOID,
Entering: BOOLEAN,
) -> NTSTATUS}
STRUCT!{struct POWER_STATE_NOTIFY_HANDLER {
Handler: PENTER_STATE_NOTIFY_HANDLER,
Context: PVOID,
}}
pub type PPOWER_STATE_NOTIFY_HANDLER = *mut POWER_STATE_NOTIFY_HANDLER;
STRUCT!{struct PROCESSOR_POWER_INFORMATION {
Number: ULONG,
MaxMhz: ULONG,
CurrentMhz: ULONG,
MhzLimit: ULONG,
MaxIdleState: ULONG,
CurrentIdleState: ULONG,
}}
pub type PPROCESSOR_POWER_INFORMATION = *mut PROCESSOR_POWER_INFORMATION;
STRUCT!{struct SYSTEM_POWER_INFORMATION {
MaxIdlenessAllowed: ULONG,
Idleness: ULONG,
TimeRemaining: ULONG,
CoolingMode: UCHAR,
}}
pub type PSYSTEM_POWER_INFORMATION = *mut SYSTEM_POWER_INFORMATION;
EXTERN!{extern "system" {
fn NtPowerInformation(
InformationLevel: POWER_INFORMATION_LEVEL,
InputBuffer: PVOID,
InputBufferLength: ULONG,
OutputBuffer: PVOID,
OutputBufferLength: ULONG,
) -> NTSTATUS;
fn NtSetThreadExecutionState(
NewFlags: EXECUTION_STATE,
PreviousFlags: PEXECUTION_STATE,
) -> NTSTATUS;
fn NtRequestWakeupLatency(
latency: LATENCY_TIME,
) -> NTSTATUS;
fn NtInitiatePowerAction(
SystemAction: POWER_ACTION,
LightestSystemState: SYSTEM_POWER_STATE,
Flags: ULONG,
Asynchronous: BOOLEAN,
) -> NTSTATUS;
fn NtSetSystemPowerState(
SystemAction: POWER_ACTION,
LightestSystemState: SYSTEM_POWER_STATE,
Flags: ULONG,
) -> NTSTATUS;
fn NtGetDevicePowerState(
Device: HANDLE,
State: PDEVICE_POWER_STATE,
) -> NTSTATUS;
fn NtIsSystemResumeAutomatic() -> BOOLEAN;
}}
|