mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 22:00:18 +00:00
Refactor DMH
This commit is contained in:
parent
fe2a919d49
commit
e4a370ba47
@ -7,7 +7,6 @@
|
||||
#define TN_KEY_LEN 32
|
||||
#define TN_KEY_FMT "%"PFMT64u
|
||||
|
||||
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
|
||||
#include "r_heap_glibc.h"
|
||||
#endif
|
||||
@ -27,8 +26,9 @@ static ut64 r_debug_get_baddr(RCore *r, const char *file) {
|
||||
char *abspath;
|
||||
RListIter *iter;
|
||||
RDebugMap *map;
|
||||
if (!r || !r->io || !r->io->desc)
|
||||
if (!r || !r->io || !r->io->desc) {
|
||||
return 0LL;
|
||||
}
|
||||
r_debug_attach (r->dbg, r->io->desc->fd);
|
||||
r_debug_map_sync (r->dbg);
|
||||
abspath = r_file_abspath (file);
|
||||
@ -830,8 +830,8 @@ beach:
|
||||
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
|
||||
|
||||
static int cmd_dbg_map_heap_glibc_32(RCore *core, const char *input);
|
||||
static int cmd_dbg_map_heap_glibc_64(RCore *core, const char *input);
|
||||
static int cmd_dbg_map_heap_glibc_32 (RCore *core, const char *input);
|
||||
static int cmd_dbg_map_heap_glibc_64 (RCore *core, const char *input);
|
||||
|
||||
static void get_hash_debug_file(const char *path, char *hash, int hash_len) {
|
||||
RListIter *iter;
|
||||
@ -1103,10 +1103,8 @@ static int cmd_debug_map(RCore *core, const char *input) {
|
||||
case 'h': // "dmh"
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
|
||||
if (SZ == 4) {
|
||||
#define GLIBC_BITS_32 1
|
||||
cmd_dbg_map_heap_glibc_32 (core, input + 1);
|
||||
} else {
|
||||
#define GLIBC_BITS_64 1
|
||||
cmd_dbg_map_heap_glibc_64 (core, input + 1);
|
||||
}
|
||||
#else
|
||||
@ -1117,11 +1115,8 @@ static int cmd_debug_map(RCore *core, const char *input) {
|
||||
return true;
|
||||
}
|
||||
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ && GLIBC_BITS_32 == 1
|
||||
#include "linux_heap_glibc_32.c"
|
||||
#endif
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__ && GLIBC_BITS_64 == 1
|
||||
#include "linux_heap_glibc_64.c"
|
||||
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
|
||||
#include "linux_heap_glibc.c"
|
||||
#endif
|
||||
|
||||
R_API void r_core_debug_rr(RCore *core, RReg *reg) {
|
||||
@ -1133,7 +1128,9 @@ R_API void r_core_debug_rr(RCore *core, RReg *reg) {
|
||||
r_debug_map_sync (core->dbg);
|
||||
r_list_foreach (list, iter, r) {
|
||||
char *rrstr;
|
||||
if (r->size != bits) continue;
|
||||
if (r->size != bits) {
|
||||
continue;
|
||||
}
|
||||
value = r_reg_get_value (core->dbg->reg, r);
|
||||
rrstr = r_core_anal_hasrefs (core, value);
|
||||
if (bits == 64) {
|
||||
|
1164
libr/core/linux_heap_glibc.c
Normal file
1164
libr/core/linux_heap_glibc.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -1,4 +1,3 @@
|
||||
|
||||
#ifndef R2_HEAP_GLIBC_H
|
||||
#define R2_HEAP_GLIBC_H
|
||||
|
||||
@ -20,18 +19,16 @@ R_LIB_VERSION_HEADER(r_heap_glibc);
|
||||
#define PRINT_BA(msg) PRINT_A (Color_BLUE, msg)
|
||||
#define PRINT_RA(msg) PRINT_A (Color_RED, msg)
|
||||
|
||||
|
||||
#define NBINS 128
|
||||
#define NSMALLBINS 64
|
||||
#define NFASTBINS 10
|
||||
#define BINMAPSHIFT 5
|
||||
#define SZ core->dbg->bits
|
||||
#define BITSPERMAP (1U << BINMAPSHIFT)
|
||||
#define BINMAPSIZE (NBINS / BITSPERMAP)
|
||||
#define SZ core->dbg->bits
|
||||
#define MAX(a,b) (((a)>(b))?(a):(b))
|
||||
#define MALLOC_ALIGNMENT MAX (2 * SZ, __alignof__ (long double))
|
||||
#define MALLOC_ALIGN_MASK (MALLOC_ALIGNMENT - 1)
|
||||
#define PFMT32x "x"
|
||||
#define NPAD -6
|
||||
|
||||
#define largebin_index_32(size) \
|
||||
@ -67,20 +64,20 @@ R_LIB_VERSION_HEADER(r_heap_glibc);
|
||||
*/
|
||||
|
||||
typedef struct r_malloc_chunk_64 {
|
||||
ut64 prev_size; /* Size of previous chunk (if free). */
|
||||
ut64 size; /* Size in bytes, including overhead. */
|
||||
ut64 prev_size; /* Size of previous chunk (if free). */
|
||||
ut64 size; /* Size in bytes, including overhead. */
|
||||
|
||||
ut64 fd; /* double links -- used only if free. */
|
||||
ut64 fd; /* double links -- used only if free. */
|
||||
ut64 bk;
|
||||
|
||||
/* Only used for large blocks: pointer to next larger size. */
|
||||
ut64 fd_nextsize; /* double links -- used only if free. */
|
||||
ut64 fd_nextsize; /* double links -- used only if free. */
|
||||
ut64 bk_nextsize;
|
||||
} RHeapChunk64;
|
||||
} RHeapChunk_64;
|
||||
|
||||
typedef struct r_malloc_chunk_32 {
|
||||
ut32 prev_size; /* Size of previous chunk (if free). */
|
||||
ut32 size; /* Size in bytes, including overhead. */
|
||||
ut32 prev_size; /* Size of previous chunk (if free). */
|
||||
ut32 size; /* Size in bytes, including overhead. */
|
||||
|
||||
ut32 fd; /* double links -- used only if free. */
|
||||
ut32 bk;
|
||||
@ -88,7 +85,7 @@ typedef struct r_malloc_chunk_32 {
|
||||
/* Only used for large blocks: pointer to next larger size. */
|
||||
ut32 fd_nextsize; /* double links -- used only if free. */
|
||||
ut32 bk_nextsize;
|
||||
} RHeapChunk32;
|
||||
} RHeapChunk_32;
|
||||
|
||||
/*
|
||||
typedef RHeapChunk64 *mfastbinptr64;
|
||||
@ -112,7 +109,7 @@ typedef struct r_malloc_state_32 {
|
||||
|
||||
ut32 system_mem; /* current allocated memory of current arena */
|
||||
ut32 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState32;
|
||||
} RHeap_MallocState_32;
|
||||
|
||||
typedef struct r_malloc_state_64 {
|
||||
int mutex; /* serialized access */
|
||||
@ -128,7 +125,7 @@ typedef struct r_malloc_state_64 {
|
||||
|
||||
ut64 system_mem; /* current allocated memory of current arena */
|
||||
ut64 max_system_mem; /* maximum system memory */
|
||||
} RHeap_MallocState64;
|
||||
} RHeap_MallocState_64;
|
||||
|
||||
typedef struct r_heap_info_32 {
|
||||
ut32 ar_ptr; /* Arena for this heap. */
|
||||
@ -140,7 +137,7 @@ typedef struct r_heap_info_32 {
|
||||
that sizeof (heap_info) + 2 * SZ is a multiple of
|
||||
MALLOC_ALIGNMENT. */
|
||||
/* char pad[NPAD * SZ & MALLOC_ALIGN_MASK]; */
|
||||
} RHeapInfo32;
|
||||
} RHeapInfo_32;
|
||||
|
||||
typedef struct r_heap_info_64 {
|
||||
ut64 ar_ptr; /* Arena for this heap. */
|
||||
@ -152,11 +149,10 @@ typedef struct r_heap_info_64 {
|
||||
that sizeof (heap_info) + 2 * SZ is a multiple of
|
||||
MALLOC_ALIGNMENT. */
|
||||
/* char pad[NPAD * SZ & MALLOC_ALIGN_MASK]; */
|
||||
} RHeapInfo64;
|
||||
} RHeapInfo_64;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user