[threads] Add specific field to check size (#3542)
authorLudovic Henry <ludovic@xamarin.com>
Fri, 9 Sep 2016 14:23:34 +0000 (16:23 +0200)
committerGitHub <noreply@github.com>
Fri, 9 Sep 2016 14:23:34 +0000 (16:23 +0200)
mcs/class/corlib/System.Threading/Thread.cs
mcs/class/corlib/System/Environment.cs
mono/metadata/appdomain.c
mono/metadata/object-internals.h
mono/metadata/object-offsets.h
mono/metadata/threads.c

index f3bec17722a2b9a496d06907a9358fddbcb3957e..9658b45606fd4c3869b70762e8219b5fedfa5df4 100644 (file)
@@ -96,6 +96,12 @@ namespace System.Threading {
                 */
                private IntPtr unused1;
                private IntPtr unused2;
+
+               /* This is used only to check that we are in sync between the representation
+                * of MonoInternalThread in native and InternalThread in managed
+                *
+                * DO NOT RENAME! DO NOT ADD FIELDS AFTER! */
+               private IntPtr last;
                #endregion
 #pragma warning restore 169, 414, 649
 
index bbe43954a3b0f5d452c4f0eab50dce08280871ed..d6b0ec038e4e7ad4878b4fd0e29645994c3e7b26 100644 (file)
@@ -57,7 +57,7 @@ namespace System {
                 * of icalls, do not require an increment.
                 */
 #pragma warning disable 169
-               private const int mono_corlib_version = 154;
+               private const int mono_corlib_version = 155;
 #pragma warning restore 169
 
                [ComVisible (true)]
index bd6487f3b5b3c3cdbbc8e5dda1debf0ac40d2b59..51fce6f40ba00a3f5f564e849c57a723793b9e1f 100644 (file)
@@ -83,7 +83,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 154
+#define MONO_CORLIB_VERSION 155
 
 typedef struct
 {
index 06d558d60db8eaf4658ff279733a406abd67b117..2be3719a196644dcc33af28ef6b352cfcde5f728 100644 (file)
@@ -388,6 +388,12 @@ struct _MonoInternalThread {
         */
        gsize unused1;
        gsize unused2;
+
+       /* This is used only to check that we are in sync between the representation
+        * of MonoInternalThread in native and InternalThread in managed
+        *
+        * DO NOT RENAME! DO NOT ADD FIELDS AFTER! */
+       gpointer last;
 };
 
 struct _MonoThread {
index 0085528adb4891ab77d4b0dce98b45e6015a1fbc..e4965a512a758da60f6db8a0512e36588a3b3bce 100644 (file)
@@ -92,6 +92,7 @@ DECL_OFFSET(MonoDelegate, extra_arg)
 DECL_OFFSET(MonoInternalThread, tid)
 DECL_OFFSET(MonoInternalThread, small_id)
 DECL_OFFSET(MonoInternalThread, static_data)
+DECL_OFFSET(MonoInternalThread, last)
 
 DECL_OFFSET(MonoMulticastDelegate, delegates)
 
index d2c38f69d665fd2ed66ed8a3b07a5a94ed3c47aa..fbe335e7d18835e4a5cd092c1550ced22bd0952b 100644 (file)
@@ -48,6 +48,7 @@
 
 #include <mono/metadata/gc-internals.h>
 #include <mono/metadata/reflection-internals.h>
+#include <mono/metadata/abi-details.h>
 
 #ifdef HAVE_SIGNAL_H
 #include <signal.h>
@@ -966,12 +967,6 @@ mono_thread_create_internal (MonoDomain *domain, gpointer func, gpointer arg, gb
        res = create_thread (thread, internal, NULL, (MonoThreadStart) func, arg, threadpool_thread, stack_size, error);
        return_val_if_nok (error, NULL);
 
-       /* Check that the managed and unmanaged layout of MonoInternalThread matches */
-#ifndef MONO_CROSS_COMPILE
-       if (mono_check_corlib_version () == NULL)
-               g_assert (((char*)&internal->unused2 - (char*)internal) == mono_defaults.internal_thread_class->fields [mono_defaults.internal_thread_class->field.count - 1].offset);
-#endif
-
        return internal;
 }
 
@@ -2898,6 +2893,9 @@ void mono_thread_init (MonoThreadStartCB start_cb,
         * anything up.
         */
        GetCurrentProcess ();
+
+       /* Check that the managed and unmanaged layout of MonoInternalThread matches */
+       g_assert (MONO_STRUCT_OFFSET (MonoInternalThread, last) == mono_field_get_offset (mono_class_get_field_from_name (mono_defaults.internal_thread_class, "last")));
 }
 
 void mono_thread_cleanup (void)