Browse Source

Add user check for large pages and combine user and write error check

Bananymous 6 months ago
parent
commit
9a9d6f3307
1 changed files with 7 additions and 9 deletions
  1. 7 9
      src/rust/cpu/cpu.rs

+ 7 - 9
src/rust/cpu/cpu.rs

@@ -1957,7 +1957,9 @@ pub unsafe fn do_page_walk(
         if 0 != page_dir_entry & PAGE_TABLE_PSE_MASK && 0 != cr4 & CR4_PSE {
             // size bit is set
 
-            if for_writing && !allow_write && !kernel_write_override {
+            let user_error = user && !allow_user;
+            let write_error = for_writing && !allow_write && !kernel_write_override;
+            if user_error || write_error {
                 if side_effects {
                     trigger_pagefault(addr, true, for_writing, user, jit);
                 }
@@ -2013,15 +2015,11 @@ pub unsafe fn do_page_walk(
             }
 
             allow_write &= page_table_entry & PAGE_TABLE_RW_MASK != 0;
-            if for_writing && !allow_write && !kernel_write_override {
-                if side_effects {
-                    trigger_pagefault(addr, true, for_writing, user, jit);
-                }
-                return Err(());
-            }
-
             allow_user &= page_table_entry & PAGE_TABLE_USER_MASK != 0;
-            if user && !allow_user {
+
+            let user_error = user && !allow_user;
+            let write_error = for_writing && !allow_write && !kernel_write_override;
+            if user_error || write_error {
                 if side_effects {
                     trigger_pagefault(addr, true, for_writing, user, jit);
                 }