changeset 202:66db83ec1ec2

kpt_alloc_check_impl and freerange
author tobaru
date Thu, 23 Jan 2020 20:48:16 +0900
parents 02bb0f8be908
children 6e03cee9733e
files src/impl/vm_impl.cbc src/impl/vm_impl.h src/impl/vm_impl_private.cbc
diffstat 3 files changed, 35 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/impl/vm_impl.cbc	Thu Jan 23 18:08:22 2020 +0900
+++ b/src/impl/vm_impl.cbc	Thu Jan 23 20:48:16 2020 +0900
@@ -53,14 +53,35 @@
     goto next(...);
 }
 
-__code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) {
+extern struct run {
+    struct run *next;
+};
 
-    goto next(...);
+static void _kpt_free (char *v)
+{
+    struct run *r;
+
+    r = (struct run*) v;
+    r->next = kpt_mem.freelist;
+    kpt_mem.freelist = r;
 }
 
-__code kpt_allocvm_impl(struct vm_impl* vm ,__code next(...)) {
+__code kpt_freerangevm_impl(struct vm_impl* vm, uint low, uint hi, __code next(...)) { 
+ 
+   if (low < hi) { 
+     _kpt_free((char*)low);
+     goto kpt_freerangevm_impl(vm, low + PT_SZ, hi, next(...));  
+  
+   } 
+  goto next(...);
+}
+__code kpt_allocvm_impl(struct vm_impl* vm, __code next(...)) {
+  struct run *r;
+  acquire(&kpt_mem.lock);
 
-    goto next(...);
+  goto kpt_alloc_check_impl(vm_impl, r, next(...));
+
+  goto next(...);
 }
 
 typedef struct proc proc;
--- a/src/impl/vm_impl.h	Thu Jan 23 18:08:22 2020 +0900
+++ b/src/impl/vm_impl.h	Thu Jan 23 20:48:16 2020 +0900
@@ -10,7 +10,7 @@
     uint pa;
     uint n;
 
-    __code init_vmm(Type* vm_impl, __code next(...));
+    __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 next(...);
--- a/src/impl/vm_impl_private.cbc	Thu Jan 23 18:08:22 2020 +0900
+++ b/src/impl/vm_impl_private.cbc	Thu Jan 23 20:48:16 2020 +0900
@@ -106,3 +106,12 @@
 
     goto next(...);
 }
+
+__code kpt_alloc_check_impl(struct vm_impl* vm_impl, __code next(...)) { 
+    
+   goto kpt_alloc_check_inital_page(vm_impl, next(...));
+}
+
+__code kpt_alloc_check_inital_page(struct vm_impl* vm_impl, __code next(...)) {
+    goto next((char*)r);
+}