From 3886a63841434af716292172737a42757a15c6a6 Mon Sep 17 00:00:00 2001 From: Ryan Lucia Date: Thu, 23 Apr 2020 08:36:16 -0400 Subject: [PATCH] [meta] Add GCHandle embedding API v2 with pointer-sized handles (#35197) --- src/mono/mono/metadata/external-only.c | 24 ++++++++++++++++++++++++ src/mono/mono/metadata/object.h | 5 +++++ 2 files changed, 29 insertions(+) diff --git a/src/mono/mono/metadata/external-only.c b/src/mono/mono/metadata/external-only.c index 8e3c782..0ccb35a 100644 --- a/src/mono/mono/metadata/external-only.c +++ b/src/mono/mono/metadata/external-only.c @@ -45,6 +45,12 @@ mono_gchandle_new (MonoObject *obj, mono_bool pinned) MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, (uint32_t)(size_t)mono_gchandle_new_internal (obj, pinned)); } +MonoGCHandle +mono_gchandle_new_v2 (MonoObject *obj, mono_bool pinned) +{ + MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoGCHandle, mono_gchandle_new_internal (obj, pinned)); +} + /** * mono_gchandle_new_weakref: * \param obj managed object to get a handle for @@ -72,6 +78,12 @@ mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection) MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, (uint32_t)(size_t)mono_gchandle_new_weakref_internal (obj, track_resurrection)); } +MonoGCHandle +mono_gchandle_new_weakref_v2 (MonoObject *obj, mono_bool track_resurrection) +{ + MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoGCHandle, mono_gchandle_new_weakref_internal (obj, track_resurrection)); +} + /** * mono_gchandle_get_target: * \param gchandle a GCHandle's handle. @@ -88,6 +100,12 @@ mono_gchandle_get_target (uint32_t gchandle) MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoObject*, mono_gchandle_get_target_internal ((MonoGCHandle)(size_t)gchandle)); } +MonoObject* +mono_gchandle_get_target_v2 (MonoGCHandle gchandle) +{ + MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoObject*, mono_gchandle_get_target_internal (gchandle)); +} + /** * mono_gchandle_free: * \param gchandle a GCHandle's handle. @@ -107,6 +125,12 @@ mono_gchandle_free (uint32_t gchandle) MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal ((MonoGCHandle)(size_t)gchandle)); } +void +mono_gchandle_free_v2 (MonoGCHandle gchandle) +{ + MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal (gchandle)); +} + /* GC write barriers support */ /** diff --git a/src/mono/mono/metadata/object.h b/src/mono/mono/metadata/object.h index da19d3d..f421c6c 100644 --- a/src/mono/mono/metadata/object.h +++ b/src/mono/mono/metadata/object.h @@ -372,6 +372,11 @@ MONO_API MONO_RT_EXTERNAL_ONLY uint32_t mono_gchandle_new_weakref (MonoObjec MONO_API MONO_RT_EXTERNAL_ONLY MonoObject* mono_gchandle_get_target (uint32_t gchandle); MONO_API MONO_RT_EXTERNAL_ONLY void mono_gchandle_free (uint32_t gchandle); +MONO_API MONO_RT_EXTERNAL_ONLY MonoGCHandle mono_gchandle_new_v2 (MonoObject *obj, mono_bool pinned); +MONO_API MONO_RT_EXTERNAL_ONLY MonoGCHandle mono_gchandle_new_weakref_v2 (MonoObject *obj, mono_bool track_resurrection); +MONO_API MONO_RT_EXTERNAL_ONLY MonoObject* mono_gchandle_get_target_v2 (MonoGCHandle gchandle); +MONO_API MONO_RT_EXTERNAL_ONLY void mono_gchandle_free_v2 (MonoGCHandle gchandle); + /* Reference queue support * * A reference queue is used to get notifications of when objects are collected. -- 2.7.4