media/libvpx/vpx_mem/include/vpx_mem_tracker.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial