1 /*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "dlmalloc.h"
18
19 #include "private/libc_logging.h"
20
21 // Send dlmalloc errors to the log.
22 static void __bionic_heap_corruption_error(const char* function);
23 static void __bionic_heap_usage_error(const char* function, void* address);
24 #define PROCEED_ON_ERROR 0
25 #define CORRUPTION_ERROR_ACTION(m) __bionic_heap_corruption_error(__FUNCTION__)
26 #define USAGE_ERROR_ACTION(m,p) __bionic_heap_usage_error(__FUNCTION__, p)
27
28 // Ugly inclusion of C file so that bionic specific #defines configure dlmalloc.
29 #include "../upstream-dlmalloc/malloc.c"
30
__bionic_heap_corruption_error(const char * function)31 static void __bionic_heap_corruption_error(const char* function) {
32 __libc_fatal("@@@ ABORTING: heap corruption detected by %s", function);
33 }
34
__bionic_heap_usage_error(const char * function,void * address)35 static void __bionic_heap_usage_error(const char* function, void* address) {
36 __libc_fatal("@@@ ABORTING: invalid address or address of corrupt block %p passed to %s",
37 address, function);
38 // So that we can get a memory dump around the specific address.
39 *((int**) 0xdeadbaad) = (int*) address;
40 }
41