diff --git a/src/mono/mono/mini/mini-runtime.c b/src/mono/mono/mini/mini-runtime.c index 0c67814f12613..a7383e612845d 100644 --- a/src/mono/mono/mini/mini-runtime.c +++ b/src/mono/mono/mini/mini-runtime.c @@ -691,7 +691,7 @@ register_dyn_icall (gpointer func, const char *name, const char *sigstr, gboolea MonoLMF * mono_get_lmf (void) { -#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) +#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR) return (MonoLMF *)mono_tls_get_lmf (); #else MonoJitTlsData *jit_tls; @@ -716,11 +716,11 @@ mono_get_lmf_addr (void) void mono_set_lmf (MonoLMF *lmf) { -#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) +#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR) mono_tls_set_lmf (lmf); -#endif - +#else (*mono_get_lmf_addr ()) = lmf; +#endif } MonoJitTlsData* @@ -852,7 +852,15 @@ setup_jit_tls_data (gpointer stack_start, gpointer abort_func) jit_tls->first_lmf = lmf; -#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) + /* + * We can have 2 configurations for accessing lmf. + * We can use only the tls_lmf_addr variable, which will store the address of + * jit_tls->lmf, or, if we have MONO_ARCH_ENABLE_MONO_LMF_VAR enabled, we can + * use both tls_lmf_addr and tls_lmf variables (in this case we need to have + * means of getting the address of a tls variable; this can be done always + * when using __thread or, on osx, even when using pthread) + */ +#if defined(MONO_ARCH_ENABLE_MONO_LMF_VAR) && defined(HAVE_GET_TLS_ADDR) /* jit_tls->lmf is unused */ mono_tls_set_lmf (lmf); mono_set_lmf_addr (mono_tls_get_tls_addr (TLS_KEY_LMF)); diff --git a/src/mono/mono/utils/mono-tls.c b/src/mono/mono/utils/mono-tls.c index 765011dbfe81a..186e1d5c551b4 100644 --- a/src/mono/mono/utils/mono-tls.c +++ b/src/mono/mono/utils/mono-tls.c @@ -7,7 +7,6 @@ * Copyright 2013 Xamarin, Inc (http://www.xamarin.com) */ -#include #include #include "mono-tls.h" @@ -34,9 +33,6 @@ * wrappers and managed allocators, both of which are not aot-ed by default. * So far, we never supported inlined fast tls on full-aot systems. */ -#ifdef HAVE_KW_THREAD -#define USE_KW_THREAD -#endif #ifdef USE_KW_THREAD @@ -270,6 +266,7 @@ mono_tls_get_tls_setter (MonoTlsKey key, gboolean name) gpointer mono_tls_get_tls_addr (MonoTlsKey key) { +#ifdef HAVE_GET_TLS_ADDR if (key == TLS_KEY_LMF) { #if defined(USE_KW_THREAD) return &mono_tls_lmf; @@ -277,6 +274,7 @@ mono_tls_get_tls_addr (MonoTlsKey key) return mono_mach_get_tls_address_from_thread (pthread_self (), mono_tls_key_lmf); #endif } +#endif /* Implement if we ever need for other targets/keys */ g_assert_not_reached (); return NULL; diff --git a/src/mono/mono/utils/mono-tls.h b/src/mono/mono/utils/mono-tls.h index 8cccc2875599a..a3751ea6e38b7 100644 --- a/src/mono/mono/utils/mono-tls.h +++ b/src/mono/mono/utils/mono-tls.h @@ -12,6 +12,7 @@ #ifndef __MONO_TLS_H__ #define __MONO_TLS_H__ +#include #include /* TLS entries used by the runtime */ @@ -27,6 +28,17 @@ typedef enum { TLS_KEY_NUM = 6 } MonoTlsKey; +#ifdef HAVE_KW_THREAD +#define USE_KW_THREAD +#endif + +#if defined(USE_KW_THREAD) +#define HAVE_GET_TLS_ADDR +#elif defined(TARGET_MACH) && (defined(TARGET_X86) || defined(TARGET_AMD64)) +/* mono_mach_get_tls_address_from_thread is untested for arm/arm64 */ +#define HAVE_GET_TLS_ADDR +#endif + #ifdef HOST_WIN32 #include