mirror of
https://github.com/wiiu-env/PayloadLoaderPayload.git
synced 2024-09-27 16:48:41 +02:00
"fix" a memory leak.
This commit is contained in:
parent
61f5ff067c
commit
9d0e08781d
30
src/main.cpp
30
src/main.cpp
@ -15,9 +15,11 @@
|
|||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
|
#include <malloc.h>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <coreinit/dynload.h>
|
#include <coreinit/dynload.h>
|
||||||
#include <coreinit/screen.h>
|
#include <coreinit/screen.h>
|
||||||
|
#include <coreinit/memexpheap.h>
|
||||||
|
|
||||||
#include "utils/ElfUtils.h"
|
#include "utils/ElfUtils.h"
|
||||||
#include "utils/logger.h"
|
#include "utils/logger.h"
|
||||||
@ -41,11 +43,14 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
|
|||||||
|
|
||||||
extern "C" void __init_wut();
|
extern "C" void __init_wut();
|
||||||
extern "C" void __fini_wut();
|
extern "C" void __fini_wut();
|
||||||
|
uint32_t memory_start = 0;
|
||||||
|
|
||||||
extern "C" uint32_t start_wrapper(int argc, char **argv) {
|
extern "C" uint32_t start_wrapper(int argc, char **argv) {
|
||||||
doKernelSetup();
|
doKernelSetup();
|
||||||
InitFunctionPointers();
|
InitFunctionPointers();
|
||||||
|
|
||||||
|
memory_start = (uint32_t) malloc(1024);
|
||||||
|
|
||||||
__init_wut();
|
__init_wut();
|
||||||
|
|
||||||
WHBLogUdpInit();
|
WHBLogUdpInit();
|
||||||
@ -86,6 +91,20 @@ extern "C" uint32_t start_wrapper(int argc, char **argv) {
|
|||||||
}
|
}
|
||||||
extern "C" int _start(int argc, char **argv) {
|
extern "C" int _start(int argc, char **argv) {
|
||||||
uint32_t entryPoint = start_wrapper(argc, argv);
|
uint32_t entryPoint = start_wrapper(argc, argv);
|
||||||
|
|
||||||
|
// Somewhere in this loader is a memory leak.
|
||||||
|
// This is a hacky solution to free that memory.
|
||||||
|
uint32_t head_end = (uint32_t) malloc(1024);
|
||||||
|
MEMExpHeapBlock *curUsedBlock = (MEMExpHeapBlock *) (head_end - 0x14);
|
||||||
|
while (curUsedBlock != 0) {
|
||||||
|
curUsedBlock = curUsedBlock->prev;
|
||||||
|
free(&curUsedBlock[1]);
|
||||||
|
|
||||||
|
if(((uint32_t) &curUsedBlock[1]) == memory_start){
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int res = -1;
|
int res = -1;
|
||||||
if (entryPoint != 0) {
|
if (entryPoint != 0) {
|
||||||
res = ((int (*)(int, char **)) entryPoint)(argc, argv);
|
res = ((int (*)(int, char **)) entryPoint)(argc, argv);
|
||||||
@ -171,13 +190,13 @@ std::vector<std::string> readDirFull(const char *base_path, const char *path, FS
|
|||||||
|
|
||||||
|
|
||||||
std::string PayloadSelectionScreen(const std::map<std::string, std::string> &payloads) {
|
std::string PayloadSelectionScreen(const std::map<std::string, std::string> &payloads) {
|
||||||
int32_t screen_buf0_size = 0;
|
|
||||||
|
|
||||||
// Init screen and screen buffers
|
// Init screen and screen buffers
|
||||||
OSScreenInit();
|
OSScreenInit();
|
||||||
screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
uint32_t screen_buf0_size = OSScreenGetBufferSizeEx(SCREEN_TV);
|
||||||
OSScreenSetBufferEx(SCREEN_TV, (void *) 0xF4000000);
|
uint32_t screen_buf1_size = OSScreenGetBufferSizeEx(SCREEN_DRC);
|
||||||
OSScreenSetBufferEx(SCREEN_DRC, (void *) (0xF4000000 + screen_buf0_size));
|
uint8_t * screenBuffer = (uint8_t*) memalign(0x100, screen_buf0_size + screen_buf1_size);
|
||||||
|
OSScreenSetBufferEx(SCREEN_TV, (void *)screenBuffer);
|
||||||
|
OSScreenSetBufferEx(SCREEN_DRC, (void *)(screenBuffer + screen_buf0_size));
|
||||||
|
|
||||||
OSScreenEnableEx(SCREEN_TV, 1);
|
OSScreenEnableEx(SCREEN_TV, 1);
|
||||||
OSScreenEnableEx(SCREEN_DRC, 1);
|
OSScreenEnableEx(SCREEN_DRC, 1);
|
||||||
@ -244,5 +263,6 @@ std::string PayloadSelectionScreen(const std::map<std::string, std::string> &pay
|
|||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
free(screenBuffer);
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user