diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2020-02-21 19:51:19 +0100 |
---|---|---|
committer | Andrea Fioraldi <andreafioraldi@gmail.com> | 2020-02-21 19:51:19 +0100 |
commit | eb05cb4d1136642067f78dbff70b825d451c34e9 (patch) | |
tree | 883464792db48485783364f0596b75ee3736f7bf | |
parent | 249cd2c7669f9dc9f49e96756b6683744213ee08 (diff) | |
download | afl++-eb05cb4d1136642067f78dbff70b825d451c34e9.tar.gz |
ooops, I forgot to merge thsi part :(
-rw-r--r-- | llvm_mode/afl-llvm-rt.o.c | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/llvm_mode/afl-llvm-rt.o.c b/llvm_mode/afl-llvm-rt.o.c index 5d6e30f5..53852320 100644 --- a/llvm_mode/afl-llvm-rt.o.c +++ b/llvm_mode/afl-llvm-rt.o.c @@ -129,6 +129,48 @@ static void __afl_map_shm(void) { __afl_area_ptr[0] = 1; } + + id_str = getenv(CMPLOG_SHM_ENV_VAR); + + if (id_str) { + +#ifdef USEMMAP + const char* shm_file_path = id_str; + int shm_fd = -1; + unsigned char* shm_base = NULL; + + /* create the shared memory segment as if it was a file */ + shm_fd = shm_open(shm_file_path, O_RDWR, 0600); + if (shm_fd == -1) { + + printf("shm_open() failed\n"); + exit(1); + + } + + /* map the shared memory segment to the address space of the process */ + shm_base = mmap(0, sizeof(struct cmp_map), PROT_READ | PROT_WRITE, + MAP_SHARED, shm_fd, 0); + if (shm_base == MAP_FAILED) { + + close(shm_fd); + shm_fd = -1; + + printf("mmap() failed\n"); + exit(2); + + } + + __afl_cmp_map = shm_base; +#else + u32 shm_id = atoi(id_str); + + __afl_cmp_map = shmat(shm_id, NULL, 0); +#endif + + if (__afl_cmp_map == (void*)-1) _exit(1); + + } } |