Rizin
unix-like reverse engineering framework and cli tools
linux_heap_jemalloc.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017 javierptd <javierptd@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef INCLUDE_HEAP_JEMALLOC_STD_C
5 #define INCLUDE_HEAP_JEMALLOC_STD_C
6 #define HEAP32 1
7 #include "linux_heap_jemalloc.c"
8 #undef HEAP32
9 #endif
10 
11 #undef GH
12 #undef GHT
13 #undef GHT_MAX
14 #undef PFMTx
15 
16 // FIXME: It should be detected at runtime, not during the compilation stage
17 #if HEAP32
18 #define GH(x) x##_32
19 #define GHT ut32
20 #define GHT_MAX UT32_MAX
21 #define PFMTx PFMT32x
22 #else
23 #define GH(x) x##_64
24 #define GHT ut64
25 #define GHT_MAX UT64_MAX
26 #define PFMTx PFMT64x
27 #endif
28 
29 #if __linux__
30 static GHT GH(je_get_va_symbol)(RzCore *core, const char *path, const char *sym_name) {
31  GHT vaddr = GHT_MAX;
32  RzBin *bin = core->bin;
33  RzBinFile *current_bf = rz_bin_cur(bin);
35  RzBinSymbol *s;
36 
37  RzBinOptions opt;
38  rz_bin_options_init(&opt, -1, 0, 0, false);
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");
42 
43  RzBinFile *libc_bf = rz_bin_open(bin, path, &opt);
44  if (!libc_bf) {
45  return vaddr;
46  }
47 
48  RzList *syms = rz_bin_get_symbols(bin);
49  rz_list_foreach (syms, iter, s) {
50  if (!strcmp(s->name, sym_name)) {
51  vaddr = s->vaddr;
52  break;
53  }
54  }
55 
56  rz_bin_file_delete(bin, libc_bf);
57  rz_bin_file_set_cur_binfile(bin, current_bf);
58  return vaddr;
59 }
60 
61 static int GH(je_matched)(const char *ptr, const char *str) {
62  int ret = strncmp(ptr, str, strlen(str) - 1);
63  return !ret;
64 }
65 #endif
66 
67 static bool GH(rz_resolve_jemalloc)(RzCore *core, char *symname, ut64 *symbol) {
69  RzDebugMap *map;
70  const char *jemalloc_ver_end = NULL;
71  ut64 jemalloc_addr = UT64_MAX;
72 
73  if (!core || !core->dbg || !core->dbg->maps) {
74  return false;
75  }
76  rz_debug_map_sync(core->dbg);
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;
81  break;
82  }
83  }
84  if (!jemalloc_ver_end) {
85  RZ_LOG_WARN("Is jemalloc mapped in memory? (see dm command)\n");
86  return false;
87  }
88 #if __linux__
89  bool is_debug_file = GH(je_matched)(jemalloc_ver_end, "/usr/local/lib");
90 
91  if (!is_debug_file) {
92  RZ_LOG_WARN("Is libjemalloc.so.2 in /usr/local/lib path?\n");
93  return false;
94  }
95  char *path = rz_str_newf("%s", jemalloc_ver_end);
96  if (rz_file_exists(path)) {
97  ut64 vaddr = GH(je_get_va_symbol)(core, path, symname);
98  if (jemalloc_addr != GHT_MAX && vaddr != 0) {
99  *symbol = jemalloc_addr + vaddr;
100  free(path);
101  return true;
102  }
103  }
104  free(path);
105  return false;
106 #else
107  (void)jemalloc_addr;
108  RZ_LOG_INFO("Resolving %s from libjemalloc.2... ", symname);
109  // this is quite sloooow, we must optimize dmi
110  char *va = rz_core_cmd_strf(core, "dmi libjemalloc.2 %s$~[1]", symname);
111  ut64 n = rz_num_get(NULL, va);
112  if (n && n != UT64_MAX) {
113  *symbol = n;
114  rz_cons_printf("0x%08" PFMT64x "\n", n);
115  } else {
116  rz_cons_printf("NOT FOUND\n");
117  }
118  free(va);
119  return true;
120 #endif
121 }
122 
123 static void GH(jemalloc_get_chunks)(RzCore *core, const char *input) {
124  ut64 cnksz;
126 
127  if (!GH(rz_resolve_jemalloc)(core, "je_chunksize", &cnksz)) {
128  RZ_LOG_ERROR("Fail at reading symbol je_chunksize\n");
129  return;
130  }
131  rz_io_read_at(core->io, cnksz, (ut8 *)&cnksz, sizeof(GHT));
132 
133  switch (input[0]) {
134  case '\0':
135  RZ_LOG_ERROR("need an arena_t to associate chunks");
136  break;
137  case ' ': {
138  GHT arena = GHT_MAX;
139  arena_t *ar = RZ_NEW0(arena_t);
140  extent_node_t *node = RZ_NEW0(extent_node_t), *head = RZ_NEW0(extent_node_t);
141  input += 1;
142  arena = rz_num_math(core->num, input);
143 
144  if (arena) {
145  rz_io_read_at(core->io, arena, (ut8 *)ar, sizeof(arena_t));
146  rz_io_read_at(core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof(extent_node_t));
147  if (head->en_addr) {
148  PRINT_YA(" Chunk - start: ");
149  PRINTF_BA("0x%08" PFMT64x, (ut64)(size_t)head->en_addr);
150  PRINT_YA(", end: ");
151  PRINTF_BA("0x%08" PFMT64x, (ut64)(size_t)((char *)head->en_addr + cnksz));
152  PRINT_YA(", size: ");
153  PRINTF_BA("0x%08" PFMT64x "\n", (ut64)cnksz);
154  rz_io_read_at(core->io, (ut64)(size_t)head->ql_link.qre_next, (ut8 *)node, sizeof(extent_node_t));
155  while (node && node->en_addr != head->en_addr) {
156  PRINT_YA(" Chunk - start: ");
157  PRINTF_BA("0x%08" PFMT64x, (ut64)(size_t)node->en_addr);
158  PRINT_YA(", end: ");
159  PRINTF_BA("0x%" PFMT64x, (ut64)(size_t)((char *)node->en_addr + cnksz));
160  PRINT_YA(", size: ");
161  PRINTF_BA("0x%08" PFMT64x "\n", cnksz);
162  rz_io_read_at(core->io, (ut64)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof(extent_node_t));
163  }
164  }
165  }
166  free(ar);
167  free(head);
168  free(node);
169  break;
170  }
171  case '*': {
172  int i = 0;
173  ut64 sym;
174  GHT arenas = GHT_MAX, arena = GHT_MAX;
175  arena_t *ar = RZ_NEW0(arena_t);
176  extent_node_t *node = RZ_NEW0(extent_node_t);
177  extent_node_t *head = RZ_NEW0(extent_node_t);
178 
179  if (!node || !head) {
180  RZ_LOG_ERROR("Failed to allocate extent_node_t\n");
181  free(ar);
182  free(node);
183  free(head);
184  return;
185  }
186 
187  if (GH(rz_resolve_jemalloc)(core, "je_arenas", &sym)) {
188  rz_io_read_at(core->io, sym, (ut8 *)&arenas, sizeof(GHT));
189  for (;;) {
190  rz_io_read_at(core->io, arenas + i * sizeof(GHT), (ut8 *)&arena, sizeof(GHT));
191  if (!arena) {
192  break;
193  }
194  PRINTF_GA("arenas[%d]: @ 0x%" PFMTx " { \n", i++, (GHT)arena);
195  rz_io_read_at(core->io, arena, (ut8 *)ar, sizeof(arena_t));
196  rz_io_read_at(core->io, (GHT)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof(extent_node_t));
197  if (head->en_addr != 0) {
198  PRINT_YA(" Chunk - start: ");
199  PRINTF_BA("0x%08" PFMT64x, (ut64)(size_t)head->en_addr);
200  PRINT_YA(", end: ");
201  PRINTF_BA("0x%" PFMT64x, (ut64)(size_t)((char *)head->en_addr + cnksz));
202  PRINT_YA(", size: ");
203  PRINTF_BA("0x%08" PFMT64x "\n", (ut64)cnksz);
204  ut64 addr = (ut64)(size_t)head->ql_link.qre_next;
205  rz_io_read_at(core->io, addr, (ut8 *)node, sizeof(extent_node_t));
206  while (node && head && node->en_addr != head->en_addr) {
207  PRINT_YA(" Chunk - start: ");
208  PRINTF_BA("0x%08" PFMT64x, (ut64)(size_t)node->en_addr);
209  PRINT_YA(", end: ");
210  PRINTF_BA("0x%" PFMT64x, (ut64)(size_t)((char *)node->en_addr + cnksz));
211  PRINT_YA(", size: ");
212  PRINTF_BA("0x%" PFMT64x "\n", cnksz);
213  rz_io_read_at(core->io, (GHT)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof(extent_node_t));
214  }
215  }
216  PRINT_GA("}\n");
217  }
218  }
219  free(ar);
220  free(head);
221  free(node);
222  } break;
223  }
224 }
225 
226 static void GH(jemalloc_print_narenas)(RzCore *core, const char *input) {
227  ut64 symaddr;
228  ut64 arenas;
229  GHT arena = GHT_MAX;
230  arena_t *ar = RZ_NEW0(arena_t);
231  if (!ar) {
232  return;
233  }
234  arena_stats_t *stats = RZ_NEW0(arena_stats_t);
235  if (!stats) {
236  free(ar);
237  return;
238  }
239  int i = 0;
240  GHT narenas = 0;
242 
243  switch (input[0]) {
244  case '\0':
245  if (GH(rz_resolve_jemalloc)(core, "narenas_total", &symaddr)) {
246  rz_io_read_at(core->io, symaddr, (ut8 *)&narenas, sizeof(GHT));
247  PRINTF_GA("narenas : %" PFMT64d "\n", (ut64)narenas);
248  }
249  if (narenas == 0) {
250  RZ_LOG_ERROR("No arenas allocated.\n");
251  free(stats);
252  free(ar);
253  return;
254  }
255  if (narenas == GHT_MAX) {
256  RZ_LOG_ERROR("Cannot find narenas_total\n");
257  free(stats);
258  free(ar);
259  return;
260  }
261 
262  if (GH(rz_resolve_jemalloc)(core, "je_arenas", &arenas)) {
263  rz_io_read_at(core->io, arenas, (ut8 *)&arenas, sizeof(GHT));
264  PRINTF_GA("arenas[%" PFMT64d "] @ 0x%" PFMT64x " {\n", (ut64)narenas, (ut64)arenas);
265  for (i = 0; i < narenas; i++) {
266  ut64 at = arenas + (i * sizeof(GHT));
267  rz_io_read_at(core->io, at, (ut8 *)&arena, sizeof(GHT));
268  if (!arena) {
269  PRINTF_YA(" arenas[%d]: (empty)\n", i);
270  continue;
271  }
272  PRINTF_YA(" arenas[%d]: ", i);
273  PRINTF_BA("@ 0x%" PFMT64x "\n", at);
274  }
275  }
276  PRINT_GA("}\n");
277  break;
278  case ' ':
279  arena = rz_num_math(core->num, input + 1);
280  rz_io_read_at(core->io, (GHT)arena, (ut8 *)ar, sizeof(arena_t));
281 
282  PRINT_GA("struct arena_s {\n");
283 #define OO(x) (ut64)(arena + rz_offsetof(arena_t, x))
284  PRINTF_BA(" ind = 0x%x\n", ar->ind);
285  PRINTF_BA(" nthreads: application allocation = 0x%" PFMT64x "\n", (ut64)ar->nthreads[0]);
286  PRINTF_BA(" nthreads: internal metadata allocation = 0x%" PFMT64x "\n", (ut64)ar->nthreads[1]);
287  PRINTF_BA(" lock = 0x%" PFMT64x "\n", OO(lock));
288  PRINTF_BA(" stats = 0x%" PFMT64x "\n", OO(stats));
289  PRINTF_BA(" tcache_ql = 0x%" PFMT64x "\n", OO(tcache_ql));
290  PRINTF_BA(" prof_accumbytes = 0x%" PFMT64x "x\n", (ut64)ar->prof_accumbytes);
291  PRINTF_BA(" offset_state = 0x%" PFMT64x "\n", (ut64)ar->offset_state);
292  PRINTF_BA(" dss_prec_t = 0x%" PFMT64x "\n", OO(dss_prec));
293  PRINTF_BA(" achunks = 0x%" PFMT64x "\n", OO(achunks));
294  PRINTF_BA(" extent_sn_next = 0x%" PFMT64x "\n", (ut64)(size_t)ar->extent_sn_next);
295  PRINTF_BA(" spare = 0x%" PFMT64x "\n", (ut64)(size_t)ar->spare);
296  PRINTF_BA(" lg_dirty_mult = 0x%" PFMT64x "\n", (ut64)(ssize_t)ar->lg_dirty_mult);
297  PRINTF_BA(" purging = %s\n", rz_str_bool(ar->purging));
298  PRINTF_BA(" nactive = 0x%" PFMT64x "\n", (ut64)(size_t)ar->nactive);
299  PRINTF_BA(" ndirty = 0x%" PFMT64x "\n", (ut64)(size_t)ar->ndirty);
300 
301  PRINTF_BA(" runs_dirty = 0x%" PFMT64x "\n", OO(runs_dirty));
302  PRINTF_BA(" chunks_cache = 0x%" PFMT64x "\n", OO(chunks_cache));
303  PRINTF_BA(" huge = 0x%" PFMT64x "\n", OO(huge));
304  PRINTF_BA(" huge_mtx = 0x%" PFMT64x "\n", OO(huge_mtx));
305 
306  PRINTF_BA(" chunks_szsnad_cached = 0x%" PFMT64x "\n", OO(chunks_szsnad_cached));
307  PRINTF_BA(" chunks_ad_cached = 0x%" PFMT64x "\n", OO(chunks_ad_cached));
308  PRINTF_BA(" chunks_szsnad_retained = 0x%" PFMT64x "\n", OO(chunks_szsnad_retained));
309  PRINTF_BA(" chunks_ad_cached = 0x%" PFMT64x "\n", OO(chunks_ad_retained));
310 
311  PRINTF_BA(" chunks_mtx = 0x%" PFMT64x "\n", OO(chunks_mtx));
312  PRINTF_BA(" node_cache = 0x%" PFMT64x "\n", OO(node_cache));
313  PRINTF_BA(" node_cache_mtx = 0x%" PFMT64x "\n", OO(node_cache_mtx));
314  PRINTF_BA(" chunks_hooks = 0x%" PFMT64x "\n", OO(chunk_hooks));
315  PRINTF_BA(" bins = %d 0x%" PFMT64x "\n", JM_NBINS, OO(bins));
316  PRINTF_BA(" runs_avail = %d 0x%" PFMT64x "\n", NPSIZES, OO(runs_avail));
317  PRINT_GA("}\n");
318  break;
319  }
320  free(ar);
321  free(stats);
322 }
323 
324 static void GH(jemalloc_get_bins)(RzCore *core, const char *input) {
325  int i = 0, j;
326  ut64 bin_info;
327  ut64 arenas;
328  GHT arena = GHT_MAX; //, bin = GHT_MAX;
329  arena_t *ar = NULL;
330  arena_bin_info_t *b = NULL;
332 
333  switch (input[0]) {
334  case ' ':
335  ar = RZ_NEW0(arena_t);
336  if (!ar) {
337  break;
338  }
339  b = RZ_NEW0(arena_bin_info_t);
340  if (!b) {
341  break;
342  }
343  if (!GH(rz_resolve_jemalloc)(core, "je_arena_bin_info", &bin_info)) {
344  RZ_LOG_ERROR("Cannot resolve je_arena_bin_info\n");
345  RZ_FREE(b);
346  break;
347  }
348  if (GH(rz_resolve_jemalloc)(core, "je_arenas", &arenas)) {
349  rz_io_read_at(core->io, arenas, (ut8 *)&arenas, sizeof(GHT));
350  PRINTF_GA("arenas @ 0x%" PFMTx " {\n", (GHT)arenas);
351  for (;;) {
352  rz_io_read_at(core->io, arenas + i * sizeof(GHT), (ut8 *)&arena, sizeof(GHT));
353  if (!arena) {
354  RZ_FREE(b);
355  break;
356  }
357  PRINTF_YA(" arenas[%d]: ", i++);
358  PRINTF_BA("@ 0x%" PFMTx, (GHT)arena);
359  PRINT_YA(" {\n");
360  rz_io_read_at(core->io, arena, (ut8 *)ar, sizeof(arena_t));
361  for (j = 0; j < JM_NBINS; j++) {
362  rz_io_read_at(core->io, (GHT)(bin_info + j * sizeof(arena_bin_info_t)),
363  (ut8 *)b, sizeof(arena_bin_info_t));
364  PRINT_YA(" {\n");
365  PRINT_YA(" regsize : ");
366  PRINTF_BA("0x%zx\n", b->reg_size);
367  PRINT_YA(" redzone size ");
368  PRINTF_BA("0x%zx\n", b->redzone_size);
369  PRINT_YA(" reg_interval : ");
370  PRINTF_BA("0x%zx\n", b->reg_interval);
371  PRINT_YA(" run_size : ");
372  PRINTF_BA("0x%zx\n", b->run_size);
373  PRINT_YA(" nregs : ");
374  PRINTF_BA("0x%x\n", b->nregs);
375  // FIXME: It's a structure of bitmap_info_t
376  // PRINT_YA (" bitmap_info : ");
377  // PRINTF_BA ("0x%"PFMT64x"\n", b->bitmap_info);
378  PRINT_YA(" reg0_offset : ");
379  PRINTF_BA("0x%" PFMT64x "\n\n", (ut64)b->reg0_offset);
380  // FIXME: It's a structure of malloc_mutex_t
381  // PRINTF_YA (" bins[%d]->lock ", j);
382  // PRINTF_BA ("= 0x%"PFMT64x"\n", ar->bins[j].lock);
383  // FIXME: It's a structure of arena_run_t*
384  // PRINTF_YA (" bins[%d]->runcur ", j);
385  // PRINTF_BA ("@ 0x%"PFMT64x"\n", ar->bins[j].runcur);
386  // FIXME: It's a structure of arena_run_heap_t*
387  // PRINTF_YA (" bins[%d]->runs ", j);
388  // PRINTF_BA ("@ 0x%"PFMTx"\n", ar->bins[j].runs);
389  // FIXME: It's a structure of malloc_bin_stats_t
390  // PRINTF_YA (" bins[%d]->stats ", j);
391  // PRINTF_BA ("= 0x%"PFMTx"\n", ar->bins[j].stats);
392  PRINT_YA(" }\n");
393  }
394  PRINT_YA(" }\n");
395  }
396  }
397  PRINT_GA("}\n");
398  break;
399  }
400  free(ar);
401  free(b);
402 }
403 
404 #if 0
405 static void GH(jemalloc_get_runs)(RzCore *core, const char *input) {
406  switch (input[0]) {
407  case ' ':
408  {
409  int pageind;
410  ut64 npages, chunksize_mask, map_bias, map_misc_offset, chunk, mapbits;;
411  arena_chunk_t *c = RZ_NEW0 (arena_chunk_t);
412 
413  if (!c) {
414  RZ_LOG_ERROR ("Cannot call calloc\n");
415  return;
416  }
417 
418  input += 1;
419  chunk = rz_num_math (core->num, input);
420 
421  if (!GH(rz_resolve_jemalloc)(core, "je_chunk_npages", &npages)) {
422  RZ_LOG_ERROR ("Cannot resolve je_chunk_npages\n");
423  return;
424  }
425  if (!GH(rz_resolve_jemalloc)(core, "je_chunksize_mask", &chunksize_mask)) {
426  RZ_LOG_ERROR ("Cannot resolve je_chunksize_mask\n");
427  return;
428  }
429  if (!GH(rz_resolve_jemalloc)(core, "je_map_bias", &map_bias)) {
430  RZ_LOG_ERROR ("Cannot resolve je_map_bias");
431  return;
432  }
433  if (!GH(rz_resolve_jemalloc)(core, "je_map_misc_offset", &map_misc_offset)) {
434  RZ_LOG_ERROR ("Cannot resolve je_map_misc_offset");
435  return;
436  }
437 
438  rz_io_read_at (core->io, npages, (ut8*)&npages, sizeof (GHT));
439  rz_io_read_at (core->io, chunksize_mask, (ut8*)&chunksize_mask, sizeof (GHT));
440  rz_io_read_at (core->io, map_bias, (ut8*)&map_bias, sizeof (GHT));
441  rz_io_read_at (core->io, map_misc_offset, (ut8*)&map_misc_offset, sizeof (GHT));
442 
443  rz_cons_printf ("map_misc_offset 0x%08"PFMT64x"\n", (ut64)map_misc_offset);
444 
445  rz_io_read_at (core->io, chunk, (ut8 *)c, sizeof (arena_chunk_t));
446  mapbits = *(GHT *)&c->map_bits;
447  rz_cons_printf ("map_bits: 0x%08"PFMT64x"\n", (ut64)mapbits);
448 
449  uint32_t offset = rz_offsetof (arena_chunk_t, map_bits);
450 
451  arena_chunk_map_bits_t *dwords = (void *)calloc (sizeof (arena_chunk_map_bits_t), npages);
452  rz_io_read_at (core->io, chunk + offset, (ut8*)dwords, sizeof (arena_chunk_map_bits_t) * npages);
453  rz_cons_printf ("map_bits @ 0x%08"PFMT64x"\n", (ut64)(chunk + offset));
454 
455  arena_run_t *r = RZ_NEW0 (arena_run_t);
456  if (!r) {
457  RZ_LOG_ERROR ("Cannot call calloc\n");
458  return;
459  }
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) {
463  // ut64 elm = ((arena_chunk_map_misc_t *)((uintptr_t)chunk + (uintptr_t)map_misc_offset) + pageind-map_bias);
464  ut64 elm = chunk + map_misc_offset + pageind-map_bias;
465  rz_cons_printf ("\nelm: 0x%"PFMT64x"\n", elm);
466  arena_chunk_map_misc_t *m = RZ_NEW0 (arena_chunk_map_misc_t);
467  if (m) {
468  ut64 run = elm + rz_offsetof (arena_chunk_map_misc_t, run);
469  rz_io_read_at (core->io, elm, (ut8*)m, sizeof (arena_chunk_map_misc_t));
470  rz_cons_printf ("Small run @ 0x%08"PFMT64x"\n", (ut64)elm);
471  rz_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t));
472  rz_cons_printf ("binind: 0x%08"PFMT64x"\n", (ut64)r->binind);
473  rz_cons_printf ("nfree: 0x%08"PFMT64x"\n", (ut64)r->nfree);
474  rz_cons_printf ("bitmap: 0x%08"PFMT64x"\n\n", (ut64)*(GHT*)r->bitmap);
475  free (m);
476  }
477  } else if (mapelm.bits & CHUNK_MAP_LARGE) {
478  ut64 run = (ut64) (size_t) chunk + (pageind << LG_PAGE);
479  rz_cons_printf ("Large run @ 0x%08"PFMT64x"\n", run);
480  rz_io_read_at (core->io, run, (ut8*)r, sizeof (arena_run_t));
481  rz_cons_printf ("binind: 0x%08"PFMT64x"\n", (ut64)r->binind);
482  rz_cons_printf ("nfree: 0x%08"PFMT64x"\n", (ut64)r->nfree);
483  rz_cons_printf ("bitmap: 0x%08"PFMT64x"\n\n", (ut64)*(GHT*)r->bitmap);
484  }
485  }
486  free (c);
487  free (r);
488  }
489  break;
490  }
491 }
492 #endif
493 
494 static int GH(cmd_dbg_map_jemalloc)(RzCore *core, const char *input) {
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",
500  // "dmhr", "[arena_chunk_t]", "print all runs created for a given arena_chunk_t instance",
501  "dmx?", "", "Show map heap help", NULL
502  };
503 
504  switch (input[0]) {
505  case '?':
506  rz_core_cmd_help(core, help_msg);
507  break;
508  case 'a': // dmha
510  (core, input + 1);
511  break;
512  case 'b': // dmhb
514  (core, input + 1);
515  break;
516  case 'c': // dmhc
518  (core, input + 1);
519  break;
520  /*
521  case 'r': //dmhr
522  GH(jemalloc_get_runs) (core, input + 1);
523  break;
524  */
525  }
526  return 0;
527 }
lzma_index ** i
Definition: index.h:629
static const ut32 ar[]
Definition: apprentice.c:1935
RZ_API bool rz_bin_file_set_cur_binfile(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:288
RZ_API bool rz_bin_file_delete(RzBin *bin, RzBinFile *bf)
Definition: bfile.c:213
RZ_DEPRECATE RZ_API RZ_BORROW RzList * rz_bin_get_symbols(RZ_NONNULL RzBin *bin)
Definition: bin.c:696
RZ_API void rz_bin_options_init(RzBinOptions *opt, int fd, ut64 baseaddr, ut64 loadaddr, bool patch_relocs)
Definition: bin.c:75
RZ_API RzBinFile * rz_bin_open(RzBin *bin, const char *file, RzBinOptions *opt)
Definition: bin.c:200
RZ_API RzBinFile * rz_bin_cur(RzBin *bin)
Definition: bin.c:895
RZ_API void rz_core_cmd_help(const RzCore *core, const char *help[])
Definition: cmd.c:163
RZ_API char * rz_core_cmd_strf(RzCore *core, const char *fmt,...)
Definition: cmd.c:5472
RZ_API bool rz_config_get_b(RzConfig *cfg, RZ_NONNULL const char *name)
Definition: config.c:142
RZ_API RzCons * rz_cons_singleton(void)
Definition: cons.c:300
RZ_API int rz_cons_printf(const char *format,...)
Definition: cons.c:1202
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
RZ_API bool rz_debug_map_sync(RzDebug *dbg)
Definition: dmap.c:33
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf uLong offset
Definition: ioapi.h:144
arena_t ** arenas
#define LG_PAGE
uint8_t ut8
Definition: lh5801.h:11
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
#define GH(x)
#define GHT
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)
#define PFMTx
static void GH() jemalloc_get_bins(RzCore *core, const char *input)
#define OO(x)
#define GHT_MAX
int n
Definition: mipsasm.c:19
#define map_bias
#define chunksize_mask
#define map_misc_offset
static RzSocket * s
Definition: rtr.c:28
static int run(int i, const char *arg)
Definition: rz-bb.c:19
RZ_API bool rz_file_exists(const char *str)
Definition: file.c:192
#define PRINT_GA(msg)
Definition: rz_heap_glibc.h:20
#define PRINTF_GA(fmt,...)
Definition: rz_heap_glibc.h:14
#define PRINT_YA(msg)
Definition: rz_heap_glibc.h:19
#define PRINTF_YA(fmt,...)
Definition: rz_heap_glibc.h:13
#define PRINTF_BA(fmt,...)
Definition: rz_heap_glibc.h:15
RZ_API bool rz_io_read_at(RzIO *io, ut64 addr, ut8 *buf, int len)
Definition: io.c:300
#define RZ_LOG_INFO(fmtstr,...)
Definition: rz_log.h:54
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API const char * rz_str_bool(int b)
Definition: str.c:3896
#define PFMT64d
Definition: rz_types.h:394
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define rz_offsetof(type, member)
Definition: rz_types.h:360
#define RZ_FREE(x)
Definition: rz_types.h:369
#define PFMT64x
Definition: rz_types.h:393
#define UT64_MAX
Definition: rz_types_base.h:86
unsigned int uint32_t
Definition: sftypes.h:29
int ssize_t
Definition: sftypes.h:39
#define b(i)
Definition: sha256.c:42
#define c(i)
Definition: sha256.c:43
Definition: malloc.c:26
Definition: malloc.c:21
XX curplugin == o->plugin.
Definition: rz_bin.h:298
RzConsPrintablePalette pal
Definition: rz_cons.h:491
RzConsContext * context
Definition: rz_cons.h:502
static void lock(volatile int *lk)
Definition: malloc.c:61
struct bin bins[64]
Definition: malloc.c:34
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58
static bool input(void *ud, zip_uint8_t *data, zip_uint64_t length)