From 15c4125cb6207f9f7d65db5dd9fc4c42f750b6d3 Mon Sep 17 00:00:00 2001 From: christos Date: Tue, 12 Mar 2019 15:13:25 +0000 Subject: [PATCH] - descend to build libjemalloc - namespace protect all functions __je - provide getters and setters for malloc_conf and malloc_message --- external/bsd/jemalloc/Makefile | 5 + external/bsd/jemalloc/dist/src/jemalloc.c | 59 ++++++-- .../bsd/jemalloc/include/jemalloc/jemalloc.h | 65 ++++---- external/bsd/jemalloc/lib/Makefile | 4 +- external/bsd/jemalloc/lib/Makefile.inc | 4 +- external/bsd/jemalloc/lib/jemalloc_stub.c | 141 ++++++++++++++++++ 6 files changed, 232 insertions(+), 46 deletions(-) create mode 100644 external/bsd/jemalloc/Makefile create mode 100644 external/bsd/jemalloc/lib/jemalloc_stub.c diff --git a/external/bsd/jemalloc/Makefile b/external/bsd/jemalloc/Makefile new file mode 100644 index 000000000000..e4847e6b8ceb --- /dev/null +++ b/external/bsd/jemalloc/Makefile @@ -0,0 +1,5 @@ +# $NetBSD: Makefile,v 1.1 2019/03/12 15:13:25 christos Exp $ + +SUBDIR= lib + +.include diff --git a/external/bsd/jemalloc/dist/src/jemalloc.c b/external/bsd/jemalloc/dist/src/jemalloc.c index 46ada482863d..ed5b321533cb 100644 --- a/external/bsd/jemalloc/dist/src/jemalloc.c +++ b/external/bsd/jemalloc/dist/src/jemalloc.c @@ -20,24 +20,31 @@ #include "jemalloc/internal/ticker.h" #include "jemalloc/internal/util.h" -__weak_alias(mallocx, je_mallocx) -__weak_alias(rallocx, je_rallocx) -__weak_alias(xallocx, je_xallocx) -__weak_alias(sallocx, je_sallocx) -__weak_alias(dallocx, je_dallocx) -__weak_alias(sdallocx, je_sdallocx) -__weak_alias(nallocx, je_nallocx) +#ifdef JEMALLOC_WEAK_NOSTD +__weak_alias(mallocx, __je_mallocx) +__weak_alias(rallocx, __je_rallocx) +__weak_alias(xallocx, __je_xallocx) +__weak_alias(sallocx, __je_sallocx) +__weak_alias(dallocx, __je_dallocx) +__weak_alias(sdallocx, __je_sdallocx) +__weak_alias(nallocx, __je_nallocx) -__weak_alias(mallctl, je_mallctl) -__weak_alias(mallctlnametomib, je_mallctlnametomib) -__weak_alias(mallctlbymib, je_mallctlbymib) +__weak_alias(mallctl, __je_mallctl) +__weak_alias(mallctlnametomib, __je_mallctlnametomib) +__weak_alias(mallctlbymib, __je_mallctlbymib) -__weak_alias(malloc_stats_print, je_malloc_stats_print) -__weak_alias(malloc_usable_size, je_malloc_usable_size) +__weak_alias(malloc_stats_print, __je_malloc_stats_print) +__weak_alias(malloc_usable_size, __je_malloc_usable_size) -__weak_alias(malloc_message, je_malloc_message) +__weak_alias(malloc_message, __je_malloc_message) +__weak_alias(malloc_conf, __je_malloc_conf) -__weak_alias(malloc_conf, je_malloc_conf) +__weak_alias(malloc_message_get, __je_malloc_message_get) +__weak_alias(malloc_conf_get, __je_malloc_conf_get) + +__weak_alias(malloc_message_set, __je_malloc_message_set) +__weak_alias(malloc_conf_set, __je_malloc_conf_set) +#endif /******************************************************************************/ /* Data. */ @@ -3354,4 +3361,28 @@ jemalloc_postfork_child(void) { ctl_postfork_child(tsd_tsdn(tsd)); } +void (* +je_malloc_message_get(void))(void *, const char *) +{ + return je_malloc_message; +} + +void +je_malloc_message_set(void (*m)(void *, const char *)) +{ + je_malloc_message = m; +} + +const char * +je_malloc_conf_get(void) +{ + return je_malloc_conf; +} + +void +je_malloc_conf_set(const char *m) +{ + je_malloc_conf = m; +} + /******************************************************************************/ diff --git a/external/bsd/jemalloc/include/jemalloc/jemalloc.h b/external/bsd/jemalloc/include/jemalloc/jemalloc.h index 40d14ae19e66..66ed9722e1a7 100644 --- a/external/bsd/jemalloc/include/jemalloc/jemalloc.h +++ b/external/bsd/jemalloc/include/jemalloc/jemalloc.h @@ -64,48 +64,51 @@ extern "C" { #ifndef JEMALLOC_NO_RENAME # define je_aligned_alloc aligned_alloc # define je_calloc calloc -# define je_dallocx dallocx # define je_free free +# define je_malloc malloc +# define je_posix_memalign posix_memalign +# define je_realloc realloc +# define je_valloc valloc + +# ifndef JEMALLOC_PROTECT_NOSTD +# define je_dallocx dallocx # define je_mallctl mallctl # define je_mallctlbymib mallctlbymib # define je_mallctlnametomib mallctlnametomib -# define je_malloc malloc # define je_malloc_conf malloc_conf +# define je_malloc_conf_get malloc_conf_get +# define je_malloc_conf_set malloc_conf_set # define je_malloc_message malloc_message +# define je_malloc_message_get malloc_message_get +# define je_malloc_message_set malloc_message_set # define je_malloc_stats_print malloc_stats_print # define je_malloc_usable_size malloc_usable_size # define je_mallocx mallocx # define je_nallocx nallocx -# define je_posix_memalign posix_memalign # define je_rallocx rallocx -# define je_realloc realloc # define je_sallocx sallocx # define je_sdallocx sdallocx # define je_xallocx xallocx -# define je_valloc valloc -#endif - -#ifdef JEMALLOC_WEAK_NOSTD - -#undef je_mallocx -#undef je_rallocx -#undef je_xallocx -#undef je_sallocx -#undef je_dallocx -#undef je_sdallocx -#undef je_nallocx - -#undef je_mallctl -#undef je_mallctlnametomib -#undef je_mallctlbymib - -#undef je_malloc_stats_print -#undef je_malloc_usable_size - -#undef je_malloc_message - -#undef je_malloc_conf - +# else +# define je_dallocx __je_dallocx +# define je_mallctl __je_mallctl +# define je_mallctlbymib __je_mallctlbymib +# define je_mallctlnametomib __je_mallctlnametomib +# define je_malloc_conf __je_malloc_conf +# define je_malloc_conf_get __je_malloc_conf_get +# define je_malloc_conf_set __je_malloc_conf_set +# define je_malloc_message __je_malloc_message +# define je_malloc_message_get __je_malloc_message_get +# define je_malloc_message_set __je_malloc_message_set +# define je_malloc_stats_print __je_malloc_stats_print +# define je_malloc_usable_size __je_malloc_usable_size +# define je_mallocx __je_mallocx +# define je_nallocx __je_nallocx +# define je_rallocx __je_rallocx +# define je_sallocx __je_sallocx +# define je_sdallocx __je_sdallocx +# define je_xallocx __je_xallocx +# endif #endif #include @@ -241,6 +244,12 @@ extern "C" { extern JEMALLOC_EXPORT const char *je_malloc_conf; extern JEMALLOC_EXPORT void (*je_malloc_message)(void *cbopaque, const char *s); +extern JEMALLOC_EXPORT const char *je_malloc_conf_get(void); +extern JEMALLOC_EXPORT void je_malloc_conf_set(const char *); +extern JEMALLOC_EXPORT void (*je_malloc_message_get(void)) + (void *cbopaque, const char *s); +extern JEMALLOC_EXPORT void je_malloc_message_set( + void (*)(void *cbopaque, const char *s)); JEMALLOC_EXPORT JEMALLOC_ALLOCATOR JEMALLOC_RESTRICT_RETURN void JEMALLOC_NOTHROW *je_malloc(size_t size) diff --git a/external/bsd/jemalloc/lib/Makefile b/external/bsd/jemalloc/lib/Makefile index ed8ec48fa5d5..60645f782c10 100644 --- a/external/bsd/jemalloc/lib/Makefile +++ b/external/bsd/jemalloc/lib/Makefile @@ -1,10 +1,10 @@ -# $NetBSD: Makefile,v 1.2 2019/03/04 19:41:37 christos Exp $ +# $NetBSD: Makefile,v 1.3 2019/03/12 15:13:25 christos Exp $ WARNS?= 5 .include LIB=jemalloc -.include "Makefile.inc" +SRCS=jemalloc_stub.c .include diff --git a/external/bsd/jemalloc/lib/Makefile.inc b/external/bsd/jemalloc/lib/Makefile.inc index 1f7bd57395ac..26b3b4445735 100644 --- a/external/bsd/jemalloc/lib/Makefile.inc +++ b/external/bsd/jemalloc/lib/Makefile.inc @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.5 2019/03/10 15:32:42 christos Exp $ +# $NetBSD: Makefile.inc,v 1.6 2019/03/12 15:13:25 christos Exp $ JEMALLOC:=${.PARSEDIR}/.. @@ -39,7 +39,7 @@ witness.c .PATH.3: ${JEMALLOC}/dist/doc .for i in ${JEMALLOC_SRCS} CPPFLAGS.${i}+=-I${JEMALLOC}/include -DJEMALLOC_NO_PRIVATE_NAMESPACE \ - -DJEMALLOC_WEAK_NOSTD -DJEMALLOC_DEBUG + -DJEMALLOC_PROTECT_NOSTD -DJEMALLOC_DEBUG COPTS.${i}+= -fvisibility=hidden -funroll-loops .endfor diff --git a/external/bsd/jemalloc/lib/jemalloc_stub.c b/external/bsd/jemalloc/lib/jemalloc_stub.c new file mode 100644 index 000000000000..01e74ec8739d --- /dev/null +++ b/external/bsd/jemalloc/lib/jemalloc_stub.c @@ -0,0 +1,141 @@ +/*- + * Copyright (c) 2019 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Christos Zoulas. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#include + +void *__je_mallocx(size_t, int); +void * +mallocx(size_t l, int f) +{ + return __je_mallocx(l, f); +} + +void *__je_rallocx(void *, size_t, int); +void * +rallocx(void *p, size_t l, int f) +{ + return __je_rallocx(p, l, f); +} + +size_t __je_xallocx(void *, size_t, size_t, int); +size_t +xallocx(void *p, size_t l, size_t s, int f) +{ + return __je_xallocx(p, l, s, f); +} + +size_t __je_sallocx(const void *, int); +size_t +sallocx(const void *p, int f) +{ + return __je_sallocx(p, f); +} + +void __je_dallocx(void *, int); +void +dallocx(void *p, int f) +{ + __je_dallocx(p, f); +} + +void __je_sdallocx(void *, size_t, int); +void +sdallocx(void *p, size_t l, int f) +{ + __je_sdallocx(p, l, f); +} + +size_t __je_nallocx(size_t, int); +size_t +nallocx(size_t l, int f) +{ + return __je_nallocx(l, f); +} + +int __je_mallctl(const char *, void *, size_t *, void *, size_t); +int +mallctl(const char *n, void *p, size_t *s, void *v, size_t l) +{ + return __je_mallctl(n, p, s, v, l); +} + +int __je_mallctlnametomib(const char *, size_t *, size_t *); +int +mallctlnametomib(const char *n, size_t *l, size_t *s) +{ + return __je_mallctlnametomib(n, l, s); +} + +int __je_mallctlbymib(const size_t *, size_t, void *, size_t *, void *, size_t); +int +mallctlbymib(const size_t *sp, size_t s, void *p , size_t *dp, void *r , + size_t l) +{ + return __je_mallctlbymib(sp, s, p , dp, r, l); +} + +void __je_malloc_stats_print(void (*)(void *, const char *), void *, + const char *); +void +malloc_stats_print(void (*f)(void *, const char *), void *p, const char *n) +{ + __je_malloc_stats_print(f, p, n); +} + +size_t __je_malloc_usable_size(const void *); +size_t +malloc_usable_size(const void *p) +{ + return __je_malloc_usable_size(p); +} +void (*__je_malloc_message_get(void))(void *, const char *); +void (* +malloc_message_get(void))(void *, const char *) +{ + return __je_malloc_message_get(); +} + +void __je_malloc_message_set(void (*)(void *, const char *)); +void +malloc_message_set(void (*m)(void *, const char *)) +{ + __je_malloc_message_set(m); +} + +const char *__je_malloc_conf_get(void); +const char * +malloc_conf_get(void) +{ + return __je_malloc_conf_get(); +} + +void __je_malloc_conf_set(const char *); +void malloc_conf_set(const char *m) +{ + __je_malloc_conf_set(m); +}