X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=mono%2Futils%2Fmach-support-x86.c;h=76d2b06beef149fdee73ddc7c1977bc6c2f40d42;hb=2e34a838d380715565ada6d447a06d03d6874136;hp=e65fe6bdeefe05a40f603c9d482fedbb2baa8b04;hpb=4df4b7a47a07d924d7bfcfc53f43bd2319b54266;p=mono.git diff --git a/mono/utils/mach-support-x86.c b/mono/utils/mach-support-x86.c index e65fe6bdeef..76d2b06beef 100644 --- a/mono/utils/mach-support-x86.c +++ b/mono/utils/mach-support-x86.c @@ -16,6 +16,14 @@ #include "utils/mono-sigcontext.h" #include "mach-support.h" +/* Known offsets used for TLS storage*/ + +/* All OSX versions up to 10.8 */ +#define TLS_VECTOR_OFFSET_CATS 0x48 +#define TLS_VECTOR_OFFSET_10_9 0xb0 + +static int tls_vector_offset; + void * mono_mach_arch_get_ip (thread_state_t state) { @@ -85,11 +93,11 @@ void * mono_mach_get_tls_address_from_thread (pthread_t thread, pthread_key_t key) { /* OSX stores TLS values in a hidden array inside the pthread_t structure - * They are keyed off a giant array offset 0x48 into the pointer. This value + * 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 *p = (intptr_t *) thread; - intptr_t **tsd = (intptr_t **) ((char*)p + 0x48); + intptr_t **tsd = (intptr_t **) ((char*)p + tls_vector_offset); return (void *) &tsd [key]; } @@ -100,5 +108,29 @@ mono_mach_arch_get_tls_value_from_thread (pthread_t thread, guint32 key) return *(void**)mono_mach_get_tls_address_from_thread (thread, key); } +void +mono_mach_init (pthread_key_t key) +{ + void *old_value = pthread_getspecific (key); + void *canary = (void*)0xDEADBEEFu; + + pthread_key_create (&key, NULL); + g_assert (old_value != canary); + + pthread_setspecific (key, canary); + + /*First we probe for cats*/ + tls_vector_offset = TLS_VECTOR_OFFSET_CATS; + if (mono_mach_arch_get_tls_value_from_thread (pthread_self (), key) == canary) + goto ok; + + tls_vector_offset = TLS_VECTOR_OFFSET_10_9; + 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