Implement __wrap_malloc_usable_size.

This is just MEMGetSizeForMBlockExpHeap.
This commit is contained in:
James Benton 2016-07-23 11:23:32 +01:00
parent d02bdf6e35
commit fc3bfa64ed
2 changed files with 50 additions and 44 deletions

View File

@ -8,7 +8,7 @@ _start:
.global __wrap___eabi
__wrap___eabi:
blr
.global __init
__init:
blr

View File

@ -14,90 +14,96 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
****************************************************************************/
#include <malloc.h>
#include <string.h>
#include <coreinit/baseheap.h>
#include <coreinit/expandedheap.h>
//!-------------------------------------------------------------------------------------------
//! wraps
//!-------------------------------------------------------------------------------------------
void *__wrap_malloc(size_t size)
void *
__wrap_malloc(size_t size)
{
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, 4);
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, 4);
}
void *__wrap_memalign(size_t align, size_t size)
void *
__wrap_memalign(size_t align, size_t size)
{
if (align < 4)
align = 4;
if (align < 4) {
align = 4;
}
// pointer to a function resolve
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, align);
return MEMAllocFromExpHeapEx(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), size, align);
}
void __wrap_free(void *p)
void
__wrap_free(void *p)
{
// pointer to a function resolve
if(p != 0)
MEMFreeToExpHeap(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), p);
if (p) {
MEMFreeToExpHeap(MEMGetBaseHeapHandle(MEM_BASE_HEAP_MEM2), p);
}
}
void *__wrap_calloc(size_t n, size_t size)
void *
__wrap_calloc(size_t n, size_t size)
{
void *p = __wrap_malloc(n * size);
if (p != 0) {
memset(p, 0, n * size);
}
return p;
void *p = __wrap_malloc(n * size);
if (p) {
memset(p, 0, n * size);
}
return p;
}
size_t __wrap_malloc_usable_size(void *p)
size_t
__wrap_malloc_usable_size(void *p)
{
//! TODO: this is totally wrong and needs to be addressed
return 0x7FFFFFFF;
return MEMGetSizeForMBlockExpHeap(p);
}
void *__wrap_realloc(void *p, size_t size)
void *
__wrap_realloc(void *p, size_t size)
{
void *new_ptr = __wrap_malloc(size);
if (new_ptr != 0)
{
memcpy(new_ptr, p, __wrap_malloc_usable_size(p) < size ? __wrap_malloc_usable_size(p) : size);
__wrap_free(p);
}
return new_ptr;
void *new_ptr = __wrap_malloc(size);
if (new_ptr) {
memcpy(new_ptr, p, __wrap_malloc_usable_size(p) < size ? __wrap_malloc_usable_size(p) : size);
__wrap_free(p);
}
return new_ptr;
}
//!-------------------------------------------------------------------------------------------
//! reent versions
//!-------------------------------------------------------------------------------------------
void *__wrap__malloc_r(struct _reent *r, size_t size)
void *
__wrap__malloc_r(struct _reent *r, size_t size)
{
return __wrap_malloc(size);
return __wrap_malloc(size);
}
void *__wrap__calloc_r(struct _reent *r, size_t n, size_t size)
void *
__wrap__calloc_r(struct _reent *r, size_t n, size_t size)
{
return __wrap_calloc(n, size);
return __wrap_calloc(n, size);
}
void *__wrap__memalign_r(struct _reent *r, size_t align, size_t size)
void *
__wrap__memalign_r(struct _reent *r, size_t align, size_t size)
{
return __wrap_memalign(align, size);
return __wrap_memalign(align, size);
}
void __wrap__free_r(struct _reent *r, void *p)
{
__wrap_free(p);
__wrap_free(p);
}
size_t __wrap__malloc_usable_size_r(struct _reent *r, void *p)
{
return __wrap_malloc_usable_size(p);
return __wrap_malloc_usable_size(p);
}
void *__wrap__realloc_r(struct _reent *r, void *p, size_t size)
{
return __wrap_realloc(p, size);
return __wrap_realloc(p, size);
}