From c1e0aa5491911b747f411fa215a0d68480000957 Mon Sep 17 00:00:00 2001 From: Jay Krell Date: Mon, 8 Jul 2019 00:44:23 -0700 Subject: [PATCH] mono_native_tls_get_value that does not change LastError. (mono/mono#15568) Commit migrated from https://github.com/mono/mono/commit/f19bc9634364185a0a3628c3e1a6fd3f06ed1a89 --- src/mono/mono/utils/mono-tls.h | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/mono/mono/utils/mono-tls.h b/src/mono/mono/utils/mono-tls.h index a171329..cf99376 100644 --- a/src/mono/mono/utils/mono-tls.h +++ b/src/mono/mono/utils/mono-tls.h @@ -52,7 +52,24 @@ g_static_assert (TLS_KEY_DOMAIN == 0); #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 + +#include + +// TlsGetValue always writes 0 to LastError. Which can cause problems. This never changes LastError. +// +static inline +void* +mono_native_tls_get_value (unsigned index) +{ + PTEB const teb = NtCurrentTeb (); + + if (index < TLS_MINIMUM_AVAILABLE) + return teb->TlsSlots [index]; + + void** const p = (void**)teb->TlsExpansionSlots; + + return p ? p [index - TLS_MINIMUM_AVAILABLE] : NULL; +} #else -- 2.7.4