Copying memory for fork across page directories
Posted: Mon Apr 20, 2009 4:31 am
Hi! I've been trying to write an x86 OS based off the template provided by the CMU OS course[http://www.cs.cmu.edu/~410/] (I'm attending the school but won't be able to take the course, at least not for a few years maybe). It's a basic OS with paging-based VM, software kernel threads (only one TSS), some basic linux-style syscalls, and console/keyboard drivers.
It's been going well (I've got single-threaded programs to run =) ) but I'm a bit stuck on forking. Most of the resources I've seen deal with the memory 'cloning' by either COW (which I really don't want to do yet) or by disabling paging temporarily to copy from one physical space to another. What I was thinking was to take an alternative route: have a page of kernel memory set aside to act as a sort of 'fake buffer' for copying memory.
When I initialize paging, I set aside a page of kernel memory, then, when I need to do what would normally be just a memcpy, I go page by page and first set the page table entry corresponding to the fake buffer to be equal to that of the destination (in another PD than the current one). That way there is now a mapping in the current PD that points to the physical memory where I want the data to end up. I copy it in and repeat. At the end I just zero the fake buffer page entry for use later.
I've not seen this sort of approach anywhere, and can't get it to work. Is there something fundamental that I'm missing that does not allow this to work?
Thank you very much, I hope I can learn a lot from all of you =)
It's been going well (I've got single-threaded programs to run =) ) but I'm a bit stuck on forking. Most of the resources I've seen deal with the memory 'cloning' by either COW (which I really don't want to do yet) or by disabling paging temporarily to copy from one physical space to another. What I was thinking was to take an alternative route: have a page of kernel memory set aside to act as a sort of 'fake buffer' for copying memory.
When I initialize paging, I set aside a page of kernel memory, then, when I need to do what would normally be just a memcpy, I go page by page and first set the page table entry corresponding to the fake buffer to be equal to that of the destination (in another PD than the current one). That way there is now a mapping in the current PD that points to the physical memory where I want the data to end up. I copy it in and repeat. At the end I just zero the fake buffer page entry for use later.
I've not seen this sort of approach anywhere, and can't get it to work. Is there something fundamental that I'm missing that does not allow this to work?
Thank you very much, I hope I can learn a lot from all of you =)