git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: Optimize the signal context overhead
[lunaix-os.git]
/
lunaix-os
/
kernel
/
asm
/
x86
/
pfault.c
diff --git
a/lunaix-os/kernel/asm/x86/pfault.c
b/lunaix-os/kernel/asm/x86/pfault.c
index 70d5e560da7a145ca1b154f9e52cafd749e38d26..f527e12c3dcc0f81c292c3761c78c125943faa80 100644
(file)
--- a/
lunaix-os/kernel/asm/x86/pfault.c
+++ b/
lunaix-os/kernel/asm/x86/pfault.c
@@
-11,6
+11,19
@@
#include <klibc/string.h>
#include <klibc/string.h>
+static u32_t
+get_ptattr(struct mm_region* vmr)
+{
+ u32_t vmr_attr = vmr->attr;
+ u32_t ptattr = PG_PRESENT | PG_ALLOW_USER;
+
+ if ((vmr_attr & PROT_WRITE)) {
+ ptattr |= PG_WRITE;
+ }
+
+ return ptattr & 0xfff;
+}
+
static void
kprintf(const char* fmt, ...)
{
static void
kprintf(const char* fmt, ...)
{
@@
-51,13
+64,16
@@
intr_routine_page_fault(const isr_param* param)
goto segv_term;
}
goto segv_term;
}
- if ((errcode & PG_ALLOW_USER)) {
- // invalid access
- goto segv_term;
- }
-
volatile x86_pte_t* pte = &PTE_MOUNTED(VMS_SELF, ptr >> 12);
if (PG_IS_PRESENT(*pte)) {
volatile x86_pte_t* pte = &PTE_MOUNTED(VMS_SELF, ptr >> 12);
if (PG_IS_PRESENT(*pte)) {
+ if (((errcode ^ mapping.flags) & PG_ALLOW_USER)) {
+ // invalid access
+ kprintf(KDEBUG "invalid user access. (%p->%p, attr:0x%x)\n",
+ mapping.va,
+ mapping.pa,
+ mapping.flags);
+ goto segv_term;
+ }
if ((hit_region->attr & COW_MASK) == COW_MASK) {
// normal page fault, do COW
cpu_invplg((ptr_t)pte);
if ((hit_region->attr & COW_MASK) == COW_MASK) {
// normal page fault, do COW
cpu_invplg((ptr_t)pte);
@@
-84,7
+100,7
@@
intr_routine_page_fault(const isr_param* param)
goto oom;
}
goto oom;
}
- *pte = *pte | pa |
PG_PRESENT | PG_ALLOW_USER
;
+ *pte = *pte | pa |
get_ptattr(hit_region)
;
memset((void*)PG_ALIGN(ptr), 0, PG_SIZE);
goto resolved;
}
memset((void*)PG_ALIGN(ptr), 0, PG_SIZE);
goto resolved;
}
@@
-107,7
+123,7
@@
intr_routine_page_fault(const isr_param* param)
}
cpu_invplg((ptr_t)pte);
}
cpu_invplg((ptr_t)pte);
- *pte = (*pte & 0xFFF) | pa |
PG_PRESENT | PG_ALLOW_USER
;
+ *pte = (*pte & 0xFFF) | pa |
get_ptattr(hit_region)
;
memset((void*)ptr, 0, PG_SIZE);
memset((void*)ptr, 0, PG_SIZE);
@@
-143,7
+159,7
@@
segv_term:
param->execp->eip,
param->execp->err_code);
param->execp->eip,
param->execp->err_code);
-
__SIGSET(__current->
sig_pending, _SIGSEGV);
+
sigset_add(__current->sigctx.
sig_pending, _SIGSEGV);
schedule();
// should not reach
schedule();
// should not reach