struct memprof_stats memprof_stats[MEMPROF_HASH_BUCKETS + 1] = { };
/* used to detect recursive calls */
-static THREAD_LOCAL int in_memprof = 0;
+#define MEMPROF_IN_INIT (1U << 0)
+
+static THREAD_LOCAL uint in_memprof = 0; // arithmetic OR of MEMPROF_IN_*
/* These ones are used by glibc and will be called early. They are in charge of
* initializing the handlers with the original functions.
*/
static void memprof_init()
{
- in_memprof++;
+ in_memprof |= MEMPROF_IN_INIT;
memprof_malloc_handler = get_sym_next_addr("malloc");
if (!memprof_malloc_handler)
memprof_die("FATAL: malloc() function not found.\n");
memprof_aligned_alloc_handler = get_sym_next_addr("aligned_alloc");
memprof_posix_memalign_handler = get_sym_next_addr("posix_memalign");
- in_memprof--;
+ in_memprof &= ~MEMPROF_IN_INIT;
}
/* the initial handlers will initialize all regular handlers and will call the
*/
static void *memprof_malloc_initial_handler(size_t size)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* it's likely that dlsym() needs malloc(), let's fail */
return NULL;
}
static void *memprof_calloc_initial_handler(size_t nmemb, size_t size)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* it's likely that dlsym() needs calloc(), let's fail */
return NULL;
}
static void *memprof_realloc_initial_handler(void *ptr, size_t size)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* it's likely that dlsym() needs realloc(), let's fail */
return NULL;
}
static char *memprof_strdup_initial_handler(const char *s)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs strdup(), let's fail */
return NULL;
}
static char *memprof_strndup_initial_handler(const char *s, size_t n)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs strndup(), let's fail */
return NULL;
}
static void *memprof_valloc_initial_handler(size_t sz)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs valloc(), let's fail */
return NULL;
}
static void *memprof_pvalloc_initial_handler(size_t sz)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs pvalloc(), let's fail */
return NULL;
}
static void *memprof_memalign_initial_handler(size_t al, size_t sz)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs memalign(), let's fail */
return NULL;
}
static void *memprof_aligned_alloc_initial_handler(size_t al, size_t sz)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs aligned_alloc(), let's fail */
return NULL;
}
static int memprof_posix_memalign_initial_handler(void **ptr, size_t al, size_t sz)
{
- if (in_memprof) {
+ if (in_memprof & MEMPROF_IN_INIT) {
/* probably that dlsym() needs posix_memalign(), let's fail */
return ENOMEM;
}