aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/w32.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/w32.c b/src/w32.c
index 6d4e968b3cb..2d52b84af4c 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -137,6 +137,15 @@ typedef BOOL (WINAPI * GetTokenInformation_Proc) (
137 LPVOID TokenInformation, 137 LPVOID TokenInformation,
138 DWORD TokenInformationLength, 138 DWORD TokenInformationLength,
139 PDWORD ReturnLength); 139 PDWORD ReturnLength);
140typedef BOOL (WINAPI * GetProcessTimes_Proc) (
141 HANDLE process_handle,
142 LPFILETIME creation_time,
143 LPFILETIME exit_time,
144 LPFILETIME kernel_time,
145 LPFILETIME user_time);
146
147GetProcessTimes_Proc get_process_times_fn = NULL;
148
140#ifdef _UNICODE 149#ifdef _UNICODE
141const char * const LookupAccountSid_Name = "LookupAccountSidW"; 150const char * const LookupAccountSid_Name = "LookupAccountSidW";
142#else 151#else
@@ -172,6 +181,46 @@ is_windows_9x ()
172 return s_b_ret; 181 return s_b_ret;
173} 182}
174 183
184/* Get total user and system times for get-internal-run-time.
185 Returns a list of three integers if the times are provided by the OS
186 (NT derivatives), otherwise it returns the result of current-time. */
187Lisp_Object
188w32_get_internal_run_time ()
189{
190 if (get_process_times_fn)
191 {
192 FILETIME create, exit, kernel, user;
193 HANDLE proc = GetCurrentProcess();
194 if ((*get_process_times_fn) (proc, &create, &exit, &kernel, &user))
195 {
196 LARGE_INTEGER user_int, kernel_int, total;
197 int microseconds;
198 user_int.LowPart = user.dwLowDateTime;
199 user_int.HighPart = user.dwHighDateTime;
200 kernel_int.LowPart = kernel.dwLowDateTime;
201 kernel_int.HighPart = kernel.dwHighDateTime;
202 total.QuadPart = user_int.QuadPart + kernel_int.QuadPart;
203 /* FILETIME is 100 nanosecond increments, Emacs only wants
204 microsecond resolution. */
205 total.QuadPart /= 10;
206 microseconds = total.QuadPart % 1000000;
207 total.QuadPart /= 1000000;
208
209 /* Sanity check to make sure we can represent the result. */
210 if (total.HighPart == 0)
211 {
212 int secs = total.LowPart;
213
214 return list3 (make_number ((secs >> 16) & 0xffff),
215 make_number (secs & 0xffff),
216 make_number (microseconds));
217 }
218 }
219 }
220
221 return Fcurrent_time ();
222}
223
175 /* ** The wrapper functions ** */ 224 /* ** The wrapper functions ** */
176 225
177BOOL WINAPI open_process_token ( 226BOOL WINAPI open_process_token (
@@ -4144,6 +4193,11 @@ BOOL WINAPI shutdown_handler(DWORD type)
4144void 4193void
4145globals_of_w32 () 4194globals_of_w32 ()
4146{ 4195{
4196 HMODULE kernel32 = GetModuleHandle ("kernel32.dll");
4197
4198 get_process_times_fn = (GetProcessTimes_Proc)
4199 GetProcAddress (kernel32, "GetProcessTimes");
4200
4147 g_b_init_is_windows_9x = 0; 4201 g_b_init_is_windows_9x = 0;
4148 g_b_init_open_process_token = 0; 4202 g_b_init_open_process_token = 0;
4149 g_b_init_get_token_information = 0; 4203 g_b_init_get_token_information = 0;