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