diff --git a/Makefile b/Makefile index 74906505..607ef012 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,7 @@ ios := 249 CFLAGS = -g -O2 -Wall -Wextra -Wno-multichar $(MACHDEP) $(INCLUDE) -DHAVE_CONFIG_H CXXFLAGS = $(CFLAGS) -LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A00000,-wrap,malloc,-wrap,free,-wrap,memalign,-wrap,calloc,-wrap,realloc,-wrap,malloc_usable_size +LDFLAGS = -g $(MACHDEP) -Wl,-Map,$(notdir $@).map,--section-start,.init=0x80A00000,-wrap,malloc,-wrap,_malloc_r,-wrap,free,-wrap,_free_r,-wrap,memalign,-wrap,_memalign_r,-wrap,calloc,-wrap,_calloc_r,-wrap,realloc,-wrap,_realloc_r,-wrap,malloc_usable_size,-wrap,_malloc_usable_size_r #--------------------------------------------------------------------------------- # any extra libraries we wish to link with the project diff --git a/source/loader/apploader.c b/source/loader/apploader.c index 9b1b20c0..d0f8351c 100644 --- a/source/loader/apploader.c +++ b/source/loader/apploader.c @@ -59,7 +59,8 @@ s32 Apploader_Run(entry_point *entry, u8 vidMode, GXRModeObj *vmode, bool vipatc /* Calculate apploader length */ appldr_len = buffer[5] + buffer[6]; - SYS_SetArena1Hi((void *)0x816FFFF0); //Kills the possibility of codedumps with gprintf + /* Clear Apploader region (important buffers are under that) */ + memset((void*)0x81200000, 0, 0x500000); /* Read apploader code */ ret = WDVD_Read(appldr, appldr_len, APPLDR_OFFSET + 0x20); diff --git a/source/memory/mem2.cpp b/source/memory/mem2.cpp index 0d57bc41..443c2c18 100644 --- a/source/memory/mem2.cpp +++ b/source/memory/mem2.cpp @@ -23,6 +23,20 @@ extern __typeof(memalign) __real_memalign; extern __typeof(free) __real_free; extern __typeof(malloc_usable_size) __real_malloc_usable_size; +extern __typeof(_malloc_r) __real__malloc_r; +extern __typeof(_calloc_r) __real__calloc_r; +extern __typeof(_realloc_r) __real__realloc_r; +extern __typeof(_memalign_r) __real__memalign_r; +extern __typeof(_free_r) __real__free_r; +extern __typeof(_malloc_usable_size_r) __real__malloc_usable_size_r; + +bool first_mem = true; + +void DisableMEM1allocR() +{ + first_mem = false; +} + void *MEM1_alloc(unsigned int s) { return __real_malloc(s); @@ -111,6 +125,14 @@ void *__wrap_malloc(size_t size) return g_mem2gp.allocate(size); } +void *__wrap__malloc_r(struct _reent *r, size_t size) +{ + if(first_mem) + return __real__malloc_r(r, size); + + return MEM2_alloc(size); +} + void *__wrap_calloc(size_t n, size_t size) { void *p; @@ -134,6 +156,17 @@ void *__wrap_calloc(size_t n, size_t size) return p; } +void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size) +{ + if(first_mem) + return __real__calloc_r(r, n, size); + + void *p = MEM2_alloc(n*size); + if(p) + memset(p, 0, n*size); + return p; +} + void *__wrap_memalign(size_t a, size_t size) { void *p; @@ -154,6 +187,14 @@ void *__wrap_memalign(size_t a, size_t size) return g_mem2gp.allocate(size); } +void *__wrap__memalign_r(struct _reent *r, size_t a, size_t size) +{ + if(first_mem) + return __real__memalign_r(r, a, size); + + return MEM2_alloc(size); +} + void __wrap_free(void *p) { if(!p) @@ -165,6 +206,14 @@ void __wrap_free(void *p) __real_free(p); } +void __wrap__free_r(struct _reent *r, void *p) +{ + if(first_mem) + __real__free_r(r, p); + else + MEM2_free(p); +} + void *__wrap_realloc(void *p, size_t size) { void *n; @@ -199,6 +248,14 @@ void *__wrap_realloc(void *p, size_t size) return n; } +void *__wrap__realloc_r(struct _reent *r, void *p, size_t size) +{ + if(first_mem) + return __real__realloc_r(r, p, size); + + return MEM2_realloc(p, size); +} + size_t __wrap_malloc_usable_size(void *p) { if(((u32)p & 0x10000000) != 0) @@ -206,4 +263,12 @@ size_t __wrap_malloc_usable_size(void *p) return __real_malloc_usable_size(p); } +size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p) +{ + if(first_mem) + return __real__malloc_usable_size_r(r, p); + + return CMEM2Alloc::usableSize(p); +} + } ///extern "C" diff --git a/source/memory/mem2.hpp b/source/memory/mem2.hpp index af8c1cf0..cf44b5c0 100644 --- a/source/memory/mem2.hpp +++ b/source/memory/mem2.hpp @@ -26,6 +26,7 @@ void *MEM2_memalign(unsigned int /* alignment */, unsigned int s); void *MEM2_realloc(void *p, unsigned int s); unsigned int MEM2_usableSize(void *p); unsigned int MEM2_freesize(); +void DisableMEM1allocR(); #ifdef __cplusplus } diff --git a/source/menu/menu_game.cpp b/source/menu/menu_game.cpp index 258ebfca..1202e2d4 100644 --- a/source/menu/menu_game.cpp +++ b/source/menu/menu_game.cpp @@ -1420,6 +1420,7 @@ void CMenu::_launchGame(dir_discHdr *hdr, bool dvd) if(strncasecmp(id.c_str(), discid, 6) != 0) return; + DisableMEM1allocR(); RunApploader(offset, videoMode, vipatch, countryPatch, patchVidMode, aspectRatio, returnTo); gprintf("Booting game\n"); Disc_BootPartition(); @@ -1470,8 +1471,8 @@ void CMenu::_initGameMenu(CMenu::SThemeData &theme) m_gameBtnAdultOff = _addPicButton(theme, "GAME/ADULTONLY_OFF", texAdultOff, texAdultOffSel, 532, 200, 48, 48); m_gameBtnSettings = _addPicButton(theme, "GAME/SETTINGS_BTN", texSettings, texSettingsSel, 460, 272, 48, 48); m_gameBtnDelete = _addPicButton(theme, "GAME/DELETE_BTN", texDelete, texDeleteSel, 532, 272, 48, 48); - m_gameBtnPlayFull = _addButton(theme, "GAME/PLAY_FULL_BTN", theme.btnFont, L"", 100, 390, 200, 56, theme.btnFontColor); - m_gameBtnBackFull = _addButton(theme, "GAME/BACK_FULL_BTN", theme.btnFont, L"", 340, 390, 200, 56, theme.btnFontColor); + m_gameBtnBackFull = _addButton(theme, "GAME/BACK_FULL_BTN", theme.btnFont, L"", 100, 390, 200, 56, theme.btnFontColor); + m_gameBtnPlayFull = _addButton(theme, "GAME/PLAY_FULL_BTN", theme.btnFont, L"", 340, 390, 200, 56, theme.btnFontColor); m_gameBtnToogle = _addPicButton(theme, "GAME/TOOGLE_BTN", texToogleBanner, texToogleBanner, 385, 31, 236, 127); m_gameBtnToogleFull = _addPicButton(theme, "GAME/TOOGLE_FULL_BTN", texToogleBanner, texToogleBanner, 20, 12, 608, 344);