I have a very compute-intensive module in which I've added stack-tracing to be able to find specific problems. Although the application is allowed to run slower when this stack-tracing is enabled, it must not run 10 times slower. That's why I am not using the StackWalk routines from DBGHELP.DLL, but I walk the stack myself using the frame pointers (so I don't use the Frame Pointer Omission compiler option).
In most cases, getting the call stack works correctly and is very fast, but in some cases, my logic fails because one of the frame pointers points to an address outside the stack (not much, just a little bit).
I know that this is probably an error somewhere, but to be able to make my code safer, I need a way to check whether a frame-pointer points to a memory location within the stack of the current thread or not. The application is 64-bit and runs under Windows.
The code at How to get thread stack information on Windows? probably solves the problem, but since this calls other functions, it probably makes my code run much slower (to be honest, I didn't test it).
I also found some inline assembly code that should perform the trick (http://nasutechtips.blogspot.com/2011/01/thread-information-block-tib-and-fs.html), but inline assembly isn't supported by Microsoft's 64-bit C++ compiler.
Also the intrinsic __readfsqword doesn't seem to work on 64-bit.
Any other suggestions on how to get the TIB on 64-bit as fast as possible?