Remove io_mmap plugin and just rely on default implementation

This commit is contained in:
Riccardo Schirone 2021-01-02 21:26:07 +01:00 committed by Florian Märkl
parent dca021bab9
commit ffb6431292
15 changed files with 0 additions and 245 deletions

View file

@ -491,7 +491,6 @@ extern RzIOPlugin rz_io_plugin_http;
extern RzIOPlugin rz_io_plugin_bfdbg;
extern RzIOPlugin rz_io_plugin_w32;
extern RzIOPlugin rz_io_plugin_zip;
extern RzIOPlugin rz_io_plugin_mmap;
extern RzIOPlugin rz_io_plugin_default;
extern RzIOPlugin rz_io_plugin_ihex;
extern RzIOPlugin rz_io_plugin_self;

View file

@ -22,7 +22,6 @@ rz_io_sources = [
'p/io_ihex.c',
'p/io_mach.c',
'p/io_malloc.c',
'p/io_mmap.c',
'p/io_null.c',
'p/io_procpid.c',
'p/io_ptrace.c',

View file

@ -1,216 +0,0 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <rz_userconf.h>
#include <rz_io.h>
#include <rz_lib.h>
typedef struct rz_io_mmo_t {
char * filename;
int mode;
int flags;
int fd;
int opened;
ut8 modified;
RzBuffer *buf;
RzIO * io_backref;
} RzIOMMapFileObj;
static ut64 rz_io_mmap_seek(RzIO *io, RzIOMMapFileObj *mmo, ut64 offset, int whence) {
ut64 seek_val = rz_buf_tell (mmo->buf);
switch (whence) {
case SEEK_SET:
seek_val = (rz_buf_size (mmo->buf) < offset)? rz_buf_size (mmo->buf): offset;
rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET);
return seek_val;
case SEEK_CUR:
seek_val = (rz_buf_size (mmo->buf) < (offset + rz_buf_tell (mmo->buf)))? rz_buf_size (mmo->buf): offset + rz_buf_tell (mmo->buf);
rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET);
return seek_val;
case SEEK_END:
seek_val = rz_buf_size (mmo->buf);
rz_buf_seek (mmo->buf, io->off = seek_val, RZ_BUF_SET);
return seek_val;
}
return seek_val;
}
static bool rz_io_mmap_refresh_buf(RzIOMMapFileObj *mmo) {
RzIO* io = mmo->io_backref;
ut64 cur = mmo->buf? rz_buf_tell (mmo->buf): 0;
if (mmo->buf) {
rz_buf_free (mmo->buf);
mmo->buf = NULL;
}
mmo->buf = rz_buf_new_mmap (mmo->filename, mmo->flags);
if (mmo->buf) {
rz_io_mmap_seek (io, mmo, cur, SEEK_SET);
}
return mmo->buf != NULL;
}
static void rz_io_mmap_free(RzIOMMapFileObj *mmo) {
free (mmo->filename);
rz_buf_free (mmo->buf);
memset (mmo, 0, sizeof (RzIOMMapFileObj));
free (mmo);
}
RzIOMMapFileObj *rz_io_mmap_create_new_file(RzIO *io, const char *filename, int mode, int flags) {
RzIOMMapFileObj *mmo;
if (!io) {
return NULL;
}
mmo = RZ_NEW0 (RzIOMMapFileObj);
if (!mmo) {
return NULL;
}
mmo->filename = strdup (filename);
mmo->fd = rz_num_rand (0xFFFF); // XXX: Use rz_io_fd api
mmo->mode = mode;
mmo->flags = flags;
mmo->io_backref = io;
if (!rz_io_mmap_refresh_buf (mmo)) {
rz_io_mmap_free (mmo);
mmo = NULL;
}
return mmo;
}
static int rz_io_mmap_close(RzIODesc *fd) {
if (!fd || !fd->data) {
return -1;
}
rz_io_mmap_free ((RzIOMMapFileObj *) fd->data);
fd->data = NULL;
return 0;
}
static int rz_io_mmap_check (const char *filename) {
return (filename && !strncmp (filename, "mmap://", 7) && *(filename + 7));
}
static int rz_io_mmap_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) {
RzIOMMapFileObj *mmo = NULL;
if (!fd || !fd->data || !buf) {
return -1;
}
mmo = fd->data;
if (rz_buf_size (mmo->buf) < io->off) {
io->off = rz_buf_size (mmo->buf);
}
int r = rz_buf_read_at (mmo->buf, io->off, buf, count);
if (r >= 0) {
rz_buf_seek (mmo->buf, r, RZ_BUF_CUR);
}
return r;
}
static int rz_io_mmap_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) {
RzIOMMapFileObj *mmo;
int len = count;
ut64 addr;
if (!io || !fd || !fd->data || !buf) {
return -1;
}
mmo = fd->data;
addr = io->off;
if ( !(mmo->flags & RZ_PERM_W)) {
return -1;
}
if ( (count + addr > rz_buf_size (mmo->buf)) || rz_buf_size (mmo->buf) == 0) {
ut64 sz = count + addr;
rz_file_truncate (mmo->filename, sz);
}
len = rz_file_mmap_write (mmo->filename, io->off, buf, len);
if (!rz_io_mmap_refresh_buf (mmo) ) {
eprintf ("io_mmap: failed to refresh the mmap backed buffer.\n");
// XXX - not sure what needs to be done here (error handling).
}
return len;
}
static RzIODesc *rz_io_mmap_open(RzIO *io, const char *file, int flags, int mode) {
if (!strncmp (file, "mmap://", 7)) {
file += 7;
}
RzIOMMapFileObj *mmo = rz_io_mmap_create_new_file (io, file, mode, flags);
return mmo? rz_io_desc_new (io, &rz_io_plugin_mmap, mmo->filename, flags, mode, mmo): NULL;
}
static ut64 rz_io_mmap_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
RzIOMMapFileObj *mmo;
if (!fd || !fd->data) {
return -1;
}
mmo = fd->data;
return rz_io_mmap_seek (io, mmo, offset, whence);
}
static bool rz_io_mmap_truncate(RzIOMMapFileObj *mmo, ut64 size) {
int res = rz_file_truncate (mmo->filename, size);
if (res && !rz_io_mmap_refresh_buf (mmo)) {
eprintf ("rz_io_mmap_truncate: Error trying to refresh the mmap'ed file.");
res = false;
} else if (res) {
eprintf ("rz_io_mmap_truncate: Error trying to resize the file.");
}
return res;
}
static bool __plugin_open(RzIO *io, const char *file, bool many) {
return rz_io_mmap_check (file);
}
static RzIODesc *__open(RzIO *io, const char *file, int flags, int mode) {
if (!rz_io_mmap_check (file)) {
return NULL;
}
return rz_io_mmap_open (io, file, flags, mode);
}
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int len) {
return rz_io_mmap_read (io, fd, buf, len);
}
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int len) {
return rz_io_mmap_write(io, fd, buf, len);
}
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
return rz_io_mmap_lseek (io, fd, offset, whence);
}
static int __close(RzIODesc *fd) {
return rz_io_mmap_close (fd);
}
static bool __resize(RzIO *io, RzIODesc *fd, ut64 size) {
if (!fd || !fd->data) {
return false;
}
return rz_io_mmap_truncate ((RzIOMMapFileObj*)fd->data, size);
}
struct rz_io_plugin_t rz_io_plugin_mmap = {
.name = "mmap",
.desc = "Open files using mmap",
.uris = "mmap://",
.license = "LGPL3",
.open = __open,
.close = __close,
.read = __read,
.check = __plugin_open,
.lseek = __lseek,
.write = __write,
.resize = __resize,
};
#ifndef RZ_PLUGIN_INCORE
RZ_API RzLibStruct rizin_plugin = {
.type = RZ_LIB_TYPE_IO,
.data = &rz_io_plugin_mmap,
.version = RZ_VERSION
};
#endif

View file

@ -1,16 +0,0 @@
OBJ_MMAP=io_mmap.o
STATIC_OBJ+=${OBJ_MMAP}
TARGET_MMAP=io_mmap.${EXT_SO}
ALL_TARGETS+=${TARGET_MMAP}
ifeq (${WITHPIC},0)
LINKFLAGS+=../../util/librz_util.a
LINKFLAGS+=../../io/librz_io.a
else
LINKFLAGS+=-L../../util -lrz_util
LINKFLAGS+=-L.. -lrz_io
endif
${TARGET_MMAP}: ${OBJ_MMAP}
${CC_LIB} $(call libname,io_mmap) ${CFLAGS} -o ${TARGET_MMAP} ${OBJ_MMAP} ${LINKFLAGS}

View file

@ -253,7 +253,6 @@ io_plugins = [
'ihex',
'mach',
'malloc',
'mmap',
'null',
'procpid',
'ptrace',

View file

@ -62,7 +62,6 @@ io.rap
io.gzip
io.http
io.bfdbg
io.mmap
io.default
io.self
io.mach

View file

@ -39,7 +39,6 @@ asm.ppc_cs
analysis.ppc_cs
io.mach
io.debug
io.mmap
io.w32
io.w32dbg
io.ihex

View file

@ -229,7 +229,6 @@ io.ihex
io.mach
io.malloc
io.sparse
io.mmap
io.procpid
io.ptrace
io.rap

View file

@ -48,7 +48,6 @@ asm.ppc_cs
analysis.ppc_cs
io.mach
io.debug
io.mmap
io.w32
io.w32dbg
io.ihex

View file

@ -59,7 +59,6 @@ io.rap
io.gzip
io.http
io.bfdbg
io.mmap
io.rzpipe
io.rzweb
io.default

View file

@ -62,7 +62,6 @@ io.rap
io.gzip
io.http
io.bfdbg
io.mmap
io.default
io.self
io.mach

View file

@ -110,7 +110,6 @@ io.ihex
io.mach
io.malloc
io.sparse
io.mmap
io.procpid
io.ptrace
io.rap

View file

@ -181,7 +181,6 @@ io.ihex
io.mach
io.malloc
io.sparse
io.mmap
io.procpid
io.ptrace
io.rap

View file

@ -182,7 +182,6 @@ io.ihex
io.mach
io.malloc
io.sparse
io.mmap
io.procpid
io.ptrace
io.rap

View file

@ -60,7 +60,6 @@ io.http
io.bfdbg
io.gdb
io.bochs
io.mmap
io.default
io.self
io.mach