Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Win32 kernel functions |
| 3 | * |
| 4 | * Copyright 1995 Martin von Loewis |
| 5 | */ |
| 6 | |
Alexandre Julliard | 7e56f68 | 1996-01-31 19:02:28 +0000 | [diff] [blame] | 7 | #include <string.h> |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 8 | #include <unistd.h> |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 9 | #include <sys/times.h> |
Marcus Meissner | 04c3e1d | 1999-02-19 10:37:02 +0000 | [diff] [blame] | 10 | #include "winbase.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 11 | #include "winerror.h" |
Alexandre Julliard | 7ebe1a4 | 1996-12-22 18:27:48 +0000 | [diff] [blame] | 12 | #include "heap.h" |
Alexandre Julliard | df2673b | 1997-03-29 17:20:20 +0000 | [diff] [blame] | 13 | #include "thread.h" |
Alexandre Julliard | 02e9008 | 1998-01-04 17:49:09 +0000 | [diff] [blame] | 14 | #include "process.h" |
Alexandre Julliard | 349a953 | 1997-02-02 19:01:52 +0000 | [diff] [blame] | 15 | #include "pe_image.h" |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 16 | #include "file.h" |
Alexandre Julliard | 767e6f6 | 1998-08-09 12:47:43 +0000 | [diff] [blame] | 17 | #include "task.h" |
| 18 | #include "toolhelp.h" |
Alexandre Julliard | 1565709 | 1999-05-23 10:25:25 +0000 | [diff] [blame] | 19 | #include "debugtools.h" |
Alexandre Julliard | ade697e | 1995-11-26 13:59:11 +0000 | [diff] [blame] | 20 | |
Patrik Stridvall | b4b9fae | 1999-04-19 14:56:29 +0000 | [diff] [blame] | 21 | DEFAULT_DEBUG_CHANNEL(win32) |
| 22 | |
Alexandre Julliard | 670cdc4 | 1997-08-24 16:00:30 +0000 | [diff] [blame] | 23 | |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 24 | /********************************************************************* |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 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 |
Alexandre Julliard | 81ee21d | 1999-12-27 05:26:00 +0000 | [diff] [blame] | 35 | * floating values are truncated on conversion to integer. |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 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. */ |
Patrik Stridvall | 9633632 | 1999-10-24 22:13:47 +0000 | [diff] [blame] | 41 | #if SIZEOF_LONG_LONG >= 8 |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 42 | unsigned long long t = td; |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 43 | filetime->dwLowDateTime = (UINT) t; |
| 44 | filetime->dwHighDateTime = (UINT) (t >> 32); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 45 | #else |
| 46 | double divider = 1. * (1 << 16) * (1 << 16); |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 47 | filetime->dwHighDateTime = (UINT) (td / divider); |
| 48 | filetime->dwLowDateTime = (UINT) (td - filetime->dwHighDateTime*divider); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 49 | /* using floor() produces wierd results, better leave this as it is |
| 50 | * ( with (UINT32) convertion ) |
| 51 | */ |
| 52 | #endif |
| 53 | } |
| 54 | |
| 55 | /********************************************************************* |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 56 | * GetProcessTimes [KERNEL32.262] |
| 57 | * |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 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. |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 63 | */ |
Alexandre Julliard | a396029 | 1999-02-26 11:11:13 +0000 | [diff] [blame] | 64 | BOOL WINAPI GetProcessTimes( |
| 65 | HANDLE hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime, |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 66 | LPFILETIME lpKernelTime, LPFILETIME lpUserTime |
| 67 | ) { |
| 68 | struct tms tms; |
| 69 | |
| 70 | times(&tms); |
Alexandre Julliard | d30dfd2 | 1998-09-27 18:28:36 +0000 | [diff] [blame] | 71 | Process_ClockTimeToFileTime(tms.tms_utime,lpUserTime); |
| 72 | Process_ClockTimeToFileTime(tms.tms_stime,lpKernelTime); |
Alexandre Julliard | 84c70f5 | 1997-05-09 08:40:27 +0000 | [diff] [blame] | 73 | return TRUE; |
| 74 | } |
| 75 | |