Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace the CafeOS default heap with a custom one (#221)
- Loading branch information
1 parent
c86b7cf
commit f1b5da9
Showing
10 changed files
with
90 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include <coreinit/memdefaultheap.h> | ||
|
||
void __init_wut_sbrk_heap(MEMHeapHandle heapHandle); | ||
void __init_wut_malloc_lock(); | ||
void __init_wut_defaultheap(); | ||
|
||
void __attribute__((weak)) | ||
__preinit_user(MEMHeapHandle *mem1, | ||
MEMHeapHandle *foreground, | ||
MEMHeapHandle *mem2) | ||
{ | ||
__init_wut_sbrk_heap(*mem2); | ||
__init_wut_malloc_lock(); | ||
__init_wut_defaultheap(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#include <coreinit/memdefaultheap.h> | ||
#include <malloc.h> | ||
|
||
void * | ||
__wut_alloc_from_defaultheap(uint32_t size) | ||
{ | ||
return malloc(size); | ||
} | ||
|
||
void * | ||
__wut_alloc_from_defaultheap_ex(uint32_t size, | ||
int32_t alignment) | ||
{ | ||
return memalign(alignment, size); | ||
} | ||
|
||
void | ||
__wut_free_to_defaultheap(void *ptr) | ||
{ | ||
free(ptr); | ||
} | ||
|
||
void | ||
__init_wut_defaultheap(void) | ||
{ | ||
MEMAllocFromDefaultHeap = __wut_alloc_from_defaultheap; | ||
MEMAllocFromDefaultHeapEx = __wut_alloc_from_defaultheap_ex; | ||
MEMFreeToDefaultHeap = __wut_free_to_defaultheap; | ||
} | ||
|
||
void | ||
__fini_wut_defaultheap(void) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,23 @@ | ||
#include "wut_newlib.h" | ||
|
||
#include <coreinit/mutex.h> | ||
#include <coreinit/spinlock.h> | ||
|
||
static OSMutex sMallocMutex; | ||
static OSSpinLock sMallocSpinLock; | ||
|
||
void | ||
__wut_malloc_lock(struct _reent *r) | ||
{ | ||
OSLockMutex(&sMallocMutex); | ||
OSUninterruptibleSpinLock_Acquire(&sMallocSpinLock); | ||
} | ||
|
||
void | ||
__wut_malloc_unlock(struct _reent *r) | ||
{ | ||
OSUnlockMutex(&sMallocMutex); | ||
OSUninterruptibleSpinLock_Release(&sMallocSpinLock); | ||
} | ||
|
||
void | ||
__init_wut_malloc_lock() | ||
{ | ||
OSInitMutex(&sMallocMutex); | ||
OSInitSpinLock(&sMallocSpinLock); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters