07_mingw_operator_new.patch (2514B)
1 # HG changeset patch 2 # User Tom Ritter <tom@mozilla.com> 3 # Date 1489000606 0 4 # Wed Mar 08 19:16:46 2017 +0000 5 # Node ID 522c35c24e2a46d97430b5f15e7703bc1c33784c 6 # Parent a99512c712f6580537e3133e5fd1adc091583e95 7 Bug 1230910 Declare operator new [](size_t, sandbox::AllocationType, void*) 8 9 MozReview-Commit-ID: GCKj5Ao2Y2n 10 11 diff --git a/sandbox/win/src/sandbox_nt_util.cc b/sandbox/win/src/sandbox_nt_util.cc 12 --- a/sandbox/win/src/sandbox_nt_util.cc 13 +++ b/sandbox/win/src/sandbox_nt_util.cc 14 @@ -663,16 +663,21 @@ void* operator new(size_t size, sandbox: 15 16 // TODO: Returning nullptr from operator new has undefined behavior, but 17 // the Allocate() functions called above can return nullptr. Consider checking 18 // for nullptr here and crashing or throwing. 19 20 return result; 21 } 22 23 +void* operator new [](size_t size, sandbox::AllocationType type, 24 + void* near_to) { 25 + return operator new(size, type, near_to); 26 +} 27 + 28 void operator delete(void* memory, sandbox::AllocationType type) { 29 if (type == sandbox::NT_ALLOC) { 30 // Use default flags. 31 VERIFY(sandbox::GetNtExports()->RtlFreeHeap(sandbox::g_heap, 0, memory)); 32 } else if (type == sandbox::NT_PAGE) { 33 void* base = memory; 34 SIZE_T size = 0; 35 VERIFY_SUCCESS(sandbox::GetNtExports()->FreeVirtualMemory( 36 diff --git a/sandbox/win/src/sandbox_nt_util.h b/sandbox/win/src/sandbox_nt_util.h 37 --- a/sandbox/win/src/sandbox_nt_util.h 38 +++ b/sandbox/win/src/sandbox_nt_util.h 39 @@ -13,16 +13,19 @@ 40 #include "sandbox/win/src/nt_internals.h" 41 #include "sandbox/win/src/sandbox_nt_types.h" 42 #include "third_party/abseil-cpp/absl/types/optional.h" 43 44 // Placement new and delete to be used from ntdll interception code. 45 void* __cdecl operator new(size_t size, 46 sandbox::AllocationType type, 47 void* near_to = nullptr); 48 +void* __cdecl operator new[](size_t size, 49 + sandbox::AllocationType type, 50 + void* near_to = nullptr); 51 void __cdecl operator delete(void* memory, sandbox::AllocationType type); 52 // Add operator delete that matches the placement form of the operator new 53 // above. This is required by compiler to generate code to call operator delete 54 // in case the object's constructor throws an exception. 55 // See http://msdn.microsoft.com/en-us/library/cxdxz3x6.aspx 56 void __cdecl operator delete(void* memory, 57 sandbox::AllocationType type, 58 void* near_to);