Having trouble with multiple address spaces

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Tim

Re:Having trouble with multiple address spaces

Post by Tim »

OK, looks like we're talking about the same thing. I've seen a few OSes which place variables at arbitrary address in memory (e.g. Menuet) and I can see no need for this -- it just makes the programmer's life harder.

Kernel stacks are allocated pagewise, growing down from E000_0000. I don't have any actual kernel stack deallocation yet, though clearly I need this in the long term. I could move this over to malloc, as long as I put unmapped guard pages at each end, or I could come up with a custom deallocator.

User stacks are allocated using the normal VMM allocator for user-mode memory. The kernel reserves the space immediately below 8000_000 at kernel startup, and allocates 1MB stacks there as each thread is created. Pages of the stack are faulted in as the thread references them, so physical memory is not wasted. Deallocation of user-mode stacks uses the normal VMM free function.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Having trouble with multiple address spaces

Post by Pype.Clicker »

Candy wrote: How do you allocate kernel stacks? Do you do that in a heap-like way, page-wise, do you allocate address space or pages, and do you use guard pages at the start/end?

And, something for my future, do you allocate user-space stacks in the same way?
I give all my kernel stacks the same 'sufficient' size and use segmentation to catch stack overflows. Page guards are not a wise thing with kernel stacks, as you need your kernel stack to handle page faults. On the other hands, overflowing a stack segment raises a "Stack Fault", which can nicely be delegated to a specific TSS.

It took me daaays to discover that 'page-guarding' stuff for kernel stacks ... hope it will save days to you ;)
Post Reply