HPCToolkit
memleak-overrides.c File Reference
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <string.h>
#include <ucontext.h>
#include <stdlib.h>
#include <malloc.h>
#include <unistd.h>
#include <sys/mman.h>
#include <sample-sources/memleak.h>
#include <messages/messages.h>
#include <safe-sampling.h>
#include <sample_event.h>
#include <monitor-exts/monitor_ext.h>
#include <lib/prof-lean/spinlock.h>
#include <lib/prof-lean/splay-macros.h>
#include <utilities/arch/inline-asm-gctxt.h>
#include <utilities/arch/mcontext.h>
Include dependency graph for memleak-overrides.c:

Go to the source code of this file.

Classes

struct  leakinfo_s
 

Macros

#define __USE_XOPEN_EXTENDED
 
#define _XOPEN_SOURCE   600
 
#define MEMLEAK_USE_HYBRID_LAYOUT   1
 
#define MEMLEAK_MAGIC   0x68706374
 
#define MEMLEAK_DEFAULT_PAGESIZE   4096
 
#define HPCRUN_MEMLEAK_PROB   "HPCRUN_MEMLEAK_PROB"
 
#define DEFAULT_PROB   0.1
 
#define real_memalign   __libc_memalign
 
#define real_valloc   __libc_valloc
 
#define real_malloc   __libc_malloc
 
#define real_free   __libc_free
 
#define real_realloc   __libc_realloc
 

Typedefs

typedef struct leakinfo_s leakinfo_t
 
typedef void * memalign_fcn(size_t, size_t)
 
typedef void * valloc_fcn(size_t)
 
typedef void * malloc_fcn(size_t)
 
typedef void free_fcn(void *)
 
typedef void * realloc_fcn(void *, size_t)
 

Enumerations

enum  { MEMLEAK_LOC_HEAD = 1, MEMLEAK_LOC_FOOT, MEMLEAK_LOC_NONE }
 

Functions

static struct leakinfo_ssplay (struct leakinfo_s *root, void *key)
 
static void splay_insert (struct leakinfo_s *node)
 
static struct leakinfo_ssplay_delete (void *memblock)
 
static float string_to_prob (char *str)
 
static void memleak_initialize (void)
 
static int memleak_same_page (void *p1, void *p2)
 
static int memleak_get_malloc_loc (void *sys_ptr, size_t bytes, size_t align, void **appl_ptr, leakinfo_t **info_ptr)
 
static int memleak_get_free_loc (void *appl_ptr, void **sys_ptr, leakinfo_t **info_ptr)
 
static void memleak_add_leakinfo (const char *name, void *sys_ptr, void *appl_ptr, leakinfo_t *info_ptr, size_t bytes, ucontext_t *uc, int loc)
 
static void * memleak_malloc_helper (const char *name, size_t bytes, size_t align, int clear, ucontext_t *uc, int *ret)
 
static void memleak_free_helper (const char *name, void *sys_ptr, void *appl_ptr, leakinfo_t *info_ptr, int loc)
 
int MONITOR_EXT_WRAP_NAME() posix_memalign (void **memptr, size_t alignment, size_t bytes)
 
void *MONITOR_EXT_WRAP_NAME() memalign (size_t boundary, size_t bytes)
 
void *MONITOR_EXT_WRAP_NAME() valloc (size_t bytes)
 
void *MONITOR_EXT_WRAP_NAME() malloc (size_t bytes)
 
void *MONITOR_EXT_WRAP_NAME() calloc (size_t nmemb, size_t bytes)
 
void MONITOR_EXT_WRAP_NAME() free (void *ptr)
 
void *MONITOR_EXT_WRAP_NAME() realloc (void *ptr, size_t bytes)
 

Variables

leakinfo_t leakinfo_NULL = { .magic = 0, .context = NULL, .bytes = 0 }
 
memalign_fcn real_memalign
 
valloc_fcn real_valloc
 
malloc_fcn real_malloc
 
free_fcn real_free
 
realloc_fcn real_realloc
 
static int leak_detection_enabled = 0
 
static int leak_detection_init = 0
 
static int use_memleak_prob = 0
 
static float memleak_prob = 0.0
 
static struct leakinfo_smemleak_tree_root = NULL
 
static spinlock_t memtree_lock = SPINLOCK_UNLOCKED
 
static int leakinfo_size = sizeof(struct leakinfo_s)
 
static long memleak_pagesize = MEMLEAK_DEFAULT_PAGESIZE
 
static char * loc_name [4]
 

Macro Definition Documentation

◆ __USE_XOPEN_EXTENDED

#define __USE_XOPEN_EXTENDED

Definition at line 60 of file memleak-overrides.c.

◆ _XOPEN_SOURCE

#define _XOPEN_SOURCE   600

Definition at line 73 of file memleak-overrides.c.

◆ DEFAULT_PROB

#define DEFAULT_PROB   0.1

Definition at line 144 of file memleak-overrides.c.

◆ HPCRUN_MEMLEAK_PROB

#define HPCRUN_MEMLEAK_PROB   "HPCRUN_MEMLEAK_PROB"

Definition at line 143 of file memleak-overrides.c.

◆ MEMLEAK_DEFAULT_PAGESIZE

#define MEMLEAK_DEFAULT_PAGESIZE   4096

Definition at line 141 of file memleak-overrides.c.

◆ MEMLEAK_MAGIC

#define MEMLEAK_MAGIC   0x68706374

Definition at line 140 of file memleak-overrides.c.

◆ MEMLEAK_USE_HYBRID_LAYOUT

#define MEMLEAK_USE_HYBRID_LAYOUT   1

Definition at line 138 of file memleak-overrides.c.

◆ real_free

#define real_free   __libc_free

Definition at line 156 of file memleak-overrides.c.

◆ real_malloc

#define real_malloc   __libc_malloc

Definition at line 155 of file memleak-overrides.c.

◆ real_memalign

#define real_memalign   __libc_memalign

Definition at line 153 of file memleak-overrides.c.

◆ real_realloc

#define real_realloc   __libc_realloc

Definition at line 157 of file memleak-overrides.c.

◆ real_valloc

#define real_valloc   __libc_valloc

Definition at line 154 of file memleak-overrides.c.

Typedef Documentation

◆ free_fcn

typedef void free_fcn(void *)

Definition at line 129 of file memleak-overrides.c.

◆ leakinfo_t

typedef struct leakinfo_s leakinfo_t

◆ malloc_fcn

typedef void* malloc_fcn(size_t)

Definition at line 128 of file memleak-overrides.c.

◆ memalign_fcn

typedef void* memalign_fcn(size_t, size_t)

Definition at line 126 of file memleak-overrides.c.

◆ realloc_fcn

typedef void* realloc_fcn(void *, size_t)

Definition at line 130 of file memleak-overrides.c.

◆ valloc_fcn

typedef void* valloc_fcn(size_t)

Definition at line 127 of file memleak-overrides.c.

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
MEMLEAK_LOC_HEAD 
MEMLEAK_LOC_FOOT 
MEMLEAK_LOC_NONE 

Definition at line 183 of file memleak-overrides.c.

Function Documentation

◆ calloc()

void* MONITOR_EXT_WRAP_NAME() calloc ( size_t  nmemb,
size_t  bytes 
)

Definition at line 704 of file memleak-overrides.c.

Here is the call graph for this function:

◆ free()

void MONITOR_EXT_WRAP_NAME() free ( void *  ptr)

Definition at line 737 of file memleak-overrides.c.

Here is the call graph for this function:

◆ malloc()

void* MONITOR_EXT_WRAP_NAME() malloc ( size_t  bytes)

Definition at line 681 of file memleak-overrides.c.

Here is the call graph for this function:

◆ memalign()

void* MONITOR_EXT_WRAP_NAME() memalign ( size_t  boundary,
size_t  bytes 
)

Definition at line 635 of file memleak-overrides.c.

Here is the call graph for this function:

◆ memleak_add_leakinfo()

static void memleak_add_leakinfo ( const char *  name,
void *  sys_ptr,
void *  appl_ptr,
leakinfo_t info_ptr,
size_t  bytes,
ucontext_t *  uc,
int  loc 
)
static

Definition at line 442 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_free_helper()

static void memleak_free_helper ( const char *  name,
void *  sys_ptr,
void *  appl_ptr,
leakinfo_t info_ptr,
int  loc 
)
static

Definition at line 555 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_get_free_loc()

static int memleak_get_free_loc ( void *  appl_ptr,
void **  sys_ptr,
leakinfo_t **  info_ptr 
)
static

Definition at line 398 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_get_malloc_loc()

static int memleak_get_malloc_loc ( void *  sys_ptr,
size_t  bytes,
size_t  align,
void **  appl_ptr,
leakinfo_t **  info_ptr 
)
static

Definition at line 372 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_initialize()

static void memleak_initialize ( void  )
static

Definition at line 303 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_malloc_helper()

static void* memleak_malloc_helper ( const char *  name,
size_t  bytes,
size_t  align,
int  clear,
ucontext_t *  uc,
int *  ret 
)
static

Definition at line 489 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ memleak_same_page()

static int memleak_same_page ( void *  p1,
void *  p2 
)
inlinestatic

Definition at line 349 of file memleak-overrides.c.

Here is the caller graph for this function:

◆ posix_memalign()

int MONITOR_EXT_WRAP_NAME() posix_memalign ( void **  memptr,
size_t  alignment,
size_t  bytes 
)

Definition at line 610 of file memleak-overrides.c.

Here is the call graph for this function:

◆ realloc()

void* MONITOR_EXT_WRAP_NAME() realloc ( void *  ptr,
size_t  bytes 
)

Definition at line 771 of file memleak-overrides.c.

Here is the call graph for this function:

◆ splay()

static struct leakinfo_s* splay ( struct leakinfo_s root,
void *  key 
)
static

Definition at line 201 of file memleak-overrides.c.

Here is the caller graph for this function:

◆ splay_delete()

static struct leakinfo_s* splay_delete ( void *  memblock)
static

Definition at line 239 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ splay_insert()

static void splay_insert ( struct leakinfo_s node)
static

Definition at line 209 of file memleak-overrides.c.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ string_to_prob()

static float string_to_prob ( char *  str)
static

Definition at line 281 of file memleak-overrides.c.

Here is the caller graph for this function:

◆ valloc()

void* MONITOR_EXT_WRAP_NAME() valloc ( size_t  bytes)

Definition at line 658 of file memleak-overrides.c.

Here is the call graph for this function:

Variable Documentation

◆ leak_detection_enabled

int leak_detection_enabled = 0
static

Definition at line 172 of file memleak-overrides.c.

◆ leak_detection_init

int leak_detection_init = 0
static

Definition at line 173 of file memleak-overrides.c.

◆ leakinfo_NULL

leakinfo_t leakinfo_NULL = { .magic = 0, .context = NULL, .bytes = 0 }

Definition at line 124 of file memleak-overrides.c.

◆ leakinfo_size

int leakinfo_size = sizeof(struct leakinfo_s)
static

Definition at line 180 of file memleak-overrides.c.

◆ loc_name

char* loc_name[4]
static
Initial value:
= {
NULL, "header", "footer", "none"
}
#define NULL
Definition: ElfHelper.cpp:85

Definition at line 189 of file memleak-overrides.c.

◆ memleak_pagesize

long memleak_pagesize = MEMLEAK_DEFAULT_PAGESIZE
static

Definition at line 181 of file memleak-overrides.c.

◆ memleak_prob

float memleak_prob = 0.0
static

Definition at line 175 of file memleak-overrides.c.

◆ memleak_tree_root

struct leakinfo_s* memleak_tree_root = NULL
static

Definition at line 177 of file memleak-overrides.c.

◆ memtree_lock

spinlock_t memtree_lock = SPINLOCK_UNLOCKED
static

Definition at line 178 of file memleak-overrides.c.

◆ real_free

free_fcn real_free

◆ real_malloc

malloc_fcn real_malloc

◆ real_memalign

memalign_fcn real_memalign

◆ real_realloc

realloc_fcn real_realloc

◆ real_valloc

valloc_fcn real_valloc

◆ use_memleak_prob

int use_memleak_prob = 0
static

Definition at line 174 of file memleak-overrides.c.