Can I get the limits of the stack in C / C++?

前端 未结 3 917
时光说笑
时光说笑 2021-02-12 08:10

My question is pretty simple and straightforward: if I have e.g. 1MB of RAM assigned to the program\'s stack, can I get the addresses of the start and the end, or the start and

3条回答
  •  忘掉有多难
    2021-02-12 08:45

    On Windows before 8, implement GetCurrentThreadStackLimits() yourself:

    #include 
    #if _WIN32_WINNT < 0x0602
    VOID WINAPI GetCurrentThreadStackLimits(LPVOID *StackLimit, LPVOID *StackBase)
    {
        NT_TIB *tib = (NT_TIB *) NtCurrentTeb();
        *StackLimit = tib->StackLimit;
        *StackBase = tib->StackBase;
    }
    #endif
    

提交回复
热议问题