| 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 |
| (...skipping 529 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 540 | 540 |
| 541 return true; | 541 return true; |
| 542 } | 542 } |
| 543 | 543 |
| 544 } // namespace sandbox | 544 } // namespace sandbox |
| 545 | 545 |
| 546 void* operator new(size_t size, sandbox::AllocationType type, | 546 void* operator new(size_t size, sandbox::AllocationType type, |
| 547 void* near_to) { | 547 void* near_to) { |
| 548 using namespace sandbox; | 548 using namespace sandbox; |
| 549 | 549 |
| 550 void* result = NULL; |
| 550 if (NT_ALLOC == type) { | 551 if (NT_ALLOC == type) { |
| 551 if (!InitHeap()) | 552 if (InitHeap()) { |
| 552 return NULL; | 553 // Use default flags for the allocation. |
| 554 result = g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size); |
| 555 } |
| 556 } else if (NT_PAGE == type) { |
| 557 result = AllocateNearTo(near_to, size); |
| 558 } else { |
| 559 NOTREACHED_NT(); |
| 560 } |
| 553 | 561 |
| 554 // Use default flags for the allocation. | 562 // TODO: Returning NULL from operator new has undefined behavior, but |
| 555 return g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size); | 563 // the Allocate() functions called above can return NULL. Consider checking |
| 556 } else if (NT_PAGE == type) { | 564 // for NULL here and crashing or throwing. |
| 557 return AllocateNearTo(near_to, size); | 565 |
| 558 } | 566 return result; |
| 559 NOTREACHED_NT(); | |
| 560 return NULL; | |
| 561 } | 567 } |
| 562 | 568 |
| 563 void operator delete(void* memory, sandbox::AllocationType type) { | 569 void operator delete(void* memory, sandbox::AllocationType type) { |
| 564 using namespace sandbox; | 570 using namespace sandbox; |
| 565 | 571 |
| 566 if (NT_ALLOC == type) { | 572 if (NT_ALLOC == type) { |
| 567 // Use default flags. | 573 // Use default flags. |
| 568 VERIFY(g_nt.RtlFreeHeap(sandbox::g_heap, 0, memory)); | 574 VERIFY(g_nt.RtlFreeHeap(sandbox::g_heap, 0, memory)); |
| 569 } else if (NT_PAGE == type) { | 575 } else if (NT_PAGE == type) { |
| 570 void* base = memory; | 576 void* base = memory; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 588 UNREFERENCED_PARAMETER(type); | 594 UNREFERENCED_PARAMETER(type); |
| 589 return buffer; | 595 return buffer; |
| 590 } | 596 } |
| 591 | 597 |
| 592 void __cdecl operator delete(void* memory, void* buffer, | 598 void __cdecl operator delete(void* memory, void* buffer, |
| 593 sandbox::AllocationType type) { | 599 sandbox::AllocationType type) { |
| 594 UNREFERENCED_PARAMETER(memory); | 600 UNREFERENCED_PARAMETER(memory); |
| 595 UNREFERENCED_PARAMETER(buffer); | 601 UNREFERENCED_PARAMETER(buffer); |
| 596 UNREFERENCED_PARAMETER(type); | 602 UNREFERENCED_PARAMETER(type); |
| 597 } | 603 } |
| OLD | NEW |