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
3 // found in the LICENSE file.
9 #include "base/process_util.h"
11 #include "third_party/skia/include/core/SkTypes.h"
12 #include "third_party/skia/include/core/SkThread.h"
14 // This implementation of sk_malloc_flags() and friends is identical
15 // to SkMemory_malloc.c, except that it disables the CRT's new_handler
16 // during malloc(), when SK_MALLOC_THROW is not set (ie., when
17 // sk_malloc_flags() would not abort on NULL).
19 SK_DECLARE_STATIC_MUTEX(gSkNewHandlerMutex
);
22 SkASSERT(!"sk_throw");
26 void sk_out_of_memory(void) {
27 SkASSERT(!"sk_out_of_memory");
31 void* sk_malloc_throw(size_t size
) {
32 return sk_malloc_flags(size
, SK_MALLOC_THROW
);
35 void* sk_realloc_throw(void* addr
, size_t size
) {
36 void* p
= realloc(addr
, size
);
46 void sk_free(void* p
) {
52 void* sk_malloc_flags(size_t size
, unsigned flags
) {
55 // Android doesn't have std::set_new_handler.
58 if (!(flags
& SK_MALLOC_THROW
)) {
59 #if defined(OS_MACOSX) && !defined(OS_IOS)
60 p
= base::UncheckedMalloc(size
);
62 SkAutoMutexAcquire
lock(gSkNewHandlerMutex
);
63 std::new_handler old_handler
= std::set_new_handler(NULL
);
65 std::set_new_handler(old_handler
);
72 if (flags
& SK_MALLOC_THROW
) {