Skip to content

Commit

Permalink
Made Heap API naming more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
MalhotraPulak committed Jun 16, 2021
1 parent f46afbc commit 24a0ed2
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 54 deletions.
80 changes: 40 additions & 40 deletions librz/core/linux_heap_glibc.c
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ static void GH(update_arena_without_tc)(GH(RzHeap_MallocState) * cmain_arena, Ma
* \param main_arena The MallocState struct in which the data is stored
* \return True if the main_arena struct was successfully updated else False
*/
RZ_API bool GH(rz_update_main_arena)(RzCore *core, GHT m_arena, MallocState *main_arena) {
RZ_API bool GH(rz_heap_update_main_arena)(RzCore *core, GHT m_arena, MallocState *main_arena) {
const int tcache = rz_config_get_i(core->config, "dbg.glibc.tcache");
if (tcache) {
GH(RzHeap_MallocState_tcache) *cmain_arena = RZ_NEW0(GH(RzHeap_MallocState_tcache));
Expand Down Expand Up @@ -404,7 +404,7 @@ static void GH(print_arena_stats)(RzCore *core, GHT m_arena, MallocState *main_a
* \param m_arena Store the location of main arena at this integer pointer
* \return True if a main arena was found else False
*/
RZ_API bool GH(rz_resolve_main_arena)(RzCore *core, GHT *m_arena) {
RZ_API bool GH(rz_heap_resolve_main_arena)(RzCore *core, GHT *m_arena) {
rz_return_val_if_fail(core && core->dbg && core->dbg->maps, false);

GHT brk_start = GHT_MAX, brk_end = GHT_MAX;
Expand Down Expand Up @@ -468,15 +468,15 @@ RZ_API bool GH(rz_resolve_main_arena)(RzCore *core, GHT *m_arena) {
}

if (main_arena_sym != GHT_MAX) {
GH(rz_update_main_arena)
GH(rz_heap_update_main_arena)
(core, main_arena_sym, ta);
*m_arena = main_arena_sym;
core->dbg->main_arena_resolved = true;
free(ta);
return true;
}
while (addr_srch < libc_addr_end) {
GH(rz_update_main_arena)
GH(rz_heap_update_main_arena)
(core, addr_srch, ta);
if (ta->GH(top) > brk_start && ta->GH(top) < brk_end &&
ta->GH(system_mem) == heap_sz) {
Expand Down Expand Up @@ -554,7 +554,7 @@ void GH(print_heap_chunk)(RzCore *core, GHT chunk) {
* \param addr Base address of the chunk
* \return RzHeapChunk struct pointer of the chunk
*/
RZ_API GH(RzHeapChunk) * GH(rz_get_heap_chunk_at_addr)(RzCore *core, GHT addr) {
RZ_API GH(RzHeapChunk) * GH(rz_heap_get_chunk_at_addr)(RzCore *core, GHT addr) {
GH(RzHeapChunk) *cnk = RZ_NEW0(GH(RzHeapChunk));
if (!cnk) {
return NULL;
Expand All @@ -569,7 +569,7 @@ RZ_API GH(RzHeapChunk) * GH(rz_get_heap_chunk_at_addr)(RzCore *core, GHT addr) {
* \param chunk Offset of the chunk in memory
*/
void GH(print_heap_chunk_simple)(RzCore *core, GHT chunk, const char *status, PJ *pj) {
GH(RzHeapChunk) *cnk = GH(rz_get_heap_chunk_at_addr)(core, chunk);
GH(RzHeapChunk) *cnk = GH(rz_heap_get_chunk_at_addr)(core, chunk);
if (!cnk) {
return;
}
Expand Down Expand Up @@ -634,7 +634,7 @@ static bool GH(is_arena)(RzCore *core, GHT m_arena, GHT m_state) {
if (!ta) {
return false;
}
if (!GH(rz_update_main_arena)(core, m_arena, ta)) {
if (!GH(rz_heap_update_main_arena)(core, m_arena, ta)) {
free(ta);
return false;
}
Expand All @@ -643,7 +643,7 @@ static bool GH(is_arena)(RzCore *core, GHT m_arena, GHT m_state) {
return true;
}
while (ta->GH(next) != GHT_MAX && ta->GH(next) != m_arena) {
if (!GH(rz_update_main_arena)(core, ta->GH(next), ta)) {
if (!GH(rz_heap_update_main_arena)(core, ta->GH(next), ta)) {
free(ta);
return false;
}
Expand Down Expand Up @@ -862,7 +862,7 @@ static int GH(print_single_linked_list_bin)(RzCore *core, MallocState *main_aren
return 0;
}

if (!GH(rz_update_main_arena)(core, m_arena, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_arena, main_arena)) {
free(cnk);
return 0;
}
Expand Down Expand Up @@ -1106,7 +1106,7 @@ static void GH(tcache_print)(RzCore *core, GH(RTcache) * tcache, PJ *pj) {
* \param main_thread_only Only get tcache information for main thread
* \return RzList of RzTcache objects
*/
RZ_API RzList *GH(rz_get_tcache_list)(RzCore *core, GHT m_arena, MallocState *main_arena, bool main_thread_only) {
RZ_API RzList *GH(rz_heap_tcache_list)(RzCore *core, GHT m_arena, MallocState *main_arena, bool main_thread_only) {
RzList *tcache_list = rz_list_newf((RzListFree)GH(tcache_free));
rz_return_val_if_fail(core && core->dbg && core->dbg->maps, tcache_list);

Expand Down Expand Up @@ -1152,7 +1152,7 @@ RZ_API RzList *GH(rz_get_tcache_list)(RzCore *core, GHT m_arena, MallocState *ma
mmap_start = ((ta->GH(next) >> 16) << 16);
tcache_start = mmap_start + sizeof(GH(RzHeapInfo)) + sizeof(GH(RzHeap_MallocState_tcache)) + GH(MMAP_ALIGN);

if (!GH(rz_update_main_arena)(core, ta->GH(next), ta)) {
if (!GH(rz_heap_update_main_arena)(core, ta->GH(next), ta)) {
free(ta);
GH(tcache_free)
(rz_tcache);
Expand All @@ -1173,12 +1173,12 @@ RZ_API RzList *GH(rz_get_tcache_list)(RzCore *core, GHT m_arena, MallocState *ma
static void GH(print_tcache_instance)(RzCore *core, GHT m_arena, MallocState *main_arena, bool main_thread_only, PJ *pj) {
rz_return_if_fail(core && core->dbg && core->dbg->maps);
RzConsPrintablePalette *pal = &rz_cons_singleton()->context->pal;
RzList *tcache_list = GH(rz_get_tcache_list)(core, m_arena, main_arena, main_thread_only);
RzList *tcache_list = GH(rz_heap_tcache_list)(core, m_arena, main_arena, main_thread_only);
if (rz_list_length(tcache_list) == 0) {
rz_list_free(tcache_list);
return;
}
RzList *arenas_list = GH(rz_get_arenas_list)(core, m_arena, main_arena);
RzList *arenas_list = GH(rz_heap_arenas_list)(core, m_arena, main_arena);
if (rz_list_length(tcache_list) > rz_list_length(arenas_list)) {
rz_list_free(tcache_list);
rz_list_free(arenas_list);
Expand Down Expand Up @@ -1248,7 +1248,7 @@ void GH(print_malloc_states)(RzCore *core, GHT m_arena, MallocState *main_arena,
ta->GH(next) = main_arena->GH(next);
while (GH(is_arena)(core, m_arena, ta->GH(next)) && ta->GH(next) != m_arena) {
ut64 ta_addr = ta->GH(next);
if (!GH(rz_update_main_arena)(core, ta->GH(next), ta)) {
if (!GH(rz_heap_update_main_arena)(core, ta->GH(next), ta)) {
free(ta);
return;
}
Expand Down Expand Up @@ -1330,7 +1330,7 @@ void GH(print_malloc_info)(RzCore *core, GHT m_state, GHT malloc_state) {
}

while (heap_info->prev != 0x0 && heap_info->prev != GHT_MAX) {
if (!GH(rz_update_main_arena)(core, malloc_state, ms)) {
if (!GH(rz_heap_update_main_arena)(core, malloc_state, ms)) {
free(ms);
free(heap_info);
return;
Expand All @@ -1356,7 +1356,7 @@ void GH(print_malloc_info)(RzCore *core, GHT m_state, GHT malloc_state) {
* \param bin_num bin number of bin whose chunk list you want
* \return RzList of RzHeapChunkListItem for the bin
*/
RZ_API RzList *GH(rz_get_bin_content_list)(RzCore *core, MallocState *main_arena, int bin_num) {
RZ_API RzList *GH(rz_heap_bin_content_list)(RzCore *core, MallocState *main_arena, int bin_num) {
int idx = 2 * bin_num;
ut64 fw = main_arena->GH(bins)[idx];
ut64 bk = main_arena->GH(bins)[idx + 1];
Expand Down Expand Up @@ -1416,7 +1416,7 @@ static int GH(print_bin_content)(RzCore *core, MallocState *main_arena, int bin_
ut64 bk = main_arena->GH(bins)[idx + 1];
RzListIter *iter;
RzHeapChunkListItem *pos;
RzList *chunks = GH(rz_get_bin_content_list)(core, main_arena, bin_num);
RzList *chunks = GH(rz_heap_bin_content_list)(core, main_arena, bin_num);
if (rz_list_length(chunks) == 0) {
rz_list_free(chunks);
return 0;
Expand Down Expand Up @@ -1616,22 +1616,22 @@ static void GH(print_main_arena_bins)(RzCore *core, GHT m_arena, MallocState *ma
* \param main_arena MallocState struct of main arena
* \return RzList pointer for list of MallocState structs of all the arenas
*/
RZ_API RzList *GH(rz_get_arenas_list)(RzCore *core, GHT m_arena, MallocState *main_arena) {
RZ_API RzList *GH(rz_heap_arenas_list)(RzCore *core, GHT m_arena, MallocState *main_arena) {
RzList *arena_list = rz_list_newf(free);
MallocState *ta = RZ_NEW0(MallocState);
if (!ta) {
return arena_list;
}
// main arena
GH(rz_update_main_arena)
GH(rz_heap_update_main_arena)
(core, m_arena, ta);
rz_list_append(arena_list, ta);
if (main_arena->GH(next) != m_arena) {
ta->GH(next) = main_arena->GH(next);
while (GH(is_arena)(core, m_arena, ta->GH(next)) && ta->GH(next) != m_arena) {
ut64 ta_addr = ta->GH(next);
ta = RZ_NEW0(MallocState);
if (!GH(rz_update_main_arena)(core, ta_addr, ta)) {
if (!GH(rz_heap_update_main_arena)(core, ta_addr, ta)) {
return arena_list;
}
// thread arenas
Expand All @@ -1650,7 +1650,7 @@ RZ_API RzList *GH(rz_get_arenas_list)(RzCore *core, GHT m_arena, MallocState *ma
* \param global_max_fast Max size of fastbin
* \return RzList pointer for list of all chunks in a given arena
*/
RZ_API RzList *GH(rz_get_heap_chunks_list)(RzCore *core, MallocState *main_arena,
RZ_API RzList *GH(rz_heap_chunks_list)(RzCore *core, MallocState *main_arena,
GHT m_arena, GHT m_state) {
RzList *chunks = rz_list_newf(free);
if (!core || !core->dbg || !core->dbg->maps) {
Expand Down Expand Up @@ -1854,15 +1854,15 @@ RZ_IPI RzCmdStatus GH(rz_cmd_arena_print_handler)(RzCore *core, int argc, const
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_arena, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_arena, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
RzList *arenas_list = GH(rz_get_arenas_list)(core, m_arena, main_arena);
RzList *arenas_list = GH(rz_heap_arenas_list)(core, m_arena, main_arena);
RzListIter *iter, *iter2;
MallocState *pos;
ut64 addr;
Expand Down Expand Up @@ -1904,7 +1904,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_chunks_print_handler)(RzCore *core, int argc,
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -1918,7 +1918,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_chunks_print_handler)(RzCore *core, int argc,
PRINT_RA("This address is not a valid arena\n");
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -1931,7 +1931,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_chunks_print_handler)(RzCore *core, int argc,
brk_start = ((m_state >> 16) << 16);
brk_end = brk_start + main_arena->GH(system_mem);
}
RzList *chunks = GH(rz_get_heap_chunks_list)(core, main_arena, m_arena, m_state);
RzList *chunks = GH(rz_heap_chunks_list)(core, main_arena, m_arena, m_state);
RzListIter *iter;
RzHeapChunkListItem *pos;
PJ *pj = NULL;
Expand Down Expand Up @@ -2075,7 +2075,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_main_arena_print_handler)(RzCore *core, int argc, c
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2089,7 +2089,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_main_arena_print_handler)(RzCore *core, int argc, c
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2105,7 +2105,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_chunk_print_handler)(RzCore *core, int argc, c
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2123,7 +2123,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_info_print_handler)(RzCore *core, int argc, co
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2137,7 +2137,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_info_print_handler)(RzCore *core, int argc, co
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2153,11 +2153,11 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_tcache_print_handler)(RzCore *core, int argc,
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_arena, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_arena, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2172,7 +2172,7 @@ RZ_IPI int GH(rz_cmd_heap_bins_list_print)(RzCore *core, const char *input) {
GHT m_arena = GHT_MAX, m_state = GHT_MAX;
RzConsPrintablePalette *pal = &rz_cons_singleton()->context->pal;
MallocState *main_arena = RZ_NEW0(MallocState);
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2192,7 +2192,7 @@ RZ_IPI int GH(rz_cmd_heap_bins_list_print)(RzCore *core, const char *input) {
}
}
if (GH(is_arena)(core, m_arena, m_state)) {
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(main_arena);
free(dup);
return RZ_CMD_STATUS_ERROR;
Expand All @@ -2216,7 +2216,7 @@ RZ_IPI int GH(rz_cmd_heap_fastbins_print)(void *data, const char *input) {
RzConsPrintablePalette *pal = &rz_cons_singleton()->context->pal;
MallocState *main_arena = RZ_NEW0(MallocState);
GHT global_max_fast = (64 * SZ / 4);
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2237,7 +2237,7 @@ RZ_IPI int GH(rz_cmd_heap_fastbins_print)(void *data, const char *input) {
}
}
if (GH(is_arena)(core, m_arena, m_state)) {
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(dup);
free(main_arena);
return RZ_CMD_STATUS_ERROR;
Expand All @@ -2263,7 +2263,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_arena_bins_print_handler)(RzCore *core, int ar
if (!main_arena) {
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_resolve_main_arena)(core, &m_arena)) {
if (!GH(rz_heap_resolve_main_arena)(core, &m_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand All @@ -2277,7 +2277,7 @@ RZ_IPI RzCmdStatus GH(rz_cmd_heap_arena_bins_print_handler)(RzCore *core, int ar
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
if (!GH(rz_update_main_arena)(core, m_state, main_arena)) {
if (!GH(rz_heap_update_main_arena)(core, m_state, main_arena)) {
free(main_arena);
return RZ_CMD_STATUS_ERROR;
}
Expand Down
28 changes: 14 additions & 14 deletions librz/include/rz_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -775,20 +775,20 @@ RZ_API void rz_core_sysenv_end(RzCore *core, const char *cmd);
RZ_API void rz_core_recover_vars(RzCore *core, RzAnalysisFunction *fcn, bool argonly);

/* linux_heap_glibc.c */
RZ_API RzHeapChunk_64 *rz_get_heap_chunk_at_addr_64(RzCore *core, ut64 addr);
RZ_API RzList *rz_get_bin_content_list_64(RzCore *core, MallocState *main_arena, int bin_num);
RZ_API RzList *rz_get_arenas_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
RZ_API RzList *rz_get_heap_chunks_list_64(RzCore *core, MallocState *main_arena, ut64 m_arena, ut64 m_state);
RZ_API bool rz_resolve_main_arena_64(RzCore *core, ut64 *m_arena);
RZ_API bool rz_update_main_arena_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
RZ_API RzList *rz_get_tcache_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena, bool main_thread_only);
RZ_API RzHeapChunk_32 *rz_get_heap_chunk_at_addr_32(RzCore *core, ut32 addr);
RZ_API RzList *rz_get_bin_content_list_32(RzCore *core, MallocState *main_arena, int bin_num);
RZ_API RzList *rz_get_arenas_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
RZ_API RzList *rz_get_heap_chunks_list_32(RzCore *core, MallocState *main_arena, ut32 m_arena, ut32 m_state);
RZ_API bool rz_resolve_main_arena_32(RzCore *core, ut32 *m_arena);
RZ_API bool rz_update_main_arena_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
RZ_API RzList *rz_get_tcache_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena, bool main_thread_only);
RZ_API RzHeapChunk_64 *rz_heap_get_chunk_at_addr_64(RzCore *core, ut64 addr);
RZ_API RzList *rz_heap_bin_content_list_64(RzCore *core, MallocState *main_arena, int bin_num);
RZ_API RzList *rz_heap_arenas_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
RZ_API RzList *rz_heap_chunks_list_64(RzCore *core, MallocState *main_arena, ut64 m_arena, ut64 m_state);
RZ_API bool rz_heap_resolve_main_arena_64(RzCore *core, ut64 *m_arena);
RZ_API bool rz_heap_update_main_arena_64(RzCore *core, ut64 m_arena, MallocState *main_arena);
RZ_API RzList *rz_heap_tcache_list_64(RzCore *core, ut64 m_arena, MallocState *main_arena, bool main_thread_only);
RZ_API RzHeapChunk_32 *rz_heap_get_chunk_at_addr_32(RzCore *core, ut32 addr);
RZ_API RzList *rz_heap_bin_content_list_32(RzCore *core, MallocState *main_arena, int bin_num);
RZ_API RzList *rz_heap_arenas_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
RZ_API RzList *rz_heap_heap_chunks_list_32(RzCore *core, MallocState *main_arena, ut32 m_arena, ut32 m_state);
RZ_API bool rz_heap_resolve_main_arena_32(RzCore *core, ut32 *m_arena);
RZ_API bool rz_heap_update_main_arena_32(RzCore *core, ut32 m_arena, MallocState *main_arena);
RZ_API RzList *rz_heap_tcache_list_32(RzCore *core, ut32 m_arena, MallocState *main_arena, bool main_thread_only);
// XXX dupe from rz_bin.h
/* bin.c */
#define RZ_CORE_BIN_ACC_STRINGS 0x001
Expand Down

0 comments on commit 24a0ed2

Please sign in to comment.