1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: fnd_DetailHeapCommon.h
4
5 Copyright (C)2009 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: 18703 $
14 *---------------------------------------------------------------------------*/
15
16 #ifndef NN_FND_DETAIL_FND_DETAIL_HEAPCOMMON_H_
17 #define NN_FND_DETAIL_FND_DETAIL_HEAPCOMMON_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 /*!
27 @addtogroup os os
28 @{
29 */
30 /*!
31 @defgroup os_Heap Heap
32 @{
33 */
34 /// @cond
35 /* ========================================================================
36 マクロ定数
37 ======================================================================== */
38
39 // 無効なヒープハンドル
40 #define NN_OS_HEAP_INVALID_HANDLE NULL
41
42 // ヒープからメモリを割り当てるときのデフォルトのアライメントサイズ
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 // 拡張ヒープのシグネチャ
48 #define NNSI_EXPHEAP_SIGNATURE NNSI_CREATE_HEAP_SIGNATURE('E','X','P','H')
49
50 // フレームヒープのシグネチャ
51 #define NNSI_FRMHEAP_SIGNATURE NNSI_CREATE_HEAP_SIGNATURE('F','R','M','H')
52
53 // ユニットヒープのシグネチャ
54 #define NNSI_UNTHEAP_SIGNATURE NNSI_CREATE_HEAP_SIGNATURE('U','N','T','H')
55
56
57 /* ------------------------------------------------------------------------
58 フィル関係
59 ------------------------------------------------------------------------ */
60
61 // メモリ確保時にメモリを0でクリア
62 #define NN_OS_HEAP_OPT_0_CLEAR (1 <<0)
63
64 // ヒープ作成時・メモリ確保・解放時にメモリ充填
65 #define NN_OS_HEAP_OPT_DEBUG_FILL (1 <<1)
66
67
68 /* ------------------------------------------------------------------------
69 ヒープチェック関係
70 ------------------------------------------------------------------------ */
71
72 // このビットが立っているとエラー出力
73 #define NN_OS_HEAP_ERROR_PRINT (1 <<0)
74
75
76 /* ========================================================================
77 enum定数
78 ======================================================================== */
79
80 enum {
81 NN_OS_HEAP_FILL_NOUSE, // デバッグフィル未使用時
82 NN_OS_HEAP_FILL_ALLOC, // デバッグフィル確保時
83 NN_OS_HEAP_FILL_FREE, // デバッグフィル解放時
84
85 NN_OS_HEAP_FILL_MAX
86 };
87
88
89 /* =======================================================================
90 型定義
91 ======================================================================== */
92
93 /*! @typedef Heap
94 @brief ヒープのハンドルを表す型
95 */
96 typedef ExpHeapImpl NNSiFndHeapHead;
97 typedef NNSiFndHeapHead* Heap; // ヒープのハンドルを表す型
98 typedef NNSiFndHeapHead const * ConstHeap;
99
100
101 /*---------------------------------------------------------------------------*
102 Name: MemGetHeapTotalSize
103
104 Description: ヒープに割り当てられているメモリサイズ(ヘッダ部分も含む全体のメモリサイズ)
105 を取得します。
106
107 Arguments: heap ヒープハンドル。
108
109 Returns: ヒープに割り当てられているメモリサイズ(ヘッダ部分も含む全体のメモリサイズ)
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 マクロ関数
120 ======================================================================== */
121
122 /*---------------------------------------------------------------------------*
123 Name: GetHeapStartAddress
124
125 Description: ヒープが利用するメモリ領域の開始アドレスを取得します。
126
127 Arguments: heap: ヒープハンドル。
128
129 Returns: ヒープが利用するメモリ領域の開始アドレスを返します。
130 *---------------------------------------------------------------------------*/
131 #define GetHeapStartAddress(heap) \
132 ((void*)(((nn::fnd::detail::NNSiFndHeapHead*)(heap))->heapStart))
133
134 /*---------------------------------------------------------------------------*
135 Name: GetHeapEndAddress
136
137 Description: ヒープが利用するメモリ領域の終了アドレス +1 を取得します。
138
139 Arguments: heap: ヒープハンドル。
140
141 Returns: ヒープが利用するメモリ領域の終了アドレス +1 を返します。
142 *---------------------------------------------------------------------------*/
143 #define GetHeapEndAddress(heap) \
144 (((nn::fnd::detail::NNSiFndHeapHead*)(heap))->heapEnd)
145
146 /* =======================================================================
147 関数プロトタイプ
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 /// @endcond
175
176 /*!
177 @}
178 */
179 /*!
180 @}
181 */
182
183
184 }}} // namespace nn::os
185
186 #endif // __cplusplus
187
188 /* NN_OS_HEAPCOMMON_H_ */
189 #endif /* NN_OS_OS_HEAPCOMMON_H_ */
190