Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/src/win_utils.h" | 5 #include "sandbox/src/win_utils.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/scoped_ptr.h" | 10 #include "base/scoped_ptr.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 if (STATUS_SUCCESS != status) | 190 if (STATUS_SUCCESS != status) |
| 191 return false; | 191 return false; |
| 192 | 192 |
| 193 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / | 193 path->assign(name->ObjectName.Buffer, name->ObjectName.Length / |
| 194 sizeof(name->ObjectName.Buffer[0])); | 194 sizeof(name->ObjectName.Buffer[0])); |
| 195 return true; | 195 return true; |
| 196 } | 196 } |
| 197 | 197 |
| 198 }; // namespace sandbox | 198 }; // namespace sandbox |
| 199 | 199 |
| 200 // The information is cached in a map. The map has to be global, so it's memory | 200 // TODO(cpu): Revert this change to use a map to speed up the function once |
| 201 // is leaked, and it's ok. | 201 // this has been deployed in the dev channel for a week. See bug 11789. |
| 202 void ResolveNTFunctionPtr(const char* name, void* ptr) { | 202 void ResolveNTFunctionPtr(const char* name, void* ptr) { |
| 203 static std::map<std::string, FARPROC>* function_map = NULL; | |
| 204 if (!function_map) | |
| 205 function_map = new std::map<std::string, FARPROC>; | |
| 206 | |
| 207 static HMODULE ntdll = ::GetModuleHandle(sandbox::kNtdllName); | 203 static HMODULE ntdll = ::GetModuleHandle(sandbox::kNtdllName); |
|
Nicolas Sylvain
2009/09/09 03:31:00
This is going to fail the same way it was failing
| |
| 208 | 204 |
| 209 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); | 205 FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr); |
| 210 *function_ptr = (*function_map)[name]; | |
| 211 if (*function_ptr) | |
| 212 return; | |
| 213 | |
| 214 *function_ptr = ::GetProcAddress(ntdll, name); | 206 *function_ptr = ::GetProcAddress(ntdll, name); |
| 215 (*function_map)[name] = *function_ptr; | 207 CHECK(*function_ptr) << "Failed to resolve NTDLL function"; |
| 216 DCHECK(*function_ptr) << "Failed to resolve NTDLL function"; | |
| 217 | |
| 218 if (!*function_ptr) { | |
| 219 // If we return NULL, we are going to crash. Unfortunately, this happens. | |
| 220 // See bug 11789. | |
| 221 // Maybe our module handle is not valid anymore? | |
| 222 HMODULE ntdll2 = ::GetModuleHandle(sandbox::kNtdllName); | |
| 223 *function_ptr = ::GetProcAddress(ntdll2, name); | |
| 224 (*function_map)[name] = *function_ptr; | |
| 225 | |
| 226 // TODO(nsylvain): Remove this check after we are done troubleshooting. | |
| 227 CHECK(ntdll2) << "Fatal error: NTLL module is NULL"; | |
| 228 CHECK(*function_ptr) << "Fatal error: Failed to resolve NTDLL function"; | |
| 229 | |
| 230 // If we are here, it means that getting the new module handle worked. This | |
| 231 // is not really expected. We want to receive some reports from users, so | |
| 232 // we will crash anyway. | |
| 233 // TODO(nsylvain): Remove this check after we are done troubleshooting. | |
| 234 CHECK(ntdll) << "Fatal Error: NTDLL module was NULL."; | |
| 235 CHECK(ntdll == ntdll2) << "Fatal Error: NTDLL module has been moved."; | |
| 236 CHECK(false) << "Fatal Error: GetProcAddress Inconsistency"; | |
| 237 } | |
| 238 } | 208 } |
| OLD | NEW |