1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/libvpx/vpx_mem/include/vpx_mem_tracker.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,179 @@ 1.4 +/* 1.5 + * Copyright (c) 2010 The WebM project authors. All Rights Reserved. 1.6 + * 1.7 + * Use of this source code is governed by a BSD-style license 1.8 + * that can be found in the LICENSE file in the root of the source 1.9 + * tree. An additional intellectual property rights grant can be found 1.10 + * in the file PATENTS. All contributing project authors may 1.11 + * be found in the AUTHORS file in the root of the source tree. 1.12 + */ 1.13 + 1.14 + 1.15 +#ifndef __VPX_MEM_TRACKER_H__ 1.16 +#define __VPX_MEM_TRACKER_H__ 1.17 + 1.18 +/* vpx_mem_tracker version info */ 1.19 +#define vpx_mem_tracker_version "2.5.1.1" 1.20 + 1.21 +#define VPX_MEM_TRACKER_VERSION_CHIEF 2 1.22 +#define VPX_MEM_TRACKER_VERSION_MAJOR 5 1.23 +#define VPX_MEM_TRACKER_VERSION_MINOR 1 1.24 +#define VPX_MEM_TRACKER_VERSION_PATCH 1 1.25 +/* END - vpx_mem_tracker version info */ 1.26 + 1.27 +#include <stdarg.h> 1.28 + 1.29 +struct mem_block { 1.30 + size_t addr; 1.31 + unsigned int size, 1.32 + line; 1.33 + char *file; 1.34 + struct mem_block *prev, 1.35 + * next; 1.36 + 1.37 + int padded; // This mem_block has padding for integrity checks. 1.38 + // As of right now, this should only be 0 if 1.39 + // using vpx_mem_alloc to allocate cache memory. 1.40 + // 2005-01-11 tjf 1.41 +}; 1.42 + 1.43 +#if defined(__cplusplus) 1.44 +extern "C" { 1.45 +#endif 1.46 + 1.47 + /* 1.48 + vpx_memory_tracker_init(int padding_size, int pad_value) 1.49 + padding_size - the size of the padding before and after each mem addr. 1.50 + Values > 0 indicate that integrity checks can be performed 1.51 + by inspecting these areas. 1.52 + pad_value - the initial value within the padding area before and after 1.53 + each mem addr. 1.54 + 1.55 + Initializes the memory tracker interface. Should be called before any 1.56 + other calls to the memory tracker. 1.57 + */ 1.58 + int vpx_memory_tracker_init(int padding_size, int pad_value); 1.59 + 1.60 + /* 1.61 + vpx_memory_tracker_destroy() 1.62 + Deinitializes the memory tracker interface 1.63 + */ 1.64 + void vpx_memory_tracker_destroy(); 1.65 + 1.66 + /* 1.67 + vpx_memory_tracker_add(size_t addr, unsigned int size, 1.68 + char * file, unsigned int line) 1.69 + addr - memory address to be added to list 1.70 + size - size of addr 1.71 + file - the file addr was referenced from 1.72 + line - the line in file addr was referenced from 1.73 + Adds memory address addr, it's size, file and line it came from 1.74 + to the memory tracker allocation table 1.75 + */ 1.76 + void vpx_memory_tracker_add(size_t addr, unsigned int size, 1.77 + char *file, unsigned int line, 1.78 + int padded); 1.79 + 1.80 + /* 1.81 + vpx_memory_tracker_add(size_t addr, unsigned int size, char * file, unsigned int line) 1.82 + addr - memory address to be added to be removed 1.83 + padded - if 0, disables bounds checking on this memory block even if bounds 1.84 + checking is enabled. (for example, when allocating cache memory, we still want 1.85 + to check for memory leaks, but we do not waste cache space for bounds check padding) 1.86 + Removes the specified address from the memory tracker's allocation 1.87 + table 1.88 + Return: 1.89 + 0: on success 1.90 + -1: if memory allocation table's mutex could not be locked 1.91 + -2: if the addr was not found in the list 1.92 + */ 1.93 + int vpx_memory_tracker_remove(size_t addr); 1.94 + 1.95 + /* 1.96 + vpx_memory_tracker_find(unsigned int addr) 1.97 + addr - address to be found in the memory tracker's 1.98 + allocation table 1.99 + Return: 1.100 + If found, pointer to the memory block that matches addr 1.101 + NULL otherwise 1.102 + */ 1.103 + struct mem_block *vpx_memory_tracker_find(size_t addr); 1.104 + 1.105 + /* 1.106 + vpx_memory_tracker_dump() 1.107 + Dumps the current contents of the memory 1.108 + tracker allocation table 1.109 + */ 1.110 + void vpx_memory_tracker_dump(); 1.111 + 1.112 + /* 1.113 + vpx_memory_tracker_check_integrity() 1.114 + If a padding_size was provided to vpx_memory_tracker_init() 1.115 + This function will verify that the region before and after each 1.116 + memory address contains the specified pad_value. Should the check 1.117 + fail, the filename and line of the check will be printed out. 1.118 + */ 1.119 + void vpx_memory_tracker_check_integrity(char *file, unsigned int line); 1.120 + 1.121 + /* 1.122 + vpx_memory_tracker_set_log_type 1.123 + type - value representing the logging type to use 1.124 + option - type specific option. This will be interpreted differently 1.125 + based on the type. 1.126 + Sets the logging type for the memory tracker. 1.127 + Values currently supported: 1.128 + 0: if option is NULL, log to stderr, otherwise interpret option as a 1.129 + filename and attempt to open it. 1.130 + 1: Use output_debug_string (WIN32 only), option ignored 1.131 + Return: 1.132 + 0: on success 1.133 + -1: if the logging type could not be set, because the value was invalid 1.134 + or because a file could not be opened 1.135 + */ 1.136 + int vpx_memory_tracker_set_log_type(int type, char *option); 1.137 + 1.138 + /* 1.139 + vpx_memory_tracker_set_log_func 1.140 + userdata - ptr to be passed to the supplied logfunc, can be NULL 1.141 + logfunc - the logging function to be used to output data from 1.142 + vpx_memory_track_dump/check_integrity 1.143 + Sets a logging function to be used by the memory tracker. 1.144 + Return: 1.145 + 0: on success 1.146 + -1: if the logging type could not be set because logfunc was NULL 1.147 + */ 1.148 + int vpx_memory_tracker_set_log_func(void *userdata, 1.149 + void(*logfunc)(void *userdata, 1.150 + const char *fmt, va_list args)); 1.151 + 1.152 + /* Wrappers to standard library functions. */ 1.153 + typedef void *(* mem_track_malloc_func)(size_t); 1.154 + typedef void *(* mem_track_calloc_func)(size_t, size_t); 1.155 + typedef void *(* mem_track_realloc_func)(void *, size_t); 1.156 + typedef void (* mem_track_free_func)(void *); 1.157 + typedef void *(* mem_track_memcpy_func)(void *, const void *, size_t); 1.158 + typedef void *(* mem_track_memset_func)(void *, int, size_t); 1.159 + typedef void *(* mem_track_memmove_func)(void *, const void *, size_t); 1.160 + 1.161 + /* 1.162 + vpx_memory_tracker_set_functions 1.163 + 1.164 + Sets the function pointers for the standard library functions. 1.165 + 1.166 + Return: 1.167 + 0: on success 1.168 + -1: if the use global function pointers is not set. 1.169 + */ 1.170 + int vpx_memory_tracker_set_functions(mem_track_malloc_func g_malloc_l 1.171 +, mem_track_calloc_func g_calloc_l 1.172 +, mem_track_realloc_func g_realloc_l 1.173 +, mem_track_free_func g_free_l 1.174 +, mem_track_memcpy_func g_memcpy_l 1.175 +, mem_track_memset_func g_memset_l 1.176 +, mem_track_memmove_func g_memmove_l); 1.177 + 1.178 +#if defined(__cplusplus) 1.179 +} 1.180 +#endif 1.181 + 1.182 +#endif // __VPX_MEM_TRACKER_H__