Files
systemd/src/basic/dlfcn-util.h
T
Christian Brauner 8b12350b75 dlfcn-util: migrate to public SD_ELF_NOTE_DLOPEN() API
Switch all internal callers from the private ELF_NOTE_DLOPEN() macro to
the new public SD_ELF_NOTE_DLOPEN() API from sd-dlopen.h, and remove
the now-redundant macro definitions from dlfcn-util.h.

Signed-off-by: Christian Brauner <brauner@kernel.org>
2026-03-18 10:28:11 +00:00

43 lines
1.9 KiB
C

/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once
#include <dlfcn.h> /* IWYU pragma: export */
#include "basic-forward.h"
void* safe_dlclose(void *dl);
static inline void dlclosep(void **dlp) {
safe_dlclose(*dlp);
}
int dlopen_verbose(void **dlp, const char *filename);
int dlsym_many_or_warn_sentinel(void *dl, int log_level, ...) _sentinel_;
int dlopen_many_sym_or_warn_sentinel(void **dlp, const char *filename, int log_level, ...) _sentinel_;
#define dlsym_many_or_warn(dl, log_level, ...) \
dlsym_many_or_warn_sentinel(dl, log_level, __VA_ARGS__, NULL)
#define dlopen_many_sym_or_warn(dlp, filename, log_level, ...) \
dlopen_many_sym_or_warn_sentinel(dlp, filename, log_level, __VA_ARGS__, NULL)
#define DLSYM_PROTOTYPE(symbol) \
typeof(symbol)* sym_##symbol
/* Macro useful for putting together variable/symbol name pairs when calling dlsym_many_or_warn(). Assumes
* that each library symbol to resolve will be placed in a variable with the "sym_" prefix, i.e. a symbol
* "foobar" is loaded into a variable "sym_foobar". */
#define DLSYM_ARG(arg) \
({ assert_cc(__builtin_types_compatible_p(typeof(sym_##arg), typeof(&arg))); &sym_##arg; }), STRINGIFY(arg)
/* libbpf is a bit confused about type-safety and API compatibility. Provide a macro that can tape over that mess. Sad. */
#define DLSYM_ARG_FORCE(arg) \
&sym_##arg, STRINGIFY(arg)
/* If called dlopen_many_sym_or_warn() will fail with EPERM. This can be used to block lazy loading of shared
* libs, if we transfer a process into a different namespace. Note that this does not work for all calls of
* dlopen(), just those through our dlopen_safe() wrapper (which we use comprehensively in our
* codebase). This hence has *no* effect on NSS. (Would be great if we could change that...) */
void block_dlopen(void);
int dlopen_safe(const char *filename, void **ret, const char **reterr_dlerror);