4 * Copyright (c) 2000 - 2011 Samsung Electronics Co., Ltd. All rights reserved.
6 * Contact: Jungmin Cho <chivalry.cho@samsung.com>, Gwangho Hwang <gwang.hwang@samsung.com>
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
27 #ifdef HEAPDGB_ACTIVATE
29 #define HOOK_RESET() \
31 __malloc_hook = old_malloc_hook; \
32 __free_hook = old_free_hook; \
37 __malloc_hook = my_malloc; \
38 __free_hook = my_free; \
41 static void *(*old_malloc_hook) (size_t size, const void *caller);
42 static void *(*old_realloc_hook) (void *ptr, size_t size, const void *caller);
43 static void (*old_free_hook) (void *ptr, const void *caller);
45 static void *my_malloc(size_t size, const void *caller);
46 static void *my_realloc(void *ptr, size_t size, const void *caller);
47 static void my_free(void *ptr, const void *caller);
49 static void my_free(void *ptr, const void *caller)
51 void *callstack_addrs[20];
52 char **callstack_strings;
57 printf("%c[1;31m[FREE] %x %x", 27, ptr, caller);
58 printf("%c[0m\n", 27);
65 static void *my_malloc(size_t size, const void *caller)
72 printf("%c[1;31m[MALLOC] %x %x", 27, ptr, caller);
73 printf("%c[0m\n", 27);
80 static void malloc_init(void)
82 old_malloc_hook = __malloc_hook;
83 old_free_hook = __free_hook;
88 __attribute__ ((visibility("default")))
89 void (*__malloc_initialize_hook) (void) = malloc_init;