kernel32: Move GetProcessTimes() implementation to kernelbase and ntdll.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
feature/deterministic
Alexandre Julliard 2020-05-22 09:15:39 +02:00
parent b65ca13305
commit 7cc9ccbd22
5 changed files with 41 additions and 69 deletions

View File

@ -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)

View File

@ -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.@)
*

View File

@ -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

View File

@ -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.@)
*/

View File

@ -32,6 +32,12 @@
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_SYS_TIME_H
# include <sys/time.h>
#endif
#ifdef HAVE_SYS_TIMES_H
# include <sys/times.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
@ -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)
{