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+=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 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 CFLAGS+=-DCORELIB -I../../shlr
LDFLAGS+=${DL_LIBS} LDFLAGS+=${DL_LIBS}

View File

@ -1581,13 +1581,20 @@ static int cmd_debug_map(RCore *core, const char *input) {
break; break;
case 'h': // "dmh" case 'h': // "dmh"
{ {
int SZ = core->assembler->bits / 8;
const char *m = r_config_get (core->config, "dbg.malloc"); const char *m = r_config_get (core->config, "dbg.malloc");
if (!strcmp ("glibc", m)) { if (!strcmp ("glibc", m)) {
(SZ == 4) ? cmd_dbg_map_heap_glibc_32 (core, input + 1): #if __linux__ && __GNU_LIBRARY__ && __GLIBC__ && __GLIBC_MINOR__
cmd_dbg_map_heap_glibc_64 (core, input + 1); (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)) { } else if (!strcmp ("jemalloc", m)) {
(SZ == 4) ? cmd_dbg_map_jemalloc_32 (core, input + 1) : (SZ == 4)
cmd_dbg_map_jemalloc_64 (core, input + 1) ; ? cmd_dbg_map_jemalloc_32 (core, input + 1)
: cmd_dbg_map_jemalloc_64 (core, input + 1);
} else { } else {
eprintf ("MALLOC algorithm not supported\n"); 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) { static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, GHT *symbol) {
RListIter *iter; RListIter *iter;
RDebugMap *map; RDebugMap *map;
char *path = NULL;
bool is_debug_file = false;
const char *jemalloc_ver_end = NULL; const char *jemalloc_ver_end = NULL;
ut64 jemalloc_addr = UT64_MAX, vaddr = UT64_MAX; ut64 jemalloc_addr = UT64_MAX, vaddr = UT64_MAX;
@ -78,33 +75,33 @@ static bool GH(r_resolve_jemalloc)(RCore *core, char *symname, GHT *symbol) {
return false; 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) { if (!is_debug_file) {
eprintf ("Warning: Is libjemaloc.so.2 in /usr/local/lib path?\n"); eprintf ("Warning: Is libjemaloc.so.2 in /usr/local/lib path?\n");
return false; return false;
} else {
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) {
*symbol = jemalloc_addr + vaddr;
free (path);
return true;
}
}
} }
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) {
*symbol = jemalloc_addr + vaddr;
free (path);
return true;
}
}
return false;
} }
static void GH(jemalloc_get_runs)(RCore *core, const char *input) { static void GH(jemalloc_get_runs)(RCore *core, const char *input) {
switch (input[0]) { switch (input[0]) {
case ' ': case ' ':
{ {
GHT misc, chunk, map_bias, map_misc_offset, chunksize_mask, npages; // GHT misc, chunk, map_bias, map_misc_offset, chunksize_mask, npages;
arena_chunk_t *c = R_NEW0 (arena_chunk_t); GHT chunk, map_bias, map_misc_offset, chunksize_mask, npages;
arena_chunk_map_misc_t *miscelm = R_NEW0 (arena_chunk_map_misc_t); // arena_chunk_t *c = R_NEW0 (arena_chunk_t);
arena_chunk_map_bits_t *bits = R_NEW0 (arena_chunk_map_bits_t); // arena_chunk_map_misc_t *miscelm = R_NEW0 (arena_chunk_map_misc_t);
int flag = 0; // arena_chunk_map_bits_t *bits = R_NEW0 (arena_chunk_map_bits_t);
input +=1; input +=1;
chunk = strstr (input, "0x") ? (GHT)strtol (input, NULL, 0) : (GHT)strtol (input, NULL, 16); 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 ("chunksize_mask: %"PFMTx"\n", chunksize_mask);
eprintf ("chunk_npages: %"PFMTx"\n", npages); 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; pageind >>= 12;
misc = ((uintptr_t)chunk + (uintptr_t)map_misc_offset) + pageind-map_bias; misc = ((uintptr_t)chunk + (uintptr_t)map_misc_offset) + pageind-map_bias;
printf ("arena_chunk_map_misc_t @ %"PFMT64x"\n", misc); 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 ("offset: %"PFMT64x"\n", offset);
eprintf ("run @ %"PFMT64x"\n", misc + offset); eprintf ("run @ %"PFMT64x"\n", misc + offset);
*/ #endif
} }
break; break;
} }
@ -187,7 +185,7 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
if (arena) { if (arena) {
r_core_read_at (core, arena, (ut8 *)ar, sizeof (arena_t)); 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) { if (head->en_addr != 0) {
PRINT_YA ("\t Chunk - start: "); PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)head->en_addr); 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)); PRINTF_BA ("0x%"PFMTx, (GHT)(head->en_addr + cnksz));
PRINT_YA (", size: "); PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz); PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); r_core_read_at (core, (ut64)(size_t)head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t));
while (node != -1 && node->en_addr != head->en_addr) { while (node && node->en_addr != head->en_addr) {
PRINT_YA ("\t Chunk - start: "); PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr); PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr);
PRINT_YA (", end: "); PRINT_YA (", end: ");
PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz)); PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz));
PRINT_YA (", size: "); PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz); 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; int i = 0;
GHT arenas = GHT_MAX, arena = GHT_MAX, sym = GHT_MAX; GHT arenas = GHT_MAX, arena = GHT_MAX, sym = GHT_MAX;
arena_t *ar = R_NEW0 (arena_t); 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; input += 1;
if (GH(r_resolve_jemalloc) (core, "je_arenas", &sym)) { 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); 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, 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) { if (head->en_addr != 0) {
PRINT_YA ("\t Chunk - start: "); PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)head->en_addr); PRINTF_BA ("0x%"PFMTx, (GHT)head->en_addr);
@ -237,18 +237,19 @@ static void GH(jemalloc_get_chunks)(RCore *core, const char *input) {
PRINTF_BA ("0x%"PFMTx, (GHT)(head->en_addr + cnksz)); PRINTF_BA ("0x%"PFMTx, (GHT)(head->en_addr + cnksz));
PRINT_YA (", size: "); PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz); PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz);
r_core_read_at (core, head->ql_link.qre_next, (ut8 *)node, sizeof (extent_node_t)); ut64 addr = (ut64) head->ql_link.qre_next;
while (node != -1 && node->en_addr != head->en_addr) { 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: "); PRINT_YA ("\t Chunk - start: ");
PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr); PRINTF_BA ("0x%"PFMTx, (GHT)node->en_addr);
PRINT_YA (", end: "); PRINT_YA (", end: ");
PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz)); PRINTF_BA ("0x%"PFMTx, (GHT)(node->en_addr + cnksz));
PRINT_YA (", size: "); PRINT_YA (", size: ");
PRINTF_BA ("0x%"PFMTx"\n", (GHT)cnksz); 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"); PRINT_GA ("}\n");
} }
} }
free (ar); free (ar);
@ -349,9 +350,9 @@ static int GH(cmd_dbg_map_jemalloc)(RCore *core, const char *input) {
case 'c': //dmhc case 'c': //dmhc
GH(jemalloc_get_chunks) (core, input + 1); GH(jemalloc_get_chunks) (core, input + 1);
break; break;
/*case 'r': //dmhr case 'r': //dmhr
GH(jemalloc_get_runs) (core, input + 1); GH(jemalloc_get_runs) (core, input + 1);
break;*/ break;
} }
return 0; return 0;
} }

View File

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

View File

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

View File

@ -32,12 +32,6 @@
# endif # endif
#endif #endif
#ifdef JEMALLOC_CC_SILENCE
# define UNUSED JEMALLOC_ATTR(unused)
#else
# define UNUSED
#endif
#define ZU(z) ((size_t)z) #define ZU(z) ((size_t)z)
#define ZI(z) ((ssize_t)z) #define ZI(z) ((ssize_t)z)
#define QU(q) ((uint64_t)q) #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; uint32_t ret, state1;
if (lg_range <1 || lg_range >32) {
return 0;
}
#if 0
assert(lg_range > 0); assert(lg_range > 0);
assert(lg_range <= 32); assert(lg_range <= 32);
#endif
if (atomic) { if (atomic) {
uint32_t state0; uint32_t state0;
@ -111,8 +116,13 @@ prng_lg_range_u64(uint64_t *state, unsigned lg_range)
{ {
uint64_t ret, state1; uint64_t ret, state1;
if (lg_range <1 || lg_range > 64) {
return 0;
}
#if 0
assert(lg_range > 0); assert(lg_range > 0);
assert(lg_range <= 64); assert(lg_range <= 64);
#endif
state1 = prng_state_next_u64(*state); state1 = prng_state_next_u64(*state);
*state = state1; *state = state1;
@ -126,8 +136,10 @@ prng_lg_range_zu(size_t *state, unsigned lg_range, bool atomic)
{ {
size_t ret, state1; size_t ret, state1;
#if 0
assert(lg_range > 0); assert(lg_range > 0);
assert(lg_range <= ZU(1) << (3 + LG_SIZEOF_PTR)); assert(lg_range <= ZU(1) << (3 + LG_SIZEOF_PTR));
#endif
if (atomic) { if (atomic) {
size_t state0; size_t state0;
@ -151,7 +163,12 @@ prng_range_u32(uint32_t *state, uint32_t range, bool atomic)
uint32_t ret; uint32_t ret;
unsigned lg_range; unsigned lg_range;
#if 0
assert(range > 1); assert(range > 1);
#endif
if (range <2) {
return 0;
}
/* Compute the ceiling of lg(range). */ /* Compute the ceiling of lg(range). */
lg_range = ffs_u32(pow2_ceil_u32(range)) - 1; 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; uint64_t ret;
unsigned lg_range; unsigned lg_range;
assert(range > 1); // assert(range > 1);
/* Compute the ceiling of lg(range). */ /* Compute the ceiling of lg(range). */
lg_range = ffs_u64(pow2_ceil_u64(range)) - 1; lg_range = ffs_u64(pow2_ceil_u64(range)) - 1;

View File

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