hard time managing multiple address spaces
Posted: Mon Apr 06, 2020 9:13 am
I am trying to implement multitasking for my kernel but I ran into a problem,
After reading about multitasking I figured that I need to do the following in order to create "threads" in my kernel.
1. Create a new address space for the new thread.
2. Copy all the pages in the old address space into the new one (as in copy the page entry in the tables which means they share memory).
3. Find the pages for the stack and swap them out for new clean pages.
4. Clone the current stack with memcpy into the new clean pages.
5. And swap to the new address space.
Right now my kernel uses recursive mapping to manage the virtual memory but this is a big problem for what I am trying to do, I can't access any of the page tables in the new address space because it isn't self-mapped.
So after a bit of thinking i came up with some solutions that might work.
The first option is to save a struct with the physical and virtual memory of the page and use some kind of temp page to map page dirs and tables I need to modified, but this will cost a lot of memory.
And the second one is using the same page tables for all kernel address spaces beside two one for self-mapping and one for the stack, but here we wast a lot of the virtual address space for just a stack.
So I am stuck cause I don't want to use any of my options because of their big draw backs, any tips ideas (or even your own experience in the matter) on how to implement that would be grate.
After reading about multitasking I figured that I need to do the following in order to create "threads" in my kernel.
1. Create a new address space for the new thread.
2. Copy all the pages in the old address space into the new one (as in copy the page entry in the tables which means they share memory).
3. Find the pages for the stack and swap them out for new clean pages.
4. Clone the current stack with memcpy into the new clean pages.
5. And swap to the new address space.
Right now my kernel uses recursive mapping to manage the virtual memory but this is a big problem for what I am trying to do, I can't access any of the page tables in the new address space because it isn't self-mapped.
So after a bit of thinking i came up with some solutions that might work.
The first option is to save a struct with the physical and virtual memory of the page and use some kind of temp page to map page dirs and tables I need to modified, but this will cost a lot of memory.
And the second one is using the same page tables for all kernel address spaces beside two one for self-mapping and one for the stack, but here we wast a lot of the virtual address space for just a stack.
So I am stuck cause I don't want to use any of my options because of their big draw backs, any tips ideas (or even your own experience in the matter) on how to implement that would be grate.