diff options
author | Costa Tsaousis <costa@netdata.cloud> | 2022-10-13 08:04:14 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-13 08:04:14 +0300 |
commit | 2974f525ec703329ef6ad079d8f6c685cfab11ad (patch) | |
tree | b0e289a5fee787d764ee37cb8b5c2ac7bcd1bd20 /libnetdata/libnetdata.h | |
parent | c805a9afad71ac96e703d599cbd6f54c29142ca7 (diff) |
overload libc memory allocators with custom ones to trace all allocations (#13810)
* overload libc memory allocators with custom ones to trace all allocations
* grab libc pointers for external c plugins
* use -ldl when necessary; fallback to work without dlsym when it is not available
* initialize global variable
* add optional dl libs
* dynamically link every library function when needed for the first time
* prevent crashes on musl libc
* another attempt
* dont dereference function
* attempt no 3
* attempt no 4
* cleanup - all attempts failed
* dont enable tracing of allocations
* missing parenthesis
Diffstat (limited to 'libnetdata/libnetdata.h')
-rw-r--r-- | libnetdata/libnetdata.h | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/libnetdata/libnetdata.h b/libnetdata/libnetdata.h index dc199ffb87..496a7fe4bc 100644 --- a/libnetdata/libnetdata.h +++ b/libnetdata/libnetdata.h @@ -15,9 +15,10 @@ extern "C" { #define NETDATA_INTERNAL_CHECKS 1 #endif -#if defined(NETDATA_INTERNAL_CHECKS) && !defined(NETDATA_TRACE_ALLOCATIONS) -#define NETDATA_TRACE_ALLOCATIONS 1 -#endif +// NETDATA_TRACE_ALLOCATIONS does not work under musl libc, so don't enable it +//#if defined(NETDATA_INTERNAL_CHECKS) && !defined(NETDATA_TRACE_ALLOCATIONS) +//#define NETDATA_TRACE_ALLOCATIONS 1 +//#endif #define OS_LINUX 1 #define OS_FREEBSD 2 @@ -312,12 +313,14 @@ int malloc_trace_walkthrough(int (*callback)(void *item, void *data), void *data #define mallocz(size) mallocz_int(size, __FILE__, __FUNCTION__, __LINE__) #define reallocz(ptr, size) reallocz_int(ptr, size, __FILE__, __FUNCTION__, __LINE__) #define freez(ptr) freez_int(ptr, __FILE__, __FUNCTION__, __LINE__) +#define mallocz_usable_size(ptr) mallocz_usable_size_int(ptr, __FILE__, __FUNCTION__, __LINE__) char *strdupz_int(const char *s, const char *file, const char *function, size_t line); void *callocz_int(size_t nmemb, size_t size, const char *file, const char *function, size_t line); void *mallocz_int(size_t size, const char *file, const char *function, size_t line); void *reallocz_int(void *ptr, size_t size, const char *file, const char *function, size_t line); void freez_int(void *ptr, const char *file, const char *function, size_t line); +size_t mallocz_usable_size_int(void *ptr, const char *file, const char *function, size_t line); #else // NETDATA_TRACE_ALLOCATIONS char *strdupz(const char *s) MALLOCLIKE NEVERNULL; @@ -327,6 +330,8 @@ void *reallocz(void *ptr, size_t size) MALLOCLIKE NEVERNULL; void freez(void *ptr); #endif // NETDATA_TRACE_ALLOCATIONS +void posix_memfree(void *ptr); + void json_escape_string(char *dst, const char *src, size_t size); void json_fix_string(char *s); |