@@ -2834,8 +2834,27 @@ 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_cachedHighLimit = 0 ;
2845+ static THREAD_LOCAL ULONG_PTR s_cachedLowLimit = 0 ;
2846+ #endif
2847+
28372848void GetCurrentThreadStackLimits (ULONG_PTR* lowLimit, ULONG_PTR* highLimit)
28382849{
2850+ #ifndef __IOS__
2851+ if (s_cachedLowLimit)
2852+ {
2853+ *lowLimit = s_cachedLowLimit;
2854+ *highLimit = s_cachedHighLimit;
2855+ return ;
2856+ }
2857+ #endif
28392858 pthread_t currentThreadHandle = pthread_self ();
28402859
28412860#ifdef __APPLE__
@@ -2866,14 +2885,12 @@ void GetCurrentThreadStackLimits(ULONG_PTR* lowLimit, ULONG_PTR* highLimit)
28662885 *lowLimit = (ULONG_PTR) stackend;
28672886 *highLimit = (ULONG_PTR) stackbase;
28682887#endif
2869- }
28702888
2871- #ifndef __APPLE__
2872- #define THREAD_LOCAL thread_local
2873- #else
2874- #define THREAD_LOCAL _Thread_local
2889+ #ifndef __IOS__
2890+ s_cachedLowLimit = *lowLimit;
2891+ s_cachedHighLimit = *highLimit;
28752892#endif
2876- static THREAD_LOCAL ULONG_PTR s_cachedThreadStackHighLimit = 0 ;
2893+ }
28772894
28782895bool IsAddressOnStack (ULONG_PTR address)
28792896{
@@ -2882,17 +2899,12 @@ bool IsAddressOnStack(ULONG_PTR address)
28822899 // bounds to speed up checking if a given address is on the stack
28832900 // The semantics of IsAddressOnStack is that we care if a given address is
28842901 // in the range of the current stack pointer
2885- if (s_cachedThreadStackHighLimit == 0 )
2886- {
2887- ULONG_PTR lowLimit, highLimit;
2888- GetCurrentThreadStackLimits (&lowLimit, &highLimit);
2889-
2890- s_cachedThreadStackHighLimit = highLimit;
2891- }
2902+ ULONG_PTR lowLimit, highLimit;
2903+ GetCurrentThreadStackLimits (&lowLimit, &highLimit);
28922904
28932905 ULONG_PTR currentStackPtr = GetCurrentSP ();
28942906
2895- if (currentStackPtr <= address && address < s_cachedThreadStackHighLimit )
2907+ if (currentStackPtr <= address && address < highLimit )
28962908 {
28972909 return true ;
28982910 }
0 commit comments