diff options
Diffstat (limited to 'src/kernel/core')
-rw-r--r-- | src/kernel/core/paging.c | 12 | ||||
-rw-r--r-- | src/kernel/core/thread.c | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/kernel/core/paging.c b/src/kernel/core/paging.c index 0b46be1..38e8407 100644 --- a/src/kernel/core/paging.c +++ b/src/kernel/core/paging.c @@ -6,6 +6,7 @@ #include <mutex.h> #include <thread.h> #include <malloc.h> +#include <freemem.h> #define PAGE_OF_ADDR(x) (((size_t)(x) >> PAGE_SHIFT) % N_PAGES_IN_PT) #define PT_OF_ADDR(x) ((size_t)(x) >> (PAGE_SHIFT + PT_SHIFT)) @@ -210,10 +211,17 @@ bool pd_map_page(void* vaddr, uint32_t frame_id, bool rw) { mutex_lock(&pdd->mutex); if (!(pd->page[pt] & PTE_PRESENT)) { - uint32_t new_pt_frame = frame_alloc(1); + + uint32_t new_pt_frame; + int tries = 0; + while ((new_pt_frame = frame_alloc(1)) == 0 && (tries++) < 3) { + mutex_unlock(&pdd->mutex); + free_some_memory(); + mutex_lock(&pdd->mutex); + } if (new_pt_frame == 0) { mutex_unlock(&pdd->mutex); - return false; // OOM + return false; } current_pd->page[pt] = pd->page[pt] = diff --git a/src/kernel/core/thread.c b/src/kernel/core/thread.c index cd46891..02e81e1 100644 --- a/src/kernel/core/thread.c +++ b/src/kernel/core/thread.c @@ -8,6 +8,7 @@ #include <paging.h> #include <worker.h> #include <process.h> +#include <freemem.h> void save_context_and_enter_scheduler(saved_context_t *ctx); void resume_context(saved_context_t *ctx); @@ -137,10 +138,15 @@ thread_t *new_thread(entry_t entry, void* data) { void* stack_high = stack_low + KPROC_STACK_SIZE; for (void* i = stack_low; i < stack_high; i += PAGE_SIZE) { - uint32_t f = frame_alloc(1); + uint32_t f; + int tries = 0; + while ((f = frame_alloc(1)) == 0 && (tries++) < 3) { + free_some_memory(); + } if (f == 0) { PANIC("TODO (OOM could not create kernel stack for new thread)"); } + bool map_ok = pd_map_page(i, f, true); if (!map_ok) { PANIC("TODO (OOM(2) could not create kernel stack for new thread)"); |