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 // TODO: should come from mono/mini/mini.h
77 * Information about a trampoline function.
82 * The native code of the trampoline. Not owned by this structure.
87 * The name of the trampoline which can be used in AOT/xdebug. Owned by this
92 * Patches required by the trampoline when aot-ing. Owned by this structure.
96 * Unwind information. Owned by this structure.
101 * Encoded unwind info loaded from AOT images
106 gpointer mono_arch_get_enter_icall_trampoline (MonoTrampInfo **info);
107 void mono_tramp_info_register (MonoTrampInfo *info, MonoDomain *domain);
109 #include <mono/mini/mini.h>
113 /* Mingw 2.1 doesnt need this any more, but leave it in for now for older versions */
116 #define finite _finite
120 #define finite isfinite
124 static gint *abort_requested;
126 /* If true, then we output the opcodes as we interpret them */
127 static int global_tracing = 1;
128 static int global_no_pointers = 0;
130 int mono_interp_traceopt = 0;
132 static int debug_indent_level = 0;
134 #define INIT_FRAME(frame,parent_frame,obj_this,method_args,method_retval,domain,mono_method,error) \
136 (frame)->parent = (parent_frame); \
137 (frame)->obj = (obj_this); \
138 (frame)->stack_args = (method_args); \
139 (frame)->retval = (method_retval); \
140 (frame)->runtime_method = mono_interp_get_runtime_method ((domain), (mono_method), (error)); \
141 (frame)->ex = NULL; \
142 (frame)->ip = NULL; \
143 (frame)->invoke_trap = 0; \
146 void ves_exec_method (MonoInvocation *frame);
148 static char* dump_stack (stackval *stack, stackval *sp);
149 static char* dump_frame (MonoInvocation *inv);
150 static MonoArray *get_trace_ips (MonoDomain *domain, MonoInvocation *top);
151 static void ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context);
153 typedef void (*ICallMethod) (MonoInvocation *frame);
155 static guint32 die_on_exception = 0;
156 static MonoNativeTlsKey thread_context_id;
158 static char* dump_args (MonoInvocation *inv);
160 #define DEBUG_INTERP 0
164 static int break_on_method = 0;
165 static int nested_trace = 0;
166 static GList *db_methods = NULL;
173 for (h = 0; h < debug_indent_level; h++)
178 db_match_method (gpointer data, gpointer user_data)
180 MonoMethod *m = (MonoMethod*)user_data;
181 MonoMethodDesc *desc = data;
183 if (mono_method_desc_full_match (desc, m))
187 static void debug_enter (MonoInvocation *frame, int *tracing)
190 g_list_foreach (db_methods, db_match_method, (gpointer)frame->runtime_method->method);
192 *tracing = nested_trace ? (global_tracing = 2, 3) : 2;
196 MonoMethod *method = frame->runtime_method->method;
197 char *mn, *args = dump_args (frame);
198 debug_indent_level++;
200 mn = mono_method_full_name (method, FALSE);
201 g_printerr ("(0x%08x) Entering %s (", mono_thread_internal_current (), mn);
203 g_printerr ("%s)\n", args);
206 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE)
207 mono_profiler_method_enter (frame->runtime_method->method);
211 #define DEBUG_LEAVE() \
214 args = dump_retval (frame); \
216 mn = mono_method_full_name (frame->runtime_method->method, FALSE); \
217 g_printerr ("(0x%08x) Leaving %s", mono_thread_internal_current (), mn); \
219 g_printerr (" => %s\n", args); \
221 debug_indent_level--; \
222 if (tracing == 3) global_tracing = 0; \
224 if (mono_profiler_events & MONO_PROFILE_ENTER_LEAVE) \
225 mono_profiler_method_leave (frame->runtime_method->method);
229 static void debug_enter (MonoInvocation *frame, int *tracing)
232 #define DEBUG_LEAVE()
237 interp_ex_handler (MonoException *ex) {
239 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
243 stack_trace = dump_frame (context->current_frame);
244 ex->stack_trace = mono_string_new (mono_domain_get(), stack_trace);
245 g_free (stack_trace);
246 if (context->current_env == NULL || strcmp(ex->object.vtable->klass->name, "ExecutionEngineException") == 0) {
247 char *strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
248 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
249 fprintf(stderr, "Nothing can catch this exception: ");
250 fprintf(stderr, "%s", ex->object.vtable->klass->name);
251 if (ex->message != NULL) {
252 char *m = mono_string_to_utf8_checked (ex->message, &error);
253 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
254 fprintf(stderr, ": %s", m);
257 fprintf(stderr, "\n%s\n", strace);
259 if (ex->inner_ex != NULL) {
260 ex = (MonoException *)ex->inner_ex;
261 fprintf(stderr, "Inner exception: %s", ex->object.vtable->klass->name);
262 if (ex->message != NULL) {
263 char *m = mono_string_to_utf8_checked (ex->message, &error);
264 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
265 fprintf(stderr, ": %s", m);
268 strace = mono_string_to_utf8_checked (ex->stack_trace, &error);
269 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
270 fprintf(stderr, "\n");
271 fprintf(stderr, "%s\n", strace);
274 /* wait for other threads to also collapse */
275 // Sleep(1000); // TODO: proper sleep
278 context->env_frame->ex = ex;
279 context->search_for_handler = 1;
280 longjmp (*context->current_env, 1);
284 ves_real_abort (int line, MonoMethod *mh,
285 const unsigned short *ip, stackval *stack, stackval *sp)
288 fprintf (stderr, "Execution aborted in method: %s::%s\n", mh->klass->name, mh->name);
289 fprintf (stderr, "Line=%d IP=0x%04lx, Aborted execution\n", line,
290 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code);
291 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
292 g_print ("0x%04x %02x\n",
293 ip-(const unsigned short *)mono_method_get_header_checked (mh, &error)->code, *ip);
294 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
296 printf ("\t[%ld] 0x%08x %0.5f\n", sp-stack, sp[-1].data.i, sp[-1].data.f);
299 #define ves_abort() \
301 ves_real_abort(__LINE__, frame->runtime_method->method, ip, frame->stack, sp); \
302 THROW_EX (mono_get_exception_execution_engine (NULL), ip); \
306 interp_create_remoting_trampoline (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target, MonoError *error)
308 g_error ("FIXME: use domain and error");
309 // return mono_interp_get_runtime_method (mono_marshal_get_remoting_invoke_for_target (method, target));
312 static mono_mutex_t runtime_method_lookup_section;
315 mono_interp_get_runtime_method (MonoDomain *domain, MonoMethod *method, MonoError *error)
318 mono_error_init (error);
320 mono_os_mutex_lock (&runtime_method_lookup_section);
321 if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
322 mono_os_mutex_unlock (&runtime_method_lookup_section);
325 rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
326 memset (rtm, 0, sizeof (*rtm));
327 rtm->method = method;
328 rtm->param_count = mono_method_signature (method)->param_count;
329 rtm->hasthis = mono_method_signature (method)->hasthis;
330 rtm->valuetype = method->klass->valuetype;
331 mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
332 mono_os_mutex_unlock (&runtime_method_lookup_section);
338 interp_create_trampoline (MonoDomain *domain, MonoMethod *method, MonoError *error)
340 if (method->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
341 method = mono_marshal_get_synchronized_wrapper (method);
342 return mono_interp_get_runtime_method (domain, method, error);
345 static inline RuntimeMethod*
346 get_virtual_method (MonoDomain *domain, RuntimeMethod *runtime_method, MonoObject *obj)
348 MonoMethod *m = runtime_method->method;
351 if ((m->flags & METHOD_ATTRIBUTE_FINAL) || !(m->flags & METHOD_ATTRIBUTE_VIRTUAL)) {
352 RuntimeMethod *ret = NULL;
353 if (obj->vtable->klass == mono_defaults.transparent_proxy_class)
354 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_remoting_invoke (m), &error);
355 else if (m->iflags & METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED)
356 ret = mono_interp_get_runtime_method (domain, mono_marshal_get_synchronized_wrapper (m), &error);
358 ret = runtime_method;
359 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
363 if (m->klass->flags & TYPE_ATTRIBUTE_INTERFACE) {
364 // return ((RuntimeMethod **)obj->vtable->interface_offsets [m->klass->interface_id]) [m->slot];
365 g_error ("FIXME: interface method lookup");
368 int slot = mono_method_get_vtable_slot (m);
369 MonoMethod *virtual_method = obj->vtable->klass->vtable [slot]; // TODO: there's a helper function for that?
370 RuntimeMethod *virtual_runtime_method = mono_interp_get_runtime_method (domain, virtual_method, &error);
371 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
372 return virtual_runtime_method;
377 stackval_from_data (MonoType *type, stackval *result, char *data, gboolean pinvoke)
380 switch (type->type) {
381 case MONO_TYPE_OBJECT:
382 case MONO_TYPE_CLASS:
383 case MONO_TYPE_STRING:
384 case MONO_TYPE_ARRAY:
385 case MONO_TYPE_SZARRAY:
390 result->data.p = *(gpointer*)data;
393 switch (type->type) {
397 result->data.i = *(gint8*)data;
400 case MONO_TYPE_BOOLEAN:
401 result->data.i = *(guint8*)data;
404 result->data.i = *(gint16*)data;
408 result->data.i = *(guint16*)data;
411 result->data.i = *(gint32*)data;
415 result->data.nati = *(mono_i*)data;
418 result->data.p = *(gpointer*)data;
421 result->data.i = *(guint32*)data;
424 result->data.f = *(float*)data;
428 result->data.l = *(gint64*)data;
431 result->data.f = *(double*)data;
433 case MONO_TYPE_STRING:
434 case MONO_TYPE_SZARRAY:
435 case MONO_TYPE_CLASS:
436 case MONO_TYPE_OBJECT:
437 case MONO_TYPE_ARRAY:
438 result->data.p = *(gpointer*)data;
440 case MONO_TYPE_VALUETYPE:
441 if (type->data.klass->enumtype) {
442 stackval_from_data (mono_class_enum_basetype (type->data.klass), result, data, pinvoke);
448 size = mono_class_native_size (type->data.klass, NULL);
450 size = mono_class_value_size (type->data.klass, NULL);
451 memcpy (result->data.vt, data, size);
455 g_warning ("got type 0x%02x", type->type);
456 g_assert_not_reached ();
461 stackval_to_data (MonoType *type, stackval *val, char *data, gboolean pinvoke)
464 gpointer *p = (gpointer*)data;
468 /* printf ("TODAT0 %p\n", data); */
469 switch (type->type) {
472 guint8 *p = (guint8*)data;
476 case MONO_TYPE_BOOLEAN: {
477 guint8 *p = (guint8*)data;
478 *p = (val->data.i != 0);
483 case MONO_TYPE_CHAR: {
484 guint16 *p = (guint16*)data;
489 mono_i *p = (mono_i*)data;
490 /* In theory the value used by stloc should match the local var type
491 but in practice it sometimes doesn't (a int32 gets dup'd and stloc'd into
492 a native int - both by csc and mcs). Not sure what to do about sign extension
493 as it is outside the spec... doing the obvious */
494 *p = (mono_i)val->data.nati;
498 mono_u *p = (mono_u*)data;
500 *p = (mono_u)val->data.nati;
505 gint32 *p = (gint32*)data;
511 gint64 *p = (gint64*)data;
516 float *p = (float*)data;
521 double *p = (double*)data;
525 case MONO_TYPE_STRING:
526 case MONO_TYPE_SZARRAY:
527 case MONO_TYPE_CLASS:
528 case MONO_TYPE_OBJECT:
529 case MONO_TYPE_ARRAY:
530 case MONO_TYPE_PTR: {
531 gpointer *p = (gpointer*)data;
535 case MONO_TYPE_VALUETYPE:
536 if (type->data.klass->enumtype) {
537 stackval_to_data (mono_class_enum_basetype (type->data.klass), val, data, pinvoke);
543 size = mono_class_native_size (type->data.klass, NULL);
545 size = mono_class_value_size (type->data.klass, NULL);
547 memcpy (data, val->data.p, size);
551 g_warning ("got type %x", type->type);
552 g_assert_not_reached ();
557 fill_in_trace (MonoException *exception, MonoInvocation *frame)
559 char *stack_trace = dump_frame (frame);
560 MonoDomain *domain = mono_domain_get();
561 (exception)->stack_trace = mono_string_new (domain, stack_trace);
562 (exception)->trace_ips = get_trace_ips (domain, frame);
563 g_free (stack_trace);
566 #define FILL_IN_TRACE(exception, frame) fill_in_trace(exception, frame)
568 #define THROW_EX(exception,ex_ip) \
570 frame->ip = (ex_ip); \
571 frame->ex = (MonoException*)(exception); \
572 FILL_IN_TRACE(frame->ex, frame); \
573 goto handle_exception; \
577 ves_array_create (MonoDomain *domain, MonoClass *klass, MonoMethodSignature *sig, stackval *values)
580 intptr_t *lower_bounds;
585 lengths = alloca (sizeof (uintptr_t) * klass->rank * 2);
586 for (i = 0; i < sig->param_count; ++i) {
587 lengths [i] = values->data.i;
590 if (klass->rank == sig->param_count) {
591 /* Only lengths provided. */
594 /* lower bounds are first. */
595 lower_bounds = (intptr_t *) lengths;
596 lengths += klass->rank;
598 obj = (MonoObject*) mono_array_new_full_checked (domain, klass, lengths, lower_bounds, &error);
599 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
604 ves_array_set (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);
630 pos = pos*ao->bounds [i].length + sp [i].data.i -
631 ao->bounds [i].lower_bound;
633 } else if (pos >= ao->max_length) {
634 frame->ex = mono_get_exception_index_out_of_range ();
635 FILL_IN_TRACE(frame->ex, frame);
640 if (sp [ac->rank].data.p && !mono_object_isinst (sp [ac->rank].data.p, mono_object_class (o)->element_class)) {
641 frame->ex = mono_get_exception_array_type_mismatch ();
642 FILL_IN_TRACE (frame->ex, frame);
647 esize = mono_array_element_size (ac);
648 ea = mono_array_addr_with_size (ao, esize, pos);
650 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
651 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
655 ves_array_get (MonoInvocation *frame)
657 stackval *sp = frame->stack_args;
661 gint32 i, t, pos, esize;
667 ac = o->vtable->klass;
669 g_assert (ac->rank >= 1);
672 if (ao->bounds != NULL) {
673 pos -= ao->bounds [0].lower_bound;
674 for (i = 1; i < ac->rank; i++) {
675 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
676 ao->bounds [i].length) {
677 frame->ex = mono_get_exception_index_out_of_range ();
678 FILL_IN_TRACE(frame->ex, frame);
682 pos = pos*ao->bounds [i].length + sp [i].data.i -
683 ao->bounds [i].lower_bound;
685 } else if (pos >= ao->max_length) {
686 frame->ex = mono_get_exception_index_out_of_range ();
687 FILL_IN_TRACE(frame->ex, frame);
691 esize = mono_array_element_size (ac);
692 ea = mono_array_addr_with_size (ao, esize, pos);
694 mt = mono_method_signature (frame->runtime_method->method)->ret;
695 stackval_from_data (mt, frame->retval, ea, FALSE);
699 ves_array_element_address (MonoInvocation *frame)
701 stackval *sp = frame->stack_args;
705 gint32 i, t, pos, esize;
710 ac = o->vtable->klass;
712 g_assert (ac->rank >= 1);
715 if (ao->bounds != NULL) {
716 pos -= ao->bounds [0].lower_bound;
717 for (i = 1; i < ac->rank; i++) {
718 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
719 ao->bounds [i].length) {
720 frame->ex = mono_get_exception_index_out_of_range ();
721 FILL_IN_TRACE(frame->ex, frame);
724 pos = pos*ao->bounds [i].length + sp [i].data.i -
725 ao->bounds [i].lower_bound;
727 } else if (pos >= ao->max_length) {
728 frame->ex = mono_get_exception_index_out_of_range ();
729 FILL_IN_TRACE(frame->ex, frame);
733 esize = mono_array_element_size (ac);
734 ea = mono_array_addr_with_size (ao, esize, pos);
736 frame->retval->data.p = ea;
740 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
742 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
743 MonoInvocation *frame;
745 MonoMethodHeader *hd;
748 if (!context) return;
750 frame = context->current_frame;
753 gboolean managed = FALSE;
754 MonoMethod *method = frame->runtime_method->method;
755 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
758 hd = mono_method_get_header_checked (method, &error);
759 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
760 il_offset = frame->ip - (const unsigned short *)hd->code;
761 if (!method->wrapper_type)
764 if (func (method, -1, il_offset, managed, user_data))
766 frame = frame->parent;
770 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
772 struct _MethodArguments {
780 typedef struct _MethodArguments MethodArguments;
782 // TODO: this function is also arch dependent (register width).
783 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
785 // TODO: don't malloc this data structure.
786 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
791 for (int i = 0; i < sig->param_count; i++) {
792 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
794 case MONO_TYPE_BOOLEAN:
805 case MONO_TYPE_SZARRAY:
806 case MONO_TYPE_CLASS:
807 case MONO_TYPE_OBJECT:
808 case MONO_TYPE_STRING:
813 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
818 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
821 g_error ("build_args_from_sig: TODO, allocate floats\n");
827 margs->iargs [0] = frame->obj;
831 for (int i = 0; i < sig->param_count; i++) {
832 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
834 case MONO_TYPE_BOOLEAN:
845 case MONO_TYPE_SZARRAY:
846 case MONO_TYPE_CLASS:
847 case MONO_TYPE_OBJECT:
848 case MONO_TYPE_STRING:
850 margs->iargs [int_i] = frame->stack_args [i].data.l;
851 g_printerr ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
855 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
863 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
867 MonoInvocation *old_frame = context->current_frame;
868 MonoInvocation *old_env_frame = context->env_frame;
869 jmp_buf *old_env = context->current_env;
872 context->current_frame = old_frame;
873 context->env_frame = old_env_frame;
874 context->current_env = old_env;
875 context->managed_code = 1;
880 context->env_frame = frame;
881 context->current_env = &env;
883 g_assert (frame->runtime_method);
884 func = frame->runtime_method->func;
886 g_printerr ("ICALL(1): func = NULL, addr = %p\n", addr);
887 if (!mono_interp_enter_icall_trampoline) {
889 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
890 // mono_tramp_info_register (info, NULL);
892 func = mono_interp_enter_icall_trampoline;
893 g_printerr ("ICALL(2): func = %p, addr = %p\n", func, addr);
896 MethodArguments *margs = build_args_from_sig (sig, frame);
898 context->current_frame = frame;
899 context->managed_code = 0;
904 context->managed_code = 1;
905 /* domain can only be changed by native code */
906 context->domain = mono_domain_get ();
908 if (*abort_requested)
909 mono_thread_interruption_checkpoint ();
911 if (!MONO_TYPE_ISSTRUCT (sig->ret))
912 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
914 context->current_frame = old_frame;
915 context->env_frame = old_env_frame;
916 context->current_env = old_env;
918 g_free (margs->iargs);
919 g_free (margs->fargs);
924 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
926 MonoDelegate *delegate = (MonoDelegate *)this;
929 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
930 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
931 delegate->target = target;
933 if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
934 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
935 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
936 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
938 delegate->method_ptr = runtime_method;
943 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
947 MonoDomain *domain = mono_domain_get ();
950 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
951 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
953 ji = mono_jit_info_table_find (domain, ftn);
955 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
957 /* FIXME: discard the wrapper and call the original method */
958 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
959 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
966 * runtime specifies that the implementation of the method is automatically
967 * provided by the runtime and is primarily used for the methods of delegates.
970 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
972 MonoMethod *method = frame->runtime_method->method;
973 const char *name = method->name;
974 MonoObject *obj = (MonoObject*)frame->obj;
975 MonoObject *isinst_obj;
978 mono_class_init (method->klass);
980 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
981 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
982 if (obj && isinst_obj) {
983 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
984 interp_delegate_ctor (context->domain, obj, frame->stack_args[0].data.p, frame->stack_args[1].data.p);
989 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
990 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
991 if (obj && isinst_obj) {
992 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
993 ves_array_set (frame);
996 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
997 ves_array_get (frame);
1000 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
1001 ves_array_element_address (frame);
1006 g_error ("Don't know how to exec runtime method %s.%s::%s",
1007 method->klass->name_space, method->klass->name,
1012 dump_stack (stackval *stack, stackval *sp)
1014 stackval *s = stack;
1015 GString *str = g_string_new ("");
1018 return g_string_free (str, FALSE);
1021 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
1024 return g_string_free (str, FALSE);
1028 dump_stackval (GString *str, stackval *s, MonoType *type)
1030 switch (type->type) {
1037 case MONO_TYPE_CHAR:
1038 case MONO_TYPE_BOOLEAN:
1039 g_string_append_printf (str, "[%d] ", s->data.i);
1041 case MONO_TYPE_STRING:
1042 case MONO_TYPE_SZARRAY:
1043 case MONO_TYPE_CLASS:
1044 case MONO_TYPE_OBJECT:
1045 case MONO_TYPE_ARRAY:
1049 g_string_append_printf (str, "[%p] ", s->data.p);
1051 case MONO_TYPE_VALUETYPE:
1052 if (type->data.klass->enumtype)
1053 g_string_append_printf (str, "[%d] ", s->data.i);
1055 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1059 g_string_append_printf (str, "[%g] ", s->data.f);
1064 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
1070 dump_args (MonoInvocation *inv)
1072 GString *str = g_string_new ("");
1074 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1076 if (signature->param_count == 0)
1077 return g_string_free (str, FALSE);
1079 if (signature->hasthis)
1080 g_string_append_printf (str, "%p ", inv->obj);
1082 for (i = 0; i < signature->param_count; ++i)
1083 dump_stackval (str, inv->stack_args + i, signature->params [i]);
1085 return g_string_free (str, FALSE);
1089 dump_retval (MonoInvocation *inv)
1091 GString *str = g_string_new ("");
1092 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1094 if (ret->type != MONO_TYPE_VOID)
1095 dump_stackval (str, inv->retval, ret);
1097 return g_string_free (str, FALSE);
1101 dump_frame (MonoInvocation *inv)
1103 GString *str = g_string_new ("");
1108 for (i = 0; inv; inv = inv->parent) {
1109 if (inv->runtime_method != NULL) {
1110 MonoMethod *method = inv->runtime_method->method;
1114 const char * opname = "";
1116 gchar *source = NULL;
1120 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1121 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1122 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1123 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1127 opname = mono_interp_opname [*inv->ip];
1128 codep = inv->ip - inv->runtime_method->code;
1129 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1134 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1135 source = mono_debug_method_lookup_location (minfo, codep);
1139 args = dump_args (inv);
1140 name = mono_method_full_name (method, TRUE);
1142 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1144 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1151 return g_string_free (str, FALSE);
1155 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1159 MonoInvocation *inv;
1162 for (i = 0, inv = top; inv; inv = inv->parent)
1163 if (inv->runtime_method != NULL)
1166 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1167 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1169 for (i = 0, inv = top; inv; inv = inv->parent)
1170 if (inv->runtime_method != NULL) {
1171 mono_array_set (res, gpointer, i, inv->runtime_method);
1173 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1181 #define MYGUINT64_MAX 18446744073709551615ULL
1182 #define MYGINT64_MAX 9223372036854775807LL
1183 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1185 #define MYGUINT32_MAX 4294967295U
1186 #define MYGINT32_MAX 2147483647
1187 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1189 #define CHECK_ADD_OVERFLOW(a,b) \
1190 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1191 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1193 #define CHECK_SUB_OVERFLOW(a,b) \
1194 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1195 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1197 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1198 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1200 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1201 (guint32)(a) < (guint32)(b) ? -1 : 0
1203 #define CHECK_ADD_OVERFLOW64(a,b) \
1204 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1205 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1207 #define CHECK_SUB_OVERFLOW64(a,b) \
1208 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1209 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1211 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1212 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1214 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1215 (guint64)(a) < (guint64)(b) ? -1 : 0
1217 #if SIZEOF_VOID_P == 4
1218 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1219 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1221 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1222 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1225 /* Resolves to TRUE if the operands would overflow */
1226 #define CHECK_MUL_OVERFLOW(a,b) \
1227 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1228 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1229 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1230 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1231 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1232 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1233 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1235 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1236 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1237 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1239 #define CHECK_MUL_OVERFLOW64(a,b) \
1240 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1241 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1242 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1243 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1244 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1245 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1246 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1248 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1249 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1250 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1252 #if SIZEOF_VOID_P == 4
1253 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1254 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1256 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1257 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1261 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1263 MonoInvocation frame;
1264 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1265 MonoObject *retval = NULL;
1266 MonoMethodSignature *sig = mono_method_signature (method);
1267 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1268 int i, type, isobject = 0;
1271 stackval *args = alloca (sizeof (stackval) * sig->param_count);
1272 ThreadContext context_struct;
1273 MonoInvocation *old_frame = NULL;
1276 mono_error_init (error);
1281 if (context != &context_struct) {
1282 context->domain = mono_domain_get ();
1283 context->current_frame = old_frame;
1284 context->managed_code = 0;
1286 mono_native_tls_set_value (thread_context_id, NULL);
1288 *exc = (MonoObject *)frame.ex;
1292 if (context == NULL) {
1293 context = &context_struct;
1294 context_struct.base_frame = &frame;
1295 context_struct.current_frame = NULL;
1296 context_struct.env_frame = &frame;
1297 context_struct.current_env = &env;
1298 context_struct.search_for_handler = 0;
1299 context_struct.managed_code = 0;
1300 mono_native_tls_set_value (thread_context_id, context);
1303 old_frame = context->current_frame;
1305 context->domain = mono_domain_get ();
1307 switch (sig->ret->type) {
1308 case MONO_TYPE_VOID:
1310 case MONO_TYPE_STRING:
1311 case MONO_TYPE_OBJECT:
1312 case MONO_TYPE_CLASS:
1313 case MONO_TYPE_ARRAY:
1314 case MONO_TYPE_SZARRAY:
1317 case MONO_TYPE_VALUETYPE:
1318 retval = mono_object_new_checked (context->domain, klass, error);
1319 ret = ((char*)retval) + sizeof (MonoObject);
1320 if (!sig->ret->data.klass->enumtype)
1321 result.data.vt = ret;
1324 retval = mono_object_new_checked (context->domain, klass, error);
1325 ret = ((char*)retval) + sizeof (MonoObject);
1329 for (i = 0; i < sig->param_count; ++i) {
1330 if (sig->params [i]->byref) {
1331 args [i].data.p = params [i];
1334 type = sig->params [i]->type;
1339 case MONO_TYPE_BOOLEAN:
1340 args [i].data.i = *(MonoBoolean*)params [i];
1344 case MONO_TYPE_CHAR:
1345 args [i].data.i = *(gint16*)params [i];
1347 #if SIZEOF_VOID_P == 4
1348 case MONO_TYPE_U: /* use VAL_POINTER? */
1353 args [i].data.i = *(gint32*)params [i];
1355 #if SIZEOF_VOID_P == 8
1361 args [i].data.l = *(gint64*)params [i];
1363 case MONO_TYPE_VALUETYPE:
1364 if (sig->params [i]->data.klass->enumtype) {
1365 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1368 args [i].data.p = params [i];
1371 case MONO_TYPE_STRING:
1372 case MONO_TYPE_CLASS:
1373 case MONO_TYPE_ARRAY:
1374 case MONO_TYPE_SZARRAY:
1375 case MONO_TYPE_OBJECT:
1376 args [i].data.p = params [i];
1379 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1383 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1384 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1385 INIT_FRAME(&frame,context->current_frame,obj,args,&result,mono_get_root_domain (),method,error);
1387 frame.invoke_trap = 1;
1388 context->managed_code = 1;
1389 ves_exec_method_with_context (&frame, context);
1390 context->managed_code = 0;
1391 if (context == &context_struct)
1392 mono_native_tls_set_value (thread_context_id, NULL);
1394 context->current_frame = old_frame;
1395 if (frame.ex != NULL) {
1397 *exc = (MonoObject*) frame.ex;
1400 if (context->current_env != NULL) {
1401 context->env_frame->ex = frame.ex;
1402 longjmp(*context->current_env, 1);
1405 printf("dropped exception...\n");
1407 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1409 if (isobject || method->string_ctor)
1410 return result.data.p;
1411 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1416 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1418 MonoInvocation *old_frame = context->current_frame;
1419 MonoInvocation *old_env_frame = context->env_frame;
1420 jmp_buf *old_env = context->current_env;
1424 context->current_frame = old_frame;
1425 context->env_frame = old_env_frame;
1426 context->current_env = old_env;
1427 context->managed_code = 1;
1431 context->env_frame = context->current_frame;
1432 context->current_env = &env;
1433 context->managed_code = 0;
1436 case MINT_ICALL_V_V: {
1437 void (*func)() = ptr;
1441 case MINT_ICALL_P_V: {
1442 void (*func)(gpointer) = ptr;
1443 func (sp [-1].data.p);
1447 case MINT_ICALL_P_P: {
1448 gpointer (*func)(gpointer) = ptr;
1449 sp [-1].data.p = func (sp [-1].data.p);
1452 case MINT_ICALL_PP_V: {
1453 void (*func)(gpointer,gpointer) = ptr;
1455 func (sp [0].data.p, sp [1].data.p);
1458 case MINT_ICALL_PI_V: {
1459 void (*func)(gpointer,int) = ptr;
1461 func (sp [0].data.p, sp [1].data.i);
1464 case MINT_ICALL_PP_P: {
1465 gpointer (*func)(gpointer,gpointer) = ptr;
1467 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1470 case MINT_ICALL_PI_P: {
1471 gpointer (*func)(gpointer,int) = ptr;
1473 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1476 case MINT_ICALL_PPP_V: {
1477 void (*func)(gpointer,gpointer,gpointer) = ptr;
1479 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1482 case MINT_ICALL_PPI_V: {
1483 void (*func)(gpointer,gpointer,int) = ptr;
1485 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1489 g_assert_not_reached ();
1492 context->env_frame = old_env_frame;
1493 context->current_env = old_env;
1498 static mono_mutex_t create_method_pointer_mutex;
1500 static GHashTable *method_pointer_hash = NULL;
1503 mono_create_method_pointer (MonoMethod *method, MonoError *error)
1507 mono_error_init (error);
1509 mono_os_mutex_lock (&create_method_pointer_mutex);
1510 if (!method_pointer_hash) {
1511 // FIXME: is registering method table as GC root really necessary?
1512 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1513 method_pointer_hash = g_hash_table_new (NULL, NULL);
1515 addr = g_hash_table_lookup (method_pointer_hash, method);
1517 mono_os_mutex_unlock (&create_method_pointer_mutex);
1522 * If it is a static P/Invoke method, we can just return the pointer
1523 * to the method implementation.
1525 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1526 ji = g_new0 (MonoJitInfo, 1);
1527 ji->d.method = method;
1529 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1531 mono_jit_info_table_add (mono_get_root_domain (), ji);
1534 g_error ("FIXME: not available? figure out new API");
1536 addr = mono_arch_create_method_pointer (method);
1540 g_hash_table_insert (method_pointer_hash, method, addr);
1541 mono_os_mutex_unlock (&create_method_pointer_mutex);
1547 static int opcode_counts[512];
1549 #define COUNT_OP(op) opcode_counts[op]++
1551 #define COUNT_OP(op)
1555 #define DUMP_INSTR() \
1556 if (tracing > 1) { \
1558 if (sp > frame->stack) { \
1559 ins = dump_stack (frame->stack, sp); \
1561 ins = g_strdup (""); \
1565 g_print ("(%u) ", mono_thread_internal_current ()); \
1566 mono_interp_dis_mintop(rtm->code, ip); \
1567 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1571 #define DUMP_INSTR()
1575 #define USE_COMPUTED_GOTO 1
1577 #if USE_COMPUTED_GOTO
1578 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1579 #define MINT_IN_CASE(x) LAB_ ## x:
1581 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1583 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1585 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1587 #define MINT_IN_SWITCH(op) switch (op)
1588 #define MINT_IN_CASE(x) case x:
1589 #define MINT_IN_BREAK break
1590 #define MINT_IN_DEFAULT default:
1594 * Defining this causes register allocation errors in some versions of gcc:
1595 * error: unable to find a register to spill in class `SIREG'
1597 /* #define MINT_USE_DEDICATED_IP_REG */
1600 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1602 MonoInvocation child_frame;
1603 GSList *finally_ips = NULL;
1604 const unsigned short *endfinally_ip = NULL;
1605 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1606 register const unsigned short *ip asm ("%esi");
1608 register const unsigned short *ip;
1610 register stackval *sp;
1613 gint tracing = global_tracing;
1614 unsigned char *vtalloc;
1617 unsigned char *vt_sp;
1618 unsigned char *locals;
1620 MonoObject *o = NULL;
1622 #if USE_COMPUTED_GOTO
1623 static void *in_labels[] = {
1624 #define OPDEF(a,b,c,d) \
1626 #include "mintops.def"
1631 frame->ex_handler = NULL;
1633 context->current_frame = frame;
1636 debug_enter (frame, &tracing);
1639 if (!frame->runtime_method->transformed) {
1640 context->managed_code = 0;
1642 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1643 g_printerr ("(0x%08x) Transforming %s\n", mono_thread_internal_current (), mn);
1646 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1647 context->managed_code = 1;
1655 rtm = frame->runtime_method;
1656 frame->args = alloca (rtm->alloca_size);
1657 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1660 memset(sp, 0, rtm->stack_size);
1662 vt_sp = (unsigned char *) sp + rtm->stack_size;
1666 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1668 child_frame.parent = frame;
1674 * using while (ip < end) may result in a 15% performance drop,
1675 * but it may be useful for debug
1679 /* g_assert (sp >= frame->stack); */
1680 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1682 MINT_IN_SWITCH (*ip) {
1683 MINT_IN_CASE(MINT_INITLOCALS)
1684 memset (locals, 0, rtm->locals_size);
1687 MINT_IN_CASE(MINT_NOP)
1690 MINT_IN_CASE(MINT_BREAK)
1692 G_BREAKPOINT (); /* this is not portable... */
1694 MINT_IN_CASE(MINT_LDNULL)
1699 MINT_IN_CASE(MINT_VTRESULT) {
1700 int ret_size = * (guint16 *)(ip + 1);
1701 unsigned char *ret_vt_sp = vt_sp;
1702 vt_sp -= READ32(ip + 2);
1704 memmove (vt_sp, ret_vt_sp, ret_size);
1705 vt_sp += (ret_size + 7) & ~7;
1710 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1711 MINT_IN_CASE(MINT_LDC_I4_M1)
1714 MINT_IN_CASE(MINT_LDC_I4_0)
1717 MINT_IN_CASE(MINT_LDC_I4_1)
1720 MINT_IN_CASE(MINT_LDC_I4_2)
1723 MINT_IN_CASE(MINT_LDC_I4_3)
1726 MINT_IN_CASE(MINT_LDC_I4_4)
1729 MINT_IN_CASE(MINT_LDC_I4_5)
1732 MINT_IN_CASE(MINT_LDC_I4_6)
1735 MINT_IN_CASE(MINT_LDC_I4_7)
1738 MINT_IN_CASE(MINT_LDC_I4_8)
1741 MINT_IN_CASE(MINT_LDC_I4_S)
1742 sp->data.i = *(const short *)(ip + 1);
1746 MINT_IN_CASE(MINT_LDC_I4)
1748 sp->data.i = READ32 (ip);
1752 MINT_IN_CASE(MINT_LDC_I8)
1754 sp->data.l = READ64 (ip);
1758 MINT_IN_CASE(MINT_LDC_R4) {
1762 sp->data.f = * (float *)&val;
1767 MINT_IN_CASE(MINT_LDC_R8)
1768 sp->data.l = READ64 (ip + 1); /* note union usage */
1772 MINT_IN_CASE(MINT_DUP)
1777 MINT_IN_CASE(MINT_DUP_VT)
1778 i32 = READ32 (ip + 1);
1780 memcpy(sp->data.p, sp [-1].data.p, i32);
1781 vt_sp += (i32 + 7) & ~7;
1785 MINT_IN_CASE(MINT_POP)
1789 MINT_IN_CASE(MINT_JMP) {
1790 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1791 if (!new_method->transformed) {
1793 frame->ex = mono_interp_transform_method (new_method, context);
1798 if (new_method->alloca_size > rtm->alloca_size)
1799 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1800 rtm = frame->runtime_method = new_method;
1801 vt_sp = (unsigned char *) sp + rtm->stack_size;
1805 locals = vt_sp + rtm->vt_stack_size;
1806 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1809 MINT_IN_CASE(MINT_CALLI) {
1810 MonoMethodSignature *csignature;
1811 stackval *endsp = sp;
1815 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1819 child_frame.runtime_method = sp->data.p;
1822 child_frame.retval = sp;
1823 /* decrement by the actual number of args */
1824 sp -= csignature->param_count;
1825 child_frame.stack_args = sp;
1826 if (csignature->hasthis) {
1828 child_frame.obj = sp->data.p;
1830 child_frame.obj = NULL;
1832 if (csignature->hasthis && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1833 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1834 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1835 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1836 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1837 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1840 ves_exec_method_with_context (&child_frame, context);
1842 context->current_frame = frame;
1844 if (child_frame.ex) {
1846 * An exception occurred, need to run finally, fault and catch handlers..
1848 frame->ex = child_frame.ex;
1849 goto handle_finally;
1852 /* need to handle typedbyref ... */
1853 if (csignature->ret->type != MONO_TYPE_VOID) {
1859 MINT_IN_CASE(MINT_CALLI_NAT) {
1860 MonoMethodSignature *csignature;
1861 stackval *endsp = sp;
1862 unsigned char *code = NULL;
1866 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1871 child_frame.runtime_method = NULL;
1874 child_frame.retval = sp;
1875 /* decrement by the actual number of args */
1876 sp -= csignature->param_count;
1877 child_frame.stack_args = sp;
1878 if (csignature->hasthis) {
1880 child_frame.obj = sp->data.p;
1882 child_frame.obj = NULL;
1884 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1886 context->current_frame = frame;
1888 if (child_frame.ex) {
1890 * An exception occurred, need to run finally, fault and catch handlers..
1892 frame->ex = child_frame.ex;
1893 if (context->search_for_handler) {
1894 context->search_for_handler = 0;
1895 goto handle_exception;
1897 goto handle_finally;
1900 /* need to handle typedbyref ... */
1901 if (csignature->ret->type != MONO_TYPE_VOID) {
1907 MINT_IN_CASE(MINT_CALL) {
1908 stackval *endsp = sp;
1912 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1915 child_frame.retval = sp;
1916 /* decrement by the actual number of args */
1917 sp -= child_frame.runtime_method->param_count;
1918 child_frame.stack_args = sp;
1919 if (child_frame.runtime_method->hasthis) {
1921 child_frame.obj = sp->data.p;
1923 child_frame.obj = NULL;
1925 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1926 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1927 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1929 ves_exec_method_with_context (&child_frame, context);
1931 context->current_frame = frame;
1933 if (child_frame.ex) {
1935 * An exception occurred, need to run finally, fault and catch handlers..
1937 frame->ex = child_frame.ex;
1938 goto handle_finally;
1941 /* need to handle typedbyref ... */
1946 MINT_IN_CASE(MINT_VCALL) {
1949 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1953 child_frame.retval = sp;
1954 /* decrement by the actual number of args */
1955 sp -= child_frame.runtime_method->param_count;
1956 child_frame.stack_args = sp;
1957 if (child_frame.runtime_method->hasthis) {
1959 child_frame.obj = sp->data.p;
1961 child_frame.obj = NULL;
1964 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1965 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1966 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1969 ves_exec_method_with_context (&child_frame, context);
1971 context->current_frame = frame;
1973 if (child_frame.ex) {
1975 * An exception occurred, need to run finally, fault and catch handlers..
1977 frame->ex = child_frame.ex;
1978 goto handle_finally;
1982 MINT_IN_CASE(MINT_CALLVIRT) {
1983 stackval *endsp = sp;
1984 MonoObject *this_arg;
1989 token = * (unsigned short *)(ip + 1);
1991 child_frame.runtime_method = rtm->data_items [token];
1993 child_frame.retval = sp;
1995 /* decrement by the actual number of args */
1996 sp -= child_frame.runtime_method->param_count;
1997 child_frame.stack_args = sp;
1999 child_frame.obj = this_arg = sp->data.p;
2001 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2002 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2004 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2005 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2008 ves_exec_method_with_context (&child_frame, context);
2010 context->current_frame = frame;
2012 if (child_frame.ex) {
2014 * An exception occurred, need to run finally, fault and catch handlers..
2016 frame->ex = child_frame.ex;
2017 if (context->search_for_handler) {
2018 context->search_for_handler = 0;
2019 goto handle_exception;
2021 goto handle_finally;
2024 /* need to handle typedbyref ... */
2029 MINT_IN_CASE(MINT_VCALLVIRT) {
2030 MonoObject *this_arg;
2035 token = * (unsigned short *)(ip + 1);
2037 child_frame.runtime_method = rtm->data_items [token];
2039 child_frame.retval = sp;
2041 /* decrement by the actual number of args */
2042 sp -= child_frame.runtime_method->param_count;
2043 child_frame.stack_args = sp;
2045 child_frame.obj = this_arg = sp->data.p;
2047 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2048 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2050 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2051 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2054 ves_exec_method_with_context (&child_frame, context);
2056 context->current_frame = frame;
2058 if (child_frame.ex) {
2060 * An exception occurred, need to run finally, fault and catch handlers..
2062 frame->ex = child_frame.ex;
2063 if (context->search_for_handler) {
2064 context->search_for_handler = 0;
2065 goto handle_exception;
2067 goto handle_finally;
2071 MINT_IN_CASE(MINT_CALLINT)
2072 g_printerr ("doing MINT_CALLINT: %p\n", ((MonoMethodPInvoke*) frame->runtime_method->method)->addr);
2073 ves_pinvoke_method (frame, mono_method_signature (frame->runtime_method->method), ((MonoMethodPInvoke*) frame->runtime_method->method)->addr,
2074 frame->runtime_method->method->string_ctor, context);
2077 goto handle_exception;
2080 MINT_IN_CASE(MINT_CALLRUN)
2081 ves_runtime_method (frame, context);
2084 goto handle_exception;
2087 MINT_IN_CASE(MINT_RET)
2089 *frame->retval = *sp;
2090 if (sp > frame->stack)
2091 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2093 MINT_IN_CASE(MINT_RET_VOID)
2094 if (sp > frame->stack)
2095 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2097 MINT_IN_CASE(MINT_RET_VT)
2098 i32 = READ32(ip + 1);
2100 memcpy(frame->retval->data.p, sp->data.p, i32);
2101 if (sp > frame->stack)
2102 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2104 MINT_IN_CASE(MINT_BR_S)
2105 ip += (short) *(ip + 1);
2107 MINT_IN_CASE(MINT_BR)
2108 ip += (gint32) READ32(ip + 1);
2110 #define ZEROP_S(datamem, op) \
2112 if (sp->data.datamem op 0) \
2113 ip += * (gint16 *)(ip + 1); \
2117 #define ZEROP(datamem, op) \
2119 if (sp->data.datamem op 0) \
2120 ip += READ32(ip + 1); \
2124 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2127 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2130 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2133 MINT_IN_CASE(MINT_BRFALSE_I4)
2136 MINT_IN_CASE(MINT_BRFALSE_I8)
2139 MINT_IN_CASE(MINT_BRFALSE_R8)
2142 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2145 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2148 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2151 MINT_IN_CASE(MINT_BRTRUE_I4)
2154 MINT_IN_CASE(MINT_BRTRUE_I8)
2157 MINT_IN_CASE(MINT_BRTRUE_R8)
2160 #define CONDBR_S(cond) \
2163 ip += * (gint16 *)(ip + 1); \
2166 #define BRELOP_S(datamem, op) \
2167 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2169 #define CONDBR(cond) \
2172 ip += READ32(ip + 1); \
2176 #define BRELOP(datamem, op) \
2177 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2179 MINT_IN_CASE(MINT_BEQ_I4_S)
2182 MINT_IN_CASE(MINT_BEQ_I8_S)
2185 MINT_IN_CASE(MINT_BEQ_R8_S)
2186 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2188 MINT_IN_CASE(MINT_BEQ_I4)
2191 MINT_IN_CASE(MINT_BEQ_I8)
2194 MINT_IN_CASE(MINT_BEQ_R8)
2195 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2197 MINT_IN_CASE(MINT_BGE_I4_S)
2200 MINT_IN_CASE(MINT_BGE_I8_S)
2203 MINT_IN_CASE(MINT_BGE_R8_S)
2204 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2206 MINT_IN_CASE(MINT_BGE_I4)
2209 MINT_IN_CASE(MINT_BGE_I8)
2212 MINT_IN_CASE(MINT_BGE_R8)
2213 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2215 MINT_IN_CASE(MINT_BGT_I4_S)
2218 MINT_IN_CASE(MINT_BGT_I8_S)
2221 MINT_IN_CASE(MINT_BGT_R8_S)
2222 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2224 MINT_IN_CASE(MINT_BGT_I4)
2227 MINT_IN_CASE(MINT_BGT_I8)
2230 MINT_IN_CASE(MINT_BGT_R8)
2231 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2233 MINT_IN_CASE(MINT_BLT_I4_S)
2236 MINT_IN_CASE(MINT_BLT_I8_S)
2239 MINT_IN_CASE(MINT_BLT_R8_S)
2240 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2242 MINT_IN_CASE(MINT_BLT_I4)
2245 MINT_IN_CASE(MINT_BLT_I8)
2248 MINT_IN_CASE(MINT_BLT_R8)
2249 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2251 MINT_IN_CASE(MINT_BLE_I4_S)
2254 MINT_IN_CASE(MINT_BLE_I8_S)
2257 MINT_IN_CASE(MINT_BLE_R8_S)
2258 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2260 MINT_IN_CASE(MINT_BLE_I4)
2263 MINT_IN_CASE(MINT_BLE_I8)
2266 MINT_IN_CASE(MINT_BLE_R8)
2267 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2269 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2272 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2275 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2276 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2278 MINT_IN_CASE(MINT_BNE_UN_I4)
2281 MINT_IN_CASE(MINT_BNE_UN_I8)
2284 MINT_IN_CASE(MINT_BNE_UN_R8)
2285 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2288 #define BRELOP_S_CAST(datamem, op, type) \
2290 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2291 ip += * (gint16 *)(ip + 1); \
2295 #define BRELOP_CAST(datamem, op, type) \
2297 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2298 ip += READ32(ip + 1); \
2302 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2303 BRELOP_S_CAST(i, >=, guint32);
2305 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2306 BRELOP_S_CAST(l, >=, guint64);
2308 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2309 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2311 MINT_IN_CASE(MINT_BGE_UN_I4)
2312 BRELOP_CAST(i, >=, guint32);
2314 MINT_IN_CASE(MINT_BGE_UN_I8)
2315 BRELOP_CAST(l, >=, guint64);
2317 MINT_IN_CASE(MINT_BGE_UN_R8)
2318 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2320 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2321 BRELOP_S_CAST(i, >, guint32);
2323 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2324 BRELOP_S_CAST(l, >, guint64);
2326 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2327 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2329 MINT_IN_CASE(MINT_BGT_UN_I4)
2330 BRELOP_CAST(i, >, guint32);
2332 MINT_IN_CASE(MINT_BGT_UN_I8)
2333 BRELOP_CAST(l, >, guint64);
2335 MINT_IN_CASE(MINT_BGT_UN_R8)
2336 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2338 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2339 BRELOP_S_CAST(i, <=, guint32);
2341 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2342 BRELOP_S_CAST(l, <=, guint64);
2344 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2345 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2347 MINT_IN_CASE(MINT_BLE_UN_I4)
2348 BRELOP_CAST(i, <=, guint32);
2350 MINT_IN_CASE(MINT_BLE_UN_I8)
2351 BRELOP_CAST(l, <=, guint64);
2353 MINT_IN_CASE(MINT_BLE_UN_R8)
2354 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2356 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2357 BRELOP_S_CAST(i, <, guint32);
2359 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2360 BRELOP_S_CAST(l, <, guint64);
2362 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2363 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2365 MINT_IN_CASE(MINT_BLT_UN_I4)
2366 BRELOP_CAST(i, <, guint32);
2368 MINT_IN_CASE(MINT_BLT_UN_I8)
2369 BRELOP_CAST(l, <, guint64);
2371 MINT_IN_CASE(MINT_BLT_UN_R8)
2372 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2374 MINT_IN_CASE(MINT_SWITCH) {
2376 const unsigned short *st;
2382 if ((guint32)sp->data.i < n) {
2384 ip += 2 * (guint32)sp->data.i;
2385 offset = READ32 (ip);
2392 MINT_IN_CASE(MINT_LDIND_I1)
2394 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2396 MINT_IN_CASE(MINT_LDIND_U1)
2398 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2400 MINT_IN_CASE(MINT_LDIND_I2)
2402 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2404 MINT_IN_CASE(MINT_LDIND_U2)
2406 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2408 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2409 MINT_IN_CASE(MINT_LDIND_U4)
2411 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2413 MINT_IN_CASE(MINT_LDIND_I8)
2415 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2417 MINT_IN_CASE(MINT_LDIND_I)
2419 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2421 MINT_IN_CASE(MINT_LDIND_R4)
2423 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2425 MINT_IN_CASE(MINT_LDIND_R8)
2427 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2429 MINT_IN_CASE(MINT_LDIND_REF)
2431 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2433 MINT_IN_CASE(MINT_STIND_REF)
2436 * (gpointer *) sp->data.p = sp[1].data.p;
2438 MINT_IN_CASE(MINT_STIND_I1)
2441 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2443 MINT_IN_CASE(MINT_STIND_I2)
2446 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2448 MINT_IN_CASE(MINT_STIND_I4)
2451 * (gint32 *) sp->data.p = sp[1].data.i;
2453 MINT_IN_CASE(MINT_STIND_I)
2456 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2458 MINT_IN_CASE(MINT_STIND_I8)
2461 * (gint64 *) sp->data.p = sp[1].data.l;
2463 MINT_IN_CASE(MINT_STIND_R4)
2466 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2468 MINT_IN_CASE(MINT_STIND_R8)
2471 * (double *) sp->data.p = sp[1].data.f;
2473 #define BINOP(datamem, op) \
2475 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2477 MINT_IN_CASE(MINT_ADD_I4)
2480 MINT_IN_CASE(MINT_ADD_I8)
2483 MINT_IN_CASE(MINT_ADD_R8)
2486 MINT_IN_CASE(MINT_ADD1_I4)
2490 MINT_IN_CASE(MINT_SUB_I4)
2493 MINT_IN_CASE(MINT_SUB_I8)
2496 MINT_IN_CASE(MINT_SUB_R8)
2499 MINT_IN_CASE(MINT_SUB1_I4)
2503 MINT_IN_CASE(MINT_MUL_I4)
2506 MINT_IN_CASE(MINT_MUL_I8)
2509 MINT_IN_CASE(MINT_MUL_R8)
2512 MINT_IN_CASE(MINT_DIV_I4)
2513 if (sp [-1].data.i == 0)
2514 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2515 if (sp [-1].data.i == (-1))
2516 THROW_EX (mono_get_exception_overflow (), ip);
2519 MINT_IN_CASE(MINT_DIV_I8)
2520 if (sp [-1].data.l == 0)
2521 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2522 if (sp [-1].data.l == (-1))
2523 THROW_EX (mono_get_exception_overflow (), ip);
2526 MINT_IN_CASE(MINT_DIV_R8)
2530 #define BINOP_CAST(datamem, op, type) \
2532 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2534 MINT_IN_CASE(MINT_DIV_UN_I4)
2535 if (sp [-1].data.i == 0)
2536 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2537 BINOP_CAST(i, /, guint32);
2539 MINT_IN_CASE(MINT_DIV_UN_I8)
2540 if (sp [-1].data.l == 0)
2541 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2542 BINOP_CAST(l, /, guint64);
2544 MINT_IN_CASE(MINT_REM_I4)
2545 if (sp [-1].data.i == 0)
2546 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2549 MINT_IN_CASE(MINT_REM_I8)
2550 if (sp [-1].data.l == 0)
2551 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2554 MINT_IN_CASE(MINT_REM_R8)
2555 /* FIXME: what do we actually do here? */
2557 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2560 MINT_IN_CASE(MINT_REM_UN_I4)
2561 if (sp [-1].data.i == 0)
2562 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2563 BINOP_CAST(i, %, guint32);
2565 MINT_IN_CASE(MINT_REM_UN_I8)
2566 if (sp [-1].data.l == 0)
2567 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2568 BINOP_CAST(l, %, guint64);
2570 MINT_IN_CASE(MINT_AND_I4)
2573 MINT_IN_CASE(MINT_AND_I8)
2576 MINT_IN_CASE(MINT_OR_I4)
2579 MINT_IN_CASE(MINT_OR_I8)
2582 MINT_IN_CASE(MINT_XOR_I4)
2585 MINT_IN_CASE(MINT_XOR_I8)
2589 #define SHIFTOP(datamem, op) \
2591 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2594 MINT_IN_CASE(MINT_SHL_I4)
2597 MINT_IN_CASE(MINT_SHL_I8)
2600 MINT_IN_CASE(MINT_SHR_I4)
2603 MINT_IN_CASE(MINT_SHR_I8)
2606 MINT_IN_CASE(MINT_SHR_UN_I4)
2608 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2611 MINT_IN_CASE(MINT_SHR_UN_I8)
2613 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2616 MINT_IN_CASE(MINT_NEG_I4)
2617 sp [-1].data.i = - sp [-1].data.i;
2620 MINT_IN_CASE(MINT_NEG_I8)
2621 sp [-1].data.l = - sp [-1].data.l;
2624 MINT_IN_CASE(MINT_NEG_R8)
2625 sp [-1].data.f = - sp [-1].data.f;
2628 MINT_IN_CASE(MINT_NOT_I4)
2629 sp [-1].data.i = ~ sp [-1].data.i;
2632 MINT_IN_CASE(MINT_NOT_I8)
2633 sp [-1].data.l = ~ sp [-1].data.l;
2636 MINT_IN_CASE(MINT_CONV_I1_I4)
2637 sp [-1].data.i = (gint8)sp [-1].data.i;
2640 MINT_IN_CASE(MINT_CONV_I1_I8)
2641 sp [-1].data.i = (gint8)sp [-1].data.l;
2644 MINT_IN_CASE(MINT_CONV_I1_R8)
2645 sp [-1].data.i = (gint8)sp [-1].data.f;
2648 MINT_IN_CASE(MINT_CONV_U1_I4)
2649 sp [-1].data.i = (guint8)sp [-1].data.i;
2652 MINT_IN_CASE(MINT_CONV_U1_I8)
2653 sp [-1].data.i = (guint8)sp [-1].data.l;
2656 MINT_IN_CASE(MINT_CONV_U1_R8)
2657 sp [-1].data.i = (guint8)sp [-1].data.f;
2660 MINT_IN_CASE(MINT_CONV_I2_I4)
2661 sp [-1].data.i = (gint16)sp [-1].data.i;
2664 MINT_IN_CASE(MINT_CONV_I2_I8)
2665 sp [-1].data.i = (gint16)sp [-1].data.l;
2668 MINT_IN_CASE(MINT_CONV_I2_R8)
2669 sp [-1].data.i = (gint16)sp [-1].data.f;
2672 MINT_IN_CASE(MINT_CONV_U2_I4)
2673 sp [-1].data.i = (guint16)sp [-1].data.i;
2676 MINT_IN_CASE(MINT_CONV_U2_I8)
2677 sp [-1].data.i = (guint16)sp [-1].data.l;
2680 MINT_IN_CASE(MINT_CONV_U2_R8)
2681 sp [-1].data.i = (guint16)sp [-1].data.f;
2684 MINT_IN_CASE(MINT_CONV_I4_R8)
2685 sp [-1].data.i = (gint32)sp [-1].data.f;
2688 MINT_IN_CASE(MINT_CONV_U4_I8)
2689 MINT_IN_CASE(MINT_CONV_I4_I8)
2690 sp [-1].data.i = (gint32)sp [-1].data.l;
2693 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2694 sp [-2].data.i = (gint32)sp [-2].data.l;
2697 MINT_IN_CASE(MINT_CONV_U4_R8)
2698 sp [-1].data.i = (guint32)sp [-1].data.f;
2701 MINT_IN_CASE(MINT_CONV_I8_I4)
2702 sp [-1].data.l = sp [-1].data.i;
2705 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2706 sp [-2].data.l = sp [-2].data.i;
2709 MINT_IN_CASE(MINT_CONV_I8_U4)
2710 sp [-1].data.l = (guint32)sp [-1].data.i;
2713 MINT_IN_CASE(MINT_CONV_I8_R8)
2714 sp [-1].data.l = (gint64)sp [-1].data.f;
2717 MINT_IN_CASE(MINT_CONV_R4_I4)
2718 sp [-1].data.f = (float)sp [-1].data.i;
2721 MINT_IN_CASE(MINT_CONV_R4_I8)
2722 sp [-1].data.f = (float)sp [-1].data.l;
2725 MINT_IN_CASE(MINT_CONV_R4_R8)
2726 sp [-1].data.f = (float)sp [-1].data.f;
2729 MINT_IN_CASE(MINT_CONV_R8_I4)
2730 sp [-1].data.f = (double)sp [-1].data.i;
2733 MINT_IN_CASE(MINT_CONV_R8_I8)
2734 sp [-1].data.f = (double)sp [-1].data.l;
2737 MINT_IN_CASE(MINT_CONV_U8_I4)
2738 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2741 MINT_IN_CASE(MINT_CONV_U8_R8)
2742 sp [-1].data.l = (guint64)sp [-1].data.f;
2746 MINT_IN_CASE(MINT_CPOBJ) {
2749 vtklass = rtm->data_items[READ32 (ip)];
2752 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2756 MINT_IN_CASE(MINT_LDOBJ) {
2759 c = rtm->data_items[* (guint16 *)(ip + 1)];
2761 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2763 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2765 size = mono_class_value_size (c, NULL);
2767 sp [-1].data.p = vt_sp;
2768 memcpy(vt_sp, p, size);
2769 vt_sp += (size + 7) & ~7;
2773 MINT_IN_CASE(MINT_LDSTR)
2774 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2778 MINT_IN_CASE(MINT_NEWOBJ) {
2779 MonoClass *newobj_class;
2780 MonoMethodSignature *csig;
2781 stackval valuetype_this;
2787 token = * (guint16 *)(ip + 1);
2790 child_frame.runtime_method = rtm->data_items [token];
2791 csig = mono_method_signature (child_frame.runtime_method->method);
2792 newobj_class = child_frame.runtime_method->method->klass;
2793 /*if (profiling_classes) {
2794 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2796 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2800 if (newobj_class->parent == mono_defaults.array_class) {
2801 sp -= csig->param_count;
2802 o = ves_array_create (context->domain, newobj_class, csig, sp);
2803 goto array_constructed;
2807 * First arg is the object.
2809 if (newobj_class->valuetype) {
2810 if (!newobj_class->enumtype && (newobj_class->byval_arg.type == MONO_TYPE_VALUETYPE)) {
2811 child_frame.obj = vt_sp;
2812 valuetype_this.data.p = vt_sp;
2814 memset (&valuetype_this, 0, sizeof (stackval));
2815 child_frame.obj = &valuetype_this;
2818 if (newobj_class != mono_defaults.string_class) {
2819 context->managed_code = 0;
2820 o = mono_object_new_checked (context->domain, newobj_class, &error);
2821 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2822 context->managed_code = 1;
2823 if (*abort_requested)
2824 mono_thread_interruption_checkpoint ();
2825 child_frame.obj = o;
2827 child_frame.retval = &retval;
2831 if (csig->param_count) {
2832 sp -= csig->param_count;
2833 child_frame.stack_args = sp;
2835 child_frame.stack_args = NULL;
2838 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2840 child_frame.ip = NULL;
2841 child_frame.ex = NULL;
2843 ves_exec_method_with_context (&child_frame, context);
2845 context->current_frame = frame;
2847 if (child_frame.ex) {
2849 * An exception occurred, need to run finally, fault and catch handlers..
2851 frame->ex = child_frame.ex;
2852 goto handle_finally;
2855 * a constructor returns void, but we need to return the object we created
2858 if (newobj_class->valuetype && !newobj_class->enumtype) {
2859 *sp = valuetype_this;
2860 } else if (newobj_class == mono_defaults.string_class) {
2868 MINT_IN_CASE(MINT_CASTCLASS)
2869 c = rtm->data_items [*(guint16 *)(ip + 1)];
2870 if ((o = sp [-1].data.p)) {
2871 if (c->marshalbyref) {
2872 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2873 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2875 THROW_EX (mono_get_exception_invalid_cast (), ip);
2877 MonoVTable *vt = o->vtable;
2878 MonoClass *oklass = vt->klass;
2879 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2880 g_error ("FIXME: interface method lookup");
2881 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2882 THROW_EX (mono_get_exception_invalid_cast (), ip);
2884 } else if (c->rank) {
2885 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2886 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2888 THROW_EX (mono_get_exception_invalid_cast (), ip);
2889 } else if (!mono_class_has_parent (oklass, c)) {
2890 THROW_EX (mono_get_exception_invalid_cast (), ip);
2896 MINT_IN_CASE(MINT_ISINST)
2897 c = rtm->data_items [*(guint16 *)(ip + 1)];
2898 if ((o = sp [-1].data.p)) {
2899 if (c->marshalbyref) {
2900 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2901 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2903 sp [-1].data.p = NULL;
2905 MonoVTable *vt = o->vtable;
2906 MonoClass *oklass = vt->klass;
2907 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2908 g_error ("FIXME: interface method lookup");
2909 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2910 sp [-1].data.p = NULL;
2912 } else if (c->rank) {
2913 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2914 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2916 sp [-1].data.p = NULL;
2917 } else if (!mono_class_has_parent (oklass, c)) {
2918 sp [-1].data.p = NULL;
2924 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2925 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2928 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2929 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2932 MINT_IN_CASE(MINT_UNBOX)
2933 c = rtm->data_items[*(guint16 *)(ip + 1)];
2937 THROW_EX (mono_get_exception_null_reference(), ip);
2939 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2940 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2942 ((o->vtable->klass->rank == 0) &&
2943 (o->vtable->klass->element_class == c->element_class))))
2944 THROW_EX (mono_get_exception_invalid_cast (), ip);
2946 sp [-1].data.p = (char *)o + sizeof (MonoObject);
2949 MINT_IN_CASE(MINT_THROW)
2951 frame->ex_handler = NULL;
2953 sp->data.p = mono_get_exception_null_reference ();
2954 THROW_EX ((MonoException *)sp->data.p, ip);
2956 MINT_IN_CASE(MINT_LDFLDA)
2959 THROW_EX (mono_get_exception_null_reference (), ip);
2960 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2963 MINT_IN_CASE(MINT_CKNULL)
2966 THROW_EX (mono_get_exception_null_reference (), ip);
2970 #define LDFLD(datamem, fieldtype) \
2971 o = sp [-1].data.p; \
2973 THROW_EX (mono_get_exception_null_reference (), ip); \
2974 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2977 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2978 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2979 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2980 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2981 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2982 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
2983 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
2984 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
2985 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
2986 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
2988 MINT_IN_CASE(MINT_LDFLD_VT)
2991 THROW_EX (mono_get_exception_null_reference (), ip);
2992 i32 = READ32(ip + 2);
2993 sp [-1].data.p = vt_sp;
2994 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
2995 vt_sp += (i32 + 7) & ~7;
2999 MINT_IN_CASE(MINT_LDRMFLD) {
3001 MonoClassField *field;
3006 THROW_EX (mono_get_exception_null_reference (), ip);
3007 field = rtm->data_items[* (guint16 *)(ip + 1)];
3009 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3010 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3012 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3013 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3015 addr = (char*)o + field->offset;
3018 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3022 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3023 MonoClassField *field;
3029 THROW_EX (mono_get_exception_null_reference (), ip);
3030 field = rtm->data_items[* (guint16 *)(ip + 1)];
3031 i32 = READ32(ip + 2);
3033 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3034 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3035 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3036 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3038 addr = (char*)o + field->offset;
3041 sp [-1].data.p = vt_sp;
3042 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3043 vt_sp += (i32 + 7) & ~7;
3044 memcpy(sp [-1].data.p, addr, i32);
3048 #define STFLD(datamem, fieldtype) \
3049 o = sp [-2].data.p; \
3051 THROW_EX (mono_get_exception_null_reference (), ip); \
3053 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3056 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3057 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3058 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3059 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3060 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3061 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3062 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3063 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3064 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
3065 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3067 MINT_IN_CASE(MINT_STFLD_VT)
3070 THROW_EX (mono_get_exception_null_reference (), ip);
3071 i32 = READ32(ip + 2);
3073 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3074 vt_sp -= (i32 + 7) & ~7;
3078 MINT_IN_CASE(MINT_STRMFLD) {
3079 MonoClassField *field;
3083 THROW_EX (mono_get_exception_null_reference (), ip);
3085 field = rtm->data_items[* (guint16 *)(ip + 1)];
3088 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3089 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3090 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3091 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3093 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3098 MINT_IN_CASE(MINT_STRMFLD_VT) {
3099 MonoClassField *field;
3103 THROW_EX (mono_get_exception_null_reference (), ip);
3104 field = rtm->data_items[* (guint16 *)(ip + 1)];
3105 i32 = READ32(ip + 2);
3108 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3109 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3110 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3111 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3113 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3116 vt_sp -= (i32 + 7) & ~7;
3119 MINT_IN_CASE(MINT_LDSFLDA) {
3120 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3121 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3124 if (!vt->initialized) {
3126 mono_runtime_class_init_full (vt, &error);
3127 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3131 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3132 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3134 sp->data.p = (char*)(vt->vtable) + field->offset;
3138 MINT_IN_CASE(MINT_LDSFLD) {
3140 MonoClassField *field;
3143 field = rtm->data_items[*(guint16 *)(ip + 1)];
3144 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3145 if (!vt->initialized) {
3147 mono_runtime_class_init_full (vt, &error);
3148 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3151 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3152 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3154 addr = (char*)(vt->vtable) + field->offset;
3156 stackval_from_data (field->type, sp, addr, FALSE);
3160 MINT_IN_CASE(MINT_LDSFLD_I4) {
3161 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3162 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3163 if (!vt->initialized) {
3165 mono_runtime_class_init_full (vt, &error);
3166 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3169 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3173 MINT_IN_CASE(MINT_LDSFLD_O) {
3174 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3175 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3176 if (!vt->initialized) {
3178 mono_runtime_class_init_full (vt, &error);
3179 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3182 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3186 MINT_IN_CASE(MINT_LDSFLD_VT) {
3188 MonoClassField *field;
3193 token = * (guint16 *)(ip + 1);
3194 size = READ32(ip + 2);
3195 field = rtm->data_items[token];
3198 vt = mono_class_vtable (context->domain, field->parent);
3199 if (!vt->initialized) {
3201 mono_runtime_class_init_full (vt, &error);
3202 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3205 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3206 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3208 addr = (char*)(vt->vtable) + field->offset;
3211 vt_sp += (size + 7) & ~7;
3212 stackval_from_data (field->type, sp, addr, FALSE);
3216 MINT_IN_CASE(MINT_STSFLD) {
3218 MonoClassField *field;
3222 token = * (guint16 *)(ip + 1);
3223 field = rtm->data_items[token];
3227 vt = mono_class_vtable (context->domain, field->parent);
3228 if (!vt->initialized) {
3230 mono_runtime_class_init_full (vt, &error);
3231 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3234 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3235 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3237 addr = (char*)(vt->vtable) + field->offset;
3239 stackval_to_data (field->type, sp, addr, FALSE);
3242 MINT_IN_CASE(MINT_STSFLD_VT) {
3244 MonoClassField *field;
3249 token = * (guint16 *)(ip + 1);
3250 size = READ32(ip + 2);
3251 field = rtm->data_items[token];
3254 vt = mono_class_vtable (context->domain, field->parent);
3255 if (!vt->initialized) {
3257 mono_runtime_class_init_full (vt, &error);
3258 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3261 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3262 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3264 addr = (char*)(vt->vtable) + field->offset;
3266 stackval_to_data (field->type, sp, addr, FALSE);
3267 vt_sp -= (size + 7) & ~7;
3270 MINT_IN_CASE(MINT_STOBJ_VT) {
3272 c = rtm->data_items[* (guint16 *)(ip + 1)];
3274 size = mono_class_value_size (c, NULL);
3275 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3276 vt_sp -= (size + 7) & ~7;
3280 MINT_IN_CASE(MINT_STOBJ) {
3282 c = rtm->data_items[* (guint16 *)(ip + 1)];
3284 size = mono_class_value_size (c, NULL);
3285 memcpy(sp [-2].data.p, &sp [-1].data, size);
3289 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3290 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3291 THROW_EX (mono_get_exception_overflow (), ip);
3292 sp [-1].data.i = (guint32)sp [-1].data.f;
3295 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3296 if (sp [-1].data.i < 0)
3297 THROW_EX (mono_get_exception_overflow (), ip);
3298 sp [-1].data.l = sp [-1].data.i;
3301 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3302 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3303 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3304 THROW_EX (mono_get_exception_overflow (), ip);
3305 sp [-1].data.l = (guint64)sp [-1].data.f;
3308 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3309 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3310 THROW_EX (mono_get_exception_overflow (), ip);
3311 sp [-1].data.l = (gint64)sp [-1].data.f;
3314 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3315 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3316 THROW_EX (mono_get_exception_overflow (), ip);
3317 sp [-1].data.i = (mono_u)sp [-1].data.l;
3320 MINT_IN_CASE(MINT_BOX)
3321 c = rtm->data_items [* (guint16 *)(ip + 1)];
3323 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3324 int size = mono_class_value_size (c, NULL);
3325 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3326 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3327 size = (size + 7) & ~7;
3331 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3332 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3333 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3337 MINT_IN_CASE(MINT_NEWARR)
3338 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3339 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3341 /*if (profiling_classes) {
3342 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3344 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3348 MINT_IN_CASE(MINT_LDLEN)
3351 THROW_EX (mono_get_exception_null_reference (), ip);
3352 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3355 MINT_IN_CASE(MINT_GETCHR) {
3359 THROW_EX (mono_get_exception_null_reference (), ip);
3360 i32 = sp [-1].data.i;
3361 if (i32 < 0 || i32 >= mono_string_length (s))
3362 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3364 sp [-1].data.i = mono_string_chars(s)[i32];
3368 MINT_IN_CASE(MINT_STRLEN)
3370 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3372 MINT_IN_CASE(MINT_ARRAY_RANK)
3375 THROW_EX (mono_get_exception_null_reference (), ip);
3376 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3379 MINT_IN_CASE(MINT_LDELEMA) {
3383 /*token = READ32 (ip)*/;
3389 aindex = sp [1].data.i;
3390 if (aindex >= mono_array_length ((MonoArray *) o))
3391 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3393 /* check the array element corresponds to token */
3394 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3396 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3400 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3401 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3402 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3403 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3404 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3405 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3406 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3407 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3408 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3409 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3410 MINT_IN_CASE(MINT_LDELEM_REF) {
3418 THROW_EX (mono_get_exception_null_reference (), ip);
3420 aindex = sp [1].data.i;
3421 if (aindex >= mono_array_length (o))
3422 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3425 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3428 case MINT_LDELEM_I1:
3429 sp [0].data.i = mono_array_get (o, gint8, aindex);
3431 case MINT_LDELEM_U1:
3432 sp [0].data.i = mono_array_get (o, guint8, aindex);
3434 case MINT_LDELEM_I2:
3435 sp [0].data.i = mono_array_get (o, gint16, aindex);
3437 case MINT_LDELEM_U2:
3438 sp [0].data.i = mono_array_get (o, guint16, aindex);
3441 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3443 case MINT_LDELEM_I4:
3444 sp [0].data.i = mono_array_get (o, gint32, aindex);
3446 case MINT_LDELEM_U4:
3447 sp [0].data.i = mono_array_get (o, guint32, aindex);
3449 case MINT_LDELEM_I8:
3450 sp [0].data.l = mono_array_get (o, guint64, aindex);
3452 case MINT_LDELEM_R4:
3453 sp [0].data.f = mono_array_get (o, float, aindex);
3455 case MINT_LDELEM_R8:
3456 sp [0].data.f = mono_array_get (o, double, aindex);
3458 case MINT_LDELEM_REF:
3459 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3469 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3470 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3471 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3472 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3473 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3474 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3475 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3476 MINT_IN_CASE(MINT_STELEM_REF) {
3483 THROW_EX (mono_get_exception_null_reference (), ip);
3485 aindex = sp [1].data.i;
3486 if (aindex >= mono_array_length ((MonoArray *)o))
3487 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3491 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3493 case MINT_STELEM_I1:
3494 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3496 case MINT_STELEM_I2:
3497 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3499 case MINT_STELEM_I4:
3500 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3502 case MINT_STELEM_I8:
3503 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3505 case MINT_STELEM_R4:
3506 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3508 case MINT_STELEM_R8:
3509 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3511 case MINT_STELEM_REF: {
3512 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3513 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3514 if (sp [2].data.p && !isinst_obj)
3515 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3516 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3525 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3526 if (sp [-1].data.i < 0)
3527 THROW_EX (mono_get_exception_overflow (), ip);
3530 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3531 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3532 THROW_EX (mono_get_exception_overflow (), ip);
3533 sp [-1].data.i = (gint32) sp [-1].data.l;
3536 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3537 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3538 THROW_EX (mono_get_exception_overflow (), ip);
3539 sp [-1].data.i = (gint32) sp [-1].data.f;
3542 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3543 if (sp [-1].data.i < 0)
3544 THROW_EX (mono_get_exception_overflow (), ip);
3547 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3548 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3549 THROW_EX (mono_get_exception_overflow (), ip);
3550 sp [-1].data.i = (guint32) sp [-1].data.l;
3553 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3554 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3555 THROW_EX (mono_get_exception_overflow (), ip);
3556 sp [-1].data.i = (guint32) sp [-1].data.f;
3559 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3560 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3561 THROW_EX (mono_get_exception_overflow (), ip);
3564 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3565 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3566 THROW_EX (mono_get_exception_overflow (), ip);
3567 sp [-1].data.i = (gint16) sp [-1].data.l;
3570 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3571 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3572 THROW_EX (mono_get_exception_overflow (), ip);
3573 sp [-1].data.i = (gint16) sp [-1].data.f;
3576 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3577 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3578 THROW_EX (mono_get_exception_overflow (), ip);
3581 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3582 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3583 THROW_EX (mono_get_exception_overflow (), ip);
3584 sp [-1].data.i = (guint16) sp [-1].data.l;
3587 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3588 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3589 THROW_EX (mono_get_exception_overflow (), ip);
3590 sp [-1].data.i = (guint16) sp [-1].data.f;
3593 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3594 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3595 THROW_EX (mono_get_exception_overflow (), ip);
3598 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3599 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3600 THROW_EX (mono_get_exception_overflow (), ip);
3601 sp [-1].data.i = (gint8) sp [-1].data.l;
3604 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3605 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3606 THROW_EX (mono_get_exception_overflow (), ip);
3607 sp [-1].data.i = (gint8) sp [-1].data.f;
3610 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3611 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3612 THROW_EX (mono_get_exception_overflow (), ip);
3615 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3616 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3617 THROW_EX (mono_get_exception_overflow (), ip);
3618 sp [-1].data.i = (guint8) sp [-1].data.l;
3621 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3622 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3623 THROW_EX (mono_get_exception_overflow (), ip);
3624 sp [-1].data.i = (guint8) sp [-1].data.f;
3628 MINT_IN_CASE(MINT_LDELEM)
3629 MINT_IN_CASE(MINT_STELEM)
3630 MINT_IN_CASE(MINT_UNBOX_ANY)
3632 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3634 MINT_IN_CASE(MINT_CKFINITE)
3635 if (!isfinite(sp [-1].data.f))
3636 THROW_EX (mono_get_exception_arithmetic (), ip);
3640 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3642 MINT_IN_CASE(MINT_LDTOKEN)
3645 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3649 MINT_IN_CASE(MINT_ADD_OVF_I4)
3650 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3651 THROW_EX (mono_get_exception_overflow (), ip);
3654 MINT_IN_CASE(MINT_ADD_OVF_I8)
3655 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3656 THROW_EX (mono_get_exception_overflow (), ip);
3659 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3660 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3661 THROW_EX (mono_get_exception_overflow (), ip);
3662 BINOP_CAST(i, +, guint32);
3664 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3665 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3666 THROW_EX (mono_get_exception_overflow (), ip);
3667 BINOP_CAST(l, +, guint64);
3669 MINT_IN_CASE(MINT_MUL_OVF_I4)
3670 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3671 THROW_EX (mono_get_exception_overflow (), ip);
3674 MINT_IN_CASE(MINT_MUL_OVF_I8)
3675 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3676 THROW_EX (mono_get_exception_overflow (), ip);
3679 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3680 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3681 THROW_EX (mono_get_exception_overflow (), ip);
3682 BINOP_CAST(i, *, guint32);
3684 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3685 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3686 THROW_EX (mono_get_exception_overflow (), ip);
3687 BINOP_CAST(l, *, guint64);
3689 MINT_IN_CASE(MINT_SUB_OVF_I4)
3690 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3691 THROW_EX (mono_get_exception_overflow (), ip);
3694 MINT_IN_CASE(MINT_SUB_OVF_I8)
3695 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3696 THROW_EX (mono_get_exception_overflow (), ip);
3699 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3700 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3701 THROW_EX (mono_get_exception_overflow (), ip);
3702 BINOP_CAST(i, -, guint32);
3704 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3705 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3706 THROW_EX (mono_get_exception_overflow (), ip);
3707 BINOP_CAST(l, -, guint64);
3709 MINT_IN_CASE(MINT_ENDFINALLY)
3711 ip = finally_ips->data;
3712 finally_ips = g_slist_remove (finally_ips, ip);
3719 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3720 MINT_IN_CASE(MINT_LEAVE_S)
3721 while (sp > frame->stack) {
3725 if (*ip == MINT_LEAVE_S) {
3726 ip += (short) *(ip + 1);
3728 ip += (gint32) READ32 (ip + 1);
3731 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3732 frame->ex_handler = NULL;
3735 goto handle_finally;
3737 MINT_IN_CASE(MINT_ICALL_V_V)
3738 MINT_IN_CASE(MINT_ICALL_P_V)
3739 MINT_IN_CASE(MINT_ICALL_P_P)
3740 MINT_IN_CASE(MINT_ICALL_PP_V)
3741 MINT_IN_CASE(MINT_ICALL_PI_V)
3742 MINT_IN_CASE(MINT_ICALL_PP_P)
3743 MINT_IN_CASE(MINT_ICALL_PI_P)
3744 MINT_IN_CASE(MINT_ICALL_PPP_V)
3745 MINT_IN_CASE(MINT_ICALL_PPI_V)
3746 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3747 if (frame->ex != NULL)
3748 goto handle_exception;
3751 MINT_IN_CASE(MINT_MONO_LDPTR)
3752 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3756 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3757 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3758 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3762 MINT_IN_CASE(MINT_MONO_FREE)
3765 g_error ("that doesn't seem right");
3766 g_free (sp->data.p);
3768 MINT_IN_CASE(MINT_MONO_RETOBJ)
3771 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3772 mono_method_signature (frame->runtime_method->method)->pinvoke);
3773 if (sp > frame->stack)
3774 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3777 #define RELOP(datamem, op) \
3779 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3781 MINT_IN_CASE(MINT_CEQ_I4)
3784 MINT_IN_CASE(MINT_CEQ0_I4)
3785 sp [-1].data.i = (sp [-1].data.i == 0);
3788 MINT_IN_CASE(MINT_CEQ_I8)
3791 MINT_IN_CASE(MINT_CEQ_R8)
3793 if (isunordered (sp [-1].data.f, sp [0].data.f))
3796 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3799 MINT_IN_CASE(MINT_CGT_I4)
3802 MINT_IN_CASE(MINT_CGT_I8)
3805 MINT_IN_CASE(MINT_CGT_R8)
3807 if (isunordered (sp [-1].data.f, sp [0].data.f))
3810 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3814 #define RELOP_CAST(datamem, op, type) \
3816 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3819 MINT_IN_CASE(MINT_CGT_UN_I4)
3820 RELOP_CAST(i, >, guint32);
3822 MINT_IN_CASE(MINT_CGT_UN_I8)
3823 RELOP_CAST(l, >, guint64);
3825 MINT_IN_CASE(MINT_CGT_UN_R8)
3827 if (isunordered (sp [-1].data.f, sp [0].data.f))
3830 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3833 MINT_IN_CASE(MINT_CLT_I4)
3836 MINT_IN_CASE(MINT_CLT_I8)
3839 MINT_IN_CASE(MINT_CLT_R8)
3841 if (isunordered (sp [-1].data.f, sp [0].data.f))
3844 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3847 MINT_IN_CASE(MINT_CLT_UN_I4)
3848 RELOP_CAST(i, <, guint32);
3850 MINT_IN_CASE(MINT_CLT_UN_I8)
3851 RELOP_CAST(l, <, guint64);
3853 MINT_IN_CASE(MINT_CLT_UN_R8)
3855 if (isunordered (sp [-1].data.f, sp [0].data.f))
3858 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3861 MINT_IN_CASE(MINT_LDFTN) {
3862 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3867 MINT_IN_CASE(MINT_LDVIRTFTN) {
3868 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3872 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3874 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3879 MINT_IN_CASE(MINT_LDTHIS)
3880 sp->data.p = frame->obj;
3884 MINT_IN_CASE(MINT_STTHIS)
3886 frame->obj = sp->data.p;
3889 MINT_IN_CASE(MINT_LDTHISA)
3890 sp->data.p = &frame->obj;
3895 #define LDARG(datamem, argtype) \
3896 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3900 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3901 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3902 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3903 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3904 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3905 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3906 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3907 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3908 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3909 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3911 MINT_IN_CASE(MINT_LDARG_VT)
3913 i32 = READ32(ip + 2);
3914 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3915 vt_sp += (i32 + 7) & ~7;
3920 #define STARG(datamem, argtype) \
3922 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3925 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3926 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3927 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3928 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3929 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3930 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3931 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3932 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3933 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3934 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3936 MINT_IN_CASE(MINT_STARG_VT)
3937 i32 = READ32(ip + 2);
3939 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3940 vt_sp -= (i32 + 7) & ~7;
3944 #define STINARG(datamem, argtype) \
3946 int n = * (guint16 *)(ip + 1); \
3947 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3951 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3952 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3953 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3954 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3955 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3956 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3957 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3958 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3959 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3960 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3962 MINT_IN_CASE(MINT_STINARG_VT) {
3963 int n = * (guint16 *)(ip + 1);
3964 i32 = READ32(ip + 2);
3965 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3970 MINT_IN_CASE(MINT_LDARGA)
3971 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3976 #define LDLOC(datamem, argtype) \
3977 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3981 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3982 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
3983 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
3984 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
3985 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
3986 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
3987 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
3988 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
3989 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
3990 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
3992 MINT_IN_CASE(MINT_LDLOC_VT)
3994 i32 = READ32(ip + 2);
3995 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
3996 vt_sp += (i32 + 7) & ~7;
4001 MINT_IN_CASE(MINT_LDLOCA_S)
4002 sp->data.p = locals + * (guint16 *)(ip + 1);
4007 #define STLOC(datamem, argtype) \
4009 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4012 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4013 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4014 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4015 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4016 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4017 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4018 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4019 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4020 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4021 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4023 #define STLOC_NP(datamem, argtype) \
4024 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4027 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4028 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4030 MINT_IN_CASE(MINT_STLOC_VT)
4031 i32 = READ32(ip + 2);
4033 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4034 vt_sp -= (i32 + 7) & ~7;
4038 MINT_IN_CASE(MINT_LOCALLOC)
4039 if (sp != frame->stack + 1) /*FIX?*/
4040 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4041 sp [-1].data.p = alloca (sp [-1].data.i);
4045 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
4047 MINT_IN_CASE(MINT_INITOBJ)
4049 memset (sp->data.vt, 0, READ32(ip + 1));
4052 MINT_IN_CASE(MINT_CPBLK)
4054 if (!sp [0].data.p || !sp [1].data.p)
4055 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4057 /* FIXME: value and size may be int64... */
4058 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4061 MINT_IN_CASE(MINT_CONSTRAINED_) {
4063 /* FIXME: implement */
4065 token = READ32 (ip);
4070 MINT_IN_CASE(MINT_INITBLK)
4073 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4075 /* FIXME: value and size may be int64... */
4076 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4079 MINT_IN_CASE(MINT_NO_)
4080 /* FIXME: implement */
4084 MINT_IN_CASE(MINT_RETHROW)
4086 * need to clarify what this should actually do:
4087 * start the search from the last found handler in
4088 * this method or continue in the caller or what.
4089 * Also, do we need to run finally/fault handlers after a retrow?
4090 * Well, this implementation will follow the usual search
4091 * for an handler, considering the current ip as throw spot.
4092 * We need to NULL frame->ex_handler for the later code to
4093 * actually run the new found handler.
4095 frame->ex_handler = NULL;
4096 THROW_EX (frame->ex, ip - 1);
4099 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4100 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4104 g_assert_not_reached ();
4106 * Exception handling code.
4107 * The exception object is stored in frame->ex.
4114 MonoInvocation *inv;
4115 MonoExceptionClause *clause;
4121 g_print ("* Handling exception '%s' at IL_%04x\n",
4122 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4123 rtm == NULL ? 0 : frame->ip - rtm->code);
4125 if (die_on_exception)
4128 for (inv = frame; inv; inv = inv->parent) {
4130 if (inv->runtime_method == NULL)
4132 method = inv->runtime_method->method;
4133 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4135 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4137 if (inv->ip == NULL)
4139 ip_offset = inv->ip - inv->runtime_method->code;
4140 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4141 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4142 clause = &inv->runtime_method->clauses [i];
4143 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4144 if (!clause->flags) {
4145 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4146 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4149 * OK, we found an handler, now we need to execute the finally
4150 * and fault blocks before branching to the handler code.
4152 inv->ex_handler = clause;
4155 g_print ("* Found handler at '%s'\n", method->name);
4157 goto handle_finally;
4160 /* FIXME: handle filter clauses */
4167 * If we get here, no handler was found: print a stack trace.
4169 for (inv = frame; inv; inv = inv->parent) {
4170 if (inv->invoke_trap)
4171 goto handle_finally;
4174 ex_obj = (MonoObject*)frame->ex;
4175 mono_unhandled_exception (ex_obj);
4182 MonoExceptionClause *clause;
4183 GSList *old_list = finally_ips;
4184 MonoMethod *method = frame->runtime_method->method;
4185 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4186 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4190 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4192 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4193 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4196 ip_offset = frame->ip - rtm->code;
4198 if (endfinally_ip != NULL)
4199 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4200 for (i = 0; i < header->num_clauses; ++i)
4201 if (frame->ex_handler == &rtm->clauses [i])
4205 clause = &rtm->clauses [i];
4206 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4207 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4208 ip = rtm->code + clause->handler_offset;
4209 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4212 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4218 endfinally_ip = NULL;
4220 if (old_list != finally_ips && finally_ips) {
4221 ip = finally_ips->data;
4222 finally_ips = g_slist_remove (finally_ips, ip);
4223 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4228 * If an exception is set, we need to execute the fault handler, too,
4229 * otherwise, we continue normally.
4239 MonoExceptionClause *clause;
4240 MonoMethod *method = frame->runtime_method->method;
4241 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4242 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4246 g_print ("* Handle fault\n");
4248 ip_offset = frame->ip - rtm->code;
4249 for (i = 0; i < header->num_clauses; ++i) {
4250 clause = &rtm->clauses [i];
4251 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4252 ip = rtm->code + clause->handler_offset;
4255 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4261 * If the handler for the exception was found in this method, we jump
4262 * to it right away, otherwise we return and let the caller run
4263 * the finally, fault and catch blocks.
4264 * This same code should be present in the endfault opcode, but it
4265 * is corrently not assigned in the ECMA specs: LAMESPEC.
4267 if (frame->ex_handler) {
4270 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4272 ip = rtm->code + frame->ex_handler->handler_offset;
4274 vt_sp = (unsigned char *) sp + rtm->stack_size;
4275 sp->data.p = frame->ex;
4286 ves_exec_method (MonoInvocation *frame)
4288 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4289 ThreadContext context_struct;
4296 mono_unhandled_exception ((MonoObject*)frame->ex);
4299 if (context == NULL) {
4300 context = &context_struct;
4301 context_struct.domain = mono_domain_get ();
4302 context_struct.base_frame = frame;
4303 context_struct.current_frame = NULL;
4304 context_struct.env_frame = frame;
4305 context_struct.current_env = &env;
4306 context_struct.search_for_handler = 0;
4307 context_struct.managed_code = 0;
4308 mono_native_tls_set_value (thread_context_id, context);
4311 frame->parent = context->current_frame;
4312 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4313 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4314 context->managed_code = 1;
4315 ves_exec_method_with_context (frame, context);
4316 context->managed_code = 0;
4318 if (context != &context_struct && context->current_env) {
4319 context->env_frame->ex = frame->ex;
4320 longjmp (*context->current_env, 1);
4323 mono_unhandled_exception ((MonoObject*)frame->ex);
4325 if (context->base_frame == frame)
4326 mono_native_tls_set_value (thread_context_id, NULL);
4328 context->current_frame = frame->parent;
4332 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4334 MonoImage *image = mono_assembly_get_image (assembly);
4339 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4340 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4343 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4345 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4346 return_val_and_set_pending_if_nok (&error, rval);
4353 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4354 "Usage is: mint [options] executable args...\n\n", VERSION);
4356 "Runtime Debugging:\n"
4361 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4364 " --traceclassinit\n"
4367 " --debug method_name\n"
4374 " --config filename load the specified config file instead of the default\n"
4375 " --workers n maximum number of worker threads\n"
4381 add_signal_handler (int signo, void (*handler)(int))
4384 signal (signo, handler);
4386 struct sigaction sa;
4388 sa.sa_handler = handler;
4389 sigemptyset (&sa.sa_mask);
4392 g_assert (sigaction (signo, &sa, NULL) != -1);
4397 segv_handler (int signum)
4399 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4400 MonoException *segv_exception;
4402 if (context == NULL)
4404 segv_exception = mono_get_exception_null_reference ();
4405 segv_exception->message = mono_string_new (mono_domain_get (), "Null Reference (SIGSEGV)");
4406 mono_raise_exception (segv_exception);
4411 quit_handler (int signum)
4413 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4414 MonoException *quit_exception;
4416 if (context == NULL)
4418 quit_exception = mono_get_exception_execution_engine ("Interrupted (SIGQUIT).");
4419 mono_raise_exception (quit_exception);
4423 abrt_handler (int signum)
4425 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4426 MonoException *abrt_exception;
4428 if (context == NULL)
4430 abrt_exception = mono_get_exception_execution_engine ("Abort (SIGABRT).");
4431 mono_raise_exception (abrt_exception);
4436 thread_abort_handler (int signum)
4438 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4441 if (context == NULL)
4444 exc = mono_thread_request_interruption (context->managed_code);
4445 if (exc) mono_raise_exception (exc);
4450 ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4451 MonoReflectionMethod **method,
4452 gint32 *iloffset, gint32 *native_offset,
4453 MonoString **file, gint32 *line, gint32 *column)
4455 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4456 MonoInvocation *inv = context->current_frame;
4460 for (i = 0; inv && i < skip; inv = inv->parent)
4461 if (inv->runtime_method != NULL)
4472 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4473 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4478 if (need_file_info) {
4482 *file = mono_string_new (mono_domain_get (), "unknown");
4489 ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4491 MonoDomain *domain = mono_domain_get ();
4493 MonoArray *ta = exc->trace_ips;
4498 /* Exception is not thrown yet */
4499 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4500 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4504 len = mono_array_length (ta);
4506 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4507 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4509 for (i = skip; i < len / 2; i++) {
4510 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4511 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4512 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4513 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4516 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4517 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4518 sf->native_offset = ip - rtm->code;
4522 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4524 if (need_file_info) {
4527 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4529 sf->filename = filename? mono_string_new (domain, filename): NULL;
4536 mono_array_set (res, gpointer, i, sf);
4543 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4545 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4546 MonoObject *delegate;
4549 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4551 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4552 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4554 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4555 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4564 int enable_debugging;
4570 static void main_thread_handler (gpointer user_data)
4572 MainThreadArgs *main_args=(MainThreadArgs *)user_data;
4573 MonoAssembly *assembly;
4575 if (main_args->enable_debugging) {
4576 mono_debug_init (MONO_DEBUG_FORMAT_MONO);
4579 assembly = mono_domain_assembly_open (main_args->domain, main_args->file);
4582 fprintf (stderr, "Can not open image %s\n", main_args->file);
4586 ves_exec (main_args->domain, assembly, main_args->argc, main_args->argv);
4590 mono_runtime_install_handlers (void)
4592 add_signal_handler (SIGSEGV, segv_handler);
4593 add_signal_handler (SIGINT, quit_handler);
4594 add_signal_handler (SIGABRT, abrt_handler);
4596 add_signal_handler (mono_thread_get_abort_signal (), thread_abort_handler);
4601 quit_function (MonoDomain *domain, gpointer user_data)
4603 mono_profiler_shutdown ();
4605 mono_runtime_cleanup (domain);
4606 mono_domain_free (domain, TRUE);
4611 mono_interp_cleanup(MonoDomain *domain)
4613 quit_function (domain, NULL);
4617 mono_interp_exec(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4619 return ves_exec (domain, assembly, argc, argv);
4623 interp_get_imt_trampoline (MonoVTable *vtable, int imt_slot_index)
4625 // FIXME: implement me
4630 interp_create_ftnptr (MonoDomain *domain, gpointer addr)
4632 // FIXME: true on all arch?
4637 mono_current_thread_has_handle_block_guard (void)
4643 mono_interp_init(const char *file)
4646 MonoRuntimeCallbacks callbacks;
4647 MonoRuntimeExceptionHandlingCallbacks ecallbacks;
4650 g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
4651 g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
4653 mono_native_tls_alloc (&thread_context_id, NULL);
4654 mono_native_tls_set_value (thread_context_id, NULL);
4655 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4656 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4658 // TODO: use callbacks?
4659 mono_runtime_install_handlers ();
4660 mono_interp_transform_init ();
4662 memset (&callbacks, 0, sizeof (callbacks));
4663 // TODO: replace with `mono_install_callbacks`
4664 callbacks.compile_method = mono_create_method_pointer;
4665 callbacks.runtime_invoke = interp_mono_runtime_invoke;
4666 callbacks.get_imt_trampoline = interp_get_imt_trampoline;
4667 callbacks.create_ftnptr = interp_create_ftnptr;
4668 #ifndef DISABLE_REMOTING
4669 mono_install_remoting_trampoline (interp_create_remoting_trampoline);
4671 callbacks.create_jit_trampoline = interp_create_trampoline;
4672 mono_install_callbacks (&callbacks);
4675 memset (&ecallbacks, 0, sizeof (ecallbacks));
4676 ecallbacks.mono_raise_exception = interp_ex_handler;
4677 ecallbacks.mono_current_thread_has_handle_block_guard = mono_current_thread_has_handle_block_guard;
4680 mono_install_stack_walk (interp_walk_stack);
4682 mono_install_eh_callbacks (&ecallbacks);
4684 mono_install_runtime_cleanup (quit_function);
4686 abort_requested = mono_thread_interruption_request_flag ();
4688 domain = mono_init_from_assembly (file, file);
4689 #ifdef __hpux /* generates very big stack frames */
4690 mono_threads_set_default_stacksize(32*1024*1024);
4693 mono_add_internal_call ("System.Diagnostics.StackFrame::get_frame_info", ves_icall_get_frame_info);
4694 mono_add_internal_call ("System.Diagnostics.StackTrace::get_trace", ves_icall_get_trace);
4695 mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers", mono_runtime_install_handlers);
4696 mono_add_internal_call ("System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal);
4698 mono_register_jit_icall (mono_thread_interruption_checkpoint, "mono_thread_interruption_checkpoint", mono_create_icall_signature ("void"), FALSE);
4700 mono_runtime_init_checked (domain, NULL, NULL, &error);
4701 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4703 mono_thread_attach (domain);
4707 typedef int (*TestMethod) (void);
4710 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4712 int result, expected, failed, cfailed, run;
4714 double elapsed, transform_time, start_time;
4716 MonoObject *result_obj;
4718 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4719 cfailed = failed = run = 0;
4720 transform_time = elapsed = 0.0;
4723 /* fixme: ugly hack - delete all previously compiled methods */
4724 if (domain_jit_info (domain)) {
4725 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4726 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4727 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4728 mono_jit_code_hash_init (&(domain->jit_code_hash));
4732 g_timer_start (timer);
4733 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4735 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4737 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4740 if (strncmp (method->name, "test_", 5) == 0) {
4741 MonoError interp_error;
4742 RuntimeMethod *runtime_method;
4743 MonoInvocation frame;
4744 ThreadContext context;
4745 stackval frame_result;
4746 MonoObject *exc = NULL;
4748 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4749 if (!mono_error_ok (&interp_error)) {
4751 g_print ("Test '%s' execution failed.\n", method->name);
4752 } else if (exc != NULL) {
4753 g_print ("Exception in Test '%s' occured:\n", method->name);
4754 mono_object_describe (exc);
4758 result = *(gint32 *) mono_object_unbox (result_obj);
4759 expected = atoi (method->name + 5); // FIXME: oh no.
4762 if (result != expected) {
4764 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4769 g_timer_stop (timer);
4770 elapsed = g_timer_elapsed (timer, NULL);
4771 if (failed > 0 || cfailed > 0){
4772 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4773 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4775 g_print ("Results: total tests: %d, all pass \n", run);
4778 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4779 elapsed - transform_time, transform_time);
4780 *total += failed + cfailed;
4784 interp_regression (MonoImage *image, int verbose, int *total_run)
4788 GTimer *timer = g_timer_new ();
4789 MonoDomain *domain = mono_domain_get ();
4790 guint32 i, exclude = 0;
4793 /* load the metadata */
4794 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4796 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4798 mono_error_cleanup (&error);
4801 mono_class_init (method->klass);
4806 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4808 g_timer_destroy (timer);
4813 interp_regression_list (int verbose, int count, char *images [])
4815 int i, total, total_run, run;
4817 total_run = total = 0;
4818 for (i = 0; i < count; ++i) {
4819 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4821 g_warning ("failed to load assembly: %s", images [i]);
4824 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4828 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4830 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);