aboutsummaryrefslogtreecommitdiff
path: root/src/kernel/core/paging.c
diff options
context:
space:
mode:
authorAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 23:13:51 +0100
committerAlex Auvolat <alex.auvolat@ens.fr>2015-02-14 23:13:51 +0100
commit817b7848dca5b7080ba53666eb2dd8f37b05453a (patch)
tree73b5e37afe39e1bc05904685095d83a44d4bd353 /src/kernel/core/paging.c
parent73cf3eddd480f2bd7e987c58da82c243861a5314 (diff)
downloadkogata-817b7848dca5b7080ba53666eb2dd8f37b05453a.tar.gz
kogata-817b7848dca5b7080ba53666eb2dd8f37b05453a.zip
Fix mchmap. Lesson : invalid pointer dereferences happen! with unexpected results.
Diffstat (limited to 'src/kernel/core/paging.c')
-rw-r--r--src/kernel/core/paging.c16
1 files changed, 9 insertions, 7 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)) {