• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)
24 extern void* dvmHeapSourceMorecore(void* mspace, intptr_t increment);
25 
26 /* Custom heap error handling. */
27 #define PROCEED_ON_ERROR 0
28 static 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 #include "../../../bionic/libc/upstream-dlmalloc/malloc.c"
40 
41 
heap_error(const char * msg,const char * function,void * p)42 static void heap_error(const char* msg, const char* function, void* p) {
43     ALOG(LOG_FATAL, LOG_TAG, "@@@ ABORTING: DALVIK: %s IN %s addr=%p", msg,
44          function, p);
45     /* So that we can get a memory dump around p */
46     *((int **) 0xdeadbaad) = (int *) p;
47 }
48