Skip to content

Commit 8276e4b

Browse files
committed
Restoring original psyqo_heap_end functionality, kind of.
1 parent 857f5f6 commit 8276e4b

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

src/mips/psyqo/alloc.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,10 @@ void *psyqo_heap_start();
9090
*
9191
* @details This function will return the pointer to the end of the
9292
* heap. The heap works lazily, and this function may return a NULL
93-
* pointer. Once it returns a non-NULL pointer, it will always return
94-
* the same pointer to the maximum address of the heap.
93+
* pointer. Once it returns a non-NULL pointer, it will approximately
94+
* correspond to the current end of the heap. The heap may actually
95+
* be larger than this pointer on occasion. The heap will always
96+
* grow, and never shrink.
9597
*
9698
* @return void* The end of the heap.
9799
*/

src/mips/psyqo/src/alloc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ _Static_assert(sizeof(allocated_block) == (2 * sizeof(void *)), "allocated_block
9797
static empty_block *head = NULL;
9898
static allocated_block *bottom = NULL;
9999
static allocated_block *top = NULL;
100+
static void *maximum_heap_end = NULL;
100101
// The marker is here to make sure that the list is always terminated,
101102
// so when we completely fill the heap, we don't end up with a NULL pointer
102103
// back to the head. It will never fit any allocation, and will always
@@ -328,6 +329,10 @@ void *psyqo_malloc(size_t size_) {
328329
}
329330

330331
// Store the size of the allocation before the pointer.
332+
void *end = (void *)((char *)ptr + size);
333+
if (end > maximum_heap_end) {
334+
maximum_heap_end = end;
335+
}
331336
ptr->size = size;
332337
ptr++;
333338

@@ -656,4 +661,4 @@ void _ZdlPvj(void *ptr, unsigned int size) { psyqo_free(ptr); }
656661
void _ZdaPvj(void *ptr, unsigned int size) { psyqo_free(ptr); }
657662

658663
void *psyqo_heap_start() { return bottom; }
659-
void *psyqo_heap_end() { return top; }
664+
void *psyqo_heap_end() { return maximum_heap_end; }

0 commit comments

Comments
 (0)