diff options
author | van Hauser <vh@thc.org> | 2019-10-29 10:41:55 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-29 10:41:55 +0100 |
commit | 66f123fb66ef99fc518e395929c86f8359f40dfb (patch) | |
tree | e83fae0e01e151ec3977a373c134a5dbbd024fbe /libdislocator/libdislocator.so.c | |
parent | 6238df88a26d8498b4a821897f030a866dafdc24 (diff) | |
parent | 87b599f4a8b875c0ff8c81aff39ebecfd34e29fc (diff) | |
download | afl++-66f123fb66ef99fc518e395929c86f8359f40dfb.tar.gz |
Merge pull request #92 from devnexen/alloc_aligned_c11_libdislocator
adding aligned_alloc + little changes proposal for posix_memalign
Diffstat (limited to 'libdislocator/libdislocator.so.c')
-rw-r--r-- | libdislocator/libdislocator.so.c | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index b3a90366..e27efc0f 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -23,6 +23,7 @@ #include <stdlib.h> #include <string.h> #include <limits.h> +#include <errno.h> #include <sys/mman.h> #include "config.h" @@ -272,7 +273,11 @@ int posix_memalign(void** ptr, size_t align, size_t len) { if ((char*)ptr == NULL || *ptr == NULL) return -1; // why would we do: FATAL("null pointer on posix_memalign()"); if ((align % 2) || (align % sizeof(void *))) - return -1; // why would we do: FATAL("bad alignment on posix_memalign()"); + return EINVAL; // why would we do: FATAL("bad alignment on posix_memalign()"); + if (len == 0) { + *ptr = NULL; + return 0; + } if (align >= 4 * sizeof(size_t)) len += align -1; *ptr = malloc(len); @@ -294,6 +299,20 @@ void *memalign(size_t align, size_t len) { return ret; } +/* sort of C11 alias of memalign only more severe, alignment-wise */ + +void *aligned_alloc(size_t align, size_t len) { + void *ret = NULL; + + if ((len % align)) return NULL; + + if (posix_memalign(&ret, align, len)) { + DEBUGF("aligned_alloc(%zu, %zu) failed", align, len); + } + + return ret; +} + __attribute__((constructor)) void __dislocator_init(void) { u8* tmp = getenv("AFL_LD_LIMIT_MB"); |