OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "sandbox/win/src/target_services.h" | 5 #include "sandbox/win/src/target_services.h" |
6 | 6 |
7 #include <new> | 7 #include <new> |
8 | 8 |
9 #include <process.h> | 9 #include <process.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 // This needs to happen after RevertToSelf() is called, because (at least) in | 69 // This needs to happen after RevertToSelf() is called, because (at least) in |
70 // the case of GetUserDefaultLCID() it checks the TEB to see if the process is | 70 // the case of GetUserDefaultLCID() it checks the TEB to see if the process is |
71 // impersonating (TEB!IsImpersonating). If it is, the cached locale information | 71 // impersonating (TEB!IsImpersonating). If it is, the cached locale information |
72 // is not used, nor is it set. Therefore, calls after RevertToSelf() will not | 72 // is not used, nor is it set. Therefore, calls after RevertToSelf() will not |
73 // have warmed-up values to use. | 73 // have warmed-up values to use. |
74 bool WarmupWindowsLocales() { | 74 bool WarmupWindowsLocales() { |
75 // NOTE(liamjm): When last checked (Win 8.1 x64) it wasn't necessary to | 75 // NOTE(liamjm): When last checked (Win 8.1 x64) it wasn't necessary to |
76 // warmup all of these functions, but let's not assume that. | 76 // warmup all of these functions, but let's not assume that. |
77 ::GetUserDefaultLangID(); | 77 ::GetUserDefaultLangID(); |
78 ::GetUserDefaultLCID(); | 78 ::GetUserDefaultLCID(); |
79 if (base::win::GetVersion() >= base::win::VERSION_VISTA) { | 79 static GetUserDefaultLocaleNameFunction GetUserDefaultLocaleName_func = |
80 static GetUserDefaultLocaleNameFunction GetUserDefaultLocaleName_func = | 80 NULL; |
81 NULL; | 81 if (!GetUserDefaultLocaleName_func) { |
| 82 HMODULE kernel32_dll = ::GetModuleHandle(kKernel32DllName); |
| 83 if (!kernel32_dll) { |
| 84 return false; |
| 85 } |
| 86 GetUserDefaultLocaleName_func = |
| 87 reinterpret_cast<GetUserDefaultLocaleNameFunction>( |
| 88 GetProcAddress(kernel32_dll, "GetUserDefaultLocaleName")); |
82 if (!GetUserDefaultLocaleName_func) { | 89 if (!GetUserDefaultLocaleName_func) { |
83 HMODULE kernel32_dll = ::GetModuleHandle(kKernel32DllName); | 90 return false; |
84 if (!kernel32_dll) { | |
85 return false; | |
86 } | |
87 GetUserDefaultLocaleName_func = | |
88 reinterpret_cast<GetUserDefaultLocaleNameFunction>( | |
89 GetProcAddress(kernel32_dll, "GetUserDefaultLocaleName")); | |
90 if (!GetUserDefaultLocaleName_func) { | |
91 return false; | |
92 } | |
93 } | 91 } |
94 wchar_t localeName[LOCALE_NAME_MAX_LENGTH] = {0}; | |
95 return (0 != GetUserDefaultLocaleName_func( | |
96 localeName, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t))); | |
97 } | 92 } |
98 return true; | 93 wchar_t localeName[LOCALE_NAME_MAX_LENGTH] = {0}; |
| 94 return (0 != GetUserDefaultLocaleName_func( |
| 95 localeName, LOCALE_NAME_MAX_LENGTH * sizeof(wchar_t))); |
99 } | 96 } |
100 | 97 |
101 // Used as storage for g_target_services, because other allocation facilities | 98 // Used as storage for g_target_services, because other allocation facilities |
102 // are not available early. We can't use a regular function static because on | 99 // are not available early. We can't use a regular function static because on |
103 // VS2015, because the CRT tries to acquire a lock to guard initialization, but | 100 // VS2015, because the CRT tries to acquire a lock to guard initialization, but |
104 // this code runs before the CRT is initialized. | 101 // this code runs before the CRT is initialized. |
105 char g_target_services_memory[sizeof(sandbox::TargetServicesBase)]; | 102 char g_target_services_memory[sizeof(sandbox::TargetServicesBase)]; |
106 sandbox::TargetServicesBase* g_target_services = nullptr; | 103 sandbox::TargetServicesBase* g_target_services = nullptr; |
107 | 104 |
108 } // namespace | 105 } // namespace |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
252 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle, | 249 ResultCode TargetServicesBase::DuplicateHandle(HANDLE source_handle, |
253 DWORD target_process_id, | 250 DWORD target_process_id, |
254 HANDLE* target_handle, | 251 HANDLE* target_handle, |
255 DWORD desired_access, | 252 DWORD desired_access, |
256 DWORD options) { | 253 DWORD options) { |
257 return sandbox::DuplicateHandleProxy(source_handle, target_process_id, | 254 return sandbox::DuplicateHandleProxy(source_handle, target_process_id, |
258 target_handle, desired_access, options); | 255 target_handle, desired_access, options); |
259 } | 256 } |
260 | 257 |
261 } // namespace sandbox | 258 } // namespace sandbox |
OLD | NEW |