This article may need to be rewritten to comply with Wikipedia's quality standards. You can help. The talk page may contain suggestions. (June 2009)

In computer programming, the word trampoline has a number of meanings, and is generally associated with jumps (i.e., moving to different code paths).

Low-level programming

Trampolines (sometimes referred to as indirect jump vectors) are memory locations holding addresses pointing to interrupt service routines, I/O routines, etc. Execution jumps into the trampoline and then immediately jumps out, or bounces, hence the term trampoline. They have many uses:

High-level programming

Continuation-passing style is a popular intermediate format for compilers of function languages, because many control flow constructs can be elegantly expressed and tail call optimization is easy. When compiling to a language without optimized tail calls, one can avoid stack growth via a technique called trampolining. The idea is to not make the final continuation call inside the function, but to exit and to return the continuation to a trampoline. That trampoline is simply a loop that invokes the returned continuations. Hence, there are no nested function calls and the stack won’t grow.[2]

No-execute stacks

Some implementations of trampolines cause a loss of no-execute stacks (NX stack). In the GNU Compiler Collection (GCC) in particular, a nested function builds a trampoline on the stack at runtime, and then calls the nested function through the data on stack. The trampoline requires the stack to be executable.

No execute stacks and nested functions are mutually exclusive under GCC. If a nested function is used in the development of a program, then the NX stack is silently lost. GCC offers the -Wtrampoline warning to alert of the condition.

Software engineered using secure development lifecycle often do not allow the use of nested functions due to the loss of NX stacks.[11]

See also

References

  1. ^ Baker, Henry G. (September 1995). "CONS Should Not CONS Its Arguments, Part II: Cheney on the M.T.A." ACM SIGPLAN Notices. 30 (9): 17–20. doi:10.1145/214448.214454. Archived from the original on 2016-11-11.
  2. ^ Asynchronous programming and continuation-passing style in JavaScript - 2ality
  3. ^ a b Muller, Hans (2005-01-31). "Asserting Control Over the GUI: Commands, Defaults, and Resource Bundles". today.java.net. Trampolines. Retrieved 2015-11-06.((cite web)): CS1 maint: url-status (link) [1]
  4. ^ Stangvik, Einar Otto (2006-08-16). "Thunking in Win32 with C++". Archived from the original on 2012-10-15.
  5. ^ Weiher, Marcel (2004). "Higher Order Messaging (HOM)" (PDF). Archived (PDF) from the original on 2018-05-26. Retrieved 2018-05-26. ((cite web)): |archive-date= / |archive-url= timestamp mismatch; 2018-05-27 suggested (help)
  6. ^ fuz (2011-11-18). "Implementation of nested functions". StackOverflow. Archived from the original on 2016-03-29. Retrieved 2018-05-26.
  7. ^ "Trampolines for Nested Functions". Using the GNU Compiler Collection (GCC). 2018 [2002]. 18.11. Archived from the original on 2018-05-27. Retrieved 2018-05-26.
  8. ^ "Nested functions". Using the GNU Compiler Collection (GCC). 2018 [2002]. 6.4. Archived from the original on 2018-05-27. Retrieved 2018-05-26.
  9. ^ Breuel, Thomas M. (2013). "Lexical Closures for C++" (PDF). Archived (PDF) from the original on 2017-12-12. Retrieved 2018-05-26.
  10. ^ Walton, Jeffrey; Manico, Jim; Wall, Kevin (2018-03-02) [2013]. "C-Based Toolchain Hardening". The Open Web Application Security Project (OWASP). Archived from the original on 2018-05-27. Retrieved 2018-03-02.