changeset 216:0f1700bd5cff

cleapteu
author tobaru
date Fri, 24 Jan 2020 15:22:44 +0900
parents 291d4e9304a1
children f940ff602312
files src/impl/vm_impl.cbc src/impl/vm_impl.h src/impl/vm_impl_private.cbc
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/vm_impl.cbc	Fri Jan 24 14:54:09 2020 +0900
+++ b/src/impl/vm_impl.cbc	Fri Jan 24 15:22:44 2020 +0900
@@ -113,7 +113,7 @@
 
 __code clearpteuvm_impl(struct vm_impl* vm, pde_t* pgdir, char* uva,  __code next(...)) {
 
-    goto next(...);
+    goto clearpteu_check_ptevm_impl(vm, pgdir, uva, next(...);
 }
 
 __code copyuvmvm_impl(struct vm_impl* vm, pde_t* pgdir, uint sz, __code next(...)) {
--- a/src/impl/vm_impl.h	Fri Jan 24 14:54:09 2020 +0900
+++ b/src/impl/vm_impl.h	Fri Jan 24 15:22:44 2020 +0900
@@ -14,12 +14,14 @@
     uint a;
     int ret;
     char* mem;
+    char* uva;
 
     __code kpt_alloc_check_impl(Type* vm_impl, __code next(...));
     __code loaduvm_ptesize_check(Type* vm_impl, __code next(...));
     __code loaduvm_loop(Type* vm_impl, uint i, pte_t* pte, uint sz, __code next(...));
     __code allocuvm_check_newsz(Type* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, __code next(...));
     __code allocuvm_loop(Type* vm_impl, pde_t* pgdir, uint oldsz, uint newsz, uint a, __code next(...));
+    __code clearpteu_check_ptevm_impl(Type* vm_impl, pde_t* pgdir, char* uva,  __code next(...));
     __code next(...);
  
 
--- a/src/impl/vm_impl_private.cbc	Fri Jan 24 14:54:09 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Fri Jan 24 15:22:44 2020 +0900
@@ -187,7 +187,7 @@
         if (mem == 0) {
             cprintf("allocuvm out of memory\n");
             deallocuvm(pgdir, newsz, oldsz);
-            goto next(ret, ...);
+            goto next(0, ...);
         }
 
         memset(mem, 0, PTE_SZ);
@@ -198,3 +198,18 @@
     ret = newsz; 
     goto next(ret, ...);
 }
+
+__code clearpteu_check_ptevm_impl(struct vm_impl* vm_impl, pde_t* pgdir, char* uva, __code next(int ret, ...)) {
+    pte_t *pte;
+
+    pte = walkpgdir(pgdir, uva, 0);
+    if (pte == 0) {
+        // panic("clearpteu");
+        // goto panic;
+    }
+
+    // in ARM, we change the AP field (ap & 0x3) << 4)
+    *pte = (*pte & ~(0x03 << 4)) | AP_KO << 4;
+
+    goto next(ret, ...);
+}