WIP: Add fork() #13
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "fork"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
This PR adds initial support for fork(), which should work well along with exec(). Should not be merged until both fork() and exec() work well separately, and together.
There is a problem here:
The child starts doing stuff with the parent's stack, since all addresses copied from the parent are directly what the parent set.
But if we map both stacks at the same place... we can't do that, since they share address spaces and modifying one will change the other.
Maybe patching the child stack? Not very usual... and hacky... let's try I guess.
I don't understand.
Now address spaces are cloned, and copied, which means they have the same addresses but modifying memory in one doesn't get reflected in the other.
And yet, with an almost identical copy (except for the state of RAX), the parent continues execution normally, and the child does weird stuff with its stack (which has the same content as the parent's, at the same place), and ends off returning to 0.
WHY???
I think my cheap solution for this right now is going be to introduce a spawn() function to spawn a new executable, and forget about fork() for now. At least until I can figure out why the hell it is working so weirdly.
Will have to come back to this in the future, since the idea is to be UNIX-like, but right now this is solved by commit 9b39d61. Now we can spawn() processes as much as we want!
Oh, by the way, the problem (which was solved LONG ago), was that we were setting the child's registers to the registers stored in the parent's Task structure. But we didn't save the parent's current context to that structure (why would we do so, that's only necessary during a context switch), and as such the child's registers were outdated (from the last context switch), clashing with up-to-date memory and stack pointers. The parent didn't mind since we didn't touch the current state of its registers.
Pull request closed