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

Side by Side Diff: sandbox/win/src/sandbox_nt_util.cc

Issue 556293002: Reorganize sandbox operator new, add a comment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 6 years, 3 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
« no previous file with comments | « no previous file | 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) 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
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
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 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698