Info
This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Determining the address of the calling function (in extern C functions)?
Is it possible (maybe using x86-64 inline asm) to determine the address of the caller of a function? Obviously yes by doing a full stack walk, but that is expensive. I just need the address of the immediate caller. (Needless to say I'm doing incredibly low level things if I'm asking about this.)
In the interest of avoiding XY problem: I'm intercepting malloc/free/etc for a heap allocation profiler, and I'm getting recursion. No problem: just use a thread local to detect that. Except that the first time you allocate a thread local it can trigger an allocation (in glibc).
Possible ways to deal with this that I have considered:
I know it is possible via global asm or naked functions, but I would prefer to write as little assembler as possible. So can it be done in normal rust and/or via "normal" inline asm?
(If frame pointers are not omited it seems it should be possible to get the return address relative rbp
, but that won't work if the user compiles without frame pointers.)
8 posts - 2 participants
🏷️ Rust_feed