[runtime] Use pointer size gchandles (#32850)
authormonojenkins <jo.shields+jenkins@xamarin.com>
Fri, 28 Feb 2020 07:06:10 +0000 (02:06 -0500)
committerGitHub <noreply@github.com>
Fri, 28 Feb 2020 07:06:10 +0000 (09:06 +0200)
This would enable in the future to use CoreCLR's GC with mono. This doesn't change the current embedding api, but, in the future, we will end up aligning with coreclr on an embedding api that uses pointer sized gchandles.

Co-authored-by: Vlad Brezae <brezaevlad@gmail.com>
46 files changed:
src/mono/mono/metadata/appdomain.c
src/mono/mono/metadata/boehm-gc.c
src/mono/mono/metadata/class-accessors.c
src/mono/mono/metadata/class-init.c
src/mono/mono/metadata/class-internals.h
src/mono/mono/metadata/cominterop.c
src/mono/mono/metadata/console-unix.c
src/mono/mono/metadata/custom-attrs.c
src/mono/mono/metadata/domain-internals.h
src/mono/mono/metadata/exception.c
src/mono/mono/metadata/external-only.c
src/mono/mono/metadata/gc-internals.h
src/mono/mono/metadata/gc.c
src/mono/mono/metadata/handle.c
src/mono/mono/metadata/handle.h
src/mono/mono/metadata/icall-decl.h
src/mono/mono/metadata/icall-def.h
src/mono/mono/metadata/icall.c
src/mono/mono/metadata/marshal-ilgen.c
src/mono/mono/metadata/marshal-windows.c
src/mono/mono/metadata/marshal.c
src/mono/mono/metadata/marshal.h
src/mono/mono/metadata/monitor.c
src/mono/mono/metadata/monitor.h
src/mono/mono/metadata/object-internals.h
src/mono/mono/metadata/object.c
src/mono/mono/metadata/reflection.c
src/mono/mono/metadata/remoting.c
src/mono/mono/metadata/sgen-mono.c
src/mono/mono/metadata/sre-encode.c
src/mono/mono/metadata/sre.c
src/mono/mono/metadata/threads.c
src/mono/mono/metadata/w32file.c
src/mono/mono/metadata/w32process-unix.c
src/mono/mono/metadata/w32process-win32.c
src/mono/mono/metadata/w32process.c
src/mono/mono/metadata/w32process.h
src/mono/mono/metadata/w32socket.c
src/mono/mono/mini/debugger-engine.h
src/mono/mono/mini/interp/interp-internals.h
src/mono/mono/mini/mini-exceptions.c
src/mono/mono/mini/mini-runtime.h
src/mono/mono/utils/mono-error-internals.h
src/mono/mono/utils/mono-forward.h
src/mono/mono/utils/mono-threads.c
src/mono/mono/utils/mono-threads.h

index 34e4619..bb712fa 100644 (file)
@@ -763,7 +763,7 @@ mono_domain_create_appdomain_internal (char *friendly_name, MonoAppDomainSetupHa
                MonoStringHandle root_app_base = MONO_HANDLE_NEW_GET (MonoString, root_setup, application_base);
                if (!MONO_HANDLE_IS_NULL (root_app_base)) {
                        /* N.B. new string is in the new domain */
-                       uint32_t gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, root_app_base), TRUE);
+                       MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, root_app_base), TRUE);
                        MonoStringHandle s = mono_string_new_utf16_handle (data, mono_string_chars_internal (MONO_HANDLE_RAW (root_app_base)), mono_string_handle_length (root_app_base), error);
                        mono_gchandle_free_internal (gchandle);
                        if (!is_ok (error)) {
@@ -2784,7 +2784,7 @@ ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomainHandle ad,
                mono_error_set_out_of_memory (error, "Could not allocate %ud bytes to copy raw assembly data", raw_assembly_len);
                return refass;
        }
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        mono_byte *raw_data = (mono_byte*) MONO_ARRAY_HANDLE_PIN (raw_assembly, gchar, 0, &gchandle);
        memcpy (assembly_data, raw_data, raw_assembly_len);
        mono_gchandle_free_internal (gchandle); /* unpin */
@@ -2794,7 +2794,7 @@ ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomainHandle ad,
 
        mono_byte *raw_symbol_data = NULL;
        guint32 symbol_len = 0;
-       uint32_t symbol_gchandle = 0;
+       MonoGCHandle symbol_gchandle = 0;
        if (!MONO_HANDLE_IS_NULL (raw_symbol_store)) {
                symbol_len = mono_array_handle_length (raw_symbol_store);
                raw_symbol_data = (mono_byte*) MONO_ARRAY_HANDLE_PIN (raw_symbol_store, mono_byte, 0, &symbol_gchandle);
@@ -3105,7 +3105,7 @@ ves_icall_System_AppDomain_InternalGetProcessGuid (MonoStringHandle newguid, Mon
                mono_domain_unlock (mono_root_domain);
                return mono_string_new_utf16_handle (mono_domain_get (), process_guid, sizeof(process_guid)/2, error);
        }
-       uint32_t gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, newguid), TRUE);
+       MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, newguid), TRUE);
        memcpy (process_guid, mono_string_chars_internal (MONO_HANDLE_RAW (newguid)), sizeof(process_guid));
        mono_gchandle_free_internal (gchandle);
        process_guid_set = TRUE;
index 1f9fa2c..681d28f 100644 (file)
@@ -1453,10 +1453,10 @@ alloc_handle (HandleData *handles, MonoObject *obj, gboolean track)
  * \returns a handle that can be used to access the object from
  * unmanaged code.
  */
-guint32
+MonoGCHandle
 mono_gchandle_new_internal (MonoObject *obj, gboolean pinned)
 {
-       return alloc_handle (&gc_handles [pinned? HANDLE_PINNED: HANDLE_NORMAL], obj, FALSE);
+       return (MonoGCHandle)(size_t)alloc_handle (&gc_handles [pinned? HANDLE_PINNED: HANDLE_NORMAL], obj, FALSE);
 }
 
 /**
@@ -1480,10 +1480,10 @@ mono_gchandle_new_internal (MonoObject *obj, gboolean pinned)
  * \returns a handle that can be used to access the object from
  * unmanaged code.
  */
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_internal (MonoObject *obj, gboolean track_resurrection)
 {
-       return alloc_handle (&gc_handles [track_resurrection? HANDLE_WEAK_TRACK: HANDLE_WEAK], obj, track_resurrection);
+       return MONO_GC_HANDLE_FROM_UINT (alloc_handle (&gc_handles [track_resurrection? HANDLE_WEAK_TRACK: HANDLE_WEAK], obj, track_resurrection));
 }
 
 /**
@@ -1497,8 +1497,9 @@ mono_gchandle_new_weakref_internal (MonoObject *obj, gboolean track_resurrection
  * NULL for a collected object if using a weakref handle.
  */
 MonoObject*
-mono_gchandle_get_target_internal (guint32 gchandle)
+mono_gchandle_get_target_internal (MonoGCHandle gch)
 {
+       guint32 gchandle = MONO_GC_HANDLE_TO_UINT (gch);
        guint slot = MONO_GC_HANDLE_SLOT (gchandle);
        guint type = MONO_GC_HANDLE_TYPE (gchandle);
        HandleData *handles = &gc_handles [type];
@@ -1522,8 +1523,9 @@ mono_gchandle_get_target_internal (guint32 gchandle)
 }
 
 void
-mono_gchandle_set_target (guint32 gchandle, MonoObject *obj)
+mono_gchandle_set_target (MonoGCHandle gch, MonoObject *obj)
 {
+       guint32 gchandle = MONO_GC_HANDLE_TO_UINT (gch);
        guint slot = MONO_GC_HANDLE_SLOT (gchandle);
        guint type = MONO_GC_HANDLE_TYPE (gchandle);
        HandleData *handles = &gc_handles [type];
@@ -1568,8 +1570,9 @@ mono_gc_is_null (void)
  * \returns TRUE if the object wrapped by the \p gchandle belongs to the specific \p domain.
  */
 gboolean
-mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
+mono_gchandle_is_in_domain (MonoGCHandle gch, MonoDomain *domain)
 {
+       guint32 gchandle = MONO_GC_HANDLE_TO_UINT (gch);
        guint slot = MONO_GC_HANDLE_SLOT (gchandle);
        guint type = MONO_GC_HANDLE_TYPE (gchandle);
        HandleData *handles = &gc_handles [type];
@@ -1606,8 +1609,9 @@ mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
  * object wrapped. 
  */
 void
-mono_gchandle_free_internal (guint32 gchandle)
+mono_gchandle_free_internal (MonoGCHandle gch)
 {
+       guint32 gchandle = MONO_GC_HANDLE_TO_UINT (gch);
        if (!gchandle)
                return;
 
index f377383..1f3533c 100644 (file)
@@ -259,27 +259,32 @@ typedef struct {
        guint32 value;
 } Uint32Property;
 
-guint32
+typedef struct {
+       MonoPropertyBagItem head;
+       MonoGCHandle value;
+} GCHandleProperty;
+
+MonoGCHandle
 mono_class_get_ref_info_handle (MonoClass *klass)
 {
-       Uint32Property *prop = (Uint32Property*)mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
-       return prop ? prop->value : 0;
+       GCHandleProperty *prop = (GCHandleProperty*)mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
+       return prop ? prop->value : NULL;
 }
 
-guint32
-mono_class_set_ref_info_handle (MonoClass *klass, guint32 value)
+MonoGCHandle
+mono_class_set_ref_info_handle (MonoClass *klass, gpointer value)
 {
        if (!value) {
-               Uint32Property *prop = (Uint32Property*)mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
+               GCHandleProperty *prop = (GCHandleProperty*)mono_property_bag_get (m_class_get_infrequent_data (klass), PROP_REF_INFO_HANDLE);
                if (prop)
-                       prop->value = 0;
-               return 0;
+                       prop->value = NULL;
+               return NULL;
        }
 
-       Uint32Property *prop = (Uint32Property*)mono_class_alloc (klass, sizeof (Uint32Property));
+       GCHandleProperty *prop = (GCHandleProperty*)mono_class_alloc (klass, sizeof (GCHandleProperty));
        prop->head.tag = PROP_REF_INFO_HANDLE;
        prop->value = value;
-       prop = (Uint32Property*)mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
+       prop = (GCHandleProperty*)mono_property_bag_add (m_class_get_infrequent_data (klass), prop);
        return prop->value;
 }
 
index 3a8cd75..0f89e62 100644 (file)
@@ -1015,7 +1015,7 @@ mono_class_create_bounded_array (MonoClass *eclass, guint32 rank, gboolean bound
                mono_class_set_type_load_failure (klass, "Could not create array type '%s[]'", full_name);
                g_free (full_name);
        } else if (eclass->enumtype && !mono_class_enum_basetype_internal (eclass)) {
-               guint32 ref_info_handle = mono_class_get_ref_info_handle (eclass);
+               MonoGCHandle ref_info_handle = mono_class_get_ref_info_handle (eclass);
                if (!ref_info_handle || eclass->wastypebuilder) {
                        g_warning ("Only incomplete TypeBuilder objects are allowed to be an enum without base_type");
                        g_assert (ref_info_handle && !eclass->wastypebuilder);
index c43a6a1..c9e7088 100644 (file)
@@ -1392,11 +1392,11 @@ mono_class_get_marshal_info (MonoClass *klass);
 void
 mono_class_set_marshal_info (MonoClass *klass, MonoMarshalType *marshal_info);
 
-guint32
+MonoGCHandle
 mono_class_get_ref_info_handle (MonoClass *klass);
 
-guint32
-mono_class_set_ref_info_handle (MonoClass *klass, guint32 value);
+MonoGCHandle
+mono_class_set_ref_info_handle (MonoClass *klass, gpointer value);
 
 MonoErrorBoxed*
 mono_class_get_exception_data (MonoClass *klass);
index 9ec1d0f..94b8e24 100644 (file)
@@ -101,7 +101,7 @@ mono_string_to_bstr_impl (MonoStringHandle s, MonoError *error)
        if (MONO_HANDLE_IS_NULL (s))
                return NULL;
 
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        mono_bstr const res = mono_ptr_to_bstr (mono_string_handle_pin_chars (s, &gchandle), mono_string_handle_length (s));
        mono_gchandle_free_internal (gchandle);
        return res;
@@ -158,7 +158,7 @@ static GENERATE_GET_CLASS_WITH_CACHE (com_default_interface_attribute, "System.R
  */
 typedef struct {
        guint32 ref_count;
-       guint32 gc_handle;
+       MonoGCHandle gc_handle;
        GHashTable* vtable_hash;
 #ifdef  HOST_WIN32
        MonoIUnknown *free_marshaler; // actually IMarshal
@@ -1813,7 +1813,7 @@ mono_System_ComObject_ReleaseInterfaces (MonoComObjectHandle obj)
                return;
 
        mono_cominterop_lock ();
-       guint32 const gchandle = GPOINTER_TO_UINT (g_hash_table_lookup (rcw_hash, MONO_HANDLE_GETVAL (obj, iunknown)));
+       MonoGCHandle gchandle = (MonoGCHandle)g_hash_table_lookup (rcw_hash, MONO_HANDLE_GETVAL (obj, iunknown));
        if (gchandle) {
                mono_gchandle_free_internal (gchandle);
                g_hash_table_remove (rcw_hash, MONO_HANDLE_GETVAL (obj, iunknown));
@@ -1836,9 +1836,9 @@ ves_icall_System_ComObject_ReleaseInterfaces (MonoComObjectHandle obj, MonoError
 static gboolean    
 cominterop_rcw_finalizer (gpointer key, gpointer value, gpointer user_data)
 {
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
 
-       gchandle = GPOINTER_TO_UINT (value);
+       gchandle = (MonoGCHandle)value;
        if (gchandle) {
                MonoComInteropProxy* proxy = (MonoComInteropProxy*)mono_gchandle_get_target_internal (gchandle);
 
@@ -1897,12 +1897,12 @@ void
 ves_icall_Mono_Interop_ComInteropProxy_AddProxy (gpointer pUnk, MonoComInteropProxy *volatile* proxy_handle)
 {
 #ifndef DISABLE_COM
-       guint32 const gchandle = mono_gchandle_new_weakref_internal ((MonoObject*)*proxy_handle, FALSE);
+       MonoGCHandle gchandle = mono_gchandle_new_weakref_internal ((MonoObject*)*proxy_handle, FALSE);
 
        mono_cominterop_lock ();
        if (!rcw_hash)
                rcw_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
-       g_hash_table_insert (rcw_hash, pUnk, GUINT_TO_POINTER (gchandle));
+       g_hash_table_insert (rcw_hash, pUnk, gchandle);
        mono_cominterop_unlock ();
 #else
        g_assert_not_reached ();
@@ -1916,11 +1916,11 @@ ves_icall_Mono_Interop_ComInteropProxy_FindProxy (gpointer pUnk, MonoComInteropP
 
 #ifndef DISABLE_COM
 
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
 
        mono_cominterop_lock ();
        if (rcw_hash)
-               gchandle = GPOINTER_TO_UINT (g_hash_table_lookup (rcw_hash, pUnk));
+               gchandle = (MonoGCHandle)g_hash_table_lookup (rcw_hash, pUnk);
        mono_cominterop_unlock ();
        if (!gchandle)
                return;
@@ -1947,7 +1947,7 @@ ves_icall_Mono_Interop_ComInteropProxy_FindProxy (gpointer pUnk, MonoComInteropP
  *
  * Returns: the corresponding object for the CCW
  */
-static gchandle_t
+static MonoGCHandle
 cominterop_get_ccw_gchandle (MonoCCWInterface* ccw_entry, gboolean verify)
 {
        /* no CCW's exist yet */
@@ -1962,14 +1962,14 @@ cominterop_get_ccw_gchandle (MonoCCWInterface* ccw_entry, gboolean verify)
 static MonoObjectHandle
 cominterop_get_ccw_handle (MonoCCWInterface* ccw_entry, gboolean verify)
 {
-       gchandle_t const gchandle = cominterop_get_ccw_gchandle (ccw_entry, verify);
+       MonoGCHandle const gchandle = cominterop_get_ccw_gchandle (ccw_entry, verify);
        return gchandle ? mono_gchandle_get_target_handle (gchandle) : NULL_HANDLE;
 }
 
 static MonoObject*
 cominterop_get_ccw_object (MonoCCWInterface* ccw_entry, gboolean verify)
 {
-       gchandle_t const gchandle = cominterop_get_ccw_gchandle (ccw_entry, verify);
+       MonoGCHandle const gchandle = cominterop_get_ccw_gchandle (ccw_entry, verify);
        return gchandle ? mono_gchandle_get_target_internal (gchandle) : NULL;
 }
 
@@ -2340,7 +2340,7 @@ mono_marshal_free_ccw_handle (MonoObjectHandle object)
                gboolean destroy_ccw = is_null || is_equal;
                if (is_null) {
                        MonoCCWInterface* ccw_entry = (MonoCCWInterface *)g_hash_table_lookup (ccw_iter->vtable_hash, mono_class_get_iunknown_class ());
-                       gchandle_t gchandle = 0;
+                       MonoGCHandle gchandle = NULL;
                        if (!(ccw_entry && (gchandle = cominterop_get_ccw_gchandle (ccw_entry, FALSE)) && mono_gchandle_target_equal (gchandle, object)))
                                destroy_ccw = FALSE;
                }
@@ -2586,7 +2586,7 @@ cominterop_ccw_addref_impl (MonoCCWInterface* ccwe)
        g_assert (ccw->gc_handle);
        gint32 const ref_count = mono_atomic_inc_i32 ((gint32*)&ccw->ref_count);
        if (ref_count == 1) {
-               guint32 oldhandle = ccw->gc_handle;
+               MonoGCHandle oldhandle = ccw->gc_handle;
                g_assert (oldhandle);
                /* since we now have a ref count, alloc a strong handle*/
                ccw->gc_handle = mono_gchandle_from_handle (mono_gchandle_get_target_handle (oldhandle), FALSE);
@@ -2621,7 +2621,7 @@ cominterop_ccw_release_impl (MonoCCWInterface* ccwe)
        gint32 const ref_count = mono_atomic_dec_i32 ((gint32*)&ccw->ref_count);
        if (ref_count == 0) {
                /* allow gc of object */
-               guint32 oldhandle = ccw->gc_handle;
+               MonoGCHandle oldhandle = ccw->gc_handle;
                g_assert (oldhandle);
                ccw->gc_handle = mono_gchandle_new_weakref_from_handle (mono_gchandle_get_target_handle (oldhandle));
                mono_gchandle_free_internal (oldhandle);
index cc9e543..908b2d6 100644 (file)
@@ -484,7 +484,7 @@ ves_icall_System_ConsoleDriver_TtySetup (MonoStringHandle keypad, MonoStringHand
        if (ret == -1)
                return FALSE;
 
-       uint32_t h;
+       MonoGCHandle h;
        set_control_chars (MONO_ARRAY_HANDLE_PIN (control_chars_arr, gchar, 0, &h), mono_attr.c_cc);
        mono_gchandle_free_internal (h);
        /* If initialized from another appdomain... */
index 3878348..7bbb1ed 100644 (file)
@@ -711,7 +711,7 @@ mono_custom_attrs_from_builders_handle (MonoImage *alloc_img, MonoImage *image,
                        continue;
                MONO_HANDLE_GET (cattr_data, cattr, data);
                unsigned char *saved = (unsigned char *)mono_image_alloc (image, mono_array_handle_length (cattr_data));
-               guint32 gchandle = 0;
+               MonoGCHandle gchandle = NULL;
                memcpy (saved, MONO_ARRAY_HANDLE_PIN (cattr_data, char, 0, &gchandle), mono_array_handle_length (cattr_data));
                mono_gchandle_free_internal (gchandle);
                ainfo->attrs [index].ctor = ctor_method;
index 3fb7ac6..f37054c 100644 (file)
@@ -288,7 +288,7 @@ struct _MonoJitInfo {
 
 typedef struct {
        gpointer *static_data; /* Used to free the static data without going through the MonoAppContext object itself. */
-       uint32_t gc_handle;
+       MonoGCHandle gc_handle;
 } ContextStaticData;
 
 struct _MonoAppContext {
index 48f96bf..59712ba 100644 (file)
@@ -1161,7 +1161,7 @@ mono_exception_handle_get_native_backtrace (MonoExceptionHandle exc)
        domain = mono_domain_get ();
        len = mono_array_handle_length (arr);
        text = g_string_new_len (NULL, len * 20);
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        gpointer *addr = MONO_ARRAY_HANDLE_PIN (arr, gpointer, 0, &gchandle);
        MONO_ENTER_GC_SAFE;
        messages = backtrace_symbols (addr, len);
index d3783f1..8e3c782 100644 (file)
@@ -42,7 +42,7 @@
 uint32_t
 mono_gchandle_new (MonoObject *obj, mono_bool pinned)
 {
-       MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, mono_gchandle_new_internal (obj, pinned));
+       MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, (uint32_t)(size_t)mono_gchandle_new_internal (obj, pinned));
 }
 
 /**
@@ -69,7 +69,7 @@ mono_gchandle_new (MonoObject *obj, mono_bool pinned)
 uint32_t
 mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection)
 {
-       MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, mono_gchandle_new_weakref_internal (obj, track_resurrection));
+       MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, (uint32_t)(size_t)mono_gchandle_new_weakref_internal (obj, track_resurrection));
 }
 
 /**
@@ -85,7 +85,7 @@ mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection)
 MonoObject*
 mono_gchandle_get_target (uint32_t gchandle)
 {
-       MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoObject*, mono_gchandle_get_target_internal (gchandle));
+       MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoObject*, mono_gchandle_get_target_internal ((MonoGCHandle)(size_t)gchandle));
 }
 
 /**
@@ -104,7 +104,7 @@ mono_gchandle_free (uint32_t gchandle)
         * the gchandle code is lockfree.  SGen calls back into Mono which
         * fires a profiler event, so the profiler must be prepared to be
         * called from threads that aren't attached to Mono. */
-       MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal (gchandle));
+       MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal ((MonoGCHandle)(size_t)gchandle));
 }
 
 /* GC write barriers support */
index eca830c..9ec974a 100644 (file)
 #define MONO_GC_UNREGISTER_ROOT(x) mono_gc_deregister_root ((char*)&(x))
 
 /*
+ * The lowest bit is used to mark pinned handles by netcore's GCHandle class. These macros
+ * are used to convert between the old int32 representation to a netcore compatible pointer
+ * representation.
+ */
+#define MONO_GC_HANDLE_TO_UINT(ptr) ((guint32)((size_t)(ptr) >> 1))
+#define MONO_GC_HANDLE_FROM_UINT(i) ((MonoGCHandle)((size_t)(i) << 1))
+/*
  * Return a GC descriptor for an array containing N pointers to memory allocated
  * by mono_gc_alloc_fixed ().
  */
@@ -84,7 +91,7 @@ extern void mono_gc_set_stack_end (void *stack_end);
 gboolean mono_object_is_alive (MonoObject* obj);
 gboolean mono_gc_is_finalizer_thread (MonoThread *thread);
 
-void mono_gchandle_set_target (guint32 gchandle, MonoObject *obj);
+void mono_gchandle_set_target (MonoGCHandle gchandle, MonoObject *obj);
 
 /*Ephemeron functionality. Sgen only*/
 gboolean    mono_gc_ephemeron_array_add (MonoObject *obj);
@@ -119,7 +126,7 @@ mono_gc_alloc_fixed_no_descriptor (size_t size, MonoGCRootSource source, void *k
 void  mono_gc_free_fixed             (void* addr);
 
 /* make sure the gchandle was allocated for an object in domain */
-gboolean mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain);
+gboolean mono_gchandle_is_in_domain (MonoGCHandle gchandle, MonoDomain *domain);
 void     mono_gchandle_free_domain  (MonoDomain *domain);
 
 typedef void (*FinalizerThreadCallback) (gpointer user_data);
@@ -362,7 +369,7 @@ typedef struct _RefQueueEntry RefQueueEntry;
 
 struct _RefQueueEntry {
        void *dis_link;
-       guint32 gchandle;
+       MonoGCHandle gchandle;
        MonoDomain *domain;
        void *user_data;
        RefQueueEntry *next;
index b620da0..d9fe1af 100644 (file)
@@ -652,10 +652,10 @@ ves_icall_System_GC_get_ephemeron_tombstone (MonoError *error)
 
 #if ENABLE_NETCORE
 
-gpointer
+MonoGCHandle
 ves_icall_System_GCHandle_InternalAlloc (MonoObjectHandle obj, gint32 type, MonoError *error)
 {
-       guint32 handle = 0;
+       MonoGCHandle handle = NULL;
 
        switch (type) {
        case HANDLE_WEAK:
@@ -673,32 +673,31 @@ ves_icall_System_GCHandle_InternalAlloc (MonoObjectHandle obj, gint32 type, Mono
        default:
                g_assert_not_reached ();
        }
-       /* The lowest bit is used to mark pinned handles by netcore's GCHandle class */
-       return GUINT_TO_POINTER (handle << 1);
+       return handle;
 }
 
 void
-ves_icall_System_GCHandle_InternalFree (gpointer handle, MonoError *error)
+ves_icall_System_GCHandle_InternalFree (MonoGCHandle handle, MonoError *error)
 {
-       mono_gchandle_free_internal (GPOINTER_TO_UINT (handle) >> 1);
+       mono_gchandle_free_internal (handle);
 }
 
 MonoObjectHandle
-ves_icall_System_GCHandle_InternalGet (gpointer handle, MonoError *error)
+ves_icall_System_GCHandle_InternalGet (MonoGCHandle handle, MonoError *error)
 {
-       return mono_gchandle_get_target_handle (GPOINTER_TO_UINT (handle) >> 1);
+       return mono_gchandle_get_target_handle (handle);
 }
 
 void
-ves_icall_System_GCHandle_InternalSet (gpointer handle, MonoObjectHandle obj, MonoError *error)
+ves_icall_System_GCHandle_InternalSet (MonoGCHandle handle, MonoObjectHandle obj, MonoError *error)
 {
-       mono_gchandle_set_target_handle (GPOINTER_TO_UINT (handle) >> 1, obj);
+       mono_gchandle_set_target_handle (handle, obj);
 }
 
 #else
 
 MonoObjectHandle
-ves_icall_System_GCHandle_GetTarget (guint32 handle, MonoError *error)
+ves_icall_System_GCHandle_GetTarget (MonoGCHandle handle, MonoError *error)
 {
        return mono_gchandle_get_target_handle (handle);
 }
@@ -706,8 +705,8 @@ ves_icall_System_GCHandle_GetTarget (guint32 handle, MonoError *error)
 /*
  * if type == -1, change the target of the handle, otherwise allocate a new handle.
  */
-guint32
-ves_icall_System_GCHandle_GetTargetHandle (MonoObjectHandle obj, guint32 handle, gint32 type, MonoError *error)
+MonoGCHandle
+ves_icall_System_GCHandle_GetTargetHandle (MonoObjectHandle obj, MonoGCHandle handle, gint32 type, MonoError *error)
 {
        if (type == -1) {
                mono_gchandle_set_target_handle (handle, obj);
@@ -726,24 +725,26 @@ ves_icall_System_GCHandle_GetTargetHandle (MonoObjectHandle obj, guint32 handle,
        default:
                g_assert_not_reached ();
        }
-       return 0;
+       return NULL;
 }
 
 void
-ves_icall_System_GCHandle_FreeHandle (guint32 handle)
+ves_icall_System_GCHandle_FreeHandle (MonoGCHandle handle)
 {
        mono_gchandle_free_internal (handle);
 }
 
 gpointer
-ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle)
+ves_icall_System_GCHandle_GetAddrOfPinnedObject (MonoGCHandle handle)
 {
        // Handles seem to only be in the way here, and the object is pinned.
 
        MonoObject *obj;
+       guint32 gch = MONO_GC_HANDLE_TO_UINT (handle);
 
-       if (MONO_GC_HANDLE_TYPE (handle) != HANDLE_PINNED)
+       if (MONO_GC_HANDLE_TYPE (gch) != HANDLE_PINNED)
                return (gpointer)-2;
+
        obj = mono_gchandle_get_target_internal (handle);
        if (obj) {
                MonoClass *klass = mono_object_class (obj);
@@ -768,7 +769,7 @@ ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle)
 }
 
 MonoBoolean
-ves_icall_System_GCHandle_CheckCurrentDomain (guint32 gchandle)
+ves_icall_System_GCHandle_CheckCurrentDomain (MonoGCHandle gchandle)
 {
        return mono_gchandle_is_in_domain (gchandle, mono_domain_get ());
 }
@@ -1197,7 +1198,7 @@ reference_queue_proccess (MonoReferenceQueue *queue)
        RefQueueEntry *entry;
        while ((entry = *iter)) {
                if (queue->should_be_deleted || !mono_gchandle_get_target_internal (entry->gchandle)) {
-                       mono_gchandle_free_internal ((guint32)entry->gchandle);
+                       mono_gchandle_free_internal (entry->gchandle);
                        ref_list_remove_element (iter, entry);
                        queue->callback (entry->user_data);
                        g_free (entry);
@@ -1252,7 +1253,7 @@ reference_queue_clear_for_domain (MonoDomain *domain)
                RefQueueEntry *entry;
                while ((entry = *iter)) {
                        if (entry->domain == domain) {
-                               mono_gchandle_free_internal ((guint32)entry->gchandle);
+                               mono_gchandle_free_internal (entry->gchandle);
                                ref_list_remove_element (iter, entry);
                                queue->callback (entry->user_data);
                                g_free (entry);
index a06ebab..d552b3f 100644 (file)
@@ -396,7 +396,7 @@ mono_array_new_full_handle (MonoDomain *domain, MonoClass *array_class, uintptr_
        return MONO_HANDLE_NEW (MonoArray, mono_array_new_full_checked (domain, array_class, lengths, lower_bounds, error));
 }
 
-uint32_t
+MonoGCHandle
 mono_gchandle_from_handle (MonoObjectHandle handle, mono_bool pinned)
 {
        // FIXME This used to check for out of scope handles.
@@ -409,13 +409,13 @@ mono_gchandle_from_handle (MonoObjectHandle handle, mono_bool pinned)
 }
 
 MonoObjectHandle
-mono_gchandle_get_target_handle (uint32_t gchandle)
+mono_gchandle_get_target_handle (MonoGCHandle gchandle)
 {
        return MONO_HANDLE_NEW (MonoObject, mono_gchandle_get_target_internal (gchandle));
 }
 
 gpointer
-mono_array_handle_pin_with_size (MonoArrayHandle handle, int size, uintptr_t idx, uint32_t *gchandle)
+mono_array_handle_pin_with_size (MonoArrayHandle handle, int size, uintptr_t idx, MonoGCHandle *gchandle)
 {
        g_assert (gchandle != NULL);
        *gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST(MonoObject,handle), TRUE);
@@ -424,7 +424,7 @@ mono_array_handle_pin_with_size (MonoArrayHandle handle, int size, uintptr_t idx
 }
 
 gunichar2*
-mono_string_handle_pin_chars (MonoStringHandle handle, uint32_t *gchandle)
+mono_string_handle_pin_chars (MonoStringHandle handle, MonoGCHandle *gchandle)
 {
        g_assert (gchandle != NULL);
        *gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, handle), TRUE);
@@ -433,7 +433,7 @@ mono_string_handle_pin_chars (MonoStringHandle handle, uint32_t *gchandle)
 }
 
 gpointer
-mono_object_handle_pin_unbox (MonoObjectHandle obj, uint32_t *gchandle)
+mono_object_handle_pin_unbox (MonoObjectHandle obj, MonoGCHandle *gchandle)
 {
        g_assert (!MONO_HANDLE_IS_NULL (obj));
        MonoClass *klass = mono_handle_class (obj);
@@ -457,7 +457,7 @@ mono_handle_stack_is_empty (HandleStack *stack)
 
 //FIXME inline
 gboolean
-mono_gchandle_target_equal (uint32_t gchandle, MonoObjectHandle equal)
+mono_gchandle_target_equal (MonoGCHandle gchandle, MonoObjectHandle equal)
 {
        // This function serves to reduce coop handle creation.
        MONO_HANDLE_SUPPRESS_SCOPE (1);
@@ -466,7 +466,7 @@ mono_gchandle_target_equal (uint32_t gchandle, MonoObjectHandle equal)
 
 //FIXME inline
 void
-mono_gchandle_target_is_null_or_equal (uint32_t gchandle, MonoObjectHandle equal, gboolean *is_null,
+mono_gchandle_target_is_null_or_equal (MonoGCHandle gchandle, MonoObjectHandle equal, gboolean *is_null,
        gboolean *is_equal)
 {
        // This function serves to reduce coop handle creation.
@@ -478,13 +478,13 @@ mono_gchandle_target_is_null_or_equal (uint32_t gchandle, MonoObjectHandle equal
 
 //FIXME inline
 void
-mono_gchandle_set_target_handle (guint32 gchandle, MonoObjectHandle obj)
+mono_gchandle_set_target_handle (MonoGCHandle gchandle, MonoObjectHandle obj)
 {
        mono_gchandle_set_target (gchandle, MONO_HANDLE_RAW (obj));
 }
 
 //FIXME inline
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_from_handle (MonoObjectHandle handle)
 {
        return mono_gchandle_new_weakref_internal (MONO_HANDLE_SUPPRESS (MONO_HANDLE_RAW (handle)), FALSE);
@@ -498,7 +498,7 @@ mono_handle_hash (MonoObjectHandle object)
 }
 
 //FIXME inline
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_from_handle_track_resurrection (MonoObjectHandle handle)
 {
        return mono_gchandle_new_weakref_internal (MONO_HANDLE_SUPPRESS (MONO_HANDLE_RAW (handle)), TRUE);
index c53b335..2cedc51 100644 (file)
@@ -619,21 +619,21 @@ mono_handle_array_getref (MonoObjectHandleOut dest, MonoArrayHandle array, uintp
 
 /* Local handles to global GC handles and back */
 
-uint32_t
+MonoGCHandle
 mono_gchandle_from_handle (MonoObjectHandle handle, mono_bool pinned);
 
 MonoObjectHandle
-mono_gchandle_get_target_handle (uint32_t gchandle);
+mono_gchandle_get_target_handle (MonoGCHandle gchandle);
 
 gboolean
-mono_gchandle_target_equal (uint32_t gchandle, MonoObjectHandle equal);
+mono_gchandle_target_equal (MonoGCHandle gchandle, MonoObjectHandle equal);
 
 void
-mono_gchandle_target_is_null_or_equal (uint32_t gchandle, MonoObjectHandle equal, gboolean *is_null,
+mono_gchandle_target_is_null_or_equal (MonoGCHandle gchandle, MonoObjectHandle equal, gboolean *is_null,
        gboolean *is_equal);
 
 void
-mono_gchandle_set_target_handle (guint32 gchandle, MonoObjectHandle obj);
+mono_gchandle_set_target_handle (MonoGCHandle gchandle, MonoObjectHandle obj);
 
 void
 mono_array_handle_memcpy_refs (MonoArrayHandle dest, uintptr_t dest_idx, MonoArrayHandle src, uintptr_t src_idx, uintptr_t len);
@@ -643,7 +643,7 @@ mono_array_handle_memcpy_refs (MonoArrayHandle dest, uintptr_t dest_idx, MonoArr
  * size.  Call mono_gchandle_free to unpin.
  */
 gpointer
-mono_array_handle_pin_with_size (MonoArrayHandle handle, int size, uintptr_t index, uint32_t *gchandle);
+mono_array_handle_pin_with_size (MonoArrayHandle handle, int size, uintptr_t index, MonoGCHandle *gchandle);
 
 #define MONO_ARRAY_HANDLE_PIN(handle,type,index,gchandle_out) ((type*)mono_array_handle_pin_with_size (MONO_HANDLE_CAST(MonoArray,(handle)), sizeof (type), (index), (gchandle_out)))
 
@@ -651,10 +651,10 @@ void
 mono_value_copy_array_handle (MonoArrayHandle dest, int dest_idx, gconstpointer src, int count);
 
 gunichar2 *
-mono_string_handle_pin_chars (MonoStringHandle s, uint32_t *gchandle_out);
+mono_string_handle_pin_chars (MonoStringHandle s, MonoGCHandle *gchandle_out);
 
 gpointer
-mono_object_handle_pin_unbox (MonoObjectHandle boxed_valuetype_obj, uint32_t *gchandle_out);
+mono_object_handle_pin_unbox (MonoObjectHandle boxed_valuetype_obj, MonoGCHandle *gchandle_out);
 
 static inline gpointer
 mono_handle_unbox_unsafe (MonoObjectHandle handle)
@@ -672,13 +672,13 @@ mono_context_get_handle (void);
 void
 mono_context_set_handle (MonoAppContextHandle new_context);
 
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_from_handle (MonoObjectHandle handle);
 
 int
 mono_handle_hash (MonoObjectHandle object);
 
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_from_handle_track_resurrection (MonoObjectHandle handle);
 
 #endif /* __MONO_HANDLE_H__ */
index 88a084c..29f4919 100644 (file)
@@ -77,7 +77,7 @@ ICALL_EXPORT MonoAssemblyName* ves_icall_System_Reflection_AssemblyName_GetNativ
 ICALL_EXPORT MonoBoolean ves_icall_RuntimeTypeHandle_is_subclass_of (MonoType*, MonoType*);
 ICALL_EXPORT MonoBoolean ves_icall_System_Environment_GetIs64BitOperatingSystem (void);
 ICALL_EXPORT MonoBoolean ves_icall_System_Environment_get_HasShutdownStarted (void);
-ICALL_EXPORT MonoBoolean ves_icall_System_GCHandle_CheckCurrentDomain (guint32 gchandle);
+ICALL_EXPORT MonoBoolean ves_icall_System_GCHandle_CheckCurrentDomain (MonoGCHandle gchandle);
 ICALL_EXPORT MonoBoolean ves_icall_System_IO_DriveInfo_GetDiskFreeSpace (const gunichar2*, gint32, guint64*, guint64*, guint64*, gint32*);
 ICALL_EXPORT MonoBoolean ves_icall_System_Reflection_AssemblyName_ParseAssemblyName (const char*, MonoAssemblyName*, MonoBoolean*, MonoBoolean* is_token_defined_arg);
 ICALL_EXPORT MonoBoolean ves_icall_System_Runtime_CompilerServices_RuntimeHelpers_SufficientExecutionStack (void);
@@ -157,7 +157,7 @@ ICALL_EXPORT gint64 ves_icall_System_Diagnostics_Process_GetProcessData (int, gi
 ICALL_EXPORT gint64 ves_icall_System_Diagnostics_Stopwatch_GetTimestamp (void);
 ICALL_EXPORT gint64 ves_icall_System_GC_GetTotalMemory (MonoBoolean forceCollection);
 ICALL_EXPORT gint64 ves_icall_System_Threading_Timer_GetTimeMonotonic (void);
-ICALL_EXPORT gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (guint32 handle);
+ICALL_EXPORT gpointer ves_icall_System_GCHandle_GetAddrOfPinnedObject (MonoGCHandle handle);
 ICALL_EXPORT int ves_icall_Interop_Sys_DoubleToString (double, char*, char*, int);
 ICALL_EXPORT int ves_icall_System_Environment_get_Platform (void);
 ICALL_EXPORT int ves_icall_System_GC_GetCollectionCount (int);
@@ -171,7 +171,7 @@ ICALL_EXPORT void ves_icall_System_Array_GetGenericValue_icall (MonoArray**, gui
 ICALL_EXPORT void ves_icall_System_Array_SetGenericValue_icall (MonoArray**, guint32, gpointer);
 ICALL_EXPORT void ves_icall_System_Buffer_MemcpyInternal (gpointer dest, gconstpointer src, gint32 count);
 ICALL_EXPORT void ves_icall_System_Environment_Exit (int);
-ICALL_EXPORT void ves_icall_System_GCHandle_FreeHandle (guint32 handle);
+ICALL_EXPORT void ves_icall_System_GCHandle_FreeHandle (MonoGCHandle handle);
 ICALL_EXPORT void ves_icall_System_GC_InternalCollect (int generation);
 ICALL_EXPORT void ves_icall_System_GC_RecordPressure (gint64);
 ICALL_EXPORT void ves_icall_System_GC_WaitForPendingFinalizers (void);
index 93fece3..05cc9bf 100644 (file)
@@ -744,8 +744,8 @@ ICALL_TYPE(GCH, "System.Runtime.InteropServices.GCHandle", GCH_1)
 NOHANDLES(ICALL(GCH_1, "CheckCurrentDomain", ves_icall_System_GCHandle_CheckCurrentDomain))
 NOHANDLES(ICALL(GCH_2, "FreeHandle", ves_icall_System_GCHandle_FreeHandle))
 NOHANDLES(ICALL(GCH_3, "GetAddrOfPinnedObject", ves_icall_System_GCHandle_GetAddrOfPinnedObject))
-HANDLES(GCH_4, "GetTarget", ves_icall_System_GCHandle_GetTarget, MonoObject, 1, (guint32))
-HANDLES(GCH_5, "GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle, guint32, 3, (MonoObject, guint32, gint32))
+HANDLES(GCH_4, "GetTarget", ves_icall_System_GCHandle_GetTarget, MonoObject, 1, (gpointer))
+HANDLES(GCH_5, "GetTargetHandle", ves_icall_System_GCHandle_GetTargetHandle, gpointer, 3, (MonoObject, gpointer, gint32))
 
 #if !defined(DISABLE_COM) || defined (HOST_WIN32)
 ICALL_TYPE(MARSHAL, "System.Runtime.InteropServices.Marshal", MARSHAL_1)
index efb3571..cefe448 100644 (file)
@@ -2454,7 +2454,7 @@ ves_icall_RuntimeFieldInfo_SetValueInternal (MonoReflectionFieldHandle field, Mo
        return_if_nok (error);
 
        gboolean isref = FALSE;
-       uint32_t value_gchandle = 0;
+       MonoGCHandle value_gchandle = 0;
        gchar *v = NULL;
        if (!type->byref) {
                switch (type->type) {
@@ -2501,7 +2501,7 @@ ves_icall_RuntimeFieldInfo_SetValueInternal (MonoReflectionFieldHandle field, Mo
                                MonoObjectHandle nullable = mono_object_new_handle (mono_domain_get (), nklass, error);
                                return_if_nok (error);
 
-                               uint32_t nullable_gchandle = 0;
+                               MonoGCHandle nullable_gchandle = 0;
                                guint8 *nval = (guint8*)mono_object_handle_pin_unbox (nullable, &nullable_gchandle);
                                mono_nullable_init_from_handle (nval, value, nklass);
 
@@ -2603,7 +2603,7 @@ ves_icall_System_RuntimeFieldHandle_SetValueDirect (MonoReflectionFieldHandle fi
        } else if (MONO_TYPE_IS_REFERENCE (f->type)) {
                mono_copy_value (f->type, (guint8*)obj->value + m_field_get_offset (f) - sizeof (MonoObject), MONO_HANDLE_RAW (value_h), FALSE);
        } else {
-               guint gchandle = 0;
+               MonoGCHandle gchandle = NULL;
                g_assert (MONO_HANDLE_RAW (value_h));
                mono_copy_value (f->type, (guint8*)obj->value + m_field_get_offset (f) - sizeof (MonoObject), mono_object_handle_pin_unbox (value_h, &gchandle), FALSE);
                mono_gchandle_free_internal (gchandle);
@@ -3339,7 +3339,7 @@ ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionTypeHan
        if (mono_class_is_ginst (klass)) {
                MonoClass *generic_class = mono_class_get_generic_class (klass)->container_class;
 
-               guint32 ref_info_handle = mono_class_get_ref_info_handle (generic_class);
+               MonoGCHandle ref_info_handle = mono_class_get_ref_info_handle (generic_class);
                
                if (m_class_was_typebuilder (generic_class) && ref_info_handle) {
                        MonoObjectHandle tb = mono_gchandle_get_target_handle (ref_info_handle);
@@ -7147,7 +7147,7 @@ ves_icall_System_Reflection_RuntimeModule_ResolveSignature (MonoImage *image, gu
 
        // FIXME MONO_ENTER_NO_SAFEPOINTS instead of pin/gchandle.
 
-       uint32_t h;
+       MonoGCHandle h;
        gpointer array_base = MONO_ARRAY_HANDLE_PIN (res, guint8, 0, &h);
        memcpy (array_base, ptr, len);
        mono_gchandle_free_internal (h);
index 5472727..9a5202f 100644 (file)
@@ -6027,7 +6027,7 @@ emit_marshal_variant_ilgen (EmitMarshalContext *m, int argnum, MonoType *t,
 }
 
 static void
-emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle)
+emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle)
 {
        MonoMethodSignature *sig, *csig;
        int i, *tmp_locals, orig_domain, attach_cookie;
@@ -6121,14 +6121,16 @@ emit_managed_wrapper_ilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_s
 
        if (sig->hasthis) {
                if (target_handle) {
-                       mono_mb_emit_icon (mb, (gint32)target_handle);
+                       mono_mb_emit_icon8 (mb, (gint64)target_handle);
+                       mono_mb_emit_byte (mb, CEE_CONV_I);
                        mono_mb_emit_icall (mb, mono_gchandle_get_target_internal);
                } else {
                        /* fixme: */
                        g_assert_not_reached ();
                }
        } else if (closed) {
-               mono_mb_emit_icon (mb, (gint32)target_handle);
+               mono_mb_emit_icon8 (mb, (gint64)target_handle);
+               mono_mb_emit_byte (mb, CEE_CONV_I);
                mono_mb_emit_icall (mb, mono_gchandle_get_target_internal);
        }
 
index a61ef60..feb0eb9 100644 (file)
@@ -107,7 +107,7 @@ mono_string_to_utf8str_impl (MonoStringHandle s, MonoError *error)
 
        // FIXME pass g_utf16_to_utf8 an allocator to avoid double alloc/copy.
 
-       uint32_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        tmp = g_utf16_to_utf8 (mono_string_handle_pin_chars (s, &gchandle), mono_string_handle_length (s), NULL, &len, &gerror);
        mono_gchandle_free_internal (gchandle);
        if (gerror) {
index d8411ee..927124d 100644 (file)
@@ -242,7 +242,7 @@ mono_marshal_init (void)
                register_icall (mono_delegate_begin_invoke, mono_icall_sig_object_object_ptr, FALSE);
                register_icall (mono_delegate_end_invoke, mono_icall_sig_object_object_ptr, FALSE);
                register_icall (mono_gc_wbarrier_generic_nostore_internal, mono_icall_sig_void_ptr, FALSE);
-               register_icall (mono_gchandle_get_target_internal, mono_icall_sig_object_int32, TRUE);
+               register_icall (mono_gchandle_get_target_internal, mono_icall_sig_object_ptr, TRUE);
                register_icall (mono_marshal_isinst_with_cache, mono_icall_sig_object_object_ptr_ptr, FALSE);
                register_icall (mono_threads_enter_gc_safe_region_unbalanced, mono_icall_sig_ptr_ptr, TRUE);
                register_icall (mono_threads_exit_gc_safe_region_unbalanced, mono_icall_sig_void_ptr_ptr, TRUE);
@@ -290,7 +290,7 @@ mono_delegate_to_ftnptr_impl (MonoDelegateHandle delegate, MonoError *error)
        gpointer result = NULL;
        MonoMethod *method, *wrapper;
        MonoClass *klass;
-       uint32_t target_handle = 0;
+       MonoGCHandle target_handle = 0;
 
        if (MONO_HANDLE_IS_NULL (delegate))
                goto leave;
@@ -364,7 +364,7 @@ delegate_hash_table_new (void) {
 static void 
 delegate_hash_table_remove (MonoDelegate *d)
 {
-       guint32 gchandle = 0;
+       MonoGCHandle gchandle = NULL;
 
        if (!d->target)
                return;
@@ -372,7 +372,7 @@ delegate_hash_table_remove (MonoDelegate *d)
        mono_marshal_lock ();
        if (delegate_hash_table == NULL)
                delegate_hash_table = delegate_hash_table_new ();
-       gchandle = GPOINTER_TO_UINT (g_hash_table_lookup (delegate_hash_table, d->delegate_trampoline));
+       gchandle = (MonoGCHandle)g_hash_table_lookup (delegate_hash_table, d->delegate_trampoline);
        g_hash_table_remove (delegate_hash_table, d->delegate_trampoline);
        mono_marshal_unlock ();
        if (gchandle)
@@ -390,21 +390,21 @@ delegate_hash_table_add (MonoDelegateHandle d)
        if (has_target) {
                // If the delegate has an instance method there is 1 to 1 mapping between
                // the delegate object and the delegate_trampoline
-               guint32 gchandle = GPOINTER_TO_UINT (g_hash_table_lookup (delegate_hash_table, delegate_trampoline));
+               MonoGCHandle gchandle = (MonoGCHandle)g_hash_table_lookup (delegate_hash_table, delegate_trampoline);
                if (gchandle) {
                        // Somehow, some other thread beat us to it ?
                        g_assert (mono_gchandle_target_equal (gchandle, MONO_HANDLE_CAST (MonoObject, d)));
                } else {
                        gchandle = mono_gchandle_new_weakref_from_handle (MONO_HANDLE_CAST (MonoObject, d));
-                       g_hash_table_insert (delegate_hash_table, delegate_trampoline, GUINT_TO_POINTER (gchandle));
+                       g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
                }
        } else {
                if (g_hash_table_lookup (delegate_hash_table, delegate_trampoline) == NULL) {
-                       guint32 gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
+                       MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, d), FALSE);
                        // This delegate will always be associated with its delegate_trampoline in the table.
                        // We don't free this delegate object because it is too expensive to keep track of these
                        // pairs and avoid races with the delegate finalization.
-                       g_hash_table_insert (delegate_hash_table, delegate_trampoline, GUINT_TO_POINTER (gchandle));
+                       g_hash_table_insert (delegate_hash_table, delegate_trampoline, gchandle);
                }
        }
        mono_marshal_unlock ();
@@ -459,7 +459,7 @@ parse_unmanaged_function_pointer_attr (MonoClass *klass, MonoMethodPInvoke *piin
 MonoDelegateHandle
 mono_ftnptr_to_delegate_impl (MonoClass *klass, gpointer ftn, MonoError *error)
 {
-       guint32 gchandle;
+       MonoGCHandle gchandle;
        MonoDelegateHandle d = MONO_HANDLE_NEW (MonoDelegate, NULL);
 
        if (ftn == NULL)
@@ -468,7 +468,7 @@ mono_ftnptr_to_delegate_impl (MonoClass *klass, gpointer ftn, MonoError *error)
        mono_marshal_lock ();
        if (delegate_hash_table == NULL)
                delegate_hash_table = delegate_hash_table_new ();
-       gchandle = GPOINTER_TO_UINT (g_hash_table_lookup (delegate_hash_table, ftn));
+       gchandle = (MonoGCHandle)g_hash_table_lookup (delegate_hash_table, ftn);
        mono_marshal_unlock ();
        if (gchandle)
                MONO_HANDLE_ASSIGN (d, MONO_HANDLE_CAST (MonoDelegate, mono_gchandle_get_target_handle (gchandle)));
@@ -539,7 +539,7 @@ mono_delegate_free_ftnptr (MonoDelegate *delegate)
        }
 
        if (ptr) {
-               uint32_t gchandle;
+               MonoGCHandle gchandle;
                void **method_data;
                MonoMethod *method;
 
@@ -552,7 +552,7 @@ mono_delegate_free_ftnptr (MonoDelegate *delegate)
                method_data = (void **)((MonoMethodWrapper*)method)->method_data;
 
                /*the target gchandle is the first entry after size and the wrapper itself.*/
-               gchandle = GPOINTER_TO_UINT (method_data [2]);
+               gchandle = (MonoGCHandle)method_data [2];
 
                if (gchandle)
                        mono_gchandle_free_internal (gchandle);
@@ -692,7 +692,7 @@ mono_byvalarray_to_byte_array_impl (MonoArrayHandle arr, const char *native_arr,
                g_error_free (gerror);
                return;
        }
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        memcpy (MONO_ARRAY_HANDLE_PIN (arr, gunichar2, 0, &gchandle), ut, items_written * sizeof (gunichar2));
        mono_gchandle_free_internal (gchandle);
        g_free (ut);
@@ -706,7 +706,7 @@ mono_array_to_byte_byvalarray_impl (gpointer native_arr, MonoArrayHandle arr, gu
 
        GError *gerror = NULL;
 
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        char *as = g_utf16_to_utf8 (MONO_ARRAY_HANDLE_PIN (arr, gunichar2, 0, &gchandle), mono_array_handle_length (arr), NULL, NULL, &gerror);
        mono_gchandle_free_internal (gchandle);
        if (gerror) {
@@ -1050,7 +1050,7 @@ mono_string_to_byvalwstr_impl (gunichar2 *dst, MonoStringHandle src, int size, M
                return;
        }
 
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        int len = MIN (size, mono_string_handle_length (src));
        memcpy (dst, mono_string_handle_pin_chars (src, &gchandle), len * sizeof (gunichar2));
        mono_gchandle_free_internal (gchandle);
@@ -3840,14 +3840,14 @@ mono_marshal_get_native_func_wrapper_aot (MonoClass *klass)
  * THIS_LOC is the memory location where the target of the delegate is stored.
  */
 void
-mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle)
+mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle)
 {
        get_marshal_cb ()->emit_managed_wrapper (mb, invoke_sig, mspecs, m, method, target_handle);
 }
 
 #ifndef ENABLE_ILGEN
 static void
-emit_managed_wrapper_noilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle)
+emit_managed_wrapper_noilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle)
 {
        MonoMethodSignature *sig, *csig;
        int i;
@@ -3890,7 +3890,7 @@ emit_managed_wrapper_noilgen (MonoMethodBuilder *mb, MonoMethodSignature *invoke
  * If \p target_handle is \c 0, the wrapper info will be a \c WrapperInfo structure.
  */
 MonoMethod *
-mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t target_handle, MonoError *error)
+mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, MonoGCHandle target_handle, MonoError *error)
 {
        MonoMethodSignature *sig, *csig, *invoke_sig;
        MonoMethodBuilder *mb;
@@ -3930,7 +3930,7 @@ mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass,
        mb = mono_mb_new (method->klass, method->name, MONO_WRAPPER_NATIVE_TO_MANAGED);
 
        /*the target gchandle must be the first entry after size and the wrapper itself.*/
-       mono_mb_add_data (mb, GUINT_TO_POINTER (target_handle));
+       mono_mb_add_data (mb, target_handle);
 
        /* we copy the signature, so that we can modify it */
        if (target_handle)
@@ -5097,7 +5097,7 @@ mono_marshal_string_to_utf16_copy_impl (MonoStringHandle s, MonoError *error)
        gsize const length = mono_string_handle_length (s);
        gunichar2 *res = (gunichar2 *)mono_marshal_alloc ((length + 1) * sizeof (*res), error);
        return_val_if_nok (error, NULL);
-       gchandle_t gchandle = 0;
+       MonoGCHandle gchandle = NULL;
        memcpy (res, mono_string_handle_pin_chars (s, &gchandle), length * sizeof (*res));
        mono_gchandle_free_internal (gchandle);
        res [length] = 0;
@@ -5147,7 +5147,7 @@ mono_marshal_clear_last_error (void)
 
 static gsize
 copy_managed_common (MonoArrayHandle managed, gconstpointer native, gint32 start_index,
-               gint32 length, gpointer *managed_addr, guint32 *gchandle, MonoError *error)
+               gint32 length, gpointer *managed_addr, MonoGCHandle *gchandle, MonoError *error)
 {
        MONO_CHECK_ARG_NULL_HANDLE (managed, 0);
        MONO_CHECK_ARG_NULL (native, 0);
@@ -5191,7 +5191,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_copy_to_unmanaged (MonoArrayHan
 {
        g_assert_not_netcore ();
 
-       guint32 gchandle = 0;
+       MonoGCHandle gchandle = 0;
        gsize const bytes = copy_managed_common (src, dest, start_index, length, (gpointer*)&managed_source_addr, &gchandle, error);
        if (bytes)
                memmove (dest, managed_source_addr, bytes); // no references should be involved
@@ -5208,7 +5208,7 @@ ves_icall_System_Runtime_InteropServices_Marshal_copy_from_unmanaged (gconstpoin
 {
        g_assert_not_netcore ();
 
-       guint32 gchandle = 0;
+       MonoGCHandle gchandle = 0;
        gsize const bytes = copy_managed_common (dest, src, start_index, length, &managed_dest_addr, &gchandle, error);
        if (bytes)
                memmove (managed_dest_addr, src, bytes); // no references should be involved
index 0517465..3442a45 100644 (file)
@@ -324,7 +324,7 @@ typedef struct {
        void (*emit_stelemref) (MonoMethodBuilder *mb);
        void (*emit_array_address) (MonoMethodBuilder *mb, int rank, int elem_size);
        void (*emit_native_wrapper) (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param, gboolean skip_gc_trans);
-       void (*emit_managed_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
+       void (*emit_managed_wrapper) (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle);
        void (*emit_runtime_invoke_body) (MonoMethodBuilder *mb, const char **param_names, MonoImage *image, MonoMethod *method, MonoMethodSignature *sig, MonoMethodSignature *callsig, gboolean virtual_, gboolean need_direct_wrapper);
        void (*emit_runtime_invoke_dynamic) (MonoMethodBuilder *mb);
        void (*emit_delegate_begin_invoke) (MonoMethodBuilder *mb, MonoMethodSignature *sig);
@@ -442,7 +442,7 @@ MonoMethodSignature*
 mono_marshal_get_string_ctor_signature (MonoMethod *method);
 
 MonoMethod *
-mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, uint32_t this_loc, MonoError *exernal_error);
+mono_marshal_get_managed_wrapper (MonoMethod *method, MonoClass *delegate_klass, MonoGCHandle this_loc, MonoError *exernal_error);
 
 gpointer
 mono_marshal_get_vtfixup_ftnptr (MonoImage *image, guint32 token, guint16 type);
@@ -662,7 +662,7 @@ void
 mono_marshal_emit_native_wrapper (MonoImage *image, MonoMethodBuilder *mb, MonoMethodSignature *sig, MonoMethodPInvoke *piinfo, MonoMarshalSpec **mspecs, gpointer func, gboolean aot, gboolean check_exceptions, gboolean func_param, gboolean skip_gc_trans);
 
 void
-mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, uint32_t target_handle);
+mono_marshal_emit_managed_wrapper (MonoMethodBuilder *mb, MonoMethodSignature *invoke_sig, MonoMarshalSpec **mspecs, EmitMarshalContext* m, MonoMethod *method, MonoGCHandle target_handle);
 
 GHashTable*
 mono_marshal_get_cache (GHashTable **var, GHashFunc hash_func, GCompareFunc equal_func);
index 14d9dcc..643af9b 100644 (file)
@@ -337,7 +337,7 @@ mono_locks_dump (gboolean include_untaken)
                                        to_recycle++;
                        } else {
                                if (!monitor_is_on_freelist ((MonoThreadsSync *)mon->data)) {
-                                       MonoObject *holder = (MonoObject *)mono_gchandle_get_target_internal ((guint32)(gsize)mon->data);
+                                       MonoObject *holder = (MonoObject *)mono_gchandle_get_target_internal ((MonoGCHandle)mon->data);
                                        if (mon_status_get_owner (mon->status)) {
                                                g_print ("Lock %p in object %p held by thread %d, nest level: %d\n",
                                                        mon, holder, mon_status_get_owner (mon->status), mon->nest);
@@ -399,7 +399,7 @@ mon_new (gsize id)
                new_ = NULL;
                for (marray = monitor_allocated; marray; marray = marray->next) {
                        for (i = 0; i < marray->num_monitors; ++i) {
-                               if (mono_gchandle_get_target_internal ((guint32)(gsize)marray->monitors [i].data) == NULL) {
+                               if (mono_gchandle_get_target_internal ((MonoGCHandle)marray->monitors [i].data) == NULL) {
                                        new_ = &marray->monitors [i];
                                        if (new_->wait_list) {
                                                /* Orphaned events left by aborted threads */
@@ -409,7 +409,7 @@ mon_new (gsize id)
                                                        new_->wait_list = g_slist_remove (new_->wait_list, new_->wait_list->data);
                                                }
                                        }
-                                       mono_gchandle_free_internal ((guint32)(gsize)new_->data);
+                                       mono_gchandle_free_internal ((MonoGCHandle)new_->data);
                                        new_->data = monitor_freelist;
                                        monitor_freelist = new_;
                                }
@@ -466,7 +466,7 @@ alloc_mon (MonoObject *obj, gint32 id)
 
        mono_monitor_allocator_lock ();
        mon = mon_new (id);
-       mon->data = (void *)(size_t)mono_gchandle_new_weakref_internal (obj, TRUE);
+       mon->data = mono_gchandle_new_weakref_internal (obj, TRUE);
        mono_monitor_allocator_unlock ();
 
        return mon;
@@ -476,7 +476,7 @@ static void
 discard_mon (MonoThreadsSync *mon)
 {
        mono_monitor_allocator_lock ();
-       mono_gchandle_free_internal ((guint32)(gsize)mon->data);
+       mono_gchandle_free_internal ((MonoGCHandle)mon->data);
        mon_finalize (mon);
        mono_monitor_allocator_unlock ();
 }
@@ -1132,7 +1132,7 @@ mono_monitor_exit (MonoObject *obj)
        MONO_EXTERNAL_ONLY_VOID (mono_monitor_exit_internal (obj));
 }
 
-guint32
+MonoGCHandle
 mono_monitor_get_object_monitor_gchandle (MonoObject *object)
 {
        LockWord lw;
@@ -1141,9 +1141,9 @@ mono_monitor_get_object_monitor_gchandle (MonoObject *object)
 
        if (lock_word_is_inflated (lw)) {
                MonoThreadsSync *mon = lock_word_get_inflated_lock (lw);
-               return (guint32)(gsize)mon->data;
+               return (MonoGCHandle)mon->data;
        }
-       return 0;
+       return NULL;
 }
 
 /*
index 711fe17..6b95a3e 100644 (file)
@@ -122,7 +122,7 @@ ICALL_EXTERN_C
 guint32
 mono_monitor_enter_v4_fast (MonoObject *obj, MonoBoolean *lock_taken);
 
-guint32
+MonoGCHandle
 mono_monitor_get_object_monitor_gchandle (MonoObject *object);
 
 void
index a3645c3..0b369ef 100644 (file)
@@ -585,7 +585,7 @@ struct _MonoInternalThread {
        MonoThreadName name;
        guint32     state;      /* must be accessed while longlived->synch_cs is locked */
        MonoException *abort_exc;
-       int abort_state_handle;
+       MonoGCHandle abort_state_handle;
        guint64 tid;    /* This is accessed as a gsize in the code (so it can hold a 64bit pointer on systems that need it), but needs to reserve 64 bits of space on all machines as it corresponds to a field in managed code */
        gsize debugger_thread; // FIXME switch to bool as soon as CI testing with corlib version bump works
        gpointer *static_data;
@@ -2327,17 +2327,17 @@ mono_runtime_get_aotid_arr (void);
  * mono_gchandle_get_target () can be used to get the object referenced by both kinds
  * of handle: for a weakref handle, if an object has been collected, it will return NULL.
  */
-uint32_t
+MonoGCHandle
 mono_gchandle_new_internal (MonoObject *obj, mono_bool pinned);
 
-uint32_t
+MonoGCHandle
 mono_gchandle_new_weakref_internal (MonoObject *obj, mono_bool track_resurrection);
 
 ICALL_EXTERN_C
 MonoObject*
-mono_gchandle_get_target_internal (uint32_t gchandle);
+mono_gchandle_get_target_internal (MonoGCHandle gchandle);
 
-void mono_gchandle_free_internal (uint32_t gchandle);
+void mono_gchandle_free_internal (MonoGCHandle gchandle);
 
 /* Reference queue support
  *
index f32dff9..5fbaeaf 100644 (file)
@@ -143,7 +143,7 @@ mono_runtime_object_init_handle (MonoObjectHandle this_obj, MonoError *error)
        g_assertf (method, "Could not lookup zero argument constructor for class %s", mono_type_get_full_name (klass));
 
        if (m_class_is_valuetype (method->klass)) {
-               guint gchandle = 0;
+               MonoGCHandle gchandle = NULL;
                gpointer raw = mono_object_handle_pin_unbox (this_obj, &gchandle);
                mono_runtime_invoke_checked (method, raw, NULL, error);
                mono_gchandle_free_internal (gchandle);
@@ -4144,7 +4144,7 @@ mono_nullable_init_from_handle (guint8 *buf, MonoObjectHandle value, MonoClass *
        MONO_REQ_GC_UNSAFE_MODE;
 
        if (!MONO_HANDLE_IS_NULL (value)) {
-               uint32_t value_gchandle = 0;
+               MonoGCHandle value_gchandle = NULL;
                gpointer src = mono_object_handle_pin_unbox (value, &value_gchandle);
                mono_nullable_init_unboxed (buf, src, klass);
 
@@ -6220,7 +6220,7 @@ mono_array_clone_in_domain (MonoDomain *domain, MonoArrayHandle array_handle, Mo
        error_init (error);
 
        /* Pin source array here - if bounds is non-NULL, it's a pointer into the object data */
-       uint32_t src_handle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, array_handle), TRUE);
+       MonoGCHandle src_handle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, array_handle), TRUE);
        
        MonoArrayBounds *array_bounds = MONO_HANDLE_GETVAL (array_handle, bounds);
        MonoArrayHandle o;
@@ -6243,7 +6243,7 @@ mono_array_clone_in_domain (MonoDomain *domain, MonoArrayHandle array_handle, Mo
                goto_if_nok (error, leave);
        }
 
-       uint32_t dst_handle;
+       MonoGCHandle dst_handle;
        dst_handle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, o), TRUE);
        array_full_copy_unchecked_size (MONO_HANDLE_RAW (array_handle), MONO_HANDLE_RAW (o), klass, size);
        mono_gchandle_free_internal (dst_handle);
index 0913311..c6f2d7f 100644 (file)
@@ -100,7 +100,7 @@ MonoReflectionTypeBuilderHandle
 mono_class_get_ref_info (MonoClass *klass)
 {
        MONO_REQ_GC_UNSAFE_MODE;
-       guint32 ref_info_handle = mono_class_get_ref_info_handle (klass);
+       MonoGCHandle ref_info_handle = mono_class_get_ref_info_handle (klass);
 
        if (ref_info_handle == 0)
                return MONO_HANDLE_NEW (MonoReflectionTypeBuilder, NULL);
@@ -119,7 +119,7 @@ mono_class_get_ref_info_raw (MonoClass *klass)
 {
        /* FIXME callers of mono_class_get_ref_info_raw should use handles */
        MONO_REQ_GC_UNSAFE_MODE;
-       guint32 ref_info_handle = mono_class_get_ref_info_handle (klass);
+       MonoGCHandle ref_info_handle = mono_class_get_ref_info_handle (klass);
 
        if (ref_info_handle == 0)
                return NULL;
@@ -131,8 +131,8 @@ mono_class_set_ref_info (MonoClass *klass, MonoObjectHandle obj)
 {
        MONO_REQ_GC_UNSAFE_MODE;
 
-       guint32 candidate = mono_gchandle_from_handle (obj, FALSE);
-       guint32 handle = mono_class_set_ref_info_handle (klass, candidate);
+       MonoGCHandle candidate = mono_gchandle_from_handle (obj, FALSE);
+       MonoGCHandle handle = mono_class_set_ref_info_handle (klass, candidate);
        ++class_ref_info_handle_count;
 
        if (handle != candidate)
@@ -143,7 +143,7 @@ void
 mono_class_free_ref_info (MonoClass *klass)
 {
        MONO_REQ_GC_NEUTRAL_MODE;
-       guint32 handle = mono_class_get_ref_info_handle (klass);
+       MonoGCHandle handle = mono_class_get_ref_info_handle (klass);
 
        if (handle) {
                mono_gchandle_free_internal (handle);
@@ -1312,7 +1312,7 @@ method_body_object_construct (MonoDomain *domain, MonoClass *unused_class, MonoM
        MonoArrayHandle il_arr;
        il_arr = mono_array_new_handle (domain, mono_defaults.byte_class, header->code_size, error);
        goto_if_nok (error, fail);
-       uint32_t il_gchandle;
+       MonoGCHandle il_gchandle;
        guint8* il_data;
        il_data = MONO_ARRAY_HANDLE_PIN (il_arr, guint8, 0, &il_gchandle);
        memcpy (il_data, header->code, header->code_size);
index 8e41325..78e8a9c 100644 (file)
@@ -2092,7 +2092,7 @@ mono_marshal_xdomain_copy_value_handle (MonoObjectHandle val, MonoError *error)
        case MONO_TYPE_U8:
        case MONO_TYPE_R4:
        case MONO_TYPE_R8: {
-               uint32_t gchandle = mono_gchandle_from_handle (val, TRUE);
+               MonoGCHandle gchandle = mono_gchandle_from_handle (val, TRUE);
                MonoObjectHandle res = MONO_HANDLE_NEW (MonoObject, mono_value_box_checked (domain, klass, ((char*)MONO_HANDLE_RAW (val)) + sizeof(MonoObject), error)); /* FIXME use handles in mono_value_box_checked */
                mono_gchandle_free_internal (gchandle);
                goto_if_nok (error, leave);
@@ -2101,7 +2101,7 @@ mono_marshal_xdomain_copy_value_handle (MonoObjectHandle val, MonoError *error)
        }
        case MONO_TYPE_STRING: {
                MonoStringHandle str = MONO_HANDLE_CAST (MonoString, val);
-               uint32_t gchandle = mono_gchandle_from_handle (val, TRUE);
+               MonoGCHandle gchandle = mono_gchandle_from_handle (val, TRUE);
                MonoStringHandle res = mono_string_new_utf16_handle (domain, mono_string_chars_internal (MONO_HANDLE_RAW (str)), mono_string_handle_length (str), error);
                mono_gchandle_free_internal (gchandle);
                goto_if_nok (error, leave);
index 79918f0..f298d6a 100644 (file)
@@ -781,7 +781,7 @@ clear_domain_process_object (GCObject *obj, MonoDomain *domain)
        remove = need_remove_object_for_domain (obj, domain);
 
        if (remove && obj->synchronisation) {
-               guint32 dislink = mono_monitor_get_object_monitor_gchandle (obj);
+               MonoGCHandle dislink = mono_monitor_get_object_monitor_gchandle (obj);
                if (dislink)
                        mono_gchandle_free_internal (dislink);
        }
@@ -2679,10 +2679,10 @@ sgen_client_metadata_for_object (GCObject *obj)
  *
  * \returns a handle that can be used to access the object from unmanaged code.
  */
-guint32
+MonoGCHandle
 mono_gchandle_new_internal (MonoObject *obj, gboolean pinned)
 {
-       return sgen_gchandle_new (obj, pinned);
+       return MONO_GC_HANDLE_FROM_UINT (sgen_gchandle_new (obj, pinned));
 }
 
 /**
@@ -2706,10 +2706,10 @@ mono_gchandle_new_internal (MonoObject *obj, gboolean pinned)
  * \returns a handle that can be used to access the object from
  * unmanaged code.
  */
-guint32
+MonoGCHandle
 mono_gchandle_new_weakref_internal (GCObject *obj, gboolean track_resurrection)
 {
-       return sgen_gchandle_new_weakref (obj, track_resurrection);
+       return MONO_GC_HANDLE_FROM_UINT (sgen_gchandle_new_weakref (obj, track_resurrection));
 }
 
 /**
@@ -2719,9 +2719,9 @@ mono_gchandle_new_weakref_internal (GCObject *obj, gboolean track_resurrection)
  * \returns TRUE if the object wrapped by the \p gchandle belongs to the specific \p domain.
  */
 gboolean
-mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
+mono_gchandle_is_in_domain (MonoGCHandle gchandle, MonoDomain *domain)
 {
-       MonoDomain *gchandle_domain = (MonoDomain *)sgen_gchandle_get_metadata (gchandle);
+       MonoDomain *gchandle_domain = (MonoDomain *)sgen_gchandle_get_metadata (MONO_GC_HANDLE_TO_UINT (gchandle));
        return domain->domain_id == gchandle_domain->domain_id;
 }
 
@@ -2734,9 +2734,9 @@ mono_gchandle_is_in_domain (guint32 gchandle, MonoDomain *domain)
  * object wrapped.
  */
 void
-mono_gchandle_free_internal (guint32 gchandle)
+mono_gchandle_free_internal (MonoGCHandle gchandle)
 {
-       sgen_gchandle_free (gchandle);
+       sgen_gchandle_free (MONO_GC_HANDLE_TO_UINT (gchandle));
 }
 
 /**
@@ -2762,9 +2762,9 @@ mono_gchandle_free_domain (MonoDomain *unloading)
  * NULL for a collected object if using a weakref handle.
  */
 MonoObject*
-mono_gchandle_get_target_internal (guint32 gchandle)
+mono_gchandle_get_target_internal (MonoGCHandle gchandle)
 {
-       return sgen_gchandle_get_target (gchandle);
+       return sgen_gchandle_get_target (MONO_GC_HANDLE_TO_UINT (gchandle));
 }
 
 static gpointer
@@ -2793,9 +2793,9 @@ sgen_null_links_for_domain (MonoDomain *domain)
 }
 
 void
-mono_gchandle_set_target (guint32 gchandle, MonoObject *obj)
+mono_gchandle_set_target (MonoGCHandle gchandle, MonoObject *obj)
 {
-       sgen_gchandle_set_target (gchandle, obj);
+       sgen_gchandle_set_target (MONO_GC_HANDLE_TO_UINT (gchandle), obj);
 }
 
 void
index 3df60f6..2ff00c2 100644 (file)
@@ -1007,7 +1007,7 @@ reflection_sighelper_get_signature_local (MonoReflectionSigHelperHandle sig, Mon
        MonoArrayHandle result;
        result = mono_array_new_handle (mono_domain_get (), mono_defaults.byte_class, buflen, error);
        goto_if_nok (error, fail);
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        void *base;
        base = MONO_ARRAY_HANDLE_PIN (result, char, 0, &gchandle);
        memcpy (base, buf.buf, buflen);
@@ -1043,7 +1043,7 @@ reflection_sighelper_get_signature_field (MonoReflectionSigHelperHandle sig, Mon
        MonoArrayHandle result;
        result = mono_array_new_handle (mono_domain_get (), mono_defaults.byte_class, buflen, error);
        goto_if_nok (error, fail);
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        void *base;
        base = MONO_ARRAY_HANDLE_PIN (result, char, 0, &gchandle);
        memcpy (base, buf.buf, buflen);
index e8121b2..afab61a 100644 (file)
@@ -1029,7 +1029,7 @@ mono_image_insert_string (MonoReflectionModuleBuilderHandle ref_module, MonoStri
                mono_metadata_encode_value (1 | (length * 2), b, &b);
                idx = mono_image_add_stream_data (&assembly->us, buf, b-buf);
                /* pinned */
-               uint32_t gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, str), TRUE);
+               MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, str), TRUE);
                const char *p = (const char*)mono_string_chars_internal (MONO_HANDLE_RAW (str));
 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
        {
@@ -4087,10 +4087,10 @@ free_dynamic_method (void *dynamic_method)
        DynamicMethodReleaseData *data = (DynamicMethodReleaseData *)dynamic_method;
        MonoDomain *domain = data->domain;
        MonoMethod *method = data->handle;
-       guint32 dis_link;
+       MonoGCHandle dis_link;
 
        mono_domain_lock (domain);
-       dis_link = (guint32)(size_t)g_hash_table_lookup (domain->method_to_dyn_method, method);
+       dis_link = g_hash_table_lookup (domain->method_to_dyn_method, method);
        g_hash_table_remove (domain->method_to_dyn_method, method);
        mono_domain_unlock (domain);
        g_assert (dis_link);
@@ -4228,7 +4228,7 @@ reflection_create_dynamic_method (MonoReflectionDynamicMethodHandle ref_mb, Mono
        mono_domain_lock (domain);
        if (!domain->method_to_dyn_method)
                domain->method_to_dyn_method = g_hash_table_new (NULL, NULL);
-       g_hash_table_insert (domain->method_to_dyn_method, handle, (gpointer)(size_t)mono_gchandle_new_weakref_internal ((MonoObject *)mb, TRUE));
+       g_hash_table_insert (domain->method_to_dyn_method, handle, mono_gchandle_new_weakref_internal ((MonoObject *)mb, TRUE));
        mono_domain_unlock (domain);
 
        return TRUE;
@@ -4674,7 +4674,7 @@ ves_icall_CustomAttributeBuilder_GetBlob (MonoReflectionAssemblyHandle assembly,
 void
 ves_icall_AssemblyBuilder_basic_init (MonoReflectionAssemblyBuilderHandle assemblyb, MonoError *error)
 {
-       uint32_t gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, assemblyb), TRUE);
+       MonoGCHandle gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, assemblyb), TRUE);
        mono_reflection_dynimage_basic_init (MONO_HANDLE_RAW (assemblyb), error);
        mono_gchandle_free_internal (gchandle);
 }
index 62d4a18..f49d21b 100644 (file)
@@ -855,7 +855,7 @@ mono_thread_attach_internal (MonoThread *thread, gboolean force_attach, gboolean
        MonoThreadInfo *info;
        MonoInternalThread *internal;
        MonoDomain *domain, *root_domain;
-       guint32 gchandle;
+       MonoGCHandle gchandle;
 
        g_assert (thread);
 
@@ -960,7 +960,7 @@ mono_thread_detach_internal (MonoInternalThread *thread)
        MonoThreadInfo *info;
        MonoInternalThread *value;
        gboolean removed;
-       guint32 gchandle;
+       MonoGCHandle gchandle;
 
        g_assert (mono_thread_internal_is_current (thread));
 
@@ -1663,7 +1663,7 @@ mono_thread_construct_internal (MonoThreadObjectHandle this_obj_handle)
 
        internal->state = ThreadState_Unstarted;
 
-       int const thread_gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, this_obj_handle), TRUE);
+       MonoGCHandle thread_gchandle = mono_gchandle_from_handle (MONO_HANDLE_CAST (MonoObject, this_obj_handle), TRUE);
 
        MonoThreadObject *this_obj = MONO_HANDLE_RAW (this_obj_handle);
 
@@ -2079,7 +2079,7 @@ byte_array_to_domain (MonoArrayHandle arr, MonoDomain *domain, MonoError *error)
        struct {
                MonoArrayHandle handle;
                gpointer p;
-               guint gchandle;
+               MonoGCHandle gchandle;
        }
        source = { arr },
        dest = { mono_array_new_handle (domain, mono_defaults.byte_class, size, error) };
@@ -3290,7 +3290,7 @@ mono_threads_register_app_context (MonoAppContextHandle ctx, MonoError *error)
        if (!context_queue)
                context_queue = mono_gc_reference_queue_new_internal (free_context);
 
-       gpointer gch = GUINT_TO_POINTER (mono_gchandle_new_weakref_from_handle (MONO_HANDLE_CAST (MonoObject, ctx)));
+       MonoGCHandle gch = mono_gchandle_new_weakref_from_handle (MONO_HANDLE_CAST (MonoObject, ctx));
        g_hash_table_insert (contexts, gch, gch);
 
        /*
@@ -3299,7 +3299,7 @@ mono_threads_register_app_context (MonoAppContextHandle ctx, MonoError *error)
         * handle in the reference queue callback.
         */
        ContextStaticData *data = g_new0 (ContextStaticData, 1);
-       data->gc_handle = GPOINTER_TO_UINT (gch);
+       data->gc_handle = gch;
        MONO_HANDLE_SETVAL (ctx, data, ContextStaticData*, data);
 
        context_adjust_static_data (ctx);
@@ -3373,7 +3373,7 @@ static void
 thread_detach (MonoThreadInfo *info)
 {
        MonoInternalThread *internal;
-       guint32 gchandle;
+       MonoGCHandle gchandle;
 
        /* If a delegate is passed to native code and invoked on a thread we dont
         * know about, marshal will register it with mono_threads_attach_coop, but
@@ -3970,7 +3970,7 @@ get_thread_dump (MonoThreadInfo *info, gpointer ud)
 typedef struct {
        int nthreads, max_threads;
 
-       guint32 *threads;
+       MonoGCHandle *threads;
 } CollectThreadsUserData;
 
 typedef struct {
@@ -3993,7 +3993,7 @@ collect_thread (gpointer key, gpointer value, gpointer user)
  * THREADS should be an array allocated on the stack.
  */
 static int
-collect_threads (guint32 *thread_handles, int max_threads)
+collect_threads (MonoGCHandle *thread_handles, int max_threads)
 {
        CollectThreadsUserData ud;
 
@@ -4100,7 +4100,7 @@ mono_threads_perform_thread_dump (void)
 {
        FILE* output_file = NULL;
        ThreadDumpUserData ud;
-       guint32 thread_array [128];
+       MonoGCHandle thread_array [128];
        int tindex, nthreads;
 
        if (!thread_dump_requested)
@@ -4132,7 +4132,7 @@ mono_threads_perform_thread_dump (void)
        ud.max_frames = 256;
 
        for (tindex = 0; tindex < nthreads; ++tindex) {
-               guint32 handle = thread_array [tindex];
+               MonoGCHandle handle = thread_array [tindex];
                MonoInternalThread *thread = (MonoInternalThread *) mono_gchandle_get_target_internal (handle);
                dump_thread (thread, &ud, output_file != NULL ? output_file : stdout);
                mono_gchandle_free_internal (handle);
@@ -4154,7 +4154,7 @@ ves_icall_System_Threading_Thread_GetStackTraces (MonoArrayHandleOut out_threads
        MONO_HANDLE_ASSIGN_RAW (out_threads_handle, NULL);
        MONO_HANDLE_ASSIGN_RAW (out_stack_frames_handle, NULL);
 
-       guint32 handle = 0;
+       MonoGCHandle handle = 0;
 
        MonoStackFrameHandle stack_frame_handle = MONO_HANDLE_NEW (MonoStackFrame, NULL);
        MonoReflectionMethodHandle reflection_method_handle = MONO_HANDLE_NEW (MonoReflectionMethod, NULL);
@@ -4162,7 +4162,7 @@ ves_icall_System_Threading_Thread_GetStackTraces (MonoArrayHandleOut out_threads
        MonoArrayHandle thread_frames_handle = MONO_HANDLE_NEW (MonoArray, NULL);
 
        ThreadDumpUserData ud;
-       guint32 thread_array [128];
+       MonoGCHandle thread_array [128];
        MonoDomain *domain = mono_domain_get ();
        MonoDebugSourceLocation *location;
        int tindex, nthreads;
@@ -4738,7 +4738,7 @@ alloc_thread_static_data_helper (gpointer key, gpointer value, gpointer user)
 static void
 alloc_context_static_data_helper (gpointer key, gpointer value, gpointer user)
 {
-       MonoAppContext *ctx = (MonoAppContext *) mono_gchandle_get_target_internal (GPOINTER_TO_INT (key));
+       MonoAppContext *ctx = (MonoAppContext *) mono_gchandle_get_target_internal ((MonoGCHandle)key);
 
        if (!ctx)
                return;
@@ -4894,7 +4894,7 @@ free_thread_static_data_helper (gpointer key, gpointer value, gpointer user)
 static void
 free_context_static_data_helper (gpointer key, gpointer value, gpointer user)
 {
-       MonoAppContext *ctx = (MonoAppContext *) mono_gchandle_get_target_internal (GPOINTER_TO_INT (key));
+       MonoAppContext *ctx = (MonoAppContext *) mono_gchandle_get_target_internal ((MonoGCHandle)key);
 
        if (!ctx)
                return;
index ea45fe7..dab4f5d 100644 (file)
@@ -538,7 +538,7 @@ ves_icall_System_IO_MonoIO_Read (HANDLE handle, MonoArrayHandle dest,
                return 0;
        }
 
-       guint32 buffer_handle = 0;
+       MonoGCHandle buffer_handle = NULL;
        buffer = MONO_ARRAY_HANDLE_PIN (dest, guchar, dest_offset, &buffer_handle);
        result = mono_w32file_read (handle, buffer, count, &n, io_error);
        mono_gchandle_free_internal (buffer_handle);
@@ -568,7 +568,7 @@ ves_icall_System_IO_MonoIO_Write (HANDLE handle, MonoArrayHandle src,
                return 0;
        }
        
-       guint32 src_handle = 0;
+       MonoGCHandle src_handle = NULL;
        buffer = MONO_ARRAY_HANDLE_PIN (src, guchar, src_offset, &src_handle);
        result = mono_w32file_write (handle, buffer, count, &n, io_error);
        mono_gchandle_free_internal (src_handle);
index 47deb48..e9bda36 100644 (file)
@@ -1814,7 +1814,7 @@ process_create (const gunichar2 *appname, const gunichar2 *cmdline,
                /* Copy each environ string into 'strings' turning it into utf8 (or the requested encoding) at the same time */
                for (gsize i = 0; i < array_length; ++i) {
                        MONO_HANDLE_ARRAY_GETREF (var, array, i);
-                       gchandle_t gchandle = 0;
+                       MonoGCHandle gchandle = NULL;
                        env_strings [i] = mono_unicode_to_external (mono_string_handle_pin_chars (var, &gchandle));
                        mono_gchandle_free_internal (gchandle);
                }
index 6920ac8..e03bf66 100644 (file)
@@ -136,7 +136,7 @@ mono_process_create_process (MonoCreateProcessCoop *coop, MonoW32ProcessInfo *mo
        PROCESS_INFORMATION *process_info)
 {
        gboolean result = FALSE;
-       gchandle_t cmd_gchandle = 0;
+       MonoGCHandle cmd_gchandle = NULL;
        gunichar2 *cmd_chars = MONO_HANDLE_IS_NULL (cmd) ? NULL : mono_string_handle_pin_chars (cmd, &cmd_gchandle);
 
        MONO_ENTER_GC_SAFE;
@@ -302,7 +302,7 @@ ves_icall_System_Diagnostics_Process_CreateProcess_internal (MonoW32ProcessStart
 
                for (gsize i = 0; i < array_length; i++) {
                        MONO_HANDLE_ARRAY_GETREF (var, array, i);
-                       gchandle_t gchandle = 0;
+                       MonoGCHandle gchandle = NULL;
                        memcpy (ptr, mono_string_handle_pin_chars (var, &gchandle), mono_string_handle_length (var) * sizeof (gunichar2));
                        mono_gchandle_free_internal (gchandle);
                        ptr += mono_string_handle_length (var);
index 7bb5d94..215fede 100644 (file)
@@ -615,7 +615,7 @@ ves_icall_System_Diagnostics_Process_GetProcessData (int pid, gint32 data_type,
 #if G_HAVE_API_SUPPORT(HAVE_CLASSIC_WINAPI_SUPPORT)
 
 static void
-mono_pin_string (MonoStringHandle in_coophandle, MonoStringHandle *out_coophandle, gunichar2 **chars, gsize *length, gchandle_t *gchandle)
+mono_pin_string (MonoStringHandle in_coophandle, MonoStringHandle *out_coophandle, gunichar2 **chars, gsize *length, MonoGCHandle *gchandle)
 {
        *out_coophandle = in_coophandle;
        if (!MONO_HANDLE_IS_NULL (in_coophandle)) {
@@ -644,7 +644,7 @@ mono_createprocess_coop_init (MonoCreateProcessCoop *coop, MonoW32ProcessStartIn
 }
 
 static void
-mono_unpin_array (gchandle_t *gchandles, gsize count)
+mono_unpin_array (MonoGCHandle *gchandles, gsize count)
 {
        for (gsize i = 0; i < count; ++i) {
                mono_gchandle_free_internal (gchandles [i]);
@@ -655,7 +655,7 @@ mono_unpin_array (gchandle_t *gchandles, gsize count)
 void
 mono_createprocess_coop_cleanup (MonoCreateProcessCoop *coop)
 {
-       mono_unpin_array ((gchandle_t*)&coop->gchandle, sizeof (coop->gchandle) / sizeof (gchandle_t));
+       mono_unpin_array ((MonoGCHandle*)&coop->gchandle, sizeof (coop->gchandle) / sizeof (MonoGCHandle));
        memset (coop, 0, sizeof (*coop));
 }
 
index ecf25da..4c512e0 100644 (file)
@@ -74,8 +74,6 @@ typedef struct
 
 TYPED_HANDLE_DECL (MonoW32ProcessStartInfo);
 
-typedef uint32_t gchandle_t; // FIXME use this more, make it typesafe.
-
 typedef struct _MonoCreateProcessCoop {
        gunichar2 *filename;
        gunichar2 *arguments;
@@ -92,12 +90,12 @@ typedef struct _MonoCreateProcessCoop {
                MonoStringHandle domain;
        } coophandle;
        struct {
-               gchandle_t filename;
-               gchandle_t arguments;
-               gchandle_t working_directory;
-               gchandle_t verb;
-               gchandle_t username;
-               gchandle_t domain;
+               MonoGCHandle filename;
+               MonoGCHandle arguments;
+               MonoGCHandle working_directory;
+               MonoGCHandle verb;
+               MonoGCHandle username;
+               MonoGCHandle domain;
        } gchandle;
        struct {
                gsize filename;
index 477a25d..d33caec 100644 (file)
@@ -1127,7 +1127,7 @@ create_sockaddr_from_handle (MonoObjectHandle saddr_obj, socklen_t *sa_size, gin
        len = MONO_HANDLE_GET_FIELD_VAL (saddr_obj, int, domain->sockaddr_data_length_field);
        g_assert (len >= 2);
 
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        guint8 *buf = MONO_ARRAY_HANDLE_PIN (data, guint8, 0, &gchandle);
        family = convert_family ((MonoAddressFamily)(buf[0] + (buf[1] << 8)));
        if (family == AF_INET) {
@@ -1901,7 +1901,7 @@ ves_icall_System_Net_Sockets_Socket_GetSocketOption_arr_icall (gsize sock, gint3
 
        valsize = mono_array_handle_length (byte_val);
 
-       uint32_t gchandle;
+       MonoGCHandle gchandle;
        guchar *buf = MONO_ARRAY_HANDLE_PIN (byte_val, guchar, 0, &gchandle);
 
        ret = mono_w32socket_getsockopt (sock, system_level, system_name, buf, &valsize);
@@ -2137,7 +2137,7 @@ ves_icall_System_Net_Sockets_Socket_SetSocketOption_icall (gsize sock, gint32 le
                }
        } else if (!MONO_HANDLE_IS_NULL (byte_val)) {
                int valsize = mono_array_handle_length (byte_val);
-               uint32_t gchandle;
+               MonoGCHandle gchandle;
                guchar *buf = MONO_ARRAY_HANDLE_PIN (byte_val, guchar, 0, &gchandle);
                
                switch(name) {
@@ -2254,8 +2254,8 @@ ves_icall_System_Net_Sockets_Socket_IOControl_icall (gsize sock, gint32 code, Mo
 #endif
        gchar *i_buffer, *o_buffer;
        gint i_len, o_len;
-       uint32_t i_gchandle = 0;
-       uint32_t o_gchandle = 0;
+       MonoGCHandle i_gchandle = 0;
+       MonoGCHandle o_gchandle = 0;
        gint ret;
 
        error_init (error);
@@ -2567,8 +2567,8 @@ ves_icall_System_Net_Sockets_Socket_SendFile_icall (gsize sock, MonoStringHandle
        HANDLE file;
        gboolean ret;
        TRANSMIT_FILE_BUFFERS buffers;
-       uint32_t pre_buffer_gchandle = 0;
-       uint32_t post_buffer_gchandle = 0;
+       MonoGCHandle pre_buffer_gchandle = 0;
+       MonoGCHandle post_buffer_gchandle = 0;
 
        error_init (error);
        *werror = 0;
@@ -2578,7 +2578,7 @@ ves_icall_System_Net_Sockets_Socket_SendFile_icall (gsize sock, MonoStringHandle
 
        /* FIXME: replace file by a proper fd that we can call open and close on, as they are interruptible */
 
-       uint32_t filename_gchandle;
+       MonoGCHandle filename_gchandle;
        gunichar2 *filename_chars = mono_string_handle_pin_chars (filename, &filename_gchandle);
        file = mono_w32file_create (filename_chars, GENERIC_READ, FILE_SHARE_READ, OPEN_EXISTING, 0);
        mono_gchandle_free_internal (filename_gchandle);
index d42e1db..85c3978 100644 (file)
@@ -203,7 +203,7 @@ typedef struct {
         * A weakref gc handle pointing to the object. The gc handle is used to 
         * detect if the object was garbage collected.
         */
-       guint32 handle;
+       MonoGCHandle handle;
 } ObjRef;
 
 
index 10bb182..010074f 100644 (file)
@@ -231,7 +231,7 @@ typedef struct {
        /* Clause that we are resuming to */
        MonoJitExceptionInfo *handler_ei;
        /* Exception that is being thrown. Set with rest of resume state */
-       guint32 exc_gchandle;
+       MonoGCHandle exc_gchandle;
        /* Stack of frame data */
        FrameStack data_stack;
 } ThreadContext;
index c8e7fde..ba51a35 100644 (file)
@@ -2176,12 +2176,12 @@ setup_stack_trace (MonoException *mono_ex, GSList **dynamic_methods, GList *trac
                        MonoMList *list = (MonoMList*)mono_ex->dynamic_methods;
 
                        for (l = *dynamic_methods; l; l = l->next) {
-                               guint32 dis_link;
+                               MonoGCHandle dis_link;
                                MonoDomain *domain = mono_domain_get ();
 
                                if (domain->method_to_dyn_method) {
                                        mono_domain_lock (domain);
-                                       dis_link = (guint32)(size_t)g_hash_table_lookup (domain->method_to_dyn_method, l->data);
+                                       dis_link = (MonoGCHandle)g_hash_table_lookup (domain->method_to_dyn_method, l->data);
                                        mono_domain_unlock (domain);
                                        if (dis_link) {
                                                MonoObject *o = mono_gchandle_get_target_internal (dis_link);
@@ -2815,7 +2815,7 @@ mono_handle_exception_internal (MonoContext *ctx, MonoObject *obj, gboolean resu
                }
 
                if (method->wrapper_type == MONO_WRAPPER_NATIVE_TO_MANAGED && ftnptr_eh_callback) {
-                       guint32 handle = mono_gchandle_new_internal (obj, FALSE);
+                       MonoGCHandle handle = mono_gchandle_new_internal (obj, FALSE);
                        MONO_STACKDATA (stackptr);
 
                        mono_threads_enter_gc_safe_region_unbalanced_internal (&stackptr);
index c89a46f..d755429 100644 (file)
@@ -111,12 +111,12 @@ struct MonoJitTlsData {
        /* 
         * The current exception in flight
         */
-       guint32 thrown_exc;
+       MonoGCHandle thrown_exc;
        /*
         * If the current exception is not a subclass of Exception,
         * the original exception.
         */
-       guint32 thrown_non_exc;
+       MonoGCHandle thrown_non_exc;
 
        /*
         * The calling assembly in llvmonly mode.
@@ -160,7 +160,7 @@ typedef struct {
 #endif
 } MonoLMFExt;
 
-typedef void (*MonoFtnPtrEHCallback) (guint32 gchandle);
+typedef void (*MonoFtnPtrEHCallback) (MonoGCHandle gchandle);
 
 typedef struct MonoDebugOptions {
        gboolean handle_sigint;
index 8de15c5..5373f28 100644 (file)
@@ -6,6 +6,7 @@
 #define __MONO_ERROR_INTERNALS_H__
 
 #include <mono/metadata/object-forward.h>
+#include <mono/utils/mono-forward.h>
 #include "mono/utils/mono-compiler.h"
 
 /*Keep in sync with MonoError*/
@@ -32,7 +33,7 @@ typedef union _MonoErrorInternal {
                        /* Valid if error_code == MONO_ERROR_EXCEPTION_INSTANCE.
                         * Generic error specified by a managed instance.
                         */
-                       uint32_t instance_handle;
+                       MonoGCHandle instance_handle;
                } exn;
                const char *full_message;
                const char *full_message_with_fields;
index 9f270f2..784f6e0 100644 (file)
@@ -10,4 +10,6 @@
 typedef struct _MonoDomain MonoDomain;
 typedef struct _MonoJitInfo MonoJitInfo;
 
+typedef void * MonoGCHandle;
+
 #endif
index fbf5618..a4cec2c 100644 (file)
@@ -468,7 +468,7 @@ register_thread (MonoThreadInfo *info)
        info->stack_end = staddr + stsize;
        info->stackdata = g_byte_array_new ();
 
-       info->internal_thread_gchandle = G_MAXUINT32;
+       info->internal_thread_gchandle = NULL;
 
        info->profiler_signal_ack = 1;
 
@@ -743,12 +743,12 @@ mono_thread_info_detach (void)
 }
 
 gboolean
-mono_thread_info_try_get_internal_thread_gchandle (MonoThreadInfo *info, guint32 *gchandle)
+mono_thread_info_try_get_internal_thread_gchandle (MonoThreadInfo *info, MonoGCHandle *gchandle)
 {
        g_assertf (info, ""); // f includes __func__
        g_assert (mono_thread_info_is_current (info));
 
-       if (info->internal_thread_gchandle == G_MAXUINT32)
+       if (info->internal_thread_gchandle == NULL)
                return FALSE;
 
        *gchandle = info->internal_thread_gchandle;
@@ -756,11 +756,10 @@ mono_thread_info_try_get_internal_thread_gchandle (MonoThreadInfo *info, guint32
 }
 
 void
-mono_thread_info_set_internal_thread_gchandle (MonoThreadInfo *info, guint32 gchandle)
+mono_thread_info_set_internal_thread_gchandle (MonoThreadInfo *info, MonoGCHandle gchandle)
 {
        g_assertf (info, ""); // f includes __func__
        g_assert (mono_thread_info_is_current (info));
-       g_assert (gchandle != G_MAXUINT32);
        info->internal_thread_gchandle = gchandle;
 }
 
@@ -769,7 +768,7 @@ mono_thread_info_unset_internal_thread_gchandle (THREAD_INFO_TYPE *info)
 {
        g_assertf (info, ""); // f includes __func__
        g_assert (mono_thread_info_is_current (info));
-       info->internal_thread_gchandle = G_MAXUINT32;
+       info->internal_thread_gchandle = NULL;
 }
 
 /*
index 335b2ea..1de863d 100644 (file)
@@ -267,7 +267,7 @@ typedef struct _MonoThreadInfo {
        gpointer stack_mark;
 
        /* GCHandle to MonoInternalThread */
-       guint32 internal_thread_gchandle;
+       MonoGCHandle internal_thread_gchandle;
 
        /*
         * Used by the sampling code in mini-posix.c to ensure that a thread has
@@ -430,10 +430,10 @@ MONO_API void
 mono_thread_info_detach (void);
 
 gboolean
-mono_thread_info_try_get_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 *gchandle);
+mono_thread_info_try_get_internal_thread_gchandle (THREAD_INFO_TYPE *info, MonoGCHandle *gchandle);
 
 void
-mono_thread_info_set_internal_thread_gchandle (THREAD_INFO_TYPE *info, guint32 gchandle);
+mono_thread_info_set_internal_thread_gchandle (THREAD_INFO_TYPE *info, MonoGCHandle gchandle);
 
 void
 mono_thread_info_unset_internal_thread_gchandle (THREAD_INFO_TYPE *info);