Mercurial > emacs
comparison src/w32.c @ 48888:f0df5f687c15
Revisited my earlier fix for the following entry in etc/PROBLEMS: 'Emacs built on Windows 9x/ME crashes at startup on Windows XP, or Emacs builtpart of on XP crashes at startup on Windows 9x/ME.' Fixed several Windows API errors detected by BoundsChecker
author | Ben Key <bkey1@tampabay.rr.com> |
---|---|
date | Wed, 18 Dec 2002 06:16:28 +0000 |
parents | b4fb06f61bfd |
children | 23a1cea22d13 |
comparison
equal
deleted
inserted
replaced
48887:e846f8d1619c | 48888:f0df5f687c15 |
---|---|
97 #include "w32.h" | 97 #include "w32.h" |
98 #include "ndir.h" | 98 #include "ndir.h" |
99 #include "w32heap.h" | 99 #include "w32heap.h" |
100 #include "systime.h" | 100 #include "systime.h" |
101 | 101 |
102 void globals_of_w32 (); | |
103 | |
102 extern Lisp_Object Vw32_downcase_file_names; | 104 extern Lisp_Object Vw32_downcase_file_names; |
103 extern Lisp_Object Vw32_generate_fake_inodes; | 105 extern Lisp_Object Vw32_generate_fake_inodes; |
104 extern Lisp_Object Vw32_get_true_file_attributes; | 106 extern Lisp_Object Vw32_get_true_file_attributes; |
105 extern Lisp_Object Vw32_num_mouse_buttons; | 107 extern Lisp_Object Vw32_num_mouse_buttons; |
106 | 108 |
107 | 109 |
110 /* | |
111 Initialization states | |
112 */ | |
113 static BOOL g_b_init_is_windows_9x; | |
114 static BOOL g_b_init_open_process_token; | |
115 static BOOL g_b_init_get_token_information; | |
116 static BOOL g_b_init_lookup_account_sid; | |
117 static BOOL g_b_init_get_sid_identifier_authority; | |
118 | |
108 /* | 119 /* |
109 BEGIN: Wrapper functions around OpenProcessToken | 120 BEGIN: Wrapper functions around OpenProcessToken |
110 and other functions in advapi32.dll that are only | 121 and other functions in advapi32.dll that are only |
111 supported in Windows NT / 2k / XP | 122 supported in Windows NT / 2k / XP |
112 */ | 123 */ |
138 PSID pSid); | 149 PSID pSid); |
139 | 150 |
140 /* ** A utility function ** */ | 151 /* ** A utility function ** */ |
141 static BOOL is_windows_9x () | 152 static BOOL is_windows_9x () |
142 { | 153 { |
143 BOOL b_ret=0; | 154 static BOOL s_b_ret=0; |
144 OSVERSIONINFO os_ver; | 155 OSVERSIONINFO os_ver; |
145 ZeroMemory(&os_ver, sizeof(OSVERSIONINFO)); | 156 if (g_b_init_is_windows_9x == 0) |
146 os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); | 157 { |
147 if (GetVersionEx (&os_ver)) | 158 g_b_init_is_windows_9x = 1; |
148 { | 159 ZeroMemory(&os_ver, sizeof(OSVERSIONINFO)); |
149 b_ret = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); | 160 os_ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO); |
150 } | 161 if (GetVersionEx (&os_ver)) |
151 return b_ret; | 162 { |
163 s_b_ret = (os_ver.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS); | |
164 } | |
165 } | |
166 return s_b_ret; | |
152 } | 167 } |
153 | 168 |
154 /* ** The wrapper functions ** */ | 169 /* ** The wrapper functions ** */ |
155 | 170 |
156 BOOL WINAPI open_process_token ( | 171 BOOL WINAPI open_process_token ( |
157 HANDLE ProcessHandle, | 172 HANDLE ProcessHandle, |
158 DWORD DesiredAccess, | 173 DWORD DesiredAccess, |
159 PHANDLE TokenHandle) | 174 PHANDLE TokenHandle) |
160 { | 175 { |
161 OpenProcessToken_Proc pfn_Open_Process_Token = NULL; | 176 static OpenProcessToken_Proc s_pfn_Open_Process_Token = NULL; |
162 HMODULE hm_advapi32 = NULL; | 177 HMODULE hm_advapi32 = NULL; |
163 if (is_windows_9x () == TRUE) | 178 if (is_windows_9x () == TRUE) |
164 { | 179 { |
165 return FALSE; | 180 return FALSE; |
166 } | 181 } |
167 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | 182 if (g_b_init_open_process_token == 0) |
168 pfn_Open_Process_Token = | 183 { |
169 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken"); | 184 g_b_init_open_process_token = 1; |
170 if (pfn_Open_Process_Token == NULL) | 185 hm_advapi32 = LoadLibrary ("Advapi32.dll"); |
186 s_pfn_Open_Process_Token = | |
187 (OpenProcessToken_Proc) GetProcAddress (hm_advapi32, "OpenProcessToken"); | |
188 } | |
189 if (s_pfn_Open_Process_Token == NULL) | |
171 { | 190 { |
172 return FALSE; | 191 return FALSE; |
173 } | 192 } |
174 return ( | 193 return ( |
175 pfn_Open_Process_Token ( | 194 s_pfn_Open_Process_Token ( |
176 ProcessHandle, | 195 ProcessHandle, |
177 DesiredAccess, | 196 DesiredAccess, |
178 TokenHandle) | 197 TokenHandle) |
179 ); | 198 ); |
180 } | 199 } |
184 TOKEN_INFORMATION_CLASS TokenInformationClass, | 203 TOKEN_INFORMATION_CLASS TokenInformationClass, |
185 LPVOID TokenInformation, | 204 LPVOID TokenInformation, |
186 DWORD TokenInformationLength, | 205 DWORD TokenInformationLength, |
187 PDWORD ReturnLength) | 206 PDWORD ReturnLength) |
188 { | 207 { |
189 GetTokenInformation_Proc pfn_Get_Token_Information = NULL; | 208 static GetTokenInformation_Proc s_pfn_Get_Token_Information = NULL; |
190 HMODULE hm_advapi32 = NULL; | 209 HMODULE hm_advapi32 = NULL; |
191 if (is_windows_9x () == TRUE) | 210 if (is_windows_9x () == TRUE) |
192 { | 211 { |
193 return FALSE; | 212 return FALSE; |
194 } | 213 } |
195 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | 214 if (g_b_init_get_token_information == 0) |
196 pfn_Get_Token_Information = | 215 { |
197 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation"); | 216 g_b_init_get_token_information = 1; |
198 if (pfn_Get_Token_Information == NULL) | 217 hm_advapi32 = LoadLibrary ("Advapi32.dll"); |
218 s_pfn_Get_Token_Information = | |
219 (GetTokenInformation_Proc) GetProcAddress (hm_advapi32, "GetTokenInformation"); | |
220 } | |
221 if (s_pfn_Get_Token_Information == NULL) | |
199 { | 222 { |
200 return FALSE; | 223 return FALSE; |
201 } | 224 } |
202 return ( | 225 return ( |
203 pfn_Get_Token_Information ( | 226 s_pfn_Get_Token_Information ( |
204 TokenHandle, | 227 TokenHandle, |
205 TokenInformationClass, | 228 TokenInformationClass, |
206 TokenInformation, | 229 TokenInformation, |
207 TokenInformationLength, | 230 TokenInformationLength, |
208 ReturnLength) | 231 ReturnLength) |
216 LPDWORD cbName, | 239 LPDWORD cbName, |
217 LPTSTR DomainName, | 240 LPTSTR DomainName, |
218 LPDWORD cbDomainName, | 241 LPDWORD cbDomainName, |
219 PSID_NAME_USE peUse) | 242 PSID_NAME_USE peUse) |
220 { | 243 { |
221 LookupAccountSid_Proc pfn_Lookup_Account_Sid = NULL; | 244 static LookupAccountSid_Proc s_pfn_Lookup_Account_Sid = NULL; |
222 HMODULE hm_advapi32 = NULL; | 245 HMODULE hm_advapi32 = NULL; |
223 if (is_windows_9x () == TRUE) | 246 if (is_windows_9x () == TRUE) |
224 { | 247 { |
225 return FALSE; | 248 return FALSE; |
226 } | 249 } |
227 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | 250 if (g_b_init_lookup_account_sid == 0) |
228 pfn_Lookup_Account_Sid = | 251 { |
229 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name); | 252 g_b_init_lookup_account_sid = 1; |
230 if (pfn_Lookup_Account_Sid == NULL) | 253 hm_advapi32 = LoadLibrary ("Advapi32.dll"); |
254 s_pfn_Lookup_Account_Sid = | |
255 (LookupAccountSid_Proc) GetProcAddress (hm_advapi32, LookupAccountSid_Name); | |
256 } | |
257 if (s_pfn_Lookup_Account_Sid == NULL) | |
231 { | 258 { |
232 return FALSE; | 259 return FALSE; |
233 } | 260 } |
234 return ( | 261 return ( |
235 pfn_Lookup_Account_Sid ( | 262 s_pfn_Lookup_Account_Sid ( |
236 lpSystemName, | 263 lpSystemName, |
237 Sid, | 264 Sid, |
238 Name, | 265 Name, |
239 cbName, | 266 cbName, |
240 DomainName, | 267 DomainName, |
244 } | 271 } |
245 | 272 |
246 PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority ( | 273 PSID_IDENTIFIER_AUTHORITY WINAPI get_sid_identifier_authority ( |
247 PSID pSid) | 274 PSID pSid) |
248 { | 275 { |
249 GetSidIdentifierAuthority_Proc pfn_Get_Sid_Identifier_Authority = NULL; | 276 static GetSidIdentifierAuthority_Proc s_pfn_Get_Sid_Identifier_Authority = NULL; |
250 HMODULE hm_advapi32 = NULL; | 277 HMODULE hm_advapi32 = NULL; |
251 if (is_windows_9x () == TRUE) | 278 if (is_windows_9x () == TRUE) |
252 { | 279 { |
253 return NULL; | 280 return NULL; |
254 } | 281 } |
255 hm_advapi32 = LoadLibrary ("Advapi32.dll"); | 282 if (g_b_init_get_sid_identifier_authority == 0) |
256 pfn_Get_Sid_Identifier_Authority = | 283 { |
257 (GetSidIdentifierAuthority_Proc) GetProcAddress ( | 284 g_b_init_get_sid_identifier_authority = 1; |
258 hm_advapi32, "GetSidIdentifierAuthority"); | 285 hm_advapi32 = LoadLibrary ("Advapi32.dll"); |
259 if (pfn_Get_Sid_Identifier_Authority == NULL) | 286 s_pfn_Get_Sid_Identifier_Authority = |
287 (GetSidIdentifierAuthority_Proc) GetProcAddress ( | |
288 hm_advapi32, "GetSidIdentifierAuthority"); | |
289 } | |
290 if (s_pfn_Get_Sid_Identifier_Authority == NULL) | |
260 { | 291 { |
261 return NULL; | 292 return NULL; |
262 } | 293 } |
263 return (pfn_Get_Sid_Identifier_Authority (pSid)); | 294 return (s_pfn_Get_Sid_Identifier_Authority (pSid)); |
264 } | 295 } |
265 | 296 |
266 /* | 297 /* |
267 END: Wrapper functions around OpenProcessToken | 298 END: Wrapper functions around OpenProcessToken |
268 and other functions in advapi32.dll that are only | 299 and other functions in advapi32.dll that are only |
3907 | 3938 |
3908 /* Check to see if Emacs has been installed correctly. */ | 3939 /* Check to see if Emacs has been installed correctly. */ |
3909 check_windows_init_file (); | 3940 check_windows_init_file (); |
3910 } | 3941 } |
3911 | 3942 |
3943 /* | |
3944 globals_of_w32 is used to initialize those global variables that | |
3945 must always be initialized on startup even when the global variable | |
3946 initialized is non zero (see the function main in emacs.c). | |
3947 */ | |
3948 void globals_of_w32 () | |
3949 { | |
3950 g_b_init_is_windows_9x = 0; | |
3951 g_b_init_open_process_token = 0; | |
3952 g_b_init_get_token_information = 0; | |
3953 g_b_init_lookup_account_sid = 0; | |
3954 g_b_init_get_sid_identifier_authority = 0; | |
3955 } | |
3956 | |
3912 /* end of nt.c */ | 3957 /* end of nt.c */ |