diff --git a/TODO.md b/TODO.md index caff04a3fc..60f371e328 100644 --- a/TODO.md +++ b/TODO.md @@ -347,6 +347,13 @@ Future - the r_flag_get by string should have another construction with btree for the string of the name +Threads +======= +* implement non-threaded thread api (dummy one, when no support) +* test w32 port +* Implement a pure clone(2) backend +* Added a threading pool super-api + # Debug information in binaries * dwarf, pdb, def, lib - from file, from section, ... diff --git a/configure b/configure index e24a319e0c..cc69ac108c 100755 --- a/configure +++ b/configure @@ -475,7 +475,7 @@ for A in ${ENVWORDS} ; do SEDFLAGS="${SEDFLAGS}s,@${A}@,${VAR},g;" done SEDFLAGS="${SEDFLAGS}'" -for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/r_io.pc pkgcfg/r_db.pc pkgcfg/r_magic.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_anal.pc pkgcfg/r_hash.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_lang.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_cmd.pc pkgcfg/r_config.pc pkgcfg/r_flags.pc pkgcfg/r_syscall.pc pkgcfg/r_sign.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_bp.pc pkgcfg/r_lib.pc pkgcfg/r_parse.pc pkgcfg/r_print.pc pkgcfg/r_th.pc pkgcfg/r_fs.pc ; do # SUBDIRS +for A in ./config-user.mk libr/include/r_userconf.h pkgcfg/r_io.pc pkgcfg/r_db.pc pkgcfg/r_magic.pc pkgcfg/r_asm.pc pkgcfg/r_bin.pc pkgcfg/r_anal.pc pkgcfg/r_hash.pc pkgcfg/r_cons.pc pkgcfg/r_diff.pc pkgcfg/r_core.pc pkgcfg/r_lang.pc pkgcfg/r_socket.pc pkgcfg/r_debug.pc pkgcfg/r_reg.pc pkgcfg/r_cmd.pc pkgcfg/r_config.pc pkgcfg/r_flags.pc pkgcfg/r_syscall.pc pkgcfg/r_sign.pc pkgcfg/r_util.pc pkgcfg/r_search.pc pkgcfg/r_bp.pc pkgcfg/r_lib.pc pkgcfg/r_parse.pc pkgcfg/r_print.pc pkgcfg/r_fs.pc ; do # SUBDIRS if [ -f "${VPATH}/${A}.acr" ]; then SD_TARGET=${A} else diff --git a/configure.acr b/configure.acr index c704b5c3dc..ad251bb557 100644 --- a/configure.acr +++ b/configure.acr @@ -132,6 +132,5 @@ SUBDIRS ./config-user.mk pkgcfg/r_lib.pc pkgcfg/r_parse.pc pkgcfg/r_print.pc - pkgcfg/r_th.pc pkgcfg/r_fs.pc ; diff --git a/libr/Makefile b/libr/Makefile index e572403d56..05aa9a2464 100644 --- a/libr/Makefile +++ b/libr/Makefile @@ -7,7 +7,7 @@ LFX=${DESTDIR}/${LIBDIR} IFX=${DESTDIR}/${INCLUDEDIR} PWD=$(shell pwd) -LIBS0=util hash th socket +LIBS0=util hash socket LIBS1=reg cons db magic lib diff bp search config LIBS2=syscall cmd lang io crypto flags bin LIBS3=fs anal diff --git a/libr/core/cmd_debug.c b/libr/core/cmd_debug.c index dec24a3e53..179ceeafdd 100644 --- a/libr/core/cmd_debug.c +++ b/libr/core/cmd_debug.c @@ -430,7 +430,6 @@ static void cmd_debug_reg(RCore *core, const char *str) { *arg = 0; r = r_reg_get (core->dbg->reg, str+1, R_REG_TYPE_GPR); if (r) { - //eprintf ("SET(%s)(%s)\n", str, arg+1); r_cons_printf ("0x%08"PFMT64x" ->", str, r_reg_get_value (core->dbg->reg, r)); r_reg_set_value (core->dbg->reg, r, @@ -448,10 +447,8 @@ static void cmd_debug_reg(RCore *core, const char *str) { *arg='\0'; size = atoi (arg); } else size = core->dbg->bits; - //eprintf ("ARG(%s)\n", str+1); type = r_reg_type_by_name (str+1); } - //printf("type = %d\nsize = %d\n", type, size); if (type != R_REG_TYPE_LAST) { r_debug_reg_sync (core->dbg, type, R_FALSE); r_debug_reg_list (core->dbg, type, size, str[0]=='*'); @@ -727,6 +724,7 @@ static int cmd_debug(void *data, const char *input) { r_cons_printf ("Usage: ds[ol] [count]\n" " ds step one instruction\n" " ds 4 step 4 instructions\n" + " dss 3 skip 3 step instructions\n" " dso 3 step over 3 instructions\n" " dsp step into program (skip libs)\n" " dsu addr step until address\n" @@ -761,6 +759,25 @@ static int cmd_debug(void *data, const char *input) { } } break; + case 's': + { + ut64 addr = r_debug_reg_get (core->dbg, "pc"); + r_reg_arena_swap (core->dbg->reg, R_TRUE); + for (i=0; idbg, R_REG_TYPE_GPR, R_FALSE); + r_io_read_at (core->io, addr, buf, sizeof (buf)); + r_anal_op (core->anal, &aop, addr, buf, sizeof (buf)); + if (aop.jump != UT64_MAX && aop.fail != UT64_MAX) { + eprintf ("Dont know how to skip this instruction\n"); + break; + } + addr += aop.length; + } + r_debug_reg_set (core->dbg, "pc", addr); + } + break; case 'o': r_reg_arena_swap (core->dbg->reg, R_TRUE); r_debug_step_over (core->dbg, times); diff --git a/libr/core/cmd_open.c b/libr/core/cmd_open.c index 526457fd03..ea1a0ea693 100644 --- a/libr/core/cmd_open.c +++ b/libr/core/cmd_open.c @@ -3,7 +3,9 @@ static int cmd_open(void *data, const char *input) { RCore *core = (RCore*)data; int perms = R_IO_READ; + RIOMap *map = NULL; RCoreFile *file; + RListIter *iter; int num = -1; ut64 addr; char *ptr; @@ -42,7 +44,6 @@ static int cmd_open(void *data, const char *input) { switch (input[1]) { case 'r': { - RIOMap *map; ut64 cur, new; const char *p = strchr (input+3, ' '); if (p) { @@ -56,7 +57,17 @@ static int cmd_open(void *data, const char *input) { map->from = new; map->to = new+diff; } else eprintf ("Cannot find any map here\n"); - } else eprintf ("Usage: omr [oldbase] [newbase]\n"); + } else { + cur = core->offset; + new = r_num_math (core->num, input+3); + map = r_io_map_resolve (core->io, core->file->fd->fd); + if (map) { + ut64 diff = map->to - map->from; + map->from = new; + map->to = new+diff; + } else eprintf ("Cannot find any map here\n"); + + } } break; case ' ': @@ -97,14 +108,10 @@ static int cmd_open(void *data, const char *input) { } break; case '\0': - { - RIOMap *im = NULL; - RListIter *iter; - r_list_foreach (core->io->maps, iter, im) { // _prev? + r_list_foreach (core->io->maps, iter, map) { // _prev? r_cons_printf ( - "%d +0x%08"PFMT64x" 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", - im->fd, im->delta, im->from, im->to); - } + "%d +0x%"PFMT64x" 0x%08"PFMT64x" - 0x%08"PFMT64x"\n", + (int)map->fd, (ut64)map->delta, (ut64)map->from, (ut64)map->to); } break; default: diff --git a/libr/core/cmd_print.c b/libr/core/cmd_print.c index debd73cdba..64650609f2 100644 --- a/libr/core/cmd_print.c +++ b/libr/core/cmd_print.c @@ -454,7 +454,7 @@ static int cmd_print(void *data, const char *input) { break; case 'W': for (i=0; iblock+i; + ut32 *p = (ut32*)core->block+i; r_cons_printf ("0x%08"PFMT64x" 0x%08x\n", core->offset+i, *p); } break; @@ -463,7 +463,7 @@ static int cmd_print(void *data, const char *input) { break; case 'Q': for (i=0; iblock+i; + ut64 *p = (ut64*)core->block+i; r_cons_printf ("0x%08"PFMT64x" 0x%016"PFMT64x"\n", core->offset+i, *p); } diff --git a/libr/core/file.c b/libr/core/file.c index 009c8d3de0..70d17c1861 100644 --- a/libr/core/file.c +++ b/libr/core/file.c @@ -162,13 +162,16 @@ R_API int r_core_bin_load(RCore *r, const char *file) { } } r_bin_select (r->bin, r->assembler->cur->arch, r->assembler->bits, NULL);//"x86_32"); + { RIOMap *im; RListIter *iter; /* Fix for fat bins */ r_list_foreach (r->io->maps, iter, im) { - im->delta = r->bin->cur.offset; - im->to = im->from + r->bin->cur.size; + if (r->bin->cur.size > 0) { + im->delta = r->bin->cur.offset; + im->to = im->from + r->bin->cur.size; + } } } } else if (!r_bin_load (r->bin, file, R_TRUE)) diff --git a/libr/th/Makefile b/libr/th/Makefile deleted file mode 100644 index 719a348a57..0000000000 --- a/libr/th/Makefile +++ /dev/null @@ -1,10 +0,0 @@ -include ../config.mk - -NAME=r_th -DEPS= - -LDFLAGS=${TH_LIBS} - -OBJS=th.o lock.o - -include ../rules.mk diff --git a/libr/th/TODO b/libr/th/TODO deleted file mode 100644 index 4e9dc00be1..0000000000 --- a/libr/th/TODO +++ /dev/null @@ -1,21 +0,0 @@ -R_TH :: TODO -============ - -* implement non-threaded thread api (dummy one, when no support) -* test w32 port -* Implement a pure clone(2) backend -* Added a threading pool super-api - -/* pools */ - -R_API void r_th_pool_init(struct r_th_pool_t *thp, int threads, int size) -{ - /* TODO: use a thread pool to handle a list of 'size' tasks */ -} - -R_API struct r_th_pool_t *r_th_pool_new(int threads, int size) -{ - struct r_th_pool_t *thp = R_NEW(struct r_th_pool_t); - r_th_pool_init(thp, threads, size); - return thp; -} diff --git a/libr/th/t/Makefile b/libr/th/t/Makefile deleted file mode 100644 index b79dc6e811..0000000000 --- a/libr/th/t/Makefile +++ /dev/null @@ -1,5 +0,0 @@ -OBJ=test.o -BIN=test -BINDEPS=r_th r_util - -include ../../rules.mk diff --git a/libr/th/task.c b/libr/th/task.c deleted file mode 100644 index 4e22905c48..0000000000 --- a/libr/th/task.c +++ /dev/null @@ -1,59 +0,0 @@ -/* radare - LGPL - Copyright 2010 pancake */ -// XXX: Must be implemented -// Launch thread if requested -// Support multiple group of tasks (more than one core f.ex) -// - -#include -#define RTask int - -#define MAXTASKS (sizeof (int)) - -static int tasks; - -void int r_task_new(int t, int ) { - if (tasks & flags) - return -1; - tasks |= flags; - return flags; -} - -R_API int r_task_wait(int t) { -} - -R_API int r_task_step(int t) { - // check and lock if cant continue or stop if cancelled -} - -R_API int r_task_stop(int t) { - -} - -R_API int r_task_pause() { -} - -R_API int r_task_finish() { -} - -R_API int r_task_check() { -} - -#ifdef TEST -#define T_FLAGS 1 -#define T_SEARCH 2 - -void task1() { - RTask t = r_task_new (foo1); - for (;;) { - if (!r_task_step (t) && !r_task_wait (t)) { - r_task_kill (t); - return; - } - } -} - -int main() { - - return 0; -} -#endif diff --git a/libr/util/Makefile b/libr/util/Makefile index 7592889683..2d446992eb 100644 --- a/libr/util/Makefile +++ b/libr/util/Makefile @@ -7,7 +7,7 @@ OBJS=mem.o pool.o num.o str.o hex.o file.o alloca.o range.o log.o OBJS+=prof.o cache.o sys.o buf.o w32-sys.o base64.o base85.o name.o OBJS+=list.o flist.o ht.o ht64.o mixed.o btree.o chmod.o graph.o OBJS+=regex/regcomp.o regex/regerror.o regex/regexec.o uleb128.o -OBJS+=sandbox.o calc.o +OBJS+=sandbox.o calc.o thread.o lock.o # DO NOT BUILD r_big api (not yet used and its buggy) ifeq (1,0) @@ -23,6 +23,7 @@ endif endif LDFLAGS+=${BN_LIBS} +LDFLAGS=${TH_LIBS} include ../rules.mk diff --git a/libr/th/lock.c b/libr/util/lock.c similarity index 96% rename from libr/th/lock.c rename to libr/util/lock.c index 8b4e297829..c405aa2076 100644 --- a/libr/th/lock.c +++ b/libr/util/lock.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009 pancake<@nopcode.org> */ +/* radare - LGPL - Copyright 2009-2012 - pancake */ #include diff --git a/libr/th/t/test.c b/libr/util/t/threads.c similarity index 100% rename from libr/th/t/test.c rename to libr/util/t/threads.c diff --git a/libr/th/th.c b/libr/util/thread.c similarity index 97% rename from libr/th/th.c rename to libr/util/thread.c index 07fb400415..a05a2d858e 100644 --- a/libr/th/th.c +++ b/libr/util/thread.c @@ -1,4 +1,4 @@ -/* radare - LGPL - Copyright 2009-2010 pancake<@nopcode.org> */ +/* radare - LGPL - Copyright 2009-2012 - pancake */ #include diff --git a/pkgcfg/r_th.pc.acr b/pkgcfg/r_th.pc.acr deleted file mode 100644 index d4b03b8010..0000000000 --- a/pkgcfg/r_th.pc.acr +++ /dev/null @@ -1,11 +0,0 @@ -prefix=@PREFIX@ -exec_prefix=${prefix} -libdir=@LIBDIR@ -includedir=${prefix}/include - -Name: r_th -Description: radare foundation libraries -Version: @VERSION@ -Requires: -Libs: -L${libdir} -lr_th -Cflags: -I${includedir}/libr