memzap

replay memory writes
git clone git://git.2f30.org/memzap.git
Log | Files | Refs | README | LICENSE

commit e768db13177889f74d4d37628bc0b5d71ac03f54
parent 3dae6fb418367a52b1a42727c86fd6f9a47194fd
Author: sin <sin@2f30.org>
Date:   Fri Mar  1 12:20:23 +0000

ops: Add linux_ops.c

We aim to have *_ops.c files to implement any OS specific
features.  The Makefile will take care of linking the appropriate
ops object.

Diffstat:
Makefile | 2+-
data.h | 3+++
linux_ops.c | 29+++++++++++++++++++++++++++++
memzap.c | 28----------------------------
4 files changed, 33 insertions(+), 29 deletions(-)
diff --git a/Makefile b/Makefile @@ -1,6 +1,6 @@ BIN = memzap VER = 0.1 -SRC = memzap.c mem.c utils.c md5.c +SRC = memzap.c mem.c utils.c md5.c linux_ops.c OBJ = ${SRC:.c=.o} PREFIX = /usr diff --git a/data.h b/data.h @@ -133,4 +133,7 @@ struct mem_region *apply_diff(struct mem_region *dst, void dump_mem_region_diff(struct mem_region_diff *rdiff); void free_mem_region_diff(struct mem_region_diff *rdiff); +/* *_ops.c */ +void readmem(pid_t pid, void *buf, off_t offset, size_t size); + #endif diff --git a/linux_ops.c b/linux_ops.c @@ -0,0 +1,29 @@ +#include "data.h" + +void +readmem(pid_t pid, void *buf, off_t offset, size_t size) +{ + char tbuf[PATH_MAX - 1]; + int fdmem, r; + ssize_t rs; + size_t s; + + snprintf(tbuf, sizeof(tbuf), "/proc/%d/mem", pid); + fdmem = open(tbuf, O_RDONLY); + if (fdmem < 0) + err(1, "open"); + + r = lseek(fdmem, offset, SEEK_SET); + if (r < 0) + err(1, "lseek"); + + s = 0; + while (s < size) { + rs = read(fdmem, buf + s, size - s); + if (rs < 0) + err(1, "read"); + s += rs; + } + + close(fdmem); +} diff --git a/memzap.c b/memzap.c @@ -4,34 +4,6 @@ static int verbose = 0; -void -readmem(pid_t pid, void *buf, off_t offset, size_t size) -{ - char tbuf[PATH_MAX - 1]; - int fdmem, r; - ssize_t rs; - size_t s; - - snprintf(tbuf, sizeof(tbuf), "/proc/%d/mem", pid); - fdmem = open(tbuf, O_RDONLY); - if (fdmem < 0) - err(1, "open"); - - r = lseek(fdmem, offset, SEEK_SET); - if (r < 0) - err(1, "lseek"); - - s = 0; - while (s < size) { - rs = read(fdmem, buf + s, size - s); - if (rs < 0) - err(1, "read"); - s += rs; - } - - close(fdmem); -} - int main(int argc, char *argv[]) {