Search code examples
operating-systemstackcontext-switch

OS - User stack - not really 4096 of usable memory


Could someone confirm that when we say that an application has 4096 bytes for its stack, it can actually not use all this space because there are memory used to switch between applications (trapframes, ...) usually located on top of the stack.

This space may depend on different OS implementation.

Am I right ?

Thanks


Solution

  • 1) 4096 would be a tiny stack these days. 2) Are you talking about available to to application?

    By the time you get to "your" code (main, whatever), the stack will have a number of call frames already (eating into your 4096 bytes). Usually, at the top, there is a frame to handle returning to the operating system. Then there may be frames for setting up libraries and exception handlers. There is usually a frame these days with command line arguments.

    All of these eat into the stack.