OLD | NEW |
1 // Copyright (c) 2012 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 #include "sandbox/win/src/sandbox_nt_util.h" | 5 #include "sandbox/win/src/sandbox_nt_util.h" |
6 | 6 |
7 #include "base/win/pe_image.h" | 7 #include "base/win/pe_image.h" |
8 #include "sandbox/win/src/sandbox_factory.h" | 8 #include "sandbox/win/src/sandbox_factory.h" |
9 #include "sandbox/win/src/target_services.h" | 9 #include "sandbox/win/src/target_services.h" |
10 | 10 |
11 namespace sandbox { | 11 namespace sandbox { |
12 | 12 |
13 // This is the list of all imported symbols from ntdll.dll. | 13 // This is the list of all imported symbols from ntdll.dll. |
14 SANDBOX_INTERCEPT NtExports g_nt = { NULL }; | 14 SANDBOX_INTERCEPT NtExports g_nt; |
15 | 15 |
16 } // namespace sandbox | 16 } // namespace sandbox |
17 | 17 |
18 namespace { | 18 namespace { |
19 | 19 |
20 #if defined(_WIN64) | 20 #if defined(_WIN64) |
21 void* AllocateNearTo(void* source, size_t size) { | 21 void* AllocateNearTo(void* source, size_t size) { |
22 using sandbox::g_nt; | 22 using sandbox::g_nt; |
23 | 23 |
24 // Start with 1 GB above the source. | 24 // Start with 1 GB above the source. |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 TouchMemory(buffer, size, intent); | 201 TouchMemory(buffer, size, intent); |
202 } __except(EXCEPTION_EXECUTE_HANDLER) { | 202 } __except(EXCEPTION_EXECUTE_HANDLER) { |
203 return false; | 203 return false; |
204 } | 204 } |
205 return true; | 205 return true; |
206 } | 206 } |
207 | 207 |
208 NTSTATUS CopyData(void* destination, const void* source, size_t bytes) { | 208 NTSTATUS CopyData(void* destination, const void* source, size_t bytes) { |
209 NTSTATUS ret = STATUS_SUCCESS; | 209 NTSTATUS ret = STATUS_SUCCESS; |
210 __try { | 210 __try { |
211 if (SandboxFactory::GetTargetServices()->GetState()->InitCalled()) { | 211 g_nt.memcpy(destination, source, bytes); |
212 memcpy(destination, source, bytes); | |
213 } else { | |
214 const char* from = reinterpret_cast<const char*>(source); | |
215 char* to = reinterpret_cast<char*>(destination); | |
216 for (size_t i = 0; i < bytes; i++) { | |
217 to[i] = from[i]; | |
218 } | |
219 } | |
220 } __except(EXCEPTION_EXECUTE_HANDLER) { | 212 } __except(EXCEPTION_EXECUTE_HANDLER) { |
221 ret = GetExceptionCode(); | 213 ret = GetExceptionCode(); |
222 } | 214 } |
223 return ret; | 215 return ret; |
224 } | 216 } |
225 | 217 |
226 // Hacky code... replace with AllocAndCopyObjectAttributes. | 218 // Hacky code... replace with AllocAndCopyObjectAttributes. |
227 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, | 219 NTSTATUS AllocAndCopyName(const OBJECT_ATTRIBUTES* in_object, |
228 wchar_t** out_name, uint32* attributes, | 220 wchar_t** out_name, uint32* attributes, |
229 HANDLE* root) { | 221 HANDLE* root) { |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 UNREFERENCED_PARAMETER(type); | 585 UNREFERENCED_PARAMETER(type); |
594 return buffer; | 586 return buffer; |
595 } | 587 } |
596 | 588 |
597 void __cdecl operator delete(void* memory, void* buffer, | 589 void __cdecl operator delete(void* memory, void* buffer, |
598 sandbox::AllocationType type) { | 590 sandbox::AllocationType type) { |
599 UNREFERENCED_PARAMETER(memory); | 591 UNREFERENCED_PARAMETER(memory); |
600 UNREFERENCED_PARAMETER(buffer); | 592 UNREFERENCED_PARAMETER(buffer); |
601 UNREFERENCED_PARAMETER(type); | 593 UNREFERENCED_PARAMETER(type); |
602 } | 594 } |
OLD | NEW |