4 #ifndef INCLUDE_HEAP_JEMALLOC_STD_C
5 #define INCLUDE_HEAP_JEMALLOC_STD_C
20 #define GHT_MAX UT32_MAX
25 #define GHT_MAX UT64_MAX
30 static GHT GH(je_get_va_symbol)(
RzCore *core,
const char *
path,
const char *sym_name) {
39 opt.obj_opts.elf_load_sections =
rz_config_get_b(core->config,
"elf.load.sections");
40 opt.obj_opts.elf_checks_sections =
rz_config_get_b(core->config,
"elf.checks.sections");
41 opt.obj_opts.elf_checks_segments =
rz_config_get_b(core->config,
"elf.checks.segments");
49 rz_list_foreach (syms,
iter,
s) {
50 if (!strcmp(
s->name, sym_name)) {
61 static int GH(je_matched)(
const char *ptr,
const char *
str) {
62 int ret = strncmp(ptr,
str, strlen(
str) - 1);
70 const char *jemalloc_ver_end =
NULL;
73 if (!core || !core->dbg || !core->dbg->maps) {
77 rz_list_foreach (core->dbg->maps,
iter,
map) {
78 if (strstr(
map->name,
"libjemalloc.")) {
79 jemalloc_addr =
map->addr;
80 jemalloc_ver_end =
map->name;
84 if (!jemalloc_ver_end) {
85 RZ_LOG_WARN(
"Is jemalloc mapped in memory? (see dm command)\n");
89 bool is_debug_file =
GH(je_matched)(jemalloc_ver_end,
"/usr/local/lib");
92 RZ_LOG_WARN(
"Is libjemalloc.so.2 in /usr/local/lib path?\n");
97 ut64 vaddr =
GH(je_get_va_symbol)(core,
path, symname);
98 if (jemalloc_addr !=
GHT_MAX && vaddr != 0) {
99 *symbol = jemalloc_addr + vaddr;
108 RZ_LOG_INFO(
"Resolving %s from libjemalloc.2... ", symname);
155 while (node && node->en_addr !=
head->en_addr) {
162 rz_io_read_at(core->io, (
ut64)(
size_t)node->ql_link.qre_next, (
ut8 *)node,
sizeof(extent_node_t));
176 extent_node_t *node =
RZ_NEW0(extent_node_t);
179 if (!node || !
head) {
197 if (
head->en_addr != 0) {
206 while (node &&
head && node->en_addr !=
head->en_addr) {
213 rz_io_read_at(core->io, (
GHT)(
size_t)node->ql_link.qre_next, (
ut8 *)node,
sizeof(extent_node_t));
234 arena_stats_t *stats =
RZ_NEW0(arena_stats_t);
265 for (
i = 0;
i < narenas;
i++) {
283 #define OO(x) (ut64)(arena + rz_offsetof(arena_t, x))
330 arena_bin_info_t *
b =
NULL;
361 for (j = 0; j < JM_NBINS; j++) {
363 (
ut8 *)
b,
sizeof(arena_bin_info_t));
405 static void GH(jemalloc_get_runs)(
RzCore *core,
const char *
input) {
411 arena_chunk_t *
c =
RZ_NEW0 (arena_chunk_t);
446 mapbits = *(
GHT *)&
c->map_bits;
451 arena_chunk_map_bits_t *dwords = (
void *)
calloc (
sizeof (arena_chunk_map_bits_t), npages);
455 arena_run_t *
r =
RZ_NEW0 (arena_run_t);
460 for (pageind =
map_bias; pageind < npages; pageind++) {
461 arena_chunk_map_bits_t mapelm = dwords[pageind-
map_bias];
462 if (mapelm.bits & CHUNK_MAP_ALLOCATED) {
466 arena_chunk_map_misc_t *
m =
RZ_NEW0 (arena_chunk_map_misc_t);
477 }
else if (mapelm.bits & CHUNK_MAP_LARGE) {
495 const char *help_msg[] = {
496 "Usage:",
"dmx",
" # Jemalloc heap parsing commands",
497 "dmxa",
"[arena_t]",
"show all arenas created, or print arena_t structure for given arena",
498 "dmxb",
"[arena_t]",
"show all bins created for given arena",
499 "dmxc",
"*|[arena_t]",
"show all chunks created in all arenas, or show all chunks created for a given arena_t instance",
501 "dmx?",
"",
"Show map heap help",
NULL
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
RZ_API void rz_bin_options_init(RzBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, bool patch_relocs)
RZ_API RzBinFile * rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt)
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
RZ_API RzCons * rz_cons_singleton(void)
RZ_API int rz_cons_printf(const char *format,...)
static static fork const void static count static fd const char const char static newpath const char static path const char path
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
size_t map(int syms, int left, int len)
RZ_API void Ht_() free(HtName_(Ht) *ht)
void * calloc(size_t number, size_t size)
static int GH() cmd_dbg_map_jemalloc(RzCore *core, const char *input)
static void GH() jemalloc_get_chunks(RzCore *core, const char *input)
static bool GH() rz_resolve_jemalloc(RzCore *core, char *symname, ut64 *symbol)
static void GH() jemalloc_print_narenas(RzCore *core, const char *input)
static void GH() jemalloc_get_bins(RzCore *core, const char *input)
static int run(int i, const char *arg)
RZ_API bool rz_file_exists(const char *str)
#define PRINTF_GA(fmt,...)
#define PRINTF_YA(fmt,...)
#define PRINTF_BA(fmt,...)
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
#define RZ_LOG_INFO(fmtstr,...)
#define RZ_LOG_WARN(fmtstr,...)
#define RZ_LOG_ERROR(fmtstr,...)
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_bool(int b)
#define rz_offsetof(type, member)
XX curplugin == o->plugin.
RzConsPrintablePalette pal
static void lock(volatile int *lk)
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)