diff --git a/portlibs/lib/libcustomext2fs.a b/portlibs/lib/libcustomext2fs.a index 55b70839..2adf2cca 100644 Binary files a/portlibs/lib/libcustomext2fs.a and b/portlibs/lib/libcustomext2fs.a differ diff --git a/portlibs/lib/libcustomfat.a b/portlibs/lib/libcustomfat.a index bad77510..c5f07d9d 100644 Binary files a/portlibs/lib/libcustomfat.a and b/portlibs/lib/libcustomfat.a differ diff --git a/portlibs/lib/libcustomntfs.a b/portlibs/lib/libcustomntfs.a index 4b418887..93046cea 100644 Binary files a/portlibs/lib/libcustomntfs.a and b/portlibs/lib/libcustomntfs.a differ diff --git a/source/devicemounter/sdhc.c b/source/devicemounter/sdhc.c index a8d7468a..adbc5da9 100644 --- a/source/devicemounter/sdhc.c +++ b/source/devicemounter/sdhc.c @@ -3,7 +3,7 @@ #include #include #include - +#include "memory/mem2.hpp" #include "sdhc.h" /* IOCTL comamnds */ @@ -25,8 +25,6 @@ static s32 hid = -1, fd = -1; static u32 sector_size = SDHC_SECTOR_SIZE; static void *sdhc_buf2; -extern void* SYS_AllocArena2MemLo(u32 size,u32 align); - bool SDHC_Init(void) { s32 ret; @@ -49,7 +47,7 @@ bool SDHC_Init(void) // allocate buf2 if (sdhc_buf2 == NULL) { - sdhc_buf2 = SYS_AllocArena2MemLo(SDHC_MEM2_SIZE, 32); + sdhc_buf2 = MEM2_lo_alloc(SDHC_MEM2_SIZE); if (sdhc_buf2 == NULL) goto err; } diff --git a/source/devicemounter/usbstorage.c b/source/devicemounter/usbstorage.c index f96fd77c..299147a9 100644 --- a/source/devicemounter/usbstorage.c +++ b/source/devicemounter/usbstorage.c @@ -31,7 +31,7 @@ #include #include #include - +#include "memory/mem2.hpp" #include "usbstorage.h" #include "usbstorage_libogc.h" #include "usbthread.h" @@ -69,8 +69,6 @@ u32 hdd_sector_size[2] = { 512, 512 }; bool first = false; int usb_libogc_mode = 0; -extern void* SYS_AllocArena2MemLo(u32 size,u32 align); - inline s32 __USBStorage_isMEM2Buffer(const void *buffer) { u32 high_addr = ((u32)buffer) >> 24; @@ -81,7 +79,7 @@ s32 USBStorage2_Init(u32 port) { /* allocate buf2 */ if(mem2_ptr == NULL) - mem2_ptr = SYS_AllocArena2MemLo(USB_MEM2_SIZE, 32); + mem2_ptr = MEM2_lo_alloc(USB_MEM2_SIZE); if(usb_libogc_mode) { diff --git a/source/devicemounter/usbstorage_libogc.c b/source/devicemounter/usbstorage_libogc.c index fa53c2de..023cc3b8 100644 --- a/source/devicemounter/usbstorage_libogc.c +++ b/source/devicemounter/usbstorage_libogc.c @@ -38,7 +38,7 @@ distribution. #include #include #include - +#include "memory/mem2.hpp" #include #include #include @@ -208,12 +208,7 @@ s32 USBStorage_OGC_Initialize() _CPU_ISR_Disable(level); LWP_InitQueue(&__usbstorage_ogc_waitq); if(!arena_ptr) { - arena_ptr = (u8*)ROUNDDOWN32(((u32)SYS_GetArena2Hi() - HEAP_SIZE)); - if((u32)arena_ptr < (u32)SYS_GetArena2Lo()) { - _CPU_ISR_Restore(level); - return IPC_ENOMEM; - } - SYS_SetArena2Hi(arena_ptr); + arena_ptr = (u8*)MEM2_lo_alloc(HEAP_SIZE); } __lwp_heap_init(&__heap, arena_ptr, HEAP_SIZE, 32); cbw_buffer=(u8*)__lwp_heap_allocate(&__heap, 32); diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index a76fb0fe..f9485d87 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -16,10 +16,14 @@ u32 MALLOC_MEM2 = 0; void *MEM1_lo_start = (void*)0x80004000; void *MEM1_lo_end = (void*)0x80620000; -void *MEM2_start = (void*)0x90200000; -void *MEM2_end = (void*)0x93100000; +void *MEM2_lo_start = (void*)0x90000000; +void *MEM2_lo_end = (void*)0x90600000; + +void *MEM2_start = (void*)0x90600000; +void *MEM2_end = (void*)0x93200000; static CMEM2Alloc g_mem1lo; +static CMEM2Alloc g_mem2lo_gp; static CMEM2Alloc g_mem2gp; extern "C" @@ -37,7 +41,10 @@ void MEM_init() g_mem1lo.init(MEM1_lo_start, MEM1_lo_end); //about 6mb g_mem1lo.clear(); - g_mem2gp.init(MEM2_start, MEM2_end); //about 47mb + g_mem2lo_gp.init(MEM2_lo_start, MEM2_lo_end); //about 6mb + g_mem2lo_gp.clear(); + + g_mem2gp.init(MEM2_start, MEM2_end); //about 44mb g_mem2gp.clear(); } @@ -80,16 +87,25 @@ unsigned int MEM1_freesize() return (g_mem1lo.FreeSize() + SYS_GetArena1Size()); } -void MEM2_cleanup(void) + +void *MEM2_lo_alloc(unsigned int s) { - g_mem2gp.cleanup(); + return g_mem2lo_gp.allocate(s); } -void MEM2_clear(void) +void *MEM2_lo_realloc(void *p, unsigned int s) { - g_mem2gp.clear(); + return g_mem2lo_gp.reallocate(p, s); } +void MEM2_lo_free(void *p) +{ + if(!p) + return; + g_mem2lo_gp.release(p); +} + + void MEM2_free(void *p) { if(!p) @@ -188,7 +204,12 @@ void __wrap_free(void *p) return; if(((u32)p & 0x10000000) != 0) - g_mem2gp.release(p); + { + if(p > MEM2_start) + g_mem2gp.release(p); + else + g_mem2lo_gp.release(p); + } else MEM1_free(p); } diff --git a/source/memory/mem2.hpp b/source/memory/mem2.hpp index 6713112a..acb655bd 100644 --- a/source/memory/mem2.hpp +++ b/source/memory/mem2.hpp @@ -20,8 +20,10 @@ void *MEM1_realloc(void *p, unsigned int s); void MEM1_free(void *p); unsigned int MEM1_freesize(); -void MEM2_cleanup(void); -void MEM2_clear(void); +void *MEM2_lo_alloc(unsigned int s); +void *MEM2_lo_realloc(void *p, unsigned int s); +void MEM2_lo_free(void *p); + void MEM2_free(void *p); void *MEM2_alloc(unsigned int s); void *MEM2_memalign(unsigned int /* alignment */, unsigned int s); diff --git a/source/memory/mem2alloc.cpp b/source/memory/mem2alloc.cpp index 8c64886a..6327ea77 100644 --- a/source/memory/mem2alloc.cpp +++ b/source/memory/mem2alloc.cpp @@ -4,21 +4,8 @@ #include #include #include - -#define IOS_RELOAD_AREA 0x90200000 - #include "lockMutex.hpp" -void CMEM2Alloc::init(unsigned int size) -{ - m_baseAddress = (SBlock *)std::max(((u32)SYS_GetArena2Lo() + 31) & ~31, IOS_RELOAD_AREA); - m_endAddress = (SBlock *)((u8*)m_baseAddress + std::min(size * 0x100000, SYS_GetArena2Size() & ~31)); - if (m_endAddress > (SBlock *)0x93100000) //rest is reserved for usb/usb2/network and other stuff... (0xE0000 bytes) - m_endAddress = (SBlock *)0x93100000; - SYS_SetArena2Lo(m_endAddress); - LWP_MutexInit(&m_mutex, 0); -} - void CMEM2Alloc::init(void *addr, void *end) { m_baseAddress = (SBlock *)(((u32)addr + 31) & ~31); @@ -32,8 +19,8 @@ void CMEM2Alloc::cleanup(void) m_mutex = 0; m_first = 0; // Try to release the range we took through SYS functions - if (SYS_GetArena2Lo() == m_endAddress) - SYS_SetArena2Lo(m_baseAddress); + /*if (SYS_GetArena2Lo() == m_endAddress) + SYS_SetArena2Lo(m_baseAddress);*/ m_baseAddress = 0; m_endAddress = 0; } diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 543c294b..e6004bad 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -961,7 +961,6 @@ void CMenu::_launchHomebrew(const char *filepath, vector arguments) Playlog_Delete(); cleanup(); // wifi and sd gecko doesnt work anymore after cleanup - loadIOS(58, true); LoadHomebrew(filepath); AddBootArgument(filepath); @@ -970,6 +969,7 @@ void CMenu::_launchHomebrew(const char *filepath, vector arguments) gprintf("Argument: %s\n", arguments[i].c_str()); AddBootArgument(arguments[i].c_str()); } + loadIOS(58, false); ShutdownBeforeExit(); BootHomebrew(); }