Skip to content

Commit 47d8ed4

Browse files
committed
xplat: cache thread stack limit
1 parent f7e94b3 commit 47d8ed4

File tree

1 file changed

+28
-6
lines changed

1 file changed

+28
-6
lines changed

pal/src/thread/pal_thread.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,8 +2834,28 @@ int CorUnix::CThreadMachExceptionHandlers::GetIndexOfHandler(exception_mask_t bm
28342834

28352835
#endif // HAVE_MACH_EXCEPTIONS
28362836

2837+
#ifndef __APPLE__
2838+
#define THREAD_LOCAL thread_local
2839+
#else
2840+
#define THREAD_LOCAL _Thread_local
2841+
#endif
2842+
2843+
#ifndef __IOS__
2844+
static THREAD_LOCAL ULONG_PTR s_cachedThreadStackHighLimit = 0;
2845+
static THREAD_LOCAL ULONG_PTR highLimit_cache = 0;
2846+
static THREAD_LOCAL ULONG_PTR lowLimit_cache = 0;
2847+
#endif
2848+
28372849
void GetCurrentThreadStackLimits(ULONG_PTR* lowLimit, ULONG_PTR* highLimit)
28382850
{
2851+
#ifndef __IOS__
2852+
if (lowLimit_cache)
2853+
{
2854+
*lowLimit = lowLimit_cache;
2855+
*highLimit = highLimit_cache;
2856+
return;
2857+
}
2858+
#endif
28392859
pthread_t currentThreadHandle = pthread_self();
28402860

28412861
#ifdef __APPLE__
@@ -2866,14 +2886,12 @@ void GetCurrentThreadStackLimits(ULONG_PTR* lowLimit, ULONG_PTR* highLimit)
28662886
*lowLimit = (ULONG_PTR) stackend;
28672887
*highLimit = (ULONG_PTR) stackbase;
28682888
#endif
2869-
}
28702889

2871-
#ifndef __APPLE__
2872-
#define THREAD_LOCAL thread_local
2873-
#else
2874-
#define THREAD_LOCAL _Thread_local
2890+
#ifndef __IOS__
2891+
lowLimit_cache = *lowLimit;
2892+
highLimit_cache = *highLimit;
28752893
#endif
2876-
static THREAD_LOCAL ULONG_PTR s_cachedThreadStackHighLimit = 0;
2894+
}
28772895

28782896
bool IsAddressOnStack(ULONG_PTR address)
28792897
{
@@ -2882,13 +2900,17 @@ bool IsAddressOnStack(ULONG_PTR address)
28822900
// bounds to speed up checking if a given address is on the stack
28832901
// The semantics of IsAddressOnStack is that we care if a given address is
28842902
// in the range of the current stack pointer
2903+
#ifndef __IOS__
28852904
if (s_cachedThreadStackHighLimit == 0)
28862905
{
2906+
#endif
28872907
ULONG_PTR lowLimit, highLimit;
28882908
GetCurrentThreadStackLimits(&lowLimit, &highLimit);
28892909

2910+
#ifndef __IOS__
28902911
s_cachedThreadStackHighLimit = highLimit;
28912912
}
2913+
#endif
28922914

28932915
ULONG_PTR currentStackPtr = GetCurrentSP();
28942916

0 commit comments

Comments
 (0)