1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: fnd_DetailHeap.h
4 Copyright (C)2009 Nintendo Co., Ltd. All rights reserved.
5 These coded instructions, statements, and computer programs contain
6 proprietary information of Nintendo of America Inc. and/or Nintendo
7 Company Ltd., and are protected by Federal copyright law. They may
8 not be disclosed to third parties or copied or duplicated in any form,
9 in whole or in part, without the prior written consent of Nintendo.
10 $Rev: 13429 $
11 *---------------------------------------------------------------------------
12
13
14 */
15
16 /* Please see man pages for details
17
18
19 */
20
21 #ifndef NN_FND_DETAIL_FND_DETAIL_HEAP_H_
22 #define NN_FND_DETAIL_FND_DETAIL_HEAP_H_
23
24 #include <nn/fnd/detail/fnd_DetailHeapHead.h>
25 #include <nn/fnd/fnd_HeapBase.h>
26 #include <nn/fnd/fnd_MemoryRange.h>
27 #include "fnd_DetailHeapCommon.h"
28
29 #define NN_OS_EXPHEAP_ALLOC_DIR_FRONT 0 // Allocate from front
30 #define NN_OS_EXPHEAP_ALLOC_DIR_REAR 1 // Allocate from back
31 #define NN_OS_EXPHEAP_ALLOC_MODE_FIRST 0
32 #define NN_OS_EXPHEAP_ALLOC_MODE_NEAR 1
33
34 #ifdef __cplusplus
35
36 namespace nn{ namespace fnd{ namespace detail {
37 /* Please see man pages for details
38
39
40 */
41 /* Please see man pages for details
42
43
44
45
46
47 */
48 /* =======================================================================
49 Constant definitions
50 ======================================================================== */
51
52 // Memory allocation direction
53 //Enums
54 //{
55 // NN_OS_EXPHEAP_ALLOC_DIR_FRONT, // Allocates from the front
56 // NN_OS_EXPHEAP_ALLOC_DIR_REAR // Allocates from the back
57 //};
58
59 // Memory allocation mode
60 //Enums
61 //{
62 /*
63 If this attribute value is set, memory larger than the size of the memory to allocate is maintained, and memory from the first empty region found is allocated.
64
65
66 */
67 // NN_OS_EXPHEAP_ALLOC_MODE_FIRST,
68
69 /*
70 If this attribute value is set, search for the empty region closest to the size of the memory to allocate, and allocate from that region.
71
72
73 */
74 // NN_OS_EXPHEAP_ALLOC_MODE_NEAR
75 //};
76
77
78 /* =======================================================================
79 Type Definitions
80 ======================================================================== */
81
82 // Callback function type called for each memory
83 typedef void (*NNSFndHeapVisitor)(
84 void* memBlock,
85 Heap heap,
86 u32 userParam);
87
88 /* =======================================================================
89 Macro Functions
90 ======================================================================== */
91
92
93
94 /* =======================================================================
95 Function Prototypes
96 ======================================================================== */
97 #if ! defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK)
98 //
99
100 void NNSi_FndDumpHeap(
101 ConstHeap heap);
102
103 //
104 #endif
105
106 /* Please see man pages for details
107
108
109
110
111
112
113
114
115
116 */
117 Heap CreateHeap(
118 Heap heapHandle,
119 void* startAddress,
120 u32 size,
121 u16 optFlag = 0);
122
123
124 /* Please see man pages for details
125
126
127
128
129
130 */
131 void DestroyHeap(
132 Heap heap);
133
134
135 /* Please see man pages for details
136
137
138
139
140
141 */
142 void SetCurrentHeap(Heap heap);
143
144
145 /* Please see man pages for details
146
147
148
149
150 */
151 Heap GetCurrentHeap(void);
152
153
154 /* Please see man pages for details
155
156
157
158
159
160
161
162
163
164
165
166
167 */
168 void* AllocFromHeap(
169 Heap heap,
170 u32 size,
171 int alignment = NN_OS_HEAP_DEFAULT_ALIGNMENT);
172
173
174 /* Please see man pages for details
175
176
177
178
179
180
181
182
183
184
185 */
186 inline void* AllocFromCurrentHeap(u32 size, int alignment = NN_OS_HEAP_DEFAULT_ALIGNMENT)
187 {
188 return AllocFromHeap(GetCurrentHeap(), size, alignment);
189 }
190
191 /* Please see man pages for details
192
193
194
195
196
197
198 */
199 void FreeToHeap(
200 Heap heap,
201 void* memBlock);
202
203
204 /* Please see man pages for details
205
206
207
208
209
210 */
FreeToCurrentHeap(void * memBlock)211 inline void FreeToCurrentHeap(void* memBlock)
212 {
213 FreeToHeap(GetCurrentHeap(), memBlock);
214 }
215
216 /* Please see man pages for details
217
218
219
220
221
222
223
224
225 */
226 u32 ResizeForMBlockHeap(
227 Heap heap,
228 void* memBlock,
229 u32 size);
230
231 /* Please see man pages for details
232
233
234
235
236
237 */
238 u32 GetTotalFreeSizeForHeap(
239 ConstHeap heap);
240
241
242 /* Please see man pages for details
243
244
245
246
247
248
249
250
251 */
252 u32 GetAllocatableSizeForHeap(
253 ConstHeap heap,
254 int alignment = NN_OS_HEAP_DEFAULT_ALIGNMENT);
255
256
257 /* Please see man pages for details
258
259
260
261
262
263
264 */
265 u16 SetAllocModeForHeap(
266 Heap heap,
267 u16 mode);
268
269 /* Please see man pages for details
270
271
272
273
274
275 */
276 u16 GetAllocModeForHeap(
277 Heap heap);
278
279 /* Please see man pages for details
280
281
282
283
284
285
286 */
287 u16 SetGroupIDForHeap(
288 Heap heap,
289 u16 groupID);
290
291 /* Please see man pages for details
292
293
294
295
296
297 */
298 u16 GetGroupIDForHeap(
299 Heap heap);
300
301 /* Please see man pages for details
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322 */
323 void VisitAllocatedForHeap(
324 Heap heap,
325 NNSFndHeapVisitor visitor,
326 u32 userParam);
327
328 /* Please see man pages for details
329
330
331
332
333
334 */
335 u32 GetSizeForMBlockHeap(
336 const void* memBlock);
337
338 /* Please see man pages for details
339
340
341
342
343
344 */
345 u16 GetGroupIDForMBlockHeap(
346 const void* memBlock);
347
348 /* Please see man pages for details
349
350
351
352
353
354 */
355 u16 GetAllocDirForMBlockHeap(
356 const void* memBlock);
357
358 /* Please see man pages for details
359
360
361
362
363
364
365 */
366 MemoryRange AdjustHeap(
367 Heap heap,
368 HeapAdjustMode mode);
369
370 /* Please see man pages for details
371
372
373
374
375
376
377
378 */
379 bool UseMarginOfAlignmentForHeap(
380 Heap heap,
381 bool reuse);
382
383
384 #if defined(NN_SWITCH_DISABLE_DEBUG_PRINT_FOR_SDK)
CheckHeap(ConstHeap,u32)385 inline bool CheckHeap(ConstHeap, u32) { return true; }
CheckForMBlockHeap(const void *,ConstHeap,u32)386 inline bool CheckForMBlockHeap(const void*, ConstHeap, u32) { return true; }
387 #else
388
389 /* Please see man pages for details
390
391
392
393
394
395
396
397 */
398 bool CheckHeap(
399 ConstHeap heap,
400 u32 optFlag);
401 /* Please see man pages for details
402
403
404
405
406
407
408
409
410 */
411 bool CheckForMBlockHeap(
412 const void* memBlock,
413 ConstHeap heap,
414 u32 optFlag);
415
416 #endif
417
418
419
420 /*
421
422 */
423 /*
424
425 */
426
427
428 }}} // namespace nn::fnd::detail
429
430 #endif // __cplusplus
431
432 /* NN_OS_HEAP_H_ */
433 #endif
434
435