| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. | 2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 | 11 |
| 12 #ifndef __VPX_MEM_TRACKER_H__ | 12 #ifndef __VPX_MEM_TRACKER_H__ |
| 13 #define __VPX_MEM_TRACKER_H__ | 13 #define __VPX_MEM_TRACKER_H__ |
| 14 | 14 |
| 15 /* vpx_mem_tracker version info */ | 15 /* vpx_mem_tracker version info */ |
| 16 #define vpx_mem_tracker_version "2.5.1.1" | 16 #define vpx_mem_tracker_version "2.5.1.1" |
| 17 | 17 |
| 18 #define VPX_MEM_TRACKER_VERSION_CHIEF 2 | 18 #define VPX_MEM_TRACKER_VERSION_CHIEF 2 |
| 19 #define VPX_MEM_TRACKER_VERSION_MAJOR 5 | 19 #define VPX_MEM_TRACKER_VERSION_MAJOR 5 |
| 20 #define VPX_MEM_TRACKER_VERSION_MINOR 1 | 20 #define VPX_MEM_TRACKER_VERSION_MINOR 1 |
| 21 #define VPX_MEM_TRACKER_VERSION_PATCH 1 | 21 #define VPX_MEM_TRACKER_VERSION_PATCH 1 |
| 22 /* END - vpx_mem_tracker version info */ | 22 /* END - vpx_mem_tracker version info */ |
| 23 | 23 |
| 24 #include <stdarg.h> | 24 #include <stdarg.h> |
| 25 | 25 |
| 26 struct mem_block | 26 struct mem_block { |
| 27 { | 27 size_t addr; |
| 28 size_t addr; | 28 unsigned int size, |
| 29 unsigned int size, | 29 line; |
| 30 line; | 30 char *file; |
| 31 char *file; | 31 struct mem_block *prev, |
| 32 struct mem_block *prev, | 32 * next; |
| 33 * next; | |
| 34 | 33 |
| 35 int padded; // This mem_block has padding for integrity checks. | 34 int padded; // This mem_block has padding for integrity checks. |
| 36 // As of right now, this should only be 0 if | 35 // As of right now, this should only be 0 if |
| 37 // using vpx_mem_alloc to allocate cache memory. | 36 // using vpx_mem_alloc to allocate cache memory. |
| 38 // 2005-01-11 tjf | 37 // 2005-01-11 tjf |
| 39 }; | 38 }; |
| 40 | 39 |
| 41 #if defined(__cplusplus) | 40 #if defined(__cplusplus) |
| 42 extern "C" { | 41 extern "C" { |
| 43 #endif | 42 #endif |
| 44 | 43 |
| 45 /* | 44 /* |
| 46 vpx_memory_tracker_init(int padding_size, int pad_value) | 45 vpx_memory_tracker_init(int padding_size, int pad_value) |
| 47 padding_size - the size of the padding before and after each mem addr. | 46 padding_size - the size of the padding before and after each mem addr. |
| 48 Values > 0 indicate that integrity checks can be perfor
med | 47 Values > 0 indicate that integrity checks can be performe
d |
| 49 by inspecting these areas. | 48 by inspecting these areas. |
| 50 pad_value - the initial value within the padding area before and after | 49 pad_value - the initial value within the padding area before and after |
| 51 each mem addr. | 50 each mem addr. |
| 52 | 51 |
| 53 Initializes the memory tracker interface. Should be called before any | 52 Initializes the memory tracker interface. Should be called before any |
| 54 other calls to the memory tracker. | 53 other calls to the memory tracker. |
| 55 */ | 54 */ |
| 56 int vpx_memory_tracker_init(int padding_size, int pad_value); | 55 int vpx_memory_tracker_init(int padding_size, int pad_value); |
| 57 | 56 |
| 58 /* | 57 /* |
| 59 vpx_memory_tracker_destroy() | 58 vpx_memory_tracker_destroy() |
| 60 Deinitializes the memory tracker interface | 59 Deinitializes the memory tracker interface |
| 61 */ | 60 */ |
| 62 void vpx_memory_tracker_destroy(); | 61 void vpx_memory_tracker_destroy(); |
| 63 | 62 |
| 64 /* | 63 /* |
| 65 vpx_memory_tracker_add(size_t addr, unsigned int size, | 64 vpx_memory_tracker_add(size_t addr, unsigned int size, |
| 66 char * file, unsigned int line) | 65 char * file, unsigned int line) |
| 67 addr - memory address to be added to list | 66 addr - memory address to be added to list |
| 68 size - size of addr | 67 size - size of addr |
| 69 file - the file addr was referenced from | 68 file - the file addr was referenced from |
| 70 line - the line in file addr was referenced from | 69 line - the line in file addr was referenced from |
| 71 Adds memory address addr, it's size, file and line it came from | 70 Adds memory address addr, it's size, file and line it came from |
| 72 to the memory tracker allocation table | 71 to the memory tracker allocation table |
| 73 */ | 72 */ |
| 74 void vpx_memory_tracker_add(size_t addr, unsigned int size, | 73 void vpx_memory_tracker_add(size_t addr, unsigned int size, |
| 75 char *file, unsigned int line, | 74 char *file, unsigned int line, |
| 76 int padded); | 75 int padded); |
| 77 | 76 |
| 78 /* | 77 /* |
| 79 vpx_memory_tracker_add(size_t addr, unsigned int size, char * file, unsi
gned int line) | 78 vpx_memory_tracker_add(size_t addr, unsigned int size, char * file, unsign
ed int line) |
| 80 addr - memory address to be added to be removed | 79 addr - memory address to be added to be removed |
| 81 padded - if 0, disables bounds checking on this memory block even if b
ounds | 80 padded - if 0, disables bounds checking on this memory block even if bou
nds |
| 82 checking is enabled. (for example, when allocating cache memory, we st
ill want | 81 checking is enabled. (for example, when allocating cache memory, we stil
l want |
| 83 to check for memory leaks, but we do not waste cache space for bounds
check padding) | 82 to check for memory leaks, but we do not waste cache space for bounds ch
eck padding) |
| 84 Removes the specified address from the memory tracker's allocation | 83 Removes the specified address from the memory tracker's allocation |
| 85 table | 84 table |
| 86 Return: | 85 Return: |
| 87 0: on success | 86 0: on success |
| 88 -1: if memory allocation table's mutex could not be locked | 87 -1: if memory allocation table's mutex could not be locked |
| 89 -2: if the addr was not found in the list | 88 -2: if the addr was not found in the list |
| 90 */ | 89 */ |
| 91 int vpx_memory_tracker_remove(size_t addr); | 90 int vpx_memory_tracker_remove(size_t addr); |
| 92 | 91 |
| 93 /* | 92 /* |
| 94 vpx_memory_tracker_find(unsigned int addr) | 93 vpx_memory_tracker_find(unsigned int addr) |
| 95 addr - address to be found in the memory tracker's | 94 addr - address to be found in the memory tracker's |
| 96 allocation table | 95 allocation table |
| 97 Return: | 96 Return: |
| 98 If found, pointer to the memory block that matches addr | 97 If found, pointer to the memory block that matches addr |
| 99 NULL otherwise | 98 NULL otherwise |
| 100 */ | 99 */ |
| 101 struct mem_block *vpx_memory_tracker_find(size_t addr); | 100 struct mem_block *vpx_memory_tracker_find(size_t addr); |
| 102 | 101 |
| 103 /* | 102 /* |
| 104 vpx_memory_tracker_dump() | 103 vpx_memory_tracker_dump() |
| 105 Dumps the current contents of the memory | 104 Dumps the current contents of the memory |
| 106 tracker allocation table | 105 tracker allocation table |
| 107 */ | 106 */ |
| 108 void vpx_memory_tracker_dump(); | 107 void vpx_memory_tracker_dump(); |
| 109 | 108 |
| 110 /* | 109 /* |
| 111 vpx_memory_tracker_check_integrity() | 110 vpx_memory_tracker_check_integrity() |
| 112 If a padding_size was provided to vpx_memory_tracker_init() | 111 If a padding_size was provided to vpx_memory_tracker_init() |
| 113 This function will verify that the region before and after each | 112 This function will verify that the region before and after each |
| 114 memory address contains the specified pad_value. Should the check | 113 memory address contains the specified pad_value. Should the check |
| 115 fail, the filename and line of the check will be printed out. | 114 fail, the filename and line of the check will be printed out. |
| 116 */ | 115 */ |
| 117 void vpx_memory_tracker_check_integrity(char *file, unsigned int line); | 116 void vpx_memory_tracker_check_integrity(char *file, unsigned int line); |
| 118 | 117 |
| 119 /* | 118 /* |
| 120 vpx_memory_tracker_set_log_type | 119 vpx_memory_tracker_set_log_type |
| 121 type - value representing the logging type to use | 120 type - value representing the logging type to use |
| 122 option - type specific option. This will be interpreted differently | 121 option - type specific option. This will be interpreted differently |
| 123 based on the type. | 122 based on the type. |
| 124 Sets the logging type for the memory tracker. | 123 Sets the logging type for the memory tracker. |
| 125 Values currently supported: | 124 Values currently supported: |
| 126 0: if option is NULL, log to stderr, otherwise interpret option as a | 125 0: if option is NULL, log to stderr, otherwise interpret option as a |
| 127 filename and attempt to open it. | 126 filename and attempt to open it. |
| 128 1: Use output_debug_string (WIN32 only), option ignored | 127 1: Use output_debug_string (WIN32 only), option ignored |
| 129 Return: | 128 Return: |
| 130 0: on success | 129 0: on success |
| 131 -1: if the logging type could not be set, because the value was invali
d | 130 -1: if the logging type could not be set, because the value was invalid |
| 132 or because a file could not be opened | 131 or because a file could not be opened |
| 133 */ | 132 */ |
| 134 int vpx_memory_tracker_set_log_type(int type, char *option); | 133 int vpx_memory_tracker_set_log_type(int type, char *option); |
| 135 | 134 |
| 136 /* | 135 /* |
| 137 vpx_memory_tracker_set_log_func | 136 vpx_memory_tracker_set_log_func |
| 138 userdata - ptr to be passed to the supplied logfunc, can be NULL | 137 userdata - ptr to be passed to the supplied logfunc, can be NULL |
| 139 logfunc - the logging function to be used to output data from | 138 logfunc - the logging function to be used to output data from |
| 140 vpx_memory_track_dump/check_integrity | 139 vpx_memory_track_dump/check_integrity |
| 141 Sets a logging function to be used by the memory tracker. | 140 Sets a logging function to be used by the memory tracker. |
| 142 Return: | 141 Return: |
| 143 0: on success | 142 0: on success |
| 144 -1: if the logging type could not be set because logfunc was NULL | 143 -1: if the logging type could not be set because logfunc was NULL |
| 145 */ | 144 */ |
| 146 int vpx_memory_tracker_set_log_func(void *userdata, | 145 int vpx_memory_tracker_set_log_func(void *userdata, |
| 147 void(*logfunc)(void *userdata, | 146 void(*logfunc)(void *userdata, |
| 148 const char *fmt, va_list args)); | 147 const char *fmt, va_list ar
gs)); |
| 149 | 148 |
| 150 /* Wrappers to standard library functions. */ | 149 /* Wrappers to standard library functions. */ |
| 151 typedef void*(* mem_track_malloc_func)(size_t); | 150 typedef void *(* mem_track_malloc_func)(size_t); |
| 152 typedef void*(* mem_track_calloc_func)(size_t, size_t); | 151 typedef void *(* mem_track_calloc_func)(size_t, size_t); |
| 153 typedef void*(* mem_track_realloc_func)(void *, size_t); | 152 typedef void *(* mem_track_realloc_func)(void *, size_t); |
| 154 typedef void (* mem_track_free_func)(void *); | 153 typedef void (* mem_track_free_func)(void *); |
| 155 typedef void*(* mem_track_memcpy_func)(void *, const void *, size_t); | 154 typedef void *(* mem_track_memcpy_func)(void *, const void *, size_t); |
| 156 typedef void*(* mem_track_memset_func)(void *, int, size_t); | 155 typedef void *(* mem_track_memset_func)(void *, int, size_t); |
| 157 typedef void*(* mem_track_memmove_func)(void *, const void *, size_t); | 156 typedef void *(* mem_track_memmove_func)(void *, const void *, size_t); |
| 158 | 157 |
| 159 /* | 158 /* |
| 160 vpx_memory_tracker_set_functions | 159 vpx_memory_tracker_set_functions |
| 161 | 160 |
| 162 Sets the function pointers for the standard library functions. | 161 Sets the function pointers for the standard library functions. |
| 163 | 162 |
| 164 Return: | 163 Return: |
| 165 0: on success | 164 0: on success |
| 166 -1: if the use global function pointers is not set. | 165 -1: if the use global function pointers is not set. |
| 167 */ | 166 */ |
| 168 int vpx_memory_tracker_set_functions(mem_track_malloc_func g_malloc_l | 167 int vpx_memory_tracker_set_functions(mem_track_malloc_func g_malloc_l |
| 169 , mem_track_calloc_func g_calloc_l | 168 , mem_track_calloc_func g_calloc_l |
| 170 , mem_track_realloc_func g_realloc_l | 169 , mem_track_realloc_func g_realloc_l |
| 171 , mem_track_free_func g_free_l | 170 , mem_track_free_func g_free_l |
| 172 , mem_track_memcpy_func g_memcpy_l | 171 , mem_track_memcpy_func g_memcpy_l |
| 173 , mem_track_memset_func g_memset_l | 172 , mem_track_memset_func g_memset_l |
| 174 , mem_track_memmove_func g_memmove_l); | 173 , mem_track_memmove_func g_memmove_l); |
| 175 | 174 |
| 176 #if defined(__cplusplus) | 175 #if defined(__cplusplus) |
| 177 } | 176 } |
| 178 #endif | 177 #endif |
| 179 | 178 |
| 180 #endif //__VPX_MEM_TRACKER_H__ | 179 #endif // __VPX_MEM_TRACKER_H__ |
| OLD | NEW |