summaryrefslogtreecommitdiff
path: root/src/kernel/arch/i386/pagedir.c
diff options
context:
space:
mode:
authordzwdz2021-08-24 19:05:46 +0200
committerdzwdz2021-08-24 19:05:46 +0200
commitb988b821372466ed58eb1d2116bcbb158f70346c (patch)
tree669bb9331082848277031632e818e8293fb6e44c /src/kernel/arch/i386/pagedir.c
parent04878a07e587f26fe6d5a1044b69651406e3aa1c (diff)
switch to using user_ptr for pointers coming from userland
this avoid accidental dereferences, and now it's easy to tell apart which pointers are safe to directly read and which aren't. cons: - const is completely discarded
Diffstat (limited to 'src/kernel/arch/i386/pagedir.c')
-rw-r--r--src/kernel/arch/i386/pagedir.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/kernel/arch/i386/pagedir.c b/src/kernel/arch/i386/pagedir.c
index 486d2a2..8f62a45 100644
--- a/src/kernel/arch/i386/pagedir.c
+++ b/src/kernel/arch/i386/pagedir.c
@@ -46,12 +46,11 @@ struct pagedir *pagedir_new(void) {
return dir;
}
-void pagedir_map(struct pagedir *dir, void *virt, void *phys,
+void pagedir_map(struct pagedir *dir, user_ptr virt, void *phys,
bool user, bool writeable)
{
- uintptr_t virt_casted = (uintptr_t) virt;
- uint32_t pd_idx = virt_casted >> 22;
- uint32_t pt_idx = virt_casted >> 12 & 0x03FF;
+ uint32_t pd_idx = virt >> 22;
+ uint32_t pt_idx = virt >> 12 & 0x03FF;
struct pagetable_entry *pagetable;
if (dir->e[pd_idx].present) {
@@ -125,13 +124,12 @@ struct pagedir *pagedir_copy(const struct pagedir *orig) {
return clone;
}
-void *pagedir_virt2phys(struct pagedir *dir, const void *virt,
+void *pagedir_virt2phys(struct pagedir *dir, const user_ptr virt,
bool user, bool writeable)
{
- uintptr_t virt_casted = (uintptr_t) virt;
uintptr_t phys;
- uint32_t pd_idx = virt_casted >> 22;
- uint32_t pt_idx = virt_casted >> 12 & 0x03FF;
+ uint32_t pd_idx = virt >> 22;
+ uint32_t pt_idx = virt >> 12 & 0x03FF;
struct pagetable_entry *pagetable, page;
/* DOESN'T CHECK PERMISSIONS ON PAGE DIRS, TODO
@@ -148,6 +146,6 @@ void *pagedir_virt2phys(struct pagedir *dir, const void *virt,
if (writeable && !page.writeable) return 0;
phys = page.address << 11;
- phys |= (uintptr_t)virt & 0xFFF;
+ phys |= virt & 0xFFF;
return (void*)phys;
}