diff --git a/core/stack.c b/core/stack.c index 956076f..b98a80d 100644 --- a/core/stack.c +++ b/core/stack.c @@ -41,7 +41,7 @@ void printStackTrace(unsigned int maxFrames) #else printf("Must be compiled with -fno-omit-frame-pointer for full stack\n"); unsigned int *ebp = &maxFrames - 2; - unsigned int eip = ebp[1]; + unsigned int *eip = ebp + sizeof(unsigned int); printf("[0] 0x%x\n", eip); #endif } diff --git a/core/thread.c b/core/thread.c index 4bd8f6d..5fe0955 100644 --- a/core/thread.c +++ b/core/thread.c @@ -41,6 +41,8 @@ void threadExit() int threadSetup(vaddr_t mainStack, size_t mainStackSize) { struct thread *current = (struct thread *)malloc(sizeof(struct thread)); + if (current == NULL) + return -ENOMEM; strzcpy(current->name, "[KINIT]", THREAD_NAME_MAX_LENGTH); current->stackAddr = mainStack; current->stackSize = mainStackSize; @@ -345,7 +347,11 @@ static void threadPrepareContext(struct thread *th) int threadChangeCurrentContext(struct mmu_context *ctx) { uint32_t flags; - struct mmu_context *prev = currentThread->squattedContext; + struct mmu_context *prev; + + assert(currentThread != NULL); + + prev = currentThread->squattedContext; if (ctx != NULL) { assert(prev == NULL); diff --git a/core/uaccess.c b/core/uaccess.c index 619e385..852cc5e 100644 --- a/core/uaccess.c +++ b/core/uaccess.c @@ -1,6 +1,8 @@ #include "assert.h" +#include "errno.h" #include "mmuContext.h" #include "paging.h" +#include "process.h" #include "thread.h" #include "uaccess.h" diff --git a/tests/test.c b/tests/test.c index 885333e..c12de53 100644 --- a/tests/test.c +++ b/tests/test.c @@ -68,7 +68,7 @@ void testPhymem(void) assert(freePageStatAlloc == 0); assert((usedPageStatAlloc - usedPageStatBegin) == (uint)allocCount); - while ((page = list_pop_head(allocated_page_list)) != NULL) { + while ((allocated_page_list != NULL) && (page = list_pop_head(allocated_page_list)) != NULL) { assertmsg(page->phy_addr == (ulong)freeCount, "page %d modified", page); assertmsg(unrefPhyPage((ulong)page) >= 0, "Failed to free page %d\n", (ulong)page); freeCount++;