Improved support for vm86 mode.
[wine.git] / win32 / process.c
blob36bdfccb885bfd5df64de1779d6ab13637897e83
1 /*
2 * Win32 kernel functions
4 * Copyright 1995 Martin von Loewis
5 */
7 #include <string.h>
8 #include <unistd.h>
9 #include <sys/times.h>
10 #include "winbase.h"
11 #include "winerror.h"
12 #include "heap.h"
13 #include "thread.h"
14 #include "process.h"
15 #include "file.h"
16 #include "task.h"
17 #include "toolhelp.h"
18 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(win32);
23 /*********************************************************************
24 * Process_ClockTimeToFileTime
25 * (olorin@fandra.org, 20-Sep-1998)
26 * Converts clock_t into FILETIME.
27 * Used by GetProcessTime.
28 * Differences to UnixTimeToFileTime:
29 * 1) Divided by CLK_TCK
30 * 2) Time is relative. There is no 'starting date', so there is
31 * no need in offset correction, like in UnixTimeToFileTime
32 * FIXME: This function should be moved to a more appropriate .c file
33 * FIXME: On floating point operations, it is assumed that
34 * floating values are truncated on conversion to integer.
36 void Process_ClockTimeToFileTime( clock_t unix_time, LPFILETIME filetime )
38 double td = (unix_time*10000000.0)/CLK_TCK;
39 /* Yes, double, because long int might overflow here. */
40 #if SIZEOF_LONG_LONG >= 8
41 unsigned long long t = td;
42 filetime->dwLowDateTime = (UINT) t;
43 filetime->dwHighDateTime = (UINT) (t >> 32);
44 #else
45 double divider = 1. * (1 << 16) * (1 << 16);
46 filetime->dwHighDateTime = (UINT) (td / divider);
47 filetime->dwLowDateTime = (UINT) (td - filetime->dwHighDateTime*divider);
48 /* using floor() produces wierd results, better leave this as it is
49 * ( with (UINT32) convertion )
51 #endif
54 /*********************************************************************
55 * GetProcessTimes [KERNEL32.262]
57 * FIXME: lpCreationTime, lpExitTime are NOT INITIALIZED.
58 * olorin@fandra.org: Would be nice to substract the cpu time,
59 * used by Wine at startup.
60 * Also, there is a need to separate times
61 * used by different applications.
63 BOOL WINAPI GetProcessTimes(
64 HANDLE hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime,
65 LPFILETIME lpKernelTime, LPFILETIME lpUserTime
66 ) {
67 struct tms tms;
69 times(&tms);
70 Process_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
71 Process_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
72 return TRUE;