1 /*---------------------------------------------------------------------------* 2 Project: MEM library 3 File: defaultHeap.h 4 5 Copyright (C) Nintendo. 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 14 #ifndef _MEM_DEFAULTHEAP_H_INCLUDED_ 15 #define _MEM_DEFAULTHEAP_H_INCLUDED_ 16 17 #include <cafe/os.h> 18 #include <cafe/mem/heapCommon.h> 19 20 #ifdef __cplusplus 21 extern "C" { 22 #endif 23 24 extern u8 * MEMUserHeapBase; 25 extern u32 MEMUserHeapSize; 26 27 typedef void * (*pfMEMAllocFromDefaultHeap)(u32 size); 28 typedef void * (*pfMEMAllocFromDefaultHeapEx)(u32 size, int alignment); 29 typedef void (*pfMEMFreeToDefaultHeap)(void* memBlock); 30 31 void CoreInitDefaultHeap(MEMHeapHandle *aMEM1_heap, MEMHeapHandle *aMEMFG_heap, MEMHeapHandle *aMEM2_heap); 32 // The default user heap initialization done in coreinit is CoreInitDefaultHeap. 33 // CoreInitDefaultHeap is used by the loader to allocate the data area memory 34 // space used by RPLs imported by the RPX. 35 // CoreInitDefaultHeap returns via the parameters the MEM_ARENA_1, MEM_ARENA_FG, and 36 // MEM_ARENA_2 heaps in that order and will return all 3 for a game. 37 38 void __preinit_user(MEMHeapHandle *aMEM1_heap, MEMHeapHandle *aMEMFG_heap, MEMHeapHandle *aMEM2_heap); 39 // The game's user heap initialization done in the RPX: 40 // If symbol __preinit_user is not present in the RPX, the initialization 41 // done in CoreInitDefaultHeap() continues to be used for the default (MEM2) heap. 42 // __preinit_user receives via the parameters the MEM_ARENA_1, MEM_ARENA_FG, and 43 // MEM_ARENA_2 heaps in that order. __preinit_user can change the handle of any or none 44 // of the heaps. The ones __preinit_user does not change will use the version defined 45 // by CoreInitDefaultHeap. 46 // __preinit_user can be used to set up diagnostics and anything else that is needed 47 // before rpl entrypoints and C++ static constructors are called. 48 49 void __post_except_user_init(void); 50 // __post_except_user_init() allows game developer's to execute code after C++ exceptions are initialized 51 // but before static constructors are executed in the startup code. 52 53 // The following variables are assigned in CoreInitDefaultHeap() 54 // and can be reassigned in an RPX in __preinit_user(). 55 extern pfMEMAllocFromDefaultHeap MEMAllocFromDefaultHeap; 56 extern pfMEMAllocFromDefaultHeapEx MEMAllocFromDefaultHeapEx; 57 extern pfMEMFreeToDefaultHeap MEMFreeToDefaultHeap; 58 59 MEMHeapHandle MEMCreateUserHeapHandle(void* startAddress, u32 size); 60 61 #ifdef __cplusplus 62 } /* extern "C" */ 63 #endif 64 65 #endif /* _MEM_DEFAULTHEAP_H_INCLUDED_ */ 66