summaryrefslogtreecommitdiffstats
path: root/libexec/rtld-elf/xmalloc.c
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2013-12-13 06:00:44 +0000
committerkib <kib@FreeBSD.org>2013-12-13 06:00:44 +0000
commitd22cb2f95ea300443f067b7feec3432fed15cf65 (patch)
treee16800b64ce5b8da3d984bb530c997b600d7a913 /libexec/rtld-elf/xmalloc.c
parenta455348768c94edff360c66f151bddaab070fb1b (diff)
downloadFreeBSD-src-d22cb2f95ea300443f067b7feec3432fed15cf65.zip
FreeBSD-src-d22cb2f95ea300443f067b7feec3432fed15cf65.tar.gz
MFC r259043:
Build an allocator for the aligned memory on top of the rtld-private malloc.
Diffstat (limited to 'libexec/rtld-elf/xmalloc.c')
-rw-r--r--libexec/rtld-elf/xmalloc.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/libexec/rtld-elf/xmalloc.c b/libexec/rtld-elf/xmalloc.c
index 178f49b..3b3408c 100644
--- a/libexec/rtld-elf/xmalloc.c
+++ b/libexec/rtld-elf/xmalloc.c
@@ -67,3 +67,33 @@ xstrdup(const char *str)
memcpy(copy, str, len);
return (copy);
}
+
+void *
+malloc_aligned(size_t size, size_t align)
+{
+ void *mem, *res;
+ uintptr_t x;
+ size_t asize, r;
+
+ r = round(sizeof(void *), align);
+ asize = round(size, align) + r;
+ mem = xmalloc(asize);
+ x = (uintptr_t)mem;
+ res = (void *)round(x, align);
+ *(void **)((uintptr_t)res - sizeof(void *)) = mem;
+ return (res);
+}
+
+void
+free_aligned(void *ptr)
+{
+ void *mem;
+ uintptr_t x;
+
+ if (ptr == NULL)
+ return;
+ x = (uintptr_t)ptr;
+ x -= sizeof(void *);
+ mem = *(void **)x;
+ free(mem);
+}
OpenPOWER on IntegriCloud