/* Malloc implementation for multiple threads without lock contention.
- Copyright (C) 2001-2019 Free Software Foundation, Inc.
+ Copyright (C) 2001-2021 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Wolfram Gloger <wg@malloc.de>, 2001.
You should have received a copy of the GNU Lesser General Public
License along with the GNU C Library; see the file COPYING.LIB. If
- not, see <http://www.gnu.org/licenses/>. */
+ not, see <https://www.gnu.org/licenses/>. */
#include <stdbool.h>
}
#if HAVE_TUNABLES
-static inline int do_set_mallopt_check (int32_t value);
-void
+static void
TUNABLE_CALLBACK (set_mallopt_check) (tunable_val_t *valp)
{
int32_t value = (int32_t) valp->numval;
# define TUNABLE_CALLBACK_FNDECL(__name, __type) \
static inline int do_ ## __name (__type value); \
-void \
+static void \
TUNABLE_CALLBACK (__name) (tunable_val_t *valp) \
{ \
__type value = (__type) (valp)->numval; \
TUNABLE_CALLBACK_FNDECL (set_tcache_count, size_t)
TUNABLE_CALLBACK_FNDECL (set_tcache_unsorted_limit, size_t)
#endif
+TUNABLE_CALLBACK_FNDECL (set_mxfast, size_t)
#else
/* Initialization routine. */
#include <string.h>
#ifdef SHARED
-static void *
-__failing_morecore (ptrdiff_t d)
-{
- return (void *) MORECORE_FAILURE;
-}
-
extern struct dl_open_hook *_dl_open_hook;
libc_hidden_proto (_dl_open_hook);
#endif
+#if USE_TCACHE
+static void tcache_key_initialize (void);
+#endif
+
static void
ptmalloc_init (void)
{
__malloc_initialized = 0;
+#if USE_TCACHE
+ tcache_key_initialize ();
+#endif
+
+#ifdef USE_MTAG
+ if ((TUNABLE_GET_FULL (glibc, mem, tagging, int32_t, NULL) & 1) != 0)
+ {
+ /* If the tunable says that we should be using tagged memory
+ and that morecore does not support tagged regions, then
+ disable it. */
+ if (__MTAG_SBRK_UNTAGGED)
+ __always_fail_morecore = true;
+
+ mtag_enabled = true;
+ mtag_mmap_flags = __MTAG_MMAP_FLAGS;
+ }
+#endif
+
#ifdef SHARED
- /* In case this libc copy is in a non-default namespace, never use brk.
- Likewise if dlopened from statically linked program. */
- Dl_info di;
- struct link_map *l;
-
- if (_dl_open_hook != NULL
- || (_dl_addr (ptmalloc_init, &di, &l, NULL) != 0
- && l->l_ns != LM_ID_BASE))
- __morecore = __failing_morecore;
+ /* In case this libc copy is in a non-default namespace, never use
+ brk. Likewise if dlopened from statically linked program. The
+ generic sbrk implementation also enforces this, but it is not
+ used on Hurd. */
+ if (!__libc_initial)
+ __always_fail_morecore = true;
#endif
thread_arena = &main_arena;
TUNABLE_GET (tcache_unsorted_limit, size_t,
TUNABLE_CALLBACK (set_tcache_unsorted_limit));
# endif
+ TUNABLE_GET (mxfast, size_t, TUNABLE_CALLBACK (set_mxfast));
#else
const char *s = NULL;
if (__glibc_likely (_environ != NULL))
if (s && s[0] != '\0' && s[0] != '0')
__malloc_check_init ();
#endif
-
-#if HAVE_MALLOC_INIT_HOOK
- void (*hook) (void) = atomic_forced_read (__malloc_initialize_hook);
- if (hook != NULL)
- (*hook)();
-#endif
- __malloc_initialized = 1;
}
/* Managing heaps and arenas (for concurrent threads) */
~MALLOC_ALIGN_MASK);
for (;; )
{
- fprintf (stderr, "chunk %p size %10lx", p, (long) p->size);
+ fprintf (stderr, "chunk %p size %10lx", p, (long) chunksize_nomask(p));
if (p == top (heap->ar_ptr))
{
fprintf (stderr, " (top)\n");
break;
}
- else if (p->size == (0 | PREV_INUSE))
+ else if (chunksize_nomask(p) == (0 | PREV_INUSE))
{
fprintf (stderr, " (fence)\n");
break;
}
}
}
- if (__mprotect (p2, size, PROT_READ | PROT_WRITE) != 0)
+ if (__mprotect (p2, size, mtag_mmap_flags | PROT_READ | PROT_WRITE) != 0)
{
__munmap (p2, HEAP_MAX_SIZE);
return 0;
{
if (__mprotect ((char *) h + h->mprotect_size,
(unsigned long) new_size - h->mprotect_size,
- PROT_READ | PROT_WRITE) != 0)
+ mtag_mmap_flags | PROT_READ | PROT_WRITE) != 0)
return -2;
h->mprotect_size = new_size;