From 517617476b7231f63b2f900d9dc825db2ee4161d Mon Sep 17 00:00:00 2001 From: "pkasting@chromium.org" Date: Thu, 7 Apr 2011 18:49:09 +0000 Subject: Make the windows_version.h functions threadsafe by using a singleton. Add accessors to the singleton for more values that various code wants, then convert almost everyone using OSVERSIONINFO or SYSTEM_INFO structs to calling these accessors. Declare an AtExitManager in the out-of-process test runner since it didn't have one and that breaks singleton-using code in the test executable (as opposed to in chrome.dll). A few other minor cleanups along the way (binding of "*", shorter code, etc.). Because I ran into problems with it while modifying gcapi.cc, I cleaned up our usage of strsafe.h a bit, so that files that don't need it don't include it and files that do use STRSAFE_NO_DEPRECATE instead of a modified #include order. BUG=none TEST=none Review URL: http://codereview.chromium.org/6713107 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@80819 0039d316-1c4b-4281-b951-d872f2087c98 --- sandbox/src/Wow64.cc | 3 ++- sandbox/src/dep_test.cc | 30 ++-------------------------- sandbox/src/integrity_level_test.cc | 8 ++++---- sandbox/src/interception.cc | 3 ++- sandbox/src/job.cc | 12 ++++------- sandbox/src/sandbox_utils.cc | 34 ++++++-------------------------- sandbox/src/service_resolver_unittest.cc | 3 ++- 7 files changed, 22 insertions(+), 71 deletions(-) (limited to 'sandbox/src') diff --git a/sandbox/src/Wow64.cc b/sandbox/src/Wow64.cc index 9284fe8..60c63fd 100644 --- a/sandbox/src/Wow64.cc +++ b/sandbox/src/Wow64.cc @@ -88,7 +88,8 @@ Wow64::~Wow64() { // bit version of ntdll is loaded, we'll remove the interception and return to // our caller. bool Wow64::WaitForNtdll() { - if (base::win::GetWOW64Status() != base::win::WOW64_ENABLED) + if (base::win::OSInfo::GetInstance()->wow64_status() != + base::win::OSInfo::WOW64_ENABLED) return true; const size_t page_size = 4096; diff --git a/sandbox/src/dep_test.cc b/sandbox/src/dep_test.cc index 7d57c6e..91d4e67 100644 --- a/sandbox/src/dep_test.cc +++ b/sandbox/src/dep_test.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. @@ -12,32 +12,6 @@ namespace sandbox { namespace { -class DepTest : public testing::Test { - public: - static bool IsTestCaseDisabled() { - OSVERSIONINFOEX version_info; - version_info.dwOSVersionInfoSize = sizeof version_info; - GetVersionEx(reinterpret_cast(&version_info)); - - // Windows 2000 doesn't support DEP at all. - if (version_info.dwMajorVersion == 5 && version_info.dwMinorVersion == 0) - return true; - - // Windows XP Service Pack 0 and 1 don't support DEP at all. - if (version_info.dwMajorVersion == 5 && version_info.dwMinorVersion == 1 - && version_info.wServicePackMajor < 2) - return true; - - // Bug 1212371 Vista SP0 DEP support is half-baked. Nobody seem to have - // noticed! - if (version_info.dwMajorVersion == 6 && - version_info.wServicePackMajor == 0) - return true; - - return false; - } -}; - BYTE kReturnCode[] = { // ret 0xC3, @@ -167,7 +141,7 @@ SBOX_TESTS_COMMAND int CheckDepLevel(int argc, wchar_t **argv) { } // namespace // This test is disabled. See bug 1275842 -TEST_F(DepTest, DISABLED_TestDepDisable) { +TEST(DepTest, DISABLED_TestDepDisable) { TestRunner runner(JOB_UNPROTECTED, USER_INTERACTIVE, USER_INTERACTIVE); runner.SetTimeout(INFINITE); diff --git a/sandbox/src/integrity_level_test.cc b/sandbox/src/integrity_level_test.cc index cdc8da7..c6e0b64 100644 --- a/sandbox/src/integrity_level_test.cc +++ b/sandbox/src/integrity_level_test.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. @@ -45,7 +45,7 @@ SBOX_TESTS_COMMAND int CheckIntegrityLevel(int argc, wchar_t **argv) { } TEST(IntegrityLevelTest, TestLowILReal) { - if (base::win::VERSION_VISTA != base::win::GetVersion()) + if (base::win::GetVersion() != base::win::VERSION_VISTA) return; TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); @@ -61,7 +61,7 @@ TEST(IntegrityLevelTest, TestLowILReal) { } TEST(DelayedIntegrityLevelTest, TestLowILDelayed) { - if (base::win::VERSION_VISTA != base::win::GetVersion()) + if (base::win::GetVersion() != base::win::VERSION_VISTA) return; TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); @@ -77,7 +77,7 @@ TEST(DelayedIntegrityLevelTest, TestLowILDelayed) { } TEST(IntegrityLevelTest, TestNoILChange) { - if (base::win::VERSION_VISTA != base::win::GetVersion()) + if (base::win::GetVersion() != base::win::VERSION_VISTA) return; TestRunner runner(JOB_LOCKDOWN, USER_INTERACTIVE, USER_INTERACTIVE); diff --git a/sandbox/src/interception.cc b/sandbox/src/interception.cc index 577d079..b66fddd 100644 --- a/sandbox/src/interception.cc +++ b/sandbox/src/interception.cc @@ -438,7 +438,8 @@ bool InterceptionManager::PatchClientFunctions(DllInterceptionData* thunks, #endif ServiceResolverThunk* thunk; - if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED) + if (base::win::OSInfo::GetInstance()->wow64_status() == + base::win::OSInfo::WOW64_ENABLED) thunk = new Wow64ResolverThunk(child_->Process(), relaxed_); else if (!IsXPSP2OrLater()) thunk = new Win2kResolverThunk(child_->Process(), relaxed_); diff --git a/sandbox/src/job.cc b/sandbox/src/job.cc index e0dca68..8ed3a77 100644 --- a/sandbox/src/job.cc +++ b/sandbox/src/job.cc @@ -1,8 +1,10 @@ -// 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. #include "sandbox/src/job.h" + +#include "base/win/windows_version.h" #include "sandbox/src/restricted_token.h" namespace sandbox { @@ -49,17 +51,11 @@ DWORD Job::Init(JobLevel security_level, wchar_t *job_name, jbur.UIRestrictionsClass |= JOB_OBJECT_UILIMIT_EXITWINDOWS; } case JOB_UNPROTECTED: { - OSVERSIONINFO version_info = {0}; - version_info.dwOSVersionInfoSize = sizeof(version_info); - GetVersionEx(&version_info); - // The JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE flag is not supported on // Windows 2000. We need a mechanism on Windows 2000 to ensure // that processes in the job are terminated when the job is closed - if ((5 == version_info.dwMajorVersion) && - (0 == version_info.dwMinorVersion)) { + if (base::win::GetVersion() == base::win::VERSION_PRE_XP) break; - } jeli.BasicLimitInformation.LimitFlags |= JOB_OBJECT_LIMIT_KILL_ON_JOB_CLOSE; diff --git a/sandbox/src/sandbox_utils.cc b/sandbox/src/sandbox_utils.cc index 9554514..b93434c 100644 --- a/sandbox/src/sandbox_utils.cc +++ b/sandbox/src/sandbox_utils.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. @@ -7,6 +7,7 @@ #include #include "base/logging.h" +#include "base/win/windows_version.h" #include "sandbox/src/internal_types.h" #include "sandbox/src/nt_internals.h" @@ -56,33 +57,10 @@ bool GetModuleHandleHelper(DWORD flags, const wchar_t* module_name, } bool IsXPSP2OrLater() { - OSVERSIONINFOEX version = {0}; - version.dwOSVersionInfoSize = sizeof(version); - if (!::GetVersionEx(reinterpret_cast(&version))) { - NOTREACHED(); - return false; - } - - // Vista or later - if (version.dwMajorVersion > 5) - return true; - - // 2k, xp or 2003 - if (version.dwMajorVersion == 5) { - // 2003 - if (version.dwMinorVersion > 1) - return true; - - // 2000 - if (version.dwMinorVersion == 0) - return false; - - // Windows Xp Sp2 or later - if (version.wServicePackMajor >= 2) - return true; - } - - return false; + base::win::Version version = base::win::GetVersion(); + return (version > base::win::VERSION_XP) || + ((version == base::win::VERSION_XP) && + (base::win::OSInfo::GetInstance()->service_pack().major >= 2)); } void InitObjectAttribs(const std::wstring& name, ULONG attributes, HANDLE root, diff --git a/sandbox/src/service_resolver_unittest.cc b/sandbox/src/service_resolver_unittest.cc index f5e29f3..36ad1d0f 100644 --- a/sandbox/src/service_resolver_unittest.cc +++ b/sandbox/src/service_resolver_unittest.cc @@ -120,7 +120,8 @@ NTSTATUS PatchNtdllWithResolver(const char* function, bool relaxed, } sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) { - if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED) + if (base::win::OSInfo::GetInstance()->wow64_status() == + base::win::OSInfo::WOW64_ENABLED) return new Wow64ResolverTest(relaxed); if (!sandbox::IsXPSP2OrLater()) return new Win2kResolverTest(relaxed); -- cgit v1.1