wine-staging/patches/kernel32-GetSystemTimes/0002-kernel32-Implement-GetSystemTimes.patch

122 lines
4.5 KiB
Diff

From eaccccc716b398e0841c5f2e7de5ba6cea3666ab Mon Sep 17 00:00:00 2001
From: "Erich E. Hoover" <erich.e.hoover@gmail.com>
Date: Sun, 27 Jul 2014 12:38:29 -0600
Subject: kernel32: Implement GetSystemTimes.
---
dlls/kernel32/tests/time.c | 12 ++++-----
dlls/kernel32/time.c | 62 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 66 insertions(+), 8 deletions(-)
diff --git a/dlls/kernel32/tests/time.c b/dlls/kernel32/tests/time.c
index c524343..63ab35a 100644
--- a/dlls/kernel32/tests/time.c
+++ b/dlls/kernel32/tests/time.c
@@ -751,13 +751,13 @@ static void test_GetSystemTimes(void)
return;
}
- todo_wine ok( pGetSystemTimes(NULL, NULL, NULL), "GetSystemTimes failed unexpectedly\n" );
+ ok( pGetSystemTimes(NULL, NULL, NULL), "GetSystemTimes failed unexpectedly\n" );
memset( &idletime, 0x11, sizeof(idletime) );
memset( &kerneltime, 0x11, sizeof(kerneltime) );
memset( &usertime, 0x11, sizeof(usertime) );
- todo_wine ok( pGetSystemTimes(&idletime, &kerneltime , &usertime),
- "GetSystemTimes failed unexpectedly\n" );
+ ok( pGetSystemTimes(&idletime, &kerneltime , &usertime),
+ "GetSystemTimes failed unexpectedly\n" );
ul1.LowPart = idletime.dwLowDateTime;
ul1.HighPart = idletime.dwHighDateTime;
@@ -800,9 +800,9 @@ static void test_GetSystemTimes(void)
trace( "total_idletime %f total_kerneltime %f total_usertime %f \n", total_idletime,
total_kerneltime, total_usertime );
- todo_wine ok( (total_idletime - (double)ul1.QuadPart/10000000.0) < 1.0, "test idletime failed\n" );
- todo_wine ok( (total_kerneltime - (double)ul2.QuadPart/10000000.0) < 1.0, "test kerneltime failed\n" );
- todo_wine ok( (total_usertime - (double)ul3.QuadPart/10000000.0) < 1.0, "test usertime failed\n" );
+ ok( (total_idletime - (double)ul1.QuadPart/10000000.0) < 1.0, "test idletime failed\n" );
+ ok( (total_kerneltime - (double)ul2.QuadPart/10000000.0) < 1.0, "test kerneltime failed\n" );
+ ok( (total_usertime - (double)ul3.QuadPart/10000000.0) < 1.0, "test usertime failed\n" );
HeapFree(GetProcessHeap(), 0, sppi);
}
diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c
index 21ac120..b877adc 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -1090,9 +1090,67 @@ BOOL WINAPI FileTimeToDosDateTime( const FILETIME *ft, LPWORD fatdate,
*/
BOOL WINAPI GetSystemTimes(LPFILETIME lpIdleTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime)
{
- FIXME("(%p,%p,%p): Stub!\n", lpIdleTime, lpKernelTime, lpUserTime);
+ LARGE_INTEGER idle_time, kernel_time, user_time;
+ SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION *sppi;
+ SYSTEM_BASIC_INFORMATION sbi;
+ NTSTATUS status;
+ ULONG ret_size;
+ int i;
+
+ TRACE("(%p,%p,%p)\n", lpIdleTime, lpKernelTime, lpUserTime);
+
+ status = NtQuerySystemInformation( SystemBasicInformation, &sbi, sizeof(sbi), &ret_size );
+ if (status != STATUS_SUCCESS)
+ {
+ SetLastError( RtlNtStatusToDosError(status) );
+ return FALSE;
+ }
- return FALSE;
+ sppi = HeapAlloc( GetProcessHeap(), 0,
+ sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) * sbi.NumberOfProcessors);
+ if (!sppi)
+ {
+ SetLastError( ERROR_OUTOFMEMORY );
+ return FALSE;
+ }
+
+ status = NtQuerySystemInformation( SystemProcessorPerformanceInformation, sppi, sizeof(*sppi) * sbi.NumberOfProcessors,
+ &ret_size );
+ if (status != STATUS_SUCCESS)
+ {
+ HeapFree( GetProcessHeap(), 0, sppi );
+ SetLastError( RtlNtStatusToDosError(status) );
+ return FALSE;
+ }
+
+ idle_time.QuadPart = 0;
+ kernel_time.QuadPart = 0;
+ user_time.QuadPart = 0;
+ for (i = 0; i < sbi.NumberOfProcessors; i++)
+ {
+ idle_time.QuadPart += sppi[i].IdleTime.QuadPart;
+ kernel_time.QuadPart += sppi[i].KernelTime.QuadPart;
+ user_time.QuadPart += sppi[i].UserTime.QuadPart;
+ }
+
+ if (lpIdleTime)
+ {
+ lpIdleTime->dwLowDateTime = idle_time.u.LowPart;
+ lpIdleTime->dwHighDateTime = idle_time.u.HighPart;
+ }
+ if (lpKernelTime)
+ {
+ lpKernelTime->dwLowDateTime = kernel_time.u.LowPart;
+ lpKernelTime->dwHighDateTime = kernel_time.u.HighPart;
+ }
+ if (lpUserTime)
+ {
+ lpUserTime->dwLowDateTime = user_time.u.LowPart;
+ lpUserTime->dwHighDateTime = user_time.u.HighPart;
+ }
+
+ HeapFree( GetProcessHeap(), 0, sppi );
+ return TRUE;
}
/***********************************************************************
--
2.1.0