comparison src/w32.c @ 83635:9c01792a3ce8

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 793-802) - Update from CVS - Remove RCS keywords - Merge from emacs--rel--22 * emacs--rel--22 (patch 42-50) - Update from CVS - Merge from gnus--rel--5.10 - Gnus ChangeLog tweaks * gnus--rel--5.10 (patch 229-232) - Merge from emacs--devo--0, emacs--rel--22 - ChangeLog tweak - Update from CVS Revision: emacs@sv.gnu.org/emacs--multi-tty--0--patch-23
author Miles Bader <miles@gnu.org>
date Sat, 16 Jun 2007 22:33:42 +0000
parents 543f6471bd22 5e608f6f217b
children 0ece58f6e0aa
comparison
equal deleted inserted replaced
83634:391cce03f832 83635:9c01792a3ce8
135 HANDLE TokenHandle, 135 HANDLE TokenHandle,
136 TOKEN_INFORMATION_CLASS TokenInformationClass, 136 TOKEN_INFORMATION_CLASS TokenInformationClass,
137 LPVOID TokenInformation, 137 LPVOID TokenInformation,
138 DWORD TokenInformationLength, 138 DWORD TokenInformationLength,
139 PDWORD ReturnLength); 139 PDWORD ReturnLength);
140 typedef 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
147 GetProcessTimes_Proc get_process_times_fn = NULL;
148
140 #ifdef _UNICODE 149 #ifdef _UNICODE
141 const char * const LookupAccountSid_Name = "LookupAccountSidW"; 150 const char * const LookupAccountSid_Name = "LookupAccountSidW";
142 #else 151 #else
143 const char * const LookupAccountSid_Name = "LookupAccountSidA"; 152 const char * const LookupAccountSid_Name = "LookupAccountSidA";
144 #endif 153 #endif
170 } 179 }
171 } 180 }
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. */
187 Lisp_Object
188 w32_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
177 BOOL WINAPI open_process_token ( 226 BOOL WINAPI open_process_token (
178 HANDLE ProcessHandle, 227 HANDLE ProcessHandle,
179 DWORD DesiredAccess, 228 DWORD DesiredAccess,
484 533
485 Use the relative portion of the identifier authority value from 534 Use the relative portion of the identifier authority value from
486 the user-sid as the user id value (same for group id using the 535 the user-sid as the user id value (same for group id using the
487 primary group sid from the process token). */ 536 primary group sid from the process token). */
488 537
489 char user_sid[256], name[256], domain[256]; 538 char user_sid[256], name[256], domain[256];
490 DWORD length = sizeof (name), dlength = sizeof (domain), trash; 539 DWORD length = sizeof (name), dlength = sizeof (domain), trash;
491 HANDLE token = NULL; 540 HANDLE token = NULL;
492 SID_NAME_USE user_type; 541 SID_NAME_USE user_type;
493 542
494 if ( 543 if (open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token)
495 open_process_token (GetCurrentProcess (), TOKEN_QUERY, &token) 544 && get_token_information (token, TokenUser,
496 && get_token_information ( 545 (PVOID) user_sid, sizeof (user_sid), &trash)
497 token, TokenUser, 546 && lookup_account_sid (NULL, *((PSID *) user_sid), name, &length,
498 (PVOID) user_sid, sizeof (user_sid), &trash) 547 domain, &dlength, &user_type))
499 && lookup_account_sid (
500 NULL, *((PSID *) user_sid), name, &length,
501 domain, &dlength, &user_type)
502 )
503 { 548 {
504 strcpy (the_passwd.pw_name, name); 549 strcpy (the_passwd.pw_name, name);
505 /* Determine a reasonable uid value. */ 550 /* Determine a reasonable uid value. */
506 if (stricmp ("administrator", name) == 0) 551 if (stricmp ("administrator", name) == 0)
507 { 552 {
522 /* restrict to conventional uid range for normal users */ 567 /* restrict to conventional uid range for normal users */
523 the_passwd.pw_uid = the_passwd.pw_uid % 60001; 568 the_passwd.pw_uid = the_passwd.pw_uid % 60001;
524 569
525 /* Get group id */ 570 /* Get group id */
526 if (get_token_information (token, TokenPrimaryGroup, 571 if (get_token_information (token, TokenPrimaryGroup,
527 (PVOID) user_sid, sizeof (user_sid), &trash)) 572 (PVOID) user_sid, sizeof (user_sid), &trash))
528 { 573 {
529 SID_IDENTIFIER_AUTHORITY * pSIA; 574 SID_IDENTIFIER_AUTHORITY * pSIA;
530 575
531 pSIA = get_sid_identifier_authority (*((PSID *) user_sid)); 576 pSIA = get_sid_identifier_authority (*((PSID *) user_sid));
532 the_passwd.pw_gid = ((pSIA->Value[2] << 24) + 577 the_passwd.pw_gid = ((pSIA->Value[2] << 24) +
539 else 584 else
540 the_passwd.pw_gid = the_passwd.pw_uid; 585 the_passwd.pw_gid = the_passwd.pw_uid;
541 } 586 }
542 } 587 }
543 /* If security calls are not supported (presumably because we 588 /* If security calls are not supported (presumably because we
544 are running under Windows 95), fallback to this. */ 589 are running under Windows 95), fallback to this. */
545 else if (GetUserName (name, &length)) 590 else if (GetUserName (name, &length))
546 { 591 {
547 strcpy (the_passwd.pw_name, name); 592 strcpy (the_passwd.pw_name, name);
548 if (stricmp ("administrator", name) == 0) 593 if (stricmp ("administrator", name) == 0)
549 the_passwd.pw_uid = 0; 594 the_passwd.pw_uid = 0;
4134 initialized is non zero (see the function main in emacs.c). 4179 initialized is non zero (see the function main in emacs.c).
4135 */ 4180 */
4136 void 4181 void
4137 globals_of_w32 () 4182 globals_of_w32 ()
4138 { 4183 {
4184 HMODULE kernel32 = GetModuleHandle ("kernel32.dll");
4185
4186 get_process_times_fn = (GetProcessTimes_Proc)
4187 GetProcAddress (kernel32, "GetProcessTimes");
4188
4139 g_b_init_is_windows_9x = 0; 4189 g_b_init_is_windows_9x = 0;
4140 g_b_init_open_process_token = 0; 4190 g_b_init_open_process_token = 0;
4141 g_b_init_get_token_information = 0; 4191 g_b_init_get_token_information = 0;
4142 g_b_init_lookup_account_sid = 0; 4192 g_b_init_lookup_account_sid = 0;
4143 g_b_init_get_sid_identifier_authority = 0; 4193 g_b_init_get_sid_identifier_authority = 0;