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 *__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_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 *__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_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_alloc(unsigned int s) { return g_mem2gp.allocate(s); }