diff options
author | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 01:17:37 +0000 |
---|---|---|
committer | pkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-03-04 01:17:37 +0000 |
commit | 1e67c2be4d77333ab9f303c8d9fa5eb58ebc6c90 (patch) | |
tree | 80434934d6420f40ea3372dc1c148123c55f6a32 /sandbox | |
parent | cf50836f5fff555ab9b8d2e961029a31514ea239 (diff) | |
download | chromium_src-1e67c2be4d77333ab9f303c8d9fa5eb58ebc6c90.zip chromium_src-1e67c2be4d77333ab9f303c8d9fa5eb58ebc6c90.tar.gz chromium_src-1e67c2be4d77333ab9f303c8d9fa5eb58ebc6c90.tar.bz2 |
Create a "GetWOW64Status()" utility function and make the rest of the codebase call it.
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/6610029
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@76854 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'sandbox')
-rw-r--r-- | sandbox/src/Wow64.cc | 50 | ||||
-rw-r--r-- | sandbox/src/Wow64.h | 16 | ||||
-rw-r--r-- | sandbox/src/Wow64_64.cc | 8 | ||||
-rw-r--r-- | sandbox/src/interception.cc | 8 | ||||
-rw-r--r-- | sandbox/src/service_resolver_unittest.cc | 21 | ||||
-rw-r--r-- | sandbox/tests/common/controller.cc | 13 |
6 files changed, 34 insertions, 82 deletions
diff --git a/sandbox/src/Wow64.cc b/sandbox/src/Wow64.cc index dec5e50..79febe8 100644 --- a/sandbox/src/Wow64.cc +++ b/sandbox/src/Wow64.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -8,7 +8,7 @@ #include "base/logging.h" #include "base/scoped_ptr.h" -#include "sandbox/src/sandbox.h" +#include "base/win/windows_version.h" #include "sandbox/src/target_process.h" namespace { @@ -80,33 +80,6 @@ Wow64::~Wow64() { ::CloseHandle(continue_load_); } -bool Wow64::IsWow64() { - if (init_) - return is_wow64_; - - is_wow64_ = false; - - HMODULE kernel32 = ::GetModuleHandle(sandbox::kKerneldllName); - if (!kernel32) - return false; - - IsWow64ProcessFunction is_wow64_process = reinterpret_cast< - IsWow64ProcessFunction>(::GetProcAddress(kernel32, "IsWow64Process")); - - init_ = true; - if (!is_wow64_process) - return false; - - BOOL wow64; - if (!is_wow64_process(::GetCurrentProcess(), &wow64)) - return false; - - if (wow64) - is_wow64_ = true; - - return is_wow64_; -} - // The basic idea is to allocate one page of memory on the child, and initialize // the first part of it with our version of PatchInfo32. Then launch the helper // process passing it that address on the child. The helper process will patch @@ -114,9 +87,8 @@ bool Wow64::IsWow64() { // first event on the buffer. We'll be waiting on that event and after the 32 // bit version of ntdll is loaded, we'll remove the interception and return to // our caller. -bool Wow64::WaitForNtdll(DWORD timeout_ms) { - DCHECK(!init_); - if (!IsWow64()) +bool Wow64::WaitForNtdll() { + if (base::win::GetWOW64Status() != base::win::WOW64_ENABLED) return true; const size_t page_size = 4096; @@ -151,19 +123,19 @@ bool Wow64::WaitForNtdll(DWORD timeout_ms) { if (offsetof(PatchInfo32, section) != written) return false; - if (!RunWowHelper(buffer, timeout_ms)) + if (!RunWowHelper(buffer)) return false; // The child is intercepted on 64 bit, go on and wait for our event. - if (!DllMapped(timeout_ms)) + if (!DllMapped()) return false; // The 32 bit version is available, cleanup the child. return Restore64Code(child_->Process(), patch_info); } -bool Wow64::RunWowHelper(void* buffer, DWORD timeout_ms) { - COMPILE_ASSERT(sizeof(buffer) <= sizeof(timeout_ms), unsupported_64_bits); +bool Wow64::RunWowHelper(void* buffer) { + COMPILE_ASSERT(sizeof(buffer) <= sizeof DWORD, unsupported_64_bits); // Get the path to the helper (beside the exe). wchar_t prog_name[MAX_PATH]; @@ -188,7 +160,7 @@ bool Wow64::RunWowHelper(void* buffer, DWORD timeout_ms) { NULL, &startup_info, &process_info)) return false; - DWORD reason = ::WaitForSingleObject(process_info.hProcess, timeout_ms); + DWORD reason = ::WaitForSingleObject(process_info.hProcess, INFINITE); DWORD code; bool ok = ::GetExitCodeProcess(process_info.hProcess, &code) ? true : false; @@ -204,14 +176,14 @@ bool Wow64::RunWowHelper(void* buffer, DWORD timeout_ms) { // First we must wake up the child, then wait for dll loads on the child until // the one we care is loaded; at that point we must suspend the child again. -bool Wow64::DllMapped(DWORD timeout_ms) { +bool Wow64::DllMapped() { if (1 != ::ResumeThread(child_->MainThread())) { NOTREACHED(); return false; } for (;;) { - DWORD reason = ::WaitForSingleObject(dll_load_, timeout_ms); + DWORD reason = ::WaitForSingleObject(dll_load_, INFINITE); if (WAIT_TIMEOUT == reason || WAIT_ABANDONED == reason) return false; diff --git a/sandbox/src/Wow64.h b/sandbox/src/Wow64.h index 7ee981a..472297e 100644 --- a/sandbox/src/Wow64.h +++ b/sandbox/src/Wow64.h @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,25 +19,21 @@ class TargetProcess; class Wow64 { public: Wow64(TargetProcess* child, HMODULE ntdll) - : child_(child), ntdll_(ntdll), init_(false), dll_load_(NULL), - continue_load_(NULL) {} + : child_(child), ntdll_(ntdll), dll_load_(NULL), continue_load_(NULL) {} ~Wow64(); // Waits for the 32 bit DLL to get loaded on the child process. This function // will return immediately if not running under WOW, or launch the helper // process and wait until ntdll is ready. - bool WaitForNtdll(DWORD timeout_ms); - - // Returns true if this is a 32 bit process running on a 64 bit OS. - bool IsWow64(); + bool WaitForNtdll(); private: // Runs the WOW helper process, passing the address of a buffer allocated on // the child (one page). - bool RunWowHelper(void* buffer, DWORD timeout_ms); + bool RunWowHelper(void* buffer); // This method receives "notifications" whenever a DLL is mapped on the child. - bool DllMapped(DWORD timeout_ms); + bool DllMapped(); // Returns true if ntdll.dll is mapped on the child. bool NtdllPresent(); @@ -46,8 +42,6 @@ class Wow64 { HMODULE ntdll_; // ntdll on the parent. HANDLE dll_load_; // Event that is signaled on dll load. HANDLE continue_load_; // Event to signal to continue execution on the child. - bool init_; // Initialization control. - bool is_wow64_; // true on WOW64 environments. DISALLOW_IMPLICIT_CONSTRUCTORS(Wow64); }; diff --git a/sandbox/src/Wow64_64.cc b/sandbox/src/Wow64_64.cc index e188d68..5218077 100644 --- a/sandbox/src/Wow64_64.cc +++ b/sandbox/src/Wow64_64.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -11,11 +11,7 @@ namespace sandbox { Wow64::~Wow64() { } -bool Wow64::IsWow64() { - return false; -} - -bool Wow64::WaitForNtdll(DWORD timeout_ms) { +bool Wow64::WaitForNtdll() { return true; } diff --git a/sandbox/src/interception.cc b/sandbox/src/interception.cc index 6636cc3..e9f89dc 100644 --- a/sandbox/src/interception.cc +++ b/sandbox/src/interception.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -424,9 +424,9 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, return false; } - Wow64 WowHelper(child_, ntdll_base); if (base::win::GetVersion() <= base::win::VERSION_VISTA) { - if (!WowHelper.WaitForNtdll(INFINITE)) + Wow64 WowHelper(child_, ntdll_base); + if (!WowHelper.WaitForNtdll()) return false; } @@ -438,7 +438,7 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, #endif ServiceResolverThunk* thunk; - if (WowHelper.IsWow64()) + if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED) thunk = new Wow64ResolverThunk(child_->Process(), relaxed_); else if (!IsXPSP2OrLater()) thunk = new Win2kResolverThunk(child_->Process(), relaxed_); diff --git a/sandbox/src/service_resolver_unittest.cc b/sandbox/src/service_resolver_unittest.cc index 793d4a1..777a5da 100644 --- a/sandbox/src/service_resolver_unittest.cc +++ b/sandbox/src/service_resolver_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,10 +6,10 @@ #include "base/basictypes.h" #include "base/scoped_ptr.h" +#include "base/win/windows_version.h" #include "sandbox/src/resolver.h" #include "sandbox/src/sandbox_utils.h" #include "sandbox/src/service_resolver.h" -#include "sandbox/src/wow64.h" #include "testing/gtest/include/gtest/gtest.h" namespace { @@ -120,18 +120,11 @@ NTSTATUS PatchNtdllWithResolver(const char* function, bool relaxed, } sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) { - HMODULE ntdll_base = ::GetModuleHandle(L"ntdll.dll"); - EXPECT_TRUE(NULL != ntdll_base); - sandbox::Wow64 WowHelper(NULL, ntdll_base); - - sandbox::ServiceResolverThunk* resolver; - if (WowHelper.IsWow64()) - resolver = new Wow64ResolverTest(relaxed); - else if (!sandbox::IsXPSP2OrLater()) - resolver = new Win2kResolverTest(relaxed); - else - resolver = new WinXpResolverTest(relaxed); - return resolver; + if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED) + return new Wow64ResolverTest(relaxed); + if (!sandbox::IsXPSP2OrLater()) + return new Win2kResolverTest(relaxed); + return new WinXpResolverTest(relaxed); } NTSTATUS PatchNtdll(const char* function, bool relaxed) { diff --git a/sandbox/tests/common/controller.cc b/sandbox/tests/common/controller.cc index 6e0f080..7efd374 100644 --- a/sandbox/tests/common/controller.cc +++ b/sandbox/tests/common/controller.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -6,9 +6,9 @@ #include <string> +#include "base/win/windows_version.h" #include "sandbox/src/sandbox_factory.h" #include "sandbox/src/sandbox_utils.h" -#include "sandbox/src/wow64.h" namespace { @@ -55,11 +55,9 @@ std::wstring MakePathToSysWow64(const wchar_t* name, bool is_obj_man_path) { namespace sandbox { std::wstring MakePathToSys(const wchar_t* name, bool is_obj_man_path) { - Wow64 current_proc(NULL, NULL); - if (current_proc.IsWow64()) + if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED) return MakePathToSysWow64(name, is_obj_man_path); - else - return MakePathToSys32(name, is_obj_man_path); + return MakePathToSys32(name, is_obj_man_path); } BrokerServices* GetBroker() { @@ -140,8 +138,7 @@ bool TestRunner::AddRuleSys32(TargetPolicy::Semantics semantics, if (!AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str())) return false; - Wow64 current_proc(NULL, NULL); - if (!current_proc.IsWow64()) + if (base::win::GetWOW64Status() != base::win::WOW64_ENABLED) return true; win32_path = MakePathToSysWow64(pattern, false); |