bind9/lib/isc/mem_p.h
Michał Kępień e974f98eb4
Improve stability of the jemalloc workaround
When jemalloc is linked into BIND 9 binaries (rather than preloaded or
used as the system allocator), depending on the decisions made by the
linker, the malloc() symbol may be resolved to a non-jemalloc
implementation at runtime.  Such a scenario foils the workaround added
in commit 2da371d005 as it relies on the
jemalloc implementation of malloc() to be executed.

Handle the above scenario properly by calling mallocx() explicitly
instead of relying on the runtime resolution of the malloc() symbol.
Use trivial wrapper functions to avoid the need to copy multiple #ifdef
lines from lib/isc/mem.c to lib/isc/trampoline.c.  Using a simpler
alternative, e.g. calling isc_mem_create() & isc_mem_destroy(), was
already considered before and rejected, as described in the log message
for commit 2da371d005.

ADJUST_ZERO_ALLOCATION_SIZE() is only used in isc__mem_free_noctx() to
concisely avoid compilation warnings about its 'size' parameter not
being used when building against jemalloc < 4.0.0 (as sdallocx() is then
redefined to dallocx(), which has a different signature).
2023-11-01 18:04:07 +01:00

47 lines
1 KiB
C

/*
* Copyright (C) Internet Systems Consortium, Inc. ("ISC")
*
* SPDX-License-Identifier: MPL-2.0
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*
* See the COPYRIGHT file distributed with this work for additional
* information regarding copyright ownership.
*/
#pragma once
#include <stdio.h>
#include <isc/mem.h>
/*! \file */
void
isc__mem_printactive(isc_mem_t *mctx, FILE *file);
/*%<
* For use by unit tests, prints active memory blocks for
* a single memory context.
*/
void *
isc__mem_alloc_noctx(size_t size);
void
isc__mem_free_noctx(void *ptr, size_t size);
/*%<
* Allocate memory that is not associated with an isc_mem memory context.
*
* For use purely in the isc_trampoline unit, to avoid the need of copying
* multiple #ifdef lines from lib/isc/mem.c to lib/isc/trampoline.c.
*/
void
isc__mem_checkdestroyed(void);
void
isc__mem_initialize(void);
void
isc__mem_shutdown(void);