2 * object.c: Object creation for the Mono runtime
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
14 #include <mono/metadata/mono-endian.h>
15 #include <mono/metadata/tabledefs.h>
16 #include <mono/metadata/tokentype.h>
17 #include <mono/metadata/loader.h>
18 #include <mono/metadata/object.h>
19 #include <mono/metadata/gc-internal.h>
20 #include <mono/metadata/exception.h>
21 #include <mono/metadata/appdomain.h>
22 #include <mono/metadata/assembly.h>
23 #include <mono/metadata/threadpool.h>
24 #include <mono/metadata/marshal.h>
25 #include "mono/metadata/debug-helpers.h"
26 #include "mono/metadata/marshal.h"
27 #include <mono/metadata/threads.h>
28 #include <mono/metadata/environment.h>
29 #include "mono/metadata/profiler-private.h"
30 #include <mono/os/gc_wrapper.h>
33 * enable to get a good speedup: we still need to figure out
34 * how the sync structure is freed.
36 #define CREATION_SPEEDUP 0
39 mono_runtime_object_init (MonoObject *this)
42 MonoMethod *method = NULL;
43 MonoClass *klass = this->vtable->klass;
45 for (i = 0; i < klass->method.count; ++i) {
46 if (!strcmp (".ctor", klass->methods [i]->name) &&
47 klass->methods [i]->signature->param_count == 0) {
48 method = klass->methods [i];
55 mono_runtime_invoke (method, this, NULL, NULL);
59 * mono_runtime_class_init:
60 * @klass: klass that needs to be initialized
62 * This routine calls the class constructor for @class.
65 mono_runtime_class_init (MonoClass *klass)
68 MonoException *exc = NULL;
69 MonoException *exc_to_throw;
73 for (i = 0; i < klass->method.count; ++i) {
74 method = klass->methods [i];
75 if ((method->flags & METHOD_ATTRIBUTE_SPECIAL_NAME) &&
76 (strcmp (".cctor", method->name) == 0)) {
77 mono_runtime_invoke (method, NULL, NULL, (MonoObject **) &exc);
85 (klass->image == mono_defaults.corlib &&
86 !strcmp (klass->name_space, "System") &&
87 !strcmp (klass->name, "TypeInitializationException")))
88 return; /* No static constructor found or avoid infinite loop */
90 if (klass->name_space && *klass->name_space)
91 full_name = g_strdup_printf ("%s.%s", klass->name_space, klass->name);
93 full_name = g_strdup (klass->name);
95 exc_to_throw = mono_get_exception_type_initialization (full_name, exc);
98 mono_raise_exception (exc_to_throw);
102 default_trampoline (MonoMethod *method)
108 default_remoting_trampoline (MonoMethod *method)
110 g_error ("remoting not installed");
114 static MonoTrampoline arch_create_jit_trampoline = default_trampoline;
115 static MonoTrampoline arch_create_remoting_trampoline = default_remoting_trampoline;
118 mono_install_trampoline (MonoTrampoline func)
120 arch_create_jit_trampoline = func? func: default_trampoline;
124 mono_install_remoting_trampoline (MonoTrampoline func)
126 arch_create_remoting_trampoline = func? func: default_remoting_trampoline;
129 static MonoCompileFunc default_mono_compile_method = NULL;
132 mono_install_compile_method (MonoCompileFunc func)
134 default_mono_compile_method = func;
138 mono_compile_method (MonoMethod *method)
140 if (!default_mono_compile_method) {
141 g_error ("compile method called on uninitialized runtime");
144 return default_mono_compile_method (method);
148 #if 0 && HAVE_BOEHM_GC
150 vtable_finalizer (void *obj, void *data) {
151 g_print ("%s finalized (%p)\n", (char*)data, obj);
157 * @domain: the application domain
158 * @class: the class to initialize
160 * VTables are domain specific because we create domain specific code, and
161 * they contain the domain specific static class data.
164 mono_class_vtable (MonoDomain *domain, MonoClass *class)
168 MonoClassField *field;
170 guint32 cols [MONO_CONSTANT_SIZE];
177 vt = class->cached_vtable;
178 if (vt && vt->domain == domain)
181 mono_domain_lock (domain);
182 if ((vt = mono_g_hash_table_lookup (domain->class_vtable_hash, class))) {
183 mono_domain_unlock (domain);
188 mono_class_init (class);
190 mono_stats.used_class_count++;
191 mono_stats.class_vtable_size += sizeof (MonoVTable) + class->vtable_size * sizeof (gpointer);
193 vt = mono_mempool_alloc0 (domain->mp, sizeof (MonoVTable) +
194 class->vtable_size * sizeof (gpointer));
198 if (class->class_size) {
200 vt->data = GC_MALLOC (class->class_size + 8);
201 /*vt->data = GC_debug_malloc (class->class_size + 8, class->name, 2);*/
202 /*GC_register_finalizer (vt->data, vtable_finalizer, class->name, NULL, NULL);*/
203 mono_g_hash_table_insert (domain->static_data_hash, class, vt->data);
205 vt->data = mono_mempool_alloc0 (domain->mp, class->class_size + 8);
208 mono_stats.class_static_data_size += class->class_size + 8;
211 for (i = class->field.first; i < class->field.last; ++i) {
212 field = &class->fields [i - class->field.first];
213 if (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC))
215 if ((field->type->attrs & FIELD_ATTRIBUTE_HAS_FIELD_RVA)) {
216 MonoClass *fklass = mono_class_from_mono_type (field->type);
217 t = (char*)vt->data + field->offset;
218 if (fklass->valuetype) {
219 memcpy (t, field->data, mono_class_value_size (fklass, NULL));
221 /* it's a pointer type: add check */
222 g_assert (fklass->byval_arg.type == MONO_TYPE_PTR);
223 *t = *(gpointer*)field->data;
227 if (!(field->type->attrs & FIELD_ATTRIBUTE_HAS_DEFAULT))
229 cindex = mono_metadata_get_constant_index (class->image, MONO_TOKEN_FIELD_DEF | (i + 1));
231 g_warning ("constant for field %s not found", field->name);
234 mono_metadata_decode_row (&class->image->tables [MONO_TABLE_CONSTANT], cindex - 1, cols, MONO_CONSTANT_SIZE);
235 p = mono_metadata_blob_heap (class->image, cols [MONO_CONSTANT_VALUE]);
236 len = mono_metadata_decode_blob_size (p, &p);
237 t = (char*)vt->data + field->offset;
238 /* should we check that the type matches? */
239 switch (cols [MONO_CONSTANT_TYPE]) {
240 case MONO_TYPE_BOOLEAN:
248 guint16 *val = (guint16*)t;
254 guint32 *val = (guint32*)t;
260 guint64 *val = (guint64*)t;
265 float *val = (float*)t;
270 double *val = (double*)t;
274 case MONO_TYPE_STRING: {
275 gpointer *val = (gpointer*)t;
276 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
277 gunichar2 *copy = g_malloc (len);
279 for (j = 0; j < len/2; j++) {
280 copy [j] = read16 (p);
283 *val = mono_string_new_utf16 (domain, copy, len/2);
286 *val = mono_string_new_utf16 (domain, (const guint16*)p, len/2);
290 case MONO_TYPE_CLASS:
291 /* nothing to do, we malloc0 the data and the value can be 0 only */
294 g_warning ("type 0x%02x should not be in constant table", cols [MONO_CONSTANT_TYPE]);
298 vt->max_interface_id = class->max_interface_id;
300 vt->interface_offsets = mono_mempool_alloc0 (domain->mp,
301 sizeof (gpointer) * (class->max_interface_id + 1));
303 /* initialize interface offsets */
304 for (k = class; k ; k = k->parent) {
305 for (i = 0; i < k->interface_count; i++) {
307 MonoClass *ic = k->interfaces [i];
308 slot = class->interface_offsets [ic->interface_id];
309 vt->interface_offsets [ic->interface_id] = &vt->vtable [slot];
314 * arch_create_jit_trampoline () can recursively call this function again
315 * because it compiles icall methods right away.
317 mono_g_hash_table_insert (domain->class_vtable_hash, class, vt);
318 if (!class->cached_vtable)
319 class->cached_vtable = vt;
321 /* initialize vtable */
322 for (i = 0; i < class->vtable_size; ++i) {
325 if ((cm = class->vtable [i]))
326 vt->vtable [i] = arch_create_jit_trampoline (cm);
329 mono_domain_unlock (domain);
331 /* make sure the the parent is initialized */
333 mono_class_vtable (domain, class->parent);
335 mono_runtime_class_init (class);
337 if (class->contextbound)
346 * mono_class_proxy_vtable:
347 * @domain: the application domain
348 * @class: the class to proxy
350 * Creates a vtable for transparent proxies. It is basically
351 * a copy of the real vtable of @class, but all function pointers invoke
352 * the remoting functions, and vtable->klass points to the
353 * transparent proxy class, and not to @class.
356 mono_class_proxy_vtable (MonoDomain *domain, MonoClass *class)
358 MonoVTable *vt, *pvt;
361 if ((pvt = mono_g_hash_table_lookup (domain->proxy_vtable_hash, class)))
364 vt = mono_class_vtable (domain, class);
365 vtsize = sizeof (MonoVTable) + class->vtable_size * sizeof (gpointer);
367 mono_stats.class_vtable_size += vtsize;
369 pvt = mono_mempool_alloc (domain->mp, vtsize);
370 memcpy (pvt, vt, vtsize);
372 pvt->klass = mono_defaults.transparent_proxy_class;
374 /* initialize vtable */
375 for (i = 0; i < class->vtable_size; ++i) {
378 if ((cm = class->vtable [i]))
379 pvt->vtable [i] = arch_create_remoting_trampoline (cm);
382 mono_g_hash_table_insert (domain->proxy_vtable_hash, class, pvt);
388 * Retrieve the MonoMethod that would to be called on obj if obj is passed as
389 * the instance of a callvirt of method.
392 mono_object_get_virtual_method (MonoObject *obj, MonoMethod *method) {
398 if ((method->flags & METHOD_ATTRIBUTE_FINAL) || !(method->flags & METHOD_ATTRIBUTE_VIRTUAL))
401 klass = mono_object_class (obj);
402 if (klass == mono_defaults.transparent_proxy_class) {
403 klass = ((MonoTransparentProxy *)obj)->klass;
408 vtable = klass->vtable;
410 /* check method->slot is a valid index: perform isinstance? */
411 if (method->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
412 res = vtable [klass->interface_offsets [method->klass->interface_id] + method->slot];
414 res = vtable [method->slot];
419 return mono_marshal_get_remoting_invoke (res);
425 dummy_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
427 g_error ("runtime invoke called on uninitialized runtime");
431 static MonoInvokeFunc default_mono_runtime_invoke = dummy_mono_runtime_invoke;
434 mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc)
436 return default_mono_runtime_invoke (method, obj, params, exc);
440 set_value (MonoType *type, void *dest, void *value, int deref_pointer) {
443 gpointer *p = (gpointer*)dest;
450 case MONO_TYPE_BOOLEAN:
453 guint8 *p = (guint8*)dest;
454 *p = *(guint8*)value;
459 case MONO_TYPE_CHAR: {
460 guint16 *p = (guint16*)dest;
461 *p = *(guint16*)value;
464 #if SIZEOF_VOID_P == 4
470 gint32 *p = (gint32*)dest;
471 *p = *(gint32*)value;
474 #if SIZEOF_VOID_P == 8
480 gint64 *p = (gint64*)dest;
481 *p = *(gint64*)value;
485 float *p = (float*)dest;
490 double *p = (double*)dest;
491 *p = *(double*)value;
494 case MONO_TYPE_STRING:
495 case MONO_TYPE_SZARRAY:
496 case MONO_TYPE_CLASS:
497 case MONO_TYPE_OBJECT:
498 case MONO_TYPE_ARRAY:
499 case MONO_TYPE_PTR: {
500 gpointer *p = (gpointer*)dest;
501 *p = deref_pointer? *(gpointer*)value: value;
504 case MONO_TYPE_VALUETYPE:
505 if (type->data.klass->enumtype) {
506 t = type->data.klass->enum_basetype->type;
510 size = mono_class_value_size (type->data.klass, NULL);
511 memcpy (dest, value, size);
515 g_warning ("got type %x", type->type);
516 g_assert_not_reached ();
521 mono_field_set_value (MonoObject *obj, MonoClassField *field, void *value)
525 g_return_if_fail (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC));
527 dest = (char*)obj + field->offset;
528 set_value (field->type, dest, value, FALSE);
532 mono_field_static_set_value (MonoVTable *vt, MonoClassField *field, void *value)
536 g_return_if_fail (field->type->attrs & FIELD_ATTRIBUTE_STATIC);
538 dest = (char*)vt->data + field->offset;
539 set_value (field->type, dest, value, FALSE);
543 mono_field_get_value (MonoObject *obj, MonoClassField *field, void *value)
547 g_return_if_fail (!(field->type->attrs & FIELD_ATTRIBUTE_STATIC));
549 src = (char*)obj + field->offset;
550 set_value (field->type, value, src, TRUE);
554 mono_field_static_get_value (MonoVTable *vt, MonoClassField *field, void *value)
558 g_return_if_fail (field->type->attrs & FIELD_ATTRIBUTE_STATIC);
560 src = (char*)vt->data + field->offset;
561 set_value (field->type, value, src, TRUE);
565 mono_property_set_value (MonoProperty *prop, void *obj, void **params, MonoObject **exc)
567 default_mono_runtime_invoke (prop->set, obj, params, exc);
571 mono_property_get_value (MonoProperty *prop, void *obj, void **params, MonoObject **exc)
573 return default_mono_runtime_invoke (prop->get, obj, params, exc);
578 mono_get_delegate_invoke (MonoClass *klass)
585 for (i = 0; i < klass->method.count; ++i) {
586 if (klass->methods [i]->name[0] == 'I' &&
587 !strcmp ("Invoke", klass->methods [i]->name)) {
588 im = klass->methods [i];
598 mono_runtime_delegate_invoke (MonoObject *delegate, void **params, MonoObject **exc)
602 im = mono_get_delegate_invoke (delegate->vtable->klass);
605 return mono_runtime_invoke (im, delegate, params, exc);
608 static MonoArray* main_args;
611 mono_runtime_get_main_args (void)
617 * Execute a standard Main() method (argc/argv contains the
618 * executable name). This method also sets the command line argument value
619 * needed by System.Environment.
622 mono_runtime_run_main (MonoMethod *method, int argc, char* argv[],
626 MonoArray *args = NULL;
627 MonoDomain *domain = mono_domain_get ();
629 main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, argc);
631 if (!g_path_is_absolute (argv [0])) {
632 gchar *basename = g_path_get_basename (argv [0]);
633 gchar *fullpath = g_build_filename (method->klass->image->assembly->basedir,
637 mono_array_set (main_args, gpointer, 0, mono_string_new (domain, fullpath));
641 mono_array_set (main_args, gpointer, 0, mono_string_new (domain, argv [0]));
644 for (i = 1; i < argc; ++i) {
645 MonoString *arg = mono_string_new (domain, argv [i]);
646 mono_array_set (main_args, gpointer, i, arg);
650 if (method->signature->param_count) {
651 args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, argc);
652 for (i = 0; i < argc; ++i) {
653 MonoString *arg = mono_string_new (domain, argv [i]);
654 mono_array_set (args, gpointer, i, arg);
657 args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, 0);
660 mono_assembly_set_main (method->klass->image->assembly);
662 return mono_runtime_exec_main (method, args, exc);
666 * We call this function when we dectect an unhandled exception. It invokes the
667 * UnhandledException event in AppDomain or print a warning to the console
670 mono_unhandled_exception (MonoObject *exc)
672 MonoDomain *domain = mono_domain_get ();
673 MonoClassField *field;
674 MonoObject *delegate;
676 field=mono_class_get_field_from_name(mono_defaults.appdomain_class,
677 "UnhandledException");
680 if (exc->vtable->klass != mono_defaults.threadabortexception_class) {
681 delegate = *(MonoObject **)(((char *)domain->domain) + field->offset);
684 mono_print_unhandled_exception (exc);
686 MonoObject *e = NULL;
689 /* fixme: pass useful arguments */
692 mono_runtime_delegate_invoke (delegate, pa, &e);
695 g_warning ("exception inside UnhandledException handler!");
701 * Launch a new thread to start all setup that requires managed code
704 * main_func is called back from the thread with main_args as the
705 * parameter. The callback function is expected to start Main()
706 * eventually. This function then waits for all managed threads to
710 mono_runtime_exec_managed_code (MonoDomain *domain,
711 MonoMainThreadFunc main_func,
714 mono_thread_create (domain, main_func, main_args);
716 mono_thread_manage ();
720 * Execute a standard Main() method (args doesn't contain the
724 mono_runtime_exec_main (MonoMethod *method, MonoArray *args, MonoObject **exc)
734 domain = mono_object_domain (args);
735 if (!domain->entry_assembly) {
736 domain->entry_assembly = method->klass->image->assembly;
737 ves_icall_System_AppDomainSetup_InitAppDomainSetup (domain->setup);
740 /* FIXME: check signature of method */
741 if (method->signature->ret->type == MONO_TYPE_I4) {
743 res = mono_runtime_invoke (method, NULL, pa, exc);
745 rval = *(guint32 *)((char *)res + sizeof (MonoObject));
749 mono_environment_exitcode_set (rval);
751 mono_runtime_invoke (method, NULL, pa, exc);
755 /* If the return type of Main is void, only
756 * set the exitcode if an exception was thrown
757 * (we don't want to blow away an
758 * explicitly-set exit code)
761 mono_environment_exitcode_set (rval);
769 mono_install_runtime_invoke (MonoInvokeFunc func)
771 default_mono_runtime_invoke = func ? func: dummy_mono_runtime_invoke;
775 mono_runtime_invoke_array (MonoMethod *method, void *obj, MonoArray *params,
778 MonoMethodSignature *sig = method->signature;
782 if (NULL != params) {
783 pa = alloca (sizeof (gpointer) * mono_array_length (params));
784 for (i = 0; i < mono_array_length (params); i++) {
785 if (sig->params [i]->byref) {
789 switch (sig->params [i]->type) {
792 case MONO_TYPE_BOOLEAN:
804 case MONO_TYPE_VALUETYPE:
805 pa [i] = (char *)(((gpointer *)params->vector)[i]) + sizeof (MonoObject);
807 case MONO_TYPE_STRING:
808 case MONO_TYPE_OBJECT:
809 case MONO_TYPE_CLASS:
810 case MONO_TYPE_ARRAY:
811 case MONO_TYPE_SZARRAY:
812 pa [i] = (char *)(((gpointer *)params->vector)[i]);
815 g_error ("type 0x%x not handled in ves_icall_InternalInvoke", sig->params [i]->type);
820 if (!strcmp (method->name, ".ctor") && method->klass != mono_defaults.string_class) {
822 obj = mono_object_new (mono_domain_get (), method->klass);
823 mono_runtime_invoke (method, obj, pa, exc);
826 return mono_runtime_invoke (method, obj, pa, exc);
830 * mono_object_allocate:
831 * @size: number of bytes to allocate
833 * This is a very simplistic routine until we have our GC-aware
836 * Returns: an allocated object of size @size, or NULL on failure.
839 mono_object_allocate (size_t size)
842 /* if this is changed to GC_debug_malloc(), we need to change also metadata/gc.c */
843 void *o = GC_MALLOC (size);
845 void *o = calloc (1, size);
848 mono_stats.new_object_count++;
856 * Frees the memory used by the object. Debugging purposes
857 * only, as we will have our GC system.
860 mono_object_free (MonoObject *o)
863 g_error ("mono_object_free called with boehm gc.");
865 MonoClass *c = o->vtable->klass;
867 memset (o, 0, c->instance_size);
874 * @klass: the class of the object that we want to create
876 * Returns: A newly created object whose definition is
877 * looked up using @klass
880 mono_object_new (MonoDomain *domain, MonoClass *klass)
882 return mono_object_new_specific (mono_class_vtable (domain, klass));
886 * mono_object_new_specific:
887 * @vtable: the vtable of the object that we want to create
889 * Returns: A newly created object with class and domain specified
893 mono_object_new_specific (MonoVTable *vtable)
900 MonoMethod *im = vtable->domain->create_proxy_for_type_method;
903 MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Runtime.Remoting.Activation", "ActivationServices");
907 mono_class_init (klass);
909 for (i = 0; i < klass->method.count; ++i) {
910 if (!strcmp ("CreateProxyForType", klass->methods [i]->name) &&
911 klass->methods [i]->signature->param_count == 1) {
912 im = klass->methods [i];
917 vtable->domain->create_proxy_for_type_method = im;
920 pa [0] = mono_type_get_object (mono_domain_get (), &vtable->klass->byval_arg);
922 o = mono_runtime_invoke (im, NULL, pa, NULL);
923 if (o != NULL) return o;
926 return mono_object_new_alloc_specific (vtable);
930 mono_object_new_alloc_specific (MonoVTable *vtable)
932 MonoObject *o = mono_object_allocate (vtable->klass->instance_size);
934 if (vtable->klass->has_finalize)
935 mono_object_register_finalizer (o);
937 mono_profiler_allocation (o, vtable->klass);
942 * mono_object_new_from_token:
943 * @image: Context where the type_token is hosted
944 * @token: a token of the type that we want to create
946 * Returns: A newly created object whose definition is
947 * looked up using @token in the @image image
950 mono_object_new_from_token (MonoDomain *domain, MonoImage *image, guint32 token)
954 class = mono_class_get (image, token);
956 return mono_object_new (domain, class);
962 * @obj: the object to clone
964 * Returns: A newly created object who is a shallow copy of @obj
967 mono_object_clone (MonoObject *obj)
972 size = obj->vtable->klass->instance_size;
973 o = mono_object_allocate (size);
974 mono_profiler_allocation (o, obj->vtable->klass);
976 memcpy (o, obj, size);
978 if (obj->vtable->klass->has_finalize)
979 mono_object_register_finalizer (o);
985 * @array: the array to clone
987 * Returns: A newly created array who is a shallow copy of @array
990 mono_array_clone (MonoArray *array)
995 MonoClass *klass = array->obj.vtable->klass;
999 if (array->bounds == NULL) {
1000 size = mono_array_length (array);
1001 o = mono_array_new_full (((MonoObject *)array)->vtable->domain,
1002 klass, &size, NULL);
1004 size *= mono_array_element_size (klass);
1005 memcpy (o, array, sizeof (MonoArray) + size);
1010 sizes = alloca (klass->rank * sizeof(guint32) * 2);
1011 size = mono_array_element_size (klass);
1012 for (i = 0; i < klass->rank; ++i) {
1013 sizes [i] = array->bounds [i].length;
1014 size *= array->bounds [i].length;
1015 sizes [i + klass->rank] = array->bounds [i].lower_bound;
1017 o = mono_array_new_full (((MonoObject *)array)->vtable->domain,
1018 klass, sizes, sizes + klass->rank);
1019 memcpy (o, array, sizeof(MonoArray) + size);
1025 * mono_array_new_full:
1026 * @domain: domain where the object is created
1027 * @array_class: array class
1028 * @lengths: lengths for each dimension in the array
1029 * @lower_bounds: lower bounds for each dimension in the array (may be NULL)
1031 * This routine creates a new array objects with the given dimensions,
1032 * lower bounds and type.
1035 mono_array_new_full (MonoDomain *domain, MonoClass *array_class,
1036 guint32 *lengths, guint32 *lower_bounds)
1038 guint32 byte_len, len;
1041 MonoArrayBounds *bounds;
1044 if (!array_class->inited)
1045 mono_class_init (array_class);
1047 byte_len = mono_array_element_size (array_class);
1050 if (array_class->rank == 1 &&
1051 (lower_bounds == NULL || lower_bounds [0] == 0)) {
1056 bounds = GC_MALLOC (sizeof (MonoArrayBounds) * array_class->rank);
1058 bounds = g_malloc0 (sizeof (MonoArrayBounds) * array_class->rank);
1060 for (i = 0; i < array_class->rank; ++i) {
1061 bounds [i].length = lengths [i];
1066 for (i = 0; i < array_class->rank; ++i)
1067 bounds [i].lower_bound = lower_bounds [i];
1072 * Following three lines almost taken from mono_object_new ():
1073 * they need to be kept in sync.
1075 o = mono_object_allocate (sizeof (MonoArray) + byte_len);
1078 o->vtable = mono_class_vtable (domain, array_class);
1080 array = (MonoArray*)o;
1082 array->bounds = bounds;
1083 array->max_length = len;
1085 mono_profiler_allocation (o, array_class);
1092 * @domain: domain where the object is created
1093 * @eclass: element class
1094 * @n: number of array elements
1096 * This routine creates a new szarray with @n elements of type @eclass.
1099 mono_array_new (MonoDomain *domain, MonoClass *eclass, guint32 n)
1103 ac = mono_array_class_get (&eclass->byval_arg, 1);
1104 g_assert (ac != NULL);
1106 return mono_array_new_specific (mono_class_vtable (domain, ac), n);
1110 * mono_array_new_specific:
1111 * @vtable: a vtable in the appropriate domain for an initialized class
1112 * @n: number of array elements
1114 * This routine is a fast alternative to mono_array_new() for code which
1115 * can be sure about the domain it operates in.
1118 mono_array_new_specific (MonoVTable *vtable, guint32 n)
1124 byte_len = n * mono_array_element_size (vtable->klass);
1125 #if CREATION_SPEEDUP
1126 if (vtable->klass->element_class->byval_arg.type >= MONO_TYPE_BOOLEAN && vtable->klass->element_class->byval_arg.type <= MONO_TYPE_R4) {
1127 o = GC_MALLOC_ATOMIC (sizeof (MonoArray) + byte_len);
1128 o->synchronisation = 0;
1129 memset (((MonoArray*)o)->vector, 0, byte_len);
1131 o = mono_object_allocate (sizeof (MonoArray) + byte_len);
1134 o = mono_object_allocate (sizeof (MonoArray) + byte_len);
1140 ao = (MonoArray *)o;
1143 mono_profiler_allocation (o, vtable->klass);
1149 * mono_string_new_utf16:
1150 * @text: a pointer to an utf16 string
1151 * @len: the length of the string
1153 * Returns: A newly created string object which contains @text.
1156 mono_string_new_utf16 (MonoDomain *domain, const guint16 *text, gint32 len)
1160 s = mono_string_new_size (domain, len);
1161 g_assert (s != NULL);
1163 memcpy (mono_string_chars (s), text, len * 2);
1169 * mono_string_new_size:
1170 * @text: a pointer to an utf16 string
1171 * @len: the length of the string
1173 * Returns: A newly created string object of @len
1176 mono_string_new_size (MonoDomain *domain, gint32 len)
1180 #if CREATION_SPEEDUP
1181 s = GC_MALLOC_ATOMIC (sizeof (MonoString) + ((len + 1) * 2));
1182 s->object.synchronisation = 0;
1183 mono_string_chars (s) [len] = 0;
1185 s = (MonoString*)mono_object_allocate (sizeof (MonoString) + ((len + 1) * 2));
1190 s->object.vtable = mono_class_vtable (domain, mono_defaults.string_class);
1192 mono_profiler_allocation ((MonoObject*)s, mono_defaults.string_class);
1198 * mono_string_new_len:
1199 * @text: a pointer to an utf8 string
1200 * @length: number of bytes in @text to consider
1202 * Returns: A newly created string object which contains @text.
1205 mono_string_new_len (MonoDomain *domain, const char *text, guint length)
1207 GError *error = NULL;
1208 MonoString *o = NULL;
1210 glong items_written;
1213 ut = g_utf8_to_utf16 (text, length, NULL, &items_written, &error);
1216 o = mono_string_new_utf16 (domain, ut, items_written);
1218 g_error_free (error);
1227 * @text: a pointer to an utf8 string
1229 * Returns: A newly created string object which contains @text.
1232 mono_string_new (MonoDomain *domain, const char *text)
1234 GError *error = NULL;
1235 MonoString *o = NULL;
1237 glong items_written;
1242 ut = g_utf8_to_utf16 (text, l, NULL, &items_written, &error);
1245 o = mono_string_new_utf16 (domain, ut, items_written);
1247 g_error_free (error);
1255 * mono_string_new_wrapper:
1256 * @text: pointer to utf8 characters.
1258 * Helper function to create a string object from @text in the current domain.
1261 mono_string_new_wrapper (const char *text)
1263 MonoDomain *domain = mono_domain_get ();
1266 return mono_string_new (domain, text);
1273 * @class: the class of the value
1274 * @value: a pointer to the unboxed data
1276 * Returns: A newly created object which contains @value.
1279 mono_value_box (MonoDomain *domain, MonoClass *class, gpointer value)
1284 g_assert (class->valuetype);
1286 size = mono_class_instance_size (class);
1287 res = mono_object_allocate (size);
1288 res->vtable = mono_class_vtable (domain, class);
1289 mono_profiler_allocation (res, class);
1291 size = size - sizeof (MonoObject);
1293 #if NO_UNALIGNED_ACCESS
1294 memcpy ((char *)res + sizeof (MonoObject), value, size);
1298 *((guint8 *) res + sizeof (MonoObject)) = *(guint8 *) value;
1301 *(guint16 *)((guint8 *) res + sizeof (MonoObject)) = *(guint16 *) value;
1304 *(guint32 *)((guint8 *) res + sizeof (MonoObject)) = *(guint32 *) value;
1307 *(guint64 *)((guint8 *) res + sizeof (MonoObject)) = *(guint64 *) value;
1310 memcpy ((char *)res + sizeof (MonoObject), value, size);
1313 if (class->has_finalize)
1314 mono_object_register_finalizer (res);
1319 * mono_object_isinst:
1321 * @klass: a pointer to a class
1323 * Returns: @obj if @obj is derived from @klass
1326 mono_object_isinst (MonoObject *obj, MonoClass *klass)
1338 mono_class_init (klass);
1340 if (klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
1341 if ((klass->interface_id <= oklass->max_interface_id) &&
1342 vt->interface_offsets [klass->interface_id])
1345 if (oklass == mono_defaults.transparent_proxy_class) {
1346 /* fixme: add check for IRemotingTypeInfo */
1347 oklass = ((MonoTransparentProxy *)obj)->klass;
1350 if (oklass->rank == klass->rank &&
1351 (oklass->cast_class->baseval - klass->cast_class->baseval) <=
1352 klass->cast_class->diffval)
1355 } else if ((oklass->baseval - klass->baseval) <= klass->diffval)
1363 mono_string_is_interned_lookup (MonoString *str, int insert)
1365 MonoGHashTable *ldstr_table;
1368 char *ins = g_malloc (4 + str->length * 2);
1372 /* Encode the length */
1374 mono_metadata_encode_value (2 * str->length, p, &p);
1377 mono_metadata_encode_value (bloblen + 2 * str->length, p, &p);
1378 bloblen = (p - ins) + 2 * str->length;
1380 * ins is stored in the hash table as a key and needs to have the same
1381 * representation as in the metadata: we swap the character bytes on big
1384 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
1387 char *p2 = mono_string_chars (str);
1388 for (i = 0; i < str->length; ++i) {
1395 memcpy (p, mono_string_chars (str), str->length * 2);
1397 domain = ((MonoObject *)str)->vtable->domain;
1398 ldstr_table = domain->ldstr_table;
1399 mono_domain_lock (domain);
1400 if ((res = mono_g_hash_table_lookup (ldstr_table, ins))) {
1401 mono_domain_unlock (domain);
1406 mono_g_hash_table_insert (ldstr_table, ins, str);
1407 mono_domain_unlock (domain);
1410 mono_domain_unlock (domain);
1416 mono_string_is_interned (MonoString *o)
1418 return mono_string_is_interned_lookup (o, FALSE);
1422 mono_string_intern (MonoString *str)
1424 return mono_string_is_interned_lookup (str, TRUE);
1429 * @domain: the domain where the string will be used.
1430 * @image: a metadata context
1431 * @idx: index into the user string table.
1433 * Implementation for the ldstr opcode.
1436 mono_ldstr (MonoDomain *domain, MonoImage *image, guint32 idx)
1438 const char *str, *sig;
1442 MONO_ARCH_SAVE_REGS;
1444 if (image->assembly->dynamic)
1445 return mono_lookup_dynamic_token (image, MONO_TOKEN_STRING | idx);
1447 sig = str = mono_metadata_user_string (image, idx);
1449 mono_domain_lock (domain);
1450 if ((o = mono_g_hash_table_lookup (domain->ldstr_table, sig))) {
1451 mono_domain_unlock (domain);
1455 len2 = mono_metadata_decode_blob_size (str, &str);
1458 o = mono_string_new_utf16 (domain, (guint16*)str, len2);
1459 #if G_BYTE_ORDER != G_LITTLE_ENDIAN
1462 guint16 *p2 = (guint16*)mono_string_chars (o);
1463 for (i = 0; i < len2; ++i) {
1464 *p2 = GUINT16_FROM_LE (*p2);
1469 mono_g_hash_table_insert (domain->ldstr_table, (gpointer)sig, o);
1470 mono_domain_unlock (domain);
1476 * mono_string_to_utf8:
1477 * @s: a System.String
1479 * Return the UTF8 representation for @s.
1480 * the resulting buffer nedds to be freed with g_free().
1483 mono_string_to_utf8 (MonoString *s)
1486 GError *error = NULL;
1492 return g_strdup ("");
1494 as = g_utf16_to_utf8 (mono_string_chars (s), s->length, NULL, NULL, &error);
1496 g_warning (error->message);
1502 * mono_string_to_utf16:
1505 * Return an null-terminated array of the utf-16 chars
1506 * contained in @s. The result must be freed with g_free().
1507 * This is a temporary helper until our string implementation
1508 * is reworked to always include the null terminating char.
1511 mono_string_to_utf16 (MonoString *s)
1518 as = g_malloc ((s->length * 2) + 2);
1519 as [(s->length * 2)] = '\0';
1520 as [(s->length * 2) + 1] = '\0';
1523 return (gunichar2 *)(as);
1526 memcpy (as, mono_string_chars(s), s->length * 2);
1527 return (gunichar2 *)(as);
1531 * Converts a NULL terminated UTF16 string (LPWSTR) to a MonoString
1534 mono_string_from_utf16 (gunichar2 *data)
1536 MonoDomain *domain = mono_domain_get ();
1542 while (data [len]) len++;
1544 return mono_string_new_utf16 (domain, data, len);
1548 default_ex_handler (MonoException *ex)
1550 MonoObject *o = (MonoObject*)ex;
1551 g_error ("Exception %s.%s raised in C code", o->vtable->klass->name_space, o->vtable->klass->name);
1554 static MonoExceptionFunc ex_handler = default_ex_handler;
1557 mono_install_handler (MonoExceptionFunc func)
1559 ex_handler = func? func: default_ex_handler;
1563 * mono_raise_exception:
1564 * @ex: exception object
1566 * Signal the runtime that the exception @ex has been raised in unmanaged code.
1569 mono_raise_exception (MonoException *ex)
1575 mono_wait_handle_new (MonoDomain *domain, HANDLE handle)
1577 MonoWaitHandle *res;
1579 res = (MonoWaitHandle *)mono_object_new (domain, mono_defaults.waithandle_class);
1581 res->handle = handle;
1587 mono_async_result_new (MonoDomain *domain, HANDLE handle, MonoObject *state, gpointer data)
1589 MonoAsyncResult *res;
1591 res = (MonoAsyncResult *)mono_object_new (domain, mono_defaults.asyncresult_class);
1594 res->async_state = state;
1595 res->handle = (MonoObject *)mono_wait_handle_new (domain, handle);
1596 res->sync_completed = FALSE;
1597 res->completed = FALSE;
1603 mono_message_init (MonoDomain *domain,
1604 MonoMethodMessage *this,
1605 MonoReflectionMethod *method,
1606 MonoArray *out_args)
1608 MonoMethodSignature *sig = method->method->signature;
1614 this->method = method;
1616 this->args = mono_array_new (domain, mono_defaults.object_class, sig->param_count);
1617 this->arg_types = mono_array_new (domain, mono_defaults.byte_class, sig->param_count);
1619 names = g_new (char *, sig->param_count);
1620 mono_method_get_param_names (method->method, (const char **) names);
1621 this->names = mono_array_new (domain, mono_defaults.string_class, sig->param_count);
1623 for (i = 0; i < sig->param_count; i++) {
1624 name = mono_string_new (domain, names [i]);
1625 mono_array_set (this->names, gpointer, i, name);
1630 for (i = 0, j = 0; i < sig->param_count; i++) {
1632 if (sig->params [i]->byref) {
1634 gpointer arg = mono_array_get (out_args, gpointer, j);
1635 mono_array_set (this->args, gpointer, i, arg);
1639 if (sig->params [i]->attrs & PARAM_ATTRIBUTE_IN)
1645 mono_array_set (this->arg_types, guint8, i, arg_type);
1650 * mono_remoting_invoke:
1651 * @real_proxy: pointer to a RealProxy object
1652 * @msg: The MonoMethodMessage to execute
1653 * @exc: used to store exceptions
1654 * @out_args: used to store output arguments
1656 * This is used to call RealProxy::Invoke(). RealProxy::Invoke() returns an
1657 * IMessage interface and it is not trivial to extract results from there. So
1658 * we call an helper method PrivateInvoke instead of calling
1659 * RealProxy::Invoke() directly.
1661 * Returns: the result object.
1664 mono_remoting_invoke (MonoObject *real_proxy, MonoMethodMessage *msg,
1665 MonoObject **exc, MonoArray **out_args)
1667 MonoMethod *im = real_proxy->vtable->domain->private_invoke_method;
1670 /*static MonoObject *(*invoke) (gpointer, gpointer, MonoObject **, MonoArray **) = NULL;*/
1676 klass = mono_defaults.real_proxy_class;
1678 for (i = 0; i < klass->method.count; ++i) {
1679 if (!strcmp ("PrivateInvoke", klass->methods [i]->name) &&
1680 klass->methods [i]->signature->param_count == 4) {
1681 im = klass->methods [i];
1687 real_proxy->vtable->domain->private_invoke_method = im;
1690 pa [0] = real_proxy;
1695 return mono_runtime_invoke (im, NULL, pa, exc);
1699 mono_message_invoke (MonoObject *target, MonoMethodMessage *msg,
1700 MonoObject **exc, MonoArray **out_args)
1702 if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
1704 return mono_remoting_invoke ((MonoObject *)((MonoTransparentProxy *)target)->rp,
1705 msg, exc, out_args);
1708 MonoDomain *domain = mono_domain_get ();
1709 MonoMethod *method = msg->method->method;
1710 MonoMethodSignature *sig = method->signature;
1711 int i, j, outarg_count = 0;
1713 for (i = 0; i < sig->param_count; i++) {
1714 if (sig->params [i]->byref)
1718 *out_args = mono_array_new (domain, mono_defaults.object_class, outarg_count);
1721 for (i = 0, j = 0; i < sig->param_count; i++) {
1722 if (sig->params [i]->byref) {
1724 arg = mono_array_get (msg->args, gpointer, i);
1725 mono_array_set (*out_args, gpointer, j, arg);
1730 return mono_runtime_invoke_array (method, target, msg->args, exc);
1735 mono_print_unhandled_exception (MonoObject *exc)
1737 char *message = (char *) "";
1741 gboolean free_message = FALSE;
1744 if (mono_object_isinst (exc, mono_defaults.exception_class)) {
1745 klass = exc->vtable->klass;
1747 while (klass && method == NULL) {
1748 for (i = 0; i < klass->method.count; ++i) {
1749 method = klass->methods [i];
1750 if (!strcmp ("ToString", method->name) &&
1751 method->signature->param_count == 0 &&
1752 method->flags & METHOD_ATTRIBUTE_VIRTUAL &&
1753 method->flags & METHOD_ATTRIBUTE_PUBLIC) {
1760 klass = klass->parent;
1765 str = (MonoString *) mono_runtime_invoke (method, exc, NULL, NULL);
1767 message = mono_string_to_utf8 (str);
1768 free_message = TRUE;
1773 * g_printerr ("\nUnhandled Exception: %s.%s: %s\n", exc->vtable->klass->name_space,
1774 * exc->vtable->klass->name, message);
1776 g_printerr ("\nUnhandled Exception: %s\n", message);
1783 * mono_delegate_ctor:
1784 * @this: pointer to an uninitialized delegate object
1785 * @target: target object
1786 * @addr: pointer to native code
1788 * This is used to initialize a delegate. We also insert the method_info if
1789 * we find the info with mono_jit_info_table_find().
1792 mono_delegate_ctor (MonoObject *this, MonoObject *target, gpointer addr)
1794 MonoDomain *domain = mono_domain_get ();
1795 MonoDelegate *delegate = (MonoDelegate *)this;
1796 MonoMethod *method = NULL;
1803 class = this->vtable->klass;
1805 if ((ji = mono_jit_info_table_find (domain, addr))) {
1806 method = ji->method;
1807 delegate->method_info = mono_method_get_object (domain, method, NULL);
1810 if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
1812 method = mono_marshal_get_remoting_invoke (method);
1813 delegate->method_ptr = mono_compile_method (method);
1814 delegate->target = target;
1816 delegate->method_ptr = addr;
1817 delegate->target = target;
1822 * mono_method_call_message_new:
1824 * Translates arguments pointers into a Message.
1827 mono_method_call_message_new (MonoMethod *method, gpointer *params, MonoMethod *invoke,
1828 MonoDelegate **cb, MonoObject **state)
1830 MonoDomain *domain = mono_domain_get ();
1831 MonoMethodSignature *sig = method->signature;
1832 MonoMethodMessage *msg;
1835 msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
1838 mono_message_init (domain, msg, mono_method_get_object (domain, invoke, NULL), NULL);
1839 count = sig->param_count - 2;
1841 mono_message_init (domain, msg, mono_method_get_object (domain, method, NULL), NULL);
1842 count = sig->param_count;
1845 for (i = 0; i < count; i++) {
1850 if (sig->params [i]->byref)
1851 vpos = *((gpointer *)params [i]);
1855 type = sig->params [i]->type;
1856 class = mono_class_from_mono_type (sig->params [i]);
1858 if (class->valuetype)
1859 arg = mono_value_box (domain, class, vpos);
1861 arg = *((MonoObject **)vpos);
1863 mono_array_set (msg->args, gpointer, i, arg);
1867 *cb = *((MonoDelegate **)params [i]);
1869 *state = *((MonoObject **)params [i]);
1876 * mono_method_return_message_restore:
1878 * Restore results from message based processing back to arguments pointers
1881 mono_method_return_message_restore (MonoMethod *method, gpointer *params, MonoArray *out_args)
1883 MonoMethodSignature *sig = method->signature;
1884 int i, j, type, size;
1886 for (i = 0, j = 0; i < sig->param_count; i++) {
1887 MonoType *pt = sig->params [i];
1889 size = mono_type_stack_size (pt, NULL);
1892 char *arg = mono_array_get (out_args, gpointer, j);
1896 case MONO_TYPE_VOID:
1897 g_assert_not_reached ();
1901 case MONO_TYPE_BOOLEAN:
1904 case MONO_TYPE_CHAR:
1911 case MONO_TYPE_VALUETYPE: {
1912 memcpy (*((gpointer *)params [i]), arg + sizeof (MonoObject), size);
1915 case MONO_TYPE_STRING:
1916 case MONO_TYPE_CLASS:
1917 case MONO_TYPE_ARRAY:
1918 case MONO_TYPE_SZARRAY:
1919 *((MonoObject **)params [i]) = (MonoObject *)arg;
1922 g_assert_not_reached ();
1931 * mono_load_remote_field:
1932 * @this: pointer to an object
1933 * @klass: klass of the object containing @field
1934 * @field: the field to load
1935 * @res: a storage to store the result
1937 * This method is called by the runtime on attempts to load fields of
1938 * transparent proxy objects. @this points to such TP, @klass is the class of
1939 * the object containing @field. @res is a storage location which can be
1940 * used to store the result.
1942 * Returns: an address pointing to the value of field.
1945 mono_load_remote_field (MonoObject *this, MonoClass *klass, MonoClassField *field, gpointer *res)
1947 static MonoMethod *getter = NULL;
1948 MonoDomain *domain = mono_domain_get ();
1949 MonoClass *field_class;
1950 MonoMethodMessage *msg;
1951 MonoArray *out_args;
1955 g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
1963 for (i = 0; i < mono_defaults.object_class->method.count; ++i) {
1964 MonoMethod *cm = mono_defaults.object_class->methods [i];
1966 if (!strcmp (cm->name, "FieldGetter")) {
1974 field_class = mono_class_from_mono_type (field->type);
1976 msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
1977 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
1978 mono_message_init (domain, msg, mono_method_get_object (domain, getter, NULL), out_args);
1980 mono_array_set (msg->args, gpointer, 0, mono_string_new (domain, klass->name));
1981 mono_array_set (msg->args, gpointer, 1, mono_string_new (domain, field->name));
1983 mono_remoting_invoke ((MonoObject *)((MonoTransparentProxy *)this)->rp, msg, &exc, &out_args);
1985 *res = mono_array_get (out_args, MonoObject *, 0);
1987 if (field_class->valuetype) {
1988 return ((char *)*res) + sizeof (MonoObject);
1994 mono_load_remote_field_new (MonoObject *this, MonoClass *klass, MonoClassField *field)
1996 static MonoMethod *getter = NULL;
1997 MonoDomain *domain = mono_domain_get ();
1998 MonoClass *field_class;
1999 MonoMethodMessage *msg;
2000 MonoArray *out_args;
2001 MonoObject *exc, *res;
2003 g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
2008 for (i = 0; i < mono_defaults.object_class->method.count; ++i) {
2009 MonoMethod *cm = mono_defaults.object_class->methods [i];
2011 if (!strcmp (cm->name, "FieldGetter")) {
2019 field_class = mono_class_from_mono_type (field->type);
2021 msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
2022 out_args = mono_array_new (domain, mono_defaults.object_class, 1);
2023 mono_message_init (domain, msg, mono_method_get_object (domain, getter, NULL), out_args);
2025 mono_array_set (msg->args, gpointer, 0, mono_string_new (domain, klass->name));
2026 mono_array_set (msg->args, gpointer, 1, mono_string_new (domain, field->name));
2028 mono_remoting_invoke ((MonoObject *)((MonoTransparentProxy *)this)->rp, msg, &exc, &out_args);
2030 res = mono_array_get (out_args, MonoObject *, 0);
2036 * mono_store_remote_field:
2037 * @this: pointer to an object
2038 * @klass: klass of the object containing @field
2039 * @field: the field to load
2040 * @val: the value/object to store
2042 * This method is called by the runtime on attempts to store fields of
2043 * transparent proxy objects. @this points to such TP, @klass is the class of
2044 * the object containing @field. @val is the new value to store in @field.
2047 mono_store_remote_field (MonoObject *this, MonoClass *klass, MonoClassField *field, gpointer val)
2049 static MonoMethod *setter = NULL;
2050 MonoDomain *domain = mono_domain_get ();
2051 MonoClass *field_class;
2052 MonoMethodMessage *msg;
2053 MonoArray *out_args;
2057 g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
2062 for (i = 0; i < mono_defaults.object_class->method.count; ++i) {
2063 MonoMethod *cm = mono_defaults.object_class->methods [i];
2065 if (!strcmp (cm->name, "FieldSetter")) {
2073 field_class = mono_class_from_mono_type (field->type);
2075 if (field_class->valuetype)
2076 arg = mono_value_box (domain, field_class, val);
2078 arg = *((MonoObject **)val);
2081 msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
2082 mono_message_init (domain, msg, mono_method_get_object (domain, setter, NULL), NULL);
2084 mono_array_set (msg->args, gpointer, 0, mono_string_new (domain, klass->name));
2085 mono_array_set (msg->args, gpointer, 1, mono_string_new (domain, field->name));
2086 mono_array_set (msg->args, gpointer, 2, arg);
2088 mono_remoting_invoke ((MonoObject *)((MonoTransparentProxy *)this)->rp, msg, &exc, &out_args);
2092 mono_store_remote_field_new (MonoObject *this, MonoClass *klass, MonoClassField *field, MonoObject *arg)
2094 static MonoMethod *setter = NULL;
2095 MonoDomain *domain = mono_domain_get ();
2096 MonoMethodMessage *msg;
2097 MonoArray *out_args;
2100 g_assert (this->vtable->klass == mono_defaults.transparent_proxy_class);
2105 for (i = 0; i < mono_defaults.object_class->method.count; ++i) {
2106 MonoMethod *cm = mono_defaults.object_class->methods [i];
2108 if (!strcmp (cm->name, "FieldSetter")) {
2116 msg = (MonoMethodMessage *)mono_object_new (domain, mono_defaults.mono_method_message_class);
2117 mono_message_init (domain, msg, mono_method_get_object (domain, setter, NULL), NULL);
2119 mono_array_set (msg->args, gpointer, 0, mono_string_new (domain, klass->name));
2120 mono_array_set (msg->args, gpointer, 1, mono_string_new (domain, field->name));
2121 mono_array_set (msg->args, gpointer, 2, arg);
2123 mono_remoting_invoke ((MonoObject *)((MonoTransparentProxy *)this)->rp, msg, &exc, &out_args);