MCPcopy Create free account
hub / github.com/beefytech/Beef / BfpThreadInfo_GetStackInfo

Function BfpThreadInfo_GetStackInfo

BeefySysLib/platform/win/Platform.cpp:2551–2580  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2549static __declspec(thread) BfpThreadInfo gThreadStackInfo;
2550
2551BFP_EXPORT void BFP_CALLTYPE BfpThreadInfo_GetStackInfo(BfpThreadInfo* threadInfo, intptr* outStackBase, int* outStackLimit, BfpThreadInfoFlags flags, BfpThreadResult* outResult)
2552{
2553 if (threadInfo == NULL)
2554 {
2555 threadInfo = &gThreadStackInfo;
2556 if (threadInfo->mTeb == NULL)
2557 threadInfo->mTeb = (NT_TIB*)NtCurrentTeb();
2558 }
2559
2560 if ((threadInfo->mStackBase == 0) || ((flags & BfpThreadInfoFlags_NoCache) != 0))
2561 {
2562 MEMORY_BASIC_INFORMATION stackInfo = { 0 };
2563 // We subtract one page for our request. VirtualQuery rounds UP to the next page.
2564 // Unfortunately, the stack grows down. If we're on the first page (last page in the
2565 // VirtualAlloc), we'll be moved to the next page, which is off the stack! Note this
2566 // doesn't work right for IA64 due to bigger pages.
2567 void* currentAddr = (void*)((intptr_t)&stackInfo - 4096);
2568
2569 // Query for the current stack allocation information.
2570 VirtualQuery(currentAddr, &stackInfo, sizeof(MEMORY_BASIC_INFORMATION));
2571
2572 threadInfo->mStackBase = (uintptr_t)threadInfo->mTeb->StackBase;
2573 threadInfo->mStackLimit = (uintptr_t)stackInfo.AllocationBase;
2574 }
2575
2576 *outStackBase = (intptr)threadInfo->mStackBase;
2577 *outStackLimit = (int)(threadInfo->mStackBase - threadInfo->mStackLimit);
2578 OUTRESULT(BfpThreadResult_Ok);
2579 return;
2580}
2581
2582///
2583

Callers 2

CanStackExpandMethod · 0.50
CalcStackStartMethod · 0.50

Calls

no outgoing calls

Tested by

no test coverage detected