diff options
Diffstat (limited to 'src/kernel')
-rw-r--r-- | src/kernel/core/paging.c | 16 | ||||
-rw-r--r-- | src/kernel/user/process.c | 2 |
2 files changed, 10 insertions, 8 deletions
diff --git a/src/kernel/core/paging.c b/src/kernel/core/paging.c index 69fb98f..0b46be1 100644 --- a/src/kernel/core/paging.c +++ b/src/kernel/core/paging.c @@ -7,8 +7,8 @@ #include <thread.h> #include <malloc.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)) +#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)) typedef struct page_table { uint32_t page[1024]; @@ -197,14 +197,16 @@ uint32_t pd_get_frame(void* vaddr) { } bool pd_map_page(void* vaddr, uint32_t frame_id, bool rw) { - uint32_t pt = PT_OF_ADDR(vaddr); - uint32_t page = PAGE_OF_ADDR(vaddr); + const uint32_t pt = PT_OF_ADDR(vaddr); + const uint32_t page = PAGE_OF_ADDR(vaddr); ASSERT((size_t)vaddr < PD_MIRROR_ADDR); - pagedir_t *pdd = ((size_t)vaddr >= K_HIGHHALF_ADDR || current_thread == 0 - ? &kernel_pd_d : current_thread->current_pd_d); - pagetable_t *pd = ((size_t)vaddr >= K_HIGHHALF_ADDR ? &kernel_pd : current_pd); + bool on_kernel_pd = (size_t)vaddr >= K_HIGHHALF_ADDR || current_thread == 0; + + pagedir_t *pdd = (on_kernel_pd ? &kernel_pd_d : current_thread->current_pd_d); + pagetable_t *pd = (on_kernel_pd ? &kernel_pd : current_pd); + mutex_lock(&pdd->mutex); if (!(pd->page[pt] & PTE_PRESENT)) { diff --git a/src/kernel/user/process.c b/src/kernel/user/process.c index 72042d9..fc608a7 100644 --- a/src/kernel/user/process.c +++ b/src/kernel/user/process.c @@ -220,7 +220,7 @@ bool mchmap(process_t *proc, void* addr, int mode) { // change mode on already mapped pages pagedir_t *save_pd = get_current_pagedir(); switch_pagedir(proc->pd); - for (void* it = r->addr; it < r->addr + r->size; r += PAGE_SIZE) { + for (void* it = r->addr; it < r->addr + r->size; it += PAGE_SIZE) { uint32_t ent = pd_get_entry(it); uint32_t frame = pd_get_frame(it); |