News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Shadow space: who owns the arguments?

Started by jj2007, August 21, 2023, 10:05:04 AM

Previous topic - Next topic

jj2007

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, Jan 13, 2020 at 18:53

NoCforMe

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!)
Assembly language programming should be fun. That's why I do it.

jj2007

#2
You may find it obvious, but...

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"