DlMalloc.cpp revision bba37bd191843ef29ef9c7a8839e98b73debfffa
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 <stdint.h> 20#include "Common.h" 21 22/* Dalvik specific morecore implementation defined in HeapSource.cpp. */ 23#define MORECORE(x) dvmHeapSourceMorecore(m, x) 24extern void* dvmHeapSourceMorecore(void* mspace, intptr_t increment); 25 26/* Custom heap error handling. */ 27#define PROCEED_ON_ERROR 0 28static void heap_error(const char* msg, const char* function, void* p); 29#define CORRUPTION_ERROR_ACTION(m) \ 30 heap_error("HEAP MEMORY CORRUPTION", __FUNCTION__, NULL) 31#define USAGE_ERROR_ACTION(m,p) \ 32 heap_error("ARGUMENT IS INVALID HEAP ADDRESS", __FUNCTION__, p) 33 34/* 35 * Ugly inclusion of C file so that Dalvik specific #defines configure 36 * dlmalloc for our use for mspaces (regular dlmalloc is still declared 37 * in bionic). 38 */ 39#pragma GCC diagnostic ignored "-Wempty-body" 40#pragma GCC diagnostic ignored "-Wstrict-aliasing" 41#include "../../../bionic/libc/upstream-dlmalloc/malloc.c" 42#pragma GCC diagnostic warning "-Wstrict-aliasing" 43#pragma GCC diagnostic warning "-Wempty-body" 44 45 46static void heap_error(const char* msg, const char* function, void* p) { 47 ALOG(LOG_FATAL, LOG_TAG, "@@@ ABORTING: DALVIK: %s IN %s addr=%p", msg, 48 function, p); 49 /* So that we can get a memory dump around p */ 50 *((int **) 0xdeadbaad) = (int *) p; 51} 52