(get_process_times_fn): New function pointer.
(globals_of_w32): Intialize it if present in kernel32.dll. (w32_get_internal_run_time): New function.
This commit is contained in:
parent
553d316401
commit
7425851806
1 changed files with 54 additions and 0 deletions
54
src/w32.c
54
src/w32.c
|
@ -137,6 +137,15 @@ typedef BOOL (WINAPI * GetTokenInformation_Proc) (
|
|||
LPVOID TokenInformation,
|
||||
DWORD TokenInformationLength,
|
||||
PDWORD ReturnLength);
|
||||
typedef BOOL (WINAPI * GetProcessTimes_Proc) (
|
||||
HANDLE process_handle,
|
||||
LPFILETIME creation_time,
|
||||
LPFILETIME exit_time,
|
||||
LPFILETIME kernel_time,
|
||||
LPFILETIME user_time);
|
||||
|
||||
GetProcessTimes_Proc get_process_times_fn = NULL;
|
||||
|
||||
#ifdef _UNICODE
|
||||
const char * const LookupAccountSid_Name = "LookupAccountSidW";
|
||||
#else
|
||||
|
@ -172,6 +181,46 @@ is_windows_9x ()
|
|||
return s_b_ret;
|
||||
}
|
||||
|
||||
/* Get total user and system times for get-internal-run-time.
|
||||
Returns a list of three integers if the times are provided by the OS
|
||||
(NT derivatives), otherwise it returns the result of current-time. */
|
||||
Lisp_Object
|
||||
w32_get_internal_run_time ()
|
||||
{
|
||||
if (get_process_times_fn)
|
||||
{
|
||||
FILETIME create, exit, kernel, user;
|
||||
HANDLE proc = GetCurrentProcess();
|
||||
if ((*get_process_times_fn) (proc, &create, &exit, &kernel, &user))
|
||||
{
|
||||
LARGE_INTEGER user_int, kernel_int, total;
|
||||
int microseconds;
|
||||
user_int.LowPart = user.dwLowDateTime;
|
||||
user_int.HighPart = user.dwHighDateTime;
|
||||
kernel_int.LowPart = kernel.dwLowDateTime;
|
||||
kernel_int.HighPart = kernel.dwHighDateTime;
|
||||
total.QuadPart = user_int.QuadPart + kernel_int.QuadPart;
|
||||
/* FILETIME is 100 nanosecond increments, Emacs only wants
|
||||
microsecond resolution. */
|
||||
total.QuadPart /= 10;
|
||||
microseconds = total.QuadPart % 1000000;
|
||||
total.QuadPart /= 1000000;
|
||||
|
||||
/* Sanity check to make sure we can represent the result. */
|
||||
if (total.HighPart == 0)
|
||||
{
|
||||
int secs = total.LowPart;
|
||||
|
||||
return list3 (make_number ((secs >> 16) & 0xffff),
|
||||
make_number (secs & 0xffff),
|
||||
make_number (microseconds));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Fcurrent_time ();
|
||||
}
|
||||
|
||||
/* ** The wrapper functions ** */
|
||||
|
||||
BOOL WINAPI open_process_token (
|
||||
|
@ -4144,6 +4193,11 @@ BOOL WINAPI shutdown_handler(DWORD type)
|
|||
void
|
||||
globals_of_w32 ()
|
||||
{
|
||||
HMODULE kernel32 = GetModuleHandle ("kernel32.dll");
|
||||
|
||||
get_process_times_fn = (GetProcessTimes_Proc)
|
||||
GetProcAddress (kernel32, "GetProcessTimes");
|
||||
|
||||
g_b_init_is_windows_9x = 0;
|
||||
g_b_init_open_process_token = 0;
|
||||
g_b_init_get_token_information = 0;
|
||||
|
|
Loading…
Add table
Reference in a new issue