Index: skia/ext/SkMemory_new_handler.cpp |
diff --git a/skia/ext/SkMemory_new_handler.cpp b/skia/ext/SkMemory_new_handler.cpp |
index 91adb34118f198f625e11d60d6ed7c122a0b6a6e..282a5d2be5ce1609bec024165a112ddba7b6a1ea 100644 |
--- a/skia/ext/SkMemory_new_handler.cpp |
+++ b/skia/ext/SkMemory_new_handler.cpp |
@@ -7,6 +7,7 @@ |
#include "base/process/memory.h" |
#include "build/build_config.h" |
+#include "skia_memory_dump_provider.h" |
#include "third_party/skia/include/core/SkTypes.h" |
// This implementation of sk_malloc_flags() and friends is similar to |
@@ -33,12 +34,16 @@ void sk_out_of_memory(void) { |
abort(); |
} |
-void* sk_realloc_throw(void* addr, size_t size) { |
- return throw_on_failure(size, realloc(addr, size)); |
+void* sk_realloc_throw(void* addr, size_t size, const char* typeName) { |
+ skia::SkiaAllocHooks::FreeHookIfEnabled(addr); |
+ void* new_address = realloc(addr, size); |
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(new_address, size, typeName); |
+ return throw_on_failure(size, new_address); |
} |
void sk_free(void* p) { |
if (p) { |
+ skia::SkiaAllocHooks::FreeHookIfEnabled(p); |
free(p); |
} |
} |
@@ -54,11 +59,13 @@ static void* prevent_overcommit(int fill, size_t size, void* p) { |
return p; |
} |
-void* sk_malloc_throw(size_t size) { |
- return prevent_overcommit(0x42, size, throw_on_failure(size, malloc(size))); |
+void* sk_malloc_throw(size_t size, const char* typeName) { |
+ void* address = throw_on_failure(size, malloc(size)); |
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(address, size, typeName); |
+ return prevent_overcommit(0x42, size, address); |
} |
-static void* sk_malloc_nothrow(size_t size) { |
+static void* sk_malloc_nothrow(size_t size, const char* typeName) { |
// TODO(b.kelemen): we should always use UncheckedMalloc but currently it |
// doesn't work as intended everywhere. |
void* result; |
@@ -71,21 +78,24 @@ static void* sk_malloc_nothrow(size_t size) { |
if (result) { |
prevent_overcommit(0x47, size, result); |
} |
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(result, size, typeName); |
return result; |
} |
-void* sk_malloc_flags(size_t size, unsigned flags) { |
+void* sk_malloc_flags(size_t size, unsigned flags, const char* typeName) { |
if (flags & SK_MALLOC_THROW) { |
- return sk_malloc_throw(size); |
+ return sk_malloc_throw(size, typeName); |
} |
- return sk_malloc_nothrow(size); |
+ return sk_malloc_nothrow(size, typeName); |
} |
-void* sk_calloc_throw(size_t size) { |
- return prevent_overcommit(0, size, throw_on_failure(size, calloc(size, 1))); |
+void* sk_calloc_throw(size_t size, const char* typeName) { |
+ void* address = calloc(size, 1); |
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(address, size, typeName); |
+ return prevent_overcommit(0, size, throw_on_failure(size, address)); |
} |
-void* sk_calloc(size_t size) { |
+void* sk_calloc(size_t size, const char* typeName) { |
// TODO(b.kelemen): we should always use UncheckedCalloc but currently it |
// doesn't work as intended everywhere. |
void* result; |
@@ -98,5 +108,6 @@ void* sk_calloc(size_t size) { |
if (result) { |
prevent_overcommit(0, size, result); |
} |
+ skia::SkiaAllocHooks::AllocationHookIfEnabled(result, size, typeName); |
return result; |
} |