2 * PLEASE NOTE: This is a research prototype.
5 * interp.c: Interpreter for CIL byte codes
8 * Paolo Molaro (lupus@ximian.com)
9 * Miguel de Icaza (miguel@ximian.com)
10 * Dietmar Maurer (dietmar@ximian.com)
12 * (C) 2001, 2002 Ximian, Inc.
27 #include <mono/utils/gc_wrapper.h>
33 # define alloca __builtin_alloca
37 /* trim excessive headers */
38 #include <mono/metadata/image.h>
39 #include <mono/metadata/assembly.h>
40 #include <mono/metadata/cil-coff.h>
41 #include <mono/metadata/mono-endian.h>
42 #include <mono/metadata/tabledefs.h>
43 #include <mono/metadata/tokentype.h>
44 #include <mono/metadata/loader.h>
45 #include <mono/metadata/threads.h>
46 #include <mono/metadata/threadpool-ms.h>
47 #include <mono/metadata/profiler-private.h>
48 #include <mono/metadata/appdomain.h>
49 #include <mono/metadata/reflection.h>
50 #include <mono/metadata/reflection-internals.h>
51 #include <mono/metadata/exception.h>
52 #include <mono/metadata/verify.h>
53 #include <mono/metadata/opcodes.h>
54 #include <mono/metadata/debug-helpers.h>
55 #include <mono/metadata/mono-config.h>
56 #include <mono/metadata/marshal.h>
57 #include <mono/metadata/environment.h>
58 #include <mono/metadata/mono-debug.h>
65 #define OPDEF(a,b,c,d,e,f,g,h,i,j) \
69 #include "mono/cil/opcode.def"
74 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
77 #define finite _finite
81 #define finite isfinite
85 static gint *abort_requested;
87 /* If true, then we output the opcodes as we interpret them */
88 static int global_tracing = 0;
89 static int global_no_pointers = 0;
91 int mono_interp_traceopt = 0;
93 static int debug_indent_level = 0;
95 #define INIT_FRAME(frame,parent_frame,obj_this,method_args,method_retval,domain,mono_method,error) \
97 (frame)->parent = (parent_frame); \
98 (frame)->obj = (obj_this); \
99 (frame)->stack_args = (method_args); \
100 (frame)->retval = (method_retval); \
101 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
102 (frame)->ex = NULL; \
103 (frame)->ip = NULL; \
104 (frame)->invoke_trap = 0; \
107 void ves_exec_method (MonoInvocation *frame);
109 static char* dump_stack (stackval *stack, stackval *sp);
110 static char* dump_frame (MonoInvocation *inv);
111 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
112 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
114 typedef void (*ICallMethod) (MonoInvocation *frame);
116 static guint32 die_on_exception = 0;
117 static MonoNativeTlsKey thread_context_id;
119 #define DEBUG_INTERP 1
123 static int break_on_method = 0;
124 static int nested_trace = 0;
125 static GList *db_methods = NULL;
132 for (h = 0; h < debug_indent_level; h++)
137 db_match_method (gpointer data, gpointer user_data)
139 MonoMethod *m = (MonoMethod*)user_data;
140 MonoMethodDesc *desc = data;
142 if (mono_method_desc_full_match (desc, m))
146 #define DEBUG_ENTER() \
148 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method); \
149 if (break_on_method) tracing=nested_trace ? (global_tracing = 2, 3) : 2; \
150 break_on_method = 0; \
153 MonoMethod *method = frame->runtime_method->method ;\
154 char *mn, *args = dump_args (frame); \
155 debug_indent_level++; \
157 mn = mono_method_full_name (method, FALSE); \
158 g_print ("(%u) Entering %s (", mono_thread_internal_current (), mn); \
160 g_print ("%s)\n", args); \
163 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
164 mono_profiler_method_enter (frame->runtime_method->method);
166 #define DEBUG_LEAVE() \
169 args = dump_retval (frame); \
171 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
172 g_print ("(%u) Leaving %s", mono_thread_internal_current (), mn); \
174 g_print (" => %s\n", args); \
176 debug_indent_level--; \
177 if (tracing == 3) global_tracing = 0; \
179 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
180 mono_profiler_method_leave (frame->runtime_method->method);
184 #define DEBUG_ENTER()
185 #define DEBUG_LEAVE()
190 interp_ex_handler (MonoException *ex) {
192 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
196 stack_trace = dump_frame (context->current_frame);
197 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
198 g_free (stack_trace);
199 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
200 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
201 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
202 fprintf(stderr, "Nothing can catch this exception: ");
203 fprintf(stderr, "%s", ex->object.vtable->klass->name);
204 if (ex->message != NULL) {
205 char *m = mono_string_to_utf8_checked (ex->message, &error);
206 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
207 fprintf(stderr, ": %s", m);
210 fprintf(stderr, "\n%s\n", strace);
212 if (ex->inner_ex != NULL) {
213 ex = (MonoException *)ex->inner_ex;
214 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
215 if (ex->message != NULL) {
216 char *m = mono_string_to_utf8_checked (ex->message, &error);
217 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
218 fprintf(stderr, ": %s", m);
221 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
222 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
223 fprintf(stderr, "\n");
224 fprintf(stderr, "%s\n", strace);
227 /* wait for other threads to also collapse */
228 // Sleep(1000); // TODO: proper sleep
231 context->env_frame->ex = ex;
232 context->search_for_handler = 1;
233 longjmp (*context->current_env, 1);
237 ves_real_abort (int line, MonoMethod *mh,
238 const unsigned short *ip, stackval *stack, stackval *sp)
241 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
242 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
243 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
244 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
245 g_print ("0x%04x %02x\n",
246 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
247 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
249 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
252 #define ves_abort() \
254 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
255 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
259 interp_create_remoting_trampoline (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target, MonoError *error)
261 g_error ("FIXME: use domain and error");
262 // return mono_interp_get_runtime_method (mono_marshal_get_remoting_invoke_for_target (method, target));
265 static mono_mutex_t runtime_method_lookup_section;
268 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
271 mono_error_init (error);
273 mono_os_mutex_lock (&runtime_method_lookup_section);
274 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
275 mono_os_mutex_unlock (&runtime_method_lookup_section);
278 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
279 memset (rtm, 0, sizeof (*rtm));
280 rtm->method = method;
281 rtm->param_count = mono_method_signature (method)->param_count;
282 rtm->hasthis = mono_method_signature (method)->hasthis;
283 rtm->valuetype = method->klass->valuetype;
284 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
285 mono_os_mutex_unlock (&runtime_method_lookup_section);
291 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
293 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
294 method = mono_marshal_get_synchronized_wrapper (method);
295 return mono_interp_get_runtime_method (domain, method, error);
298 static inline RuntimeMethod*
299 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
301 MonoMethod *m = runtime_method->method;
304 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
305 RuntimeMethod *ret = NULL;
306 if (obj->vtable->klass == mono_defaults.transparent_proxy_class)
307 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
308 else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
309 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
311 ret = runtime_method;
312 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
316 if (m->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
317 // return ((RuntimeMethod **)obj->vtable->interface_offsets [m->klass->interface_id]) [m->slot];
318 g_error ("FIXME: interface method lookup");
321 return ((RuntimeMethod **)obj->vtable->vtable) [m->slot];
326 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
329 switch (type->type) {
330 case MONO_TYPE_OBJECT:
331 case MONO_TYPE_CLASS:
332 case MONO_TYPE_STRING:
333 case MONO_TYPE_ARRAY:
334 case MONO_TYPE_SZARRAY:
339 result->data.p = *(gpointer*)data;
342 switch (type->type) {
346 result->data.i = *(gint8*)data;
349 case MONO_TYPE_BOOLEAN:
350 result->data.i = *(guint8*)data;
353 result->data.i = *(gint16*)data;
357 result->data.i = *(guint16*)data;
360 result->data.i = *(gint32*)data;
364 result->data.nati = *(mono_i*)data;
367 result->data.p = *(gpointer*)data;
370 result->data.i = *(guint32*)data;
373 result->data.f = *(float*)data;
377 result->data.l = *(gint64*)data;
380 result->data.f = *(double*)data;
382 case MONO_TYPE_STRING:
383 case MONO_TYPE_SZARRAY:
384 case MONO_TYPE_CLASS:
385 case MONO_TYPE_OBJECT:
386 case MONO_TYPE_ARRAY:
387 result->data.p = *(gpointer*)data;
389 case MONO_TYPE_VALUETYPE:
390 if (type->data.klass->enumtype) {
391 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
397 size = mono_class_native_size (type->data.klass, NULL);
399 size = mono_class_value_size (type->data.klass, NULL);
400 memcpy (result->data.vt, data, size);
404 g_warning ("got type 0x%02x", type->type);
405 g_assert_not_reached ();
410 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
413 gpointer *p = (gpointer*)data;
417 /* printf ("TODAT0 %p\n", data); */
418 switch (type->type) {
421 guint8 *p = (guint8*)data;
425 case MONO_TYPE_BOOLEAN: {
426 guint8 *p = (guint8*)data;
427 *p = (val->data.i != 0);
432 case MONO_TYPE_CHAR: {
433 guint16 *p = (guint16*)data;
438 mono_i *p = (mono_i*)data;
439 /* In theory the value used by stloc should match the local var type
440 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
441 a native int - both by csc and mcs). Not sure what to do about sign extension
442 as it is outside the spec... doing the obvious */
443 *p = (mono_i)val->data.nati;
447 mono_u *p = (mono_u*)data;
449 *p = (mono_u)val->data.nati;
454 gint32 *p = (gint32*)data;
460 gint64 *p = (gint64*)data;
465 float *p = (float*)data;
470 double *p = (double*)data;
474 case MONO_TYPE_STRING:
475 case MONO_TYPE_SZARRAY:
476 case MONO_TYPE_CLASS:
477 case MONO_TYPE_OBJECT:
478 case MONO_TYPE_ARRAY:
479 case MONO_TYPE_PTR: {
480 gpointer *p = (gpointer*)data;
484 case MONO_TYPE_VALUETYPE:
485 if (type->data.klass->enumtype) {
486 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
492 size = mono_class_native_size (type->data.klass, NULL);
494 size = mono_class_value_size (type->data.klass, NULL);
496 memcpy (data, val->data.p, size);
500 g_warning ("got type %x", type->type);
501 g_assert_not_reached ();
506 fill_in_trace (MonoException *exception, MonoInvocation *frame)
508 char *stack_trace = dump_frame (frame);
509 MonoDomain *domain = mono_domain_get();
510 (exception)->stack_trace = mono_string_new (domain, stack_trace);
511 (exception)->trace_ips = get_trace_ips (domain, frame);
512 g_free (stack_trace);
515 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
517 #define THROW_EX(exception,ex_ip) \
519 frame->ip = (ex_ip); \
520 frame->ex = (MonoException*)(exception); \
521 FILL_IN_TRACE(frame->ex, frame); \
522 goto handle_exception; \
526 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
529 intptr_t *lower_bounds;
534 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
535 for (i = 0; i < sig->param_count; ++i) {
536 lengths [i] = values->data.i;
539 if (klass->rank == sig->param_count) {
540 /* Only lengths provided. */
543 /* lower bounds are first. */
544 lower_bounds = (intptr_t *) lengths;
545 lengths += klass->rank;
547 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
548 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
553 ves_array_set (MonoInvocation *frame)
555 stackval *sp = frame->stack_args;
559 gint32 i, t, pos, esize;
565 ac = o->vtable->klass;
567 g_assert (ac->rank >= 1);
570 if (ao->bounds != NULL) {
571 pos -= ao->bounds [0].lower_bound;
572 for (i = 1; i < ac->rank; i++) {
573 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
574 ao->bounds [i].length) {
575 frame->ex = mono_get_exception_index_out_of_range ();
576 FILL_IN_TRACE(frame->ex, frame);
579 pos = pos*ao->bounds [i].length + sp [i].data.i -
580 ao->bounds [i].lower_bound;
582 } else if (pos >= ao->max_length) {
583 frame->ex = mono_get_exception_index_out_of_range ();
584 FILL_IN_TRACE(frame->ex, frame);
589 if (sp [ac->rank].data.p && !mono_object_isinst (sp [ac->rank].data.p, mono_object_class (o)->element_class)) {
590 frame->ex = mono_get_exception_array_type_mismatch ();
591 FILL_IN_TRACE (frame->ex, frame);
596 esize = mono_array_element_size (ac);
597 ea = mono_array_addr_with_size (ao, esize, pos);
599 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
600 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
604 ves_array_get (MonoInvocation *frame)
606 stackval *sp = frame->stack_args;
610 gint32 i, t, pos, esize;
616 ac = o->vtable->klass;
618 g_assert (ac->rank >= 1);
621 if (ao->bounds != NULL) {
622 pos -= ao->bounds [0].lower_bound;
623 for (i = 1; i < ac->rank; i++) {
624 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
625 ao->bounds [i].length) {
626 frame->ex = mono_get_exception_index_out_of_range ();
627 FILL_IN_TRACE(frame->ex, frame);
631 pos = pos*ao->bounds [i].length + sp [i].data.i -
632 ao->bounds [i].lower_bound;
634 } else if (pos >= ao->max_length) {
635 frame->ex = mono_get_exception_index_out_of_range ();
636 FILL_IN_TRACE(frame->ex, frame);
640 esize = mono_array_element_size (ac);
641 ea = mono_array_addr_with_size (ao, esize, pos);
643 mt = mono_method_signature (frame->runtime_method->method)->ret;
644 stackval_from_data (mt, frame->retval, ea, FALSE);
648 ves_array_element_address (MonoInvocation *frame)
650 stackval *sp = frame->stack_args;
654 gint32 i, t, pos, esize;
659 ac = o->vtable->klass;
661 g_assert (ac->rank >= 1);
664 if (ao->bounds != NULL) {
665 pos -= ao->bounds [0].lower_bound;
666 for (i = 1; i < ac->rank; i++) {
667 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
668 ao->bounds [i].length) {
669 frame->ex = mono_get_exception_index_out_of_range ();
670 FILL_IN_TRACE(frame->ex, frame);
673 pos = pos*ao->bounds [i].length + sp [i].data.i -
674 ao->bounds [i].lower_bound;
676 } else if (pos >= ao->max_length) {
677 frame->ex = mono_get_exception_index_out_of_range ();
678 FILL_IN_TRACE(frame->ex, frame);
682 esize = mono_array_element_size (ac);
683 ea = mono_array_addr_with_size (ao, esize, pos);
685 frame->retval->data.p = ea;
689 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
691 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
692 MonoInvocation *frame;
694 MonoMethodHeader *hd;
697 if (!context) return;
699 frame = context->current_frame;
702 gboolean managed = FALSE;
703 MonoMethod *method = frame->runtime_method->method;
704 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
707 hd = mono_method_get_header_checked (method, &error);
708 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
709 il_offset = frame->ip - (const unsigned short *)hd->code;
710 if (!method->wrapper_type)
713 if (func (method, -1, il_offset, managed, user_data))
715 frame = frame->parent;
720 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
724 MonoInvocation *old_frame = context->current_frame;
725 MonoInvocation *old_env_frame = context->env_frame;
726 jmp_buf *old_env = context->current_env;
729 context->current_frame = old_frame;
730 context->env_frame = old_env_frame;
731 context->current_env = old_env;
732 context->managed_code = 1;
737 context->env_frame = frame;
738 context->current_env = &env;
740 if (frame->runtime_method) {
741 func = frame->runtime_method->func;
743 g_error ("FIXME: not available?");
745 func = mono_arch_create_trampoline (sig, string_ctor);
749 context->current_frame = frame;
750 context->managed_code = 0;
752 func (addr, &frame->retval->data.p, frame->obj, frame->stack_args);
754 context->managed_code = 1;
755 /* domain can only be changed by native code */
756 context->domain = mono_domain_get ();
758 if (*abort_requested)
759 mono_thread_interruption_checkpoint ();
762 stackval_from_data (&mono_defaults.string_class->byval_arg, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
763 } else if (!MONO_TYPE_ISSTRUCT (sig->ret))
764 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
766 context->current_frame = old_frame;
767 context->env_frame = old_env_frame;
768 context->current_env = old_env;
772 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
774 MonoDelegate *delegate = (MonoDelegate *)this;
777 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
778 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
779 delegate->target = target;
781 if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
782 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
783 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
784 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
786 delegate->method_ptr = runtime_method;
791 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
795 MonoDomain *domain = mono_domain_get ();
798 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
799 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
801 ji = mono_jit_info_table_find (domain, ftn);
803 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
805 /* FIXME: discard the wrapper and call the original method */
806 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
807 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
814 * runtime specifies that the implementation of the method is automatically
815 * provided by the runtime and is primarily used for the methods of delegates.
818 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
820 MonoMethod *method = frame->runtime_method->method;
821 const char *name = method->name;
822 MonoObject *obj = (MonoObject*)frame->obj;
823 MonoObject *isinst_obj;
826 mono_class_init (method->klass);
828 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
829 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
830 if (obj && isinst_obj) {
831 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
832 interp_delegate_ctor (context->domain, obj, frame->stack_args[0].data.p, frame->stack_args[1].data.p);
837 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
838 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
839 if (obj && isinst_obj) {
840 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
841 ves_array_set (frame);
844 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
845 ves_array_get (frame);
848 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
849 ves_array_element_address (frame);
854 g_error ("Don't know how to exec runtime method %s.%s::%s",
855 method->klass->name_space, method->klass->name,
860 dump_stack (stackval *stack, stackval *sp)
863 GString *str = g_string_new ("");
866 return g_string_free (str, FALSE);
869 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
872 return g_string_free (str, FALSE);
876 dump_stackval (GString *str, stackval *s, MonoType *type)
878 switch (type->type) {
886 case MONO_TYPE_BOOLEAN:
887 g_string_append_printf (str, "[%d] ", s->data.i);
889 case MONO_TYPE_STRING:
890 case MONO_TYPE_SZARRAY:
891 case MONO_TYPE_CLASS:
892 case MONO_TYPE_OBJECT:
893 case MONO_TYPE_ARRAY:
897 g_string_append_printf (str, "[%p] ", s->data.p);
899 case MONO_TYPE_VALUETYPE:
900 if (type->data.klass->enumtype)
901 g_string_append_printf (str, "[%d] ", s->data.i);
903 g_string_append_printf (str, "[vt:%p] ", s->data.p);
907 g_string_append_printf (str, "[%g] ", s->data.f);
912 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
918 dump_args (MonoInvocation *inv)
920 GString *str = g_string_new ("");
922 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
924 if (signature->param_count == 0)
925 return g_string_free (str, FALSE);
927 if (signature->hasthis)
928 g_string_append_printf (str, "%p ", inv->obj);
930 for (i = 0; i < signature->param_count; ++i)
931 dump_stackval (str, inv->stack_args + i, signature->params [i]);
933 return g_string_free (str, FALSE);
937 dump_retval (MonoInvocation *inv)
939 GString *str = g_string_new ("");
940 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
942 if (ret->type != MONO_TYPE_VOID)
943 dump_stackval (str, inv->retval, ret);
945 return g_string_free (str, FALSE);
949 dump_frame (MonoInvocation *inv)
951 GString *str = g_string_new ("");
956 for (i = 0; inv; inv = inv->parent) {
957 if (inv->runtime_method != NULL) {
958 MonoMethod *method = inv->runtime_method->method;
962 const char * opname = "";
964 gchar *source = NULL;
968 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
969 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
970 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
971 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
975 opname = mono_interp_opname [*inv->ip];
976 codep = inv->ip - inv->runtime_method->code;
980 g_error ("FIXME: proper source location");
981 // source = mono_debug_source_location_from_il_offset (method, codep, NULL);
984 args = dump_args (inv);
985 name = mono_method_full_name (method, TRUE);
987 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname,
990 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname,
998 return g_string_free (str, FALSE);
1002 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1006 MonoInvocation *inv;
1009 for (i = 0, inv = top; inv; inv = inv->parent)
1010 if (inv->runtime_method != NULL)
1013 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1014 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1016 for (i = 0, inv = top; inv; inv = inv->parent)
1017 if (inv->runtime_method != NULL) {
1018 mono_array_set (res, gpointer, i, inv->runtime_method);
1020 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1028 #define MYGUINT64_MAX 18446744073709551615ULL
1029 #define MYGINT64_MAX 9223372036854775807LL
1030 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1032 #define MYGUINT32_MAX 4294967295U
1033 #define MYGINT32_MAX 2147483647
1034 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1036 #define CHECK_ADD_OVERFLOW(a,b) \
1037 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1038 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1040 #define CHECK_SUB_OVERFLOW(a,b) \
1041 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1042 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1044 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1045 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1047 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1048 (guint32)(a) < (guint32)(b) ? -1 : 0
1050 #define CHECK_ADD_OVERFLOW64(a,b) \
1051 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1052 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1054 #define CHECK_SUB_OVERFLOW64(a,b) \
1055 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1056 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1058 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1059 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1061 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1062 (guint64)(a) < (guint64)(b) ? -1 : 0
1064 #if SIZEOF_VOID_P == 4
1065 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1066 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1068 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1069 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1072 /* Resolves to TRUE if the operands would overflow */
1073 #define CHECK_MUL_OVERFLOW(a,b) \
1074 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1075 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1076 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1077 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1078 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1079 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1080 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1082 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1083 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1084 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1086 #define CHECK_MUL_OVERFLOW64(a,b) \
1087 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1088 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1089 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1090 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1091 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1092 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1093 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1095 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1096 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1097 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1099 #if SIZEOF_VOID_P == 4
1100 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1101 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1103 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1104 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1108 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1110 MonoInvocation frame;
1111 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1112 MonoObject *retval = NULL;
1113 MonoMethodSignature *sig = mono_method_signature (method);
1114 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1115 int i, type, isobject = 0;
1118 stackval *args = alloca (sizeof (stackval) * sig->param_count);
1119 ThreadContext context_struct;
1120 MonoInvocation *old_frame = NULL;
1123 mono_error_init (error);
1128 if (context != &context_struct) {
1129 context->domain = mono_domain_get ();
1130 context->current_frame = old_frame;
1131 context->managed_code = 0;
1133 mono_native_tls_set_value (thread_context_id, NULL);
1135 *exc = (MonoObject *)frame.ex;
1139 if (context == NULL) {
1140 context = &context_struct;
1141 context_struct.base_frame = &frame;
1142 context_struct.current_frame = NULL;
1143 context_struct.env_frame = &frame;
1144 context_struct.current_env = &env;
1145 context_struct.search_for_handler = 0;
1146 context_struct.managed_code = 0;
1147 mono_native_tls_set_value (thread_context_id, context);
1150 old_frame = context->current_frame;
1152 context->domain = mono_domain_get ();
1154 switch (sig->ret->type) {
1155 case MONO_TYPE_VOID:
1157 case MONO_TYPE_STRING:
1158 case MONO_TYPE_OBJECT:
1159 case MONO_TYPE_CLASS:
1160 case MONO_TYPE_ARRAY:
1161 case MONO_TYPE_SZARRAY:
1164 case MONO_TYPE_VALUETYPE:
1165 retval = mono_object_new_checked (context->domain, klass, error);
1166 ret = ((char*)retval) + sizeof (MonoObject);
1167 if (!sig->ret->data.klass->enumtype)
1168 result.data.vt = ret;
1171 retval = mono_object_new_checked (context->domain, klass, error);
1172 ret = ((char*)retval) + sizeof (MonoObject);
1176 for (i = 0; i < sig->param_count; ++i) {
1177 if (sig->params [i]->byref) {
1178 args [i].data.p = params [i];
1181 type = sig->params [i]->type;
1186 case MONO_TYPE_BOOLEAN:
1187 args [i].data.i = *(MonoBoolean*)params [i];
1191 case MONO_TYPE_CHAR:
1192 args [i].data.i = *(gint16*)params [i];
1194 #if SIZEOF_VOID_P == 4
1195 case MONO_TYPE_U: /* use VAL_POINTER? */
1200 args [i].data.i = *(gint32*)params [i];
1202 #if SIZEOF_VOID_P == 8
1208 args [i].data.l = *(gint64*)params [i];
1210 case MONO_TYPE_VALUETYPE:
1211 if (sig->params [i]->data.klass->enumtype) {
1212 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1215 args [i].data.p = params [i];
1218 case MONO_TYPE_STRING:
1219 case MONO_TYPE_CLASS:
1220 case MONO_TYPE_ARRAY:
1221 case MONO_TYPE_SZARRAY:
1222 case MONO_TYPE_OBJECT:
1223 args [i].data.p = params [i];
1226 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1230 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1231 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1232 INIT_FRAME(&frame,context->current_frame,obj,args,&result,mono_get_root_domain (),method,error);
1234 frame.invoke_trap = 1;
1235 context->managed_code = 1;
1236 ves_exec_method_with_context (&frame, context);
1237 context->managed_code = 0;
1238 if (context == &context_struct)
1239 mono_native_tls_set_value (thread_context_id, NULL);
1241 context->current_frame = old_frame;
1242 if (frame.ex != NULL) {
1244 *exc = (MonoObject*) frame.ex;
1247 if (context->current_env != NULL) {
1248 context->env_frame->ex = frame.ex;
1249 longjmp(*context->current_env, 1);
1252 printf("dropped exception...\n");
1254 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1256 if (isobject || method->string_ctor)
1257 return result.data.p;
1258 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1263 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1265 MonoInvocation *old_frame = context->current_frame;
1266 MonoInvocation *old_env_frame = context->env_frame;
1267 jmp_buf *old_env = context->current_env;
1271 context->current_frame = old_frame;
1272 context->env_frame = old_env_frame;
1273 context->current_env = old_env;
1274 context->managed_code = 1;
1278 context->env_frame = context->current_frame;
1279 context->current_env = &env;
1280 context->managed_code = 0;
1283 case MINT_ICALL_V_V: {
1284 void (*func)() = ptr;
1288 case MINT_ICALL_P_V: {
1289 void (*func)(gpointer) = ptr;
1290 func (sp [-1].data.p);
1294 case MINT_ICALL_P_P: {
1295 gpointer (*func)(gpointer) = ptr;
1296 sp [-1].data.p = func (sp [-1].data.p);
1299 case MINT_ICALL_PP_V: {
1300 void (*func)(gpointer,gpointer) = ptr;
1302 func (sp [0].data.p, sp [1].data.p);
1305 case MINT_ICALL_PI_V: {
1306 void (*func)(gpointer,int) = ptr;
1308 func (sp [0].data.p, sp [1].data.i);
1311 case MINT_ICALL_PP_P: {
1312 gpointer (*func)(gpointer,gpointer) = ptr;
1314 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1317 case MINT_ICALL_PI_P: {
1318 gpointer (*func)(gpointer,int) = ptr;
1320 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1323 case MINT_ICALL_PPP_V: {
1324 void (*func)(gpointer,gpointer,gpointer) = ptr;
1326 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1329 case MINT_ICALL_PPI_V: {
1330 void (*func)(gpointer,gpointer,int) = ptr;
1332 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1336 g_assert_not_reached ();
1339 context->env_frame = old_env_frame;
1340 context->current_env = old_env;
1345 static mono_mutex_t create_method_pointer_mutex;
1347 static GHashTable *method_pointer_hash = NULL;
1350 mono_create_method_pointer (MonoMethod *method, MonoError *error)
1354 mono_error_init (error);
1356 mono_os_mutex_lock (&create_method_pointer_mutex);
1357 if (!method_pointer_hash) {
1358 // FIXME: is registering method table as GC root really necessary?
1359 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1360 method_pointer_hash = g_hash_table_new (NULL, NULL);
1362 addr = g_hash_table_lookup (method_pointer_hash, method);
1364 mono_os_mutex_unlock (&create_method_pointer_mutex);
1369 * If it is a static P/Invoke method, we can just return the pointer
1370 * to the method implementation.
1372 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1373 ji = g_new0 (MonoJitInfo, 1);
1374 ji->d.method = method;
1376 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1378 mono_jit_info_table_add (mono_get_root_domain (), ji);
1381 g_error ("FIXME: not available? figure out new API");
1383 addr = mono_arch_create_method_pointer (method);
1387 g_hash_table_insert (method_pointer_hash, method, addr);
1388 mono_os_mutex_unlock (&create_method_pointer_mutex);
1394 static int opcode_counts[512];
1396 #define COUNT_OP(op) opcode_counts[op]++
1398 #define COUNT_OP(op)
1402 #define DUMP_INSTR() \
1403 if (tracing > 1) { \
1405 if (sp > frame->stack) { \
1406 ins = dump_stack (frame->stack, sp); \
1408 ins = g_strdup (""); \
1412 g_print ("(%u) ", mono_thread_internal_current ()); \
1413 mono_interp_dis_mintop(rtm->code, ip); \
1414 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1418 #define DUMP_INSTR()
1422 #define USE_COMPUTED_GOTO 1
1424 #if USE_COMPUTED_GOTO
1425 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1426 #define MINT_IN_CASE(x) LAB_ ## x:
1428 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1430 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1432 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1434 #define MINT_IN_SWITCH(op) switch (op)
1435 #define MINT_IN_CASE(x) case x:
1436 #define MINT_IN_BREAK break
1437 #define MINT_IN_DEFAULT default:
1441 * Defining this causes register allocation errors in some versions of gcc:
1442 * error: unable to find a register to spill in class `SIREG'
1444 /* #define MINT_USE_DEDICATED_IP_REG */
1447 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1449 MonoInvocation child_frame;
1450 GSList *finally_ips = NULL;
1451 const unsigned short *endfinally_ip = NULL;
1452 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1453 register const unsigned short *ip asm ("%esi");
1455 register const unsigned short *ip;
1457 register stackval *sp;
1460 gint tracing = global_tracing;
1461 unsigned char *vtalloc;
1464 unsigned char *vt_sp;
1465 unsigned char *locals;
1467 MonoObject *o = NULL;
1469 #if USE_COMPUTED_GOTO
1470 static void *in_labels[] = {
1471 #define OPDEF(a,b,c,d) \
1473 #include "mintops.def"
1478 frame->ex_handler = NULL;
1480 context->current_frame = frame;
1484 if (!frame->runtime_method->transformed) {
1485 context->managed_code = 0;
1486 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1487 context->managed_code = 1;
1495 rtm = frame->runtime_method;
1496 frame->args = alloca (rtm->alloca_size);
1497 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1500 memset(sp, 0, rtm->stack_size);
1502 vt_sp = (unsigned char *) sp + rtm->stack_size;
1506 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1508 child_frame.parent = frame;
1514 * using while (ip < end) may result in a 15% performance drop,
1515 * but it may be useful for debug
1519 /* g_assert (sp >= frame->stack); */
1520 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1522 MINT_IN_SWITCH (*ip) {
1523 MINT_IN_CASE(MINT_INITLOCALS)
1524 memset (locals, 0, rtm->locals_size);
1527 MINT_IN_CASE(MINT_NOP)
1530 MINT_IN_CASE(MINT_BREAK)
1532 G_BREAKPOINT (); /* this is not portable... */
1534 MINT_IN_CASE(MINT_LDNULL)
1539 MINT_IN_CASE(MINT_VTRESULT) {
1540 int ret_size = * (guint16 *)(ip + 1);
1541 unsigned char *ret_vt_sp = vt_sp;
1542 vt_sp -= READ32(ip + 2);
1544 memmove (vt_sp, ret_vt_sp, ret_size);
1545 vt_sp += (ret_size + 7) & ~7;
1550 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1551 MINT_IN_CASE(MINT_LDC_I4_M1)
1554 MINT_IN_CASE(MINT_LDC_I4_0)
1557 MINT_IN_CASE(MINT_LDC_I4_1)
1560 MINT_IN_CASE(MINT_LDC_I4_2)
1563 MINT_IN_CASE(MINT_LDC_I4_3)
1566 MINT_IN_CASE(MINT_LDC_I4_4)
1569 MINT_IN_CASE(MINT_LDC_I4_5)
1572 MINT_IN_CASE(MINT_LDC_I4_6)
1575 MINT_IN_CASE(MINT_LDC_I4_7)
1578 MINT_IN_CASE(MINT_LDC_I4_8)
1581 MINT_IN_CASE(MINT_LDC_I4_S)
1582 sp->data.i = *(const short *)(ip + 1);
1586 MINT_IN_CASE(MINT_LDC_I4)
1588 sp->data.i = READ32 (ip);
1592 MINT_IN_CASE(MINT_LDC_I8)
1594 sp->data.l = READ64 (ip);
1598 MINT_IN_CASE(MINT_LDC_R4) {
1602 sp->data.f = * (float *)&val;
1607 MINT_IN_CASE(MINT_LDC_R8)
1608 sp->data.l = READ64 (ip + 1); /* note union usage */
1612 MINT_IN_CASE(MINT_DUP)
1617 MINT_IN_CASE(MINT_DUP_VT)
1618 i32 = READ32 (ip + 1);
1620 memcpy(sp->data.p, sp [-1].data.p, i32);
1621 vt_sp += (i32 + 7) & ~7;
1625 MINT_IN_CASE(MINT_POP)
1627 fprintf (stderr, "POP: 0x%08x\n", (sp-1)->data.i);
1630 MINT_IN_CASE(MINT_JMP) {
1631 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1632 if (!new_method->transformed) {
1634 frame->ex = mono_interp_transform_method (new_method, context);
1639 if (new_method->alloca_size > rtm->alloca_size)
1640 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1641 rtm = frame->runtime_method = new_method;
1642 vt_sp = (unsigned char *) sp + rtm->stack_size;
1646 locals = vt_sp + rtm->vt_stack_size;
1647 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1650 MINT_IN_CASE(MINT_CALLI) {
1651 MonoMethodSignature *csignature;
1652 stackval *endsp = sp;
1656 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1660 child_frame.runtime_method = sp->data.p;
1663 child_frame.retval = sp;
1664 /* decrement by the actual number of args */
1665 sp -= csignature->param_count;
1666 child_frame.stack_args = sp;
1667 if (csignature->hasthis) {
1669 child_frame.obj = sp->data.p;
1671 child_frame.obj = NULL;
1673 if (csignature->hasthis && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1674 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1675 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1676 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1677 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1678 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1681 ves_exec_method_with_context (&child_frame, context);
1683 context->current_frame = frame;
1685 if (child_frame.ex) {
1687 * An exception occurred, need to run finally, fault and catch handlers..
1689 frame->ex = child_frame.ex;
1690 goto handle_finally;
1693 /* need to handle typedbyref ... */
1694 if (csignature->ret->type != MONO_TYPE_VOID) {
1700 MINT_IN_CASE(MINT_CALLI_NAT) {
1701 MonoMethodSignature *csignature;
1702 stackval *endsp = sp;
1703 unsigned char *code = NULL;
1707 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1712 child_frame.runtime_method = NULL;
1715 child_frame.retval = sp;
1716 /* decrement by the actual number of args */
1717 sp -= csignature->param_count;
1718 child_frame.stack_args = sp;
1719 if (csignature->hasthis) {
1721 child_frame.obj = sp->data.p;
1723 child_frame.obj = NULL;
1725 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1727 context->current_frame = frame;
1729 if (child_frame.ex) {
1731 * An exception occurred, need to run finally, fault and catch handlers..
1733 frame->ex = child_frame.ex;
1734 if (context->search_for_handler) {
1735 context->search_for_handler = 0;
1736 goto handle_exception;
1738 goto handle_finally;
1741 /* need to handle typedbyref ... */
1742 if (csignature->ret->type != MONO_TYPE_VOID) {
1748 MINT_IN_CASE(MINT_CALL) {
1749 stackval *endsp = sp;
1753 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1756 child_frame.retval = sp;
1757 /* decrement by the actual number of args */
1758 sp -= child_frame.runtime_method->param_count;
1759 child_frame.stack_args = sp;
1760 if (child_frame.runtime_method->hasthis) {
1762 child_frame.obj = sp->data.p;
1764 child_frame.obj = NULL;
1766 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1767 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1768 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1770 ves_exec_method_with_context (&child_frame, context);
1772 context->current_frame = frame;
1774 if (child_frame.ex) {
1776 * An exception occurred, need to run finally, fault and catch handlers..
1778 frame->ex = child_frame.ex;
1779 goto handle_finally;
1782 /* need to handle typedbyref ... */
1787 MINT_IN_CASE(MINT_VCALL) {
1790 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1794 child_frame.retval = sp;
1795 /* decrement by the actual number of args */
1796 sp -= child_frame.runtime_method->param_count;
1797 child_frame.stack_args = sp;
1798 if (child_frame.runtime_method->hasthis) {
1800 child_frame.obj = sp->data.p;
1802 child_frame.obj = NULL;
1805 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1806 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1807 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1810 ves_exec_method_with_context (&child_frame, context);
1812 context->current_frame = frame;
1814 if (child_frame.ex) {
1816 * An exception occurred, need to run finally, fault and catch handlers..
1818 frame->ex = child_frame.ex;
1819 goto handle_finally;
1823 MINT_IN_CASE(MINT_CALLVIRT) {
1824 stackval *endsp = sp;
1825 MonoObject *this_arg;
1830 token = * (unsigned short *)(ip + 1);
1832 child_frame.runtime_method = rtm->data_items [token];
1834 child_frame.retval = sp;
1836 /* decrement by the actual number of args */
1837 sp -= child_frame.runtime_method->param_count;
1838 child_frame.stack_args = sp;
1840 child_frame.obj = this_arg = sp->data.p;
1842 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1843 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1845 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1846 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
1849 ves_exec_method_with_context (&child_frame, context);
1851 context->current_frame = frame;
1853 if (child_frame.ex) {
1855 * An exception occurred, need to run finally, fault and catch handlers..
1857 frame->ex = child_frame.ex;
1858 if (context->search_for_handler) {
1859 context->search_for_handler = 0;
1860 goto handle_exception;
1862 goto handle_finally;
1865 /* need to handle typedbyref ... */
1870 MINT_IN_CASE(MINT_VCALLVIRT) {
1871 MonoObject *this_arg;
1876 token = * (unsigned short *)(ip + 1);
1878 child_frame.runtime_method = rtm->data_items [token];
1880 child_frame.retval = sp;
1882 /* decrement by the actual number of args */
1883 sp -= child_frame.runtime_method->param_count;
1884 child_frame.stack_args = sp;
1886 child_frame.obj = this_arg = sp->data.p;
1888 THROW_EX (mono_get_exception_null_reference(), ip - 2);
1889 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
1891 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
1892 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
1895 ves_exec_method_with_context (&child_frame, context);
1897 context->current_frame = frame;
1899 if (child_frame.ex) {
1901 * An exception occurred, need to run finally, fault and catch handlers..
1903 frame->ex = child_frame.ex;
1904 if (context->search_for_handler) {
1905 context->search_for_handler = 0;
1906 goto handle_exception;
1908 goto handle_finally;
1912 MINT_IN_CASE(MINT_CALLINT)
1913 ves_pinvoke_method (frame, mono_method_signature (frame->runtime_method->method), ((MonoMethodPInvoke*) frame->runtime_method->method)->addr,
1914 frame->runtime_method->method->string_ctor, context);
1917 goto handle_exception;
1920 MINT_IN_CASE(MINT_CALLRUN)
1921 ves_runtime_method (frame, context);
1924 goto handle_exception;
1927 MINT_IN_CASE(MINT_RET)
1929 *frame->retval = *sp;
1930 if (sp > frame->stack)
1931 g_warning ("ret: more values on stack: %d", sp-frame->stack);
1933 MINT_IN_CASE(MINT_RET_VOID)
1934 if (sp > frame->stack)
1935 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
1937 MINT_IN_CASE(MINT_RET_VT)
1938 i32 = READ32(ip + 1);
1940 memcpy(frame->retval->data.p, sp->data.p, i32);
1941 if (sp > frame->stack)
1942 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
1944 MINT_IN_CASE(MINT_BR_S)
1945 ip += (short) *(ip + 1);
1947 MINT_IN_CASE(MINT_BR)
1948 ip += (gint32) READ32(ip + 1);
1950 #define ZEROP_S(datamem, op) \
1952 if (sp->data.datamem op 0) \
1953 ip += * (gint16 *)(ip + 1); \
1957 #define ZEROP(datamem, op) \
1959 if (sp->data.datamem op 0) \
1960 ip += READ32(ip + 1); \
1964 MINT_IN_CASE(MINT_BRFALSE_I4_S)
1967 MINT_IN_CASE(MINT_BRFALSE_I8_S)
1970 MINT_IN_CASE(MINT_BRFALSE_R8_S)
1973 MINT_IN_CASE(MINT_BRFALSE_I4)
1976 MINT_IN_CASE(MINT_BRFALSE_I8)
1979 MINT_IN_CASE(MINT_BRFALSE_R8)
1982 MINT_IN_CASE(MINT_BRTRUE_I4_S)
1985 MINT_IN_CASE(MINT_BRTRUE_I8_S)
1988 MINT_IN_CASE(MINT_BRTRUE_R8_S)
1991 MINT_IN_CASE(MINT_BRTRUE_I4)
1994 MINT_IN_CASE(MINT_BRTRUE_I8)
1997 MINT_IN_CASE(MINT_BRTRUE_R8)
2000 #define CONDBR_S(cond) \
2003 ip += * (gint16 *)(ip + 1); \
2006 #define BRELOP_S(datamem, op) \
2007 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2009 #define CONDBR(cond) \
2012 ip += READ32(ip + 1); \
2016 #define BRELOP(datamem, op) \
2017 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2019 MINT_IN_CASE(MINT_BEQ_I4_S)
2022 MINT_IN_CASE(MINT_BEQ_I8_S)
2025 MINT_IN_CASE(MINT_BEQ_R8_S)
2026 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2028 MINT_IN_CASE(MINT_BEQ_I4)
2031 MINT_IN_CASE(MINT_BEQ_I8)
2034 MINT_IN_CASE(MINT_BEQ_R8)
2035 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2037 MINT_IN_CASE(MINT_BGE_I4_S)
2040 MINT_IN_CASE(MINT_BGE_I8_S)
2043 MINT_IN_CASE(MINT_BGE_R8_S)
2044 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2046 MINT_IN_CASE(MINT_BGE_I4)
2049 MINT_IN_CASE(MINT_BGE_I8)
2052 MINT_IN_CASE(MINT_BGE_R8)
2053 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2055 MINT_IN_CASE(MINT_BGT_I4_S)
2058 MINT_IN_CASE(MINT_BGT_I8_S)
2061 MINT_IN_CASE(MINT_BGT_R8_S)
2062 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2064 MINT_IN_CASE(MINT_BGT_I4)
2067 MINT_IN_CASE(MINT_BGT_I8)
2070 MINT_IN_CASE(MINT_BGT_R8)
2071 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2073 MINT_IN_CASE(MINT_BLT_I4_S)
2076 MINT_IN_CASE(MINT_BLT_I8_S)
2079 MINT_IN_CASE(MINT_BLT_R8_S)
2080 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2082 MINT_IN_CASE(MINT_BLT_I4)
2085 MINT_IN_CASE(MINT_BLT_I8)
2088 MINT_IN_CASE(MINT_BLT_R8)
2089 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2091 MINT_IN_CASE(MINT_BLE_I4_S)
2094 MINT_IN_CASE(MINT_BLE_I8_S)
2097 MINT_IN_CASE(MINT_BLE_R8_S)
2098 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2100 MINT_IN_CASE(MINT_BLE_I4)
2103 MINT_IN_CASE(MINT_BLE_I8)
2106 MINT_IN_CASE(MINT_BLE_R8)
2107 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2109 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2112 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2115 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2116 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2118 MINT_IN_CASE(MINT_BNE_UN_I4)
2121 MINT_IN_CASE(MINT_BNE_UN_I8)
2124 MINT_IN_CASE(MINT_BNE_UN_R8)
2125 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2128 #define BRELOP_S_CAST(datamem, op, type) \
2130 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2131 ip += * (gint16 *)(ip + 1); \
2135 #define BRELOP_CAST(datamem, op, type) \
2137 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2138 ip += READ32(ip + 1); \
2142 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2143 BRELOP_S_CAST(i, >=, guint32);
2145 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2146 BRELOP_S_CAST(l, >=, guint64);
2148 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2149 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2151 MINT_IN_CASE(MINT_BGE_UN_I4)
2152 BRELOP_CAST(i, >=, guint32);
2154 MINT_IN_CASE(MINT_BGE_UN_I8)
2155 BRELOP_CAST(l, >=, guint64);
2157 MINT_IN_CASE(MINT_BGE_UN_R8)
2158 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2160 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2161 BRELOP_S_CAST(i, >, guint32);
2163 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2164 BRELOP_S_CAST(l, >, guint64);
2166 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2167 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2169 MINT_IN_CASE(MINT_BGT_UN_I4)
2170 BRELOP_CAST(i, >, guint32);
2172 MINT_IN_CASE(MINT_BGT_UN_I8)
2173 BRELOP_CAST(l, >, guint64);
2175 MINT_IN_CASE(MINT_BGT_UN_R8)
2176 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2178 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2179 BRELOP_S_CAST(i, <=, guint32);
2181 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2182 BRELOP_S_CAST(l, <=, guint64);
2184 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2185 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2187 MINT_IN_CASE(MINT_BLE_UN_I4)
2188 BRELOP_CAST(i, <=, guint32);
2190 MINT_IN_CASE(MINT_BLE_UN_I8)
2191 BRELOP_CAST(l, <=, guint64);
2193 MINT_IN_CASE(MINT_BLE_UN_R8)
2194 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2196 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2197 BRELOP_S_CAST(i, <, guint32);
2199 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2200 BRELOP_S_CAST(l, <, guint64);
2202 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2203 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2205 MINT_IN_CASE(MINT_BLT_UN_I4)
2206 BRELOP_CAST(i, <, guint32);
2208 MINT_IN_CASE(MINT_BLT_UN_I8)
2209 BRELOP_CAST(l, <, guint64);
2211 MINT_IN_CASE(MINT_BLT_UN_R8)
2212 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2214 MINT_IN_CASE(MINT_SWITCH) {
2216 const unsigned short *st;
2222 if ((guint32)sp->data.i < n) {
2224 ip += 2 * (guint32)sp->data.i;
2225 offset = READ32 (ip);
2232 MINT_IN_CASE(MINT_LDIND_I1)
2234 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2236 MINT_IN_CASE(MINT_LDIND_U1)
2238 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2240 MINT_IN_CASE(MINT_LDIND_I2)
2242 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2244 MINT_IN_CASE(MINT_LDIND_U2)
2246 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2248 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2249 MINT_IN_CASE(MINT_LDIND_U4)
2251 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2253 MINT_IN_CASE(MINT_LDIND_I8)
2255 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2257 MINT_IN_CASE(MINT_LDIND_I)
2259 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2261 MINT_IN_CASE(MINT_LDIND_R4)
2263 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2265 MINT_IN_CASE(MINT_LDIND_R8)
2267 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2269 MINT_IN_CASE(MINT_LDIND_REF)
2271 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2273 MINT_IN_CASE(MINT_STIND_REF)
2276 * (gpointer *) sp->data.p = sp[1].data.p;
2278 MINT_IN_CASE(MINT_STIND_I1)
2281 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2283 MINT_IN_CASE(MINT_STIND_I2)
2286 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2288 MINT_IN_CASE(MINT_STIND_I4)
2291 * (gint32 *) sp->data.p = sp[1].data.i;
2293 MINT_IN_CASE(MINT_STIND_I)
2296 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2298 MINT_IN_CASE(MINT_STIND_I8)
2301 * (gint64 *) sp->data.p = sp[1].data.l;
2303 MINT_IN_CASE(MINT_STIND_R4)
2306 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2308 MINT_IN_CASE(MINT_STIND_R8)
2311 * (double *) sp->data.p = sp[1].data.f;
2313 #define BINOP(datamem, op) \
2315 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2317 MINT_IN_CASE(MINT_ADD_I4)
2320 MINT_IN_CASE(MINT_ADD_I8)
2323 MINT_IN_CASE(MINT_ADD_R8)
2326 MINT_IN_CASE(MINT_ADD1_I4)
2330 MINT_IN_CASE(MINT_SUB_I4)
2333 MINT_IN_CASE(MINT_SUB_I8)
2336 MINT_IN_CASE(MINT_SUB_R8)
2339 MINT_IN_CASE(MINT_SUB1_I4)
2343 MINT_IN_CASE(MINT_MUL_I4)
2346 MINT_IN_CASE(MINT_MUL_I8)
2349 MINT_IN_CASE(MINT_MUL_R8)
2352 MINT_IN_CASE(MINT_DIV_I4)
2353 if (sp [-1].data.i == 0)
2354 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2357 MINT_IN_CASE(MINT_DIV_I8)
2358 if (sp [-1].data.l == 0)
2359 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2362 MINT_IN_CASE(MINT_DIV_R8)
2366 #define BINOP_CAST(datamem, op, type) \
2368 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2370 MINT_IN_CASE(MINT_DIV_UN_I4)
2371 if (sp [-1].data.i == 0)
2372 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2373 BINOP_CAST(i, /, guint32);
2375 MINT_IN_CASE(MINT_DIV_UN_I8)
2376 if (sp [-1].data.l == 0)
2377 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2378 BINOP_CAST(l, /, guint64);
2380 MINT_IN_CASE(MINT_REM_I4)
2381 if (sp [-1].data.i == 0)
2382 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2385 MINT_IN_CASE(MINT_REM_I8)
2386 if (sp [-1].data.l == 0)
2387 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2390 MINT_IN_CASE(MINT_REM_R8)
2391 /* FIXME: what do we actually do here? */
2393 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2396 MINT_IN_CASE(MINT_REM_UN_I4)
2397 if (sp [-1].data.i == 0)
2398 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2399 BINOP_CAST(i, %, guint32);
2401 MINT_IN_CASE(MINT_REM_UN_I8)
2402 if (sp [-1].data.l == 0)
2403 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2404 BINOP_CAST(l, %, guint64);
2406 MINT_IN_CASE(MINT_AND_I4)
2409 MINT_IN_CASE(MINT_AND_I8)
2412 MINT_IN_CASE(MINT_OR_I4)
2415 MINT_IN_CASE(MINT_OR_I8)
2418 MINT_IN_CASE(MINT_XOR_I4)
2421 MINT_IN_CASE(MINT_XOR_I8)
2425 #define SHIFTOP(datamem, op) \
2427 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2430 MINT_IN_CASE(MINT_SHL_I4)
2433 MINT_IN_CASE(MINT_SHL_I8)
2436 MINT_IN_CASE(MINT_SHR_I4)
2439 MINT_IN_CASE(MINT_SHR_I8)
2442 MINT_IN_CASE(MINT_SHR_UN_I4)
2444 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2447 MINT_IN_CASE(MINT_SHR_UN_I8)
2449 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2452 MINT_IN_CASE(MINT_NEG_I4)
2453 sp [-1].data.i = - sp [-1].data.i;
2456 MINT_IN_CASE(MINT_NEG_I8)
2457 sp [-1].data.l = - sp [-1].data.l;
2460 MINT_IN_CASE(MINT_NEG_R8)
2461 sp [-1].data.f = - sp [-1].data.f;
2464 MINT_IN_CASE(MINT_NOT_I4)
2465 sp [-1].data.i = ~ sp [-1].data.i;
2468 MINT_IN_CASE(MINT_NOT_I8)
2469 sp [-1].data.l = ~ sp [-1].data.l;
2472 MINT_IN_CASE(MINT_CONV_I1_I4)
2473 sp [-1].data.i = (gint8)sp [-1].data.i;
2476 MINT_IN_CASE(MINT_CONV_I1_I8)
2477 sp [-1].data.i = (gint8)sp [-1].data.l;
2480 MINT_IN_CASE(MINT_CONV_I1_R8)
2481 sp [-1].data.i = (gint8)sp [-1].data.f;
2484 MINT_IN_CASE(MINT_CONV_U1_I4)
2485 sp [-1].data.i = (guint8)sp [-1].data.i;
2488 MINT_IN_CASE(MINT_CONV_U1_I8)
2489 sp [-1].data.i = (guint8)sp [-1].data.l;
2492 MINT_IN_CASE(MINT_CONV_U1_R8)
2493 sp [-1].data.i = (guint8)sp [-1].data.f;
2496 MINT_IN_CASE(MINT_CONV_I2_I4)
2497 sp [-1].data.i = (gint16)sp [-1].data.i;
2500 MINT_IN_CASE(MINT_CONV_I2_I8)
2501 sp [-1].data.i = (gint16)sp [-1].data.l;
2504 MINT_IN_CASE(MINT_CONV_I2_R8)
2505 sp [-1].data.i = (gint16)sp [-1].data.f;
2508 MINT_IN_CASE(MINT_CONV_U2_I4)
2509 sp [-1].data.i = (guint16)sp [-1].data.i;
2512 MINT_IN_CASE(MINT_CONV_U2_I8)
2513 sp [-1].data.i = (guint16)sp [-1].data.l;
2516 MINT_IN_CASE(MINT_CONV_U2_R8)
2517 sp [-1].data.i = (guint16)sp [-1].data.f;
2520 MINT_IN_CASE(MINT_CONV_I4_R8)
2521 sp [-1].data.i = (gint32)sp [-1].data.f;
2524 MINT_IN_CASE(MINT_CONV_U4_I8)
2525 MINT_IN_CASE(MINT_CONV_I4_I8)
2526 sp [-1].data.i = (gint32)sp [-1].data.l;
2529 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2530 sp [-2].data.i = (gint32)sp [-2].data.l;
2533 MINT_IN_CASE(MINT_CONV_U4_R8)
2534 sp [-1].data.i = (guint32)sp [-1].data.f;
2537 MINT_IN_CASE(MINT_CONV_I8_I4)
2538 sp [-1].data.l = sp [-1].data.i;
2541 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2542 sp [-2].data.l = sp [-2].data.i;
2545 MINT_IN_CASE(MINT_CONV_I8_U4)
2546 sp [-1].data.l = (guint32)sp [-1].data.i;
2549 MINT_IN_CASE(MINT_CONV_I8_R8)
2550 sp [-1].data.l = (gint64)sp [-1].data.f;
2553 MINT_IN_CASE(MINT_CONV_R4_I4)
2554 sp [-1].data.f = (float)sp [-1].data.i;
2557 MINT_IN_CASE(MINT_CONV_R4_I8)
2558 sp [-1].data.f = (float)sp [-1].data.l;
2561 MINT_IN_CASE(MINT_CONV_R4_R8)
2562 sp [-1].data.f = (float)sp [-1].data.f;
2565 MINT_IN_CASE(MINT_CONV_R8_I4)
2566 sp [-1].data.f = (double)sp [-1].data.i;
2569 MINT_IN_CASE(MINT_CONV_R8_I8)
2570 sp [-1].data.f = (double)sp [-1].data.l;
2573 MINT_IN_CASE(MINT_CONV_U8_I4)
2574 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2577 MINT_IN_CASE(MINT_CONV_U8_R8)
2578 sp [-1].data.l = (guint64)sp [-1].data.f;
2582 MINT_IN_CASE(MINT_CPOBJ) {
2585 vtklass = rtm->data_items[READ32 (ip)];
2588 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2592 MINT_IN_CASE(MINT_LDOBJ) {
2595 c = rtm->data_items[* (guint16 *)(ip + 1)];
2597 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2599 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2601 size = mono_class_value_size (c, NULL);
2603 sp [-1].data.p = vt_sp;
2604 memcpy(vt_sp, p, size);
2605 vt_sp += (size + 7) & ~7;
2609 MINT_IN_CASE(MINT_LDSTR)
2610 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2614 MINT_IN_CASE(MINT_NEWOBJ) {
2615 MonoClass *newobj_class;
2616 MonoMethodSignature *csig;
2617 stackval valuetype_this;
2623 token = * (guint16 *)(ip + 1);
2626 child_frame.runtime_method = rtm->data_items [token];
2627 csig = mono_method_signature (child_frame.runtime_method->method);
2628 newobj_class = child_frame.runtime_method->method->klass;
2629 /*if (profiling_classes) {
2630 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2632 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2636 if (newobj_class->parent == mono_defaults.array_class) {
2637 sp -= csig->param_count;
2638 o = ves_array_create (context->domain, newobj_class, csig, sp);
2639 goto array_constructed;
2643 * First arg is the object.
2645 if (newobj_class->valuetype) {
2646 if (!newobj_class->enumtype && (newobj_class->byval_arg.type == MONO_TYPE_VALUETYPE)) {
2647 child_frame.obj = vt_sp;
2648 valuetype_this.data.p = vt_sp;
2650 memset (&valuetype_this, 0, sizeof (stackval));
2651 child_frame.obj = &valuetype_this;
2654 if (newobj_class != mono_defaults.string_class) {
2655 context->managed_code = 0;
2656 o = mono_object_new_checked (context->domain, newobj_class, &error);
2657 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2658 context->managed_code = 1;
2659 if (*abort_requested)
2660 mono_thread_interruption_checkpoint ();
2661 child_frame.obj = o;
2663 child_frame.retval = &retval;
2667 if (csig->param_count) {
2668 sp -= csig->param_count;
2669 child_frame.stack_args = sp;
2671 child_frame.stack_args = NULL;
2674 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2676 child_frame.ip = NULL;
2677 child_frame.ex = NULL;
2679 ves_exec_method_with_context (&child_frame, context);
2681 context->current_frame = frame;
2683 if (child_frame.ex) {
2685 * An exception occurred, need to run finally, fault and catch handlers..
2687 frame->ex = child_frame.ex;
2688 goto handle_finally;
2691 * a constructor returns void, but we need to return the object we created
2694 if (newobj_class->valuetype && !newobj_class->enumtype) {
2695 *sp = valuetype_this;
2696 } else if (newobj_class == mono_defaults.string_class) {
2704 MINT_IN_CASE(MINT_CASTCLASS)
2705 c = rtm->data_items [*(guint16 *)(ip + 1)];
2706 if ((o = sp [-1].data.p)) {
2707 if (c->marshalbyref) {
2708 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2709 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2711 THROW_EX (mono_get_exception_invalid_cast (), ip);
2713 MonoVTable *vt = o->vtable;
2714 MonoClass *oklass = vt->klass;
2715 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2716 g_error ("FIXME: interface method lookup");
2717 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2718 THROW_EX (mono_get_exception_invalid_cast (), ip);
2720 } else if (c->rank) {
2721 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2722 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2724 THROW_EX (mono_get_exception_invalid_cast (), ip);
2725 } else if (!mono_class_has_parent (oklass, c)) {
2726 THROW_EX (mono_get_exception_invalid_cast (), ip);
2732 MINT_IN_CASE(MINT_ISINST)
2733 c = rtm->data_items [*(guint16 *)(ip + 1)];
2734 if ((o = sp [-1].data.p)) {
2735 if (c->marshalbyref) {
2736 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2737 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2739 sp [-1].data.p = NULL;
2741 MonoVTable *vt = o->vtable;
2742 MonoClass *oklass = vt->klass;
2743 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2744 g_error ("FIXME: interface method lookup");
2745 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2746 sp [-1].data.p = NULL;
2748 } else if (c->rank) {
2749 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2750 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2752 sp [-1].data.p = NULL;
2753 } else if (!mono_class_has_parent (oklass, c)) {
2754 sp [-1].data.p = NULL;
2760 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2761 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2764 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2765 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2768 MINT_IN_CASE(MINT_UNBOX)
2769 c = rtm->data_items[*(guint16 *)(ip + 1)];
2773 THROW_EX (mono_get_exception_null_reference(), ip);
2775 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2776 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2778 ((o->vtable->klass->rank == 0) &&
2779 (o->vtable->klass->element_class == c->element_class))))
2780 THROW_EX (mono_get_exception_invalid_cast (), ip);
2782 sp [-1].data.p = (char *)o + sizeof (MonoObject);
2785 MINT_IN_CASE(MINT_THROW)
2787 frame->ex_handler = NULL;
2789 sp->data.p = mono_get_exception_null_reference ();
2790 THROW_EX ((MonoException *)sp->data.p, ip);
2792 MINT_IN_CASE(MINT_LDFLDA)
2795 THROW_EX (mono_get_exception_null_reference (), ip);
2796 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2799 MINT_IN_CASE(MINT_CKNULL)
2802 THROW_EX (mono_get_exception_null_reference (), ip);
2806 #define LDFLD(datamem, fieldtype) \
2807 o = sp [-1].data.p; \
2809 THROW_EX (mono_get_exception_null_reference (), ip); \
2810 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2813 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2814 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2815 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2816 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2817 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2818 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2819 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2820 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2821 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2822 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2824 MINT_IN_CASE(MINT_LDFLD_VT)
2827 THROW_EX (mono_get_exception_null_reference (), ip);
2828 i32 = READ32(ip + 2);
2829 sp [-1].data.p = vt_sp;
2830 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2831 vt_sp += (i32 + 7) & ~7;
2835 MINT_IN_CASE(MINT_LDRMFLD) {
2837 MonoClassField *field;
2842 THROW_EX (mono_get_exception_null_reference (), ip);
2843 field = rtm->data_items[* (guint16 *)(ip + 1)];
2845 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
2846 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2848 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2849 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2851 addr = (char*)o + field->offset;
2854 stackval_from_data (field->type, &sp [-1], addr, FALSE);
2858 MINT_IN_CASE(MINT_LDRMFLD_VT) {
2859 MonoClassField *field;
2865 THROW_EX (mono_get_exception_null_reference (), ip);
2866 field = rtm->data_items[* (guint16 *)(ip + 1)];
2867 i32 = READ32(ip + 2);
2869 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
2870 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2871 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
2872 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2874 addr = (char*)o + field->offset;
2877 sp [-1].data.p = vt_sp;
2878 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2879 vt_sp += (i32 + 7) & ~7;
2880 memcpy(sp [-1].data.p, addr, i32);
2884 #define STFLD(datamem, fieldtype) \
2885 o = sp [-2].data.p; \
2887 THROW_EX (mono_get_exception_null_reference (), ip); \
2889 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
2892 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
2893 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
2894 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
2895 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
2896 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
2897 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
2898 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
2899 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
2900 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
2901 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
2903 MINT_IN_CASE(MINT_STFLD_VT)
2906 THROW_EX (mono_get_exception_null_reference (), ip);
2907 i32 = READ32(ip + 2);
2909 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
2910 vt_sp -= (i32 + 7) & ~7;
2914 MINT_IN_CASE(MINT_STRMFLD) {
2915 MonoClassField *field;
2919 THROW_EX (mono_get_exception_null_reference (), ip);
2921 field = rtm->data_items[* (guint16 *)(ip + 1)];
2924 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
2925 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2926 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
2927 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2929 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
2934 MINT_IN_CASE(MINT_STRMFLD_VT) {
2935 MonoClassField *field;
2939 THROW_EX (mono_get_exception_null_reference (), ip);
2940 field = rtm->data_items[* (guint16 *)(ip + 1)];
2941 i32 = READ32(ip + 2);
2944 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
2945 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
2946 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
2947 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2949 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
2952 vt_sp -= (i32 + 7) & ~7;
2955 MINT_IN_CASE(MINT_LDSFLDA) {
2956 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
2957 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
2960 if (!vt->initialized) {
2962 mono_runtime_class_init_full (vt, &error);
2963 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2967 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
2968 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
2970 sp->data.p = (char*)(vt->vtable) + field->offset;
2974 MINT_IN_CASE(MINT_LDSFLD) {
2976 MonoClassField *field;
2979 field = rtm->data_items[*(guint16 *)(ip + 1)];
2980 vt = rtm->data_items [*(guint16 *)(ip + 2)];
2981 if (!vt->initialized) {
2983 mono_runtime_class_init_full (vt, &error);
2984 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2987 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
2988 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
2990 addr = (char*)(vt->vtable) + field->offset;
2992 stackval_from_data (field->type, sp, addr, FALSE);
2996 MINT_IN_CASE(MINT_LDSFLD_I4) {
2997 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
2998 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
2999 if (!vt->initialized) {
3001 mono_runtime_class_init_full (vt, &error);
3002 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3005 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3009 MINT_IN_CASE(MINT_LDSFLD_O) {
3010 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3011 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3012 if (!vt->initialized) {
3014 mono_runtime_class_init_full (vt, &error);
3015 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3018 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3022 MINT_IN_CASE(MINT_LDSFLD_VT) {
3024 MonoClassField *field;
3029 token = * (guint16 *)(ip + 1);
3030 size = READ32(ip + 2);
3031 field = rtm->data_items[token];
3034 vt = mono_class_vtable (context->domain, field->parent);
3035 if (!vt->initialized) {
3037 mono_runtime_class_init_full (vt, &error);
3038 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3041 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3042 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3044 addr = (char*)(vt->vtable) + field->offset;
3047 vt_sp += (size + 7) & ~7;
3048 stackval_from_data (field->type, sp, addr, FALSE);
3052 MINT_IN_CASE(MINT_STSFLD) {
3054 MonoClassField *field;
3058 token = * (guint16 *)(ip + 1);
3059 field = rtm->data_items[token];
3063 vt = mono_class_vtable (context->domain, field->parent);
3064 if (!vt->initialized) {
3066 mono_runtime_class_init_full (vt, &error);
3067 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3070 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3071 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3073 addr = (char*)(vt->vtable) + field->offset;
3075 stackval_to_data (field->type, sp, addr, FALSE);
3078 MINT_IN_CASE(MINT_STSFLD_VT) {
3080 MonoClassField *field;
3085 token = * (guint16 *)(ip + 1);
3086 size = READ32(ip + 2);
3087 field = rtm->data_items[token];
3090 vt = mono_class_vtable (context->domain, field->parent);
3091 if (!vt->initialized) {
3093 mono_runtime_class_init_full (vt, &error);
3094 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3097 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3098 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3100 addr = (char*)(vt->vtable) + field->offset;
3102 stackval_to_data (field->type, sp, addr, FALSE);
3103 vt_sp -= (size + 7) & ~7;
3106 MINT_IN_CASE(MINT_STOBJ_VT) {
3108 c = rtm->data_items[* (guint16 *)(ip + 1)];
3110 size = mono_class_value_size (c, NULL);
3111 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3112 vt_sp -= (size + 7) & ~7;
3116 MINT_IN_CASE(MINT_STOBJ) {
3118 c = rtm->data_items[* (guint16 *)(ip + 1)];
3120 size = mono_class_value_size (c, NULL);
3121 memcpy(sp [-2].data.p, &sp [-1].data, size);
3125 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3126 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3127 THROW_EX (mono_get_exception_overflow (), ip);
3128 sp [-1].data.i = (guint32)sp [-1].data.f;
3131 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3132 if (sp [-1].data.i < 0)
3133 THROW_EX (mono_get_exception_overflow (), ip);
3134 sp [-1].data.l = sp [-1].data.i;
3137 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3138 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3139 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3140 THROW_EX (mono_get_exception_overflow (), ip);
3141 sp [-1].data.l = (guint64)sp [-1].data.f;
3144 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3145 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3146 THROW_EX (mono_get_exception_overflow (), ip);
3147 sp [-1].data.l = (gint64)sp [-1].data.f;
3150 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3151 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3152 THROW_EX (mono_get_exception_overflow (), ip);
3153 sp [-1].data.i = (mono_u)sp [-1].data.l;
3156 MINT_IN_CASE(MINT_BOX)
3157 c = rtm->data_items [* (guint16 *)(ip + 1)];
3159 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3160 int size = mono_class_value_size (c, NULL);
3161 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3162 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3163 size = (size + 7) & ~7;
3167 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3168 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3169 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3173 MINT_IN_CASE(MINT_NEWARR)
3174 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3175 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3177 /*if (profiling_classes) {
3178 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3180 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3184 MINT_IN_CASE(MINT_LDLEN)
3187 THROW_EX (mono_get_exception_null_reference (), ip);
3188 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3191 MINT_IN_CASE(MINT_GETCHR) {
3195 THROW_EX (mono_get_exception_null_reference (), ip);
3196 i32 = sp [-1].data.i;
3197 if (i32 < 0 || i32 >= mono_string_length (s))
3198 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3200 sp [-1].data.i = mono_string_chars(s)[i32];
3204 MINT_IN_CASE(MINT_STRLEN)
3206 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3208 MINT_IN_CASE(MINT_ARRAY_RANK)
3211 THROW_EX (mono_get_exception_null_reference (), ip);
3212 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3215 MINT_IN_CASE(MINT_LDELEMA) {
3219 /*token = READ32 (ip)*/;
3225 aindex = sp [1].data.i;
3226 if (aindex >= mono_array_length ((MonoArray *) o))
3227 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3229 /* check the array element corresponds to token */
3230 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3232 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3236 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3237 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3238 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3239 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3240 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3241 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3242 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3243 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3244 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3245 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3246 MINT_IN_CASE(MINT_LDELEM_REF) {
3254 THROW_EX (mono_get_exception_null_reference (), ip);
3256 aindex = sp [1].data.i;
3257 if (aindex >= mono_array_length (o))
3258 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3261 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3264 case MINT_LDELEM_I1:
3265 sp [0].data.i = mono_array_get (o, gint8, aindex);
3267 case MINT_LDELEM_U1:
3268 sp [0].data.i = mono_array_get (o, guint8, aindex);
3270 case MINT_LDELEM_I2:
3271 sp [0].data.i = mono_array_get (o, gint16, aindex);
3273 case MINT_LDELEM_U2:
3274 sp [0].data.i = mono_array_get (o, guint16, aindex);
3277 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3279 case MINT_LDELEM_I4:
3280 sp [0].data.i = mono_array_get (o, gint32, aindex);
3282 case MINT_LDELEM_U4:
3283 sp [0].data.i = mono_array_get (o, guint32, aindex);
3285 case MINT_LDELEM_I8:
3286 sp [0].data.l = mono_array_get (o, guint64, aindex);
3288 case MINT_LDELEM_R4:
3289 sp [0].data.f = mono_array_get (o, float, aindex);
3291 case MINT_LDELEM_R8:
3292 sp [0].data.f = mono_array_get (o, double, aindex);
3294 case MINT_LDELEM_REF:
3295 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3305 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3306 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3307 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3308 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3309 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3310 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3311 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3312 MINT_IN_CASE(MINT_STELEM_REF) {
3319 THROW_EX (mono_get_exception_null_reference (), ip);
3321 aindex = sp [1].data.i;
3322 if (aindex >= mono_array_length ((MonoArray *)o))
3323 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3327 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3329 case MINT_STELEM_I1:
3330 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3332 case MINT_STELEM_I2:
3333 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3335 case MINT_STELEM_I4:
3336 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3338 case MINT_STELEM_I8:
3339 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3341 case MINT_STELEM_R4:
3342 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3344 case MINT_STELEM_R8:
3345 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3347 case MINT_STELEM_REF: {
3348 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3349 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3350 if (sp [2].data.p && !isinst_obj)
3351 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3352 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3361 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3362 if (sp [-1].data.i < 0)
3363 THROW_EX (mono_get_exception_overflow (), ip);
3366 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3367 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3368 THROW_EX (mono_get_exception_overflow (), ip);
3369 sp [-1].data.i = (gint32) sp [-1].data.l;
3372 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3373 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3374 THROW_EX (mono_get_exception_overflow (), ip);
3375 sp [-1].data.i = (gint32) sp [-1].data.f;
3378 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3379 if (sp [-1].data.i < 0)
3380 THROW_EX (mono_get_exception_overflow (), ip);
3383 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3384 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3385 THROW_EX (mono_get_exception_overflow (), ip);
3386 sp [-1].data.i = (guint32) sp [-1].data.l;
3389 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3390 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3391 THROW_EX (mono_get_exception_overflow (), ip);
3392 sp [-1].data.i = (guint32) sp [-1].data.f;
3395 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3396 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3397 THROW_EX (mono_get_exception_overflow (), ip);
3400 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3401 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3402 THROW_EX (mono_get_exception_overflow (), ip);
3403 sp [-1].data.i = (gint16) sp [-1].data.l;
3406 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3407 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3408 THROW_EX (mono_get_exception_overflow (), ip);
3409 sp [-1].data.i = (gint16) sp [-1].data.f;
3412 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3413 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3414 THROW_EX (mono_get_exception_overflow (), ip);
3417 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3418 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3419 THROW_EX (mono_get_exception_overflow (), ip);
3420 sp [-1].data.i = (guint16) sp [-1].data.l;
3423 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3424 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3425 THROW_EX (mono_get_exception_overflow (), ip);
3426 sp [-1].data.i = (guint16) sp [-1].data.f;
3429 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3430 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3431 THROW_EX (mono_get_exception_overflow (), ip);
3434 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3435 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3436 THROW_EX (mono_get_exception_overflow (), ip);
3437 sp [-1].data.i = (gint8) sp [-1].data.l;
3440 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3441 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3442 THROW_EX (mono_get_exception_overflow (), ip);
3443 sp [-1].data.i = (gint8) sp [-1].data.f;
3446 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3447 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3448 THROW_EX (mono_get_exception_overflow (), ip);
3451 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3452 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3453 THROW_EX (mono_get_exception_overflow (), ip);
3454 sp [-1].data.i = (guint8) sp [-1].data.l;
3457 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3458 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3459 THROW_EX (mono_get_exception_overflow (), ip);
3460 sp [-1].data.i = (guint8) sp [-1].data.f;
3464 MINT_IN_CASE(MINT_LDELEM)
3465 MINT_IN_CASE(MINT_STELEM)
3466 MINT_IN_CASE(MINT_UNBOX_ANY)
3468 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3470 MINT_IN_CASE(MINT_CKFINITE)
3471 if (!isfinite(sp [-1].data.f))
3472 THROW_EX (mono_get_exception_arithmetic (), ip);
3476 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3478 MINT_IN_CASE(MINT_LDTOKEN)
3481 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3485 MINT_IN_CASE(MINT_ADD_OVF_I4)
3486 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3487 THROW_EX (mono_get_exception_overflow (), ip);
3490 MINT_IN_CASE(MINT_ADD_OVF_I8)
3491 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3492 THROW_EX (mono_get_exception_overflow (), ip);
3495 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3496 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3497 THROW_EX (mono_get_exception_overflow (), ip);
3498 BINOP_CAST(i, +, guint32);
3500 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3501 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3502 THROW_EX (mono_get_exception_overflow (), ip);
3503 BINOP_CAST(l, +, guint64);
3505 MINT_IN_CASE(MINT_MUL_OVF_I4)
3506 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3507 THROW_EX (mono_get_exception_overflow (), ip);
3510 MINT_IN_CASE(MINT_MUL_OVF_I8)
3511 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3512 THROW_EX (mono_get_exception_overflow (), ip);
3515 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3516 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3517 THROW_EX (mono_get_exception_overflow (), ip);
3518 BINOP_CAST(i, *, guint32);
3520 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3521 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3522 THROW_EX (mono_get_exception_overflow (), ip);
3523 BINOP_CAST(l, *, guint64);
3525 MINT_IN_CASE(MINT_SUB_OVF_I4)
3526 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3527 THROW_EX (mono_get_exception_overflow (), ip);
3530 MINT_IN_CASE(MINT_SUB_OVF_I8)
3531 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3532 THROW_EX (mono_get_exception_overflow (), ip);
3535 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3536 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3537 THROW_EX (mono_get_exception_overflow (), ip);
3538 BINOP_CAST(i, -, guint32);
3540 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3541 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3542 THROW_EX (mono_get_exception_overflow (), ip);
3543 BINOP_CAST(l, -, guint64);
3545 MINT_IN_CASE(MINT_ENDFINALLY)
3547 ip = finally_ips->data;
3548 finally_ips = g_slist_remove (finally_ips, ip);
3555 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3556 MINT_IN_CASE(MINT_LEAVE_S)
3557 while (sp > frame->stack) {
3561 if (*ip == MINT_LEAVE_S) {
3562 ip += (short) *(ip + 1);
3564 ip += (gint32) READ32 (ip + 1);
3567 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3568 frame->ex_handler = NULL;
3571 goto handle_finally;
3573 MINT_IN_CASE(MINT_ICALL_V_V)
3574 MINT_IN_CASE(MINT_ICALL_P_V)
3575 MINT_IN_CASE(MINT_ICALL_P_P)
3576 MINT_IN_CASE(MINT_ICALL_PP_V)
3577 MINT_IN_CASE(MINT_ICALL_PI_V)
3578 MINT_IN_CASE(MINT_ICALL_PP_P)
3579 MINT_IN_CASE(MINT_ICALL_PI_P)
3580 MINT_IN_CASE(MINT_ICALL_PPP_V)
3581 MINT_IN_CASE(MINT_ICALL_PPI_V)
3582 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3583 if (frame->ex != NULL)
3584 goto handle_exception;
3587 MINT_IN_CASE(MINT_MONO_LDPTR)
3588 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3592 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3593 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3594 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3598 MINT_IN_CASE(MINT_MONO_FREE)
3601 g_free (sp->data.p);
3603 MINT_IN_CASE(MINT_MONO_RETOBJ)
3606 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3607 mono_method_signature (frame->runtime_method->method)->pinvoke);
3608 if (sp > frame->stack)
3609 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3612 #define RELOP(datamem, op) \
3614 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3616 MINT_IN_CASE(MINT_CEQ_I4)
3619 MINT_IN_CASE(MINT_CEQ0_I4)
3620 sp [-1].data.i = (sp [-1].data.i == 0);
3623 MINT_IN_CASE(MINT_CEQ_I8)
3626 MINT_IN_CASE(MINT_CEQ_R8)
3628 if (isunordered (sp [-1].data.f, sp [0].data.f))
3631 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3634 MINT_IN_CASE(MINT_CGT_I4)
3637 MINT_IN_CASE(MINT_CGT_I8)
3640 MINT_IN_CASE(MINT_CGT_R8)
3642 if (isunordered (sp [-1].data.f, sp [0].data.f))
3645 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3649 #define RELOP_CAST(datamem, op, type) \
3651 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3654 MINT_IN_CASE(MINT_CGT_UN_I4)
3655 RELOP_CAST(i, >, guint32);
3657 MINT_IN_CASE(MINT_CGT_UN_I8)
3658 RELOP_CAST(l, >, guint64);
3660 MINT_IN_CASE(MINT_CGT_UN_R8)
3662 if (isunordered (sp [-1].data.f, sp [0].data.f))
3665 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3668 MINT_IN_CASE(MINT_CLT_I4)
3671 MINT_IN_CASE(MINT_CLT_I8)
3674 MINT_IN_CASE(MINT_CLT_R8)
3676 if (isunordered (sp [-1].data.f, sp [0].data.f))
3679 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3682 MINT_IN_CASE(MINT_CLT_UN_I4)
3683 RELOP_CAST(i, <, guint32);
3685 MINT_IN_CASE(MINT_CLT_UN_I8)
3686 RELOP_CAST(l, <, guint64);
3688 MINT_IN_CASE(MINT_CLT_UN_R8)
3690 if (isunordered (sp [-1].data.f, sp [0].data.f))
3693 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3696 MINT_IN_CASE(MINT_LDFTN) {
3697 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3702 MINT_IN_CASE(MINT_LDVIRTFTN) {
3703 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3707 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3709 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3714 MINT_IN_CASE(MINT_LDTHIS)
3715 sp->data.p = frame->obj;
3719 MINT_IN_CASE(MINT_STTHIS)
3721 frame->obj = sp->data.p;
3724 MINT_IN_CASE(MINT_LDTHISA)
3725 sp->data.p = &frame->obj;
3730 #define LDARG(datamem, argtype) \
3731 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3735 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3736 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3737 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3738 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3739 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3740 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3741 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3742 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3743 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3744 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3746 MINT_IN_CASE(MINT_LDARG_VT)
3748 i32 = READ32(ip + 2);
3749 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3750 vt_sp += (i32 + 7) & ~7;
3755 #define STARG(datamem, argtype) \
3757 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3760 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3761 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3762 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3763 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3764 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3765 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3766 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3767 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3768 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3769 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3771 MINT_IN_CASE(MINT_STARG_VT)
3772 i32 = READ32(ip + 2);
3774 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3775 vt_sp -= (i32 + 7) & ~7;
3779 #define STINARG(datamem, argtype) \
3781 int n = * (guint16 *)(ip + 1); \
3782 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3786 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3787 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3788 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3789 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3790 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3791 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3792 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3793 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3794 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3795 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3797 MINT_IN_CASE(MINT_STINARG_VT) {
3798 int n = * (guint16 *)(ip + 1);
3799 i32 = READ32(ip + 2);
3800 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3805 MINT_IN_CASE(MINT_LDARGA)
3806 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3811 #define LDLOC(datamem, argtype) \
3812 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3816 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3817 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3818 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3819 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3820 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3821 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3822 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3823 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3824 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3825 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3827 MINT_IN_CASE(MINT_LDLOC_VT)
3829 i32 = READ32(ip + 2);
3830 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3831 vt_sp += (i32 + 7) & ~7;
3836 MINT_IN_CASE(MINT_LDLOCA_S)
3837 sp->data.p = locals + * (guint16 *)(ip + 1);
3842 #define STLOC(datamem, argtype) \
3844 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3847 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
3848 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
3849 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
3850 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
3851 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
3852 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
3853 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
3854 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
3855 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
3856 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
3858 #define STLOC_NP(datamem, argtype) \
3859 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
3862 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
3863 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
3865 MINT_IN_CASE(MINT_STLOC_VT)
3866 i32 = READ32(ip + 2);
3868 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
3869 vt_sp -= (i32 + 7) & ~7;
3873 MINT_IN_CASE(MINT_LOCALLOC)
3874 if (sp != frame->stack + 1) /*FIX?*/
3875 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
3876 sp [-1].data.p = alloca (sp [-1].data.i);
3880 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
3882 MINT_IN_CASE(MINT_INITOBJ)
3884 memset (sp->data.vt, 0, READ32(ip + 1));
3887 MINT_IN_CASE(MINT_CPBLK)
3889 if (!sp [0].data.p || !sp [1].data.p)
3890 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3892 /* FIXME: value and size may be int64... */
3893 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
3896 MINT_IN_CASE(MINT_CONSTRAINED_) {
3898 /* FIXME: implement */
3900 token = READ32 (ip);
3905 MINT_IN_CASE(MINT_INITBLK)
3908 THROW_EX (mono_get_exception_null_reference(), ip - 1);
3910 /* FIXME: value and size may be int64... */
3911 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
3914 MINT_IN_CASE(MINT_NO_)
3915 /* FIXME: implement */
3919 MINT_IN_CASE(MINT_RETHROW)
3921 * need to clarify what this should actually do:
3922 * start the search from the last found handler in
3923 * this method or continue in the caller or what.
3924 * Also, do we need to run finally/fault handlers after a retrow?
3925 * Well, this implementation will follow the usual search
3926 * for an handler, considering the current ip as throw spot.
3927 * We need to NULL frame->ex_handler for the later code to
3928 * actually run the new found handler.
3930 frame->ex_handler = NULL;
3931 THROW_EX (frame->ex, ip - 1);
3934 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
3935 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
3939 g_assert_not_reached ();
3941 * Exception handling code.
3942 * The exception object is stored in frame->ex.
3949 MonoInvocation *inv;
3950 MonoExceptionClause *clause;
3956 g_print ("* Handling exception '%s' at IL_%04x\n",
3957 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
3958 rtm == NULL ? 0 : frame->ip - rtm->code);
3960 if (die_on_exception)
3963 for (inv = frame; inv; inv = inv->parent) {
3965 if (inv->runtime_method == NULL)
3967 method = inv->runtime_method->method;
3968 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
3970 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
3972 if (inv->ip == NULL)
3974 ip_offset = inv->ip - inv->runtime_method->code;
3975 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
3976 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
3977 clause = &inv->runtime_method->clauses [i];
3978 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
3979 if (!clause->flags) {
3980 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
3981 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3984 * OK, we found an handler, now we need to execute the finally
3985 * and fault blocks before branching to the handler code.
3987 inv->ex_handler = clause;
3990 g_print ("* Found handler at '%s'\n", method->name);
3992 goto handle_finally;
3995 /* FIXME: handle filter clauses */
4002 * If we get here, no handler was found: print a stack trace.
4004 for (inv = frame; inv; inv = inv->parent) {
4005 if (inv->invoke_trap)
4006 goto handle_finally;
4009 ex_obj = (MonoObject*)frame->ex;
4010 mono_unhandled_exception (ex_obj);
4017 MonoExceptionClause *clause;
4018 GSList *old_list = finally_ips;
4019 MonoMethod *method = frame->runtime_method->method;
4020 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4021 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4025 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4027 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4028 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4031 ip_offset = frame->ip - rtm->code;
4033 if (endfinally_ip != NULL)
4034 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4035 for (i = 0; i < header->num_clauses; ++i)
4036 if (frame->ex_handler == &rtm->clauses [i])
4040 clause = &rtm->clauses [i];
4041 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4042 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4043 ip = rtm->code + clause->handler_offset;
4044 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4047 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4053 endfinally_ip = NULL;
4055 if (old_list != finally_ips && finally_ips) {
4056 ip = finally_ips->data;
4057 finally_ips = g_slist_remove (finally_ips, ip);
4058 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4063 * If an exception is set, we need to execute the fault handler, too,
4064 * otherwise, we continue normally.
4074 MonoExceptionClause *clause;
4075 MonoMethod *method = frame->runtime_method->method;
4076 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4077 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4081 g_print ("* Handle fault\n");
4083 ip_offset = frame->ip - rtm->code;
4084 for (i = 0; i < header->num_clauses; ++i) {
4085 clause = &rtm->clauses [i];
4086 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4087 ip = rtm->code + clause->handler_offset;
4090 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4096 * If the handler for the exception was found in this method, we jump
4097 * to it right away, otherwise we return and let the caller run
4098 * the finally, fault and catch blocks.
4099 * This same code should be present in the endfault opcode, but it
4100 * is corrently not assigned in the ECMA specs: LAMESPEC.
4102 if (frame->ex_handler) {
4105 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4107 ip = rtm->code + frame->ex_handler->handler_offset;
4109 vt_sp = (unsigned char *) sp + rtm->stack_size;
4110 sp->data.p = frame->ex;
4121 ves_exec_method (MonoInvocation *frame)
4123 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4124 ThreadContext context_struct;
4131 mono_unhandled_exception ((MonoObject*)frame->ex);
4134 if (context == NULL) {
4135 context = &context_struct;
4136 context_struct.domain = mono_domain_get ();
4137 context_struct.base_frame = frame;
4138 context_struct.current_frame = NULL;
4139 context_struct.env_frame = frame;
4140 context_struct.current_env = &env;
4141 context_struct.search_for_handler = 0;
4142 context_struct.managed_code = 0;
4143 mono_native_tls_set_value (thread_context_id, context);
4146 frame->parent = context->current_frame;
4147 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4148 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4149 context->managed_code = 1;
4150 ves_exec_method_with_context(frame, context);
4151 context->managed_code = 0;
4153 if (context != &context_struct && context->current_env) {
4154 context->env_frame->ex = frame->ex;
4155 longjmp (*context->current_env, 1);
4158 mono_unhandled_exception ((MonoObject*)frame->ex);
4160 if (context->base_frame == frame)
4161 mono_native_tls_set_value (thread_context_id, NULL);
4163 context->current_frame = frame->parent;
4167 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4169 MonoImage *image = mono_assembly_get_image (assembly);
4174 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4175 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4178 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4180 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4181 return_val_and_set_pending_if_nok (&error, rval);
4188 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4189 "Usage is: mint [options] executable args...\n\n", VERSION);
4191 "Runtime Debugging:\n"
4196 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4199 " --traceclassinit\n"
4202 " --debug method_name\n"
4208 " --config filename load the specified config file instead of the default\n"
4209 " --workers n maximum number of worker threads\n"
4216 test_load_class (MonoImage* image)
4218 MonoTableInfo *t = &image->tables [MONO_TABLE_TYPEDEF];
4222 for (i = 1; i <= t->rows; ++i) {
4223 klass = mono_class_get (image, MONO_TOKEN_TYPE_DEF | i);
4224 mono_class_init (klass);
4230 add_signal_handler (int signo, void (*handler)(int))
4233 signal (signo, handler);
4235 struct sigaction sa;
4237 sa.sa_handler = handler;
4238 sigemptyset (&sa.sa_mask);
4241 g_assert (sigaction (signo, &sa, NULL) != -1);
4246 segv_handler (int signum)
4248 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4249 MonoException *segv_exception;
4251 if (context == NULL)
4253 segv_exception = mono_get_exception_null_reference ();
4254 segv_exception->message = mono_string_new (mono_domain_get (), "Null Reference (SIGSEGV)");
4255 mono_raise_exception (segv_exception);
4260 quit_handler (int signum)
4262 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4263 MonoException *quit_exception;
4265 if (context == NULL)
4267 quit_exception = mono_get_exception_execution_engine ("Interrupted (SIGQUIT).");
4268 mono_raise_exception (quit_exception);
4272 abrt_handler (int signum)
4274 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4275 MonoException *abrt_exception;
4277 if (context == NULL)
4279 abrt_exception = mono_get_exception_execution_engine ("Abort (SIGABRT).");
4280 mono_raise_exception (abrt_exception);
4285 thread_abort_handler (int signum)
4287 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4290 if (context == NULL)
4293 exc = mono_thread_request_interruption (context->managed_code);
4294 if (exc) mono_raise_exception (exc);
4299 ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4300 MonoReflectionMethod **method,
4301 gint32 *iloffset, gint32 *native_offset,
4302 MonoString **file, gint32 *line, gint32 *column)
4304 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4305 MonoInvocation *inv = context->current_frame;
4309 for (i = 0; inv && i < skip; inv = inv->parent)
4310 if (inv->runtime_method != NULL)
4321 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4322 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4327 if (need_file_info) {
4331 *file = mono_string_new (mono_domain_get (), "unknown");
4338 ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4340 MonoDomain *domain = mono_domain_get ();
4342 MonoArray *ta = exc->trace_ips;
4347 /* Exception is not thrown yet */
4348 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4349 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4353 len = mono_array_length (ta);
4355 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4356 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4358 for (i = skip; i < len / 2; i++) {
4359 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4360 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4361 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4362 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4365 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4366 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4367 sf->native_offset = ip - rtm->code;
4371 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4373 if (need_file_info) {
4376 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4378 sf->filename = filename? mono_string_new (domain, filename): NULL;
4385 mono_array_set (res, gpointer, i, sf);
4392 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4394 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4395 MonoObject *delegate;
4398 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4400 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4401 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4403 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4404 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4413 int enable_debugging;
4419 static void main_thread_handler (gpointer user_data)
4421 MainThreadArgs *main_args=(MainThreadArgs *)user_data;
4422 MonoAssembly *assembly;
4424 if (main_args->enable_debugging) {
4425 mono_debug_init (MONO_DEBUG_FORMAT_MONO);
4428 assembly = mono_domain_assembly_open (main_args->domain, main_args->file);
4431 fprintf (stderr, "Can not open image %s\n", main_args->file);
4436 test_load_class (assembly->image);
4439 ves_exec (main_args->domain, assembly, main_args->argc, main_args->argv);
4444 mono_runtime_install_handlers (void)
4446 add_signal_handler (SIGSEGV, segv_handler);
4447 add_signal_handler (SIGINT, quit_handler);
4448 add_signal_handler (SIGABRT, abrt_handler);
4450 add_signal_handler (mono_thread_get_abort_signal (), thread_abort_handler);
4455 quit_function (MonoDomain *domain, gpointer user_data)
4457 mono_profiler_shutdown ();
4459 mono_runtime_cleanup (domain);
4460 mono_domain_free (domain, TRUE);
4465 mono_interp_cleanup(MonoDomain *domain)
4467 quit_function (domain, NULL);
4471 mono_interp_exec(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4473 return ves_exec (domain, assembly, argc, argv);
4477 interp_get_imt_trampoline (MonoVTable *vtable, int imt_slot_index)
4479 // FIXME: implement me
4484 mono_interp_init(const char *file)
4487 MonoRuntimeCallbacks callbacks;
4488 MonoRuntimeExceptionHandlingCallbacks ecallbacks;
4491 g_set_prgname (file);
4492 mono_set_rootdir ();
4494 g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
4495 g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
4497 mono_native_tls_alloc (&thread_context_id, NULL);
4498 mono_native_tls_set_value (thread_context_id, NULL);
4499 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4500 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4502 // TODO: use callbacks?
4503 mono_runtime_install_handlers ();
4504 mono_interp_transform_init ();
4506 memset (&callbacks, 0, sizeof (callbacks));
4507 // TODO: replace with `mono_install_callbacks`
4508 callbacks.compile_method = mono_create_method_pointer;
4509 callbacks.runtime_invoke = interp_mono_runtime_invoke;
4510 callbacks.get_imt_trampoline = interp_get_imt_trampoline;
4511 #ifndef DISABLE_REMOTING
4512 mono_install_remoting_trampoline (interp_create_remoting_trampoline);
4514 callbacks.create_jit_trampoline = interp_create_trampoline;
4515 mono_install_callbacks (&callbacks);
4518 memset (&ecallbacks, 0, sizeof (ecallbacks));
4519 ecallbacks.mono_raise_exception = interp_ex_handler;
4522 mono_install_stack_walk (interp_walk_stack);
4524 mono_install_eh_callbacks (&ecallbacks);
4526 mono_install_runtime_cleanup (quit_function);
4528 abort_requested = mono_thread_interruption_request_flag ();
4530 domain = mono_init_from_assembly (file, file);
4531 #ifdef __hpux /* generates very big stack frames */
4532 mono_threads_set_default_stacksize(32*1024*1024);
4535 mono_add_internal_call ("System.Diagnostics.StackFrame::get_frame_info", ves_icall_get_frame_info);
4536 mono_add_internal_call ("System.Diagnostics.StackTrace::get_trace", ves_icall_get_trace);
4537 mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers", mono_runtime_install_handlers);
4538 mono_add_internal_call ("System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal);
4540 mono_register_jit_icall (mono_thread_interruption_checkpoint, "mono_thread_interruption_checkpoint", mono_create_icall_signature ("void"), FALSE);
4542 mono_runtime_init_checked (domain, NULL, NULL, &error);
4543 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4545 mono_thread_attach (domain);
4546 fprintf (stderr, "INTERPRETER: INIT DONE\n");
4551 mono_main (int argc, char *argv [])
4555 char *file, *config_file = NULL;
4556 int enable_debugging = FALSE;
4557 MainThreadArgs main_args;
4560 setlocale (LC_ALL, "");
4564 for (i = 1; i < argc && argv [i][0] == '-'; i++){
4565 if (strcmp (argv [i], "--trace") == 0)
4567 if (strcmp (argv [i], "--noptr") == 0)
4568 global_no_pointers = 1;
4569 if (strcmp (argv [i], "--traceops") == 0)
4571 if (strcmp (argv [i], "--traceopt") == 0)
4572 ++mono_interp_traceopt;
4573 if (strcmp (argv [i], "--dieonex") == 0) {
4574 die_on_exception = 1;
4575 enable_debugging = 1;
4577 if (strcmp (argv [i], "--print-vtable") == 0)
4578 mono_print_vtable = TRUE;
4579 if (strcmp (argv [i], "--profile") == 0)
4580 mono_profiler_load (NULL);
4581 if (strcmp (argv [i], "--config") == 0)
4582 config_file = argv [++i];
4583 if (strcmp (argv [i], "--help") == 0)
4586 if (strcmp (argv [i], "--debug") == 0) {
4587 MonoMethodDesc *desc = mono_method_desc_new (argv [++i], FALSE);
4589 g_error ("Invalid method name '%s'", argv [i]);
4590 db_methods = g_list_append (db_methods, desc);
4592 if (strcmp (argv [i], "--nested") == 0)
4602 domain = mono_interp_init (file);
4603 mono_config_parse (config_file);
4605 error = mono_check_corlib_version ();
4607 fprintf (stderr, "Corlib not in sync with this runtime: %s\n", error);
4608 fprintf (stderr, "Download a newer corlib at http://www.go-mono.com/daily.\n");
4612 main_args.domain=domain;
4613 main_args.file=file;
4614 main_args.argc=argc-i;
4615 main_args.argv=argv+i;
4616 main_args.enable_debugging=enable_debugging;
4618 fprintf (stderr, "INTERPRETER: INIT DONE\n");
4619 mono_runtime_exec_managed_code (domain, main_thread_handler,
4622 quit_function (domain, NULL);
4624 /* Get the return value from System.Environment.ExitCode */
4625 retval=mono_environment_exitcode_get ();
4628 for (i = 0; i < 512; i++)
4629 if (opcode_counts[i] != 0)
4630 printf("%s %d\n", mono_interp_opname[i], opcode_counts[i]);