# HG changeset patch # User tobaru # Date 1579780096 -32400 # Node ID 66db83ec1ec2ca730c0e97b38f77531bac51ddb2 # Parent 02bb0f8be908b7aa9445b7c8292168c19dbd9d1e kpt_alloc_check_impl and freerange diff -r 02bb0f8be908 -r 66db83ec1ec2 src/impl/vm_impl.cbc --- 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; diff -r 02bb0f8be908 -r 66db83ec1ec2 src/impl/vm_impl.h --- 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(...); diff -r 02bb0f8be908 -r 66db83ec1ec2 src/impl/vm_impl_private.cbc --- 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); +}