11 #define PTR_ALIGN(ptr, mask) \
12 (char *) (((uintptr_t) ((ptr) + (mask)) & ~(mask)))
14 void *fio_memalign(size_t alignment, size_t size)
16 struct align_footer *f;
17 void *ptr, *ret = NULL;
19 assert(!(alignment & (alignment - 1)));
21 ptr = malloc(size + alignment + size + sizeof(*f) - 1);
23 ret = PTR_ALIGN(ptr, alignment - 1);
25 f->offset = (uintptr_t) ret - (uintptr_t) ptr;
31 void fio_memfree(void *ptr, size_t size)
33 struct align_footer *f = ptr + size;
35 free(ptr - f->offset);