Add --with-new-io-cache configure and meson flags ##build

* That's an ABI breaking change optimizing io.cache=1
This commit is contained in:
pancake 2023-03-14 15:29:53 +01:00 committed by GitHub
parent 1de7776d2f
commit cf004aff20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 190 additions and 64 deletions

View File

@ -84,6 +84,28 @@ jobs:
# r2pm -gci muon # installs samurai as dependency
# ./preconfigure
# XXX muon setup m && samu -C m -j5
try-new-cache:
name: try-new-cache
runs-on: ubuntu-20.04
continue-on-error: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install meson ninja r2pipe wget
sudo apt install gperf
- name: Installing with symlinks
run: |
export CFLAGS="-O0 -Werror -Wno-unused-result -Wno-stringop-truncation"
sys/install.sh --with-new-io-cache
- name: Running tests
run: r2r -o /tmp/r2r.json test/db/cmd
- uses: actions/upload-artifact@v3
with:
name: r2r.json
path: /tmp/r2r.json
build-acr-gperf:
name: linux-acr-gperf
runs-on: ubuntu-20.04

View File

@ -20,6 +20,7 @@ WANT_DYLINK=@WANT_DYLINK@
WANT_CAPSTONE=@WANT_CAPSTONE@
WITH_STATIC_THEMES=@WITH_STATIC_THEMES@
WITH_LIBR=@WITH_LIBR@
NEW_IO_CACHE=@NEW_IO_CACHE@
ifeq ($(USE_RPATH),1)
LDFLAGS_RPATH=-Wl,-rpath,"${LIBDIR}"

13
configure vendored
View File

@ -1,5 +1,5 @@
#!/bin/sh
# This script was automatically generated by ACR v2.1.0
# This script was automatically generated by ACR v2.1.1
# @author: pancake <nopcode.org>
# @url: http://www.nopcode.org
# @repo: git clone https://github.com/radare/acr
@ -28,6 +28,7 @@ HAVE_FORK=1
WANT_PTRACE_WRAP=1
WANT_GPERF=1
WANT_CAPSTONE=1
NEW_IO_CACHE=0
WITH_LIBR=0
WITH_STATIC_THEMES=0
USE_CS5=0
@ -199,6 +200,7 @@ Optional Features:
--without-ptrace-wrap build ptrace-wrap support needed for the iaito debugger on Linux
--without-gperf do not statically link the sdb databases even if gperf is found
--without-capstone dont build the capstone dependency
--with-new-io-cache an *abi break* option to use rbtree instead of skyline
--with-libr build libr.a and libr.dylib
--with-static-themes default themes are compiled and fallback if not available on disk
--with-capstone5 build next branch of capstone5 (default)
@ -256,7 +258,7 @@ if [ "$QUIET" = 1 ]; then
echo "5.8.3"
exit 0
fi
echo "radare2-5.8.3 configuration script done with acr v2.1.0.
echo "radare2-5.8.3 configuration script done with acr v2.1.1.
The 'Free Software Foundation' message is only for autodetection.
Originally written by pancake <nopcode.org>."
exit 0
@ -293,7 +295,7 @@ echo "LANGS: c"
echo "REQUIRED: libdl"
echo "OPTIONAL: libmagic libz libzip libxxhash libssl liblibuv>=1.0.0"
echo "PKGCONFIG: capstone liblz4 openssl libuv"
echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disable-loadlibs --enable-threadsafety --without-dylink --without-fork --without-ptrace-wrap --without-gperf --without-capstone --with-libr --with-static-themes --with-capstone5 --with-capstone4 --with-syscapstone --with-syslz4 --with-syszip --with-sysxxhash --without-gpl --with-ssl --with-ssl-crypto --with-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --with-checks-level=2"
echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disable-loadlibs --enable-threadsafety --without-dylink --without-fork --without-ptrace-wrap --without-gperf --without-capstone --with-new-io-cache --with-libr --with-static-themes --with-capstone5 --with-capstone4 --with-syscapstone --with-syslz4 --with-syszip --with-sysxxhash --without-gpl --with-ssl --with-ssl-crypto --with-libuv --with-rpath --with-compiler=gcc --with-ostype=auto --with-libversion=xxx --without-jemalloc --with-checks-level=2"
exit 0
;;
--cache-file)
@ -355,6 +357,7 @@ echo "FLAGS: --disable-debugger --with-sysmagic --disable-threads --disabl
"--without-ptrace-wrap") WANT_PTRACE_WRAP="0"; ;;
"--without-gperf") WANT_GPERF="0"; ;;
"--without-capstone") WANT_CAPSTONE="0"; ;;
"--with-new-io-cache") NEW_IO_CACHE="1"; ;;
"--with-libr") WITH_LIBR="1"; ;;
"--with-static-themes") WITH_STATIC_THEMES="1"; ;;
"--with-capstone5") USE_CS5="1"; ;;
@ -390,7 +393,7 @@ parse_options "$1"
shift
done
ENVWORDS="MANDIR DESCRIPTION INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR ETCDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGCFG_LIBDIR PKGCFG_INCDIR PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS PKGCONFIG HAVE_PATCH PATCH HAVE_AR AR HAVE_GIT GIT HAVE_GPERF GPERF HAVE_LIB_MAGIC HAVE_LINUX_CAN_H USE_MAGIC USE_LIB_MAGIC LIBMAGIC WANT_THREADS LOADLIBS R_CRITICAL_ENABLED WANT_DYLINK HAVE_FORK WANT_PTRACE_WRAP WANT_GPERF WANT_CAPSTONE WITH_LIBR WITH_STATIC_THEMES USE_CS5 USE_CS4 WITH_CAPSTONE CAPSTONE_CFLAGS CAPSTONE_LDFLAGS HAVE_PKGCFG_CAPSTONE USE_CAPSTONE LZ4_CFLAGS LZ4_LDFLAGS HAVE_PKGCFG_LIBLZ4 WITH_SYSLZ4 USE_SYSLZ4 HAVE_LIB_Z HAVE_LIB_ZIP USE_ZIP USE_LIB_ZIP LIBZIP HAVE_LIB_XXHASH USE_XXHASH USE_LIB_XXHASH LIBXXHASH WITH_GPL HAVE_DECL_ADDR_NO_RANDOMIZE HAVE_DECL___GLIBC__ HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_CLOCK_NANOSLEEP HAVE_SIGACTION HAVE_CLOCK_GETTIME CLOCK_LDFLAGS SUPPORT_GNU99 HAVE_LIB_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL WANT_SSL WANT_SSL_CRYPTO WANT_LIBUV HAVE_LIBUV_VERSION_1_0_0 LIBUV_CFLAGS LIBUV_LDFLAGS HAVE_PKGCFG_LIBUV HAVE_LIBUV USE_RPATH USERCC USEROSTYPE LIBVERSION HAVE_JEMALLOC HAVE_PTRACE USE_PTRACE_WRAP R_CHECKS_LEVEL"
ENVWORDS="MANDIR DESCRIPTION INFODIR LIBDIR INCLUDEDIR LOCALSTATEDIR ETCDIR SYSCONFDIR DATADIR DOCDIR LIBEXECDIR SBINDIR BINDIR EPREFIX PREFIX SPREFIX TARGET HOST BUILD INSTALL INSTALL_LIB INSTALL_MAN INSTALL_PROGRAM INSTALL_PROGRAM_STRIP INSTALL_DIR INSTALL_SCRIPT INSTALL_DATA HOST_OS HOST_CPU BUILD_OS BUILD_CPU TARGET_OS TARGET_CPU VERSION VERSION_MAJOR VERSION_MINOR VERSION_PATCH VERSION_NUMBER PKGCFG_LIBDIR PKGCFG_INCDIR PKGNAME VPATH CONTACT CONTACT_NAME CONTACT_MAIL CC CFLAGS CPPFLAGS LDFLAGS HAVE_LANG_C DEBUGGER HAVE_LIB_DL DL_LIBS PKGCONFIG HAVE_PATCH PATCH HAVE_AR AR HAVE_GIT GIT HAVE_GPERF GPERF HAVE_LIB_MAGIC HAVE_LINUX_CAN_H USE_MAGIC USE_LIB_MAGIC LIBMAGIC WANT_THREADS LOADLIBS R_CRITICAL_ENABLED WANT_DYLINK HAVE_FORK WANT_PTRACE_WRAP WANT_GPERF WANT_CAPSTONE NEW_IO_CACHE WITH_LIBR WITH_STATIC_THEMES USE_CS5 USE_CS4 WITH_CAPSTONE CAPSTONE_CFLAGS CAPSTONE_LDFLAGS HAVE_PKGCFG_CAPSTONE USE_CAPSTONE LZ4_CFLAGS LZ4_LDFLAGS HAVE_PKGCFG_LIBLZ4 WITH_SYSLZ4 USE_SYSLZ4 HAVE_LIB_Z HAVE_LIB_ZIP USE_ZIP USE_LIB_ZIP LIBZIP HAVE_LIB_XXHASH USE_XXHASH USE_LIB_XXHASH LIBXXHASH WITH_GPL HAVE_DECL_ADDR_NO_RANDOMIZE HAVE_DECL___GLIBC__ HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_CLOCK_NANOSLEEP HAVE_SIGACTION HAVE_CLOCK_GETTIME CLOCK_LDFLAGS SUPPORT_GNU99 HAVE_LIB_GMP HAVE_LIB_SSL SSL_CFLAGS SSL_LDFLAGS HAVE_PKGCFG_OPENSSL HAVE_OPENSSL WANT_SSL WANT_SSL_CRYPTO WANT_LIBUV HAVE_LIBUV_VERSION_1_0_0 LIBUV_CFLAGS LIBUV_LDFLAGS HAVE_PKGCFG_LIBUV HAVE_LIBUV USE_RPATH USERCC USEROSTYPE LIBVERSION HAVE_JEMALLOC HAVE_PTRACE USE_PTRACE_WRAP R_CHECKS_LEVEL"
create_environ
@ -976,7 +979,7 @@ do_remove
if [ "$QUIET" = 0 ]; then
echo
echo "Final report:"
for A in BUILD CC CFLAGS DEBUGGER HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_FORK HAVE_GPERF HAVE_LIBUV HAVE_LIB_GMP HAVE_OPENSSL WANT_SSL_CRYPTO HAVE_PTRACE HOST LDFLAGS LIBVERSION PKGCONFIG PREFIX R_CHECKS_LEVEL TARGET USERCC USEROSTYPE USE_CAPSTONE USE_LIB_MAGIC USE_LIB_XXHASH USE_LIB_ZIP USE_PTRACE_WRAP USE_SYSLZ4 VERSION WANT_DYLINK ; do
for A in BUILD CC CFLAGS DEBUGGER HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO HAVE_EXPLICIT_MEMSET HAVE_FORK HAVE_GPERF HAVE_LIBUV HAVE_LIB_GMP HAVE_OPENSSL WANT_SSL_CRYPTO HAVE_PTRACE HOST LDFLAGS LIBVERSION PKGCONFIG PREFIX R_CHECKS_LEVEL TARGET USERCC USEROSTYPE USE_CAPSTONE USE_LIB_MAGIC NEW_IO_CACHE USE_LIB_XXHASH USE_LIB_ZIP USE_PTRACE_WRAP USE_SYSLZ4 VERSION WANT_DYLINK ; do
eval VAL="\$${A}"
[ -z "${VAL}" ] && VAL="\"\""
echo " - ${A} = ${VAL}"

View File

@ -40,6 +40,8 @@ ARG_WITHOUT WANT_PTRACE_WRAP ptrace-wrap build ptrace-wrap support needed for th
ARG_WITHOUT WANT_GPERF gperf do not statically link the sdb databases even if gperf is found ;
ARG_WITHOUT WANT_CAPSTONE capstone dont build the capstone dependency ;
ARG_WITH NEW_IO_CACHE new-io-cache an *abi break* option to use rbtree instead of skyline ;
IFNOT WANT_GPERF {
HAVE_GPERF = 0 ;
}
@ -280,7 +282,7 @@ REPORT
BUILD CC CFLAGS DEBUGGER HAVE_ARC4RANDOM_UNIFORM HAVE_EXPLICIT_BZERO
HAVE_EXPLICIT_MEMSET HAVE_FORK HAVE_GPERF HAVE_LIBUV HAVE_LIB_GMP
HAVE_OPENSSL WANT_SSL_CRYPTO HAVE_PTRACE HOST LDFLAGS LIBVERSION PKGCONFIG PREFIX
R_CHECKS_LEVEL TARGET USERCC USEROSTYPE USE_CAPSTONE USE_LIB_MAGIC
R_CHECKS_LEVEL TARGET USERCC USEROSTYPE USE_CAPSTONE USE_LIB_MAGIC NEW_IO_CACHE
USE_LIB_XXHASH USE_LIB_ZIP USE_PTRACE_WRAP USE_SYSLZ4 VERSION WANT_DYLINK
;

View File

@ -1,10 +1,7 @@
/* radare - LGPL - Copyright 2011-2022 - earada, pancake */
/* radare - LGPL - Copyright 2011-2023 - earada, pancake */
#define R_LOG_ORIGIN "core.bin"
#include <r_core.h>
#include <r_config.h>
#include <r_util.h>
#include <r_util/r_time.h>
#define is_in_range(at, from, sz) ((at) >= (from) && (at) < ((from) + (sz)))
@ -1832,7 +1829,12 @@ static int bin_relocs(RCore *r, PJ *pj, int mode, int va) {
return false;
}
if (bin_cache) {
if (r_pvector_length (&r->io->cache) == 0) {
#if USE_NEW_IO_CACHE_API
bool cache_is_empty = r_pvector_length (r->io->cache->vec) == 0;
#else
bool cache_is_empty = r_pvector_length (&r->io->cache) == 0;
#endif
if (cache_is_empty) {
r_config_set_b (r->config, "io.cache", false);
} else {
r_config_set_b (r->config, "io.cache.read", true);

View File

@ -1,4 +1,4 @@
/* radare - LGPL - Copyright 2009-2022 - pancake */
/* radare - LGPL - Copyright 2009-2023 - pancake */
#include <r_core.h>
@ -761,6 +761,9 @@ static int cmd_wf(void *data, const char *input) {
}
static void squash_write_cache(RCore *core, const char *input) {
#if USE_NEW_IO_CACHE_API
R_LOG_TODO ("Squash is not implemented for the for the new io-cache");
#else
void **iter;
RPVector *v = &core->io->cache;
ut64 end = UT64_MAX;
@ -786,14 +789,13 @@ static void squash_write_cache(RCore *core, const char *input) {
R_LOG_INFO ("Squashed %d write caches", squashed);
// r_pvector_clear (&core->io->cache);
memcpy (&(core->io->cache), nv, sizeof (RIOCache));
#endif
}
static void cmd_write_pcache(RCore *core, const char *input) {
RIODesc *desc;
RIOCache *c;
RList *caches;
RListIter *iter;
int fd, i;
int fd;
bool rad = false;
if (core && core->io && core->io->p_cache && core->print && core->print->cb_printf) {
switch (input[0]) {
@ -817,6 +819,12 @@ static void cmd_write_pcache(RCore *core, const char *input) {
desc = core->io->desc;
}
if ((caches = r_io_desc_cache_list (desc))) {
#if USE_NEW_IO_CACHE_API
R_LOG_TODO ("pcache listing not working for the new io-cache (%d)", rad);
#else
int i;
RIOCache *c;
RListIter *iter;
if (rad) {
core->print->cb_printf ("e io.va = false\n");
r_list_foreach (caches, iter, c) {
@ -842,6 +850,7 @@ static void cmd_write_pcache(RCore *core, const char *input) {
core->print->cb_printf ("\n");
}
}
#endif
r_list_free (caches);
}
break;
@ -1315,6 +1324,7 @@ static char *__current_filename(RCore *core) {
return NULL;
}
#if !USE_NEW_IO_CACHE_API
static ut64 __va2pa(RCore *core, ut64 va) {
RIOMap *map = r_io_map_get_at (core->io, va);
if (map) {
@ -1322,6 +1332,7 @@ static ut64 __va2pa(RCore *core, ut64 va) {
}
return va;
}
#endif
static void cmd_wcf(RCore *core, const char *dfn) {
char *sfn = __current_filename (core);
@ -1332,6 +1343,9 @@ static void cmd_wcf(RCore *core, const char *dfn) {
size_t sfs;
ut8 *sfb = (ut8*)r_file_slurp (sfn, &sfs);
if (sfb) {
#if USE_NEW_IO_CACHE_API
R_LOG_TODO ("wcf not supported yet with the new io cache");
#else
void **iter;
r_pvector_foreach (&core->io->cache, iter) {
RIOCache *c = *iter;
@ -1344,6 +1358,7 @@ static void cmd_wcf(RCore *core, const char *dfn) {
R_LOG_ERROR ("Out of bounds patch at 0x%08"PFMT64x, pa);
}
}
#endif
// patch buffer
r_file_dump (dfn, sfb, sfs, false);
free (sfb);
@ -1352,6 +1367,9 @@ static void cmd_wcf(RCore *core, const char *dfn) {
}
static void wcu(RCore *core) {
#if USE_NEW_IO_CACHE_API
R_LOG_WARN ("wcu not implemented for the new io-cache-api");
#else
void **iter;
RIO *io = core->io;
r_pvector_foreach_prev (&io->cache, iter) {
@ -1373,6 +1391,7 @@ static void wcu(RCore *core) {
c = *iter;
r_skyline_add (&io->cache_skyline, c->itv, c);
}
#endif
}
static int cmd_wc(void *data, const char *input) {

View File

@ -4197,6 +4197,7 @@ static inline bool is_filtered_flag(RDisasmState *ds, const char *name) {
/* convert numeric value in opcode to ascii char or number */
static void ds_print_ptr(RDisasmState *ds, int len, int idx) {
r_return_if_fail (ds);
RCore *core = ds->core;
const bool be = R_ARCH_CONFIG_IS_BIG_ENDIAN (core->rasm->config);
ut64 p = ds->analop.ptr;
@ -7181,6 +7182,9 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) {
}
}
REsil *esil = core->anal->esil;
#if USE_NEW_IO_CACHE_API
r_io_cache_init (core->io);
#else
RPVector ocache = core->io->cache;
const int ocached = core->io->cached;
if (ocache.v.a) {
@ -7191,6 +7195,7 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) {
} else {
r_io_cache_init (core->io);
}
#endif
r_reg_arena_push (reg);
RConfigHold *chold = r_config_hold_new (core->config);
r_config_hold (chold, "io.cache", "asm.lines", NULL);
@ -7290,6 +7295,9 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) {
}
free (buf);
r_reg_arena_pop (reg);
#if USE_NEW_IO_CACHE_API
R_LOG_TODO ("new-io-cache doesnt rollbacks yet");
#else
int len = r_pvector_length (&ocache);
if (r_pvector_length (&core->io->cache) > len) {
// TODO: Implement push/pop for IO.cache
@ -7308,6 +7316,7 @@ R_API int r_core_disasm_pde(RCore *core, int nb_opcodes, int mode) {
r_skyline_add (&core->io->cache_skyline, c->itv, c);
}
core->io->cached = ocached;
#endif
r_config_hold_restore (chold);
r_config_hold_free (chold);
return i;

View File

@ -10,7 +10,9 @@
#include "r_skyline.h"
#include <r_util/r_w32dw.h>
#ifndef USE_NEW_IO_CACHE_API
#define USE_NEW_IO_CACHE_API 0
#endif
#define R_IO_SEEK_SET 0
#define R_IO_SEEK_CUR 1
@ -253,12 +255,22 @@ typedef struct r_io_bank_t {
bool drain_me; // speedup r_io_nread_at
} RIOBank;
#if USE_NEW_IO_CACHE_API
typedef struct io_cache_item_t {
RInterval *tree_itv;
RInterval itv;
ut8 *data;
ut8 *odata; //is this a good idea?
} RIOCacheItem;
#else
typedef struct r_io_cache_t {
RInterval itv;
ut8 *data;
ut8 *odata;
int written;
} RIOCache;
#endif
#define R_IO_DESC_CACHE_SIZE (sizeof (ut64) * 8)
typedef struct r_io_desc_cache_t {
@ -522,10 +534,9 @@ R_API bool r_io_cache_write_at(RIO *io, ut64 addr, const ut8 *buf, int len);
R_API bool r_io_cache_read_at(RIO *io, ut64 addr, ut8 *buf, int len);
R_API RIOCache *r_io_cache_clone(RIO *io);
R_API void r_io_cache_replace(RIO *io, RIOCache *cache);
#else
#endif
R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len);
R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len);
#endif
/* io/p_cache.c */

View File

@ -1,10 +1,9 @@
/* radare - LGPL - Copyright 2008-2021 - pancake */
/* radare - LGPL - Copyright 2008-2023 - pancake, condret */
#include <r_io.h>
#include <r_skyline.h>
#if USE_NEW_IO_CACHE_API
#else
#if !USE_NEW_IO_CACHE_API
static void cache_item_free(RIOCache *cache) {
if (cache) {
@ -150,7 +149,7 @@ R_API bool r_io_cache_list(RIO *io, int rad) {
}
R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) {
r_return_val_if_fail (io && buf, false);
r_return_val_if_fail (io && buf && len > 0, false);
RIOCache *ch = R_NEW0 (RIOCache);
if (!ch) {
return false;
@ -188,7 +187,7 @@ R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) {
}
R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
r_return_val_if_fail (io && buf, false);
r_return_val_if_fail (io && buf && len > 0, false);
RSkyline *skyline = &io->cache_skyline;
const RSkylineItem *iter = r_skyline_get_item_intersect (skyline, addr, len);
if (!iter) {
@ -196,9 +195,11 @@ R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
}
const RSkylineItem *last = (RSkylineItem *)skyline->v.a + skyline->v.len;
bool covered = false;
int count = 0;
while (iter != last) {
const ut64 begin = r_itv_begin (iter->itv);
const ut64 end = r_itv_end (iter->itv);
count++;
if (end < addr) {
iter++;
continue;
@ -228,35 +229,39 @@ R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
iter++;
continue;
}
if (count > 32) {
break;
}
// eprintf ("inrange (%llx %d)\n", begin, (int)(end - begin));
if (read > 0) {
memcpy (buf + buf_offset, cache->data + cache_offset, read);
}
covered = true;
iter++;
}
#if 0
eprintf ("COUNT %d (0x%llx %d)\n", count, addr, len);
if (count > 45000) {
r_sys_breakpoint ();
}
#endif
return covered;
}
#endif
#if USE_NEW_IO_CACHE_API
typedef struct io_cache_item_t {
RInterval *tree_itv;
RInterval itv;
ut8 *data;
ut8 *odata; //is this a good idea?
} IOCacheItem;
#else
// USE_NEW_IO_CACHE_API
IOCacheItem * _io_cache_item_new (RInterval *itv) {
IOCacheItem *ci = R_NEW0 (IOCacheItem);
R_API RIOCacheItem * _io_cache_item_new(RInterval *itv) {
RIOCacheItem *ci = R_NEW0 (RIOCacheItem);
if (!ci) {
return NULL;
}
ci->data = R_NEWS (ut8, itv->len);
ci->data = R_NEWS (ut8, itv->size);
if (!ci->data) {
free (ci);
return NULL;
}
ci->odata = R_NEWS (ut8, itv->len);
ci->odata = R_NEWS (ut8, itv->size);
if (!ci->odata) {
free (ci->data);
free (ci);
@ -273,8 +278,8 @@ IOCacheItem * _io_cache_item_new (RInterval *itv) {
return ci;
}
void _io_cache_item_free (void *data) {
IOCacheItem *ci = (IOCacheItem *)data;
void _io_cache_item_free(void *data) {
RIOCacheItem *ci = (RIOCacheItem *)data;
if (ci) {
free (ci->tree_itv);
free (ci->data);
@ -312,7 +317,7 @@ R_API void r_io_cache_reset(RIO *io, int set) {
static int _find_lowest_intersection_ci_cb(void *incoming, void *in, void *user) {
RInterval *itv = (RInterval *)incoming;
IOCacheItem *ci = (IOCacheItem *)in;
RIOCacheItem *ci = (RIOCacheItem *)in;
if (r_itv_overlap (itv[0], ci->tree_itv[0])) {
return 0;
}
@ -329,7 +334,7 @@ static RRBNode *_find_entry_ci_node(RRBTree *caache_tree, RInterval *itv) {
return NULL;
}
RRBNode *prev = r_rbnode_prev (node);
while (prev && r_itv_overlap (itv[0], ((IOCacheItem *)(prev->data))->tree_itv[0])) {
while (prev && r_itv_overlap (itv[0], ((RIOCacheItem *)(prev->data))->tree_itv[0])) {
node = prev;
prev = r_rbnode_prev (node);
}
@ -337,7 +342,7 @@ static RRBNode *_find_entry_ci_node(RRBTree *caache_tree, RInterval *itv) {
}
static int _ci_start_cmp_cb(void *incoming, void *in, void *user) {
IOCacheItem *incoming_ci = (IOCacheItem *)incoming, *in_ci = (IOCacheItem *)in;
RIOCacheItem *incoming_ci = (RIOCacheItem *)incoming, *in_ci = (RIOCacheItem *)in;
if (incoming_ci->tree_itv->addr < in_ci->tree_itv->addr) {
return -1;
}
@ -347,10 +352,14 @@ static int _ci_start_cmp_cb(void *incoming, void *in, void *user) {
return 0;
}
R_API bool r_io_cache_write_at(RIO *io, ut64 addr, ut8 *buf, int len) {
R_API bool r_io_cache_write(RIO *io, ut64 addr, const ut8 *buf, int len) {
return r_io_cache_write_at (io, addr, buf, len);
}
R_API bool r_io_cache_write_at(RIO *io, ut64 addr, const ut8 *buf, int len) {
r_return_val_if_fail (io && buf && (len > 0), false);
RInterval itv = (RInterval){addr, len};
IOCacheItem *ci = _io_cache_item_new (&itv);
RIOCacheItem *ci = _io_cache_item_new (&itv);
if (!ci) {
return false;
}
@ -358,17 +367,17 @@ R_API bool r_io_cache_write_at(RIO *io, ut64 addr, ut8 *buf, int len) {
memcpy (ci->data, buf, len);
RRBNode *node = _find_entry_ci_node (io->cache->tree, &itv);
if (node) {
IOCacheItem *_ci = (IOCacheItem *)node->data;
RIOCacheItem *_ci = (RIOCacheItem *)node->data;
if (itv.addr > _ci->tree_itv->addr) {
_ci->tree_itv->size = itv.addr - _ci->tree_itv->addr;
node = r_rbnode_next (node);
_ci = node? (IOCacheItem *)node->data: NULL;
_ci = node? (RIOCacheItem *)node->data: NULL;
}
while (_ci && r_itv_include (itv, _ci->tree_itv[0])) {
node = r_rbnode_next (node);
r_crbtree_delete (io->cache->tree, _ci, _ci_start_cmp_cb, NULL);
R_FREE (_ci->tree_itv);
_ci = node? (IOCacheItem *)node->data: NULL;
_ci = node? (RIOCacheItem *)node->data: NULL;
}
if (_ci && r_itv_contain (itv, _ci->tree_itv->addr)) {
_ci->tree_itv->size = r_itv_end (_ci->tree_itv[0]) - r_itv_end (itv);
@ -380,19 +389,43 @@ R_API bool r_io_cache_write_at(RIO *io, ut64 addr, ut8 *buf, int len) {
return true;
}
// R2_590 deprecate and use the _at method directly
R_API bool r_io_cache_read(RIO *io, ut64 addr, ut8 *buf, int len) {
return r_io_cache_read_at (io, addr, buf, len);
}
R_API bool r_io_cache_read_at(RIO *io, ut64 addr, ut8 *buf, int len) {
r_return_val_if_fail (io && buf && (len > 0), false);
RInterval itv = (RInterval){addr, len};
RRBNode *node = _find_entry_ci_node (io->cache->tree, &itv);
IOCacheItem *ci = node? (IOCacheItem *)node->data: NULL;
RIOCacheItem *ci = node? (RIOCacheItem *)node->data: NULL;
const bool ret = !!ci;
while (ci && r_itv_overlap (ci->tree_itv[0], itv)) {
node = r_rbnode_next (node);
RInterval its = r_itv_intersect (ci->tree_itv[0], itv);
memcpy (&buf[addr - r_itv_begin (its)],
&ci->data[r_itv_begin (its) - r_itv_begin (ci->itv)],
r_itv_size (its));
ci = node? (IOCacheItem *)node->data: NULL;
int itvlen = R_MIN (r_itv_size (its), r_itv_size (ci->itv));
if (r_itv_begin (its) > addr) {
// R_LOG_ERROR ("io-cache missfeature");
ut64 aa = addr;
// ut64 as = len;
ut64 ba = r_itv_begin (its);
ut64 bs = r_itv_size (its);
// ut64 ca = r_itv_begin (ci->itv);
// ut64 cs = r_itv_size (ci->itv);
// eprintf ("%llx %llx - %llx %llx - %llx %llx\n", aa, as, ba, bs, ca, cs);
int delta = (ba - aa);
if (delta + bs > len) {
itvlen = len - delta;
}
memcpy (buf + (ba - aa), ci->data, itvlen);
// r_sys_breakpoint ();
} else {
st64 offa = addr - r_itv_begin (its);
st64 offb = r_itv_begin (its) - r_itv_begin (ci->itv);
// eprintf ("OFFA (addr %llx iv %llx) %llx %llx\n", addr, r_itv_begin (its), offa, offb);
memcpy (buf + offa, ci->data + offb, itvlen);
}
ci = node? (RIOCacheItem *)node->data: NULL;
}
return ret;
}
@ -404,13 +437,13 @@ R_API bool r_io_cache_at(RIO *io, ut64 addr) {
}
// this uses closed boundary input
R_API ut32 r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) {
R_API int r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) {
r_return_val_if_fail (io && from <= to, 0);
RInterval itv = (RInterval){from, (to + 1) - from};
void **iter;
ut32 invalidated_cache_bytes = 0;
r_pvector_foreach_prev (io->cache->vec, iter) {
IOCacheItem *ci = (IOCacheItem *)*iter;
RIOCacheItem *ci = (RIOCacheItem *)*iter;
if (!r_itv_overlap (itv, ci->itv)) {
continue;
}
@ -423,11 +456,11 @@ R_API ut32 r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) {
continue;
}
if (r_itv_include (ci->itv, itv)) {
IOCacheItem *_ci = _io_cache_item_new (
(RInterval){r_itv_end (itv), r_itv_end (ci->itv) - r_itv_end (itv)});
RInterval iitv = (RInterval){r_itv_end (itv), r_itv_end (ci->itv) - r_itv_end (itv)};
RIOCacheItem *_ci = _io_cache_item_new (&iitv);
memcpy (_ci->data, &ci->data[r_itv_end (itv) - r_itv_begin (ci->itv)], r_itv_size (_ci->itv));
memcpy (_ci->odata, &ci->odata[r_itv_end (itv) - r_itv_begin (ci->itv)], r_itv_size (_ci->itv));
ci->itv.size = itv.addr - ci->itv;
ci->itv.size = itv.addr - ci->itv.addr;
ci->data = realloc (ci->data, (size_t)r_itv_size (ci->itv));
ci->odata = realloc (ci->odata, (size_t)r_itv_size (ci->itv));
if (ci->tree_itv) {
@ -453,7 +486,7 @@ R_API ut32 r_io_cache_invalidate(RIO *io, ut64 from, ut64 to) {
continue;
}
if (r_itv_begin (ci->itv) < r_itv_begin (itv)) {
ci->itv.size = itv.addr - ci->itv;
ci->itv.size = itv.addr - ci->itv.addr;
ci->data = realloc (ci->data, (size_t)r_itv_size (ci->itv));
ci->odata = realloc (ci->odata, (size_t)r_itv_size (ci->itv));
if (ci->tree_itv) {
@ -496,7 +529,7 @@ R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) {
if (from == 0LL && to == UT64_MAX) {
RRBNode *node = r_crbtree_first_node (io->cache->tree);
while (node) {
IOCacheItem *ci = (IOCacheItem *)node->data;
RIOCacheItem *ci = (RIOCacheItem *)node->data;
node = r_rbnode_next (node);
r_io_bank_write_at (io, io->bank, r_itv_begin (ci->tree_itv[0]),
&ci->data[r_itv_begin (ci->tree_itv[0]) - r_itv_begin (ci->itv)],
@ -510,13 +543,13 @@ R_API void r_io_cache_commit(RIO *io, ut64 from, ut64 to) {
if (!node) {
return;
}
IOCacheItem *ci = (IOCacheItem *)node->data;
RIOCacheItem *ci = (RIOCacheItem *)node->data;
while (ci && r_itv_overlap (itv, ci->tree_itv[0])) {
RInterval its = r_itv_intersect (itv, ci->tree_itv[0]);
r_io_bank_write_at (io, io->bank, r_itv_begin (its),
&ci->data[r_itv_begin (its) - r_itv_begin (ci->itv)], r_itv_size (its));
node = r_rbnode_next (node);
ci = node? (IOCacheItem *)node->data: NULL;
ci = node? (RIOCacheItem *)node->data: NULL;
}
r_io_cache_invalidate (io, from, to);
}
@ -525,7 +558,7 @@ R_API bool r_io_cache_list(RIO *io, int rad) {
r_return_val_if_fail (io, false);
size_t i, j = 0;
void **iter;
IOCacheItem *ci;
RIOCacheItem *ci;
PJ *pj = NULL;
if (rad == 2) {
pj = pj_new ();
@ -581,8 +614,8 @@ R_API bool r_io_cache_list(RIO *io, int rad) {
return false;
}
static IOCacheItem *_clone_ci(IOCacheItem *ci) {
IOCacheItem *clone = R_NEWCOPY (IOCacheItem, ci);
static RIOCacheItem *_clone_ci(RIOCacheItem *ci) {
RIOCacheItem *clone = R_NEWCOPY (RIOCacheItem, ci);
if (clone) {
clone->data = R_NEWS (ut8, r_itv_size (ci->itv));
clone->odata = R_NEWS (ut8, r_itv_size (ci->itv));
@ -605,7 +638,7 @@ R_API RIOCache *r_io_cache_clone(RIO *io) {
clone->vec = r_pvector_new ((RPVectorFree)_io_cache_item_free);
void **iter;
r_pvector_foreach_prev (io->cache->vec, iter) {
IOCacheItem *ci = _clone_ci ((IOCacheItem *)*iter);
RIOCacheItem *ci = _clone_ci ((RIOCacheItem *)*iter);
r_pvector_push (clone->vec, ci);
if (ci->tree_itv) {
r_crbtree_insert (clone->tree, clone, _ci_start_cmp_cb, NULL);

View File

@ -99,6 +99,10 @@ r_io = library('r_io', r_io_sources,
r_io_dep = declare_dependency(link_with: [r_io, r_crypto],
include_directories: platform_inc)
if get_option('use_new_io_cache')
add_project_arguments('-DUSE_NEW_IO_CACHE_API=1', language: 'c')
endif
if get_option('blob')
r_io_static_deps = [
r_util_static_dep,

View File

@ -188,16 +188,22 @@ beach:
static void __riocache_free(void *user) {
RIOCache *cache = (RIOCache *) user;
#if !USE_NEW_IO_CACHE_API
if (cache) {
free (cache->data);
free (cache->odata);
}
#endif
free (cache);
}
static bool __desc_cache_list_cb(void *user, const ut64 k, const void *v) {
RList *writes = (RList *)user;
#if USE_NEW_IO_CACHE_API
RIOCacheItem *cache = NULL;
#else
RIOCache *cache = NULL;
#endif
ut64 blockaddr;
int byteaddr, i;
if (!writes) {
@ -208,7 +214,11 @@ static bool __desc_cache_list_cb(void *user, const ut64 k, const void *v) {
for (i = byteaddr = 0; byteaddr < R_IO_DESC_CACHE_SIZE; byteaddr++) {
if (dcache->cached & (0x1LL << byteaddr)) {
if (!cache) {
#if USE_NEW_IO_CACHE_API
cache = R_NEW0 (RIOCacheItem);
#else
cache = R_NEW0 (RIOCache);
#endif
if (!cache) {
return false;
}
@ -258,7 +268,11 @@ R_API RList *r_io_desc_cache_list(RIODesc *desc) {
desc->io->desc = desc;
desc->io->p_cache = false;
#if USE_NEW_IO_CACHE_API
RIOCacheItem *c;
#else
RIOCache *c;
#endif
RListIter *iter;
r_list_foreach (writes, iter, c) {
const ut64 itvSize = r_itv_size (c->itv);

View File

@ -11,6 +11,9 @@ export NOSTRIP=1
CFLAGS+=-g
LINK+=-g
endif
ifeq ($(NEW_IO_CACHE),1)
CFLAGS+=-DUSE_NEW_IO_CACHE_API=1
endif
LIBR:=$(abspath $(dir $(lastword $(MAKEFILE_LIST))))

View File

@ -38,6 +38,7 @@ option('use_ssl', type: 'boolean', value: false)
option('use_ssl_crypto', type: 'boolean', value: false)
option('use_v35', type: 'boolean', value: false)
option('use_sys_openssl', type: 'boolean', value: false)
option('use_new_io_cache', type: 'boolean', value: false)
option('static_sys_openssl', type: 'boolean', value: false)
option('use_libuv', type: 'boolean', value: false)
option('use_fork', type: 'boolean', value: true)

View File

@ -92,7 +92,8 @@ ${MAKE} mrproper > /dev/null 2>&1
unset R2DEPS
pwd
./configure ${CFGARG} --prefix="${PREFIX}" || exit 1
echo ./configure ${CFGARG} --prefix="${PREFIX}"
eval ./configure ${CFGARG} --prefix="${PREFIX}" || exit 1
${MAKE} -s -j${MAKE_JOBS} MAKE_JOBS=${MAKE_JOBS} || exit 1
if [ "${OSNAME}" = Darwin ]; then
./sys/macos-cert.sh

View File

@ -154,6 +154,7 @@ if [ "$NEED_CAPSTONE" = 1 ]; then
./preconfigure
fi
fi
echo "ARGS=$ARGS"
if [ "${M32}" = 1 ]; then
${SHELL} ./sys/build-m32.sh ${ARGS} || exit 1

View File

@ -59,4 +59,4 @@ if [ "$1" = "-u" ]; then
shift
SCRIPT=user.sh
fi
exec sys/${SCRIPT} --with-check-level=0 $*
exec sys/${SCRIPT} $* --with-check-level=0