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

Side by Side Diff: base/process/memory_mac.mm

Issue 23455061: Add sk_calloc and sk_calloc_throw to SkMemory_new_handler.cpp. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 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
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "base/process/memory.h" 5 #include "base/process/memory.h"
6 6
7 #include <CoreFoundation/CoreFoundation.h> 7 #include <CoreFoundation/CoreFoundation.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <mach/mach.h> 9 #include <mach/mach.h>
10 #include <mach/mach_vm.h> 10 #include <mach/mach_vm.h>
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 if (g_old_malloc) { 491 if (g_old_malloc) {
492 #if ARCH_CPU_32_BITS 492 #if ARCH_CPU_32_BITS
493 ScopedClearErrno clear_errno; 493 ScopedClearErrno clear_errno;
494 ThreadLocalBooleanAutoReset flag(g_unchecked_malloc.Pointer(), true); 494 ThreadLocalBooleanAutoReset flag(g_unchecked_malloc.Pointer(), true);
495 #endif // ARCH_CPU_32_BITS 495 #endif // ARCH_CPU_32_BITS
496 return g_old_malloc(malloc_default_zone(), size); 496 return g_old_malloc(malloc_default_zone(), size);
497 } 497 }
498 return malloc(size); 498 return malloc(size);
499 } 499 }
500 500
501 void* UncheckedCalloc(size_t num_items, size_t size) {
502 if (g_old_calloc) {
503 #if ARCH_CPU_32_BITS
504 ScopedClearErrno clear_errno;
505 ThreadLocalBooleanAutoReset flag(g_unchecked_malloc.Pointer(), true);
Scott Hess - ex-Googler 2013/09/24 21:05:54 This reads confusing - maybe change g_unchecked_ma
mtklein 2013/09/24 21:12:18 You bet. Was thinking that myself. Done.
506 #endif // ARCH_CPU_32_BITS
507 return g_old_calloc(malloc_default_zone(), num_items, size);
508 }
509 return calloc(num_items, size);
510 }
511
501 void EnableTerminationOnOutOfMemory() { 512 void EnableTerminationOnOutOfMemory() {
502 if (g_oom_killer_enabled) 513 if (g_oom_killer_enabled)
503 return; 514 return;
504 515
505 g_oom_killer_enabled = true; 516 g_oom_killer_enabled = true;
506 517
507 // === C malloc/calloc/valloc/realloc/posix_memalign === 518 // === C malloc/calloc/valloc/realloc/posix_memalign ===
508 519
509 // This approach is not perfect, as requests for amounts of memory larger than 520 // This approach is not perfect, as requests for amounts of memory larger than
510 // MALLOC_ABSOLUTE_MAX_SIZE (currently SIZE_T_MAX - (2 * PAGE_SIZE)) will 521 // MALLOC_ABSOLUTE_MAX_SIZE (currently SIZE_T_MAX - (2 * PAGE_SIZE)) will
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 @selector(allocWithZone:)); 706 @selector(allocWithZone:));
696 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>( 707 g_old_allocWithZone = reinterpret_cast<allocWithZone_t>(
697 method_getImplementation(orig_method)); 708 method_getImplementation(orig_method));
698 CHECK(g_old_allocWithZone) 709 CHECK(g_old_allocWithZone)
699 << "Failed to get allocWithZone allocation function."; 710 << "Failed to get allocWithZone allocation function.";
700 method_setImplementation(orig_method, 711 method_setImplementation(orig_method,
701 reinterpret_cast<IMP>(oom_killer_allocWithZone)); 712 reinterpret_cast<IMP>(oom_killer_allocWithZone));
702 } 713 }
703 714
704 } // namespace base 715 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698