1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     fnd_DetailHeapCommon.h
4 
5   Copyright (C)2009-2012 Nintendo Co., Ltd.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Rev: 46347 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NN_LIBRARIES_FND_DETAIL_FND_DETAIL_HEAP_COMMON_H_
17 #define NN_LIBRARIES_FND_DETAIL_FND_DETAIL_HEAP_COMMON_H_
18 
19 #include <nn/types.h>
20 #include <nn/fnd/detail/fnd_DetailHeapHead.h>
21 #include "./fnd_DetailList.h"
22 
23 #ifdef __cplusplus
24 
25 namespace nn { namespace fnd { namespace detail {
26 /* Please see man pages for details
27 
28 
29 */
30 /* Please see man pages for details
31 
32 
33 */
34 //
35 /* ========================================================================
36     Macro Constants
37    ======================================================================== */
38 
39 // Invalid heap handle
40 #define NN_OS_HEAP_INVALID_HANDLE     NULL
41 
42 // Default alignment size when memory is allocated from heap
43 #define NN_OS_HEAP_DEFAULT_ALIGNMENT    4
44 
45 #define NNSI_CREATE_HEAP_SIGNATURE(a,b,c,d)  ( ((a & 0xFF) << 24) | ((b & 0xFF) << 16) | ((c & 0xFF) << 8) | ((d & 0xFF) << 0) )
46 
47 // Signature of expanded heap
48 #define NNSI_EXPHEAP_SIGNATURE    NNSI_CREATE_HEAP_SIGNATURE('E','X','P','H')
49 
50 // Signature of frame heap
51 #define NNSI_FRMHEAP_SIGNATURE    NNSI_CREATE_HEAP_SIGNATURE('F','R','M','H')
52 
53 // Signature of unit heap
54 #define NNSI_UNTHEAP_SIGNATURE    NNSI_CREATE_HEAP_SIGNATURE('U','N','T','H')
55 
56 
57 /* ------------------------------------------------------------------------
58     Fill-related
59    ------------------------------------------------------------------------ */
60 
61 // Zero out memory when memory is allocated.
62 #define NN_OS_HEAP_OPT_0_CLEAR        (1 <<0)
63 
64 // Memory filled when heap is created, memory is allocated, or memory is freed.
65 #define NN_OS_HEAP_OPT_DEBUG_FILL     (1 <<1)
66 
67 
68 /* ------------------------------------------------------------------------
69     Heap check related
70    ------------------------------------------------------------------------ */
71 
72 //  If this bit stands, output error
73 #define NN_OS_HEAP_ERROR_PRINT        (1 <<0)
74 
75 
76 /* ========================================================================
77     enum constant
78    ======================================================================== */
79 
80 enum {
81     NN_OS_HEAP_FILL_NOUSE,    // When debug fill is not used
82     NN_OS_HEAP_FILL_ALLOC,    // When debug fill is allocated
83     NN_OS_HEAP_FILL_FREE,     // When debug fill is freed
84 
85     NN_OS_HEAP_FILL_MAX
86 };
87 
88 
89 /* =======================================================================
90     Type Definitions
91    ======================================================================== */
92 
93 /* Please see man pages for details
94 
95 */
96 typedef ExpHeapImpl NNSiFndHeapHead;
97 typedef NNSiFndHeapHead* Heap;   // Type to represent heap handle
98 typedef NNSiFndHeapHead const * ConstHeap;
99 
100 
101 /*---------------------------------------------------------------------------*
102   Name:         MemGetHeapTotalSize
103 
104   Description:  Gets the memory size allocated to the heap (including that of the header).
105 
106 
107   Arguments:    heap    Heap handle
108 
109   Returns:      Returns the memory size allocated to the heap (including that of the header).
110 
111  *---------------------------------------------------------------------------*/
112 static inline s32
GetHeapTotalSize(ConstHeap heap)113 GetHeapTotalSize(ConstHeap heap)
114 {
115     return ((s32)(heap->heapEnd) - (s32)(heap->heapStart));
116 }
117 
118 /* ========================================================================
119     Macro Functions
120    ======================================================================== */
121 
122 /*---------------------------------------------------------------------------*
123   Name:         GetHeapStartAddress
124 
125   Description:  Gets start address of memory area used by heap
126 
127   Arguments:    heap:  Heap handle
128 
129   Returns:      Return start address of memory area used by heap
130  *---------------------------------------------------------------------------*/
131 #define             GetHeapStartAddress(heap) \
132                         ((void*)(((nn::fnd::detail::NNSiFndHeapHead*)(heap))->heapStart))
133 
134 /*---------------------------------------------------------------------------*
135   Name:         GetHeapEndAddress
136 
137   Description:  Gets end address +1 of memory region used by heap.
138 
139   Arguments:    heap:  Heap handle
140 
141   Returns:      Return end address +1 of memory area used by heap
142  *---------------------------------------------------------------------------*/
143 #define             GetHeapEndAddress(heap) \
144                         (((nn::fnd::detail::NNSiFndHeapHead*)(heap))->heapEnd)
145 
146 /* =======================================================================
147     Function Prototypes
148    ======================================================================== */
149 
150 Heap    FindContainHeap(
151                         const void* memBlock);
152 
153 #if defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK)
154     #define             DumpHeap(heap)				((void)0)
155 #else
156 	void                DumpHeap(
157 	                        Heap heap);
158 #endif
159 
160 #ifndef NN_BUILD_VERBOSE
161     #define             SetFillValForHeap(type, val) (0)
162 #else
163     u32                 SetFillValForHeap(
164                             int     type,
165                             u32     val);
166 #endif
167 
168 #ifndef NN_BUILD_VERBOSE
169     #define             GetFillValForHeap(type)      (0)
170 #else
171     u32                 GetFillValForHeap(
172                             int     type);
173 #endif
174 //
175 
176 /*
177 
178 */
179 /*
180 
181 */
182 
183 
184 }}} // namespace nn::os
185 
186 #endif // __cplusplus
187 
188 #endif /* NN_LIBRARIES_FND_DETAIL_FND_DETAIL_HEAP_COMMON_H_ */
189