Keith Thompson wrote, On 05/08/08 16:10:
Well, the function itself must be able to get at the return address in
order to return to it, but that doesn't necessarily mean it's possible
to retrieve that address.
My assumption is that it's always possible, but I could well be
mistaken.
I know of one implementation where it is definitely *not* possible
without resort to assembler for all functions and there is not always an
easy way to determine if it is possible. The reason it is not always
possible is that the processor has an 8 deep HW stack for return
addresses which is *not* mapped in to any of the address spaces (it can
only be accessed by call, return, push and pop type assembler
instructions). The compiler will pop return addresses of the stack if
the function calls other functions *unless* it only calls functions from
the provided C library *and* it knows those functions will not cause the
HW stack to overflow. So if a function calls only library functions you
would have to either examine the generated code or determine what the
compiler knows about the library functions which are called to determine
whether the return address is on the HW stack or has been popped of the
HW stack on to the SW stack.
So I would say that on this particular implementation it is impossible
in general without resorting to assembler (as opposed to non-portable C
constructs).
Oh, and this is ignoring the possibility someone else raised that the
function might have been inlined, something that can cause problems with
the non-portable extension provided by at least one implementation for
this purpose
OK, now which of these stacks is *the* stack? ;-)