[mono/mono] 270fc620: [runtime] Fix unaligned access in volatile icalls.
| Newsgroups | gmane.comp.gnome.mono.patches |
|---|---|
| Message-ID | <0000014260ce99a0-5157a750-61d8-47c7-ad68-05e157ba9ae7-000000@email.amazonses.com> |
Branch: refs/heads/master
Home: https://github.com/mono/mono
Compare: https://github.com/mono/mono/compare/521e757bfe61...270fc62074a1
Commit: 270fc62074a139f6b6f9e52af3063e40d7679e13
Author: Zoltan Varga <[email protected]> (vargaz)
Date: 2013-11-16 12:05:55 GMT
URL: https://github.com/mono/mono/commit/270fc62074a139f6b6f9e52af3063e40d7679e13
[runtime] Fix unaligned access in volatile icalls.
Changed paths:
M mono/metadata/threads.c
Modified: mono/metadata/threads.c
===================================================================
@@ -2526,6 +2526,15 @@ void mono_thread_stop (MonoThread *thread)
gint64
ves_icall_System_Threading_Volatile_Read8 (void *ptr)
{
+#if SIZEOF_VOID_P == 4
+ if (G_UNLIKELY ((size_t)ptr & 0x7)) {
+ gint64 val;
+ mono_interlocked_lock ();
+ val = *(gint64*)ptr;
+ mono_interlocked_unlock ();
+ return val;
+ }
+#endif
return InterlockedRead64 (ptr);
}
@@ -2540,6 +2549,16 @@ void mono_thread_stop (MonoThread *thread)
{
LongDoubleUnion u;
+#if SIZEOF_VOID_P == 4
+ if (G_UNLIKELY ((size_t)ptr & 0x7)) {
+ double val;
+ mono_interlocked_lock ();
+ val = *(double*)ptr;
+ mono_interlocked_unlock ();
+ return val;
+ }
+#endif
+
u.ival = InterlockedRead64 (ptr);
return u.fval;
@@ -2630,6 +2649,15 @@ void mono_thread_stop (MonoThread *thread)
void
ves_icall_System_Threading_Volatile_Write8 (void *ptr, gint64 value)
{
+#if SIZEOF_VOID_P == 4
+ if (G_UNLIKELY ((size_t)ptr & 0x7)) {
+ mono_interlocked_lock ();
+ *(gint64*)ptr = value;
+ mono_interlocked_unlock ();
+ return;
+ }
+#endif
+
InterlockedWrite64 (ptr, value);
}
@@ -2644,6 +2672,15 @@ void mono_thread_stop (MonoThread *thread)
{
LongDoubleUnion u;
+#if SIZEOF_VOID_P == 4
+ if (G_UNLIKELY ((size_t)ptr & 0x7)) {
+ mono_interlocked_lock ();
+ *(double*)ptr = value;
+ mono_interlocked_unlock ();
+ return;
+ }
+#endif
+
u.fval = value;
InterlockedWrite64 (ptr, u.ival);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches