Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(792)

Side by Side Diff: sandbox/src/service_resolver_unittest.cc

Issue 6610029: Create a "GetWOW64Status()" utility function and make the rest of the codebas... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // This file contains unit tests for ServiceResolverThunk. 5 // This file contains unit tests for ServiceResolverThunk.
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/scoped_ptr.h" 8 #include "base/scoped_ptr.h"
9 #include "base/win/windows_version.h"
9 #include "sandbox/src/resolver.h" 10 #include "sandbox/src/resolver.h"
10 #include "sandbox/src/sandbox_utils.h" 11 #include "sandbox/src/sandbox_utils.h"
11 #include "sandbox/src/service_resolver.h" 12 #include "sandbox/src/service_resolver.h"
12 #include "sandbox/src/wow64.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace { 15 namespace {
16 16
17 // This is the concrete resolver used to perform service-call type functions 17 // This is the concrete resolver used to perform service-call type functions
18 // inside ntdll.dll. 18 // inside ntdll.dll.
19 template<typename T> 19 template<typename T>
20 class ResolverThunkTest : public T { 20 class ResolverThunkTest : public T {
21 public: 21 public:
22 // The service resolver needs a child process to write to. 22 // The service resolver needs a child process to write to.
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 ret = resolver->Setup(ntdll_base, NULL, function, NULL, function_entry, 113 ret = resolver->Setup(ntdll_base, NULL, function, NULL, function_entry,
114 thunk.get(), thunk_size, &used); 114 thunk.get(), thunk_size, &used);
115 CheckJump(service, thunk.get()); 115 CheckJump(service, thunk.get());
116 } 116 }
117 } 117 }
118 118
119 return ret; 119 return ret;
120 } 120 }
121 121
122 sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) { 122 sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) {
123 HMODULE ntdll_base = ::GetModuleHandle(L"ntdll.dll"); 123 if (base::win::GetWOW64Status() == base::win::WOW64_ENABLED)
124 EXPECT_TRUE(NULL != ntdll_base); 124 return new Wow64ResolverTest(relaxed);
125 sandbox::Wow64 WowHelper(NULL, ntdll_base); 125 if (!sandbox::IsXPSP2OrLater())
126 126 return new Win2kResolverTest(relaxed);
127 sandbox::ServiceResolverThunk* resolver; 127 return new WinXpResolverTest(relaxed);
128 if (WowHelper.IsWow64())
129 resolver = new Wow64ResolverTest(relaxed);
130 else if (!sandbox::IsXPSP2OrLater())
131 resolver = new Win2kResolverTest(relaxed);
132 else
133 resolver = new WinXpResolverTest(relaxed);
134 return resolver;
135 } 128 }
136 129
137 NTSTATUS PatchNtdll(const char* function, bool relaxed) { 130 NTSTATUS PatchNtdll(const char* function, bool relaxed) {
138 sandbox::ServiceResolverThunk* resolver = GetTestResolver(relaxed); 131 sandbox::ServiceResolverThunk* resolver = GetTestResolver(relaxed);
139 132
140 NTSTATUS ret = PatchNtdllWithResolver(function, relaxed, resolver); 133 NTSTATUS ret = PatchNtdllWithResolver(function, relaxed, resolver);
141 delete resolver; 134 delete resolver;
142 return ret; 135 return ret;
143 } 136 }
144 137
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 ::GetLastError(); 196 ::GetLastError();
204 197
205 ret = PatchNtdllWithResolver("NtMapViewOfSection", true, resolver); 198 ret = PatchNtdllWithResolver("NtMapViewOfSection", true, resolver);
206 EXPECT_EQ(STATUS_SUCCESS, ret) << "NtMapViewOfSection, last error: " << 199 EXPECT_EQ(STATUS_SUCCESS, ret) << "NtMapViewOfSection, last error: " <<
207 ::GetLastError(); 200 ::GetLastError();
208 delete resolver; 201 delete resolver;
209 #endif 202 #endif
210 } 203 }
211 204
212 } // namespace 205 } // namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698