blob: 6a3a894a7895b46ef972918d57c90198c727d57f [file] [log] [blame]
Alexandre Julliardade697e1995-11-26 13:59:11 +00001/*
2 * Win32 kernel functions
3 *
4 * Copyright 1995 Martin von Loewis
5 */
6
Alexandre Julliard7e56f681996-01-31 19:02:28 +00007#include <string.h>
Alexandre Julliardade697e1995-11-26 13:59:11 +00008#include <unistd.h>
Alexandre Julliard84c70f51997-05-09 08:40:27 +00009#include <sys/times.h>
Marcus Meissner04c3e1d1999-02-19 10:37:02 +000010#include "winbase.h"
Alexandre Julliardade697e1995-11-26 13:59:11 +000011#include "winerror.h"
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000012#include "heap.h"
Alexandre Julliarddf2673b1997-03-29 17:20:20 +000013#include "thread.h"
Alexandre Julliard02e90081998-01-04 17:49:09 +000014#include "process.h"
Alexandre Julliard349a9531997-02-02 19:01:52 +000015#include "pe_image.h"
Alexandre Julliard84c70f51997-05-09 08:40:27 +000016#include "file.h"
Alexandre Julliard767e6f61998-08-09 12:47:43 +000017#include "task.h"
18#include "toolhelp.h"
Alexandre Julliard15657091999-05-23 10:25:25 +000019#include "debugtools.h"
Alexandre Julliardade697e1995-11-26 13:59:11 +000020
Patrik Stridvallb4b9fae1999-04-19 14:56:29 +000021DEFAULT_DEBUG_CHANNEL(win32)
22
Alexandre Julliard670cdc41997-08-24 16:00:30 +000023
Alexandre Julliard84c70f51997-05-09 08:40:27 +000024/*********************************************************************
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000025 * 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 Julliard81ee21d1999-12-27 05:26:00 +000035 * floating values are truncated on conversion to integer.
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000036 */
37void 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 Stridvall96336321999-10-24 22:13:47 +000041#if SIZEOF_LONG_LONG >= 8
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000042 unsigned long long t = td;
Alexandre Julliarda3960291999-02-26 11:11:13 +000043 filetime->dwLowDateTime = (UINT) t;
44 filetime->dwHighDateTime = (UINT) (t >> 32);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000045#else
46 double divider = 1. * (1 << 16) * (1 << 16);
Alexandre Julliarda3960291999-02-26 11:11:13 +000047 filetime->dwHighDateTime = (UINT) (td / divider);
48 filetime->dwLowDateTime = (UINT) (td - filetime->dwHighDateTime*divider);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000049 /* using floor() produces wierd results, better leave this as it is
50 * ( with (UINT32) convertion )
51 */
52#endif
53}
54
55/*********************************************************************
Alexandre Julliard84c70f51997-05-09 08:40:27 +000056 * GetProcessTimes [KERNEL32.262]
57 *
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000058 * 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 Julliard84c70f51997-05-09 08:40:27 +000063 */
Alexandre Julliarda3960291999-02-26 11:11:13 +000064BOOL WINAPI GetProcessTimes(
65 HANDLE hprocess,LPFILETIME lpCreationTime,LPFILETIME lpExitTime,
Alexandre Julliard84c70f51997-05-09 08:40:27 +000066 LPFILETIME lpKernelTime, LPFILETIME lpUserTime
67) {
68 struct tms tms;
69
70 times(&tms);
Alexandre Julliardd30dfd21998-09-27 18:28:36 +000071 Process_ClockTimeToFileTime(tms.tms_utime,lpUserTime);
72 Process_ClockTimeToFileTime(tms.tms_stime,lpKernelTime);
Alexandre Julliard84c70f51997-05-09 08:40:27 +000073 return TRUE;
74}
75