libsystemd = shared_library(
'systemd',
- disable_mempool_c,
version : libsystemd_version,
include_directories : libsystemd_includes,
link_args : ['-shared',
basic_gcrypt_sources,
basic_compress_sources,
fundamental_sources,
- disable_mempool_c,
include_directories : libsystemd_includes,
build_by_default : static_libsystemd != 'false',
install : static_libsystemd != 'false',
libudev = shared_library(
'udev',
- disable_mempool_c,
version : libudev_version,
include_directories : includes,
link_args : ['-shared',
shared_sources,
libsystemd_sources,
libudev_sources,
- disable_mempool_c,
include_directories : includes,
build_by_default : static_libudev != 'false',
install : static_libudev != 'false',
test_dlopen = executable(
'test-dlopen',
test_dlopen_c,
- disable_mempool_c,
include_directories : includes,
link_with : [libbasic],
dependencies : [libdl],
nss = shared_library(
'nss_' + module,
sources,
- disable_mempool_c,
version : '2',
include_directories : incs,
# Note that we link NSS modules with '-z nodelete' so that mempools never get orphaned
static struct HashmapBase* hashmap_base_new(const struct hash_ops *hash_ops, enum HashmapType type HASHMAP_DEBUG_PARAMS) {
HashmapBase *h;
const struct hashmap_type_info *hi = &hashmap_type_info[type];
- bool up;
- up = mempool_enabled();
+ bool use_pool = mempool_enabled && mempool_enabled();
- h = up ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
+ h = use_pool ? mempool_alloc0_tile(hi->mempool) : malloc0(hi->head_size);
if (!h)
return NULL;
h->type = type;
- h->from_pool = up;
+ h->from_pool = use_pool;
h->hash_ops = hash_ops ?: &trivial_hash_ops;
if (type == HASHMAP_TYPE_ORDERED) {
#include <stdint.h>
#include <stdlib.h>
-#include "env-util.h"
#include "macro.h"
#include "memory-util.h"
#include "mempool.h"
-#include "process-util.h"
-#include "util.h"
struct pool {
struct pool *next;
mp->freelist = p;
}
-bool mempool_enabled(void) {
- static int b = -1;
-
- if (!is_main_thread())
- return false;
-
- if (!mempool_use_allowed)
- b = false;
- if (b < 0)
- b = getenv_bool("SYSTEMD_MEMPOOL") != 0;
-
- return b;
-}
-
#if VALGRIND
void mempool_drop(struct mempool *mp) {
struct pool *p = mp->first_pool;
.at_least = alloc_at_least, \
}
-extern const bool mempool_use_allowed;
-bool mempool_enabled(void);
+__attribute__((weak)) bool mempool_enabled(void);
#if VALGRIND
void mempool_drop(struct mempool *mp);
+++ /dev/null
-/* SPDX-License-Identifier: LGPL-2.1-or-later */
-
-#include "mempool.h"
-
-const bool mempool_use_allowed = false;
'sd-utf8/sd-utf8.c',
) + sd_journal_sources + id128_sources + sd_daemon_sources + sd_event_sources + sd_login_sources
-disable_mempool_c = files('disable-mempool.c')
libsystemd_c_args = ['-fvisibility=default']
/* SPDX-License-Identifier: LGPL-2.1-or-later */
+#include <stdbool.h>
+
+#include "env-util.h"
#include "mempool.h"
+#include "process-util.h"
+
+bool mempool_enabled(void) {
+ static int cache = -1;
+
+ if (!is_main_thread())
+ return false;
+
+ if (cache < 0)
+ cache = getenv_bool("SYSTEMD_MEMPOOL") != 0;
-const bool mempool_use_allowed = true;
+ return cache;
+}
#include <pthread.h>
+#include "mempool.h"
#include "process-util.h"
#include "set.h"
#include "tests.h"
assert_se(*s);
assert_se(!is_main_thread());
+ assert_se(mempool_enabled);
+ assert_se(!mempool_enabled());
+
assert_se(set_size(*s) == NUM);
*s = set_free(*s);
log_info("Testing with SYSTEMD_MEMPOOL=%s", val);
assert_se(setenv("SYSTEMD_MEMPOOL", val, true) == 0);
+
assert_se(is_main_thread());
+ assert_se(mempool_enabled); /* It is a weak symbol, but we expect it to be available */
+ assert_se(!mempool_enabled());
assert_se(s = set_new(NULL));
for (i = 0; i < NUM; i++)