From owner-svn-src-all@FreeBSD.ORG Fri Dec 13 06:01:21 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D410CEE5; Fri, 13 Dec 2013 06:01:21 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BFECF1530; Fri, 13 Dec 2013 06:01:21 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBD61LS5079083; Fri, 13 Dec 2013 06:01:21 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBD61LkD079081; Fri, 13 Dec 2013 06:01:21 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201312130601.rBD61LkD079081@svn.freebsd.org> From: Konstantin Belousov Date: Fri, 13 Dec 2013 06:01:21 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-9@freebsd.org Subject: svn commit: r259291 - stable/9/libexec/rtld-elf X-SVN-Group: stable-9 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 13 Dec 2013 06:01:21 -0000 Author: kib Date: Fri Dec 13 06:01:21 2013 New Revision: 259291 URL: http://svnweb.freebsd.org/changeset/base/259291 Log: MFC r259043: Build an allocator for the aligned memory on top of the rtld-private malloc. Modified: stable/9/libexec/rtld-elf/rtld.h stable/9/libexec/rtld-elf/xmalloc.c Directory Properties: stable/9/libexec/rtld-elf/ (props changed) Modified: stable/9/libexec/rtld-elf/rtld.h ============================================================================== --- stable/9/libexec/rtld-elf/rtld.h Fri Dec 13 06:00:44 2013 (r259290) +++ stable/9/libexec/rtld-elf/rtld.h Fri Dec 13 06:01:21 2013 (r259291) @@ -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/9/libexec/rtld-elf/xmalloc.c ============================================================================== --- stable/9/libexec/rtld-elf/xmalloc.c Fri Dec 13 06:00:44 2013 (r259290) +++ stable/9/libexec/rtld-elf/xmalloc.c Fri Dec 13 06:01:21 2013 (r259291) @@ -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); +}