/* Known offsets used for TLS storage*/
-/*Found on iOS 6 */
-#define TLS_VECTOR_OFFSET_0 0x48
-#define TLS_VECTOR_OFFSET_1 0xA8
+
+static const int known_tls_offsets[] = {
+ 0x48, /*Found on iOS 6 */
+ 0xA4,
+ 0xA8,
+};
+
+#define TLS_PROBE_COUNT (sizeof (known_tls_offsets) / sizeof (int))
static int tls_vector_offset;
void *
mono_mach_get_tls_address_from_thread (pthread_t thread, pthread_key_t key)
{
-#ifdef MONO_HAVE_FAST_TLS
/* Mach stores TLS values in a hidden array inside the pthread_t structure
* They are keyed off a giant array from a known offset into the pointer. This value
* is baked into their pthread_getspecific implementation
intptr_t **tsd = (intptr_t **) ((char*)p + tls_vector_offset);
return (void *) &tsd [key];
-#else
- g_error ("fast tls not supported on this target");
-#endif
}
void *
void
mono_mach_init (pthread_key_t key)
{
-#ifdef MONO_HAVE_FAST_TLS
+ int i;
void *old_value = pthread_getspecific (key);
void *canary = (void*)0xDEADBEEFu;
pthread_setspecific (key, canary);
/*First we probe for cats*/
- tls_vector_offset = TLS_VECTOR_OFFSET_0;
- if (mono_mach_arch_get_tls_value_from_thread (pthread_self (), key) == canary)
- goto ok;
-
- tls_vector_offset = TLS_VECTOR_OFFSET_1;
- if (mono_mach_arch_get_tls_value_from_thread (pthread_self (), key) == canary)
- goto ok;
+ for (i = 0; i < TLS_PROBE_COUNT; ++i) {
+ tls_vector_offset = known_tls_offsets [i];
+ if (mono_mach_arch_get_tls_value_from_thread (pthread_self (), key) == canary)
+ goto ok;
+ }
g_error ("could not discover the mach TLS offset");
ok:
pthread_setspecific (key, old_value);
-#endif
}
#endif