michael@0: /* michael@0: * Copyright (c) 2010 The WebM project authors. All Rights Reserved. michael@0: * michael@0: * Use of this source code is governed by a BSD-style license michael@0: * that can be found in the LICENSE file in the root of the source michael@0: * tree. An additional intellectual property rights grant can be found michael@0: * in the file PATENTS. All contributing project authors may michael@0: * be found in the AUTHORS file in the root of the source tree. michael@0: */ michael@0: michael@0: michael@0: #ifndef __VPX_MEM_TRACKER_H__ michael@0: #define __VPX_MEM_TRACKER_H__ michael@0: michael@0: /* vpx_mem_tracker version info */ michael@0: #define vpx_mem_tracker_version "2.5.1.1" michael@0: michael@0: #define VPX_MEM_TRACKER_VERSION_CHIEF 2 michael@0: #define VPX_MEM_TRACKER_VERSION_MAJOR 5 michael@0: #define VPX_MEM_TRACKER_VERSION_MINOR 1 michael@0: #define VPX_MEM_TRACKER_VERSION_PATCH 1 michael@0: /* END - vpx_mem_tracker version info */ michael@0: michael@0: #include michael@0: michael@0: struct mem_block { michael@0: size_t addr; michael@0: unsigned int size, michael@0: line; michael@0: char *file; michael@0: struct mem_block *prev, michael@0: * next; michael@0: michael@0: int padded; // This mem_block has padding for integrity checks. michael@0: // As of right now, this should only be 0 if michael@0: // using vpx_mem_alloc to allocate cache memory. michael@0: // 2005-01-11 tjf michael@0: }; michael@0: michael@0: #if defined(__cplusplus) michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /* michael@0: vpx_memory_tracker_init(int padding_size, int pad_value) michael@0: padding_size - the size of the padding before and after each mem addr. michael@0: Values > 0 indicate that integrity checks can be performed michael@0: by inspecting these areas. michael@0: pad_value - the initial value within the padding area before and after michael@0: each mem addr. michael@0: michael@0: Initializes the memory tracker interface. Should be called before any michael@0: other calls to the memory tracker. michael@0: */ michael@0: int vpx_memory_tracker_init(int padding_size, int pad_value); michael@0: michael@0: /* michael@0: vpx_memory_tracker_destroy() michael@0: Deinitializes the memory tracker interface michael@0: */ michael@0: void vpx_memory_tracker_destroy(); michael@0: michael@0: /* michael@0: vpx_memory_tracker_add(size_t addr, unsigned int size, michael@0: char * file, unsigned int line) michael@0: addr - memory address to be added to list michael@0: size - size of addr michael@0: file - the file addr was referenced from michael@0: line - the line in file addr was referenced from michael@0: Adds memory address addr, it's size, file and line it came from michael@0: to the memory tracker allocation table michael@0: */ michael@0: void vpx_memory_tracker_add(size_t addr, unsigned int size, michael@0: char *file, unsigned int line, michael@0: int padded); michael@0: michael@0: /* michael@0: vpx_memory_tracker_add(size_t addr, unsigned int size, char * file, unsigned int line) michael@0: addr - memory address to be added to be removed michael@0: padded - if 0, disables bounds checking on this memory block even if bounds michael@0: checking is enabled. (for example, when allocating cache memory, we still want michael@0: to check for memory leaks, but we do not waste cache space for bounds check padding) michael@0: Removes the specified address from the memory tracker's allocation michael@0: table michael@0: Return: michael@0: 0: on success michael@0: -1: if memory allocation table's mutex could not be locked michael@0: -2: if the addr was not found in the list michael@0: */ michael@0: int vpx_memory_tracker_remove(size_t addr); michael@0: michael@0: /* michael@0: vpx_memory_tracker_find(unsigned int addr) michael@0: addr - address to be found in the memory tracker's michael@0: allocation table michael@0: Return: michael@0: If found, pointer to the memory block that matches addr michael@0: NULL otherwise michael@0: */ michael@0: struct mem_block *vpx_memory_tracker_find(size_t addr); michael@0: michael@0: /* michael@0: vpx_memory_tracker_dump() michael@0: Dumps the current contents of the memory michael@0: tracker allocation table michael@0: */ michael@0: void vpx_memory_tracker_dump(); michael@0: michael@0: /* michael@0: vpx_memory_tracker_check_integrity() michael@0: If a padding_size was provided to vpx_memory_tracker_init() michael@0: This function will verify that the region before and after each michael@0: memory address contains the specified pad_value. Should the check michael@0: fail, the filename and line of the check will be printed out. michael@0: */ michael@0: void vpx_memory_tracker_check_integrity(char *file, unsigned int line); michael@0: michael@0: /* michael@0: vpx_memory_tracker_set_log_type michael@0: type - value representing the logging type to use michael@0: option - type specific option. This will be interpreted differently michael@0: based on the type. michael@0: Sets the logging type for the memory tracker. michael@0: Values currently supported: michael@0: 0: if option is NULL, log to stderr, otherwise interpret option as a michael@0: filename and attempt to open it. michael@0: 1: Use output_debug_string (WIN32 only), option ignored michael@0: Return: michael@0: 0: on success michael@0: -1: if the logging type could not be set, because the value was invalid michael@0: or because a file could not be opened michael@0: */ michael@0: int vpx_memory_tracker_set_log_type(int type, char *option); michael@0: michael@0: /* michael@0: vpx_memory_tracker_set_log_func michael@0: userdata - ptr to be passed to the supplied logfunc, can be NULL michael@0: logfunc - the logging function to be used to output data from michael@0: vpx_memory_track_dump/check_integrity michael@0: Sets a logging function to be used by the memory tracker. michael@0: Return: michael@0: 0: on success michael@0: -1: if the logging type could not be set because logfunc was NULL michael@0: */ michael@0: int vpx_memory_tracker_set_log_func(void *userdata, michael@0: void(*logfunc)(void *userdata, michael@0: const char *fmt, va_list args)); michael@0: michael@0: /* Wrappers to standard library functions. */ michael@0: typedef void *(* mem_track_malloc_func)(size_t); michael@0: typedef void *(* mem_track_calloc_func)(size_t, size_t); michael@0: typedef void *(* mem_track_realloc_func)(void *, size_t); michael@0: typedef void (* mem_track_free_func)(void *); michael@0: typedef void *(* mem_track_memcpy_func)(void *, const void *, size_t); michael@0: typedef void *(* mem_track_memset_func)(void *, int, size_t); michael@0: typedef void *(* mem_track_memmove_func)(void *, const void *, size_t); michael@0: michael@0: /* michael@0: vpx_memory_tracker_set_functions michael@0: michael@0: Sets the function pointers for the standard library functions. michael@0: michael@0: Return: michael@0: 0: on success michael@0: -1: if the use global function pointers is not set. michael@0: */ michael@0: int vpx_memory_tracker_set_functions(mem_track_malloc_func g_malloc_l michael@0: , mem_track_calloc_func g_calloc_l michael@0: , mem_track_realloc_func g_realloc_l michael@0: , mem_track_free_func g_free_l michael@0: , mem_track_memcpy_func g_memcpy_l michael@0: , mem_track_memset_func g_memset_l michael@0: , mem_track_memmove_func g_memmove_l); michael@0: michael@0: #if defined(__cplusplus) michael@0: } michael@0: #endif michael@0: michael@0: #endif // __VPX_MEM_TRACKER_H__