| 1 | /* |
| 2 | * SPDX-License-Identifier: MIT |
| 3 | * |
| 4 | * Copyright (C) 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> |
| 5 | * |
| 6 | * dlfcn.h compatibility layer. |
| 7 | */ |
| 8 | |
| 9 | #ifndef _UST_COMMON_COMPAT_DLFCN_H |
| 10 | #define _UST_COMMON_COMPAT_DLFCN_H |
| 11 | |
| 12 | #ifdef _DLFCN_H |
| 13 | #error "Please include compat/dlfcn.h before dlfcn.h." |
| 14 | #endif /* _DLFCN_H */ |
| 15 | |
| 16 | #ifdef __GLIBC__ |
| 17 | /* |
| 18 | * glibc declares dlsym() and dlerror() with __attribute__((leaf)) (see |
| 19 | * THROW annotation). Unfortunately, this is not in sync with reality, |
| 20 | * as those functions call the memory allocator. Work-around this glibc |
| 21 | * bug by declaring our own symbols. |
| 22 | * |
| 23 | * There has been a similar issue for dlopen() and dlclose(), as |
| 24 | * constructors and destructors are called from these functions, so they |
| 25 | * are clearly non-leaf. Work-around the issue for those too for older |
| 26 | * glibc where these have not been fixed. |
| 27 | */ |
| 28 | #define dlopen glibc_dlopen_proto_lies_about_leafness |
| 29 | #define dlclose glibc_dlclose_proto_lies_about_leafness |
| 30 | #define dlsym glibc_dlsym_proto_lies_about_leafness |
| 31 | #define dlerror glibc_dlerror_proto_lies_about_leafness |
| 32 | #define dlmopen glibc_dlmopen_proto_lies_about_leafness |
| 33 | #define dlvsym glibc_dlvsym_proto_lies_about_leafness |
| 34 | #include <dlfcn.h> |
| 35 | #undef dlvsym |
| 36 | #undef dlmopen |
| 37 | #undef dlerror |
| 38 | #undef dlsym |
| 39 | #undef dlclose |
| 40 | #undef dlopen |
| 41 | |
| 42 | extern void *dlopen(__const char *__file, int __mode); |
| 43 | extern int dlclose(void *__handle) __nonnull ((1)); |
| 44 | extern void *dlsym(void *__restrict __handle, |
| 45 | __const char *__restrict __name) __nonnull ((2)); |
| 46 | extern char *dlerror(void); |
| 47 | #ifdef __USE_GNU |
| 48 | extern void *dlmopen(Lmid_t __nsid, const char *__file, int __mode); |
| 49 | extern void *dlvsym(void *__restrict __handle, |
| 50 | __const char *__restrict __name, |
| 51 | __const char *__restrict __version); |
| 52 | #endif |
| 53 | #else |
| 54 | #include <dlfcn.h> |
| 55 | #endif /* __GLIBC__ */ |
| 56 | |
| 57 | #endif /* _UST_COMMON_COMPAT_DLFCN_H */ |