From b9c587d5a7e5d0a6c669b4fd2fd6d09985b26a2f Mon Sep 17 00:00:00 2001 From: "jschuh@chromium.org" Date: Mon, 27 Jun 2011 18:46:57 +0000 Subject: Modifying ResolveNTFunctionPtr in an attempt to eliminate crashes on random unresolved functions. BUG=11789 TEST=None. Review URL: http://codereview.chromium.org/7276004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90614 0039d316-1c4b-4281-b951-d872f2087c98 --- sandbox/src/win_utils.cc | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'sandbox') diff --git a/sandbox/src/win_utils.cc b/sandbox/src/win_utils.cc index 5a846e0..8a43d97 100644 --- a/sandbox/src/win_utils.cc +++ b/sandbox/src/win_utils.cc @@ -298,15 +298,26 @@ bool WriteProtectedChildMemory(HANDLE child_process, void* address, }; // namespace sandbox -// TODO(cpu): This is not the final code we want here but we are yet -// to understand what is going on. See bug 11789. +// TODO(jschuh): http://crbug.com/11789 +// I'm guessing we have a race where some "security" software is messing +// with ntdll/imports underneath us. So, we retry a few times, and in the +// worst case we sleep briefly before a few more attempts. (Normally sleeping +// would be very bad, but it's better than crashing in this case.) void ResolveNTFunctionPtr(const char* name, void* ptr) { - HMODULE ntdll = ::GetModuleHandle(sandbox::kNtdllName); + const int max_tries = 5; + const int sleep_threshold = 2; + + static HMODULE ntdll = ::GetModuleHandle(sandbox::kNtdllName); + FARPROC* function_ptr = reinterpret_cast(ptr); *function_ptr = ::GetProcAddress(ntdll, name); - if (*function_ptr) - return; - // We have data that re-trying helps. - *function_ptr = ::GetProcAddress(ntdll, name); + + for (int tries = 1; !(*function_ptr) && tries < max_tries; ++tries) { + if (tries >= sleep_threshold) + ::Sleep(1); + ntdll = ::GetModuleHandle(sandbox::kNtdllName); + *function_ptr = ::GetProcAddress(ntdll, name); + } + CHECK(*function_ptr); } -- cgit v1.1