void MEM1_free(void *p) { if((u32)p < (u32)&__init_start - 0x100 && (u32)p >= 0x80004000) g_mem1Lgp.release(p); else if((u32)p > (u32)APPLOADER_START && (u32)p < (u32)APPLOADER_END) g_mem1Ugp.release(p); }
void *__wrap_realloc(void *p, size_t size) { void *n; // ptr from mem2 if(((u32)p & 0x10000000) != 0 || (p == 0 && size > MEM2_PRIORITY_SIZE)) { n = g_mem2gp.reallocate(p, size); if(n != 0) return n; n = __real_malloc(size); if(n == 0) return 0; if(p != 0) { memcpy(n, p, MEM2_usableSize(p) < size ? MEM2_usableSize(p) : size); g_mem2gp.release(p); } return n; } // ptr from malloc n = __real_realloc(p, size); if(n != 0) return n; n = g_mem2gp.allocate(size); if(n == 0) return 0; if(p != 0) { memcpy(n, p, __real_malloc_usable_size(p) < size ? __real_malloc_usable_size(p) : size); __real_free(p); } return n; }
void MEM2_init(unsigned int mem2Size, unsigned int coverSize) { g_mem2gp.init(mem2Size); g_mem2covers.init(coverSize); g_mem1locovers.init(&__cdat_end + 0x100, &__init_start - 0x100); g_mem1hicovers.init((void *)0x81200000, (void *)0x816FFFF0); memset(g_mem2obj, 0, sizeof g_mem2obj); }
void *MEM1_realloc(void *p, unsigned int s) { if((u32)p < (u32)&__init_start - 0x100 && (u32)p >= 0x80004000) return g_mem1Lgp.reallocate(p, s); else if((u32)p > (u32)APPLOADER_START && (u32)p < (u32)APPLOADER_END) return g_mem1Ugp.reallocate(p, s); return NULL; }
void *MEM1_alloc(unsigned int s) { if(g_mem1Lgp.FreeSize() >= s) return g_mem1Lgp.allocate(s); if(g_mem1Ugp.FreeSize() >= s) return g_mem1Ugp.allocate(s); return NULL; }
void MEM2_cleanup(void) { for (int n = 0; n < 8; ++n) for (int i = 0; i < NUM_OBJALLOC && g_mem2obj[n][i] != 0; ++i) g_mem2obj[n][i]->cleanup(); g_mem1hicovers.cleanup(); g_mem1locovers.cleanup(); g_mem2covers.cleanup(); g_mem2gp.cleanup(); memset(g_mem2obj, 0, sizeof g_mem2obj); }
void *__wrap_malloc(size_t size) { void *p; if(size >= MEM2_PRIORITY_SIZE) { p = g_mem2gp.allocate(size); if(p != 0) return p; return __real_malloc(size); } p = __real_malloc(size); if(p != 0) return p; return g_mem2gp.allocate(size); }
void *__wrap_malloc(size_t size) { void *p; if ((SYS_GetArena1Lo() > MAX_MEM1_ARENA_LO) || (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)) { p = g_mem2gp.allocate(size); if (p != 0) { return p; } return __real_malloc(size); } p = __real_malloc(size); if (p != 0) { return p; } return g_mem2gp.allocate(size); }
void *__wrap_memalign(size_t a, size_t size) { void *p; if(size >= MEM2_PRIORITY_SIZE) { if(a <= 32 && 32 % a == 0) { p = g_mem2gp.allocate(size); if (p != 0) return p; } return __real_memalign(a, size); } p = __real_memalign(a, size); if(p != 0 || a > 32 || 32 % a != 0) return p; return g_mem2gp.allocate(size); }
void __wrap_free(void *p) { if(!p) return; if(((u32)p & 0x10000000) != 0) g_mem2gp.release(p); else __real_free(p); }
void *__wrap_memalign(size_t a, size_t size) { void *p; if ((SYS_GetArena1Lo() > MAX_MEM1_ARENA_LO) || (g_bigGoesToMem2 && size > MEM2_PRIORITY_SIZE)) { if (a <= 32 && 32 % a == 0) { p = g_mem2gp.allocate(size); if (p != 0) { return p; } } return __real_memalign(a, size); } p = __real_memalign(a, size); if (p != 0 || a > 32 || 32 % a != 0) { return p; } return g_mem2gp.allocate(size); }
void *__wrap_calloc(size_t n, size_t size) { void *p; if((n * size) >= MEM2_PRIORITY_SIZE) { p = g_mem2gp.allocate(n * size); if (p != 0) { memset(p, 0, n * size); return p; } return __real_calloc(n, size); } p = __real_calloc(n, size); if (p != 0) return p; p = g_mem2gp.allocate(n * size); if (p != 0) memset(p, 0, n * size); return p; }
void MEM2_init(unsigned int mem2Size) { if(&_end + 0x100 > APPLOADER_START) gprintf("ZOMG MOVE THE ENTRYPOINT DOWN!"); g_mem2gp.init(mem2Size); g_mem2gp.clear(); /* If these are used, they must be cleared before running the apploader */ /* Below executable */ g_mem1Lgp.init((void *)0x80004000, &__init_start - 0x100); g_mem1Lgp.clear(); /* Above Executable */ g_mem1Ugp.init(APPLOADER_START, APPLOADER_END); g_mem1Ugp.clear(); /* Protect space reserved for apploader */ SYS_SetArena1Hi(APPLOADER_START); }
unsigned int MEM2_freesize() { return g_mem2gp.FreeSize(); }
unsigned int MEM2_usableSize(void *p) { return g_mem2gp.usableSize(p); }
void *MEM2_realloc(void *p, unsigned int s) { return g_mem2gp.reallocate(p, s); }
void *MEM2_alloc(unsigned int s) { return g_mem2gp.allocate(s); }
void MEM2_free(void *p) { if(!p) return; g_mem2gp.release(p); }
void MEM2_clear(void) { g_mem2gp.clear(); }
void MEM1_cleanup(void) { g_mem1Lgp.cleanup(); g_mem1Ugp.cleanup(); }
void MEM_init() { g_mem2gp.init(MEM2_start, MEM2_end); //about 47mb g_mem2gp.clear(); }
void MEM2_init(unsigned int mem2Size) { g_mem2gp.init(mem2Size); }
unsigned int MEM1_freesize() { return g_mem1Lgp.FreeSize() + g_mem1Ugp.FreeSize(); }
void MEM2_free(void *p) { g_mem2gp.release(p); }
void MEM2_cleanup(void) { g_mem2gp.cleanup(); }
void MEM1_clear(void) { g_mem1Lgp.clear(); g_mem1Ugp.clear(); }