summaryrefslogtreecommitdiffstats
path: root/libexec
diff options
context:
space:
mode:
authorkib <kib@FreeBSD.org>2013-12-06 21:30:31 +0000
committerkib <kib@FreeBSD.org>2013-12-06 21:30:31 +0000
commit18ee9284073c6ab130b819f7a74bc50fbd018c60 (patch)
tree2c32cab27cf33e6518041a0bf49ead225ae99f1e /libexec
parent44b7f6b41bc428f56c93d61b9ce9f618fb29c982 (diff)
downloadFreeBSD-src-18ee9284073c6ab130b819f7a74bc50fbd018c60.zip
FreeBSD-src-18ee9284073c6ab130b819f7a74bc50fbd018c60.tar.gz
Build an allocator for the aligned memory on top of the rtld-private
malloc. Reviewed by: kan Sponsored by: The FreeBSD Foundation MFC after: 1 week
Diffstat (limited to 'libexec')
-rw-r--r--libexec/rtld-elf/rtld.h2
-rw-r--r--libexec/rtld-elf/xmalloc.c30
2 files changed, 32 insertions, 0 deletions
diff --git a/libexec/rtld-elf/rtld.h b/libexec/rtld-elf/rtld.h
index 083f5a4..d186dcc 100644
--- a/libexec/rtld-elf/rtld.h
+++ b/libexec/rtld-elf/rtld.h
@@ -352,6 +352,8 @@ Obj_Entry *map_object(int, const char *, const struct stat *);
void *xcalloc(size_t, size_t);
void *xmalloc(size_t);
char *xstrdup(const char *);
+void *malloc_aligned(size_t size, size_t align);
+void free_aligned(void *ptr);
extern Elf_Addr _GLOBAL_OFFSET_TABLE_[];
extern Elf_Sym sym_zero; /* For resolving undefined weak refs. */
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