Page 2 of 2

Re:Having trouble with multiple address spaces

Posted: Sun Dec 07, 2003 5:43 pm
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.

Re:Having trouble with multiple address spaces

Posted: Tue Dec 16, 2003 6:36 am
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 ;)