summaryrefslogtreecommitdiffstats
path: root/sandbox
diff options
context:
space:
mode:
authorpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 18:49:09 +0000
committerpkasting@chromium.org <pkasting@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-07 18:49:09 +0000
commit517617476b7231f63b2f900d9dc825db2ee4161d (patch)
treea09d1e81c9796b0859a01dfc467710724046e8ce /sandbox
parentd91ddfc676314764d240a9ad0da06063bb265d76 (diff)
downloadchromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.zip
chromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.tar.gz
chromium_src-517617476b7231f63b2f900d9dc825db2ee4161d.tar.bz2
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
Diffstat (limited to 'sandbox')
-rw-r--r--sandbox/src/Wow64.cc3
-rw-r--r--sandbox/src/dep_test.cc30
-rw-r--r--sandbox/src/integrity_level_test.cc8
-rw-r--r--sandbox/src/interception.cc3
-rw-r--r--sandbox/src/job.cc12
-rw-r--r--sandbox/src/sandbox_utils.cc34
-rw-r--r--sandbox/src/service_resolver_unittest.cc3
-rw-r--r--sandbox/tests/common/controller.cc10
8 files changed, 28 insertions, 75 deletions
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<OSVERSIONINFO*>(&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 <windows.h>
#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<OSVERSIONINFO*>(&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);
diff --git a/sandbox/tests/common/controller.cc b/sandbox/tests/common/controller.cc
index 7efd374..b618069 100644
--- a/sandbox/tests/common/controller.cc
+++ b/sandbox/tests/common/controller.cc
@@ -55,9 +55,10 @@ 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) {
- if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED)
- return MakePathToSysWow64(name, is_obj_man_path);
- return MakePathToSys32(name, is_obj_man_path);
+ return (base::win::OSInfo::GetInstance()->wow64_status() ==
+ base::win::OSInfo::WOW64_ENABLED) ?
+ MakePathToSysWow64(name, is_obj_man_path) :
+ MakePathToSys32(name, is_obj_man_path);
}
BrokerServices* GetBroker() {
@@ -138,7 +139,8 @@ bool TestRunner::AddRuleSys32(TargetPolicy::Semantics semantics,
if (!AddRule(TargetPolicy::SUBSYS_FILES, semantics, win32_path.c_str()))
return false;
- if (base::win::GetWOW64Status() != base::win::WOW64_ENABLED)
+ if (base::win::OSInfo::GetInstance()->wow64_status() !=
+ base::win::OSInfo::WOW64_ENABLED)
return true;
win32_path = MakePathToSysWow64(pattern, false);