[runtime] Rename most System.Reflection.MonoX classes to RuntimeX for consistency...
[mono-project.git] / mono / metadata / external-only.c
blob8961def9833f676e7610de517666b74e283031e1
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 "object-internals.h"
16 #include "class-init.h"
17 #include "marshal.h"
18 #include "object.h"
20 /**
21 * mono_gchandle_new:
22 * \param obj managed object to get a handle for
23 * \param pinned whether the object should be pinned
24 * This returns a handle that wraps the object, this is used to keep a
25 * reference to a managed object from the unmanaged world and preventing the
26 * object from being disposed.
28 * If \p pinned is false the address of the object can not be obtained, if it is
29 * true the address of the object can be obtained. This will also pin the
30 * object so it will not be possible by a moving garbage collector to move the
31 * object.
33 * \returns a handle that can be used to access the object from unmanaged code.
35 uint32_t
36 mono_gchandle_new (MonoObject *obj, mono_bool pinned)
38 MONO_EXTERNAL_ONLY (uint32_t, mono_gchandle_new_internal (obj, pinned));
41 /**
42 * mono_gchandle_new_weakref:
43 * \param obj managed object to get a handle for
44 * \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.
46 * This returns a weak handle that wraps the object, this is used to
47 * keep a reference to a managed object from the unmanaged world.
48 * Unlike the \c mono_gchandle_new_internal the object can be reclaimed by the
49 * garbage collector. In this case the value of the GCHandle will be
50 * set to zero.
52 * If \p track_resurrection is TRUE the object will be tracked through
53 * finalization and if the object is resurrected during the execution
54 * of the finalizer, then the returned weakref will continue to hold
55 * a reference to the object. If \p track_resurrection is FALSE, then
56 * the weak reference's target will become NULL as soon as the object
57 * is passed on to the finalizer.
59 * \returns a handle that can be used to access the object from
60 * unmanaged code.
62 uint32_t
63 mono_gchandle_new_weakref (MonoObject *obj, mono_bool track_resurrection)
65 MONO_EXTERNAL_ONLY (uint32_t, mono_gchandle_new_weakref_internal (obj, track_resurrection));
68 /**
69 * mono_gchandle_get_target:
70 * \param gchandle a GCHandle's handle.
72 * The handle was previously created by calling \c mono_gchandle_new or
73 * \c mono_gchandle_new_weakref.
75 * \returns a pointer to the \c MonoObject* represented by the handle or
76 * NULL for a collected object if using a weakref handle.
78 MonoObject*
79 mono_gchandle_get_target (uint32_t gchandle)
81 MONO_EXTERNAL_ONLY (MonoObject*, mono_gchandle_get_target_internal (gchandle));
84 /**
85 * mono_gchandle_free:
86 * \param gchandle a GCHandle's handle.
88 * Frees the \p gchandle handle. If there are no outstanding
89 * references, the garbage collector can reclaim the memory of the
90 * object wrapped.
92 void
93 mono_gchandle_free (uint32_t gchandle)
95 MONO_EXTERNAL_ONLY_VOID (mono_gchandle_free_internal (gchandle));
98 /* GC write barriers support */
101 * mono_gc_wbarrier_set_field:
103 void
104 mono_gc_wbarrier_set_field (MonoObject *obj, void* field_ptr, MonoObject* value)
106 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_set_field_internal (obj, field_ptr, value));
110 * mono_gc_wbarrier_set_arrayref:
112 void
113 mono_gc_wbarrier_set_arrayref (MonoArray *arr, void* slot_ptr, MonoObject* value)
115 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_set_arrayref_internal (arr, slot_ptr, value));
118 void
119 mono_gc_wbarrier_arrayref_copy (void* dest_ptr, void* src_ptr, int count)
121 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_arrayref_copy_internal (dest_ptr, src_ptr, count));
125 * mono_gc_wbarrier_generic_store:
127 void
128 mono_gc_wbarrier_generic_store (void* ptr, MonoObject* value)
130 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_generic_store_internal (ptr, value));
134 * mono_gc_wbarrier_generic_store_atomic_internal:
135 * Same as \c mono_gc_wbarrier_generic_store but performs the store
136 * as an atomic operation with release semantics.
138 void
139 mono_gc_wbarrier_generic_store_atomic (void *ptr, MonoObject *value)
141 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_generic_store_atomic_internal (ptr, value));
144 void
145 mono_gc_wbarrier_generic_nostore (void* ptr)
147 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_generic_nostore_internal (ptr));
150 void
151 mono_gc_wbarrier_value_copy (void* dest, /*const*/ void* src, int count, MonoClass *klass)
153 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_value_copy_internal (dest, src, count, klass));
157 * mono_gc_wbarrier_object_copy:
159 * Write barrier to call when \p obj is the result of a clone or copy of an object.
161 void
162 mono_gc_wbarrier_object_copy (MonoObject* obj, MonoObject *src)
164 MONO_EXTERNAL_ONLY_VOID (mono_gc_wbarrier_object_copy_internal (obj, src));
168 * mono_class_init:
169 * \param klass the class to initialize
171 * Compute the \c instance_size, \c class_size and other infos that cannot be
172 * computed at \c mono_class_get time. Also compute vtable_size if possible.
173 * Initializes the following fields in \p klass:
174 * - all the fields initialized by \c mono_class_init_sizes
175 * - has_cctor
176 * - ghcimpl
177 * - inited
179 * LOCKING: Acquires the loader lock.
181 * \returns TRUE on success or FALSE if there was a problem in loading
182 * the type (incorrect assemblies, missing assemblies, methods, etc).
184 mono_bool
185 mono_class_init (MonoClass *klass)
187 MONO_EXTERNAL_ONLY_GC_UNSAFE (gboolean, mono_class_init_internal (klass));