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 if (NT_ALLOC == type) { | 550 void* result = NULL; |
551 if (!InitHeap()) | 551 if (NT_ALLOC == type && InitHeap()) { |
552 return NULL; | 552 // Use default flags for the allocation. |
553 result = g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size); | |
554 } else if (NT_PAGE == type) { | |
555 result = AllocateNearTo(near_to, size); | |
556 } else { | |
557 NOTREACHED_NT(); | |
rvargas (doing something else)
2014/09/10 22:22:58
This is a change in behavior for debug builds :(
Nico
2014/09/10 22:24:27
Oh, you mean when type == NOT_ALLOC but InitHead()
| |
558 } | |
553 | 559 |
554 // Use default flags for the allocation. | 560 // TODO: Returning NULL from operator new has undefined behavior, but |
555 return g_nt.RtlAllocateHeap(sandbox::g_heap, 0, size); | 561 // the Allocate() functions called above can return NULL. Consider checking |
556 } else if (NT_PAGE == type) { | 562 // for NULL here and crashing or throwing. |
557 return AllocateNearTo(near_to, size); | 563 |
558 } | 564 return result; |
559 NOTREACHED_NT(); | |
560 return NULL; | |
561 } | 565 } |
562 | 566 |
563 void operator delete(void* memory, sandbox::AllocationType type) { | 567 void operator delete(void* memory, sandbox::AllocationType type) { |
564 using namespace sandbox; | 568 using namespace sandbox; |
565 | 569 |
566 if (NT_ALLOC == type) { | 570 if (NT_ALLOC == type) { |
567 // Use default flags. | 571 // Use default flags. |
568 VERIFY(g_nt.RtlFreeHeap(sandbox::g_heap, 0, memory)); | 572 VERIFY(g_nt.RtlFreeHeap(sandbox::g_heap, 0, memory)); |
569 } else if (NT_PAGE == type) { | 573 } else if (NT_PAGE == type) { |
570 void* base = memory; | 574 void* base = memory; |
(...skipping 17 matching lines...) Expand all Loading... | |
588 UNREFERENCED_PARAMETER(type); | 592 UNREFERENCED_PARAMETER(type); |
589 return buffer; | 593 return buffer; |
590 } | 594 } |
591 | 595 |
592 void __cdecl operator delete(void* memory, void* buffer, | 596 void __cdecl operator delete(void* memory, void* buffer, |
593 sandbox::AllocationType type) { | 597 sandbox::AllocationType type) { |
594 UNREFERENCED_PARAMETER(memory); | 598 UNREFERENCED_PARAMETER(memory); |
595 UNREFERENCED_PARAMETER(buffer); | 599 UNREFERENCED_PARAMETER(buffer); |
596 UNREFERENCED_PARAMETER(type); | 600 UNREFERENCED_PARAMETER(type); |
597 } | 601 } |
OLD | NEW |