Pass the --clr-memory-model flag on the command line instead of MONO_DEBUG so its...
[mono-project.git] / mono / metadata / external-only.c
blob290db63535e72d315117bd6939046a20b93d8c20
1 /**
2 * Functions that are in the (historical) embedding API
3 * but must not be used by the runtime. Often
4 * just a thin wrapper mono_foo => mono_foo_internal.
6 * Copyright 2018 Microsoft
7 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
8 */
10 // FIXME In order to confirm this is all extern_only,
11 // a variant of the runtime should be linked without it.
13 #include "config.h"
14 #include "class-internals.h"
15 #include "domain-internals.h"
16 #include "mono-hash-internals.h"
17 #include "mono-config-internals.h"
18 #include "object-internals.h"
19 #include "class-init.h"
20 #include "marshal.h"
21 #include "object.h"
23 /**
24 * mono_gchandle_new:
25 * \param obj managed object to get a handle for
26 * \param pinned whether the object should be pinned
27 * This returns a handle that wraps the object, this is used to keep a
28 * reference to a managed object from the unmanaged world and preventing the
29 * object from being disposed.
31 * If \p pinned is false the address of the object can not be obtained, if it is
32 * true the address of the object can be obtained. This will also pin the
33 * object so it will not be possible by a moving garbage collector to move the
34 * object.
36 * \returns a handle that can be used to access the object from unmanaged code.
38 uint32_t
39 mono_gchandle_new (MonoObject *obj, mono_bool pinned)
41 MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, mono_gchandle_new_internal (obj, pinned));
44 /**
45 * mono_gchandle_new_weakref:
46 * \param obj managed object to get a handle for
47 * \param track_resurrection Determines how long to track the object, if this is set to TRUE, the object is tracked after finalization, if FALSE, the object is only tracked up until the point of finalization.
49 * This returns a weak handle that wraps the object, this is used to
50 * keep a reference to a managed object from the unmanaged world.
51 * Unlike the \c mono_gchandle_new_internal the object can be reclaimed by the
52 * garbage collector. In this case the value of the GCHandle will be
53 * set to zero.
55 * If \p track_resurrection is TRUE the object will be tracked through
56 * finalization and if the object is resurrected during the execution
57 * of the finalizer, then the returned weakref will continue to hold
58 * a reference to the object. If \p track_resurrection is FALSE, then
59 * the weak reference's target will become NULL as soon as the object
60 * is passed on to the finalizer.
62 * \returns a handle that can be used to access the object from
63 * unmanaged code.
65 uint32_t
66 mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection)
68 MONO_EXTERNAL_ONLY_GC_UNSAFE (uint32_t, mono_gchandle_new_weakref_internal (obj, track_resurrection));
71 /**
72 * mono_gchandle_get_target:
73 * \param gchandle a GCHandle's handle.
75 * The handle was previously created by calling \c mono_gchandle_new or
76 * \c mono_gchandle_new_weakref.
78 * \returns a pointer to the \c MonoObject* represented by the handle or
79 * NULL for a collected object if using a weakref handle.
81 MonoObject*
82 mono_gchandle_get_target (uint32_t gchandle)
84 MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoObject*, mono_gchandle_get_target_internal (gchandle));
87 /**
88 * mono_gchandle_free:
89 * \param gchandle a GCHandle's handle.
91 * Frees the \p gchandle handle. If there are no outstanding
92 * references, the garbage collector can reclaim the memory of the
93 * object wrapped.
95 void
96 mono_gchandle_free (uint32_t gchandle)
98 /* Xamarin.Mac and Xamarin.iOS can call this from a worker thread
99 * that's not attached to the runtime. This is okay for SGen because
100 * the gchandle code is lockfree. SGen calls back into Mono which
101 * fires a profiler event, so the profiler must be prepared to be
102 * called from threads that aren't attached to Mono. */
103 MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal (gchandle));
106 /* GC write barriers support */
109 * mono_gc_wbarrier_set_field:
111 void
112 mono_gc_wbarrier_set_field (MonoObject *obj, void* field_ptr, MonoObject* value)
114 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_set_field_internal (obj, field_ptr, value));
118 * mono_gc_wbarrier_set_arrayref:
120 void
121 mono_gc_wbarrier_set_arrayref (MonoArray *arr, void* slot_ptr, MonoObject* value)
123 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_set_arrayref_internal (arr, slot_ptr, value));
126 void
127 mono_gc_wbarrier_arrayref_copy (void* dest_ptr, void* src_ptr, int count)
129 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_arrayref_copy_internal (dest_ptr, src_ptr, count));
133 * mono_gc_wbarrier_generic_store:
135 void
136 mono_gc_wbarrier_generic_store (void* ptr, MonoObject* value)
138 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_generic_store_internal (ptr, value));
142 * mono_gc_wbarrier_generic_store_atomic_internal:
143 * Same as \c mono_gc_wbarrier_generic_store but performs the store
144 * as an atomic operation with release semantics.
146 void
147 mono_gc_wbarrier_generic_store_atomic (void *ptr, MonoObject *value)
149 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_generic_store_atomic_internal (ptr, value));
152 void
153 mono_gc_wbarrier_generic_nostore (void* ptr)
155 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_generic_nostore_internal (ptr));
158 void
159 mono_gc_wbarrier_value_copy (void* dest, /*const*/ void* src, int count, MonoClass *klass)
161 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_value_copy_internal (dest, src, count, klass));
165 * mono_gc_wbarrier_object_copy:
167 * Write barrier to call when \p obj is the result of a clone or copy of an object.
169 void
170 mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
172 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_gc_wbarrier_object_copy_internal (obj, src));
176 * mono_class_init:
177 * \param klass the class to initialize
179 * Compute the \c instance_size, \c class_size and other infos that cannot be
180 * computed at \c mono_class_get time. Also compute vtable_size if possible.
181 * Initializes the following fields in \p klass:
182 * - all the fields initialized by \c mono_class_init_sizes
183 * - has_cctor
184 * - ghcimpl
185 * - inited
187 * LOCKING: Acquires the loader lock.
189 * \returns TRUE on success or FALSE if there was a problem in loading
190 * the type (incorrect assemblies, missing assemblies, methods, etc).
192 mono_bool
193 mono_class_init (MonoClass *klass)
195 MONO_EXTERNAL_ONLY_GC_UNSAFE (gboolean, mono_class_init_internal (klass));
199 * mono_g_hash_table_new_type:
201 MonoGHashTable*
202 mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, MonoGHashGCType type, MonoGCRootSource source, void *key, const char *msg)
204 MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoGHashTable*, mono_g_hash_table_new_type_internal (hash_func, key_equal_func, type, source, key, msg));
208 * mono_config_for_assembly:
210 void
211 mono_config_for_assembly (MonoImage *assembly)
213 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_config_for_assembly_internal (assembly));
217 * mono_class_get_property_from_name:
218 * \param klass a class
219 * \param name name of the property to lookup in the specified class
221 * Use this method to lookup a property in a class
222 * \returns the \c MonoProperty with the given name, or NULL if the property
223 * does not exist on the \p klass.
225 MonoProperty*
226 mono_class_get_property_from_name (MonoClass *klass, const char *name)
228 MONO_EXTERNAL_ONLY_GC_UNSAFE (MonoProperty*, mono_class_get_property_from_name_internal (klass, name));
232 * mono_class_is_subclass_of:
233 * \param klass class to probe if it is a subclass of another one
234 * \param klassc the class we suspect is the base class
235 * \param check_interfaces whether we should perform interface checks
237 * This method determines whether \p klass is a subclass of \p klassc.
239 * If the \p check_interfaces flag is set, then if \p klassc is an interface
240 * this method return TRUE if the \p klass implements the interface or
241 * if \p klass is an interface, if one of its base classes is \p klass.
243 * If \p check_interfaces is false, then if \p klass is not an interface,
244 * it returns TRUE if the \p klass is a subclass of \p klassc.
246 * if \p klass is an interface and \p klassc is \c System.Object, then this function
247 * returns TRUE.
250 gboolean
251 mono_class_is_subclass_of (MonoClass *klass, MonoClass *klassc, gboolean check_interfaces)
253 MONO_EXTERNAL_ONLY_GC_UNSAFE (gboolean, mono_class_is_subclass_of_internal (klass, klassc, check_interfaces));
257 * mono_domain_set_internal:
258 * \param domain the new domain
260 * Sets the current domain to \p domain.
262 void
263 mono_domain_set_internal (MonoDomain *domain)
265 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_domain_set_internal_with_options (domain, TRUE));
269 * mono_domain_set:
270 * \param domain domain
271 * \param force force setting.
273 * Set the current appdomain to \p domain. If \p force is set, set it even
274 * if it is being unloaded.
276 * \returns TRUE on success; FALSE if the domain is unloaded
278 gboolean
279 mono_domain_set (MonoDomain *domain, gboolean force)
281 if (!force && domain->state == MONO_APPDOMAIN_UNLOADED)
282 return FALSE;
284 MONO_EXTERNAL_ONLY_GC_UNSAFE_VOID (mono_domain_set_internal_with_options (domain, TRUE));
285 return TRUE;