Signed-off-by: Chip Davis [email protected] --- dlls/ntdll/nt.c | 17 +++++++++++++++++ dlls/ntdll/ntdll.spec | 4 ++-- include/winternl.h | 1 + 3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/dlls/ntdll/nt.c b/dlls/ntdll/nt.c index b58c2d6e98a..cdfbd9fa822 100644 --- a/dlls/ntdll/nt.c +++ b/dlls/ntdll/nt.c @@ -3056,6 +3056,23 @@ NTSTATUS WINAPI NtInitiatePowerAction( return STATUS_NOT_IMPLEMENTED; }
+/****************************************************************************** + * NtSetThreadExecutionState [NTDLL.@] + * + */ +NTSTATUS WINAPI NtSetThreadExecutionState( EXECUTION_STATE new_state, EXECUTION_STATE *old_state ) +{ + static EXECUTION_STATE current = + ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_USER_PRESENT; + *old_state = current; + + WARN( "(0x%x, %p): stub, harmless.\n", new_state, old_state ); + + if (!(current & ES_CONTINUOUS) || (new_state & ES_CONTINUOUS)) + current = new_state; + return STATUS_SUCCESS; +} + #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 323d5eae77a..278699c7077 100644 --- a/dlls/ntdll/ntdll.spec +++ b/dlls/ntdll/ntdll.spec @@ -381,7 +381,7 @@ @ stdcall NtSetSystemInformation(long ptr long) @ stub NtSetSystemPowerState @ stdcall NtSetSystemTime(ptr ptr) -# @ stub NtSetThreadExecutionState +@ stdcall NtSetThreadExecutionState(long ptr) @ stdcall NtSetTimer(long ptr ptr ptr long long ptr) @ stdcall NtSetTimerResolution(long long ptr) # @ stub NtSetUuidSeed @@ -1330,7 +1330,7 @@ @ stdcall -private ZwSetSystemInformation(long ptr long) NtSetSystemInformation @ stub ZwSetSystemPowerState @ stdcall -private ZwSetSystemTime(ptr ptr) NtSetSystemTime -# @ stub ZwSetThreadExecutionState +@ stdcall ZwSetThreadExecutionState(long ptr) NtSetThreadExecutionState @ stdcall -private ZwSetTimer(long ptr ptr ptr long long ptr) NtSetTimer @ stdcall -private ZwSetTimerResolution(long long ptr) NtSetTimerResolution # @ stub ZwSetUuidSeed diff --git a/include/winternl.h b/include/winternl.h index 49eedaf1f98..d6543917e64 100644 --- a/include/winternl.h +++ b/include/winternl.h @@ -2515,6 +2515,7 @@ NTSYSAPI NTSTATUS WINAPI NtSetSystemEnvironmentValue(PUNICODE_STRING,PUNICODE_S NTSYSAPI NTSTATUS WINAPI NtSetSystemInformation(SYSTEM_INFORMATION_CLASS,PVOID,ULONG); NTSYSAPI NTSTATUS WINAPI NtSetSystemPowerState(POWER_ACTION,SYSTEM_POWER_STATE,ULONG); NTSYSAPI NTSTATUS WINAPI NtSetSystemTime(const LARGE_INTEGER*,LARGE_INTEGER*); +NTSYSAPI NTSTATUS WINAPI NtSetThreadExecutionState(EXECUTION_STATE,EXECUTION_STATE*); NTSYSAPI NTSTATUS WINAPI NtSetTimer(HANDLE, const LARGE_INTEGER*, PTIMER_APC_ROUTINE, PVOID, BOOLEAN, ULONG, BOOLEAN*); NTSYSAPI NTSTATUS WINAPI NtSetTimerResolution(ULONG,BOOLEAN,PULONG); NTSYSAPI NTSTATUS WINAPI NtSetValueKey(HANDLE,const UNICODE_STRING *,ULONG,ULONG,const void *,ULONG);
Signed-off-by: Chip Davis [email protected] --- dlls/kernel32/powermgnt.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-)
diff --git a/dlls/kernel32/powermgnt.c b/dlls/kernel32/powermgnt.c index 81e43b4ecf7..056dd9df692 100644 --- a/dlls/kernel32/powermgnt.c +++ b/dlls/kernel32/powermgnt.c @@ -21,6 +21,7 @@
#include "windef.h" #include "winbase.h" +#include "winternl.h" #include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(powermgnt); @@ -100,14 +101,10 @@ BOOL WINAPI SetSystemPowerState(BOOL suspend_or_hibernate, */ EXECUTION_STATE WINAPI SetThreadExecutionState(EXECUTION_STATE flags) { - static EXECUTION_STATE current = - ES_SYSTEM_REQUIRED | ES_DISPLAY_REQUIRED | ES_USER_PRESENT; - EXECUTION_STATE old = current; + EXECUTION_STATE old;
- WARN("(0x%x): stub, harmless.\n", flags); + NtSetThreadExecutionState(flags, &old);
- if (!(current & ES_CONTINUOUS) || (flags & ES_CONTINUOUS)) - current = flags; return old; }
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] --- dlls/ntdll/nt.c | 33 +++++++++++++++++++++++++++++++++ dlls/ntdll/ntdll.spec | 6 ++++++ include/winternl.h | 20 ++++++++++++++++++++ 3 files changed, 59 insertions(+)
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/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 40d883e3a92..e73821112d3 100644 --- a/include/winnt.h +++ b/include/winnt.h @@ -5582,6 +5582,11 @@ typedef struct _SYSTEM_POWER_POLICY { } SYSTEM_POWER_POLICY, *PSYSTEM_POWER_POLICY;
+#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;
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=54979
Your paranoid android.
=== debian10 (build log) ===
../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? Task: The win32 build failed
=== debian10 (build log) ===
../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? Task: The wow64 build failed
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=54978
Your paranoid android.
=== debian10 (build log) ===
../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? Task: The win32 build failed
=== debian10 (build log) ===
../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../wine/include/winternl.h:2346:54: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? ../../wine/include/winternl.h:2532:52: error: unknown type name ‘POWER_REQUEST_TYPE’; did you mean ‘VER_PRODUCT_TYPE’? Task: The wow64 build failed
Hi,
While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check?
Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=54977
Your paranoid android.
=== debian10 (32 bit report) ===
kernel32: Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x00438134).
Report errors: kernel32:virtual prints too much data (91050 bytes)
=== debian10 (32 bit Chinese:China report) ===
kernel32: Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x00438134).
Report errors: kernel32:virtual prints too much data (91050 bytes)
=== debian10 (32 bit WoW report) ===
kernel32: Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x00438134).
Report errors: kernel32:virtual prints too much data (91050 bytes)
=== debian10 (64 bit WoW report) ===
kernel32: Unhandled exception: page fault on write access to 0x00000000 in 32-bit code (0x00438134).
Report errors: kernel32:virtual prints too much data (91050 bytes)