Merge "Minor tweak to get memory around corrupted heap chunks dumped." into jb-dev

This commit is contained in:
Andy McFadden 2012-06-19 11:28:15 -07:00 committed by Android (Google) Code Review
commit 4d0128f13a

View File

@ -2327,12 +2327,14 @@ static void __bionic_heap_error(const char* msg, const char* function, void* p)
} }
__libc_android_log_write(ANDROID_LOG_FATAL,"libc",buffer); __libc_android_log_write(ANDROID_LOG_FATAL,"libc",buffer);
abort();
/* So that we can get a memory dump around p */
*((int **) 0xdeadbaad) = (int *) p;
} }
# ifndef CORRUPTION_ERROR_ACTION # ifndef CORRUPTION_ERROR_ACTION
# define CORRUPTION_ERROR_ACTION(m) \ # define CORRUPTION_ERROR_ACTION(m,p) \
__bionic_heap_error("HEAP MEMORY CORRUPTION", __FUNCTION__, 0) __bionic_heap_error("HEAP MEMORY CORRUPTION", __FUNCTION__, p)
# endif # endif
# ifndef USAGE_ERROR_ACTION # ifndef USAGE_ERROR_ACTION
# define USAGE_ERROR_ACTION(m,p) \ # define USAGE_ERROR_ACTION(m,p) \
@ -2342,7 +2344,7 @@ static void __bionic_heap_error(const char* msg, const char* function, void* p)
#else /* !LOG_ON_HEAP_ERROR */ #else /* !LOG_ON_HEAP_ERROR */
# ifndef CORRUPTION_ERROR_ACTION # ifndef CORRUPTION_ERROR_ACTION
# define CORRUPTION_ERROR_ACTION(m) ABORT # define CORRUPTION_ERROR_ACTION(m,p) ABORT
# endif /* CORRUPTION_ERROR_ACTION */ # endif /* CORRUPTION_ERROR_ACTION */
# ifndef USAGE_ERROR_ACTION # ifndef USAGE_ERROR_ACTION
@ -3079,7 +3081,7 @@ static void internal_malloc_stats(mstate m) {
else if (RTCHECK(ok_address(M, B->fd)))\ else if (RTCHECK(ok_address(M, B->fd)))\
F = B->fd;\ F = B->fd;\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, B);\
}\ }\
B->fd = P;\ B->fd = P;\
F->bk = P;\ F->bk = P;\
@ -3096,7 +3098,7 @@ static void internal_malloc_stats(mstate m) {
mchunkptr B = P->bk;\ mchunkptr B = P->bk;\
bindex_t I = small_index(S);\ bindex_t I = small_index(S);\
if (__builtin_expect (F->bk != P || B->fd != P, 0))\ if (__builtin_expect (F->bk != P || B->fd != P, 0))\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, P);\
assert(P != B);\ assert(P != B);\
assert(P != F);\ assert(P != F);\
assert(chunksize(P) == small_index2size(I));\ assert(chunksize(P) == small_index2size(I));\
@ -3108,7 +3110,7 @@ static void internal_malloc_stats(mstate m) {
B->fd = F;\ B->fd = F;\
}\ }\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, P);\
}\ }\
} }
@ -3119,7 +3121,7 @@ static void internal_malloc_stats(mstate m) {
#define unlink_first_small_chunk(M, B, P, I) {\ #define unlink_first_small_chunk(M, B, P, I) {\
mchunkptr F = P->fd;\ mchunkptr F = P->fd;\
if (__builtin_expect (F->bk != P || B->fd != P, 0))\ if (__builtin_expect (F->bk != P || B->fd != P, 0))\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, P);\
assert(P != B);\ assert(P != B);\
assert(P != F);\ assert(P != F);\
assert(chunksize(P) == small_index2size(I));\ assert(chunksize(P) == small_index2size(I));\
@ -3130,7 +3132,7 @@ static void internal_malloc_stats(mstate m) {
F->bk = B;\ F->bk = B;\
}\ }\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, P);\
}\ }\
} }
@ -3179,7 +3181,7 @@ static void internal_malloc_stats(mstate m) {
break;\ break;\
}\ }\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, C);\
break;\ break;\
}\ }\
}\ }\
@ -3193,7 +3195,7 @@ static void internal_malloc_stats(mstate m) {
break;\ break;\
}\ }\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, F);\
break;\ break;\
}\ }\
}\ }\
@ -3228,13 +3230,13 @@ static void internal_malloc_stats(mstate m) {
tchunkptr F = X->fd;\ tchunkptr F = X->fd;\
R = X->bk;\ R = X->bk;\
if (__builtin_expect (F->bk != X || R->fd != X, 0))\ if (__builtin_expect (F->bk != X || R->fd != X, 0))\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, X);\
if (RTCHECK(ok_address(M, F))) {\ if (RTCHECK(ok_address(M, F))) {\
F->bk = R;\ F->bk = R;\
R->fd = F;\ R->fd = F;\
}\ }\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, F);\
}\ }\
}\ }\
else {\ else {\
@ -3249,7 +3251,7 @@ static void internal_malloc_stats(mstate m) {
if (RTCHECK(ok_address(M, RP)))\ if (RTCHECK(ok_address(M, RP)))\
*RP = 0;\ *RP = 0;\
else {\ else {\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, RP);\
}\ }\
}\ }\
}\ }\
@ -3266,7 +3268,7 @@ static void internal_malloc_stats(mstate m) {
XP->child[1] = R;\ XP->child[1] = R;\
}\ }\
else\ else\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, XP);\
if (R != 0) {\ if (R != 0) {\
if (RTCHECK(ok_address(M, R))) {\ if (RTCHECK(ok_address(M, R))) {\
tchunkptr C0, C1;\ tchunkptr C0, C1;\
@ -3277,7 +3279,7 @@ static void internal_malloc_stats(mstate m) {
C0->parent = R;\ C0->parent = R;\
}\ }\
else\ else\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, C0);\
}\ }\
if ((C1 = X->child[1]) != 0) {\ if ((C1 = X->child[1]) != 0) {\
if (RTCHECK(ok_address(M, C1))) {\ if (RTCHECK(ok_address(M, C1))) {\
@ -3285,11 +3287,11 @@ static void internal_malloc_stats(mstate m) {
C1->parent = R;\ C1->parent = R;\
}\ }\
else\ else\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, C1);\
}\ }\
}\ }\
else\ else\
CORRUPTION_ERROR_ACTION(M);\ CORRUPTION_ERROR_ACTION(M, R);\
}\ }\
}\ }\
} }
@ -3940,7 +3942,7 @@ static void* tmalloc_large(mstate m, size_t nb) {
return chunk2mem(v); return chunk2mem(v);
} }
} }
CORRUPTION_ERROR_ACTION(m); CORRUPTION_ERROR_ACTION(m, v);
} }
return 0; return 0;
} }
@ -3980,7 +3982,7 @@ static void* tmalloc_small(mstate m, size_t nb) {
} }
} }
CORRUPTION_ERROR_ACTION(m); CORRUPTION_ERROR_ACTION(m, v);
return 0; return 0;
} }