From 7cc9ccbd22511d71d23ee298cd9718da1e448dbc Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Fri, 22 May 2020 09:15:39 +0200 Subject: [PATCH] kernel32: Move GetProcessTimes() implementation to kernelbase and ntdll. Signed-off-by: Alexandre Julliard --- dlls/kernel32/kernel32.spec | 2 +- dlls/kernel32/time.c | 64 --------------------------------- dlls/kernelbase/kernelbase.spec | 2 +- dlls/kernelbase/process.c | 23 ++++++++++++ dlls/ntdll/process.c | 19 ++++++++-- 5 files changed, 41 insertions(+), 69 deletions(-) diff --git a/dlls/kernel32/kernel32.spec b/dlls/kernel32/kernel32.spec index 659f72cf780..efb892bf1bb 100644 --- a/dlls/kernel32/kernel32.spec +++ b/dlls/kernel32/kernel32.spec @@ -791,7 +791,7 @@ @ stdcall -import GetProcessPriorityBoost(long ptr) @ stdcall -import GetProcessShutdownParameters(ptr ptr) # @ stub GetProcessorSystemCycleTime -@ stdcall GetProcessTimes(long ptr ptr ptr ptr) +@ stdcall -import GetProcessTimes(long ptr ptr ptr ptr) # @ stub GetProcessUserModeExceptionPolicy @ stdcall GetProcessVersion(long) @ stdcall GetProcessWorkingSetSize(long ptr ptr) diff --git a/dlls/kernel32/time.c b/dlls/kernel32/time.c index 5d27fc7ac30..5aef53da639 100644 --- a/dlls/kernel32/time.c +++ b/dlls/kernel32/time.c @@ -55,12 +55,6 @@ WINE_DEFAULT_DEBUG_CHANNEL(time); static const struct _KUSER_SHARED_DATA *user_shared_data = (struct _KUSER_SHARED_DATA *)0x7ffe0000; -static inline void longlong_to_filetime( LONGLONG t, FILETIME *ft ) -{ - ft->dwLowDateTime = (DWORD)t; - ft->dwHighDateTime = (DWORD)(t >> 32); -} - /*********************************************************************** * GetSystemTimeAdjustment (KERNEL32.@) @@ -109,64 +103,6 @@ BOOL WINAPI SetSystemTimeAdjustment( DWORD dwTimeAdjustment, BOOL bTimeAdjustmen return TRUE; } -/********************************************************************* - * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998) - * - * Used by GetProcessTimes to convert clock_t into FILETIME. - * - * Differences to UnixTimeToFileTime: - * 1) Divided by CLK_TCK - * 2) Time is relative. There is no 'starting date', so there is - * no need for offset correction, like in UnixTimeToFileTime - */ -static void TIME_ClockTimeToFileTime(clock_t unix_time, LPFILETIME filetime) -{ - long clocksPerSec = sysconf(_SC_CLK_TCK); - ULONGLONG secs = (ULONGLONG)unix_time * 10000000 / clocksPerSec; - filetime->dwLowDateTime = (DWORD)secs; - filetime->dwHighDateTime = (DWORD)(secs >> 32); -} - -/********************************************************************* - * GetProcessTimes (KERNEL32.@) - * - * Get the user and kernel execution times of a process, - * along with the creation and exit times if known. - * - * PARAMS - * hprocess [in] The process to be queried. - * lpCreationTime [out] The creation time of the process. - * lpExitTime [out] The exit time of the process if exited. - * lpKernelTime [out] The time spent in kernel routines in 100's of nanoseconds. - * lpUserTime [out] The time spent in user routines in 100's of nanoseconds. - * - * RETURNS - * TRUE. - * - * NOTES - * olorin@fandra.org: - * Would be nice to subtract the cpu time used by Wine at startup. - * Also, there is a need to separate times used by different applications. - * - * BUGS - * KernelTime and UserTime are always for the current process - */ -BOOL WINAPI GetProcessTimes( HANDLE hprocess, LPFILETIME lpCreationTime, - LPFILETIME lpExitTime, LPFILETIME lpKernelTime, LPFILETIME lpUserTime ) -{ - struct tms tms; - KERNEL_USER_TIMES pti; - - times(&tms); - TIME_ClockTimeToFileTime(tms.tms_utime,lpUserTime); - TIME_ClockTimeToFileTime(tms.tms_stime,lpKernelTime); - if (NtQueryInformationProcess( hprocess, ProcessTimes, &pti, sizeof(pti), NULL)) - return FALSE; - longlong_to_filetime( pti.CreateTime.QuadPart, lpCreationTime ); - longlong_to_filetime( pti.ExitTime.QuadPart, lpExitTime ); - return TRUE; -} - /********************************************************************* * GetCalendarInfoA (KERNEL32.@) * diff --git a/dlls/kernelbase/kernelbase.spec b/dlls/kernelbase/kernelbase.spec index 1f1a65fc853..4a6bc5eea4e 100644 --- a/dlls/kernelbase/kernelbase.spec +++ b/dlls/kernelbase/kernelbase.spec @@ -635,7 +635,7 @@ @ stdcall GetProcessPreferredUILanguages(long ptr ptr ptr) kernel32.GetProcessPreferredUILanguages @ stdcall GetProcessPriorityBoost(long ptr) @ stdcall GetProcessShutdownParameters(ptr ptr) -@ stdcall GetProcessTimes(long ptr ptr ptr ptr) kernel32.GetProcessTimes +@ stdcall GetProcessTimes(long ptr ptr ptr ptr) @ stdcall GetProcessVersion(long) kernel32.GetProcessVersion @ stdcall GetProcessWorkingSetSizeEx(long ptr ptr ptr) # @ stub GetProcessorSystemCycleTime diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c index 67fcb5f04ea..66e115ce697 100644 --- a/dlls/kernelbase/process.c +++ b/dlls/kernelbase/process.c @@ -791,6 +791,29 @@ BOOL WINAPI DECLSPEC_HOTPATCH GetProcessShutdownParameters( LPDWORD level, LPDWO } +/********************************************************************* + * GetProcessTimes (kernelbase.@) + */ +BOOL WINAPI DECLSPEC_HOTPATCH GetProcessTimes( HANDLE process, FILETIME *create, FILETIME *exit, + FILETIME *kernel, FILETIME *user ) +{ + KERNEL_USER_TIMES time; + + if (!set_ntstatus( NtQueryInformationProcess( process, ProcessTimes, &time, sizeof(time), NULL ))) + return FALSE; + + create->dwLowDateTime = time.CreateTime.u.LowPart; + create->dwHighDateTime = time.CreateTime.u.HighPart; + exit->dwLowDateTime = time.ExitTime.u.LowPart; + exit->dwHighDateTime = time.ExitTime.u.HighPart; + kernel->dwLowDateTime = time.KernelTime.u.LowPart; + kernel->dwHighDateTime = time.KernelTime.u.HighPart; + user->dwLowDateTime = time.UserTime.u.LowPart; + user->dwHighDateTime = time.UserTime.u.HighPart; + return TRUE; +} + + /*********************************************************************** * GetProcessWorkingSetSizeEx (kernelbase.@) */ diff --git a/dlls/ntdll/process.c b/dlls/ntdll/process.c index cd867e60284..637bef0b656 100644 --- a/dlls/ntdll/process.c +++ b/dlls/ntdll/process.c @@ -32,6 +32,12 @@ #ifdef HAVE_SYS_SOCKET_H #include #endif +#ifdef HAVE_SYS_TIME_H +# include +#endif +#ifdef HAVE_SYS_TIMES_H +# include +#endif #include #ifdef HAVE_SYS_WAIT_H # include @@ -359,7 +365,7 @@ NTSTATUS WINAPI NtQueryInformationProcess( break; case ProcessTimes: { - KERNEL_USER_TIMES pti; + KERNEL_USER_TIMES pti = {{{0}}}; if (ProcessInformationLength >= sizeof(KERNEL_USER_TIMES)) { @@ -369,8 +375,15 @@ NTSTATUS WINAPI NtQueryInformationProcess( ret = STATUS_INVALID_HANDLE; else { - /* FIXME : User- and KernelTime have to be implemented */ - memset(&pti, 0, sizeof(KERNEL_USER_TIMES)); + long ticks = sysconf(_SC_CLK_TCK); + struct tms tms; + + /* FIXME: user/kernel times only work for current process */ + if (ticks && times( &tms ) != -1) + { + pti.UserTime.QuadPart = (ULONGLONG)tms.tms_utime * 10000000 / ticks; + pti.KernelTime.QuadPart = (ULONGLONG)tms.tms_stime * 10000000 / ticks; + } SERVER_START_REQ(get_process_info) {