Simplify ResolveNTFunctionPtr (temporary)
I want to test the theory that the issues we are observing here are actually a race condition. - The race condtion would be related with 2 operations that are not thread safe: 1- check/creation of the map 2- search/insert on the map I would like to air this CL on dev channel for a week and observe the crash rate. BUG=11789 Review URL: http://codereview.chromium.org/199052 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25741 0039d316-1c4b-4281-b951-d872f2087c98
This commit is contained in:
@ -197,42 +197,12 @@ bool GetPathFromHandle(HANDLE handle, std::wstring* path) {
|
||||
|
||||
}; // namespace sandbox
|
||||
|
||||
// The information is cached in a map. The map has to be global, so it's memory
|
||||
// is leaked, and it's ok.
|
||||
// TODO(cpu): Revert this change to use a map to speed up the function once
|
||||
// this has been deployed in the dev channel for a week. See bug 11789.
|
||||
void ResolveNTFunctionPtr(const char* name, void* ptr) {
|
||||
static std::map<std::string, FARPROC>* function_map = NULL;
|
||||
if (!function_map)
|
||||
function_map = new std::map<std::string, FARPROC>;
|
||||
|
||||
static HMODULE ntdll = ::GetModuleHandle(sandbox::kNtdllName);
|
||||
|
||||
FARPROC* function_ptr = reinterpret_cast<FARPROC*>(ptr);
|
||||
*function_ptr = (*function_map)[name];
|
||||
if (*function_ptr)
|
||||
return;
|
||||
|
||||
*function_ptr = ::GetProcAddress(ntdll, name);
|
||||
(*function_map)[name] = *function_ptr;
|
||||
DCHECK(*function_ptr) << "Failed to resolve NTDLL function";
|
||||
|
||||
if (!*function_ptr) {
|
||||
// If we return NULL, we are going to crash. Unfortunately, this happens.
|
||||
// See bug 11789.
|
||||
// Maybe our module handle is not valid anymore?
|
||||
HMODULE ntdll2 = ::GetModuleHandle(sandbox::kNtdllName);
|
||||
*function_ptr = ::GetProcAddress(ntdll2, name);
|
||||
(*function_map)[name] = *function_ptr;
|
||||
|
||||
// TODO(nsylvain): Remove this check after we are done troubleshooting.
|
||||
CHECK(ntdll2) << "Fatal error: NTLL module is NULL";
|
||||
CHECK(*function_ptr) << "Fatal error: Failed to resolve NTDLL function";
|
||||
|
||||
// If we are here, it means that getting the new module handle worked. This
|
||||
// is not really expected. We want to receive some reports from users, so
|
||||
// we will crash anyway.
|
||||
// TODO(nsylvain): Remove this check after we are done troubleshooting.
|
||||
CHECK(ntdll) << "Fatal Error: NTDLL module was NULL.";
|
||||
CHECK(ntdll == ntdll2) << "Fatal Error: NTDLL module has been moved.";
|
||||
CHECK(false) << "Fatal Error: GetProcAddress Inconsistency";
|
||||
}
|
||||
CHECK(*function_ptr) << "Failed to resolve NTDLL function";
|
||||
}
|
||||
|
Reference in New Issue
Block a user