• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /* -*- c++ -*- */
19 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
20 
21 //           O S C L _ M E M _ A U D I T _ I N T E R N A L S
22 
23 // = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
24 
25 /*! \addtogroup osclmemory OSCL Memory
26  *
27  * @{
28  */
29 
30 
31 /*! \file oscl_mem_audit_internals.h
32     \brief This file contains the internal definitions for the mem audit library
33 */
34 
35 
36 #ifndef OSCL_MEM_AUDIT_INTERNALS_H
37 #define OSCL_MEM_AUDIT_INTERNALS_H
38 
39 
40 #include "oscl_base.h"
41 #include "oscl_mem_audit.h"
42 #include "oscl_mem_inst.h"
43 
44 #define OSCL_DISABLE_WARNING_TRUNCATE_DEBUG_MESSAGE
45 #include "osclconfig_compiler_warnings.h"
46 
47 #if(PVMEM_INST_LEVEL>0)
48 #define MM_AUDIT_ALLOC_NODE_SUPPORT 1
49 #define MM_AUDIT_FENCE_SUPPORT 1
50 #define MM_AUDIT_INCLUDE_ALL_HEAP_VALIDATION 1
51 #define MM_AUDIT_FILL_SUPPORT 1
52 #define MM_AUDIT_FAILURE_SIMULATION_SUPPORT 1
53 #else
54 #define MM_AUDIT_ALLOC_NODE_SUPPORT 1
55 #define MM_AUDIT_FENCE_SUPPORT 0
56 #define MM_AUDIT_INCLUDE_ALL_HEAP_VALIDATION 1
57 #define MM_AUDIT_FILL_SUPPORT 0
58 #define MM_AUDIT_FAILURE_SIMULATION_SUPPORT 1
59 #endif
60 
61 #define FENCE_PATTERN 0xAA
62 #define MIN_FENCE_SIZE 4
63 
64 #ifdef MEM_ALIGN_4
65 #define MEM_ALIGN_SIZE 4
66 #else
67 #define MEM_ALIGN_SIZE 8
68 #endif
69 
70 
71 
72 /* CURRENTLY THIS STRUCTURE IS A MULTIPLE OF 8 BYTES.  MAKE SURE IT
73  * MAINTAINS A SIZE THAT IS AN INTEGER MULTIPLE OF THE ALIGNMENT SIZE
74  * FOR THE PLATFORM IN QUESTION.  ADD PAD BYTES TO THE STRUCTURE
75  * IF NECESSARY
76  */
77 struct MM_AllocBlockHdr
78 {
79     void *pNode; //pointer to either a stats node or an alloc node.
80     uint32 size;
81 
82     void *pRootNode; //pointer to root node, to use when de-allocating.
83     uint32 pad;//to maintain 8-byte alignment
84 
85     /* windows compiler assumes the the assignment
86      * is a pure-virtual declaration and does not allow
87      * it to be non-zero.  We actually set the value below.
88      */
89     static const uint32 ALLOC_NODE_FLAG; // = 0x80000000;
90 
isAllocNodePtrMM_AllocBlockHdr91     bool isAllocNodePtr()
92     {
93         return ((size & ALLOC_NODE_FLAG) != 0);
94     };
setAllocNodeFlagMM_AllocBlockHdr95     void setAllocNodeFlag()
96     {
97         size |= ALLOC_NODE_FLAG;
98     };
99 
MM_AllocBlockHdrMM_AllocBlockHdr100     MM_AllocBlockHdr(): pNode(0), size(0), pRootNode(0) {};
MM_AllocBlockHdrMM_AllocBlockHdr101     MM_AllocBlockHdr(void* ptr, uint32 inSize): pNode(ptr), size(inSize) {};
102 };
103 
104 // actually set the value here.
105 const uint32 MM_AllocBlockHdr::ALLOC_NODE_FLAG = 0x80000000;
106 
107 #define COMPUTE_MEM_ALIGN_SIZE(x,y,z) (y+(((x+y)%z) ? (z - (x+y)%z) : 0))
108 
109 struct MM_AllocBlockFence
110 {
111 
112     uint8 pad[COMPUTE_MEM_ALIGN_SIZE(sizeof(MM_AllocBlockHdr), MIN_FENCE_SIZE, MEM_ALIGN_SIZE)];
MM_AllocBlockFenceMM_AllocBlockFence113     MM_AllocBlockFence()
114     {
115         fill_fence();
116     };
117 
fill_fenceMM_AllocBlockFence118     void fill_fence()
119     {
120         oscl_memset(pad, FENCE_PATTERN, sizeof(pad));
121     };
122 
check_fenceMM_AllocBlockFence123     bool check_fence()
124     {
125         for (uint ii = 0; ii < sizeof(pad); ++ii)
126         {
127             if (pad[ii] != FENCE_PATTERN) return false;
128         }
129         return true;
130     };
131 };
132 
133 
134 
135 
136 #define DEFAULT_PREFILL_PATTERN 0x96
137 #define DEFAULT_POSTFILL_PATTERN 0x5A
138 
139 
140 
141 
142 
143 #endif
144 
145 /*! @} */
146