memzap

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

commit 3dae6fb418367a52b1a42727c86fd6f9a47194fd
parent fd0d7bc2bffa40a376fd4def7148de03a27a6b25
Author: sin <sin@2f30.org>
Date:   Fri Mar  1 12:16:34 +0000

utils: Add map_buf() and unmap_buf() helpers

Diffstat:
data.h | 2++
memzap.c | 17++++-------------
utils.c | 23+++++++++++++++++++++++
3 files changed, 29 insertions(+), 13 deletions(-)
diff --git a/data.h b/data.h @@ -110,6 +110,8 @@ num_blocks(size_t len) /* utils.c */ void *xmalloc(size_t len); void *xrealloc(void *ptr, size_t len); +void *map_buf(size_t len); +void unmap_buf(void *buf, size_t len); /* mem.c */ uint32_t weak_sum(const void *buf, size_t len); diff --git a/memzap.c b/memzap.c @@ -76,17 +76,8 @@ main(int argc, char *argv[]) if (verbose > 0) printf("[+] Mapping buffers into memory\n"); - buf = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, - -1, 0); - if (buf == MAP_FAILED) { - err(1, "mmap"); - } - - buf_new = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, - -1, 0); - if (buf_new == MAP_FAILED) { - err(1, "mmap"); - } + buf = map_buf(len); + buf_new = map_buf(len); if (verbose > 0) printf("[+] Single stepping child with pid %jd\n", @@ -139,7 +130,7 @@ main(int argc, char *argv[]) } while(1); out_mmap: - munmap(buf, len); - munmap(buf_new, len); + unmap_buf(buf, len); + unmap_buf(buf_new, len); return 0; } diff --git a/utils.c b/utils.c @@ -23,3 +23,26 @@ xrealloc(void *ptr, size_t size) err(1, "malloc"); return p; } + +void * +map_buf(size_t len) +{ + void *buf; + + buf = mmap(0, len, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, + -1, 0); + if (buf == MAP_FAILED) + err(1, "mmap"); + + return buf; +} + +void +unmap_buf(void *buf, size_t len) +{ + int ret; + + ret = munmap(buf, len); + if (ret < 0) + err(1, "munmap"); +}