extern gpointer GetCurrentThread(void);
extern guint32 ResumeThread(gpointer handle);
extern guint32 SuspendThread(gpointer handle);
-extern guint32 mono_pthread_key_for_tls (guint32 idx);
-extern guint32 TlsAlloc(void);
-extern gboolean TlsFree(guint32 idx);
-extern gpointer TlsGetValue(guint32 idx);
-extern gboolean TlsSetValue(guint32 idx, gpointer value);
extern void Sleep(guint32 ms);
extern guint32 SleepEx(guint32 ms, gboolean alertable);
extern guint32 QueueUserAPC (WapiApcProc apc_callback, gpointer thread_handle,
#endif
#undef DEBUG
-#undef TLS_DEBUG
#if 0
#define WAIT_DEBUG(code) do { code } while (0)
return(0xFFFFFFFF);
}
-/*
- * We assume here that TLS_MINIMUM_AVAILABLE is less than
- * PTHREAD_KEYS_MAX, allowing enough overhead for a few TLS keys for
- * library usage.
- *
- * Currently TLS_MINIMUM_AVAILABLE is 64 and _POSIX_THREAD_KEYS_MAX
- * (the minimum value for PTHREAD_KEYS_MAX) is 128, so we should be
- * fine.
- */
-
-static pthread_key_t TLS_keys[TLS_MINIMUM_AVAILABLE];
-static gboolean TLS_used[TLS_MINIMUM_AVAILABLE]={FALSE};
-static pthread_mutex_t TLS_mutex = PTHREAD_MUTEX_INITIALIZER;
-
-guint32
-mono_pthread_key_for_tls (guint32 idx)
-{
- return (guint32)TLS_keys [idx];
-}
-
-/**
- * TlsAlloc:
- *
- * Allocates a Thread Local Storage (TLS) index. Any thread in the
- * same process can use this index to store and retrieve values that
- * are local to that thread.
- *
- * Return value: The index value, or %TLS_OUT_OF_INDEXES if no index
- * is available.
- */
-guint32 TlsAlloc(void)
-{
- guint32 i;
- int thr_ret;
-
- pthread_mutex_lock (&TLS_mutex);
-
- for(i=0; i<TLS_MINIMUM_AVAILABLE; i++) {
- if(TLS_used[i]==FALSE) {
- TLS_used[i]=TRUE;
- thr_ret = pthread_key_create(&TLS_keys[i], NULL);
- g_assert (thr_ret == 0);
-
- pthread_mutex_unlock (&TLS_mutex);
-
-#ifdef TLS_DEBUG
- g_message ("%s: returning key %d", __func__, i);
-#endif
-
- return(i);
- }
- }
-
- pthread_mutex_unlock (&TLS_mutex);
-
-#ifdef TLS_DEBUG
- g_message ("%s: out of indices", __func__);
-#endif
-
-
- return(TLS_OUT_OF_INDEXES);
-}
-
-#define MAKE_GC_ID(idx) (GUINT_TO_POINTER((idx)|(GetCurrentThreadId()<<8)))
-
-/**
- * TlsFree:
- * @idx: The TLS index to free
- *
- * Releases a TLS index, making it available for reuse. This call
- * will delete any TLS data stored under index @idx in all threads.
- *
- * Return value: %TRUE on success, %FALSE otherwise.
- */
-gboolean TlsFree(guint32 idx)
-{
- int thr_ret;
-
-#ifdef TLS_DEBUG
- g_message ("%s: freeing key %d", __func__, idx);
-#endif
-
- if (idx >= TLS_MINIMUM_AVAILABLE) {
- SetLastError (ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- pthread_mutex_lock (&TLS_mutex);
-
- if(TLS_used[idx]==FALSE) {
- pthread_mutex_unlock (&TLS_mutex);
- SetLastError (ERROR_INVALID_PARAMETER);
- return(FALSE);
- }
-
- TLS_used[idx]=FALSE;
- thr_ret = pthread_key_delete(TLS_keys[idx]);
- g_assert (thr_ret == 0);
-
- pthread_mutex_unlock (&TLS_mutex);
-
- return(TRUE);
-}
-
-/**
- * TlsGetValue:
- * @idx: The TLS index to retrieve
- *
- * Retrieves the TLS data stored under index @idx.
- *
- * Return value: The value stored in the TLS index @idx in the current
- * thread, or %NULL on error. As %NULL can be a valid return value,
- * in this case GetLastError() returns %ERROR_SUCCESS.
- */
-gpointer TlsGetValue(guint32 idx)
-{
- gpointer ret;
-
-#ifdef TLS_DEBUG
- g_message ("%s: looking up key %d", __func__, idx);
-#endif
- if (idx >= TLS_MINIMUM_AVAILABLE) {
- SetLastError (ERROR_INVALID_PARAMETER);
- return NULL;
- }
- ret=pthread_getspecific(TLS_keys[idx]);
-
-#ifdef TLS_DEBUG
- g_message ("%s: returning %p", __func__, ret);
-#endif
-
- SetLastError (ERROR_SUCCESS);
- return(ret);
-}
-
-/**
- * TlsSetValue:
- * @idx: The TLS index to store
- * @value: The value to store under index @idx
- *
- * Stores @value at TLS index @idx.
- *
- * Return value: %TRUE on success, %FALSE otherwise.
- */
-gboolean TlsSetValue(guint32 idx, gpointer value)
-{
- int ret;
-
-#ifdef TLS_DEBUG
- g_message ("%s: setting key %d to %p", __func__, idx, value);
-#endif
- if (idx >= TLS_MINIMUM_AVAILABLE) {
- SetLastError (ERROR_INVALID_PARAMETER);
- return FALSE;
- }
-
- ret=pthread_setspecific(TLS_keys[idx], value);
-#ifdef TLS_DEBUG
- if(ret!=0)
- g_message ("%s: pthread_setspecific error: %s", __func__,
- strerror (ret));
-#endif
-
- return(ret == 0);
-}
-
/**
* SleepEx:
* @ms: The time in milliseconds to suspend for
#include <mono/utils/mono-membar.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/hazard-pointer.h>
+#include <mono/utils/mono-tls.h>
#include <mono/metadata/object.h>
#include <mono/metadata/object-internals.h>
#include <mono/metadata/domain-internals.h>
* or the other (we used to do it because tls slots were GC-tracked,
* but we can't depend on this).
*/
-static guint32 appdomain_thread_id = -1;
+static MonoNativeTlsKey appdomain_thread_id;
/*
* Avoid calling TlsSetValue () if possible, since in the io-layer, it acquires
#else
#define SET_APPDOMAIN(x) do { \
MONO_FAST_TLS_SET (tls_appdomain,x); \
- TlsSetValue (appdomain_thread_id, x); \
+ mono_native_tls_set_value (appdomain_thread_id, x); \
} while (FALSE)
#endif
#else /* !MONO_HAVE_FAST_TLS */
-#define GET_APPDOMAIN() ((MonoDomain *)TlsGetValue (appdomain_thread_id))
-#define SET_APPDOMAIN(x) TlsSetValue (appdomain_thread_id, x);
+#define GET_APPDOMAIN() ((MonoDomain *)mono_native_tls_get_value (appdomain_thread_id))
+#define SET_APPDOMAIN(x) mono_native_tls_set_value (appdomain_thread_id, x);
#endif
static MonoImage*
mono_jit_info_find_aot_module (guint8* addr);
-guint32
+MonoNativeTlsKey
mono_domain_get_tls_key (void)
{
return appdomain_thread_id;
mono_gc_base_init ();
MONO_FAST_TLS_INIT (tls_appdomain);
- appdomain_thread_id = TlsAlloc ();
+ mono_native_tls_alloc (appdomain_thread_id, NULL);
InitializeCriticalSection (&appdomains_mutex);
mono_debug_cleanup ();
mono_metadata_cleanup ();
- TlsFree (appdomain_thread_id);
+ mono_native_tls_free (appdomain_thread_id);
DeleteCriticalSection (&appdomains_mutex);
- /*
- * This should be called last as TlsGetValue ()/TlsSetValue () can be called during
- * shutdown.
- */
#ifndef HOST_WIN32
_wapi_cleanup ();
#endif
#include <mono/utils/mono-membar.h>
#include <mono/utils/mono-counters.h>
#include <mono/utils/mono-error-internals.h>
+#include <mono/utils/mono-tls.h>
MonoDefaults mono_defaults;
/*
* This TLS variable contains the last type load error encountered by the loader.
*/
-guint32 loader_error_thread_id;
+MonoNativeTlsKey loader_error_thread_id;
/*
* This TLS variable holds how many times the current thread has acquired the loader
* lock.
*/
-guint32 loader_lock_nest_id;
+MonoNativeTlsKey loader_lock_nest_id;
static void dllmap_cleanup (void);
InitializeCriticalSection (&loader_mutex);
loader_lock_inited = TRUE;
- loader_error_thread_id = TlsAlloc ();
- loader_lock_nest_id = TlsAlloc ();
+ mono_native_tls_alloc (loader_error_thread_id, NULL);
+ mono_native_tls_alloc (loader_lock_nest_id, NULL);
mono_counters_register ("Inflated signatures size",
MONO_COUNTER_GENERICS | MONO_COUNTER_INT, &inflated_signatures_size);
{
dllmap_cleanup ();
- TlsFree (loader_error_thread_id);
- TlsFree (loader_lock_nest_id);
+ mono_native_tls_free (loader_error_thread_id);
+ mono_native_tls_free (loader_lock_nest_id);
DeleteCriticalSection (&loader_mutex);
loader_lock_inited = FALSE;
static void
set_loader_error (MonoLoaderError *error)
{
- TlsSetValue (loader_error_thread_id, error);
+ mono_native_tls_set_value (loader_error_thread_id, error);
}
/**
MonoLoaderError*
mono_loader_get_last_error (void)
{
- return (MonoLoaderError*)TlsGetValue (loader_error_thread_id);
+ return (MonoLoaderError*)mono_native_tls_get_value (loader_error_thread_id);
}
/**
void
mono_loader_clear_error (void)
{
- MonoLoaderError *ex = (MonoLoaderError*)TlsGetValue (loader_error_thread_id);
+ MonoLoaderError *ex = (MonoLoaderError*)mono_native_tls_get_value (loader_error_thread_id);
if (ex) {
g_free (ex->class_name);
g_free (ex->assembly_name);
g_free (ex->msg);
g_free (ex);
-
- TlsSetValue (loader_error_thread_id, NULL);
+
+ mono_native_tls_set_value (loader_error_thread_id, NULL);
}
}
{
mono_locks_acquire (&loader_mutex, LoaderLock);
if (G_UNLIKELY (loader_lock_track_ownership)) {
- TlsSetValue (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (TlsGetValue (loader_lock_nest_id)) + 1));
+ mono_native_tls_set_value (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (mono_native_tls_get_value (loader_lock_nest_id)) + 1));
}
}
{
mono_locks_release (&loader_mutex, LoaderLock);
if (G_UNLIKELY (loader_lock_track_ownership)) {
- TlsSetValue (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (TlsGetValue (loader_lock_nest_id)) - 1));
+ mono_native_tls_set_value (loader_lock_nest_id, GUINT_TO_POINTER (GPOINTER_TO_UINT (mono_native_tls_get_value (loader_lock_nest_id)) - 1));
}
}
{
g_assert (loader_lock_track_ownership);
- return GPOINTER_TO_UINT (TlsGetValue (loader_lock_nest_id)) > 0;
+ return GPOINTER_TO_UINT (mono_native_tls_get_value (loader_lock_nest_id)) > 0;
}
/*
#include "mono/metadata/gc-internal.h"
#include "mono/metadata/cominterop.h"
#include "mono/utils/mono-counters.h"
+#include "mono/utils/mono-tls.h"
#include <string.h>
#include <errno.h>
static CRITICAL_SECTION marshal_mutex;
static gboolean marshal_mutex_initialized;
-static guint32 last_error_tls_id;
+static MonoNativeTlsKey last_error_tls_id;
-static guint32 load_type_info_tls_id;
+static MonoNativeTlsKey load_type_info_tls_id;
static void
delegate_hash_table_add (MonoDelegate *d);
module_initialized = TRUE;
InitializeCriticalSection (&marshal_mutex);
marshal_mutex_initialized = TRUE;
- last_error_tls_id = TlsAlloc ();
- load_type_info_tls_id = TlsAlloc ();
+ mono_native_tls_alloc (last_error_tls_id, NULL);
+ mono_native_tls_alloc (load_type_info_tls_id, NULL);
register_icall (ves_icall_System_Threading_Thread_ResetAbort, "ves_icall_System_Threading_Thread_ResetAbort", "void", TRUE);
register_icall (mono_marshal_string_to_utf16, "mono_marshal_string_to_utf16", "ptr obj", FALSE);
{
mono_cominterop_cleanup ();
- TlsFree (load_type_info_tls_id);
- TlsFree (last_error_tls_id);
+ mono_native_tls_free (load_type_info_tls_id);
+ mono_native_tls_free (last_error_tls_id);
DeleteCriticalSection (&marshal_mutex);
marshal_mutex_initialized = FALSE;
}
mono_marshal_set_last_error (void)
{
#ifdef WIN32
- TlsSetValue (last_error_tls_id, GINT_TO_POINTER (GetLastError ()));
+ mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (GetLastError ()));
#else
- TlsSetValue (last_error_tls_id, GINT_TO_POINTER (errno));
+ mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (errno));
#endif
}
mono_marshal_set_last_error_windows (int error)
{
#ifdef WIN32
- TlsSetValue (last_error_tls_id, GINT_TO_POINTER (error));
+ mono_native_tls_set_value (last_error_tls_id, GINT_TO_POINTER (error));
#endif
}
{
MONO_ARCH_SAVE_REGS;
- return (GPOINTER_TO_INT (TlsGetValue (last_error_tls_id)));
+ return (GPOINTER_TO_INT (mono_native_tls_get_value (last_error_tls_id)));
}
guint32
static gboolean
mono_marshal_is_loading_type_info (MonoClass *klass)
{
- GSList *loads_list = TlsGetValue (load_type_info_tls_id);
+ GSList *loads_list = mono_native_tls_get_value (load_type_info_tls_id);
return g_slist_find (loads_list, klass) != NULL;
}
* under initialization in a TLS list.
*/
g_assert (!mono_marshal_is_loading_type_info (klass));
- loads_list = TlsGetValue (load_type_info_tls_id);
+ loads_list = mono_native_tls_get_value (load_type_info_tls_id);
loads_list = g_slist_prepend (loads_list, klass);
- TlsSetValue (load_type_info_tls_id, loads_list);
+ mono_native_tls_set_value (load_type_info_tls_id, loads_list);
iter = NULL;
while ((field = mono_class_get_fields (klass, &iter))) {
mono_marshal_load_type_info (klass->element_class);
}
- loads_list = TlsGetValue (load_type_info_tls_id);
+ loads_list = mono_native_tls_get_value (load_type_info_tls_id);
loads_list = g_slist_remove (loads_list, klass);
- TlsSetValue (load_type_info_tls_id, loads_list);
+ mono_native_tls_set_value (load_type_info_tls_id, loads_list);
/*We do double-checking locking on marshal_info */
mono_memory_barrier ();
#include <mono/metadata/object.h>
#include <mono/metadata/mono-wsq.h>
#include <mono/utils/mono-semaphore.h>
+#include <mono/utils/mono-tls.h>
#define INITIAL_LENGTH 32
#define WSQ_DEBUG(...)
};
#define NO_KEY ((guint32) -1)
-static guint32 wsq_tlskey = NO_KEY;
+static MonoNativeTlsKey wsq_tlskey;
+static gboolean wsq_tlskey_inited = FALSE;
void
mono_wsq_init ()
{
- wsq_tlskey = TlsAlloc ();
+ mono_native_tls_alloc (wsq_tlskey, NULL);
}
void
mono_wsq_cleanup ()
{
- if (wsq_tlskey == NO_KEY)
+ if (!wsq_tlskey_inited)
return;
- TlsFree (wsq_tlskey);
- wsq_tlskey = NO_KEY;
+ mono_native_tls_free (wsq_tlskey);
+ wsq_tlskey_inited = FALSE;
}
MonoWSQ *
MonoWSQ *wsq;
MonoDomain *root;
- if (wsq_tlskey == NO_KEY)
+ if (!wsq_tlskey_inited)
return NULL;
wsq = g_new0 (MonoWSQ, 1);
root = mono_get_root_domain ();
wsq->queue = mono_array_new_cached (root, mono_defaults.object_class, INITIAL_LENGTH);
MONO_SEM_INIT (&wsq->lock, 1);
- if (!TlsSetValue (wsq_tlskey, wsq)) {
+ if (!mono_native_tls_set_value (wsq_tlskey, wsq)) {
mono_wsq_destroy (wsq);
wsq = NULL;
}
MONO_GC_UNREGISTER_ROOT (wsq->queue);
MONO_SEM_DESTROY (&wsq->lock);
memset (wsq, 0, sizeof (MonoWSQ));
- if (wsq_tlskey != NO_KEY && TlsGetValue (wsq_tlskey) == wsq)
- TlsSetValue (wsq_tlskey, NULL);
+ if (wsq_tlskey_inited && mono_native_tls_get_value (wsq_tlskey) == wsq)
+ mono_native_tls_set_value (wsq_tlskey, NULL);
g_free (wsq);
}
int count;
MonoWSQ *wsq;
- if (obj == NULL || wsq_tlskey == NO_KEY)
+ if (obj == NULL || !wsq_tlskey_inited)
return FALSE;
- wsq = (MonoWSQ *) TlsGetValue (wsq_tlskey);
+ wsq = (MonoWSQ *) mono_native_tls_get_value (wsq_tlskey);
if (wsq == NULL) {
WSQ_DEBUG ("local_push: no wsq\n");
return FALSE;
gboolean res;
MonoWSQ *wsq;
- if (ptr == NULL || wsq_tlskey == NO_KEY)
+ if (ptr == NULL || !wsq_tlskey_inited)
return FALSE;
- wsq = (MonoWSQ *) TlsGetValue (wsq_tlskey);
+ wsq = (MonoWSQ *) mono_native_tls_get_value (wsq_tlskey);
if (wsq == NULL) {
WSQ_DEBUG ("local_pop: no wsq\n");
return FALSE;
void
mono_wsq_try_steal (MonoWSQ *wsq, void **ptr, guint32 ms_timeout)
{
- if (wsq == NULL || ptr == NULL || *ptr != NULL || wsq_tlskey == NO_KEY)
+ if (wsq == NULL || ptr == NULL || *ptr != NULL || !wsq_tlskey_inited)
return;
- if (TlsGetValue (wsq_tlskey) == wsq)
+ if (mono_native_tls_get_value (wsq_tlskey) == wsq)
return;
if (mono_sem_timedwait (&wsq->lock, ms_timeout, FALSE) == 0) {
#include "mono/utils/mono-compiler.h"
#include "mono/utils/mono-error.h"
#include "mono/utils/mono-stack-unwinding.h"
+#include "mono/utils/mono-tls.h"
/*
* We should find a better place for this stuff. We can't put it in mono-compiler.h,
int
mono_thread_kill (MonoInternalThread *thread, int signal) MONO_INTERNAL;
-guint32
+MonoNativeTlsKey
mono_thread_get_tls_key (void) MONO_INTERNAL;
gint32
mono_thread_get_tls_offset (void) MONO_INTERNAL;
-guint32
+MonoNativeTlsKey
mono_domain_get_tls_key (void) MONO_INTERNAL;
gint32
#include <mono/utils/mono-time.h>
#include <mono/utils/mono-threads.h>
#include <mono/utils/hazard-pointer.h>
+#include <mono/utils/mono-tls.h>
#include <mono/metadata/gc-internal.h>
static MonoGHashTable *thread_start_args = NULL;
/* The TLS key that holds the MonoObject assigned to each thread */
-static guint32 current_object_key = -1;
+static MonoNativeTlsKey current_object_key;
#ifdef MONO_HAVE_FAST_TLS
/* we need to use both the Tls* functions and __thread because
MONO_FAST_TLS_DECLARE(tls_current_object);
#define SET_CURRENT_OBJECT(x) do { \
MONO_FAST_TLS_SET (tls_current_object, x); \
- TlsSetValue (current_object_key, x); \
+ mono_native_tls_set_value (current_object_key, x); \
} while (FALSE)
#define GET_CURRENT_OBJECT() ((MonoInternalThread*) MONO_FAST_TLS_GET (tls_current_object))
#else
-#define SET_CURRENT_OBJECT(x) TlsSetValue (current_object_key, x)
-#define GET_CURRENT_OBJECT() (MonoInternalThread*) TlsGetValue (current_object_key)
+#define SET_CURRENT_OBJECT(x) mono_native_tls_set_value (current_object_key, x)
+#define GET_CURRENT_OBJECT() (MonoInternalThread*) mono_native_tls_get_value (current_object_key)
#endif
/* function called at thread start */
return InterlockedIncrement (&managed_thread_id_counter);
}
-guint32
+MonoNativeTlsKey
mono_thread_get_tls_key (void)
{
return current_object_key;
mono_init_static_data_info (&context_static_info);
MONO_FAST_TLS_INIT (tls_current_object);
- current_object_key=TlsAlloc();
+ mono_native_tls_alloc (current_object_key, NULL);
THREAD_DEBUG (g_message ("%s: Allocated current_object_key %d", __func__, current_object_key));
mono_thread_start_cb = start_cb;
CloseHandle (background_change_event);
#endif
- TlsFree (current_object_key);
+ mono_native_tls_free (current_object_key);
}
void
static GPtrArray *event_requests;
-static guint32 debugger_tls_id;
+static MonoNativeTlsKey debugger_tls_id;
static gboolean vm_start_event_sent, vm_death_event_sent, disconnected;
mono_profiler_install_jit_end (jit_end);
mono_profiler_install_method_invoke (start_runtime_invoke, end_runtime_invoke);
- debugger_tls_id = TlsAlloc ();
+ mono_native_tls_alloc (debugger_tls_id, NULL);
thread_to_tls = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC);
MONO_GC_REGISTER_ROOT_FIXED (thread_to_tls);
{
DebuggerTlsData *tls;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
if (ctx)
if (!inited)
return FALSE;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
if (!tls)
return FALSE;
int i;
if (!tls)
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
for (i = 0; i < tls->frame_count; ++i) {
return;
}
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
mono_mutex_lock (&suspend_mutex);
}
}
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (!tls);
// FIXME: Free this somewhere
tls = g_new0 (DebuggerTlsData, 1);
tls->resume_event = CreateEvent (NULL, FALSE, FALSE, NULL);
MONO_GC_REGISTER_ROOT_SINGLE (tls->thread);
tls->thread = thread;
- TlsSetValue (debugger_tls_id, tls);
+ mono_native_tls_set_value (debugger_tls_id, tls);
DEBUG (1, fprintf (log_file, "[%p] Thread started, obj=%p, tls=%p.\n", (gpointer)tid, thread, tls));
if (!restore_context)
restore_context = mono_get_restore_context ();
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
/* Have to save/restore the restore_ctx as we can be called recursively during invokes etc. */
memcpy (&orig_restore_ctx, &tls->restore_ctx, sizeof (MonoContext));
memcpy (&tls->restore_ctx, &tls->handler_ctx, sizeof (MonoContext));
/* Save the original context in TLS */
// FIXME: This might not work on an altstack ?
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
// FIXME: MonoContext usually doesn't include the fp registers, so these are
{
DebuggerTlsData *tls;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
memcpy (&tls->restore_ctx, ctx, sizeof (MonoContext));
{
DebuggerTlsData *tls;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
memcpy (&tls->restore_ctx, ctx, sizeof (MonoContext));
if (!inited)
return;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
if (!tls)
return;
if (!inited)
return;
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
if (!tls)
return;
if (!restore_context)
restore_context = mono_get_restore_context ();
- tls = TlsGetValue (debugger_tls_id);
+ tls = mono_native_tls_get_value (debugger_tls_id);
g_assert (tls);
/*
static void
handle_signal_exception (gpointer obj, gboolean test_only)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoContext ctx;
static void (*restore_context) (MonoContext *);
* signal is disabled, and we could run arbitrary code though the debugger. So
* resume into the normal stack and do most work there if possible.
*/
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
guint64 sp = UCONTEXT_REG_RSP (ctx);
/* Pass the ctx parameter in TLS */
static void
restore_soft_guard_pages (void)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (jit_tls->stack_ovf_guard_base)
mono_mprotect (jit_tls->stack_ovf_guard_base, jit_tls->stack_ovf_guard_size, MONO_MMAP_NONE);
}
static void
handle_signal_exception (gpointer obj, gboolean test_only)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoContext ctx;
static void (*restore_context) (MonoContext *);
* signal is disabled, and we could run arbitrary code though the debugger. So
* resume into the normal stack and do most work there if possible.
*/
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
guint64 sp = UCONTEXT_REG_SP (sigctx);
/* Pass the ctx parameter in TLS */
static void
handle_signal_exception (gpointer obj, gboolean test_only)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoContext ctx;
static void (*restore_context) (MonoContext *);
* signal is disabled, and we could run arbitrary code though the debugger. So
* resume into the normal stack and do most work there if possible.
*/
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
mgreg_t sp;
void *sigctx = ctx;
int frame_size;
DWORD page_size;
MonoDomain *domain = mono_domain_get ();
MonoJitInfo rji;
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoLMF *lmf = jit_tls->lmf;
MonoContext initial_ctx;
MonoContext ctx;
static void
handle_signal_exception (gpointer obj)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoContext ctx;
static void (*restore_context) (MonoContext *);
* signal is disabled, and we could run arbitrary code though the debugger. So
* resume into the normal stack and do most work there if possible.
*/
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
/* Pass the ctx parameter in TLS */
mono_arch_sigctx_to_monoctx (ctx, &jit_tls->ex_ctx);
return TRUE;
#elif defined (TARGET_WIN32)
MonoContext mctx;
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
struct sigcontext *ctx = (struct sigcontext *)sigctx;
mono_arch_sigctx_to_monoctx (sigctx, &jit_tls->ex_ctx);
static void
restore_soft_guard_pages (void)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (jit_tls->stack_ovf_guard_base)
mono_mprotect (jit_tls->stack_ovf_guard_base, jit_tls->stack_ovf_guard_size, MONO_MMAP_NONE);
}
MonoJitTlsData *jit_tls = NULL;
if (mini_get_debug_options ()->better_cast_details) {
- jit_tls = TlsGetValue (mono_jit_tls_id);
+ jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
jit_tls->class_cast_from = NULL;
}
gpointer cached_vtable, obj_vtable;
if (mini_get_debug_options ()->better_cast_details) {
- jit_tls = TlsGetValue (mono_jit_tls_id);
+ jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
jit_tls->class_cast_from = NULL;
}
#include <mono/utils/mono-math.h>
#include <mono/utils/mono-mmap.h>
#include <mono/utils/mono-memory-model.h>
+#include <mono/utils/mono-tls.h>
#include "trace.h"
#include "ir-emit.h"
/* amd64_call_reg_internal, which uses amd64_alu_* macros, etc. */
/* We only want to force bundle alignment for the top level instruction, */
/* so NaCl pseudo-instructions can be implemented with sub instructions. */
-static guint32 nacl_instruction_depth;
+static MonoNativeTlsKey nacl_instruction_depth;
-static guint32 nacl_rex_tag;
-static guint32 nacl_legacy_prefix_tag;
+static MonoNativeTlsKey nacl_rex_tag;
+static MonoNativeTlsKey nacl_legacy_prefix_tag;
void
amd64_nacl_clear_legacy_prefix_tag ()
{
- TlsSetValue (nacl_legacy_prefix_tag, NULL);
+ mono_native_tls_set_value (nacl_legacy_prefix_tag, NULL);
}
void
amd64_nacl_tag_legacy_prefix (guint8* code)
{
- if (TlsGetValue (nacl_legacy_prefix_tag) == NULL)
- TlsSetValue (nacl_legacy_prefix_tag, code);
+ if (mono_native_tls_get_value (nacl_legacy_prefix_tag) == NULL)
+ mono_native_tls_set_value (nacl_legacy_prefix_tag, code);
}
void
amd64_nacl_tag_rex (guint8* code)
{
- TlsSetValue (nacl_rex_tag, code);
+ mono_native_tls_set_value (nacl_rex_tag, code);
}
guint8*
amd64_nacl_get_legacy_prefix_tag ()
{
- return (guint8*)TlsGetValue (nacl_legacy_prefix_tag);
+ return (guint8*)mono_native_tls_get_value (nacl_legacy_prefix_tag);
}
guint8*
amd64_nacl_get_rex_tag ()
{
- return (guint8*)TlsGetValue (nacl_rex_tag);
+ return (guint8*)mono_native_tls_get_value (nacl_rex_tag);
}
/* Increment the instruction "depth" described above */
void
amd64_nacl_instruction_pre ()
{
- intptr_t depth = (intptr_t) TlsGetValue (nacl_instruction_depth);
+ intptr_t depth = (intptr_t) mono_native_tls_get_value (nacl_instruction_depth);
depth++;
- TlsSetValue (nacl_instruction_depth, (gpointer)depth);
+ mono_native_tls_set_value (nacl_instruction_depth, (gpointer)depth);
}
/* amd64_nacl_instruction_post: Decrement instruction "depth", force bundle */
void
amd64_nacl_instruction_post (guint8 **start, guint8 **end)
{
- intptr_t depth = (intptr_t) TlsGetValue(nacl_instruction_depth);
+ intptr_t depth = (intptr_t) mono_native_tls_get_value (nacl_instruction_depth);
depth--;
- TlsSetValue (nacl_instruction_depth, (void*)depth);
+ mono_native_tls_set_value (nacl_instruction_depth, (void*)depth);
g_assert ( depth >= 0 );
if (depth == 0) {
InitializeCriticalSection (&mini_arch_mutex);
#if defined(__native_client_codegen__)
- nacl_instruction_depth = TlsAlloc ();
- TlsSetValue (nacl_instruction_depth, (gpointer)0);
- nacl_rex_tag = TlsAlloc ();
- nacl_legacy_prefix_tag = TlsAlloc ();
+ mono_native_tls_alloc (nacl_instruction_depth, NULL);
+ mono_native_tls_set_value (nacl_instruction_depth, (gpointer)0);
+ mono_native_tls_alloc (nacl_rex_tag, NULL);
+ mono_native_tls_alloc (nacl_legacy_prefix_tag, NULL);
#endif
#ifdef MONO_ARCH_NOMAP32BIT
{
DeleteCriticalSection (&mini_arch_mutex);
#if defined(__native_client_codegen__)
- TlsFree (nacl_instruction_depth);
- TlsFree (nacl_rex_tag);
- TlsFree (nacl_legacy_prefix_tag);
+ mono_native_tls_free (nacl_instruction_depth);
+ mono_native_tls_free (nacl_rex_tag);
+ mono_native_tls_free (nacl_legacy_prefix_tag);
#endif
}
mono_runtime_walk_stack_with_ctx (MonoJitStackWalk func, MonoContext *start_ctx, MonoUnwindOptions unwind_options, void *user_data)
{
if (!start_ctx) {
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (jit_tls && jit_tls->orig_ex_ctx_set)
start_ctx = &jit_tls->orig_ex_ctx;
}
MonoString **file, gint32 *line, gint32 *column)
{
MonoDomain *domain = mono_domain_get ();
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoLMF *lmf = mono_get_lmf ();
MonoJitInfo *ji = NULL;
MonoContext ctx, new_ctx;
MonoDomain *domain = mono_domain_get ();
MonoJitInfo *ji;
static int (*call_filter) (MonoContext *, gpointer) = NULL;
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoLMF *lmf = mono_get_lmf ();
MonoArray *initial_trace_ips = NULL;
GList *trace_ips = NULL;
MonoJitInfo *ji;
static int (*call_filter) (MonoContext *, gpointer) = NULL;
static void (*restore_context) (void *);
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoLMF *lmf = mono_get_lmf ();
MonoException *mono_ex;
gboolean stack_overflow = FALSE;
{
static int (*call_filter) (MonoContext *, gpointer) = NULL;
MonoDomain *domain = mono_domain_get ();
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoLMF *lmf = mono_get_lmf ();
MonoContext ctx, new_ctx;
MonoJitInfo *ji, rji;
static void
try_more_restore (void)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (try_restore_stack_protection (jit_tls, 500))
jit_tls->restore_stack_prot = NULL;
}
static void
restore_stack_protection (void)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
MonoException *ex = mono_domain_get ()->stack_overflow_ex;
/* if we can't restore the stack protection, keep a callback installed so
* we'll try to restore as much stack as we can at each return from unmanaged
#ifdef MONO_ARCH_USE_SIGACTION
struct sigaction sa;
#endif
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (handling_sigsegv)
return;
void
mono_resume_unwind (MonoContext *ctx)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
static void (*restore_context) (MonoContext *);
MonoContext new_ctx;
MonoJitTlsData *jit_tls = NULL;
if (mini_get_debug_options ()->better_cast_details) {
- jit_tls = TlsGetValue (mono_jit_tls_id);
+ jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
jit_tls->class_cast_from = from;
jit_tls->class_cast_to = to;
}
mono_setup_async_callback (MonoContext *ctx, void (*async_cb)(void *fun), gpointer user_data)
{
#ifdef MONO_ARCH_HAVE_SETUP_ASYNC_CALLBACK
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
jit_tls->ex_ctx = *ctx;
mono_arch_setup_async_callback (ctx, async_cb, user_data);
} else {
tls->has_context = FALSE;
}
- tls->jit_tls = TlsGetValue (mono_jit_tls_id);
+ tls->jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
}
#define DEAD_REF ((gpointer)(gssize)0x2a2a2a2a2a2a2a2aULL)
#include "mini.h"
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mempool-internals.h>
+#include <mono/utils/mono-tls.h>
#ifndef __STDC_LIMIT_MACROS
#define __STDC_LIMIT_MACROS
};
static LLVMExecutionEngineRef ee;
-static guint32 current_cfg_tls_id;
+static MonoNativeTlsKey current_cfg_tls_id;
static MonoLLVMModule jit_module, aot_module;
static gboolean jit_module_inited;
mono_loader_lock ();
/* Used to communicate with the callbacks */
- TlsSetValue (current_cfg_tls_id, cfg);
+ mono_native_tls_set_value (current_cfg_tls_id, cfg);
ctx = g_new0 (EmitContext, 1);
ctx->cfg = cfg;
g_free (ctx);
- TlsSetValue (current_cfg_tls_id, NULL);
+ mono_native_tls_set_value (current_cfg_tls_id, NULL);
mono_loader_unlock ();
}
{
MonoCompile *cfg;
- cfg = TlsGetValue (current_cfg_tls_id);
+ cfg = mono_native_tls_get_value (current_cfg_tls_id);
if (cfg) {
// FIXME: dynamic
{
MonoCompile *cfg;
- cfg = TlsGetValue (current_cfg_tls_id);
+ cfg = mono_native_tls_get_value (current_cfg_tls_id);
g_assert (cfg);
cfg->code_len = (guint8*)end - (guint8*)start;
}
gpointer *type_info;
int this_reg, this_offset;
- cfg = TlsGetValue (current_cfg_tls_id);
+ cfg = mono_native_tls_get_value (current_cfg_tls_id);
g_assert (cfg);
/*
void
mono_llvm_init (void)
{
- current_cfg_tls_id = TlsAlloc ();
+ mono_native_tls_alloc (current_cfg_tls_id, NULL);
}
static void
if (call_chain_depth == 0) {
mono_profiler_stat_hit (mono_arch_ip_from_context (ctx), ctx);
} else {
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
int current_frame_index = 1;
MonoContext mono_context;
guchar *ips [call_chain_depth + 1];
{
MonoContext ctx;
MonoException *exc;
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
gpointer resume_ip = jit_tls->handler_block_return_address;
memcpy (&ctx, &jit_tls->handler_block_context, sizeof (MonoContext));
#include <mono/utils/mono-counters.h>
#include <mono/utils/mono-logger-internal.h>
#include <mono/utils/mono-mmap.h>
+#include <mono/utils/mono-tls.h>
#include <mono/utils/dtrace.h>
#include "mini.h"
static guint32 default_opt = 0;
static gboolean default_opt_set = FALSE;
-guint32 mono_jit_tls_id = -1;
+MonoNativeTlsKey mono_jit_tls_id;
#ifdef MONO_HAVE_FAST_TLS
MONO_FAST_TLS_DECLARE(mono_jit_tls);
#endif
#endif
-guint32
+MonoNativeTlsKey
mono_get_jit_tls_key (void)
{
return mono_jit_tls_id;
#else
MonoJitTlsData *jit_tls;
- if ((jit_tls = TlsGetValue (mono_jit_tls_id)))
+ if ((jit_tls = mono_native_tls_get_value (mono_jit_tls_id)))
return jit_tls->lmf;
/*
* We do not assert here because this function can be called from
#else
MonoJitTlsData *jit_tls;
- if ((jit_tls = TlsGetValue (mono_jit_tls_id)))
+ if ((jit_tls = mono_native_tls_get_value (mono_jit_tls_id)))
return &jit_tls->lmf;
/*
mono_jit_thread_attach (NULL);
- if ((jit_tls = TlsGetValue (mono_jit_tls_id)))
+ if ((jit_tls = mono_native_tls_get_value (mono_jit_tls_id)))
return &jit_tls->lmf;
g_assert_not_reached ();
static void
mono_set_jit_tls (MonoJitTlsData *jit_tls)
{
- TlsSetValue (mono_jit_tls_id, jit_tls);
+ mono_native_tls_set_value (mono_jit_tls_id, jit_tls);
#ifdef MONO_HAVE_FAST_TLS
MONO_FAST_TLS_SET (mono_jit_tls, jit_tls);
mono_thread_set_state (mono_thread_internal_current (), ThreadState_Background);
}
#else
- if (!TlsGetValue (mono_jit_tls_id)) {
+ if (!mono_native_tls_get_value (mono_jit_tls_id)) {
mono_thread_attach (domain);
mono_thread_set_state (mono_thread_internal_current (), ThreadState_Background);
}
static void
mono_thread_abort (MonoObject *obj)
{
- /* MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id); */
+ /* MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id); */
/* handle_remove should be eventually called for this thread, too
g_free (jit_tls);*/
MonoJitTlsData *jit_tls;
MonoLMF *lmf;
- jit_tls = TlsGetValue (mono_jit_tls_id);
+ jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
if (jit_tls)
return jit_tls;
SIG_HANDLER_SIGNATURE (mono_sigsegv_signal_handler)
{
MonoJitInfo *ji;
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
gpointer fault_addr = NULL;
GET_CONTEXT;
if (!g_thread_supported ())
g_thread_init (NULL);
- mono_jit_tls_id = TlsAlloc ();
+ mono_native_tls_alloc (mono_jit_tls_id, NULL);
setup_jit_tls_data ((gpointer)-1, mono_thread_abort);
if (default_opt & MONO_OPT_AOT)
mono_runtime_cleanup (domain);
#endif
- free_jit_tls_data (TlsGetValue (mono_jit_tls_id));
+ free_jit_tls_data (mono_native_tls_get_value (mono_jit_tls_id));
mono_icall_cleanup ();
if (mono_inject_async_exc_method)
mono_method_desc_free (mono_inject_async_exc_method);
- TlsFree(mono_jit_tls_id);
+ mono_native_tls_free (mono_jit_tls_id);
DeleteCriticalSection (&jit_mutex);
#include <mono/utils/mono-machine.h>
#include <mono/utils/mono-stack-unwinding.h>
#include <mono/utils/mono-threads.h>
+#include <mono/utils/mono-tls.h>
#define MONO_BREAKPOINT_ARRAY_SIZE 64
typedef struct MonoSpillInfo MonoSpillInfo;
typedef struct MonoTraceSpec MonoTraceSpec;
-extern guint32 mono_jit_tls_id;
+extern MonoNativeTlsKey mono_jit_tls_id;
extern MonoTraceSpec *mono_jit_trace_calls;
extern gboolean mono_break_on_exc;
extern int mono_exc_esp_offset;
MonoLMF** mono_get_lmf_addr (void) MONO_INTERNAL;
void mono_set_lmf (MonoLMF *lmf) MONO_INTERNAL;
void mono_jit_thread_attach (MonoDomain *domain);
-guint32 mono_get_jit_tls_key (void) MONO_INTERNAL;
+MonoNativeTlsKey mono_get_jit_tls_key (void) MONO_INTERNAL;
gint32 mono_get_jit_tls_offset (void) MONO_INTERNAL;
gint32 mono_get_lmf_tls_offset (void) MONO_INTERNAL;
gint32 mono_get_lmf_addr_tls_offset (void) MONO_INTERNAL;
if (cont->domain)
return mono_get_exception_argument ("cont", "Already marked");
- jit_tls = TlsGetValue (mono_jit_tls_id);
+ jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
lmf = mono_get_lmf();
cont->domain = mono_domain_get ();
cont->thread_id = GetCurrentThreadId ();
static void
handler_block_trampoline_helper (gpointer *ptr)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
*ptr = jit_tls->handler_block_return_address;
}
static void
handler_block_trampoline_helper (gpointer *ptr)
{
- MonoJitTlsData *jit_tls = TlsGetValue (mono_jit_tls_id);
+ MonoJitTlsData *jit_tls = mono_native_tls_get_value (mono_jit_tls_id);
*ptr = jit_tls->handler_block_return_address;
}
#include <mono/metadata/threads.h>
#include <mono/metadata/debug-helpers.h>
#include <mono/metadata/mono-gc.h>
+#include <mono/utils/mono-tls.h>
#include <mono/io-layer/atomic.h>
#include <string.h>
#include <stdio.h>
#define CURRENT_THREAD_ID() (gsize) GetCurrentThreadId ()
#ifndef HAVE_KW_THREAD
-static guint32 profiler_thread_id = -1;
-#define LOOKUP_PROFILER_THREAD_DATA() ((ProfilerPerThreadData*)TlsGetValue (profiler_thread_id))
-#define SET_PROFILER_THREAD_DATA(x) TlsSetValue (profiler_thread_id, (x));
-#define ALLOCATE_PROFILER_THREAD_DATA() profiler_thread_id = TlsAlloc ()
-#define FREE_PROFILER_THREAD_DATA() TlsFree (profiler_thread_id)
+static MonoNativeTlsKey profiler_thread_id;
+#define LOOKUP_PROFILER_THREAD_DATA() ((ProfilerPerThreadData*)mono_native_tls_get_value (profiler_thread_id))
+#define SET_PROFILER_THREAD_DATA(x) mono_native_tls_set_value (profiler_thread_id, (x));
+#define ALLOCATE_PROFILER_THREAD_DATA() mono_native_tls_alloc (profiler_thread_id, NULL)
+#define FREE_PROFILER_THREAD_DATA() mono_native_tls_free (profiler_thread_id)
#endif
#define EVENT_TYPE HANDLE
#define MonoNativeTlsKey DWORD
#define mono_native_tls_alloc(key,destructor) ((key = TlsAlloc ()) != TLS_OUT_OF_INDEXES && destructor == NULL)
+#define mono_native_tls_free TlsFree
#define mono_native_tls_set_value TlsSetValue
#define mono_native_tls_get_value TlsGetValue
#define MonoNativeTlsKey pthread_key_t
#define mono_native_tls_alloc(key,destructor) (pthread_key_create (&key, destructor) == 0)
-#define mono_native_tls_set_value pthread_setspecific
+#define mono_native_tls_free pthread_key_delete
+#define mono_native_tls_set_value(k,v) (!pthread_setspecific ((k), (v)))
#define mono_native_tls_get_value pthread_getspecific
#endif /* HOST_WIN32 */