Fix malloc debugging for LP64.
Change-Id: Idd0b239f5c66d45de315d556271a5d13b8eb907c
This commit is contained in:
parent
458076c3c7
commit
ef0696d46a
@ -85,11 +85,11 @@ struct hdr_t {
|
|||||||
uintptr_t freed_bt[MAX_BACKTRACE_DEPTH];
|
uintptr_t freed_bt[MAX_BACKTRACE_DEPTH];
|
||||||
int freed_bt_depth;
|
int freed_bt_depth;
|
||||||
size_t size;
|
size_t size;
|
||||||
char front_guard[FRONT_GUARD_LEN];
|
uint8_t front_guard[FRONT_GUARD_LEN];
|
||||||
} __attribute__((packed, aligned(MALLOC_ALIGNMENT)));
|
} __attribute__((packed, aligned(MALLOC_ALIGNMENT)));
|
||||||
|
|
||||||
struct ftr_t {
|
struct ftr_t {
|
||||||
char rear_guard[REAR_GUARD_LEN];
|
uint8_t rear_guard[REAR_GUARD_LEN];
|
||||||
} __attribute__((packed));
|
} __attribute__((packed));
|
||||||
|
|
||||||
static inline ftr_t* to_ftr(hdr_t* hdr) {
|
static inline ftr_t* to_ftr(hdr_t* hdr) {
|
||||||
@ -126,10 +126,10 @@ static inline void init_front_guard(hdr_t* hdr) {
|
|||||||
static inline bool is_front_guard_valid(hdr_t* hdr) {
|
static inline bool is_front_guard_valid(hdr_t* hdr) {
|
||||||
for (size_t i = 0; i < FRONT_GUARD_LEN; i++) {
|
for (size_t i = 0; i < FRONT_GUARD_LEN; i++) {
|
||||||
if (hdr->front_guard[i] != FRONT_GUARD) {
|
if (hdr->front_guard[i] != FRONT_GUARD) {
|
||||||
return 0;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 1;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void init_rear_guard(hdr_t* hdr) {
|
static inline void init_rear_guard(hdr_t* hdr) {
|
||||||
@ -207,13 +207,14 @@ static inline void poison(hdr_t* hdr) {
|
|||||||
memset(user(hdr), FREE_POISON, hdr->size);
|
memset(user(hdr), FREE_POISON, hdr->size);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int was_used_after_free(hdr_t* hdr) {
|
static bool was_used_after_free(hdr_t* hdr) {
|
||||||
unsigned i;
|
const uint8_t* data = reinterpret_cast<const uint8_t*>(user(hdr));
|
||||||
const char* data = reinterpret_cast<const char *>(user(hdr));
|
for (size_t i = 0; i < hdr->size; i++) {
|
||||||
for (i = 0; i < hdr->size; i++)
|
if (data[i] != FREE_POISON) {
|
||||||
if (data[i] != FREE_POISON)
|
return true;
|
||||||
return 1;
|
}
|
||||||
return 0;
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* returns 1 if valid, *safe == 1 if safe to dump stack */
|
/* returns 1 if valid, *safe == 1 if safe to dump stack */
|
||||||
|
@ -394,9 +394,9 @@ static inline void* mallocdesc_alloc_end(const MallocDesc* desc) {
|
|||||||
* code - Event code (one of the TRACE_DEV_XXX).
|
* code - Event code (one of the TRACE_DEV_XXX).
|
||||||
* val - Event's value parameter.
|
* val - Event's value parameter.
|
||||||
*/
|
*/
|
||||||
static inline void notify_qemu(uint32_t code, uint32_t val) {
|
static inline void notify_qemu(uint32_t code, uintptr_t val) {
|
||||||
if (NULL != qtrace) {
|
if (NULL != qtrace) {
|
||||||
*(volatile uint32_t*)((uint32_t)qtrace + ((code - 1024) << 2)) = val;
|
*(volatile uintptr_t*)((uintptr_t)qtrace + ((code - 1024) << 2)) = val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -407,7 +407,7 @@ static inline void notify_qemu(uint32_t code, uint32_t val) {
|
|||||||
*/
|
*/
|
||||||
static void notify_qemu_string(const char* str) {
|
static void notify_qemu_string(const char* str) {
|
||||||
if (str != NULL) {
|
if (str != NULL) {
|
||||||
notify_qemu(TRACE_DEV_REG_PRINT_USER_STR, (uint32_t)str);
|
notify_qemu(TRACE_DEV_REG_PRINT_USER_STR, reinterpret_cast<uintptr_t>(str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,7 +432,7 @@ static inline int notify_qemu_malloc(volatile MallocDesc* desc) {
|
|||||||
desc->libc_pid = malloc_pid;
|
desc->libc_pid = malloc_pid;
|
||||||
desc->allocator_pid = getpid();
|
desc->allocator_pid = getpid();
|
||||||
desc->av_count = 0;
|
desc->av_count = 0;
|
||||||
notify_qemu(TRACE_DEV_REG_MALLOC, (uint32_t)desc);
|
notify_qemu(TRACE_DEV_REG_MALLOC, reinterpret_cast<uintptr_t>(desc));
|
||||||
|
|
||||||
/* Emulator reports failure by zeroing libc_pid field of the
|
/* Emulator reports failure by zeroing libc_pid field of the
|
||||||
* descriptor. */
|
* descriptor. */
|
||||||
@ -451,7 +451,7 @@ static inline int notify_qemu_free(void* ptr_to_free) {
|
|||||||
free_desc.ptr = ptr_to_free;
|
free_desc.ptr = ptr_to_free;
|
||||||
free_desc.libc_pid = malloc_pid;
|
free_desc.libc_pid = malloc_pid;
|
||||||
free_desc.free_pid = getpid();
|
free_desc.free_pid = getpid();
|
||||||
notify_qemu(TRACE_DEV_REG_FREE_PTR, (uint32_t)&free_desc);
|
notify_qemu(TRACE_DEV_REG_FREE_PTR, reinterpret_cast<uintptr_t>(&free_desc));
|
||||||
|
|
||||||
/* Emulator reports failure by zeroing libc_pid field of the
|
/* Emulator reports failure by zeroing libc_pid field of the
|
||||||
* descriptor. */
|
* descriptor. */
|
||||||
@ -477,7 +477,7 @@ static inline int query_qemu_malloc_info(const void* ptr, MallocDesc* desc, uint
|
|||||||
query.query_pid = getpid();
|
query.query_pid = getpid();
|
||||||
query.routine = routine;
|
query.routine = routine;
|
||||||
query.desc = desc;
|
query.desc = desc;
|
||||||
notify_qemu(TRACE_DEV_REG_QUERY_MALLOC, (uint32_t)&query);
|
notify_qemu(TRACE_DEV_REG_QUERY_MALLOC, reinterpret_cast<uintptr_t>(&query));
|
||||||
|
|
||||||
/* Emulator reports failure by zeroing libc_pid field of the
|
/* Emulator reports failure by zeroing libc_pid field of the
|
||||||
* descriptor. */
|
* descriptor. */
|
||||||
@ -534,9 +534,9 @@ static void qemu_log(int prio, const char* fmt, ...) {
|
|||||||
static void dump_malloc_descriptor(char* str, size_t str_buf_size, const MallocDesc* desc) {
|
static void dump_malloc_descriptor(char* str, size_t str_buf_size, const MallocDesc* desc) {
|
||||||
if (str_buf_size) {
|
if (str_buf_size) {
|
||||||
snprintf(str, str_buf_size,
|
snprintf(str, str_buf_size,
|
||||||
"MDesc: %p: %X <-> %X [%u + %u + %u] by pid=%03u in libc_pid=%03u",
|
"MDesc: %p: %p <-> %p [%u + %u + %u] by pid=%03u in libc_pid=%03u",
|
||||||
mallocdesc_user_ptr(desc), (uint32_t)desc->ptr,
|
mallocdesc_user_ptr(desc), desc->ptr,
|
||||||
(uint32_t)mallocdesc_alloc_end(desc), desc->prefix_size,
|
mallocdesc_alloc_end(desc), desc->prefix_size,
|
||||||
desc->requested_bytes, desc->suffix_size, desc->allocator_pid,
|
desc->requested_bytes, desc->suffix_size, desc->allocator_pid,
|
||||||
desc->libc_pid);
|
desc->libc_pid);
|
||||||
str[str_buf_size - 1] = '\0';
|
str[str_buf_size - 1] = '\0';
|
||||||
|
Loading…
Reference in New Issue
Block a user