This is an educated guess on what these would be, based on: *) The power request APIs in kernel32. *) The power request APIs exposed for drivers' use in ntoskrnl. *) Other NtXxx calls.
Signed-off-by: Chip Davis [email protected] ---
Notes: v2: Move POWER_REQUEST_TYPE to winnt.h to try to fix the build.
dlls/ntdll/nt.c | 33 +++++++++++++++++++++++++++++++++ dlls/ntdll/ntdll.spec | 6 ++++++ include/winbase.h | 7 ------- include/winnt.h | 7 +++++++ include/winternl.h | 20 ++++++++++++++++++++ 5 files changed, 66 insertions(+), 7 deletions(-)
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index cdfbd9fa822..a9985fbc224 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -3073,6 +3073,39 @@ NTSTATUS WINAPI NtSetThreadExecutionState( EXECUTION_STATE new_state, EXECUTION_ return STATUS_SUCCESS; }
+/****************************************************************************** + * NtCreatePowerRequest [NTDLL.@] + * + */ +NTSTATUS WINAPI NtCreatePowerRequest( HANDLE *handle, COUNTED_REASON_CONTEXT *context ) +{ + FIXME( "(%p, %p): stub\n", handle, context ); + + return STATUS_NOT_IMPLEMENTED; +} + +/****************************************************************************** + * NtSetPowerRequest [NTDLL.@] + * + */ +NTSTATUS WINAPI NtSetPowerRequest( HANDLE handle, POWER_REQUEST_TYPE type ) +{ + FIXME( "(%p, %u): stub\n", handle, type ); + + return STATUS_NOT_IMPLEMENTED; +} + +/****************************************************************************** + * NtClearPowerRequest [NTDLL.@] + * + */ +NTSTATUS WINAPI NtClearPowerRequest( HANDLE handle, POWER_REQUEST_TYPE type ) +{ + FIXME( "(%p, %u): stub\n", handle, type ); + + return STATUS_NOT_IMPLEMENTED; +} + #ifdef linux /* Fallback using /proc/cpuinfo for Linux systems without cpufreq. For * most distributions on recent enough hardware, this is only likely to diff --git a/dlls/ntdll/ntdll.spec b/dlls/ntdll/ntdll.spec index 278699c7077..32b2f614468 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -142,6 +142,7 @@ @ stdcall NtCancelIoFileEx(long ptr ptr) @ stdcall NtCancelTimer(long ptr) @ stdcall NtClearEvent(long) +@ stdcall NtClearPowerRequest(long long) @ stdcall NtClose(long) @ stub NtCloseObjectAuditAlarm # @ stub NtCompactKeys @@ -167,6 +168,7 @@ @ stdcall NtCreateNamedPipeFile(ptr long ptr ptr long long long long long long long long long ptr) @ stdcall NtCreatePagingFile(ptr ptr ptr ptr) @ stdcall NtCreatePort(ptr ptr long long ptr) +@ stdcall NtCreatePowerRequest(ptr ptr) @ stub NtCreateProcess # @ stub NtCreateProcessEx @ stub NtCreateProfile @@ -374,6 +376,7 @@ @ stub NtSetLowEventPair @ stub NtSetLowWaitHighEventPair @ stub NtSetLowWaitHighThread +@ stdcall NtSetPowerRequest(long long) # @ stub NtSetQuotaInformationFile @ stdcall NtSetSecurityObject(long long ptr) @ stub NtSetSystemEnvironmentValue @@ -1094,6 +1097,7 @@ @ stdcall -private ZwCancelIoFileEx(long ptr ptr) NtCancelIoFileEx @ stdcall -private ZwCancelTimer(long ptr) NtCancelTimer @ stdcall -private ZwClearEvent(long) NtClearEvent +@ stdcall -private ZwClearPowerRequest(long long) NtClearPowerRequest @ stdcall -private ZwClose(long) NtClose @ stub ZwCloseObjectAuditAlarm # @ stub ZwCompactKeys @@ -1118,6 +1122,7 @@ @ stdcall -private ZwCreateNamedPipeFile(ptr long ptr ptr long long long long long long long long long ptr) NtCreateNamedPipeFile @ stdcall -private ZwCreatePagingFile(ptr ptr ptr ptr) NtCreatePagingFile @ stdcall -private ZwCreatePort(ptr ptr long long ptr) NtCreatePort +@ stdcall -private ZwCreatePowerRequest(ptr ptr) NtCreatePowerRequest @ stub ZwCreateProcess # @ stub ZwCreateProcessEx @ stub ZwCreateProfile @@ -1323,6 +1328,7 @@ @ stub ZwSetLowEventPair @ stub ZwSetLowWaitHighEventPair @ stub ZwSetLowWaitHighThread +@ stdcall -private ZwSetPowerRequest(long long) NtSetPowerRequest # @ stub ZwSetQuotaInformationFile @ stdcall -private ZwSetSecurityObject(long long ptr) NtSetSecurityObject @ stub ZwSetSystemEnvironmentValue diff --git a/include/winbase.h b/include/winbase.h index 086a8b36459..9ee290a5b6c 100644 --- a/include/winbase.h +++ b/include/winbase.h @@ -966,13 +966,6 @@ typedef struct _SYSTEM_POWER_STATUS DWORD BatteryFullLifeTime; } SYSTEM_POWER_STATUS, *LPSYSTEM_POWER_STATUS;
-typedef enum _POWER_REQUEST_TYPE -{ - PowerRequestDisplayRequired, - PowerRequestSystemRequired, - PowerRequestAwayModeRequired -} POWER_REQUEST_TYPE, *PPOWER_REQUEST_TYPE; - typedef struct _SYSTEM_INFO { union { diff --git a/include/winnt.h b/include/winnt.h index 40d883e3a92..a9ecd5a5a99 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -5582,6 +5582,13 @@ typedef struct _SYSTEM_POWER_POLICY { } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
+typedef enum _POWER_REQUEST_TYPE +{ + PowerRequestDisplayRequired, + PowerRequestSystemRequired, + PowerRequestAwayModeRequired +} POWER_REQUEST_TYPE, *PPOWER_REQUEST_TYPE; + typedef union _FILE_SEGMENT_ELEMENT { PVOID64 Buffer; ULONGLONG Alignment; diff --git a/include/winternl.h b/include/winternl.h index d6543917e64..fd898e93f05 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2070,6 +2070,23 @@ typedef enum _SHUTDOWN_ACTION { ShutdownPowerOff } SHUTDOWN_ACTION, *PSHUTDOWN_ACTION;
+typedef struct _COUNTED_REASON_CONTEXT +{ + ULONG Version; + ULONG Flags; + union + { + struct + { + UNICODE_STRING ResourceFileName; + USHORT ResourceReasonId; + ULONG StringCount; + UNICODE_STRING *ReasonStrings; + } DUMMYSTRUCTNAME; + UNICODE_STRING SimpleString; + } DUMMYUNIONNAME; +} COUNTED_REASON_CONTEXT, *PCOUNTED_REASON_CONTEXT; + typedef enum _KPROFILE_SOURCE { ProfileTime, ProfileAlignmentFixup, @@ -2326,6 +2343,7 @@ NTSYSAPI NTSTATUS WINAPI NtCancelIoFile(HANDLE,PIO_STATUS_BLOCK); NTSYSAPI NTSTATUS WINAPI NtCancelIoFileEx(HANDLE,PIO_STATUS_BLOCK,PIO_STATUS_BLOCK); NTSYSAPI NTSTATUS WINAPI NtCancelTimer(HANDLE, BOOLEAN*); NTSYSAPI NTSTATUS WINAPI NtClearEvent(HANDLE); +NTSYSAPI NTSTATUS WINAPI NtClearPowerRequest(HANDLE,POWER_REQUEST_TYPE); NTSYSAPI NTSTATUS WINAPI NtClose(HANDLE); NTSYSAPI NTSTATUS WINAPI NtCloseObjectAuditAlarm(PUNICODE_STRING,HANDLE,BOOLEAN); NTSYSAPI NTSTATUS WINAPI NtCompleteConnectPort(HANDLE); @@ -2345,6 +2363,7 @@ NTSYSAPI NTSTATUS WINAPI NtCreateMutant(HANDLE*,ACCESS_MASK,const OBJECT_ATTRIB NTSYSAPI NTSTATUS WINAPI NtCreateNamedPipeFile(PHANDLE,ULONG,POBJECT_ATTRIBUTES,PIO_STATUS_BLOCK,ULONG,ULONG,ULONG,ULONG,ULONG,ULONG,ULONG,ULONG,ULONG,PLARGE_INTEGER); NTSYSAPI NTSTATUS WINAPI NtCreatePagingFile(PUNICODE_STRING,PLARGE_INTEGER,PLARGE_INTEGER,PLARGE_INTEGER); NTSYSAPI NTSTATUS WINAPI NtCreatePort(PHANDLE,POBJECT_ATTRIBUTES,ULONG,ULONG,PULONG); +NTSYSAPI NTSTATUS WINAPI NtCreatePowerRequest(HANDLE*,COUNTED_REASON_CONTEXT*); NTSYSAPI NTSTATUS WINAPI NtCreateProcess(PHANDLE,ACCESS_MASK,POBJECT_ATTRIBUTES,HANDLE,BOOLEAN,HANDLE,HANDLE,HANDLE); NTSYSAPI NTSTATUS WINAPI NtCreateProfile(PHANDLE,HANDLE,PVOID,ULONG,ULONG,PVOID,ULONG,KPROFILE_SOURCE,KAFFINITY); NTSYSAPI NTSTATUS WINAPI NtCreateSection(HANDLE*,ACCESS_MASK,const OBJECT_ATTRIBUTES*,const LARGE_INTEGER*,ULONG,ULONG,HANDLE); @@ -2510,6 +2529,7 @@ NTSYSAPI NTSTATUS WINAPI NtSetLdtEntries(ULONG,ULONG,ULONG,ULONG,ULONG,ULONG); NTSYSAPI NTSTATUS WINAPI NtSetLowEventPair(HANDLE); NTSYSAPI NTSTATUS WINAPI NtSetLowWaitHighEventPair(HANDLE); NTSYSAPI NTSTATUS WINAPI NtSetLowWaitHighThread(VOID); +NTSYSAPI NTSTATUS WINAPI NtSetPowerRequest(HANDLE,POWER_REQUEST_TYPE); NTSYSAPI NTSTATUS WINAPI NtSetSecurityObject(HANDLE,SECURITY_INFORMATION,PSECURITY_DESCRIPTOR); NTSYSAPI NTSTATUS WINAPI NtSetSystemEnvironmentValue(PUNICODE_STRING,PUNICODE_STRING); NTSYSAPI NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS,PVOID,ULONG);
Signed-off-by: Chip Davis [email protected] --- dlls/kernel32/powermgnt.c | 53 +++++++++++++++++++++++++++++++-------- include/winnt.h | 5 ++++ 2 files changed, 47 insertions(+), 11 deletions(-)
diff --git a/dlls/kernel32/powermgnt.c b/dlls/kernel32/powermgnt.c index 056dd9df692..190dc016c31 100644 --- a/dlls/kernel32/powermgnt.c +++ b/dlls/kernel32/powermgnt.c @@ -19,10 +19,15 @@
#include <stdarg.h>
+#define NONAMELESSUNION +#define NONAMELESSSTRUCT +#include "ntstatus.h" +#define WIN32_NO_STATUS #include "windef.h" #include "winbase.h" #include "winternl.h" #include "wine/debug.h" +#include "wine/heap.h"
WINE_DEFAULT_DEBUG_CHANNEL(powermgnt);
@@ -113,10 +118,36 @@ EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) */ HANDLE WINAPI PowerCreateRequest(REASON_CONTEXT *context) { - FIXME("(%p): stub\n", context); + COUNTED_REASON_CONTEXT nt_context; + HANDLE handle; + NTSTATUS status; + WCHAR module_name[MAX_PATH]; + + TRACE( "(%p)\n", context ); + + nt_context.Version = context->Version; + nt_context.Flags = context->Flags; + if (context->Flags & POWER_REQUEST_CONTEXT_SIMPLE_STRING) + RtlInitUnicodeString( &nt_context.u.SimpleString, context->Reason.SimpleReasonString ); + else if (context->Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING) + { + int i; + + GetModuleFileNameW( context->Reason.Detailed.LocalizedReasonModule, module_name, ARRAY_SIZE(module_name) ); + RtlInitUnicodeString( &nt_context.u.s.ResourceFileName, module_name ); + nt_context.u.s.ResourceReasonId = context->Reason.Detailed.LocalizedReasonId; + nt_context.u.s.StringCount = context->Reason.Detailed.ReasonStringCount; + nt_context.u.s.ReasonStrings = heap_alloc( nt_context.u.s.StringCount * sizeof(UNICODE_STRING) ); + for (i = 0; i < nt_context.u.s.StringCount; i++) + RtlInitUnicodeString( &nt_context.u.s.ReasonStrings[i], context->Reason.Detailed.ReasonStrings[i] ); + }
- SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return INVALID_HANDLE_VALUE; + status = NtCreatePowerRequest( &handle, &nt_context ); + if (nt_context.Flags & POWER_REQUEST_CONTEXT_DETAILED_STRING) + heap_free( nt_context.u.s.ReasonStrings ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS ? handle : INVALID_HANDLE_VALUE; }
/*********************************************************************** @@ -124,10 +155,10 @@ HANDLE WINAPI PowerCreateRequest(REASON_CONTEXT *context) */ BOOL WINAPI PowerSetRequest(HANDLE request, POWER_REQUEST_TYPE type) { - FIXME("(%p, %u): stub\n", request, type); - - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + NTSTATUS status = NtSetPowerRequest( request, type ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS; }
/*********************************************************************** @@ -135,8 +166,8 @@ BOOL WINAPI PowerSetRequest(HANDLE request, POWER_REQUEST_TYPE type) */ BOOL WINAPI PowerClearRequest(HANDLE request, POWER_REQUEST_TYPE type) { - FIXME("(%p, %u): stub\n", request, type); - - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return FALSE; + NTSTATUS status = NtClearPowerRequest( request, type ); + if (status) + SetLastError( RtlNtStatusToDosError(status) ); + return status == STATUS_SUCCESS; } diff --git a/include/winnt.h b/include/winnt.h index a9ecd5a5a99..87b4adbfea0 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -5589,6 +5589,11 @@ typedef enum _POWER_REQUEST_TYPE PowerRequestAwayModeRequired } POWER_REQUEST_TYPE, *PPOWER_REQUEST_TYPE;
+#define POWER_REQUEST_CONTEXT_VERSION 0 + +#define POWER_REQUEST_CONTEXT_SIMPLE_STRING 0x00000001 +#define POWER_REQUEST_CONTEXT_DETAILED_STRING 0x00000002 + typedef union _FILE_SEGMENT_ELEMENT { PVOID64 Buffer; ULONGLONG Alignment;