aboutsummaryrefslogtreecommitdiff
path: root/include/snapshot-inl.h
diff options
context:
space:
mode:
authorAndrea Fioraldi <andreafioraldi@gmail.com>2020-07-28 16:13:32 +0200
committerAndrea Fioraldi <andreafioraldi@gmail.com>2020-07-28 16:13:32 +0200
commita22f4dd1ac1fe12bc5b81c3311524bc175a2eed0 (patch)
treef854486c862b92bc8a8afb4aee2f5cc7c1bf0f5f /include/snapshot-inl.h
parent952e5b47ebaa0e1813e42ad7e7b524a519135d46 (diff)
downloadAFLplusplus-a22f4dd1ac1fe12bc5b81c3311524bc175a2eed0.tar.gz
new snapshot api
Diffstat (limited to 'include/snapshot-inl.h')
-rw-r--r--include/snapshot-inl.h63
1 files changed, 54 insertions, 9 deletions
diff --git a/include/snapshot-inl.h b/include/snapshot-inl.h
index b73a001e..55251db5 100644
--- a/include/snapshot-inl.h
+++ b/include/snapshot-inl.h
@@ -25,35 +25,80 @@
// From AFL-Snapshot-LKM/include/afl_snapshot.h (must be kept synced)
#include <sys/ioctl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
+#include <stdlib.h>
#include <fcntl.h>
#define AFL_SNAPSHOT_FILE_NAME "/dev/afl_snapshot"
#define AFL_SNAPSHOT_IOCTL_MAGIC 44313
-#define AFL_SNAPSHOT_IOCTL_DO _IO(AFL_SNAPSHOT_IOCTL_MAGIC, 1)
-#define AFL_SNAPSHOT_IOCTL_CLEAN _IO(AFL_SNAPSHOT_IOCTL_MAGIC, 2)
+#define AFL_SNAPSHOT_EXCLUDE_VMRANGE _IOR(AFL_SNAPSHOT_IOCTL_MAGIC, 1, struct afl_snapshot_vmrange_args*)
+#define AFL_SNAPSHOT_INCLUDE_VMRANGE _IOR(AFL_SNAPSHOT_IOCTL_MAGIC, 2, struct afl_snapshot_vmrange_args*)
+#define AFL_SNAPSHOT_IOCTL_TAKE _IOR(AFL_SNAPSHOT_IOCTL_MAGIC, 3, int)
+#define AFL_SNAPSHOT_IOCTL_RESTORE _IO(AFL_SNAPSHOT_IOCTL_MAGIC, 4)
+#define AFL_SNAPSHOT_IOCTL_CLEAN _IO(AFL_SNAPSHOT_IOCTL_MAGIC, 5)
+
+// Trace new mmaped ares and unmap them on restore.
+#define AFL_SNAPSHOT_MMAP 1
+// Do not snapshot any page (by default all writeable not-shared pages
+// are shanpshotted.
+#define AFL_SNAPSHOT_BLOCK 2
+// Snapshot file descriptor state, close newly opened descriptors
+#define AFL_SNAPSHOT_FDS 4
+// Snapshot registers state
+#define AFL_SNAPSHOT_REGS 8
+// Perform a restore when exit_group is invoked
+#define AFL_SNAPSHOT_EXIT 16
+// TODO(andrea) allow not COW snapshots (high perf on small processes)
+// Disable COW, restore all the snapshotted pages
+#define AFL_SNAPSHOT_NOCOW 32
+// Do not snapshot Stack pages
+#define AFL_SNAPSHOT_NOSTACK 64
+
+struct afl_snapshot_vmrange_args {
+
+ unsigned long start, end;
+
+};
static int afl_snapshot_dev_fd;
-static int afl_snapshot_init(void) {
+static int afl_snapshot_init() {
afl_snapshot_dev_fd = open(AFL_SNAPSHOT_FILE_NAME, 0);
return afl_snapshot_dev_fd;
}
-static int afl_snapshot_do() {
+static void afl_snapshot_exclude_vmrange(void* start, void* end) {
- return ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_IOCTL_DO);
+ struct afl_snapshot_vmrange_args args = {(unsigned long)start, (unsigned long)end};
+ ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_EXCLUDE_VMRANGE, &args);
}
-static int afl_snapshot_clean(void) {
+static void afl_snapshot_include_vmrange(void* start, void* end) {
- return ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_IOCTL_CLEAN);
+ struct afl_snapshot_vmrange_args args = {(unsigned long)start, (unsigned long)end};
+ ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_INCLUDE_VMRANGE, &args);
+
+}
+
+static int afl_snapshot_take(int config) {
+
+ return ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_IOCTL_TAKE, config);
+
+}
+
+static void afl_snapshot_restore(void) {
+
+ ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_IOCTL_RESTORE);
+
+}
+
+static void afl_snapshot_clean(void) {
+
+ ioctl(afl_snapshot_dev_fd, AFL_SNAPSHOT_IOCTL_CLEAN);
}