[2020-02] Fix leak in assembly-specific dllmap lookups (#21053)
[mono-project.git] / mono / metadata / object-internals.h
blob4e4378302b96c3b8fe0386b8fdaf4e43f07ef6f8
1 /**
2 * \file
3 */
5 #ifndef __MONO_OBJECT_INTERNALS_H__
6 #define __MONO_OBJECT_INTERNALS_H__
8 #include <mono/utils/mono-forward-internal.h>
9 #include <mono/metadata/object-forward.h>
10 #include <mono/metadata/handle-decl.h>
12 #include <mono/metadata/object.h>
13 #include <mono/metadata/threads.h>
14 #include <mono/metadata/reflection.h>
15 #include <mono/metadata/mempool.h>
16 #include <mono/metadata/class-internals.h>
17 #include <mono/metadata/threads-types.h>
18 #include <mono/metadata/handle.h>
19 #include <mono/metadata/abi-details.h>
20 #include "mono/utils/mono-compiler.h"
21 #include "mono/utils/mono-error.h"
22 #include "mono/utils/mono-error-internals.h"
23 #include "mono/utils/mono-machine.h"
24 #include "mono/utils/mono-stack-unwinding.h"
25 #include "mono/utils/mono-tls.h"
26 #include "mono/utils/mono-coop-mutex.h"
27 #include <mono/metadata/icalls.h>
29 /* Use this as MONO_CHECK_ARG (arg,expr,) in functions returning void */
30 #define MONO_CHECK_ARG(arg, expr, retval) do { \
31 if (G_UNLIKELY (!(expr))) \
32 { \
33 if (0) { (void)(arg); } /* check if the name exists */ \
34 ERROR_DECL (error); \
35 mono_error_set_argument_format (error, #arg, "assertion `%s' failed", #expr); \
36 mono_error_set_pending_exception (error); \
37 return retval; \
38 } \
39 } while (0)
41 #define MONO_CHECK_ARG_NULL_NAMED(arg, argname, retval) do { \
42 if (G_UNLIKELY (!(arg))) \
43 { \
44 ERROR_DECL (error); \
45 mono_error_set_argument_null (error, (argname), ""); \
46 mono_error_set_pending_exception (error); \
47 return retval; \
48 } \
49 } while (0)
50 /* Use this as MONO_CHECK_ARG_NULL (arg,) in functions returning void */
51 #define MONO_CHECK_ARG_NULL(arg, retval) do { \
52 if (G_UNLIKELY (!(arg))) \
53 { \
54 mono_error_set_argument_null (error, #arg, ""); \
55 return retval; \
56 } \
57 } while (0)
59 /* Use this as MONO_CHECK_ARG_NULL_HANDLE (arg,) in functions returning void */
60 #define MONO_CHECK_ARG_NULL_HANDLE(arg, retval) do { \
61 if (G_UNLIKELY (MONO_HANDLE_IS_NULL (arg))) \
62 { \
63 mono_error_set_argument_null (error, #arg, ""); \
64 return retval; \
65 } \
66 } while (0)
68 #define MONO_CHECK_ARG_NULL_HANDLE_NAMED(arg, argname, retval) do { \
69 if (G_UNLIKELY (MONO_HANDLE_IS_NULL (arg))) \
70 { \
71 mono_error_set_argument_null (error, (argname), ""); \
72 return retval; \
73 } \
74 } while (0)
76 /* Use this as MONO_CHECK_NULL (arg,) in functions returning void */
77 #define MONO_CHECK_NULL(arg, retval) do { \
78 if (G_UNLIKELY (!(arg))) \
79 { \
80 ERROR_DECL (error); \
81 mono_error_set_null_reference (error); \
82 mono_error_set_pending_exception (error); \
83 return retval; \
84 } \
85 } while (0)
87 MonoClass *
88 mono_class_create_array (MonoClass *element_class, uint32_t rank);
90 MonoArrayHandle
91 mono_array_new_specific_handle (MonoVTable *vtable, uintptr_t n, MonoError *error);
93 MonoArray*
94 mono_array_new_specific_checked (MonoVTable *vtable, uintptr_t n, MonoError *error);
96 /*
97 * Macros which cache.
98 * These should be used instead of the original versions.
101 static inline MonoClass*
102 mono_array_class_get_cached_function (MonoClass *eclass, MonoClass **aclass)
104 MonoClass *a = *aclass;
105 if (a)
106 return a;
107 a = mono_class_create_array (eclass, 1);
108 g_assert (a);
109 if (a)
110 *aclass = a;
111 return *aclass;
114 // eclass should be a run-time constant
115 // If you get an error using this macro, you need to manually instantiate the MonoClass *foo ## _array cache.
116 // See for example object_class_array.
117 #define mono_array_class_get_cached(eclass) (mono_array_class_get_cached_function ((eclass), &(eclass ## _array)))
119 static inline MonoArray*
120 mono_array_new_cached_function (MonoDomain *domain, MonoClass *aclass, int size, MonoError *error)
122 MonoVTable *vtable = mono_class_vtable_checked (domain, aclass, error);
123 MonoArray *arr = NULL;
124 if (is_ok (error))
125 arr = mono_array_new_specific_checked (vtable, size, error);
126 return arr;
129 // eclass should be a run-time constant
130 // If you get an error using this macro, you need to manually instantiate the MonoClass *foo ## _array cache.
131 // See for example object_class_array.
132 #define mono_array_new_cached(domain, eclass, size, error) \
133 mono_array_new_cached_function ((domain), mono_array_class_get_cached (eclass), (size), (error))
135 static inline MonoArrayHandle
136 mono_array_new_cached_handle_function (MonoDomain *domain, MonoClass *aclass, int size, MonoError *error)
138 MonoVTable *vtable = mono_class_vtable_checked (domain, aclass, error);
139 MonoArrayHandle arr = NULL_HANDLE_ARRAY;
140 if (is_ok (error))
141 arr = mono_array_new_specific_handle (vtable, size, error);
142 return arr;
145 // eclass should be a run-time constant
146 // If you get an error using this macro, you need to manually instantiate the MonoClass *foo ## _array cache.
147 // See for example object_class_array.
148 #define mono_array_new_cached_handle(domain, eclass, size, error) \
149 mono_array_new_cached_handle_function ((domain), mono_array_class_get_cached (eclass), (size), (error))
151 #ifdef MONO_BIG_ARRAYS
152 typedef uint64_t mono_array_size_t;
153 typedef int64_t mono_array_lower_bound_t;
154 #define MONO_ARRAY_MAX_INDEX G_MAXINT64
155 #define MONO_ARRAY_MAX_SIZE G_MAXUINT64
156 #else
157 typedef uint32_t mono_array_size_t;
158 typedef int32_t mono_array_lower_bound_t;
159 #define MONO_ARRAY_MAX_INDEX ((int32_t) 0x7fffffff)
160 #define MONO_ARRAY_MAX_SIZE ((uint32_t) 0xffffffff)
161 #endif
163 typedef struct {
164 mono_array_size_t length;
165 mono_array_lower_bound_t lower_bound;
166 } MonoArrayBounds;
168 struct _MonoArray {
169 MonoObject obj;
170 /* bounds is NULL for szarrays */
171 MonoArrayBounds *bounds;
172 /* total number of elements of the array */
173 mono_array_size_t max_length;
174 /* we use mono_64bitaligned_t to ensure proper alignment on platforms that need it */
175 mono_64bitaligned_t vector [MONO_ZERO_LEN_ARRAY];
178 #define MONO_SIZEOF_MONO_ARRAY (MONO_STRUCT_OFFSET (MonoArray, vector))
180 struct _MonoString {
181 MonoObject object;
182 int32_t length;
183 mono_unichar2 chars [MONO_ZERO_LEN_ARRAY];
186 #define MONO_SIZEOF_MONO_STRING (MONO_STRUCT_OFFSET (MonoString, chars))
188 #define mono_object_class(obj) (((MonoObject*)(obj))->vtable->klass)
189 #define mono_object_domain(obj) (((MonoObject*)(obj))->vtable->domain)
191 #define mono_string_chars_fast(s) ((mono_unichar2*)(s)->chars)
192 #define mono_string_length_fast(s) ((s)->length)
195 * mono_array_length_internal:
196 * \param array a \c MonoArray*
197 * \returns the total number of elements in the array. This works for
198 * both vectors and multidimensional arrays.
200 #define mono_array_length_internal(array) ((array)->max_length)
202 static inline
203 uintptr_t
204 mono_array_handle_length (MonoArrayHandle arr)
206 MONO_REQ_GC_UNSAFE_MODE;
208 return mono_array_length_internal (MONO_HANDLE_RAW (arr));
211 // Equivalent to mono_array_addr_with_size, except:
212 // 1. A macro instead of a function -- the types of size and index are open.
213 // 2. mono_array_addr_with_size could, but does not, do GC mode transitions.
214 #define mono_array_addr_with_size_fast(array,size,index) ( ((char*)(array)->vector) + (size) * (index) )
216 #define mono_array_addr_fast(array,type,index) ((type*)(void*) mono_array_addr_with_size_fast (array, sizeof (type), index))
217 #define mono_array_get_fast(array,type,index) ( *(type*)mono_array_addr_fast ((array), type, (index)) )
218 #define mono_array_set_fast(array,type,index,value) \
219 do { \
220 type *__p = (type *) mono_array_addr_fast ((array), type, (index)); \
221 *__p = (value); \
222 } while (0)
223 #define mono_array_setref_fast(array,index,value) \
224 do { \
225 void **__p = (void **) mono_array_addr_fast ((array), void*, (index)); \
226 mono_gc_wbarrier_set_arrayref_internal ((array), __p, (MonoObject*)(value)); \
227 /* *__p = (value);*/ \
228 } while (0)
229 #define mono_array_memcpy_refs_fast(dest,destidx,src,srcidx,count) \
230 do { \
231 void **__p = (void **) mono_array_addr_fast ((dest), void*, (destidx)); \
232 void **__s = mono_array_addr_fast ((src), void*, (srcidx)); \
233 mono_gc_wbarrier_arrayref_copy_internal (__p, __s, (count)); \
234 } while (0)
236 // _internal is like _fast, but preserves the preexisting subtlety of the closed types of things:
237 // int size
238 // uintptr_t idx
239 // in order to mimic non-_internal but without the GC mode transitions, or at least,
240 // to avoid the runtime using the embedding API, whether or not it has GC mode transitions.
241 static inline char*
242 mono_array_addr_with_size_internal (MonoArray *array, int size, uintptr_t idx)
244 return mono_array_addr_with_size_fast (array, size, idx);
247 #define mono_array_addr_internal(array,type,index) ((type*)(void*) mono_array_addr_with_size_internal (array, sizeof (type), index))
248 #define mono_array_get_internal(array,type,index) ( *(type*)mono_array_addr_internal ((array), type, (index)) )
249 #define mono_array_set_internal(array,type,index,value) \
250 do { \
251 type *__p = (type *) mono_array_addr_internal ((array), type, (index)); \
252 *__p = (value); \
253 } while (0)
254 #define mono_array_setref_internal(array,index,value) \
255 do { \
256 void **__p = (void **) mono_array_addr_internal ((array), void*, (index)); \
257 mono_gc_wbarrier_set_arrayref_internal ((array), __p, (MonoObject*)(value)); \
258 /* *__p = (value);*/ \
259 } while (0)
260 #define mono_array_memcpy_refs_internal(dest,destidx,src,srcidx,count) \
261 do { \
262 void **__p = (void **) mono_array_addr_internal ((dest), void*, (destidx)); \
263 void **__s = mono_array_addr_internal ((src), void*, (srcidx)); \
264 mono_gc_wbarrier_arrayref_copy_internal (__p, __s, (count)); \
265 } while (0)
267 static inline gboolean
268 mono_handle_array_has_bounds (MonoArrayHandle arr)
270 return MONO_HANDLE_GETVAL (arr, bounds) != NULL;
273 static inline void
274 mono_handle_array_get_bounds_dim (MonoArrayHandle arr, gint32 dim, MonoArrayBounds *bounds)
276 *bounds = MONO_HANDLE_GETVAL (arr, bounds [dim]);
279 typedef struct {
280 MonoObject obj;
281 #ifndef ENABLE_NETCORE
282 MonoObject *identity;
283 #endif
284 } MonoMarshalByRefObject;
286 TYPED_HANDLE_DECL (MonoMarshalByRefObject);
288 /* This is a copy of System.AppDomain */
289 struct _MonoAppDomain {
290 MonoMarshalByRefObject mbr;
291 MonoDomain *data;
294 /* Safely access System.AppDomain from native code */
295 TYPED_HANDLE_DECL (MonoAppDomain);
297 /* Safely access System.AppDomainSetup from native code. (struct is in domain-internals.h) */
298 TYPED_HANDLE_DECL (MonoAppDomainSetup);
300 typedef struct _MonoStringBuilder MonoStringBuilder;
301 TYPED_HANDLE_DECL (MonoStringBuilder);
303 struct _MonoStringBuilder {
304 MonoObject object;
305 MonoArray *chunkChars;
306 MonoStringBuilder* chunkPrevious; // Link to the block logically before this block
307 int chunkLength; // The index in ChunkChars that represent the end of the block
308 int chunkOffset; // The logial offset (sum of all characters in previous blocks)
309 int maxCapacity;
312 static inline int
313 mono_string_builder_capacity (MonoStringBuilderHandle sbh)
315 MonoStringBuilder *sb = MONO_HANDLE_RAW (sbh);
316 return sb->chunkOffset + sb->chunkChars->max_length;
319 static inline int
320 mono_string_builder_string_length (MonoStringBuilderHandle sbh)
322 MonoStringBuilder *sb = MONO_HANDLE_RAW (sbh);
323 return sb->chunkOffset + sb->chunkLength;
326 typedef struct {
327 MonoType *type;
328 gpointer value;
329 MonoClass *klass;
330 } MonoTypedRef;
332 typedef struct {
333 gpointer args;
334 } MonoArgumentHandle;
336 typedef struct {
337 MonoMethodSignature *sig;
338 gpointer args;
339 gint32 next_arg;
340 gint32 num_args;
341 } MonoArgIterator;
343 struct _MonoException {
344 MonoObject object;
345 MonoString *class_name;
346 MonoString *message;
347 MonoObject *_data;
348 MonoObject *inner_ex;
349 MonoString *help_link;
350 /* Stores the IPs and the generic sharing infos
351 (vtable/MRGCTX) of the frames. */
352 MonoArray *trace_ips;
353 MonoString *stack_trace;
354 MonoString *remote_stack_trace;
355 gint32 remote_stack_index;
356 /* Dynamic methods referenced by the stack trace */
357 MonoObject *dynamic_methods;
358 gint32 hresult;
359 MonoString *source;
360 MonoObject *serialization_manager;
361 MonoObject *captured_traces;
362 MonoArray *native_trace_ips;
363 gint32 caught_in_unmanaged;
366 typedef struct {
367 MonoException base;
368 } MonoSystemException;
370 TYPED_HANDLE_DECL (MonoSystemException);
372 #ifndef ENABLE_NETCORE
373 typedef struct {
374 MonoSystemException base;
375 MonoString *param_name;
376 } MonoArgumentException;
377 #endif
379 typedef struct {
380 MonoObject object;
381 MonoObject *async_state;
382 MonoObject *handle;
383 MonoObject *async_delegate;
384 gpointer *data;
385 MonoObject *object_data;
386 MonoBoolean sync_completed;
387 MonoBoolean completed;
388 MonoBoolean endinvoke_called;
389 MonoObject *async_callback;
390 MonoObject *execution_context;
391 MonoObject *original_context;
392 gint64 add_time;
393 } MonoAsyncResult;
395 TYPED_HANDLE_DECL (MonoAsyncResult);
397 typedef struct {
398 MonoMarshalByRefObject object;
399 gpointer handle;
400 } MonoWaitHandle;
402 TYPED_HANDLE_DECL (MonoWaitHandle);
404 /* This is a copy of System.Runtime.Remoting.Messaging.CallType */
405 typedef enum {
406 CallType_Sync = 0,
407 CallType_BeginInvoke = 1,
408 CallType_EndInvoke = 2,
409 CallType_OneWay = 3
410 } MonoCallType;
412 /* System.Threading.StackCrawlMark */
414 * This type is used to identify the method where execution has entered
415 * the BCL during stack walks. The outermost public method should
416 * define it like this:
417 * StackCrawlMark stackMark = StackCrawlMark.LookForMyCaller;
418 * and pass the stackMark as a byref argument down the call chain
419 * until it reaches an icall.
421 typedef enum {
422 STACK_CRAWL_ME = 0,
423 STACK_CRAWL_CALLER = 1,
424 STACK_CRAWL_CALLERS_CALLER = 2,
425 STACK_CRAWL_THREAD = 3
426 } MonoStackCrawlMark;
428 /* MonoSafeHandle is in class-internals.h. */
429 /* Safely access System.Net.Sockets.SafeSocketHandle from native code */
430 TYPED_HANDLE_DECL (MonoSafeHandle);
432 /* This corresponds to System.Type */
433 struct _MonoReflectionType {
434 MonoObject object;
435 MonoType *type;
438 /* Safely access System.Type from native code */
439 TYPED_HANDLE_DECL (MonoReflectionType);
441 typedef struct {
442 MonoObject object;
443 MonoReflectionType *class_to_proxy;
444 MonoObject *context;
445 MonoObject *unwrapped_server;
446 gint32 target_domain_id;
447 MonoString *target_uri;
448 MonoObject *object_identity;
449 MonoObject *obj_TP;
450 MonoObject *stub_data;
451 } MonoRealProxy;
453 /* Safely access System.Runtime.Remoting.Proxies.RealProxy from native code */
454 TYPED_HANDLE_DECL (MonoRealProxy);
456 typedef struct _MonoIUnknown MonoIUnknown;
457 typedef struct _MonoIUnknownVTable MonoIUnknownVTable;
459 /* STDCALL on windows, CDECL everywhere else to work with XPCOM and MainWin COM */
460 #ifdef HOST_WIN32
461 #define STDCALL __stdcall
462 #else
463 #define STDCALL
464 #endif
466 struct _MonoIUnknownVTable
468 int (STDCALL *QueryInterface)(MonoIUnknown *pUnk, gconstpointer riid, gpointer* ppv);
469 int (STDCALL *AddRef)(MonoIUnknown *pUnk);
470 int (STDCALL *Release)(MonoIUnknown *pUnk);
473 struct _MonoIUnknown
475 const MonoIUnknownVTable *vtable;
478 typedef struct {
479 MonoMarshalByRefObject object;
480 MonoIUnknown *iunknown;
481 GHashTable* itf_hash;
482 MonoObject *synchronization_context;
483 } MonoComObject;
485 TYPED_HANDLE_DECL (MonoComObject);
487 typedef struct {
488 MonoRealProxy real_proxy;
489 MonoComObject *com_object;
490 gint32 ref_count;
491 } MonoComInteropProxy;
493 TYPED_HANDLE_DECL (MonoComInteropProxy);
495 typedef struct {
496 MonoObject object;
497 MonoRealProxy *rp;
498 MonoRemoteClass *remote_class;
499 MonoBoolean custom_type_info;
500 } MonoTransparentProxy;
502 /* Safely access System.Runtime.Remoting.Proxies.TransparentProxy from native code */
503 TYPED_HANDLE_DECL (MonoTransparentProxy);
505 typedef struct {
506 MonoObject obj;
507 MonoReflectionMethod *method;
508 MonoArray *args;
509 MonoArray *names;
510 MonoArray *arg_types;
511 MonoObject *ctx;
512 MonoObject *rval;
513 MonoObject *exc;
514 MonoAsyncResult *async_result;
515 guint32 call_type;
516 } MonoMethodMessage;
518 TYPED_HANDLE_DECL (MonoMethodMessage);
520 /* Keep in sync with the System.MonoAsyncCall */
521 typedef struct {
522 MonoObject object;
523 MonoMethodMessage *msg;
524 MonoMethod *cb_method;
525 MonoDelegate *cb_target;
526 MonoObject *state;
527 MonoObject *res;
528 MonoArray *out_args;
529 } MonoAsyncCall;
531 TYPED_HANDLE_DECL (MonoAsyncCall);
533 typedef struct {
534 MonoObject obj;
535 MonoArray *frames;
536 MonoArray *captured_traces;
537 MonoBoolean debug_info;
538 } MonoStackTrace;
540 TYPED_HANDLE_DECL (MonoStackTrace);
542 typedef struct {
543 MonoObject obj;
544 gint32 il_offset;
545 gint32 native_offset;
546 gint64 method_address;
547 gint32 method_index;
548 MonoReflectionMethod *method;
549 MonoString *filename;
550 gint32 line;
551 gint32 column;
552 MonoString *internal_method_name;
553 } MonoStackFrame;
555 TYPED_HANDLE_DECL (MonoStackFrame);
557 typedef enum {
558 MONO_THREAD_FLAG_DONT_MANAGE = 1, // Don't wait for or abort this thread
559 MONO_THREAD_FLAG_NAME_SET = 2, // Thread name set from managed code
560 MONO_THREAD_FLAG_APPDOMAIN_ABORT = 4, // Current requested abort originates from appdomain unload
561 } MonoThreadFlags;
563 struct _MonoThreadInfo;
565 typedef struct MonoThreadName {
566 char* volatile chars; // null check outside of lock
567 gint32 free; // bool
568 gint32 length;
569 } MonoThreadName;
571 void
572 mono_gstring_append_thread_name (GString*, MonoInternalThread*);
576 * NETCORE: There is only one thread object,
577 * thread->internal_thread points to itself.
579 struct _MonoInternalThread {
580 // FIXME: Mechanize keeping this in sync with managed.
581 MonoObject obj;
582 volatile int lock_thread_id; /* to be used as the pre-shifted thread id in thin locks. Used for appdomain_ref push/pop */
583 MonoThreadHandle *handle;
584 gpointer native_handle;
585 MonoThreadName name;
586 guint32 state; /* must be accessed while longlived->synch_cs is locked */
587 MonoException *abort_exc;
588 int abort_state_handle;
589 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 */
590 gsize debugger_thread; // FIXME switch to bool as soon as CI testing with corlib version bump works
591 gpointer *static_data;
592 struct _MonoThreadInfo *thread_info;
593 MonoAppContext *current_appcontext;
594 MonoThread *root_domain_thread;
595 MonoObject *_serialized_principal;
596 int _serialized_principal_version;
597 gpointer appdomain_refs;
598 /* This is modified using atomic ops, so keep it a gint32 */
599 gint32 __interruption_requested;
600 /* data that must live as long as this managed object is not finalized
601 * or as long as the underlying thread is attached, whichever is
602 * longer */
603 MonoLongLivedThreadData *longlived;
604 MonoBoolean threadpool_thread;
605 MonoBoolean thread_interrupt_requested;
606 int stack_size;
607 guint8 apartment_state;
608 gint32 critical_region_level;
609 gint32 managed_id;
610 guint32 small_id;
611 MonoThreadManageCallback manage_callback;
612 gsize flags;
613 gpointer thread_pinning_ref;
614 gsize __abort_protected_block_count;
615 gint32 priority;
616 GPtrArray *owned_mutexes;
617 MonoOSEvent *suspended;
618 gint32 self_suspended; // TRUE | FALSE
619 gsize thread_state;
621 #ifdef ENABLE_NETCORE
622 struct _MonoInternalThread *internal_thread;
623 MonoObject *start_obj;
624 MonoException *pending_exception;
625 #else
626 void* unused [3]; // same size as netcore
627 #endif
628 /* This is used only to check that we are in sync between the representation
629 * of MonoInternalThread in native and InternalThread in managed
631 * DO NOT RENAME! DO NOT ADD FIELDS AFTER! */
632 gpointer last;
635 #ifndef ENABLE_NETCORE
636 struct _MonoThread {
637 MonoObject obj;
638 MonoInternalThread *internal_thread;
639 MonoObject *start_obj;
640 MonoException *pending_exception;
642 #endif
644 typedef struct {
645 guint32 state;
646 MonoObject *additional;
647 } MonoStreamingContext;
649 #if !ENABLE_NETCORE
650 typedef struct {
651 MonoObject obj;
652 MonoBoolean readOnly;
653 MonoString *AMDesignator;
654 MonoString *PMDesignator;
655 MonoString *DateSeparator;
656 MonoString *TimeSeparator;
657 MonoString *ShortDatePattern;
658 MonoString *LongDatePattern;
659 MonoString *ShortTimePattern;
660 MonoString *LongTimePattern;
661 MonoString *MonthDayPattern;
662 MonoString *YearMonthPattern;
663 guint32 FirstDayOfWeek;
664 guint32 CalendarWeekRule;
665 MonoArray *AbbreviatedDayNames;
666 MonoArray *DayNames;
667 MonoArray *MonthNames;
668 MonoArray *GenitiveMonthNames;
669 MonoArray *AbbreviatedMonthNames;
670 MonoArray *GenitiveAbbreviatedMonthNames;
671 MonoArray *ShortDatePatterns;
672 MonoArray *LongDatePatterns;
673 MonoArray *ShortTimePatterns;
674 MonoArray *LongTimePatterns;
675 MonoArray *MonthDayPatterns;
676 MonoArray *YearMonthPatterns;
677 MonoArray *ShortestDayNames;
678 } MonoDateTimeFormatInfo;
680 typedef struct
682 MonoObject obj;
683 MonoArray *numberGroupSizes;
684 MonoArray *currencyGroupSizes;
685 MonoArray *percentGroupSizes;
686 MonoString *positiveSign;
687 MonoString *negativeSign;
688 MonoString *numberDecimalSeparator;
689 MonoString *numberGroupSeparator;
690 MonoString *currencyGroupSeparator;
691 MonoString *currencyDecimalSeparator;
692 MonoString *currencySymbol;
693 MonoString *ansiCurrencySymbol; /* unused */
694 MonoString *naNSymbol;
695 MonoString *positiveInfinitySymbol;
696 MonoString *negativeInfinitySymbol;
697 MonoString *percentDecimalSeparator;
698 MonoString *percentGroupSeparator;
699 MonoString *percentSymbol;
700 MonoString *perMilleSymbol;
701 MonoString *nativeDigits; /* unused */
702 gint32 dataItem; /* unused */
703 guint32 numberDecimalDigits;
704 gint32 currencyDecimalDigits;
705 gint32 currencyPositivePattern;
706 gint32 currencyNegativePattern;
707 gint32 numberNegativePattern;
708 gint32 percentPositivePattern;
709 gint32 percentNegativePattern;
710 gint32 percentDecimalDigits;
711 } MonoNumberFormatInfo;
713 typedef struct {
714 MonoObject obj;
715 gint32 lcid;
716 MonoString *icu_name;
717 gpointer ICU_collator;
718 } MonoCompareInfo;
720 typedef struct {
721 MonoObject obj;
722 MonoString *NativeName;
723 MonoArray *ShortDatePatterns;
724 MonoArray *YearMonthPatterns;
725 MonoArray *LongDatePatterns;
726 MonoString *MonthDayPattern;
728 MonoArray *EraNames;
729 MonoArray *AbbreviatedEraNames;
730 MonoArray *AbbreviatedEnglishEraNames;
731 MonoArray *DayNames;
732 MonoArray *AbbreviatedDayNames;
733 MonoArray *SuperShortDayNames;
734 MonoArray *MonthNames;
735 MonoArray *AbbreviatedMonthNames;
736 MonoArray *GenitiveMonthNames;
737 MonoArray *GenitiveAbbreviatedMonthNames;
738 } MonoCalendarData;
740 TYPED_HANDLE_DECL (MonoCalendarData);
742 typedef struct {
743 MonoObject obj;
744 MonoString *AMDesignator;
745 MonoString *PMDesignator;
746 MonoString *TimeSeparator;
747 MonoArray *LongTimePatterns;
748 MonoArray *ShortTimePatterns;
749 guint32 FirstDayOfWeek;
750 guint32 CalendarWeekRule;
751 } MonoCultureData;
753 TYPED_HANDLE_DECL (MonoCultureData);
755 typedef struct {
756 MonoObject obj;
757 MonoBoolean is_read_only;
758 gint32 lcid;
759 gint32 parent_lcid;
760 gint32 datetime_index;
761 gint32 number_index;
762 gint32 calendar_type;
763 MonoBoolean use_user_override;
764 MonoNumberFormatInfo *number_format;
765 MonoDateTimeFormatInfo *datetime_format;
766 MonoObject *textinfo;
767 MonoString *name;
768 MonoString *englishname;
769 MonoString *nativename;
770 MonoString *iso3lang;
771 MonoString *iso2lang;
772 MonoString *win3lang;
773 MonoString *territory;
774 MonoArray *native_calendar_names;
775 MonoCompareInfo *compareinfo;
776 const void* text_info_data;
777 } MonoCultureInfo;
779 TYPED_HANDLE_DECL (MonoCultureInfo);
781 typedef struct {
782 MonoObject obj;
783 gint32 geo_id;
784 MonoString *iso2name;
785 MonoString *iso3name;
786 MonoString *win3name;
787 MonoString *english_name;
788 MonoString *native_name;
789 MonoString *currency_symbol;
790 MonoString *iso_currency_symbol;
791 MonoString *currency_english_name;
792 MonoString *currency_native_name;
793 } MonoRegionInfo;
795 TYPED_HANDLE_DECL (MonoRegionInfo);
797 #endif /* !ENABLE_NETCORE */
799 typedef struct {
800 MonoObject object;
801 guint32 intType;
802 } MonoInterfaceTypeAttribute;
804 /* Safely access System.Delegate from native code */
805 TYPED_HANDLE_DECL (MonoDelegate);
808 * Callbacks supplied by the runtime and called by the modules in metadata/
809 * This interface is easier to extend than adding a new function type +
810 * a new 'install' function for every callback.
812 typedef struct {
813 gpointer (*create_ftnptr) (MonoDomain *domain, gpointer addr);
814 gpointer (*get_addr_from_ftnptr) (gpointer descr);
815 char* (*get_runtime_build_info) (void);
816 const char* (*get_runtime_build_version) (void);
817 gpointer (*get_vtable_trampoline) (MonoVTable *vtable, int slot_index);
818 gpointer (*get_imt_trampoline) (MonoVTable *vtable, int imt_slot_index);
819 gboolean (*imt_entry_inited) (MonoVTable *vtable, int imt_slot_index);
820 void (*set_cast_details) (MonoClass *from, MonoClass *to);
821 void (*debug_log) (int level, MonoString *category, MonoString *message);
822 gboolean (*debug_log_is_enabled) (void);
823 void (*init_delegate) (MonoDelegateHandle delegate, MonoError *error);
824 MonoObject* (*runtime_invoke) (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error);
825 void* (*compile_method) (MonoMethod *method, MonoError *error);
826 gpointer (*create_jump_trampoline) (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper, MonoError *error);
827 gpointer (*create_jit_trampoline) (MonoDomain *domain, MonoMethod *method, MonoError *error);
828 /* used to free a dynamic method */
829 void (*free_method) (MonoDomain *domain, MonoMethod *method);
830 gpointer (*create_remoting_trampoline) (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target, MonoError *error);
831 gpointer (*create_delegate_trampoline) (MonoDomain *domain, MonoClass *klass);
832 gpointer (*interp_get_remoting_invoke) (MonoMethod *method, gpointer imethod, MonoError *error);
833 GHashTable *(*get_weak_field_indexes) (MonoImage *image);
834 void (*install_state_summarizer) (void);
835 gboolean (*is_interpreter_enabled) (void);
836 } MonoRuntimeCallbacks;
838 typedef gboolean (*MonoInternalStackWalk) (MonoStackFrameInfo *frame, MonoContext *ctx, gpointer data);
839 typedef gboolean (*MonoInternalExceptionFrameWalk) (MonoMethod *method, gpointer ip, size_t native_offset, gboolean managed, gpointer user_data);
841 typedef struct {
842 void (*mono_walk_stack_with_ctx) (MonoInternalStackWalk func, MonoContext *ctx, MonoUnwindOptions options, void *user_data);
843 void (*mono_walk_stack_with_state) (MonoInternalStackWalk func, MonoThreadUnwindState *state, MonoUnwindOptions options, void *user_data);
844 void (*mono_raise_exception) (MonoException *ex);
845 void (*mono_raise_exception_with_ctx) (MonoException *ex, MonoContext *ctx);
846 gboolean (*mono_exception_walk_trace) (MonoException *ex, MonoInternalExceptionFrameWalk func, gpointer user_data);
847 gboolean (*mono_install_handler_block_guard) (MonoThreadUnwindState *unwind_state);
848 void (*mono_uninstall_current_handler_block_guard) (void);
849 gboolean (*mono_current_thread_has_handle_block_guard) (void);
850 gboolean (*mono_above_abort_threshold) (void);
851 void (*mono_clear_abort_threshold) (void);
852 void (*mono_reraise_exception) (MonoException *ex);
853 void (*mono_summarize_managed_stack) (MonoThreadSummary *out);
854 void (*mono_summarize_unmanaged_stack) (MonoThreadSummary *out);
855 void (*mono_summarize_exception) (MonoException *exc, MonoThreadSummary *out);
856 void (*mono_register_native_library) (const char *module_path, const char *module_name);
857 void (*mono_allow_all_native_libraries) (void);
858 } MonoRuntimeExceptionHandlingCallbacks;
860 MONO_COLD void mono_set_pending_exception (MonoException *exc);
862 /* remoting and async support */
864 MonoAsyncResult *
865 mono_async_result_new (MonoDomain *domain, gpointer handle,
866 MonoObject *state, gpointer data, MonoObject *object_data, MonoError *error);
867 MonoWaitHandle *
868 mono_wait_handle_new (MonoDomain *domain, gpointer handle, MonoError *error);
870 gpointer
871 mono_wait_handle_get_handle (MonoWaitHandle *handle);
873 gboolean
874 mono_message_init (MonoDomain *domain, MonoMethodMessage *this_obj,
875 MonoReflectionMethod *method, MonoArray *out_args, MonoError *error);
877 MonoMethodMessage *
878 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
879 MonoDelegate **cb, MonoObject **state, MonoError *error);
881 void
882 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args, MonoError *error);
884 gboolean
885 mono_delegate_ctor_with_method (MonoObjectHandle this_obj, MonoObjectHandle target, gpointer addr, MonoMethod *method, MonoError *error);
887 gboolean
888 mono_delegate_ctor (MonoObjectHandle this_obj, MonoObjectHandle target, gpointer addr, MonoError *error);
890 MonoMethod *
891 mono_get_delegate_invoke_checked (MonoClass *klass, MonoError *error);
893 MonoMethod *
894 mono_get_delegate_begin_invoke_checked (MonoClass *klass, MonoError *error);
896 MonoMethod *
897 mono_get_delegate_end_invoke_checked (MonoClass *klass, MonoError *error);
899 void
900 mono_runtime_free_method (MonoDomain *domain, MonoMethod *method);
902 void
903 mono_install_callbacks (MonoRuntimeCallbacks *cbs);
905 MonoRuntimeCallbacks*
906 mono_get_runtime_callbacks (void);
908 void
909 mono_install_eh_callbacks (MonoRuntimeExceptionHandlingCallbacks *cbs);
911 MonoRuntimeExceptionHandlingCallbacks *
912 mono_get_eh_callbacks (void);
914 void
915 mono_raise_exception_deprecated (MonoException *ex);
917 void
918 mono_reraise_exception_deprecated (MonoException *ex);
920 void
921 mono_raise_exception_with_context (MonoException *ex, MonoContext *ctx);
923 void
924 mono_type_initialization_init (void);
926 void
927 mono_type_initialization_cleanup (void);
930 mono_thread_kill (MonoInternalThread *thread, int signal);
932 MonoNativeTlsKey
933 mono_thread_get_tls_key (void);
935 gint32
936 mono_thread_get_tls_offset (void);
938 MonoNativeTlsKey
939 mono_domain_get_tls_key (void);
941 gint32
942 mono_domain_get_tls_offset (void);
944 /* Reflection and Reflection.Emit support */
947 * Handling System.Type objects:
949 * Fields defined as System.Type in managed code should be defined as MonoObject*
950 * in unmanaged structures, and the monotype_cast () function should be used for
951 * casting them to MonoReflectionType* to avoid crashes/security issues when
952 * encountering instances of user defined subclasses of System.Type.
955 #define IS_MONOTYPE(obj) (!(obj) || (m_class_get_image (mono_object_class ((obj))) == mono_defaults.corlib && ((MonoReflectionType*)(obj))->type != NULL))
957 #define IS_MONOTYPE_HANDLE(obj) IS_MONOTYPE (MONO_HANDLE_RAW (obj))
959 /* This should be used for accessing members of Type[] arrays */
960 #define mono_type_array_get(arr,index) monotype_cast (mono_array_get_internal ((arr), gpointer, (index)))
963 * Cast an object to MonoReflectionType, making sure it is a System.MonoType or
964 * a subclass of it.
966 static inline MonoReflectionType*
967 monotype_cast (MonoObject *obj)
969 g_assert (IS_MONOTYPE (obj));
971 return (MonoReflectionType*)obj;
975 * The following structure must match the C# implementation in our corlib.
978 struct _MonoReflectionMethod {
979 MonoObject object;
980 MonoMethod *method;
981 MonoString *name;
982 MonoReflectionType *reftype;
985 /* Safely access System.Reflection.MonoMethod from native code */
986 TYPED_HANDLE_DECL (MonoReflectionMethod);
988 struct _MonoDelegate {
989 MonoObject object;
990 /* The compiled code of the target method */
991 gpointer method_ptr;
992 /* The invoke code */
993 gpointer invoke_impl;
994 MonoObject *target;
995 MonoMethod *method;
996 gpointer delegate_trampoline;
997 /* Extra argument passed to the target method in llvmonly mode */
998 gpointer extra_arg;
1000 * If non-NULL, this points to a memory location which stores the address of
1001 * the compiled code of the method, or NULL if it is not yet compiled.
1003 guint8 **method_code;
1004 gpointer interp_method;
1005 /* Interp method that is executed when invoking the delegate */
1006 gpointer interp_invoke_impl;
1007 MonoReflectionMethod *method_info;
1008 MonoReflectionMethod *original_method_info;
1009 MonoObject *data;
1010 MonoBoolean method_is_virtual;
1013 typedef struct _MonoMulticastDelegate MonoMulticastDelegate;
1014 struct _MonoMulticastDelegate {
1015 MonoDelegate delegate;
1016 MonoArray *delegates;
1019 /* Safely access System.MulticastDelegate from native code */
1020 TYPED_HANDLE_DECL (MonoMulticastDelegate);
1022 struct _MonoReflectionField {
1023 MonoObject object;
1024 MonoClass *klass;
1025 MonoClassField *field;
1026 MonoString *name;
1027 MonoReflectionType *type;
1028 guint32 attrs;
1031 /* Safely access System.Reflection.MonoField from native code */
1032 TYPED_HANDLE_DECL (MonoReflectionField);
1034 struct _MonoReflectionProperty {
1035 MonoObject object;
1036 MonoClass *klass;
1037 MonoProperty *property;
1040 /* Safely access System.Reflection.MonoProperty from native code */
1041 TYPED_HANDLE_DECL (MonoReflectionProperty);
1043 /*This is System.EventInfo*/
1044 struct _MonoReflectionEvent {
1045 MonoObject object;
1046 #ifndef ENABLE_NETCORE
1047 MonoObject *cached_add_event;
1048 #endif
1051 /* Safely access System.Reflection.EventInfo from native code */
1052 TYPED_HANDLE_DECL (MonoReflectionEvent);
1054 typedef struct {
1055 MonoReflectionEvent object;
1056 MonoClass *klass;
1057 MonoEvent *event;
1058 } MonoReflectionMonoEvent;
1060 /* Safely access Systme.Reflection.MonoEvent from native code */
1061 TYPED_HANDLE_DECL (MonoReflectionMonoEvent);
1063 typedef struct {
1064 MonoObject object;
1065 } MonoReflectionParameter;
1067 /* Safely access System.Reflection.ParameterInfo from native code */
1068 TYPED_HANDLE_DECL (MonoReflectionParameter);
1070 struct _MonoReflectionMethodBody {
1071 MonoObject object;
1074 /* Safely access System.Reflection.MethodBody from native code */
1075 TYPED_HANDLE_DECL (MonoReflectionMethodBody);
1077 /* System.RuntimeAssembly */
1078 struct _MonoReflectionAssembly {
1079 MonoObject object;
1080 MonoAssembly *assembly;
1081 /* CAS related */
1082 MonoObject *evidence; /* Evidence */
1085 typedef struct {
1086 MonoReflectionType *utype;
1087 MonoArray *values;
1088 MonoArray *names;
1089 } MonoEnumInfo;
1091 typedef struct {
1092 MonoReflectionType *parent;
1093 MonoReflectionType *ret;
1094 guint32 attrs;
1095 guint32 implattrs;
1096 guint32 callconv;
1097 } MonoMethodInfo;
1099 typedef struct {
1100 MonoReflectionType *parent;
1101 MonoReflectionType *declaring_type;
1102 MonoString *name;
1103 MonoReflectionMethod *get;
1104 MonoReflectionMethod *set;
1105 guint32 attrs;
1106 } MonoPropertyInfo;
1108 typedef struct {
1109 MonoReflectionType *declaring_type;
1110 MonoReflectionType *reflected_type;
1111 MonoString *name;
1112 MonoReflectionMethod *add_method;
1113 MonoReflectionMethod *remove_method;
1114 MonoReflectionMethod *raise_method;
1115 guint32 attrs;
1116 MonoArray *other_methods;
1117 } MonoEventInfo;
1119 typedef struct {
1120 MonoObject *member;
1121 gint32 code_pos;
1122 } MonoReflectionILTokenInfo;
1124 typedef struct {
1125 MonoObject object;
1126 MonoArray *code;
1127 gint32 code_len;
1128 gint32 max_stack;
1129 gint32 cur_stack;
1130 MonoArray *locals;
1131 MonoArray *ex_handlers;
1132 gint32 num_token_fixups;
1133 MonoArray *token_fixups;
1134 } MonoReflectionILGen;
1136 typedef struct {
1137 MonoArray *handlers;
1138 gint32 start;
1139 gint32 len;
1140 gint32 label;
1141 } MonoILExceptionInfo;
1143 typedef struct {
1144 MonoObject *extype;
1145 gint32 type;
1146 gint32 start;
1147 gint32 len;
1148 gint32 filter_offset;
1149 } MonoILExceptionBlock;
1151 typedef struct {
1152 MonoObject object;
1153 MonoObject *catch_type;
1154 gint32 filter_offset;
1155 gint32 flags;
1156 gint32 try_offset;
1157 gint32 try_length;
1158 gint32 handler_offset;
1159 gint32 handler_length;
1160 } MonoReflectionExceptionHandlingClause;
1163 /* Safely access System.Reflection.ExceptionHandlingClause from native code */
1164 TYPED_HANDLE_DECL (MonoReflectionExceptionHandlingClause);
1166 typedef struct {
1167 MonoObject object;
1168 MonoReflectionType *local_type;
1169 MonoBoolean is_pinned;
1170 guint16 local_index;
1171 } MonoReflectionLocalVariableInfo;
1173 /* Safely access System.Reflection.LocalVariableInfo from native code */
1174 TYPED_HANDLE_DECL (MonoReflectionLocalVariableInfo);
1176 typedef struct {
1178 * Must have the same layout as MonoReflectionLocalVariableInfo, since
1179 * LocalBuilder inherits from it under net 2.0.
1181 MonoObject object;
1182 MonoObject *type;
1183 MonoBoolean is_pinned;
1184 guint16 local_index;
1185 MonoString *name;
1186 } MonoReflectionLocalBuilder;
1188 typedef struct {
1189 MonoObject object;
1190 gint32 count;
1191 gint32 type;
1192 gint32 eltype;
1193 MonoString *guid;
1194 MonoString *mcookie;
1195 MonoString *marshaltype;
1196 MonoObject *marshaltyperef;
1197 gint32 param_num;
1198 MonoBoolean has_size;
1199 } MonoReflectionMarshal;
1201 typedef struct {
1202 MonoObject object;
1203 MonoObject* methodb;
1204 MonoString *name;
1205 MonoArray *cattrs;
1206 MonoReflectionMarshal *marshal_info;
1207 guint32 attrs;
1208 int position;
1209 guint32 table_idx;
1210 MonoObject *def_value;
1211 } MonoReflectionParamBuilder;
1213 typedef struct {
1214 MonoObject object;
1215 MonoMethod *mhandle;
1216 MonoReflectionILGen *ilgen;
1217 MonoArray *parameters;
1218 guint32 attrs;
1219 guint32 iattrs;
1220 guint32 table_idx;
1221 guint32 call_conv;
1222 MonoObject *type;
1223 MonoArray *pinfo;
1224 MonoArray *cattrs;
1225 MonoBoolean init_locals;
1226 MonoArray *param_modreq;
1227 MonoArray *param_modopt;
1228 MonoArray *permissions;
1229 } MonoReflectionCtorBuilder;
1231 /* Safely access System.Reflection.Emit.ConstructorBuilder from native code */
1232 TYPED_HANDLE_DECL (MonoReflectionCtorBuilder);
1234 typedef struct {
1235 MonoObject object;
1236 MonoMethod *mhandle;
1237 MonoObject *rtype;
1238 MonoArray *parameters;
1239 guint32 attrs;
1240 guint32 iattrs;
1241 MonoString *name;
1242 guint32 table_idx;
1243 MonoArray *code;
1244 MonoReflectionILGen *ilgen;
1245 MonoObject *type;
1246 MonoArray *pinfo;
1247 MonoArray *cattrs;
1248 MonoArray *override_methods;
1249 MonoString *dll;
1250 MonoString *dllentry;
1251 guint32 charset;
1252 guint32 extra_flags;
1253 guint32 native_cc;
1254 guint32 call_conv;
1255 MonoBoolean init_locals;
1256 MonoGenericContainer *generic_container;
1257 MonoArray *generic_params;
1258 MonoArray *return_modreq;
1259 MonoArray *return_modopt;
1260 MonoArray *param_modreq;
1261 MonoArray *param_modopt;
1262 MonoArray *permissions;
1263 } MonoReflectionMethodBuilder;
1265 /* Safely access System.Reflection.Emit.MethodBuilder from native code */
1266 TYPED_HANDLE_DECL (MonoReflectionMethodBuilder);
1268 typedef struct {
1269 MonoObject object;
1270 MonoMethod *mhandle;
1271 MonoReflectionType *parent;
1272 MonoReflectionType *ret;
1273 MonoArray *parameters;
1274 MonoString *name;
1275 guint32 table_idx;
1276 guint32 call_conv;
1277 } MonoReflectionArrayMethod;
1279 /* Safely access System.Reflection.Emit.MonoArrayMethod from native code */
1280 TYPED_HANDLE_DECL (MonoReflectionArrayMethod);
1282 typedef struct {
1283 MonoArray *data;
1284 MonoString *name;
1285 MonoString *filename;
1286 guint32 attrs;
1287 guint32 offset;
1288 MonoObject *stream;
1289 } MonoReflectionResource;
1291 typedef struct {
1292 guint32 res_type;
1293 guint32 res_id;
1294 guint32 lang_id;
1295 MonoArray *res_data;
1296 } MonoReflectionWin32Resource;
1298 typedef struct {
1299 guint32 action;
1300 MonoString *pset;
1301 } MonoReflectionPermissionSet;
1303 typedef struct {
1304 MonoReflectionAssembly assembly;
1305 MonoDynamicAssembly *dynamic_assembly;
1306 MonoReflectionMethod *entry_point;
1307 MonoArray *modules;
1308 MonoString *name;
1309 MonoString *dir;
1310 MonoArray *cattrs;
1311 MonoArray *resources;
1312 MonoArray *public_key;
1313 MonoString *version;
1314 MonoString *culture;
1315 guint32 algid;
1316 guint32 flags;
1317 guint32 pekind;
1318 MonoBoolean delay_sign;
1319 guint32 access;
1320 MonoArray *loaded_modules;
1321 MonoArray *win32_resources;
1322 /* CAS related */
1323 MonoArray *permissions_minimum;
1324 MonoArray *permissions_optional;
1325 MonoArray *permissions_refused;
1326 gint32 pe_kind;
1327 gint32 machine;
1328 MonoBoolean corlib_internal;
1329 MonoArray *type_forwarders;
1330 MonoArray *pktoken; /* as hexadecimal byte[] */
1331 } MonoReflectionAssemblyBuilder;
1333 /* Safely access System.Reflection.Emit.AssemblyBuilder from native code */
1334 TYPED_HANDLE_DECL (MonoReflectionAssemblyBuilder);
1336 typedef struct {
1337 MonoObject object;
1338 guint32 attrs;
1339 MonoObject *type;
1340 MonoString *name;
1341 MonoObject *def_value;
1342 gint32 offset;
1343 MonoReflectionType *typeb;
1344 MonoArray *rva_data;
1345 MonoArray *cattrs;
1346 MonoReflectionMarshal *marshal_info;
1347 MonoClassField *handle;
1348 MonoArray *modreq;
1349 MonoArray *modopt;
1350 } MonoReflectionFieldBuilder;
1352 /* Safely access System.Reflection.Emit.FieldBuilder from native code */
1353 TYPED_HANDLE_DECL (MonoReflectionFieldBuilder);
1355 typedef struct {
1356 MonoObject object;
1357 guint32 attrs;
1358 MonoString *name;
1359 MonoObject *type;
1360 MonoArray *parameters;
1361 MonoArray *cattrs;
1362 MonoObject *def_value;
1363 MonoReflectionMethodBuilder *set_method;
1364 MonoReflectionMethodBuilder *get_method;
1365 gint32 table_idx;
1366 MonoObject *type_builder;
1367 MonoArray *returnModReq;
1368 MonoArray *returnModOpt;
1369 MonoArray *paramModReq;
1370 MonoArray *paramModOpt;
1371 guint32 call_conv;
1372 } MonoReflectionPropertyBuilder;
1374 /* System.RuntimeModule */
1375 struct _MonoReflectionModule {
1376 MonoObject obj;
1377 MonoImage *image;
1378 MonoReflectionAssembly *assembly;
1379 MonoString *fqname;
1380 MonoString *name;
1381 MonoString *scopename;
1382 MonoBoolean is_resource;
1383 guint32 token;
1386 /* Safely access System.Reflection.Module from native code */
1387 TYPED_HANDLE_DECL (MonoReflectionModule);
1389 typedef struct {
1390 MonoReflectionModule module;
1391 MonoDynamicImage *dynamic_image;
1392 gint32 num_types;
1393 MonoArray *types;
1394 MonoArray *cattrs;
1395 MonoArray *guid;
1396 guint32 table_idx;
1397 MonoReflectionAssemblyBuilder *assemblyb;
1398 MonoArray *global_methods;
1399 MonoArray *global_fields;
1400 gboolean is_main;
1401 MonoArray *resources;
1402 GHashTable *unparented_classes;
1403 MonoArray *table_indexes;
1404 } MonoReflectionModuleBuilder;
1406 /* Safely acess System.Reflection.Emit.ModuleBuidler from native code */
1407 TYPED_HANDLE_DECL (MonoReflectionModuleBuilder);
1409 typedef enum {
1410 MonoTypeBuilderNew = 0,
1411 MonoTypeBuilderEntered = 1,
1412 MonoTypeBuilderFinished = 2
1413 } MonoTypeBuilderState;
1415 struct _MonoReflectionTypeBuilder {
1416 MonoReflectionType type;
1417 MonoString *name;
1418 MonoString *nspace;
1419 MonoObject *parent;
1420 MonoReflectionType *nesting_type;
1421 MonoArray *interfaces;
1422 gint32 num_methods;
1423 MonoArray *methods;
1424 MonoArray *ctors;
1425 MonoArray *properties;
1426 gint32 num_fields;
1427 MonoArray *fields;
1428 MonoArray *events;
1429 MonoArray *cattrs;
1430 MonoArray *subtypes;
1431 guint32 attrs;
1432 guint32 table_idx;
1433 MonoReflectionModuleBuilder *module;
1434 gint32 class_size;
1435 gint32 packing_size;
1436 MonoGenericContainer *generic_container;
1437 MonoArray *generic_params;
1438 MonoArray *permissions;
1439 MonoReflectionType *created;
1440 gint32 state;
1443 typedef struct {
1444 MonoReflectionType type;
1445 MonoReflectionType *element_type;
1446 gint32 rank;
1447 } MonoReflectionArrayType;
1449 /* Safely access System.Reflection.Emit.ArrayType (in DerivedTypes.cs) from native code */
1450 TYPED_HANDLE_DECL (MonoReflectionArrayType);
1452 typedef struct {
1453 MonoReflectionType type;
1454 MonoReflectionType *element_type;
1455 } MonoReflectionDerivedType;
1457 /* Safely access System.Reflection.Emit.SymbolType and subclasses (in DerivedTypes.cs) from native code */
1458 TYPED_HANDLE_DECL (MonoReflectionDerivedType);
1460 typedef struct {
1461 MonoReflectionType type;
1462 MonoReflectionTypeBuilder *tbuilder;
1463 MonoReflectionMethodBuilder *mbuilder;
1464 MonoString *name;
1465 guint32 index;
1466 MonoReflectionType *base_type;
1467 MonoArray *iface_constraints;
1468 MonoArray *cattrs;
1469 guint32 attrs;
1470 } MonoReflectionGenericParam;
1472 /* Safely access System.Reflection.Emit.GenericTypeParameterBuilder from native code */
1473 TYPED_HANDLE_DECL (MonoReflectionGenericParam);
1475 typedef struct {
1476 MonoReflectionType type;
1477 MonoReflectionTypeBuilder *tb;
1478 } MonoReflectionEnumBuilder;
1480 /* Safely access System.Reflection.Emit.EnumBuilder from native code */
1481 TYPED_HANDLE_DECL (MonoReflectionEnumBuilder);
1483 typedef struct _MonoReflectionGenericClass MonoReflectionGenericClass;
1484 struct _MonoReflectionGenericClass {
1485 MonoReflectionType type;
1486 MonoReflectionType *generic_type; /*Can be either a MonoType or a TypeBuilder*/
1487 MonoArray *type_arguments;
1490 /* Safely access System.Reflection.Emit.TypeBuilderInstantiation from native code */
1491 TYPED_HANDLE_DECL (MonoReflectionGenericClass);
1493 typedef struct {
1494 MonoObject obj;
1495 MonoString *name;
1496 MonoString *codebase;
1497 gint32 major, minor, build, revision;
1498 MonoObject *cultureInfo;
1499 guint32 flags;
1500 guint32 hashalg;
1501 MonoObject *keypair;
1502 MonoArray *publicKey;
1503 MonoArray *keyToken;
1504 guint32 versioncompat;
1505 MonoObject *version;
1506 guint32 processor_architecture;
1507 } MonoReflectionAssemblyName;
1509 /* Safely access System.Reflection.AssemblyName from native code */
1510 TYPED_HANDLE_DECL (MonoReflectionAssemblyName);
1512 typedef struct {
1513 MonoObject obj;
1514 MonoString *name;
1515 MonoReflectionType *type;
1516 MonoReflectionTypeBuilder *typeb;
1517 MonoArray *cattrs;
1518 MonoReflectionMethodBuilder *add_method;
1519 MonoReflectionMethodBuilder *remove_method;
1520 MonoReflectionMethodBuilder *raise_method;
1521 MonoArray *other_methods;
1522 guint32 attrs;
1523 guint32 table_idx;
1524 } MonoReflectionEventBuilder;
1526 typedef struct {
1527 MonoObject obj;
1528 MonoReflectionMethod *ctor;
1529 MonoArray *data;
1530 } MonoReflectionCustomAttr;
1532 TYPED_HANDLE_DECL (MonoReflectionCustomAttr);
1534 #if ENABLE_NETCORE
1535 typedef struct {
1536 MonoObject object;
1537 guint32 utype;
1538 gint32 safe_array_subtype;
1539 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1540 gint32 IidParameterIndex;
1541 guint32 array_subtype;
1542 gint16 size_param_index;
1543 gint32 size_const;
1544 MonoString *marshal_type;
1545 MonoReflectionType *marshal_type_ref;
1546 MonoString *marshal_cookie;
1547 } MonoReflectionMarshalAsAttribute;
1548 #else
1549 typedef struct {
1550 MonoObject object;
1551 MonoString *marshal_cookie;
1552 MonoString *marshal_type;
1553 MonoReflectionType *marshal_type_ref;
1554 MonoReflectionType *marshal_safe_array_user_defined_subtype;
1555 guint32 utype;
1556 guint32 array_subtype;
1557 gint32 safe_array_subtype;
1558 gint32 size_const;
1559 gint32 IidParameterIndex;
1560 gint16 size_param_index;
1561 } MonoReflectionMarshalAsAttribute;
1562 #endif
1564 /* Safely access System.Runtime.InteropServices.MarshalAsAttribute */
1565 TYPED_HANDLE_DECL (MonoReflectionMarshalAsAttribute);
1567 typedef struct {
1568 MonoObject object;
1569 gint32 call_conv;
1570 gint32 charset;
1571 MonoBoolean best_fit_mapping;
1572 MonoBoolean throw_on_unmappable;
1573 MonoBoolean set_last_error;
1574 } MonoReflectionUnmanagedFunctionPointerAttribute;
1576 typedef struct {
1577 MonoObject object;
1578 MonoString *guid;
1579 } MonoReflectionGuidAttribute;
1581 typedef struct {
1582 MonoObject object;
1583 MonoMethod *mhandle;
1584 MonoString *name;
1585 MonoReflectionType *rtype;
1586 MonoArray *parameters;
1587 guint32 attrs;
1588 guint32 call_conv;
1589 MonoReflectionModule *module;
1590 MonoBoolean skip_visibility;
1591 MonoBoolean init_locals;
1592 MonoReflectionILGen *ilgen;
1593 gint32 nrefs;
1594 MonoArray *refs;
1595 GSList *referenced_by;
1596 MonoReflectionType *owner;
1597 } MonoReflectionDynamicMethod;
1599 /* Safely access System.Reflection.Emit.DynamicMethod from native code */
1600 TYPED_HANDLE_DECL (MonoReflectionDynamicMethod);
1602 typedef struct {
1603 MonoObject object;
1604 MonoReflectionModuleBuilder *module;
1605 MonoArray *arguments;
1606 guint32 type;
1607 MonoReflectionType *return_type;
1608 guint32 call_conv;
1609 guint32 unmanaged_call_conv;
1610 MonoArray *modreqs;
1611 MonoArray *modopts;
1612 } MonoReflectionSigHelper;
1614 /* Safely access System.Reflection.Emit.SignatureHelper from native code */
1615 TYPED_HANDLE_DECL (MonoReflectionSigHelper);
1617 typedef struct {
1618 MonoObject object;
1619 MonoBoolean visible;
1620 } MonoReflectionComVisibleAttribute;
1622 typedef struct {
1623 MonoObject object;
1624 MonoReflectionType *type;
1625 } MonoReflectionComDefaultInterfaceAttribute;
1627 enum {
1628 RESOURCE_LOCATION_EMBEDDED = 1,
1629 RESOURCE_LOCATION_ANOTHER_ASSEMBLY = 2,
1630 RESOURCE_LOCATION_IN_MANIFEST = 4
1633 typedef struct {
1634 MonoObject object;
1635 MonoReflectionAssembly *assembly;
1636 MonoString *filename;
1637 guint32 location;
1638 } MonoManifestResourceInfo;
1640 /* Safely access System.Reflection.ManifestResourceInfo from native code */
1641 TYPED_HANDLE_DECL (MonoManifestResourceInfo);
1643 /* A boxed IntPtr */
1644 typedef struct {
1645 MonoObject object;
1646 gpointer m_value;
1647 } MonoIntPtr;
1649 /* Keep in sync with System.GenericParameterAttributes */
1650 typedef enum {
1651 GENERIC_PARAMETER_ATTRIBUTE_NON_VARIANT = 0,
1652 GENERIC_PARAMETER_ATTRIBUTE_COVARIANT = 1,
1653 GENERIC_PARAMETER_ATTRIBUTE_CONTRAVARIANT = 2,
1654 GENERIC_PARAMETER_ATTRIBUTE_VARIANCE_MASK = 3,
1656 GENERIC_PARAMETER_ATTRIBUTE_NO_SPECIAL_CONSTRAINT = 0,
1657 GENERIC_PARAMETER_ATTRIBUTE_REFERENCE_TYPE_CONSTRAINT = 4,
1658 GENERIC_PARAMETER_ATTRIBUTE_VALUE_TYPE_CONSTRAINT = 8,
1659 GENERIC_PARAMETER_ATTRIBUTE_CONSTRUCTOR_CONSTRAINT = 16,
1660 GENERIC_PARAMETER_ATTRIBUTE_SPECIAL_CONSTRAINTS_MASK = 28
1661 } GenericParameterAttributes;
1663 typedef struct {
1664 MonoType *type;
1665 MonoClassField *field;
1666 MonoProperty *prop;
1667 } CattrNamedArg;
1669 /* All MonoInternalThread instances should be pinned, so it's safe to use the raw ptr. However
1670 * for uniformity, icall wrapping will make handles anyway. So this is the method for getting the payload.
1672 static inline MonoInternalThread*
1673 mono_internal_thread_handle_ptr (MonoInternalThreadHandle h)
1675 /* The SUPPRESS here prevents a Centrinel warning due to merely seeing this
1676 * function definition. Callees will still get a warning unless we
1677 * attach a suppress attribute to the declaration.
1679 return MONO_HANDLE_SUPPRESS (MONO_HANDLE_RAW (h));
1682 gboolean mono_image_create_pefile (MonoReflectionModuleBuilder *module, gpointer file, MonoError *error);
1683 guint32 mono_image_insert_string (MonoReflectionModuleBuilderHandle module, MonoStringHandle str, MonoError *error);
1684 guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObjectHandle obj, gboolean create_methodspec, gboolean register_token, MonoError *error);
1685 void mono_dynamic_image_free (MonoDynamicImage *image);
1686 void mono_dynamic_image_free_image (MonoDynamicImage *image);
1687 void mono_dynamic_image_release_gc_roots (MonoDynamicImage *image);
1689 void mono_reflection_setup_internal_class (MonoReflectionTypeBuilder *tb);
1691 void mono_reflection_get_dynamic_overrides (MonoClass *klass, MonoMethod ***overrides, int *num_overrides, MonoError *error);
1693 void mono_reflection_destroy_dynamic_method (MonoReflectionDynamicMethod *mb);
1695 ICALL_EXPORT
1696 void
1697 ves_icall_SymbolType_create_unmanaged_type (MonoReflectionType *type);
1699 void mono_reflection_register_with_runtime (MonoReflectionType *type);
1701 MonoMethodSignature * mono_reflection_lookup_signature (MonoImage *image, MonoMethod *method, guint32 token, MonoError *error);
1703 MonoArrayHandle mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoClass *refclass, MonoError *error);
1705 MonoClass*
1706 mono_class_bind_generic_parameters (MonoClass *klass, int type_argc, MonoType **types, gboolean is_dynamic);
1707 MonoType*
1708 mono_reflection_bind_generic_parameters (MonoReflectionTypeHandle type, int type_argc, MonoType **types, MonoError *error);
1709 void
1710 mono_reflection_generic_class_initialize (MonoReflectionGenericClass *type, MonoArray *fields);
1712 ICALL_EXPORT
1713 MonoReflectionEvent *
1714 ves_icall_TypeBuilder_get_event_info (MonoReflectionTypeBuilder *tb, MonoReflectionEventBuilder *eb);
1716 MonoReflectionMarshalAsAttributeHandle
1717 mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec, MonoError *error);
1719 gpointer
1720 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
1722 gboolean
1723 mono_reflection_call_is_assignable_to (MonoClass *klass, MonoClass *oklass, MonoError *error);
1725 gboolean
1726 mono_image_build_metadata (MonoReflectionModuleBuilder *module, MonoError *error);
1728 gboolean
1729 mono_get_constant_value_from_blob (MonoDomain* domain, MonoTypeEnum type, const char *blob, void *value, MonoStringHandleOut string_handle, MonoError *error);
1731 gboolean
1732 mono_metadata_read_constant_value (const char *blob, MonoTypeEnum type, void *value, MonoError *error);
1734 char*
1735 mono_string_from_blob (const char *str, MonoError *error);
1737 void
1738 mono_release_type_locks (MonoInternalThread *thread);
1741 * mono_string_handle_length:
1742 * \param s \c MonoString
1743 * \returns the length in characters of the string
1745 #ifdef ENABLE_CHECKED_BUILD_GC
1748 mono_string_handle_length (MonoStringHandle s);
1750 #else
1752 #define mono_string_handle_length(s) (MONO_HANDLE_GETVAL ((s), length))
1754 #endif
1756 char *
1757 mono_string_handle_to_utf8 (MonoStringHandle s, MonoError *error);
1759 char *
1760 mono_string_to_utf8_image (MonoImage *image, MonoStringHandle s, MonoError *error);
1762 MonoArrayHandle
1763 mono_array_clone_in_domain (MonoDomain *domain, MonoArrayHandle array, MonoError *error);
1765 MonoArray*
1766 mono_array_clone_checked (MonoArray *array, MonoError *error);
1768 void
1769 mono_array_full_copy (MonoArray *src, MonoArray *dest);
1771 gboolean
1772 mono_array_calc_byte_len (MonoClass *klass, uintptr_t len, uintptr_t *res);
1774 MonoArray*
1775 mono_array_new_checked (MonoDomain *domain, MonoClass *eclass, uintptr_t n, MonoError *error);
1777 MonoArray*
1778 mono_array_new_full_checked (MonoDomain *domain, MonoClass *array_class, uintptr_t *lengths, intptr_t *lower_bounds, MonoError *error);
1780 ICALL_EXPORT
1781 MonoArray*
1782 ves_icall_array_new (MonoDomain *domain, MonoClass *eclass, uintptr_t n);
1784 ICALL_EXPORT
1785 MonoArray*
1786 ves_icall_array_new_specific (MonoVTable *vtable, uintptr_t n);
1788 #ifndef DISABLE_REMOTING
1789 MonoRemoteClass*
1790 mono_remote_class (MonoDomain *domain, MonoStringHandle class_name, MonoClass *proxy_class, MonoError *error);
1792 gboolean
1793 mono_remote_class_is_interface_proxy (MonoRemoteClass *remote_class);
1795 MonoObject *
1796 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg, MonoObject **exc, MonoArray **out_args, MonoError *error);
1798 gpointer
1799 mono_remote_class_vtable (MonoDomain *domain, MonoRemoteClass *remote_class, MonoRealProxyHandle real_proxy, MonoError *error);
1801 gboolean
1802 mono_upgrade_remote_class (MonoDomain *domain, MonoObjectHandle tproxy, MonoClass *klass, MonoError *error);
1804 void*
1805 mono_load_remote_field_checked (MonoObject *this_obj, MonoClass *klass, MonoClassField *field, void **res, MonoError *error);
1807 MonoObject *
1808 mono_load_remote_field_new_checked (MonoObject *this_obj, MonoClass *klass, MonoClassField *field, MonoError *error);
1810 gboolean
1811 mono_store_remote_field_checked (MonoObject *this_obj, MonoClass *klass, MonoClassField *field, void* val, MonoError *error);
1813 gboolean
1814 mono_store_remote_field_new_checked (MonoObject *this_obj, MonoClass *klass, MonoClassField *field, MonoObject *arg, MonoError *error);
1817 #endif
1819 gpointer
1820 mono_create_ftnptr (MonoDomain *domain, gpointer addr);
1822 gpointer
1823 mono_get_addr_from_ftnptr (gpointer descr);
1825 void
1826 mono_nullable_init (guint8 *buf, MonoObject *value, MonoClass *klass);
1828 void
1829 mono_nullable_init_from_handle (guint8 *buf, MonoObjectHandle value, MonoClass *klass);
1831 void
1832 mono_nullable_init_unboxed (guint8 *buf, gpointer value, MonoClass *klass);
1834 MonoObject *
1835 mono_value_box_checked (MonoDomain *domain, MonoClass *klass, void* val, MonoError *error);
1837 MonoObjectHandle
1838 mono_value_box_handle (MonoDomain *domain, MonoClass *klass, gpointer val, MonoError *error);
1840 MonoObject*
1841 mono_nullable_box (gpointer buf, MonoClass *klass, MonoError *error);
1843 MonoObjectHandle
1844 mono_nullable_box_handle (gpointer buf, MonoClass *klass, MonoError *error);
1846 // A code size optimization (source and object) equivalent to MONO_HANDLE_NEW (MonoObject, NULL);
1847 MonoObjectHandle
1848 mono_new_null (void);
1850 #ifdef MONO_SMALL_CONFIG
1851 #define MONO_IMT_SIZE 9
1852 #else
1853 #define MONO_IMT_SIZE 19
1854 #endif
1856 typedef union {
1857 int vtable_slot;
1858 gpointer target_code;
1859 } MonoImtItemValue;
1861 typedef struct _MonoImtBuilderEntry {
1862 gpointer key;
1863 struct _MonoImtBuilderEntry *next;
1864 MonoImtItemValue value;
1865 int children;
1866 guint8 has_target_code : 1;
1867 } MonoImtBuilderEntry;
1869 typedef struct _MonoIMTCheckItem MonoIMTCheckItem;
1871 struct _MonoIMTCheckItem {
1872 gpointer key;
1873 int check_target_idx;
1874 MonoImtItemValue value;
1875 guint8 *jmp_code;
1876 guint8 *code_target;
1877 guint8 is_equals;
1878 guint8 compare_done;
1879 guint8 chunk_size;
1880 guint8 short_branch;
1881 guint8 has_target_code;
1884 typedef gpointer (*MonoImtTrampolineBuilder) (MonoVTable *vtable, MonoDomain *domain,
1885 MonoIMTCheckItem **imt_entries, int count, gpointer fail_trunk);
1887 void
1888 mono_install_imt_trampoline_builder (MonoImtTrampolineBuilder func);
1890 void
1891 mono_set_always_build_imt_trampolines (gboolean value);
1893 void
1894 mono_vtable_build_imt_slot (MonoVTable* vtable, int imt_slot);
1896 guint32
1897 mono_method_get_imt_slot (MonoMethod *method);
1899 void
1900 mono_method_add_generic_virtual_invocation (MonoDomain *domain, MonoVTable *vtable,
1901 gpointer *vtable_slot,
1902 MonoMethod *method, gpointer code);
1904 gpointer
1905 mono_method_alloc_generic_virtual_trampoline (MonoDomain *domain, int size);
1907 #define mono_method_alloc_generic_virtual_trampoline(domain, size) (g_cast (mono_method_alloc_generic_virtual_trampoline ((domain), (size))))
1909 typedef enum {
1910 MONO_UNHANDLED_POLICY_LEGACY,
1911 MONO_UNHANDLED_POLICY_CURRENT
1912 } MonoRuntimeUnhandledExceptionPolicy;
1914 MonoRuntimeUnhandledExceptionPolicy
1915 mono_runtime_unhandled_exception_policy_get (void);
1916 void
1917 mono_runtime_unhandled_exception_policy_set (MonoRuntimeUnhandledExceptionPolicy policy);
1919 void
1920 mono_unhandled_exception_checked (MonoObjectHandle exc, MonoError *error);
1922 MonoVTable *
1923 mono_class_try_get_vtable (MonoDomain *domain, MonoClass *klass);
1925 gboolean
1926 mono_runtime_run_module_cctor (MonoImage *image, MonoDomain *domain, MonoError *error);
1928 gboolean
1929 mono_runtime_class_init_full (MonoVTable *vtable, MonoError *error);
1931 void
1932 mono_method_clear_object (MonoDomain *domain, MonoMethod *method);
1934 gsize*
1935 mono_class_compute_bitmap (MonoClass *klass, gsize *bitmap, int size, int offset, int *max_set, gboolean static_fields);
1937 MonoObjectHandle
1938 mono_object_xdomain_representation (MonoObjectHandle obj, MonoDomain *target_domain, MonoError *error);
1940 gboolean
1941 mono_class_is_reflection_method_or_constructor (MonoClass *klass);
1943 MonoObjectHandle
1944 mono_get_object_from_blob (MonoDomain *domain, MonoType *type, const char *blob, MonoStringHandleOut string_handle, MonoError *error);
1946 gboolean
1947 mono_class_has_ref_info (MonoClass *klass);
1949 MonoReflectionTypeBuilder*
1950 mono_class_get_ref_info_raw (MonoClass *klass);
1952 void
1953 mono_class_set_ref_info (MonoClass *klass, MonoObjectHandle obj);
1955 void
1956 mono_class_free_ref_info (MonoClass *klass);
1958 MonoObject *
1959 mono_object_new_pinned (MonoDomain *domain, MonoClass *klass, MonoError *error);
1961 MonoObjectHandle
1962 mono_object_new_pinned_handle (MonoDomain *domain, MonoClass *klass, MonoError *error);
1964 MonoObject *
1965 mono_object_new_specific_checked (MonoVTable *vtable, MonoError *error);
1967 ICALL_EXPORT
1968 MonoObject *
1969 ves_icall_object_new (MonoDomain *domain, MonoClass *klass);
1971 ICALL_EXPORT
1972 MonoObject *
1973 ves_icall_object_new_specific (MonoVTable *vtable);
1975 MonoObject *
1976 mono_object_new_alloc_specific_checked (MonoVTable *vtable, MonoError *error);
1978 void
1979 mono_field_get_value_internal (MonoObject *obj, MonoClassField *field, void *value);
1981 void
1982 mono_field_static_get_value_checked (MonoVTable *vt, MonoClassField *field, void *value, MonoStringHandleOut string_handle, MonoError *error);
1984 void
1985 mono_field_static_get_value_for_thread (MonoInternalThread *thread, MonoVTable *vt, MonoClassField *field, void *value, MonoStringHandleOut string_handle, MonoError *error);
1987 MonoMethod*
1988 mono_object_handle_get_virtual_method (MonoObjectHandle obj, MonoMethod *method, MonoError *error);
1990 /* exported, used by the debugger */
1991 MONO_API void *
1992 mono_vtable_get_static_field_data (MonoVTable *vt);
1994 MonoObject *
1995 mono_field_get_value_object_checked (MonoDomain *domain, MonoClassField *field, MonoObject *obj, MonoError *error);
1997 MonoObjectHandle
1998 mono_static_field_get_value_handle (MonoDomain *domain, MonoClassField *field, MonoError *error);
2000 gboolean
2001 mono_property_set_value_handle (MonoProperty *prop, MonoObjectHandle obj, void **params, MonoError *error);
2003 MonoObject*
2004 mono_property_get_value_checked (MonoProperty *prop, void *obj, void **params, MonoError *error);
2006 MonoString*
2007 mono_object_try_to_string (MonoObject *obj, MonoObject **exc, MonoError *error);
2009 char *
2010 mono_string_to_utf8_ignore (MonoString *s);
2012 gboolean
2013 mono_monitor_is_il_fastpath_wrapper (MonoMethod *method);
2015 MonoStringHandle
2016 mono_string_is_interned_lookup (MonoStringHandle str, gboolean insert, MonoError *error);
2019 * mono_string_intern_checked:
2020 * \param str String to intern
2021 * \param error set on error.
2022 * Interns the string passed.
2023 * \returns The interned string. On failure returns NULL and sets \p error
2025 #define mono_string_intern_checked(str, error) (mono_string_is_interned_lookup ((str), TRUE, (error)))
2028 * mono_string_is_interned_internal:
2029 * \param o String to probe
2030 * \returns Whether the string has been interned.
2032 #define mono_string_is_interned_internal(str, error) (mono_string_is_interned_lookup ((str), FALSE, (error)))
2034 char *
2035 mono_exception_handle_get_native_backtrace (MonoExceptionHandle exc);
2037 char *
2038 mono_exception_get_managed_backtrace (MonoException *exc);
2040 void
2041 mono_copy_value (MonoType *type, void *dest, void *value, int deref_pointer);
2043 void
2044 mono_error_raise_exception_deprecated (MonoError *target_error);
2046 gboolean
2047 mono_error_set_pending_exception_slow (MonoError *error);
2049 static inline gboolean
2050 mono_error_set_pending_exception (MonoError *error)
2052 return is_ok (error) ? FALSE : mono_error_set_pending_exception_slow (error);
2055 MonoArray *
2056 mono_glist_to_array (GList *list, MonoClass *eclass, MonoError *error);
2058 MonoObject *
2059 mono_object_new_checked (MonoDomain *domain, MonoClass *klass, MonoError *error);
2061 MonoObjectHandle
2062 mono_object_new_handle (MonoDomain *domain, MonoClass *klass, MonoError *error);
2064 // This function skips handling of remoting and COM.
2065 // "alloc" means "less".
2066 MonoObjectHandle
2067 mono_object_new_alloc_by_vtable (MonoVTable *vtable, MonoError *error);
2069 MonoObject*
2070 mono_object_new_mature (MonoVTable *vtable, MonoError *error);
2072 MonoObjectHandle
2073 mono_object_new_handle_mature (MonoVTable *vtable, MonoError *error);
2075 MonoObject *
2076 mono_object_clone_checked (MonoObject *obj, MonoError *error);
2078 MonoObjectHandle
2079 mono_object_clone_handle (MonoObjectHandle obj, MonoError *error);
2081 MonoObject *
2082 mono_object_isinst_checked (MonoObject *obj, MonoClass *klass, MonoError *error);
2084 MonoObjectHandle
2085 mono_object_handle_isinst (MonoObjectHandle obj, MonoClass *klass, MonoError *error);
2087 MonoObjectHandle
2088 mono_object_handle_isinst_mbyref (MonoObjectHandle obj, MonoClass *klass, MonoError *error);
2090 gboolean
2091 mono_object_handle_isinst_mbyref_raw (MonoObjectHandle obj, MonoClass *klass, MonoError *error);
2093 MonoStringHandle
2094 mono_string_new_size_handle (MonoDomain *domain, gint32 len, MonoError *error);
2096 MonoString*
2097 mono_string_new_len_checked (MonoDomain *domain, const char *text, guint length, MonoError *error);
2099 MonoString *
2100 mono_string_new_size_checked (MonoDomain *domain, gint32 len, MonoError *error);
2102 MonoString*
2103 mono_ldstr_checked (MonoDomain *domain, MonoImage *image, uint32_t str_index, MonoError *error);
2105 MonoStringHandle
2106 mono_ldstr_handle (MonoDomain *domain, MonoImage *image, uint32_t str_index, MonoError *error);
2108 MONO_PROFILER_API MonoString*
2109 mono_string_new_checked (MonoDomain *domain, const char *text, MonoError *merror);
2111 MonoString*
2112 mono_string_new_wtf8_len_checked (MonoDomain *domain, const char *text, guint length, MonoError *error);
2114 MonoString *
2115 mono_string_new_utf16_checked (MonoDomain *domain, const gunichar2 *text, gint32 len, MonoError *error);
2117 MonoStringHandle
2118 mono_string_new_utf16_handle (MonoDomain *domain, const gunichar2 *text, gint32 len, MonoError *error);
2120 MonoStringHandle
2121 mono_string_new_utf8_len (MonoDomain *domain, const char *text, guint length, MonoError *error);
2123 MonoString *
2124 mono_string_from_utf16_checked (const mono_unichar2 *data, MonoError *error);
2126 MonoString *
2127 mono_string_from_utf32_checked (const mono_unichar4 *data, MonoError *error);
2129 char*
2130 mono_ldstr_utf8 (MonoImage *image, guint32 idx, MonoError *error);
2132 char*
2133 mono_utf16_to_utf8 (const mono_unichar2 *s, gsize slength, MonoError *error);
2135 char*
2136 mono_utf16_to_utf8len (const mono_unichar2 *s, gsize slength, gsize *utf8_length, MonoError *error);
2138 gboolean
2139 mono_runtime_object_init_checked (MonoObject *this_obj, MonoError *error);
2141 MONO_PROFILER_API MonoObject*
2142 mono_runtime_try_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error);
2144 // The exc parameter is deliberately missing and so far this has proven to reduce code duplication.
2145 // In particular, if an exception is returned from underlying otherwise succeeded call,
2146 // is set into the MonoError with mono_error_set_exception_instance.
2147 // The result is that caller need only check MonoError.
2148 MonoObjectHandle
2149 mono_runtime_try_invoke_handle (MonoMethod *method, MonoObjectHandle obj, void **params, MonoError* error);
2151 MonoObject*
2152 mono_runtime_invoke_checked (MonoMethod *method, void *obj, void **params, MonoError *error);
2154 MonoObjectHandle
2155 mono_runtime_invoke_handle (MonoMethod *method, MonoObjectHandle obj, void **params, MonoError* error);
2157 void
2158 mono_runtime_invoke_handle_void (MonoMethod *method, MonoObjectHandle obj, void **params, MonoError* error);
2160 MonoObject*
2161 mono_runtime_try_invoke_array (MonoMethod *method, void *obj, MonoArray *params,
2162 MonoObject **exc, MonoError *error);
2164 MonoObject*
2165 mono_runtime_invoke_array_checked (MonoMethod *method, void *obj, MonoArray *params,
2166 MonoError *error);
2168 void*
2169 mono_compile_method_checked (MonoMethod *method, MonoError *error);
2171 MonoObject*
2172 mono_runtime_delegate_try_invoke (MonoObject *delegate, void **params,
2173 MonoObject **exc, MonoError *error);
2175 MonoObject*
2176 mono_runtime_delegate_invoke_checked (MonoObject *delegate, void **params,
2177 MonoError *error);
2179 MonoArrayHandle
2180 mono_runtime_get_main_args_handle (MonoError *error);
2183 mono_runtime_run_main_checked (MonoMethod *method, int argc, char* argv[],
2184 MonoError *error);
2187 mono_runtime_try_run_main (MonoMethod *method, int argc, char* argv[],
2188 MonoObject **exc);
2191 mono_runtime_exec_main_checked (MonoMethod *method, MonoArray *args, MonoError *error);
2194 mono_runtime_try_exec_main (MonoMethod *method, MonoArray *args, MonoObject **exc);
2196 MonoAssembly*
2197 mono_try_assembly_resolve_handle (MonoAssemblyLoadContext *alc, MonoStringHandle fname, MonoAssembly *requesting, gboolean refonly, MonoError *error);
2199 gboolean
2200 mono_runtime_object_init_handle (MonoObjectHandle this_obj, MonoError *error);
2202 /* GC write barriers support */
2203 void
2204 mono_gc_wbarrier_object_copy_handle (MonoObjectHandle obj, MonoObjectHandle src);
2206 MonoMethod*
2207 mono_class_get_virtual_method (MonoClass *klass, MonoMethod *method, gboolean is_proxy, MonoError *error);
2209 MonoStringHandle
2210 mono_string_empty_handle (MonoDomain *domain);
2213 * mono_object_get_data:
2215 * Return a pointer to the beginning of data inside a MonoObject.
2217 static inline gpointer
2218 mono_object_get_data (MonoObject *o)
2220 return (guint8*)o + MONO_ABI_SIZEOF (MonoObject);
2223 #define mono_handle_get_data_unsafe(handle) ((gpointer)((guint8*)MONO_HANDLE_RAW (handle) + MONO_ABI_SIZEOF (MonoObject)))
2225 gpointer
2226 mono_vtype_get_field_addr (gpointer vtype, MonoClassField *field);
2228 #define MONO_OBJECT_SETREF_INTERNAL(obj,fieldname,value) do { \
2229 mono_gc_wbarrier_set_field_internal ((MonoObject*)(obj), &((obj)->fieldname), (MonoObject*)value); \
2230 /*(obj)->fieldname = (value);*/ \
2231 } while (0)
2233 /* This should be used if 's' can reside on the heap */
2234 #define MONO_STRUCT_SETREF_INTERNAL(s,field,value) do { \
2235 mono_gc_wbarrier_generic_store_internal (&((s)->field), (MonoObject*)(value)); \
2236 } while (0)
2238 static inline gunichar2*
2239 mono_string_chars_internal (MonoString *s)
2241 MONO_REQ_GC_UNSAFE_MODE;
2242 return s->chars;
2245 static inline int
2246 mono_string_length_internal (MonoString *s)
2248 MONO_REQ_GC_UNSAFE_MODE;
2249 return s->length;
2252 MonoString*
2253 mono_string_empty_internal (MonoDomain *domain);
2255 char *
2256 mono_string_to_utf8len (MonoStringHandle s, gsize *utf8len, MonoError *error);
2258 char*
2259 mono_string_to_utf8_checked_internal (MonoString *string_obj, MonoError *error);
2261 mono_bool
2262 mono_string_equal_internal (MonoString *s1, MonoString *s2);
2264 unsigned
2265 mono_string_hash_internal (MonoString *s);
2268 mono_object_hash_internal (MonoObject* obj);
2270 ICALL_EXTERN_C
2271 void
2272 mono_value_copy_internal (void* dest, const void* src, MonoClass *klass);
2274 void
2275 mono_value_copy_array_internal (MonoArray *dest, int dest_idx, const void* src, int count);
2277 MONO_PROFILER_API MonoVTable* mono_object_get_vtable_internal (MonoObject *obj);
2279 MonoDomain*
2280 mono_object_get_domain_internal (MonoObject *obj);
2282 static inline gpointer
2283 mono_object_unbox_internal (MonoObject *obj)
2285 /* add assert for valuetypes? */
2286 g_assert (m_class_is_valuetype (mono_object_class (obj)));
2287 return mono_object_get_data (obj);
2290 ICALL_EXPORT
2291 void
2292 mono_monitor_exit_internal (MonoObject *obj);
2294 MONO_PROFILER_API unsigned mono_object_get_size_internal (MonoObject *o);
2296 MONO_PROFILER_API MonoDomain* mono_vtable_domain_internal (MonoVTable *vtable);
2298 MONO_PROFILER_API MonoClass* mono_vtable_class_internal (MonoVTable *vtable);
2300 MonoMethod*
2301 mono_object_get_virtual_method_internal (MonoObject *obj, MonoMethod *method);
2303 MonoMethod*
2304 mono_get_delegate_invoke_internal (MonoClass *klass);
2306 MonoMethod*
2307 mono_get_delegate_begin_invoke_internal (MonoClass *klass);
2309 MonoMethod*
2310 mono_get_delegate_end_invoke_internal (MonoClass *klass);
2312 void
2313 mono_unhandled_exception_internal (MonoObject *exc);
2315 void
2316 mono_print_unhandled_exception_internal (MonoObject *exc);
2318 void
2319 mono_raise_exception_internal (MonoException *ex);
2321 void
2322 mono_field_set_value_internal (MonoObject *obj, MonoClassField *field, void *value);
2324 void
2325 mono_field_static_set_value_internal (MonoVTable *vt, MonoClassField *field, void *value);
2327 void
2328 mono_field_get_value_internal (MonoObject *obj, MonoClassField *field, void *value);
2330 MonoMethod* mono_get_context_capture_method (void);
2332 guint8*
2333 mono_runtime_get_aotid_arr (void);
2335 /* GC handles support
2337 * A handle can be created to refer to a managed object and either prevent it
2338 * from being garbage collected or moved or to be able to know if it has been
2339 * collected or not (weak references).
2340 * mono_gchandle_new () is used to prevent an object from being garbage collected
2341 * until mono_gchandle_free() is called. Use a TRUE value for the pinned argument to
2342 * prevent the object from being moved (this should be avoided as much as possible
2343 * and this should be used only for shorts periods of time or performance will suffer).
2344 * To create a weakref use mono_gchandle_new_weakref (): track_resurrection should
2345 * usually be false (see the GC docs for more details).
2346 * mono_gchandle_get_target () can be used to get the object referenced by both kinds
2347 * of handle: for a weakref handle, if an object has been collected, it will return NULL.
2349 uint32_t
2350 mono_gchandle_new_internal (MonoObject *obj, mono_bool pinned);
2352 uint32_t
2353 mono_gchandle_new_weakref_internal (MonoObject *obj, mono_bool track_resurrection);
2355 ICALL_EXTERN_C
2356 MonoObject*
2357 mono_gchandle_get_target_internal (uint32_t gchandle);
2359 void mono_gchandle_free_internal (uint32_t gchandle);
2361 /* Reference queue support
2363 * A reference queue is used to get notifications of when objects are collected.
2364 * Call mono_gc_reference_queue_new to create a new queue and pass the callback that
2365 * will be invoked when registered objects are collected.
2366 * Call mono_gc_reference_queue_add to register a pair of objects and data within a queue.
2367 * The callback will be triggered once an object is both unreachable and finalized.
2369 MonoReferenceQueue*
2370 mono_gc_reference_queue_new_internal (mono_reference_queue_callback callback);
2372 void
2373 mono_gc_reference_queue_free_internal (MonoReferenceQueue *queue);
2375 mono_bool
2376 mono_gc_reference_queue_add_internal (MonoReferenceQueue *queue, MonoObject *obj, void *user_data);
2378 #define mono_gc_reference_queue_add_handle(queue, obj, user_data) \
2379 (mono_gc_reference_queue_add_internal ((queue), MONO_HANDLE_RAW (MONO_HANDLE_CAST (MonoObject, obj)), (user_data)))
2381 /* GC write barriers support */
2382 void
2383 mono_gc_wbarrier_set_field_internal (MonoObject *obj, void* field_ptr, MonoObject* value);
2385 void
2386 mono_gc_wbarrier_set_arrayref_internal (MonoArray *arr, void* slot_ptr, MonoObject* value);
2388 void
2389 mono_gc_wbarrier_arrayref_copy_internal (void* dest_ptr, const void* src_ptr, int count);
2391 void
2392 mono_gc_wbarrier_generic_store_internal (void volatile* ptr, MonoObject* value);
2394 void
2395 mono_gc_wbarrier_generic_store_atomic_internal (void *ptr, MonoObject *value);
2397 ICALL_EXTERN_C
2398 void
2399 mono_gc_wbarrier_generic_nostore_internal (void* ptr);
2401 void
2402 mono_gc_wbarrier_value_copy_internal (void* dest, const void* src, int count, MonoClass *klass);
2404 void
2405 mono_gc_wbarrier_object_copy_internal (MonoObject* obj, MonoObject *src);
2407 #endif /* __MONO_OBJECT_INTERNALS_H__ */