diff options
author | van Hauser <vh@thc.org> | 2022-05-08 12:47:25 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-08 12:47:25 +0200 |
commit | 47dae21f4a0da74e3e454f637285baebf0567491 (patch) | |
tree | 4db3309f18020528619e8f0db8fa7e147a8802e6 | |
parent | ba12c7fc090d0e6ae2f049394c7c332728ddd4fd (diff) | |
parent | 229a45c6a6498c9735d2432588fe303531898ed2 (diff) | |
download | afl++-47dae21f4a0da74e3e454f637285baebf0567491.tar.gz |
Merge pull request #1401 from devnexen/fbsd_largepage
large shared segment optimisation (in TEST_MMAP mode)
-rw-r--r-- | src/afl-sharedmem.c | 34 |
1 files changed, 32 insertions, 2 deletions
diff --git a/src/afl-sharedmem.c b/src/afl-sharedmem.c index 63575318..9e0d7531 100644 --- a/src/afl-sharedmem.c +++ b/src/afl-sharedmem.c @@ -153,6 +153,8 @@ u8 *afl_shm_init(sharedmem_t *shm, size_t map_size, shm->g_shm_fd = -1; shm->cmplog_g_shm_fd = -1; + const int shmflags = O_RDWR | O_EXCL; + /* ====== generate random file name for multi instance @@ -161,9 +163,37 @@ u8 *afl_shm_init(sharedmem_t *shm, size_t map_size, so we do this worse workaround */ snprintf(shm->g_shm_file_path, L_tmpnam, "/afl_%d_%ld", getpid(), random()); +#ifdef SHM_LARGEPAGE_ALLOC_DEFAULT + /* trying to get large memory segment optimised and monitorable separately as such */ + static size_t sizes[4] = {(size_t)-1}; + static int psizes = 0; + int i; + if (sizes[0] == (size_t)-1) { psizes = getpagesizes(sizes, 4); } + + /* very unlikely to fail even if the arch supports only two sizes */ + if (likely(psizes > 0)) { + + for (i = psizes - 1; shm->g_shm_fd == -1 && i >= 0; --i) { + + if (sizes[i] == 0 || map_size % sizes[i]) { continue; } + + shm->g_shm_fd = shm_create_largepage(shm->g_shm_file_path, shmflags, i, + SHM_LARGEPAGE_ALLOC_DEFAULT, DEFAULT_PERMISSION); + + } + + } +#endif + + /* create the shared memory segment as if it was a file */ - shm->g_shm_fd = shm_open(shm->g_shm_file_path, O_CREAT | O_RDWR | O_EXCL, - DEFAULT_PERMISSION); + if (shm->g_shm_fd == -1) { + + shm->g_shm_fd = shm_open(shm->g_shm_file_path, shmflags | O_CREAT, + DEFAULT_PERMISSION); + + } + if (shm->g_shm_fd == -1) { PFATAL("shm_open() failed"); } /* configure the size of the shared memory segment */ |