The MASM Forum

64 bit assembler => 64 bit assembler. Conceptual Issues => Topic started by: jj2007 on August 21, 2023, 10:05:04 AM

Title: Shadow space: who owns the arguments?
Post by: jj2007 on August 21, 2023, 10:05:04 AM
This question pops up every now and then - glad to have found such a clear statement by Peter Cordes, who knows his stuff:

QuoteA function "owns" its stack args, too, and can modify them after function entry. To be able to see args function were actually called with while backtracing, you'd have to write code that used different variables instead of modifying the incoming args. (Or the compiler could copy the stack args if you did that.) Since debug info shows where to find all vars, not just args, you can see arg variables in the stack frame where the compiler spilled them regardless of shadow space or not. e.g. the x86-64 System V calling convention doesn't have a problem with this, even without shadow space. –
Peter Cordes (https://stackoverflow.com/questions/30190132/what-is-the-shadow-space-in-x64-assembly), Jan 13, 2020 at 18:53
Title: Re: Shadow space: who owns the arguments?
Post by: NoCforMe on August 22, 2023, 03:27:22 PM
Hmm, isn't that a little like saying "the sky is blue"? I mean, to me it's always been self-evident that arguments (and to be clear, that means values passed into a function as opposed to "automatic", "local" variables allocated on the stack, which are only visible to the function) are exactly the same as local vars, so far as accessibility by the function code is concerned. Amiright? I mean, it's not as if they have some kind of special protection that prevents them from being written to just like a local variable, as well as read; they're just memory locations that happen to be in stack space. (Oddly enough, I don't think I've ever actually done that--write to a function argument--in about 40 years of programming!)
Title: Re: Shadow space: who owns the arguments?
Post by: jj2007 on August 22, 2023, 08:55:02 PM
You may find it obvious, but...

https://stackoverflow.com/questions/21132073/is-it-considered-a-bad-practice-to-modify-parameters (https://stackoverflow.com/questions/21132073/is-it-considered-a-bad-practice-to-modify-parameters)

About 419 hits for "modify arguments" "stack" site:stackoverflow.com
About 736 hits for "modify parameters" "stack" site:stackoverflow.com

I can remember discussions here where senior members argued that no, it was not allowed to do that. Unfortunately, neither forum search nor Google are very good at finding specific posts with "modify" and "arguments" or "args" or "parameters"