mirror of https://github.com/zeldaret/tmc.git
parent
50b8efb7d9
commit
1e8ced01e6
23
src/common.c
23
src/common.c
|
@ -350,9 +350,8 @@ void sub_0801D898(void* dest, void* src, u32 word, u32 size) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void* zMalloc(u32 size) {
|
void* zMalloc(u32 size) {
|
||||||
|
|
||||||
FORCE_REGISTER(u32 slotFound, r5);
|
|
||||||
u16* heapStartOffset;
|
u16* heapStartOffset;
|
||||||
|
u32 slotFound;
|
||||||
u8* allocatedEntryStartOffset;
|
u8* allocatedEntryStartOffset;
|
||||||
u8* allocatedEntryEndOffset;
|
u8* allocatedEntryEndOffset;
|
||||||
u8* candidateSlotEndOffset;
|
u8* candidateSlotEndOffset;
|
||||||
|
@ -377,7 +376,8 @@ void* zMalloc(u32 size) {
|
||||||
|
|
||||||
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
|
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
|
||||||
candidateSlotStartOffset <= allocatedEntryEndOffset)) {
|
candidateSlotStartOffset <= allocatedEntryEndOffset)) {
|
||||||
goto other_search;
|
slotFound = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((allocatedEntryStartOffset <= candidateSlotEndOffset &&
|
if ((allocatedEntryStartOffset <= candidateSlotEndOffset &&
|
||||||
|
@ -390,17 +390,15 @@ void* zMalloc(u32 size) {
|
||||||
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
|
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
|
||||||
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
|
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
|
||||||
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
|
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
|
||||||
goto other_search;
|
slotFound = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!slotFound) {
|
if (!slotFound) {
|
||||||
other_search:
|
|
||||||
|
|
||||||
index1 = 0;
|
index1 = 0;
|
||||||
// Start searching for candidate slot from the left side of the heap buffer.
|
// Start searching for candidate slot from the left side of the heap buffer.
|
||||||
do {
|
do {
|
||||||
|
|
||||||
candidateSlotEndOffset = gzHeap + heapStartOffset[(index1 * 2) + 1];
|
candidateSlotEndOffset = gzHeap + heapStartOffset[(index1 * 2) + 1];
|
||||||
candidateSlotStartOffset = candidateSlotEndOffset - size;
|
candidateSlotStartOffset = candidateSlotEndOffset - size;
|
||||||
slotFound = FALSE;
|
slotFound = FALSE;
|
||||||
|
@ -417,7 +415,8 @@ void* zMalloc(u32 size) {
|
||||||
|
|
||||||
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
|
if ((allocatedEntryStartOffset <= candidateSlotStartOffset &&
|
||||||
candidateSlotStartOffset < allocatedEntryEndOffset)) {
|
candidateSlotStartOffset < allocatedEntryEndOffset)) {
|
||||||
goto iter_end;
|
slotFound = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((allocatedEntryStartOffset < candidateSlotEndOffset &&
|
if ((allocatedEntryStartOffset < candidateSlotEndOffset &&
|
||||||
|
@ -430,17 +429,13 @@ void* zMalloc(u32 size) {
|
||||||
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
|
candidateSlotEndOffset <= allocatedEntryEndOffset) ||
|
||||||
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
|
(candidateSlotStartOffset <= allocatedEntryStartOffset &&
|
||||||
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
|
allocatedEntryEndOffset <= candidateSlotEndOffset)) {
|
||||||
goto iter_end;
|
slotFound = FALSE;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (slotFound) {
|
if (slotFound) {
|
||||||
break;
|
break;
|
||||||
} else {
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
iter_end:
|
|
||||||
slotFound = FALSE;
|
|
||||||
}
|
}
|
||||||
} while ((index1 = (u16)(index1 + 1)) < numEntries);
|
} while ((index1 = (u16)(index1 + 1)) < numEntries);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue