svn commit: r259290 - stable/10/libexec/rtld-elf

Konstantin Belousov kib at FreeBSD.org
Fri Dec 13 06:00:44 UTC 2013


Author: kib
Date: Fri Dec 13 06:00:44 2013
New Revision: 259290
URL: http://svnweb.freebsd.org/changeset/base/259290

Log:
  MFC r259043:
  Build an allocator for the aligned memory on top of the rtld-private
  malloc.

Modified:
  stable/10/libexec/rtld-elf/rtld.h
  stable/10/libexec/rtld-elf/xmalloc.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/libexec/rtld-elf/rtld.h
==============================================================================
--- stable/10/libexec/rtld-elf/rtld.h	Fri Dec 13 05:54:58 2013	(r259289)
+++ stable/10/libexec/rtld-elf/rtld.h	Fri Dec 13 06:00:44 2013	(r259290)
@@ -352,6 +352,8 @@ Obj_Entry *map_object(int, const char *,
 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. */
 

Modified: stable/10/libexec/rtld-elf/xmalloc.c
==============================================================================
--- stable/10/libexec/rtld-elf/xmalloc.c	Fri Dec 13 05:54:58 2013	(r259289)
+++ stable/10/libexec/rtld-elf/xmalloc.c	Fri Dec 13 06:00:44 2013	(r259290)
@@ -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);
+}


More information about the svn-src-stable-10 mailing list