1c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev/*
2c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Copyright (c) 2010, Texas Instruments Incorporated
3c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * All rights reserved.
4c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
5c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * Redistribution and use in source and binary forms, with or without
6c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * modification, are permitted provided that the following conditions
7c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * are met:
8c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
9c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * *  Redistributions of source code must retain the above copyright
10c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *    notice, this list of conditions and the following disclaimer.
11c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
12c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * *  Redistributions in binary form must reproduce the above copyright
13c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *    notice, this list of conditions and the following disclaimer in the
14c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *    documentation and/or other materials provided with the distribution.
15c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
16c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * *  Neither the name of Texas Instruments Incorporated nor the names of
17c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *    its contributors may be used to endorse or promote products derived
18c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *    from this software without specific prior written permission.
19c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev *
20c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
27c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
28c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
29c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
30c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev */
32c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
33c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#ifndef OMX_DEBUGMEM_H
34c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define OMX_DEBUGMEM_H
35c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
36c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#include <stdlib.h> // for size_t
37c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
38c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#if OMX_DEBUG
39c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevvoid* OMX_DebugMem_calloc(size_t num, size_t size,
40c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                           const char* file, const char* func, int line);
41c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevvoid* OMX_DebugMem_malloc(size_t size,
42c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                           const char* file, const char* func, int line);
43c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevvoid* OMX_DebugMem_realloc(void *ptr, size_t size,
44c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                           const char* file, const char* func, int line);
45c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevvoid  OMX_DebugMem_free(void* ptr,
46c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                         const char* file, const char* func, int line);
47c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevint   OMX_DebugMem_validate(void *ptr,
48c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev                         const char* file, const char* func, int line);
49c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
50c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchevvoid OMX_DebugMem_dump(const char *file, const char *func, int line);
51c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#endif
52c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
53c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define OMX_MASK_MEMORY    0x00010000 /** One of the reserved bits from OMX_MASK_USERMASK */
54c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
55c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#define MEM_DEBUG_HANDLE_DESCR "DebugMemory"
56c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
57c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#if OMX_DEBUG
58c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define malloc(x)    OMX_DebugMem_malloc(x,__FILE__,__FUNCTION__,__LINE__)
59c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define calloc(n,s)  OMX_DebugMem_calloc(n,s,__FILE__,__FUNCTION__,__LINE__)
60c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define realloc(x,s) OMX_DebugMem_realloc(x,s,__FILE__,__FUNCTION__,__LINE__)
61c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define free(x)      OMX_DebugMem_free(x,__FILE__,__FUNCTION__ ,__LINE__)
62c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define validate(x)  OMX_DebugMem_validate(x, __FILE__,__FUNCTION__ ,__LINE__)
63c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define dump()      OMX_DebugMem_dump( __FILE__,__FUNCTION__ ,__LINE__)
64c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#else
65c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define validate(x)
66c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev    #define dump()
67c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#endif
68c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
69c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
70c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev#endif
71c322989ae6ff6769490828de1b5eda12b749cce9Iliyan Malchev
72