Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What are function epilogues and prologues?

While reading some calling convention in some CPU architecture I read something like

"epilogue and prologue", when a function is called from another function.

What is a function prologue or epilogue?

like image 701
Renjith G Avatar asked Jul 12 '10 18:07

Renjith G


2 Answers

The epilogue and prologue of a function are simply the set of instructions that 'set up' the context for the function when it's called and clean up when it returns.

The prologue typically performs such tasks as:

  • saves any registers that the function might use (that are required by the platform's standard to be preserved across function calls)
  • allocates storage on the stack that the function might require for local variables
  • sets up any pointer (or other linkage) to parameters that might be passed on the stack

The epilogue generally only needs to restore any save registers and restore the stack pointer such that any memory reserved by the function for its own use is 'freed'.

The exact mechanisms that might be used in a prologue/epilogue are Dependant on the CPU architecture, the platforms standard, the arguments and return values of the function, and the particular calling convention the function might be using.

like image 143
Michael Burr Avatar answered Sep 30 '22 09:09

Michael Burr


Wikipedia FTW: https://en.wikipedia.org/wiki/Function_prologue

This seemed to explain it fairly well, in my opinion. If there is anything that is unclear, let me know and I can try and clear things up.

like image 28
Adam Shiemke Avatar answered Sep 30 '22 11:09

Adam Shiemke