Fix build

This commit is contained in:
pancake 2017-08-03 13:27:11 +02:00
parent edfd37e7e4
commit e913c770f5
57 changed files with 78 additions and 56 deletions

View File

@ -11,6 +11,7 @@ OBJS+=hack.o vasm.o patch.o cbin.o log.o rtr.o cmd_api.o
OBJS+=canal.o project.o gdiff.o asm.o vmenus.o disasm.o plugin.o
OBJS+=help.o task.o panels.o pseudo.o vmarks.o anal_tp.o blaze.o
CFLAGS+=-I../../shlr/heap/include
CFLAGS+=-DCORELIB -I../../shlr
LDFLAGS+=${DL_LIBS}

View File

@ -1581,13 +1581,20 @@ static int cmd_debug_map(RCore *core, const char *input) {
break;
case 'h': // "dmh"
{
int SZ = core->assembler->bits / 8;
const char *m = r_config_get (core->config, "dbg.malloc");
if (!strcmp ("glibc", m)) {
(SZ == 4) ? cmd_dbg_map_heap_glibc_32 (core, input + 1):
cmd_dbg_map_heap_glibc_64 (core, input + 1);
#if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
(SZ == 4)
? cmd_dbg_map_heap_glibc_32 (core, input + 1)
: cmd_dbg_map_heap_glibc_64 (core, input + 1);
#else
eprintf ("glibc not supported for this platform\n");
#endif
} else if (!strcmp ("jemalloc", m)) {
(SZ == 4) ? cmd_dbg_map_jemalloc_32 (core, input + 1) :
cmd_dbg_map_jemalloc_64 (core, input + 1) ;
(SZ == 4)
? cmd_dbg_map_jemalloc_32 (core, input + 1)
: cmd_dbg_map_jemalloc_64 (core, input + 1);
} else {
eprintf ("MALLOC algorithm not supported\n");
}

View File

@ -55,9 +55,6 @@ static int GH(je_matched)(const char *ptr, const char *str) {
static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, GHT *symbol) {
RListIter *iter;
RDebugMap *map;
char *path = NULL;
bool is_debug_file = false;
const char *jemalloc_ver_end = NULL;
ut64 jemalloc_addr = UT64_MAX, vaddr = UT64_MAX;
@ -78,13 +75,13 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, GHT *symbol) {
return false;
}
is_debug_file = GH(je_matched)(jemalloc_ver_end, "/usr/local/lib");
bool is_debug_file = GH(je_matched)(jemalloc_ver_end, "/usr/local/lib");
if (!is_debug_file) {
eprintf ("Warning: Is libjemaloc.so.2 in /usr/local/lib path?\n");
return false;
} else {
path = r_str_newf ("%s", jemalloc_ver_end);
}
char *path = r_str_newf ("%s", jemalloc_ver_end);
if (r_file_exists (path)) {
vaddr = GH(je_get_va_symbol)(path, symname);
if (jemalloc_addr != GHT_MAX && vaddr != 0) {
@ -93,18 +90,18 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, GHT *symbol) {
return true;
}
}
}
return false;
}
static void GH(jemalloc_get_runs)(RCore *core, const char *input) {
switch (input[0]) {
case ' ':
{
GHT misc, chunk, map_bias, map_misc_offset, chunksize_mask, npages;
arena_chunk_t *c = R_NEW0 (arena_chunk_t);
arena_chunk_map_misc_t *miscelm = R_NEW0 (arena_chunk_map_misc_t);
arena_chunk_map_bits_t *bits = R_NEW0 (arena_chunk_map_bits_t);
int flag = 0;
// GHT misc, chunk, map_bias, map_misc_offset, chunksize_mask, npages;
GHT chunk, map_bias, map_misc_offset, chunksize_mask, npages;
// arena_chunk_t *c = R_NEW0 (arena_chunk_t);
// arena_chunk_map_misc_t *miscelm = R_NEW0 (arena_chunk_map_misc_t);
// arena_chunk_map_bits_t *bits = R_NEW0 (arena_chunk_map_bits_t);
input +=1;
chunk = strstr (input, "0x") ? (GHT)strtol (input, NULL, 0) : (GHT)strtol (input, NULL, 16);
@ -141,9 +138,10 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) {
eprintf ("chunksize_mask: %"PFMTx"\n", chunksize_mask);
eprintf ("chunk_npages: %"PFMTx"\n", npages);
GHT pageind;
/*for (pageind = map_bias; pageind < npages; pageind ++) {
#if 0
GHT pageind = 0;
for (pageind = map_bias; pageind < npages; pageind ++) {
pageind >>= 12;
misc = ((uintptr_t)chunk + (uintptr_t)map_misc_offset) + pageind-map_bias;
printf ("arena_chunk_map_misc_t @ %"PFMT64x"\n", misc);
@ -157,7 +155,7 @@ static void GH(jemalloc_get_runs)(RCore *core, const char *input) {
}
eprintf ("offset: %"PFMT64x"\n", offset);
eprintf ("run @ %"PFMT64x"\n", misc + offset);
*/
#endif
}
break;
}
@ -187,7 +185,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
if (arena) {
r_core_read_at (core, arena, (ut8 *)ar, sizeof (arena_t));
r_core_read_at (core, ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t));
r_core_read_at (core, (ut64)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t));
if (head->en_addr != 0) {
PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)head->en_addr);
@ -195,15 +193,15 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
PRINTF_BA ("0x%"PFMTx, (GHT)(head->en_addr + cnksz));
PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
while (node != -1 && node->en_addr != head->en_addr) {
r_core_read_at (core, (ut64)(size_t)head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
while (node && node->en_addr != head->en_addr) {
PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr);
PRINT_YA (", end: ");
PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz));
PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
r_core_read_at (core, (ut64)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
}
}
}
@ -217,7 +215,9 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
int i = 0;
GHT arenas = GHT_MAX, arena = GHT_MAX, sym = GHT_MAX;
arena_t *ar = R_NEW0 (arena_t);
extent_node_t *node = R_NEW0 (extent_node_t), *head = R_NEW0 (extent_node_t);
extent_node_t *node = R_NEW0 (extent_node_t);
extent_node_t *head = R_NEW0 (extent_node_t);
// TODO : check for null allocations here
input += 1;
if (GH(r_resolve_jemalloc) (core, "je_arenas", &sym)) {
@ -229,7 +229,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
}
PRINTF_GA ("arenas[%d]: @ 0x%"PFMTx" { \n", i++, (GHT)arena);
r_core_read_at (core, arena, (ut8 *)ar, sizeof (arena_t));
r_core_read_at (core, ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t));
r_core_read_at (core, (ut64)(size_t)ar->achunks.qlh_first, (ut8 *)head, sizeof (extent_node_t));
if (head->en_addr != 0) {
PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)head->en_addr);
@ -237,15 +237,16 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
PRINTF_BA ("0x%"PFMTx, (GHT)(head->en_addr + cnksz));
PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
while (node != -1 && node->en_addr != head->en_addr) {
ut64 addr = (ut64) head->ql_link.qre_next;
r_core_read_at (core, addr, (ut8 *)node, sizeof (extent_node_t));
while (node && node->en_addr != head->en_addr) {
PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr);
PRINT_YA (", end: ");
PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz));
PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
r_core_read_at (core, (ut64)(size_t)node->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
}
}
PRINT_GA ("}\n");
@ -349,9 +350,9 @@ static int GH(cmd_dbg_map_jemalloc)(RCore *core, const char *input) {
case 'c': //dmhc
GH(jemalloc_get_chunks) (core, input + 1);
break;
/*case 'r': //dmhr
case 'r': //dmhr
GH(jemalloc_get_runs) (core, input + 1);
break;*/
break;
}
return 0;
}

View File

@ -5,7 +5,7 @@
#ifndef assert
#define assert(e) do { \
if (unlikely(config_debug && !(e))) { \
malloc_printf( \
eprintf( \
"<jemalloc>: %s:%d: Failed assertion: \"%s\"\n", \
__FILE__, __LINE__, #e); \
abort(); \
@ -16,7 +16,7 @@
#ifndef not_reached
#define not_reached() do { \
if (config_debug) { \
malloc_printf( \
eprintf( \
"<jemalloc>: %s:%d: Unreachable code reached\n", \
__FILE__, __LINE__); \
abort(); \
@ -28,7 +28,7 @@
#ifndef not_implemented
#define not_implemented() do { \
if (config_debug) { \
malloc_printf("<jemalloc>: %s:%d: Not implemented\n", \
eprintf("<jemalloc>: %s:%d: Not implemented\n", \
__FILE__, __LINE__); \
abort(); \
} \

View File

@ -149,10 +149,6 @@ static const bool config_cache_oblivious =
#endif
;
#ifdef JEMALLOC_C11ATOMICS
#include <stdatomic.h>
#endif
#ifdef JEMALLOC_ATOMIC9
#include <machine/atomic.h>
#endif

View File

@ -32,12 +32,6 @@
# endif
#endif
#ifdef JEMALLOC_CC_SILENCE
# define UNUSED JEMALLOC_ATTR(unused)
#else
# define UNUSED
#endif
#define ZU(z) ((size_t)z)
#define ZI(z) ((ssize_t)z)
#define QU(q) ((uint64_t)q)

View File

@ -86,8 +86,13 @@ prng_lg_range_u32(uint32_t *state, unsigned lg_range, bool atomic)
{
uint32_t ret, state1;
if (lg_range <1 || lg_range >32) {
return 0;
}
#if 0
assert(lg_range > 0);
assert(lg_range <= 32);
#endif
if (atomic) {
uint32_t state0;
@ -111,8 +116,13 @@ prng_lg_range_u64(uint64_t *state, unsigned lg_range)
{
uint64_t ret, state1;
if (lg_range <1 || lg_range > 64) {
return 0;
}
#if 0
assert(lg_range > 0);
assert(lg_range <= 64);
#endif
state1 = prng_state_next_u64(*state);
*state = state1;
@ -126,8 +136,10 @@ prng_lg_range_zu(size_t *state, unsigned lg_range, bool atomic)
{
size_t ret, state1;
#if 0
assert(lg_range > 0);
assert(lg_range <= ZU(1) << (3 + LG_SIZEOF_PTR));
#endif
if (atomic) {
size_t state0;
@ -151,7 +163,12 @@ prng_range_u32(uint32_t *state, uint32_t range, bool atomic)
uint32_t ret;
unsigned lg_range;
#if 0
assert(range > 1);
#endif
if (range <2) {
return 0;
}
/* Compute the ceiling of lg(range). */
lg_range = ffs_u32(pow2_ceil_u32(range)) - 1;
@ -170,7 +187,7 @@ prng_range_u64(uint64_t *state, uint64_t range)
uint64_t ret;
unsigned lg_range;
assert(range > 1);
// assert(range > 1);
/* Compute the ceiling of lg(range). */
lg_range = ffs_u64(pow2_ceil_u64(range)) - 1;

View File

@ -1,6 +1,8 @@
/******************************************************************************/
#ifdef JEMALLOC_H_TYPES
// XXX: remove all asserts
#ifdef _WIN32
# ifdef _WIN64
# define FMT64_PREFIX "ll"
@ -106,6 +108,7 @@ void malloc_write(const char *s);
*/
size_t malloc_vsnprintf(char *str, size_t size, const char *format,
va_list ap);
/*
size_t malloc_snprintf(char *str, size_t size, const char *format, ...)
JEMALLOC_FORMAT_PRINTF(3, 4);
void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
@ -113,6 +116,7 @@ void malloc_vcprintf(void (*write_cb)(void *, const char *), void *cbopaque,
void malloc_cprintf(void (*write)(void *, const char *), void *cbopaque,
const char *format, ...) JEMALLOC_FORMAT_PRINTF(3, 4);
void malloc_printf(const char *format, ...) JEMALLOC_FORMAT_PRINTF(1, 2);
*/
#endif /* JEMALLOC_H_EXTERNS */
/******************************************************************************/
@ -249,13 +253,15 @@ lg_floor(size_t x)
{
size_t ret;
assert(x != 0);
if (x == 0) {
return UINT_MAX;
}
asm ("bsr %1, %0"
: "=r"(ret) // Outputs.
: "r"(x) // Inputs.
);
assert(ret < UINT_MAX);
// assert(ret < UINT_MAX);
return ((unsigned)ret);
}
#elif (defined(_MSC_VER))