memzap

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

commit 5dd9567aa339c70db072780c1dc0ed9edcf679f2
parent 13b9ef7de2cc0016ed3304da34d125d00d9f0766
Author: sin <sin@2f30.org>
Date:   Sat,  2 Mar 2013 15:30:10 +0000

Rename data.h to proto.h

We have a single header for now, proto.h that contains all type
declarations as well as inline functions and function prototypes.

Diffstat:
Ddata.h | 141-------------------------------------------------------------------------------
Mlinux_ops.c | 2+-
Mmem.c | 2+-
Mmemzap.c | 2+-
Mopenbsd_ops.c | 2+-
Aproto.h | 141+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mutils.c | 2+-
7 files changed, 146 insertions(+), 146 deletions(-)

diff --git a/data.h b/data.h @@ -1,141 +0,0 @@ -/* See LICENSE file for copyright and license details. */ - -#ifndef _DATA_H -#define _DATA_H - -#include <errno.h> -#include <unistd.h> -#include <sys/stat.h> -#include <sys/ptrace.h> -#include <sys/wait.h> -#include <sys/mman.h> -#include <fcntl.h> - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <stdint.h> -#include <stdbool.h> -#include <limits.h> -#include <signal.h> -#include <err.h> - -#include "queue.h" -#include "tree.h" -#include "md5.h" - -#define min(a, b) ((a) < (b) ? (a) : (b)) - -enum { - /* The preferred block size */ - BLKSIZE = 16384 -}; - -struct mem_blk { - /* Points to the actual data for this - * block. The user should never free pointers - * passed to this API unless the corresponding - * memory region has been freed. */ - void *buf; - /* Simple rolling sum of this block */ - uint32_t weak_sum; - /* The MD5 digest */ - unsigned char digest[MD5_DIGEST_LENGTH]; - /* Offset into the memory region of this block */ - off_t offset; - /* Size of this block, typically `BLKSIZE' - * or less for the last block */ - size_t len; -}; - -struct mem_region { - /* Size of the memory region */ - size_t rsize; - /* Number of blocks in this region */ - size_t nblocks; - /* rsize % nblocks */ - size_t rem; - /* The block size used for this region */ - size_t blksize; - /* There are `nblocks' mem_blk entries - * here, describing the entire memory region */ - struct mem_blk *mblks; -}; - -struct mem_diff { - /* Our updated data */ - void *buf; - /* Offset into the memory region where - * this buffer should be written */ - off_t offset; - /* Actual size of the buffer */ - size_t len; - /* Index into the memory region where - * the corresponding memory block is located */ - int index; -}; - -struct mem_region_diff { - /* The diffs for this memory region */ - struct mem_diff *mrdiffs; - /* The number of diffs */ - size_t nmrdiffs; -}; - -struct mem_tree_entry { - /* The rolling sum for this rbnode, we sort - * based on this property */ - uint32_t weak_sum; - /* Pointers to memory blocks, normally there - * will be only 1 memory block here, however, - * if we have weak sum collisions, then we will - * chain more entries here */ - struct mem_blk **mblks; - /* Actual number of tracked memory blocks */ - size_t nmblks; - /* The memory region this tree is generated - * from */ - struct mem_region *mr; - RB_ENTRY(mem_tree_entry) entry; -}; -RB_HEAD(mem_tree, mem_tree_entry); - -/* Return the number of blocks in a buffer of `len' bytes */ -static inline size_t -num_blocks(size_t len) -{ - return (len + (BLKSIZE - 1)) / BLKSIZE; -} - -/* 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); -void strong_sum(const void *buf, size_t len, void *digest); -void dump_mem_blk(struct mem_blk *mb); -struct mem_region *build_mem_region(unsigned char *buf, size_t len); -void dump_mem_region(struct mem_region *mr); -void free_mem_region(struct mem_region *mr); -int mem_cmp(struct mem_tree_entry *a, struct mem_tree_entry *b); -RB_PROTOTYPE(mem_tree, mem_tree_entry, entry, - mem_cmp); -struct mem_tree *build_mem_tree(struct mem_region *mr); -void dump_mem_tree(struct mem_tree *mt); -void free_mem_tree(struct mem_tree *mt); -struct mem_region_diff *diff_mem_region(struct mem_tree *dst, - struct mem_region *src); -struct mem_region *apply_diff(struct mem_region *dst, - struct mem_region_diff *rdiff); -void dump_mem_region_diff(struct mem_region_diff *rdiff); -void free_mem_region_diff(struct mem_region_diff *rdiff); - -/* *_ops.c */ -int traceme(void); -int single_step(pid_t pid); -void readmem(pid_t pid, void *buf, void *offset, size_t size); - -#endif diff --git a/linux_ops.c b/linux_ops.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include "data.h" +#include "proto.h" int traceme(void) diff --git a/mem.c b/mem.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include "data.h" +#include "proto.h" /* In this file a simplified version of the rsync * algorithm is implemented. The idea is to diff diff --git a/memzap.c b/memzap.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include "data.h" +#include "proto.h" static int verbose = 0; diff --git a/openbsd_ops.c b/openbsd_ops.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include "data.h" +#include "proto.h" int traceme(void) diff --git a/proto.h b/proto.h @@ -0,0 +1,141 @@ +/* See LICENSE file for copyright and license details. */ + +#ifndef _PROTO_H +#define _PROTO_H + +#include <errno.h> +#include <unistd.h> +#include <sys/stat.h> +#include <sys/ptrace.h> +#include <sys/wait.h> +#include <sys/mman.h> +#include <fcntl.h> + +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <stdint.h> +#include <stdbool.h> +#include <limits.h> +#include <signal.h> +#include <err.h> + +#include "queue.h" +#include "tree.h" +#include "md5.h" + +#define min(a, b) ((a) < (b) ? (a) : (b)) + +enum { + /* The preferred block size */ + BLKSIZE = 16384 +}; + +struct mem_blk { + /* Points to the actual data for this + * block. The user should never free pointers + * passed to this API unless the corresponding + * memory region has been freed. */ + void *buf; + /* Simple rolling sum of this block */ + uint32_t weak_sum; + /* The MD5 digest */ + unsigned char digest[MD5_DIGEST_LENGTH]; + /* Offset into the memory region of this block */ + off_t offset; + /* Size of this block, typically `BLKSIZE' + * or less for the last block */ + size_t len; +}; + +struct mem_region { + /* Size of the memory region */ + size_t rsize; + /* Number of blocks in this region */ + size_t nblocks; + /* rsize % nblocks */ + size_t rem; + /* The block size used for this region */ + size_t blksize; + /* There are `nblocks' mem_blk entries + * here, describing the entire memory region */ + struct mem_blk *mblks; +}; + +struct mem_diff { + /* Our updated data */ + void *buf; + /* Offset into the memory region where + * this buffer should be written */ + off_t offset; + /* Actual size of the buffer */ + size_t len; + /* Index into the memory region where + * the corresponding memory block is located */ + int index; +}; + +struct mem_region_diff { + /* The diffs for this memory region */ + struct mem_diff *mrdiffs; + /* The number of diffs */ + size_t nmrdiffs; +}; + +struct mem_tree_entry { + /* The rolling sum for this rbnode, we sort + * based on this property */ + uint32_t weak_sum; + /* Pointers to memory blocks, normally there + * will be only 1 memory block here, however, + * if we have weak sum collisions, then we will + * chain more entries here */ + struct mem_blk **mblks; + /* Actual number of tracked memory blocks */ + size_t nmblks; + /* The memory region this tree is generated + * from */ + struct mem_region *mr; + RB_ENTRY(mem_tree_entry) entry; +}; +RB_HEAD(mem_tree, mem_tree_entry); + +/* Return the number of blocks in a buffer of `len' bytes */ +static inline size_t +num_blocks(size_t len) +{ + return (len + (BLKSIZE - 1)) / BLKSIZE; +} + +/* 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); +void strong_sum(const void *buf, size_t len, void *digest); +void dump_mem_blk(struct mem_blk *mb); +struct mem_region *build_mem_region(unsigned char *buf, size_t len); +void dump_mem_region(struct mem_region *mr); +void free_mem_region(struct mem_region *mr); +int mem_cmp(struct mem_tree_entry *a, struct mem_tree_entry *b); +RB_PROTOTYPE(mem_tree, mem_tree_entry, entry, + mem_cmp); +struct mem_tree *build_mem_tree(struct mem_region *mr); +void dump_mem_tree(struct mem_tree *mt); +void free_mem_tree(struct mem_tree *mt); +struct mem_region_diff *diff_mem_region(struct mem_tree *dst, + struct mem_region *src); +struct mem_region *apply_diff(struct mem_region *dst, + struct mem_region_diff *rdiff); +void dump_mem_region_diff(struct mem_region_diff *rdiff); +void free_mem_region_diff(struct mem_region_diff *rdiff); + +/* *_ops.c */ +int traceme(void); +int single_step(pid_t pid); +void readmem(pid_t pid, void *buf, void *offset, size_t size); + +#endif diff --git a/utils.c b/utils.c @@ -1,6 +1,6 @@ /* See LICENSE file for copyright and license details. */ -#include "data.h" +#include "proto.h" void * xmalloc(size_t size)