2016-07-21 07:45:53 +02:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <coreinit/baseheap.h>
|
|
|
|
#include <coreinit/expandedheap.h>
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_memalign(size_t alignment, size_t size) {
|
|
|
|
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, alignment);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_malloc(size_t size) {
|
|
|
|
return __wrap_memalign(4, size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_free(void *ptr) {
|
|
|
|
if (ptr) {
|
|
|
|
MEMFreeToExpHeap(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), ptr);
|
2016-07-23 12:23:32 +02:00
|
|
|
}
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_realloc(void *ptr, size_t size) {
|
|
|
|
void *realloc_ptr = __wrap_malloc(size);
|
|
|
|
|
|
|
|
if(realloc_ptr) {
|
|
|
|
memcpy(realloc_ptr, ptr, size);
|
|
|
|
__wrap_free(ptr);
|
2016-07-23 12:23:32 +02:00
|
|
|
}
|
2016-07-24 02:57:04 +02:00
|
|
|
|
|
|
|
return realloc_ptr;
|
|
|
|
}
|
2016-07-23 12:23:32 +02:00
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
void *
|
|
|
|
__wrap_calloc(size_t num, size_t size) {
|
|
|
|
void *ptr = __wrap_malloc(num*size);
|
|
|
|
|
|
|
|
if(ptr) {
|
|
|
|
memset(ptr, 0, num*size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ptr;
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
size_t
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_malloc_usable_size(void *ptr) {
|
|
|
|
return MEMGetSizeForMBlockExpHeap(ptr);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap_valloc(size_t size) {
|
|
|
|
return __wrap_memalign(64, size);
|
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
|
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
void *
|
|
|
|
__wrap__memalign_r(struct _reent *r, size_t alignment, size_t size) {
|
|
|
|
return __wrap_memalign(alignment, size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap__malloc_r(struct _reent *r, size_t size) {
|
2016-07-23 12:23:32 +02:00
|
|
|
return __wrap_malloc(size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
void
|
|
|
|
__wrap__free_r(struct _reent *r, void *ptr) {
|
|
|
|
return __wrap_free(ptr);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-23 12:23:32 +02:00
|
|
|
void *
|
2016-07-24 02:57:04 +02:00
|
|
|
__wrap__realloc_r(struct _reent *r, void *ptr, size_t size) {
|
|
|
|
return __wrap_realloc(ptr, size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
void *
|
|
|
|
__wrap__calloc_r(struct _reent *r, size_t num, size_t size) {
|
|
|
|
return __wrap_calloc(num, size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
size_t
|
|
|
|
__wrap__malloc_usable_size_r(struct _reent *r, void *ptr) {
|
|
|
|
return __wrap_malloc_usable_size(ptr);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|
|
|
|
|
2016-07-24 02:57:04 +02:00
|
|
|
void *
|
|
|
|
__wrap__valloc_r(struct _reent *r, size_t size) {
|
|
|
|
return __wrap_valloc(size);
|
2016-07-21 07:45:53 +02:00
|
|
|
}
|