I was wondering if there's a function available from a Windows kernel driver that can unwind the stack to get (nested) function addresses that called the current function?
@UnmannedPlayer: I'm doing this from a kernel mode. Although RtlCaptureStackBackTrace seems to be the function to use. It is basically a wrapper for RtlWalkFrameChain that it calls repeatedly a requested number of counts.
@RbMm: There's one issue though with what you said about IRQL. If we follow documentation for RtlCaptureStackBackTrace it is <= DISPATCH_LEVEL, which as I said above, is the same as calling RtlWalkFrameChain without RTL_WALK_USER_MODE_STACK (1) flag. What makes you think that it can be called at any IRQL? I stepped into it and there's a lot of other function calls inside. It "walks" through various memory sections and loaded system images. There's no way all of them are loaded in a non-paged memory. There are also some locks that are being set up in some functions.
RtlWalkFrameChain
RtlCaptureStackBackTrace
seems to be the function to use. It is basically a wrapper forRtlWalkFrameChain
that it calls repeatedly a requested number of counts.RtlCaptureStackBackTrace
it is<= DISPATCH_LEVEL
, which as I said above, is the same as callingRtlWalkFrameChain
withoutRTL_WALK_USER_MODE_STACK (1)
flag. What makes you think that it can be called at any IRQL? I stepped into it and there's a lot of other function calls inside. It "walks" through various memory sections and loaded system images. There's no way all of them are loaded in a non-paged memory. There are also some locks that are being set up in some functions.