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_H__ michael@0: #define __VPX_MEM_H__ michael@0: michael@0: #include "vpx_config.h" michael@0: #if defined(__uClinux__) michael@0: # include michael@0: #endif michael@0: michael@0: /* vpx_mem version info */ michael@0: #define vpx_mem_version "2.2.1.5" michael@0: michael@0: #define VPX_MEM_VERSION_CHIEF 2 michael@0: #define VPX_MEM_VERSION_MAJOR 2 michael@0: #define VPX_MEM_VERSION_MINOR 1 michael@0: #define VPX_MEM_VERSION_PATCH 5 michael@0: /* end - vpx_mem version info */ michael@0: michael@0: #ifndef VPX_TRACK_MEM_USAGE michael@0: # define VPX_TRACK_MEM_USAGE 0 /* enable memory tracking/integrity checks */ michael@0: #endif michael@0: #ifndef VPX_CHECK_MEM_FUNCTIONS michael@0: # define VPX_CHECK_MEM_FUNCTIONS 0 /* enable basic safety checks in _memcpy, michael@0: _memset, and _memmove */ michael@0: #endif michael@0: #ifndef REPLACE_BUILTIN_FUNCTIONS michael@0: # define REPLACE_BUILTIN_FUNCTIONS 0 /* replace builtin functions with their michael@0: vpx_ equivalents */ michael@0: #endif michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #if defined(__cplusplus) michael@0: extern "C" { michael@0: #endif michael@0: michael@0: /* michael@0: vpx_mem_get_version() michael@0: provided for runtime version checking. Returns an unsigned int of the form michael@0: CHIEF | MAJOR | MINOR | PATCH, where the chief version number is the high michael@0: order byte. michael@0: */ michael@0: unsigned int vpx_mem_get_version(void); michael@0: michael@0: /* michael@0: vpx_mem_set_heap_size(size_t size) michael@0: size - size in bytes for the memory manager to allocate for its heap michael@0: Sets the memory manager's initial heap size michael@0: Return: michael@0: 0: on success michael@0: -1: if memory manager calls have not been included in the vpx_mem lib michael@0: -2: if the memory manager has been compiled to use static memory michael@0: -3: if the memory manager has already allocated its heap michael@0: */ michael@0: int vpx_mem_set_heap_size(size_t size); michael@0: michael@0: void *vpx_memalign(size_t align, size_t size); michael@0: void *vpx_malloc(size_t size); michael@0: void *vpx_calloc(size_t num, size_t size); michael@0: void *vpx_realloc(void *memblk, size_t size); michael@0: void vpx_free(void *memblk); michael@0: michael@0: void *vpx_memcpy(void *dest, const void *src, size_t length); michael@0: void *vpx_memset(void *dest, int val, size_t length); michael@0: void *vpx_memmove(void *dest, const void *src, size_t count); michael@0: michael@0: /* special memory functions */ michael@0: void *vpx_mem_alloc(int id, size_t size, size_t align); michael@0: void vpx_mem_free(int id, void *mem, size_t size); michael@0: michael@0: /* Wrappers to standard library functions. */ michael@0: typedef void *(* g_malloc_func)(size_t); michael@0: typedef void *(* g_calloc_func)(size_t, size_t); michael@0: typedef void *(* g_realloc_func)(void *, size_t); michael@0: typedef void (* g_free_func)(void *); michael@0: typedef void *(* g_memcpy_func)(void *, const void *, size_t); michael@0: typedef void *(* g_memset_func)(void *, int, size_t); michael@0: typedef void *(* g_memmove_func)(void *, const void *, size_t); michael@0: michael@0: int vpx_mem_set_functions(g_malloc_func g_malloc_l michael@0: , g_calloc_func g_calloc_l michael@0: , g_realloc_func g_realloc_l michael@0: , g_free_func g_free_l michael@0: , g_memcpy_func g_memcpy_l michael@0: , g_memset_func g_memset_l michael@0: , g_memmove_func g_memmove_l); michael@0: int vpx_mem_unset_functions(void); michael@0: michael@0: michael@0: /* some defines for backward compatibility */ michael@0: #define DMEM_GENERAL 0 michael@0: michael@0: // (*)< michael@0: michael@0: #if REPLACE_BUILTIN_FUNCTIONS michael@0: # ifndef __VPX_MEM_C__ michael@0: # define memalign vpx_memalign michael@0: # define malloc vpx_malloc michael@0: # define calloc vpx_calloc michael@0: # define realloc vpx_realloc michael@0: # define free vpx_free michael@0: # define memcpy vpx_memcpy michael@0: # define memmove vpx_memmove michael@0: # define memset vpx_memset michael@0: # endif michael@0: #endif michael@0: michael@0: #if CONFIG_MEM_TRACKER michael@0: #include michael@0: /*from vpx_mem/vpx_mem_tracker.c*/ michael@0: extern void vpx_memory_tracker_dump(); michael@0: extern void vpx_memory_tracker_check_integrity(char *file, unsigned int line); michael@0: extern int vpx_memory_tracker_set_log_type(int type, char *option); michael@0: extern 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: # ifndef __VPX_MEM_C__ michael@0: # define vpx_memalign(align, size) xvpx_memalign((align), (size), __FILE__, __LINE__) michael@0: # define vpx_malloc(size) xvpx_malloc((size), __FILE__, __LINE__) michael@0: # define vpx_calloc(num, size) xvpx_calloc(num, size, __FILE__, __LINE__) michael@0: # define vpx_realloc(addr, size) xvpx_realloc(addr, size, __FILE__, __LINE__) michael@0: # define vpx_free(addr) xvpx_free(addr, __FILE__, __LINE__) michael@0: # define vpx_memory_tracker_check_integrity() vpx_memory_tracker_check_integrity(__FILE__, __LINE__) michael@0: # define vpx_mem_alloc(id,size,align) xvpx_mem_alloc(id, size, align, __FILE__, __LINE__) michael@0: # define vpx_mem_free(id,mem,size) xvpx_mem_free(id, mem, size, __FILE__, __LINE__) michael@0: # endif michael@0: michael@0: void *xvpx_memalign(size_t align, size_t size, char *file, int line); michael@0: void *xvpx_malloc(size_t size, char *file, int line); michael@0: void *xvpx_calloc(size_t num, size_t size, char *file, int line); michael@0: void *xvpx_realloc(void *memblk, size_t size, char *file, int line); michael@0: void xvpx_free(void *memblk, char *file, int line); michael@0: void *xvpx_mem_alloc(int id, size_t size, size_t align, char *file, int line); michael@0: void xvpx_mem_free(int id, void *mem, size_t size, char *file, int line); michael@0: michael@0: #else michael@0: # ifndef __VPX_MEM_C__ michael@0: # define vpx_memory_tracker_dump() michael@0: # define vpx_memory_tracker_check_integrity() michael@0: # define vpx_memory_tracker_set_log_type(t,o) 0 michael@0: # define vpx_memory_tracker_set_log_func(u,f) 0 michael@0: # endif michael@0: #endif michael@0: michael@0: #if !VPX_CHECK_MEM_FUNCTIONS michael@0: # ifndef __VPX_MEM_C__ michael@0: # include michael@0: # define vpx_memcpy memcpy michael@0: # define vpx_memset memset michael@0: # define vpx_memmove memmove michael@0: # endif michael@0: #endif michael@0: michael@0: #ifdef VPX_MEM_PLTFRM michael@0: # include VPX_MEM_PLTFRM michael@0: #endif michael@0: michael@0: #if defined(__cplusplus) michael@0: } michael@0: #endif michael@0: michael@0: #endif /* __VPX_MEM_H__ */