Fastest way to get the TID (Thread Information Block) in a 64-bit Windows application?

前端 未结 2 1319
予麋鹿
予麋鹿 2021-01-15 11:22

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

相关标签:
2条回答
  • 2021-01-15 11:36

    Found it, the following code does the trick:

    #include <windows.h>
    #include <winnt.h>
    
    struct _TEB
       {
       NT_TIB NtTib;
       // Ignore rest of struct
       };
    
    void *startOfStack;
    startOfStack = NtCurrentTeb()->NtTib.StackBase;
    std::cout << "startOfStack = " << startOfStack << std::endl;
    

    I looked to the definition of NtCurrentTeb() in winnt.h and it looks like this is a very low level function, so it will probably be fast enough to get what I want.

    0 讨论(0)
  • 2021-01-15 11:46

    it should be __readgsqword instead of __readfsqword on 64-bit.

    0 讨论(0)
提交回复
热议问题