ftrace_graph_ret_addr(9)

πŸ“¦ version 7.3.1, in nixpkgs unstable

πŸ’… ftrace_graph_ret_addr(9) β€” or, how to un-glow-up a return address

okay bestie, welcome to the Kernel API Manual ✨ β€” yes, that manual, the one your kernel-dev mutuals keep quoting. today's episode: ftrace_graph_ret_addr, which returns the original value of the return address πŸŽ€. no cap, that's the whole NAME section, and it ate.


✨ SYNOPSIS ✨

unsigned long ftrace_graph_ret_addr (struct task_struct *task , int *idx
, unsigned long ret , unsigned long *retp );

that's the whole signature, copy it exactly, do not come for me about the comma spacing, that's how it is in the source πŸ’€


🌸 ARGUMENTS 🌸

  • task β€” the task the unwinder is being executed on 🧚 like, which poor little process are we walking the stack for
  • idx β€” an initialized pointer to the next stack index to use πŸ“ it's your lil bookmark, treat it right
  • ret β€” the current return address (likely pointing to return_handler) πŸ‘€ "likely" is doing a lot of work there, but slay
  • retp β€” the address on the stack of the current return location 🫢 like the home address, but for a return address

πŸ’– DESCRIPTION πŸ’–

okay so here's the tea β˜• β€” this function gets called by stack unwinding code, and its whole job is converting a found stack return address (ret) back to its original value πŸ”₯. why? because the function graph tracer might have modified it to be 'return_to_handler' 😭 so the address you found is giving fake identity energy and needs a reality check.

if the address hasn't been modified? iconic. the unchanged value of ret is returned, no drama, no notes πŸ’…

now, idx is the main character here πŸ‘‘ β€” it holds the last index used to know where to start from. it should be initialized to zero for the first iteration, because zero means "start at the top of the shadow stack" ⭐. and if the location is found, this pointer gets assigned that location, so that if you call again it'll just continue where it left off 🎯 lowkey efficient, highkey the way that it should be.

and retp? retp is a pointer to the return address on the stack 🌈 simple, honest, doing its job.

ngl, if you're passing in an uninitialized idx on the first iteration, that's not a vibe β€” zero, bestie, zero 🫠

πŸ‘‘ SEE ALSO πŸ‘‘

your reading list, fr fr, all of it, go off:


πŸŽ€ sign-off πŸŽ€

this whole little masterpiece lives in ./kernel/trace πŸ’œ and it's dated October 2026 ⭐ β€” yes, the future, she's ahead of her time. mwah, go read the source, ily, bye πŸ¦‹πŸ’–

πŸ“¦ where this page comes from