wine-staging/patches/kernel32-GetSystemTimes/0002-kernel32-Implement-GetSystemTimes.patch
2014-09-09 16:14:39 +02:00

116 lines
4.4 KiB
Diff

From 7bfcc7c62a34a77b6cf613fb37aaef72af644cf1 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 | 56 ++++++++++++++++++++++++++++++++++++++++++++--
2 files changed, 60 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..96753d9 100644
--- a/dlls/kernel32/time.c
+++ b/dlls/kernel32/time.c
@@ -1090,9 +1090,61 @@ 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) 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),
+ &ret_size);
+ if (status != STATUS_SUCCESS)
+ {
+ HeapFree( GetProcessHeap(), 0, sppi );
+ 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