Paging and Process Stacks
Posted: Sat Sep 11, 2010 5:05 pm
So I recently got completely hacktastic context switching (multi-tasking, yay!!!) working in my kernel, and I cheated; I did so without virtual memory of any kind. I'm about to make the big giant leap of faith and enable paging and proper process loading (from ELF format) all at once, and while I was thinking about my spawn process function, something occured to me.
Processes each have their own stack, and naturally that stack would start out as a single 4k page at the end of the virtual address space, and then be allowed to grow downwards as needed, right? But, when the stack needs to grow past the page, wouldn't that result in a page fault? And doesn't a page fault (and any interrupt really) need to throw stuff on the stack? How does that work exactly?
I was looking at http://wiki.osdev.org/Context_Switching and it seems to suggest something about a TSS entry. Does this mean that all virtual processes will need to run in not-ring 3, and that their interrupt information will then end up on the kernel's stack? This seems logical, although I would need to rewrite some things, as presently I'm pushing my processes state info onto its own stack and just having the kernel hold on to the stack pointer for each process.
Or, is it more normal for the process stack to be a fixed size? I mean, I want there to be a limit on stack size, but I was hoping for it to grow dynamically so the limit could be rather large if needed / could possibly be set by the program as part of its header.
Thanks in advance. ^_^
Processes each have their own stack, and naturally that stack would start out as a single 4k page at the end of the virtual address space, and then be allowed to grow downwards as needed, right? But, when the stack needs to grow past the page, wouldn't that result in a page fault? And doesn't a page fault (and any interrupt really) need to throw stuff on the stack? How does that work exactly?
I was looking at http://wiki.osdev.org/Context_Switching and it seems to suggest something about a TSS entry. Does this mean that all virtual processes will need to run in not-ring 3, and that their interrupt information will then end up on the kernel's stack? This seems logical, although I would need to rewrite some things, as presently I'm pushing my processes state info onto its own stack and just having the kernel hold on to the stack pointer for each process.
Or, is it more normal for the process stack to be a fixed size? I mean, I want there to be a limit on stack size, but I was hoping for it to grow dynamically so the limit could be rather large if needed / could possibly be set by the program as part of its header.
Thanks in advance. ^_^