From f67e1baa257bef2ecdd9f2bd50ec75499ad542f8 Mon Sep 17 00:00:00 2001 From: Julian Barathieu Date: Tue, 26 Mar 2019 10:34:36 +0100 Subject: [PATCH] Heap fix --- kaleid/kernel/buf/bput.c | 5 ++--- kaleid/kernel/init/init.c | 10 ++++------ kaleid/kernel/mm/heap.c | 12 +++++++----- kaleid/kernel/mm/malloc.c | 2 +- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/kaleid/kernel/buf/bput.c b/kaleid/kernel/buf/bput.c index 46ce839..0162653 100644 --- a/kaleid/kernel/buf/bput.c +++ b/kaleid/kernel/buf/bput.c @@ -69,12 +69,11 @@ error_t bputc(Buffer_t *buf, uchar ch) // We assume tabs are 4 characters long for now else if (ch == '\t') { rc = bputc(buf, ' '); - if (rc > 0) return rc; while (buf->lastLF % 4 > 0) { rc = bputc(buf, ' '); - if (rc > 0) return rc; } + if (rc > 0) return rc; } // Deal with line feeds by filling the rest of the line with spaces @@ -83,8 +82,8 @@ error_t bputc(Buffer_t *buf, uchar ch) assert(buf->lastLF < buf->lineLen); while (buf->lastLF > 0) { rc = bputc(buf, ' '); - if (rc > 0) return rc; } + if (rc > 0) return rc; } // Just a regular character diff --git a/kaleid/kernel/init/init.c b/kaleid/kernel/init/init.c index 4fd22bd..09456e8 100644 --- a/kaleid/kernel/init/init.c +++ b/kaleid/kernel/init/init.c @@ -145,12 +145,10 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, int mbMagic) MmInitHeap(); PsInitSched(); - Buffer_t *buf = BOpenLineBuf(NULL, BS_WRONLY, 80, 24, 1, NULL); - - error_t rc = BPrintOnBuf(buf, "%+#05x", 0xcafeb00b); - if(rc)KernLog("error\n"); - - KernLog((char*)buf->buf); + //Buffer_t *buf = BOpenLineBuf(NULL, BS_WRONLY, 80, 24, 1, NULL); + //error_t rc = BPrintOnBuf(buf, "%+#05x", 0xcafeb00b); + //if(rc)KernLog("error\n"); + //KernLog((char*)buf->buf); // We're out PsFiniSched(); diff --git a/kaleid/kernel/mm/heap.c b/kaleid/kernel/mm/heap.c index 86c6878..631f45c 100644 --- a/kaleid/kernel/mm/heap.c +++ b/kaleid/kernel/mm/heap.c @@ -44,14 +44,16 @@ void MmInitHeap(void) // Get the first available zone address _heap_start = MmGetFirstAvailZone((void*)0); + // Align it - while ((size_t)_heap_start % alignof(QWORD)) { - _heap_start++; - } + _heap_start = (void *)_ALIGN_UP((size_t)_heap_start, alignof(QWORD)); + // Initialize the heap _heap_end = _heap_start; - _heap_max = lmin(8 * MB, MmGetAvailZoneSize(_heap_end)); - KernLog("[InitHeap] Start address : %p, Max length : %u Mio\n\n", _heap_start, _heap_max / MB); + _heap_max = MmGetAvailZoneSize(_heap_end); + + KernLog("[InitHeap] Start address : %p, Max length : %u Mio\n\n", + _heap_start, _heap_max / MB); } // diff --git a/kaleid/kernel/mm/malloc.c b/kaleid/kernel/mm/malloc.c index a510204..1b7de5c 100644 --- a/kaleid/kernel/mm/malloc.c +++ b/kaleid/kernel/mm/malloc.c @@ -49,7 +49,7 @@ error_t KalAllocMemory(void **ptr, size_t req, int flags, size_t align) if (rc) { if ((flags & M_CANFAIL) != 0) return rc; - KeStartPanic("Out of memory"); + KeStartPanic("KalAllocMemory: Out of memory"); } if (flags & M_ZEROED) {