define variables in mallo.c

This commit is contained in:
YamaArashi 2016-11-01 14:45:06 -07:00
parent 532cff43fb
commit f71ceb29b4
2 changed files with 15 additions and 18 deletions

View File

@ -1,7 +1,7 @@
#include "global.h" #include "global.h"
extern void *gHeapStart; static void *sHeapStart;
extern u32 gHeapSize; static u32 sHeapSize;
#define MALLOC_SYSTEM_ID 0xA3A3 #define MALLOC_SYSTEM_ID 0xA3A3
@ -15,10 +15,10 @@ struct MemBlock {
// Size of the block (not including this header struct). // Size of the block (not including this header struct).
u32 size; u32 size;
// Previous block pointer. Equals gHeapStart if this is the first block. // Previous block pointer. Equals sHeapStart if this is the first block.
struct MemBlock *prev; struct MemBlock *prev;
// Next block pointer. Equals gHeapStart if this is the last block. // Next block pointer. Equals sHeapStart if this is the last block.
struct MemBlock *next; struct MemBlock *next;
// Data in the memory block. (Arrays of length 0 are a GNU extension.) // Data in the memory block. (Arrays of length 0 are a GNU extension.)
@ -169,40 +169,40 @@ bool32 CheckMemBlockInternal(void *heapStart, void *pointer)
void InitHeap(void *heapStart, u32 heapSize) void InitHeap(void *heapStart, u32 heapSize)
{ {
gHeapStart = heapStart; sHeapStart = heapStart;
gHeapSize = heapSize; sHeapSize = heapSize;
PutFirstMemBlockHeader(heapStart, heapSize); PutFirstMemBlockHeader(heapStart, heapSize);
} }
void *Alloc(u32 size) void *Alloc(u32 size)
{ {
AllocInternal(gHeapStart, size); AllocInternal(sHeapStart, size);
} }
void *AllocZeroed(u32 size) void *AllocZeroed(u32 size)
{ {
AllocZeroedInternal(gHeapStart, size); AllocZeroedInternal(sHeapStart, size);
} }
void Free(void *pointer) void Free(void *pointer)
{ {
FreeInternal(gHeapStart, pointer); FreeInternal(sHeapStart, pointer);
} }
bool32 CheckMemBlock(void *pointer) bool32 CheckMemBlock(void *pointer)
{ {
return CheckMemBlockInternal(gHeapStart, pointer); return CheckMemBlockInternal(sHeapStart, pointer);
} }
bool32 CheckHeap() bool32 CheckHeap()
{ {
struct MemBlock *pos = (struct MemBlock *)gHeapStart; struct MemBlock *pos = (struct MemBlock *)sHeapStart;
do { do {
if (!CheckMemBlockInternal(gHeapStart, pos->data)) if (!CheckMemBlockInternal(sHeapStart, pos->data))
return FALSE; return FALSE;
pos = pos->next; pos = pos->next;
} while (pos != (struct MemBlock *)gHeapStart); } while (pos != (struct MemBlock *)sHeapStart);
return TRUE; return TRUE;
} }

View File

@ -1,12 +1,9 @@
gUnknown_03000000: @ 3000000 gUnknown_03000000: @ 3000000
.space 0x4 .space 0x4
gHeapStart: @ 3000004 .include "src/malloc.o"
.space 0x4
gHeapSize: @ 3000008
.space 0x8
.align 4
gDma3Requests: @ 3000010 gDma3Requests: @ 3000010
.space 0xC .space 0xC