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

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

Issue 10021033: Sandbox: Add support for interceptions on Windows 8. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 8 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
« no previous file with comments | « sandbox/src/service_resolver_32.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/win/windows_version.h" 9 #include "base/win/windows_version.h"
10 #include "sandbox/src/resolver.h" 10 #include "sandbox/src/resolver.h"
11 #include "sandbox/src/sandbox_utils.h" 11 #include "sandbox/src/sandbox_utils.h"
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
48 return ret; 48 return ret;
49 }; 49 };
50 50
51 private: 51 private:
52 // Holds the address of the fake target. 52 // Holds the address of the fake target.
53 void* fake_target_; 53 void* fake_target_;
54 54
55 DISALLOW_COPY_AND_ASSIGN(ResolverThunkTest); 55 DISALLOW_COPY_AND_ASSIGN(ResolverThunkTest);
56 }; 56 };
57 57
58 typedef ResolverThunkTest<sandbox::ServiceResolverThunk> WinXpResolverTest;
59
60 #if !defined(_WIN64)
58 typedef ResolverThunkTest<sandbox::Win2kResolverThunk> Win2kResolverTest; 61 typedef ResolverThunkTest<sandbox::Win2kResolverThunk> Win2kResolverTest;
59 typedef ResolverThunkTest<sandbox::ServiceResolverThunk> WinXpResolverTest; 62 typedef ResolverThunkTest<sandbox::Win8ResolverThunk> Win8ResolverTest;
60 typedef ResolverThunkTest<sandbox::Wow64ResolverThunk> Wow64ResolverTest; 63 typedef ResolverThunkTest<sandbox::Wow64ResolverThunk> Wow64ResolverTest;
64 typedef ResolverThunkTest<sandbox::Wow64W8ResolverThunk> Wow64W8ResolverTest;
65 #endif
61 66
62 const BYTE kJump32 = 0xE9; 67 const BYTE kJump32 = 0xE9;
63 68
64 void CheckJump(void* source, void* target) { 69 void CheckJump(void* source, void* target) {
65 #pragma pack(push) 70 #pragma pack(push)
66 #pragma pack(1) 71 #pragma pack(1)
67 struct Code { 72 struct Code {
68 BYTE jump; 73 BYTE jump;
69 ULONG delta; 74 ULONG delta;
70 }; 75 };
71 #pragma pack(pop) 76 #pragma pack(pop)
72 77
78 #if defined(_WIN64)
79 FAIL() << "Running 32-bit codepath";
80 #else
73 Code* patched = reinterpret_cast<Code*>(source); 81 Code* patched = reinterpret_cast<Code*>(source);
74 EXPECT_EQ(kJump32, patched->jump); 82 EXPECT_EQ(kJump32, patched->jump);
75 83
76 ULONG source_addr = bit_cast<ULONG>(source); 84 ULONG source_addr = bit_cast<ULONG>(source);
77 ULONG target_addr = bit_cast<ULONG>(target); 85 ULONG target_addr = bit_cast<ULONG>(target);
78 EXPECT_EQ(target_addr + 19 - source_addr, patched->delta); 86 EXPECT_EQ(target_addr + 19 - source_addr, patched->delta);
87 #endif
79 } 88 }
80 89
81 NTSTATUS PatchNtdllWithResolver(const char* function, bool relaxed, 90 NTSTATUS PatchNtdllWithResolver(const char* function, bool relaxed,
82 sandbox::ServiceResolverThunk* resolver) { 91 sandbox::ServiceResolverThunk* resolver) {
83 HMODULE ntdll_base = ::GetModuleHandle(L"ntdll.dll"); 92 HMODULE ntdll_base = ::GetModuleHandle(L"ntdll.dll");
84 EXPECT_TRUE(NULL != ntdll_base); 93 EXPECT_TRUE(NULL != ntdll_base);
85 94
86 void* target = ::GetProcAddress(ntdll_base, function); 95 void* target = ::GetProcAddress(ntdll_base, function);
87 EXPECT_TRUE(NULL != target); 96 EXPECT_TRUE(NULL != target);
88 if (NULL == target) 97 if (NULL == target)
(...skipping 24 matching lines...) Expand all
113 ret = resolver->Setup(ntdll_base, NULL, function, NULL, function_entry, 122 ret = resolver->Setup(ntdll_base, NULL, function, NULL, function_entry,
114 thunk.get(), thunk_size, &used); 123 thunk.get(), thunk_size, &used);
115 CheckJump(service, thunk.get()); 124 CheckJump(service, thunk.get());
116 } 125 }
117 } 126 }
118 127
119 return ret; 128 return ret;
120 } 129 }
121 130
122 sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) { 131 sandbox::ServiceResolverThunk* GetTestResolver(bool relaxed) {
123 if (base::win::OSInfo::GetInstance()->wow64_status() == 132 #if defined(_WIN64)
124 base::win::OSInfo::WOW64_ENABLED) 133 return new WinXpResolverTest(relaxed);
134 #else
135 base::win::OSInfo* os_info = base::win::OSInfo::GetInstance();
136 if (os_info->wow64_status() == base::win::OSInfo::WOW64_ENABLED) {
137 if (os_info->version() >= base::win::VERSION_WIN8)
138 return new Wow64W8ResolverTest(relaxed);
125 return new Wow64ResolverTest(relaxed); 139 return new Wow64ResolverTest(relaxed);
140 }
141
126 if (!sandbox::IsXPSP2OrLater()) 142 if (!sandbox::IsXPSP2OrLater())
127 return new Win2kResolverTest(relaxed); 143 return new Win2kResolverTest(relaxed);
144
145 if (os_info->version() >= base::win::VERSION_WIN8)
146 return new Win8ResolverTest(relaxed);
147
128 return new WinXpResolverTest(relaxed); 148 return new WinXpResolverTest(relaxed);
149 #endif
129 } 150 }
130 151
131 NTSTATUS PatchNtdll(const char* function, bool relaxed) { 152 NTSTATUS PatchNtdll(const char* function, bool relaxed) {
132 sandbox::ServiceResolverThunk* resolver = GetTestResolver(relaxed); 153 sandbox::ServiceResolverThunk* resolver = GetTestResolver(relaxed);
133 154
134 NTSTATUS ret = PatchNtdllWithResolver(function, relaxed, resolver); 155 NTSTATUS ret = PatchNtdllWithResolver(function, relaxed, resolver);
135 delete resolver; 156 delete resolver;
136 return ret; 157 return ret;
137 } 158 }
138 159
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 ::GetLastError(); 218 ::GetLastError();
198 219
199 ret = PatchNtdllWithResolver("NtMapViewOfSection", true, resolver); 220 ret = PatchNtdllWithResolver("NtMapViewOfSection", true, resolver);
200 EXPECT_EQ(STATUS_SUCCESS, ret) << "NtMapViewOfSection, last error: " << 221 EXPECT_EQ(STATUS_SUCCESS, ret) << "NtMapViewOfSection, last error: " <<
201 ::GetLastError(); 222 ::GetLastError();
202 delete resolver; 223 delete resolver;
203 #endif 224 #endif
204 } 225 }
205 226
206 } // namespace 227 } // namespace
OLDNEW
« no previous file with comments | « sandbox/src/service_resolver_32.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698