How and when are stack frames constructed?

I'm currently reading about using memory vulnerabilities on Linux, and it was hard for me to find any information about when the layout of the stack frames would be determined. In other words, is it something specific during compilation, before program execution, or when constructing a function when calling a function? Are the differences between operating systems different?

+4
source share
3 answers

There are several factors. On x86, there is a calling convention that defines how to call a function. I assume other architectures have similar things. A system library (e.g. glibc) may define additional conventions. But in the end, the compiler decides how it uses the stack — at least when it doesn't need to interact with external libraries and needs to follow their stack structure.

+2
source

I doubt that you generally or easily find a documented answer to how stack frames were created. As others have noted, what is documented is the result of this design process, often without much of the rationale that I agree would be quite interesting.

, , , . , (? Lexical scopes?), ( ? ?), .. Microsoft, , , x86 ; x86-32 x86-64. , , .

, " " , x86.

  • , ( , ), ; " " - , " ". ( " " ). , , ; , , . , , . , , . , . PUSH EBP/LEA ESP, k [ESP], x86.
  • , . , "" ( ) ECX . , , , , .
  • , . 32- EAX, EDX 64- EAX/EDX; . ; 2 EAX/EDX.
  • PARLANSE . , "" ( ) , ESP. , "", , . , , ; , , .

, , . , , , , .

, .

+2

, /, .

Stack , , , , . ( ), , .

, , , - , , , , , , , , , , .

Stack frames are human compiler design choices and are part of compilation time, not runtime. If you use the same compiler with the same choice, you can get the same layout on different operating systems, use a different compiler on the same operating system or different operating systems, and there is no guarantee that the same same layout or if both use stack frame.

0
source

All Articles