diff options
author | Andrea Fioraldi <andreafioraldi@gmail.com> | 2019-10-28 15:49:43 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-28 15:49:43 +0100 |
commit | 0df37d0fa1452f7a9c06474a26da71d3442ae319 (patch) | |
tree | 10e47c615fc20cf2953ee6c0fda4ba59d9c51ef4 | |
parent | 64fa11d204c13ad32f9fe0dbb9abbfedc00ebb3d (diff) | |
parent | fbb131da737fdabe4908558bd839c468410ab3fc (diff) | |
download | afl++-0df37d0fa1452f7a9c06474a26da71d3442ae319.tar.gz |
Merge pull request #91 from devnexen/posix_memalign_prop
memalign/posix_memalign proposal for libdislocator
-rw-r--r-- | libdislocator/libdislocator.so.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/libdislocator/libdislocator.so.c b/libdislocator/libdislocator.so.c index d172f7a2..f1972797 100644 --- a/libdislocator/libdislocator.so.c +++ b/libdislocator/libdislocator.so.c @@ -264,6 +264,36 @@ void* realloc(void* ptr, size_t len) { } +/* posix_memalign we mainly check the proper alignment argument + if the requested size fits within the alignment we do + a normal request */ + +int posix_memalign(void** ptr, size_t align, size_t len) { + if (!ptr) FATAL("null pointer on posix_memalign()"); + if ((align % 2) || (align % sizeof(void *))) FATAL("bad alignment on posix_memalign()"); + if (align >= 4 * sizeof(size_t)) { + + len += align -1; + + } + + *ptr = malloc(len); + + DEBUGF("posix_memalign(%p %zu, %zu)", ptr, len, align); + + return 0; +} + +/* just the non-posix fashion */ + +void *memalign(size_t align, size_t len) { + void* ret; + + posix_memalign(&ret, align, len); + + return ret; +} + __attribute__((constructor)) void __dislocator_init(void) { u8* tmp = getenv("AFL_LD_LIMIT_MB"); |