NASM Forum > Programming with NASM

allocating the shadow space


Hi All,

I understand the principle around the shadow space, just not the times that its required.
I have read here that if the code and functions is all yours, you do not have to worry about it, but if you call an external API/C/C++ function you do have to worry about it ?.

My confusion comes from seeing example code where this is only partly followed.
If there is multiple function calls, do you have to do the shadow space for all the calls you make  sub rsp, 32  add rsp, 32  plus any stack args  or can you do one at the start of the code only, not every call ?  .


Hi all,

After further reading I see the idea is to use the stack over again within the same program. But I think for my own peace of mind I will align the stack and then place(and remove) the shadow space and any additional 8 byte balancing on each function.  Then maybe clean the code up after its working.


I have always created a single stack for my small code examples, but will be looking into local stack frames (I think that's the same as what you call a shadow space) when I get back into writing a simple operating system this year (I am going to rewrite the windowing system I wrote previously in C++ as the interface to my OS, but the kernel will be small with modules communicating via the kernel).

The only real advice I can offer is to remember to clean up your local stacks and restore the callers stack when you leave a routine that changes it.

The easiest way to create a stack frame is to use the ENTER and LEAVE instructions.

Frank Kotler:
Hi Debs,

I am confused about "shadow space". I think it is above the return address, rather than below as you'd get with "enter". I may well be wrong about this. Caution!


Ah, yes, you are right. According to the first hit on Google, it is 32 bytes above the return address, and has to be set up by the caller. I'd have to read up more to understand how this wouldn't destroy code that may be re-executed (in the case of loops or callable routines routines, etc) :)


[0] Message Index

Go to full version