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);
639 if (sp [ac->rank].data.p && !mono_object_class (o)->element_class->valuetype) {
641 MonoObject *isinst = mono_object_isinst_checked (sp [ac->rank].data.p, mono_object_class (o)->element_class, &error);
642 mono_error_cleanup (&error);
644 frame->ex = mono_get_exception_array_type_mismatch ();
645 FILL_IN_TRACE (frame->ex, frame);
650 esize = mono_array_element_size (ac);
651 ea = mono_array_addr_with_size (ao, esize, pos);
653 mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
654 stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
658 ves_array_get (MonoInvocation *frame)
660 stackval *sp = frame->stack_args;
664 gint32 i, t, pos, esize;
670 ac = o->vtable->klass;
672 g_assert (ac->rank >= 1);
675 if (ao->bounds != NULL) {
676 pos -= ao->bounds [0].lower_bound;
677 for (i = 1; i < ac->rank; i++) {
678 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
679 ao->bounds [i].length) {
680 frame->ex = mono_get_exception_index_out_of_range ();
681 FILL_IN_TRACE(frame->ex, frame);
685 pos = pos*ao->bounds [i].length + sp [i].data.i -
686 ao->bounds [i].lower_bound;
688 } else if (pos >= ao->max_length) {
689 frame->ex = mono_get_exception_index_out_of_range ();
690 FILL_IN_TRACE(frame->ex, frame);
694 esize = mono_array_element_size (ac);
695 ea = mono_array_addr_with_size (ao, esize, pos);
697 mt = mono_method_signature (frame->runtime_method->method)->ret;
698 stackval_from_data (mt, frame->retval, ea, FALSE);
702 ves_array_element_address (MonoInvocation *frame)
704 stackval *sp = frame->stack_args;
708 gint32 i, t, pos, esize;
713 ac = o->vtable->klass;
715 g_assert (ac->rank >= 1);
718 if (ao->bounds != NULL) {
719 pos -= ao->bounds [0].lower_bound;
720 for (i = 1; i < ac->rank; i++) {
721 if ((t = sp [i].data.i - ao->bounds [i].lower_bound) >=
722 ao->bounds [i].length) {
723 frame->ex = mono_get_exception_index_out_of_range ();
724 FILL_IN_TRACE(frame->ex, frame);
727 pos = pos*ao->bounds [i].length + sp [i].data.i -
728 ao->bounds [i].lower_bound;
730 } else if (pos >= ao->max_length) {
731 frame->ex = mono_get_exception_index_out_of_range ();
732 FILL_IN_TRACE(frame->ex, frame);
736 esize = mono_array_element_size (ac);
737 ea = mono_array_addr_with_size (ao, esize, pos);
739 frame->retval->data.p = ea;
743 interp_walk_stack (MonoStackWalk func, gboolean do_il_offset, gpointer user_data)
745 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
746 MonoInvocation *frame;
748 MonoMethodHeader *hd;
751 if (!context) return;
753 frame = context->current_frame;
756 gboolean managed = FALSE;
757 MonoMethod *method = frame->runtime_method->method;
758 if (!method || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME)))
761 hd = mono_method_get_header_checked (method, &error);
762 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
763 il_offset = frame->ip - (const unsigned short *)hd->code;
764 if (!method->wrapper_type)
767 if (func (method, -1, il_offset, managed, user_data))
769 frame = frame->parent;
773 static MonoPIFunc mono_interp_enter_icall_trampoline = NULL;
775 struct _MethodArguments {
783 typedef struct _MethodArguments MethodArguments;
785 // TODO: this function is also arch dependent (register width).
786 static MethodArguments* build_args_from_sig (MonoMethodSignature *sig, MonoInvocation *frame)
788 // TODO: don't malloc this data structure.
789 MethodArguments *margs = g_malloc0 (sizeof (MethodArguments));
794 for (int i = 0; i < sig->param_count; i++) {
795 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
797 case MONO_TYPE_BOOLEAN:
808 case MONO_TYPE_SZARRAY:
809 case MONO_TYPE_CLASS:
810 case MONO_TYPE_OBJECT:
811 case MONO_TYPE_STRING:
816 g_error ("build_args_from_sig: not implemented yet (1): 0x%x\n", ptype);
821 margs->iargs = g_malloc0 (sizeof (gpointer) * margs->ilen);
824 g_error ("build_args_from_sig: TODO, more than two iregs\n");
827 g_error ("build_args_from_sig: TODO, allocate floats\n");
834 margs->iargs [0] = frame->obj;
838 for (int i = 0; i < sig->param_count; i++) {
839 guint32 ptype = sig->params [i]->byref ? MONO_TYPE_PTR : sig->params [i]->type;
841 case MONO_TYPE_BOOLEAN:
852 case MONO_TYPE_SZARRAY:
853 case MONO_TYPE_CLASS:
854 case MONO_TYPE_OBJECT:
855 case MONO_TYPE_STRING:
857 margs->iargs [int_i] = frame->stack_args [i].data.l;
858 g_printerr ("build_args_from_sig: margs->iargs[%d]: %p (frame @ %d)\n", int_i, margs->iargs[int_i], i);
862 g_error ("build_args_from_sig: not implemented yet (2): 0x%x\n", ptype);
866 if (sig->ret->type != MONO_TYPE_VOID) {
867 margs->retval = &(frame->retval->data.p);
869 margs->retval = NULL;
876 ves_pinvoke_method (MonoInvocation *frame, MonoMethodSignature *sig, MonoFuncV addr, gboolean string_ctor, ThreadContext *context)
880 MonoInvocation *old_frame = context->current_frame;
881 MonoInvocation *old_env_frame = context->env_frame;
882 jmp_buf *old_env = context->current_env;
885 context->current_frame = old_frame;
886 context->env_frame = old_env_frame;
887 context->current_env = old_env;
888 context->managed_code = 1;
893 context->env_frame = frame;
894 context->current_env = &env;
896 g_assert (frame->runtime_method);
897 func = frame->runtime_method->func;
899 g_printerr ("ICALL(1): func = NULL, addr = %p\n", addr);
900 if (!mono_interp_enter_icall_trampoline) {
902 mono_interp_enter_icall_trampoline = mono_arch_get_enter_icall_trampoline (&info);
903 // mono_tramp_info_register (info, NULL);
905 func = mono_interp_enter_icall_trampoline;
906 g_printerr ("ICALL(2): func = %p, addr = %p\n", func, addr);
909 MethodArguments *margs = build_args_from_sig (sig, frame);
911 g_printerr ("margs(out): ilen=%d, flen=%d\n", margs->ilen, margs->flen);
913 context->current_frame = frame;
914 context->managed_code = 0;
919 context->managed_code = 1;
920 /* domain can only be changed by native code */
921 context->domain = mono_domain_get ();
923 if (*abort_requested)
924 mono_thread_interruption_checkpoint ();
926 if (!MONO_TYPE_ISSTRUCT (sig->ret))
927 stackval_from_data (sig->ret, frame->retval, (char*)&frame->retval->data.p, sig->pinvoke);
929 context->current_frame = old_frame;
930 context->env_frame = old_env_frame;
931 context->current_env = old_env;
933 g_free (margs->iargs);
934 g_free (margs->fargs);
939 interp_delegate_ctor (MonoDomain *domain, MonoObject *this, MonoObject *target, RuntimeMethod *runtime_method)
941 MonoDelegate *delegate = (MonoDelegate *)this;
944 delegate->method_info = mono_method_get_object_checked (domain, runtime_method->method, NULL, &error);
945 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
946 delegate->target = target;
948 if (target && target->vtable->klass == mono_defaults.transparent_proxy_class) {
949 MonoMethod *method = mono_marshal_get_remoting_invoke (runtime_method->method);
950 delegate->method_ptr = mono_interp_get_runtime_method (domain, method, &error);
951 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
953 delegate->method_ptr = runtime_method;
958 mono_interp_ftnptr_to_delegate (MonoClass *klass, gpointer ftn)
962 MonoDomain *domain = mono_domain_get ();
965 d = (MonoDelegate*)mono_object_new_checked (domain, klass, &error);
966 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
968 ji = mono_jit_info_table_find (domain, ftn);
970 mono_raise_exception (mono_get_exception_argument ("", "Function pointer was not created by a Delegate."));
972 /* FIXME: discard the wrapper and call the original method */
973 interp_delegate_ctor (domain, (MonoObject*)d, NULL, mono_interp_get_runtime_method (domain, ji->d.method, &error));
974 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
981 * runtime specifies that the implementation of the method is automatically
982 * provided by the runtime and is primarily used for the methods of delegates.
985 ves_runtime_method (MonoInvocation *frame, ThreadContext *context)
987 MonoMethod *method = frame->runtime_method->method;
988 const char *name = method->name;
989 MonoObject *obj = (MonoObject*)frame->obj;
990 MonoObject *isinst_obj;
993 mono_class_init (method->klass);
995 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.multicastdelegate_class, &error);
996 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
997 if (obj && isinst_obj) {
998 if (*name == '.' && (strcmp (name, ".ctor") == 0)) {
999 interp_delegate_ctor (context->domain, obj, frame->stack_args[0].data.p, frame->stack_args[1].data.p);
1004 isinst_obj = mono_object_isinst_checked (obj, mono_defaults.array_class, &error);
1005 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1006 if (obj && isinst_obj) {
1007 if (*name == 'S' && (strcmp (name, "Set") == 0)) {
1008 ves_array_set (frame);
1011 if (*name == 'G' && (strcmp (name, "Get") == 0)) {
1012 ves_array_get (frame);
1015 if (*name == 'A' && (strcmp (name, "Address") == 0)) {
1016 ves_array_element_address (frame);
1021 g_error ("Don't know how to exec runtime method %s.%s::%s",
1022 method->klass->name_space, method->klass->name,
1027 dump_stack (stackval *stack, stackval *sp)
1029 stackval *s = stack;
1030 GString *str = g_string_new ("");
1033 return g_string_free (str, FALSE);
1036 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
1039 return g_string_free (str, FALSE);
1043 dump_stackval (GString *str, stackval *s, MonoType *type)
1045 switch (type->type) {
1052 case MONO_TYPE_CHAR:
1053 case MONO_TYPE_BOOLEAN:
1054 g_string_append_printf (str, "[%d] ", s->data.i);
1056 case MONO_TYPE_STRING:
1057 case MONO_TYPE_SZARRAY:
1058 case MONO_TYPE_CLASS:
1059 case MONO_TYPE_OBJECT:
1060 case MONO_TYPE_ARRAY:
1064 g_string_append_printf (str, "[%p] ", s->data.p);
1066 case MONO_TYPE_VALUETYPE:
1067 if (type->data.klass->enumtype)
1068 g_string_append_printf (str, "[%d] ", s->data.i);
1070 g_string_append_printf (str, "[vt:%p] ", s->data.p);
1074 g_string_append_printf (str, "[%g] ", s->data.f);
1079 g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
1085 dump_args (MonoInvocation *inv)
1087 GString *str = g_string_new ("");
1089 MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
1091 if (signature->param_count == 0)
1092 return g_string_free (str, FALSE);
1094 if (signature->hasthis)
1095 g_string_append_printf (str, "%p ", inv->obj);
1097 for (i = 0; i < signature->param_count; ++i)
1098 dump_stackval (str, inv->stack_args + i, signature->params [i]);
1100 return g_string_free (str, FALSE);
1104 dump_retval (MonoInvocation *inv)
1106 GString *str = g_string_new ("");
1107 MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
1109 if (ret->type != MONO_TYPE_VOID)
1110 dump_stackval (str, inv->retval, ret);
1112 return g_string_free (str, FALSE);
1116 dump_frame (MonoInvocation *inv)
1118 GString *str = g_string_new ("");
1123 for (i = 0; inv; inv = inv->parent) {
1124 if (inv->runtime_method != NULL) {
1125 MonoMethod *method = inv->runtime_method->method;
1129 const char * opname = "";
1131 gchar *source = NULL;
1135 if ((method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) == 0 &&
1136 (method->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) == 0) {
1137 MonoMethodHeader *hd = mono_method_get_header_checked (method, &error);
1138 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1142 opname = mono_interp_opname [*inv->ip];
1143 codep = inv->ip - inv->runtime_method->code;
1144 source = g_strdup_printf ("%s:%d // (TODO: proper stacktrace)", method->name, codep);
1149 MonoDebugSourceLocation *minfo = mono_debug_lookup_method (method);
1150 source = mono_debug_method_lookup_location (minfo, codep);
1154 args = dump_args (inv);
1155 name = mono_method_full_name (method, TRUE);
1157 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname, name, args, source);
1159 g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname, name, args);
1166 return g_string_free (str, FALSE);
1170 get_trace_ips (MonoDomain *domain, MonoInvocation *top)
1174 MonoInvocation *inv;
1177 for (i = 0, inv = top; inv; inv = inv->parent)
1178 if (inv->runtime_method != NULL)
1181 res = mono_array_new_checked (domain, mono_defaults.int_class, 2 * i, &error);
1182 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1184 for (i = 0, inv = top; inv; inv = inv->parent)
1185 if (inv->runtime_method != NULL) {
1186 mono_array_set (res, gpointer, i, inv->runtime_method);
1188 mono_array_set (res, gpointer, i, (gpointer)inv->ip);
1196 #define MYGUINT64_MAX 18446744073709551615ULL
1197 #define MYGINT64_MAX 9223372036854775807LL
1198 #define MYGINT64_MIN (-MYGINT64_MAX -1LL)
1200 #define MYGUINT32_MAX 4294967295U
1201 #define MYGINT32_MAX 2147483647
1202 #define MYGINT32_MIN (-MYGINT32_MAX -1)
1204 #define CHECK_ADD_OVERFLOW(a,b) \
1205 (gint32)(b) >= 0 ? (gint32)(MYGINT32_MAX) - (gint32)(b) < (gint32)(a) ? -1 : 0 \
1206 : (gint32)(MYGINT32_MIN) - (gint32)(b) > (gint32)(a) ? +1 : 0
1208 #define CHECK_SUB_OVERFLOW(a,b) \
1209 (gint32)(b) < 0 ? (gint32)(MYGINT32_MAX) + (gint32)(b) < (gint32)(a) ? -1 : 0 \
1210 : (gint32)(MYGINT32_MIN) + (gint32)(b) > (gint32)(a) ? +1 : 0
1212 #define CHECK_ADD_OVERFLOW_UN(a,b) \
1213 (guint32)(MYGUINT32_MAX) - (guint32)(b) < (guint32)(a) ? -1 : 0
1215 #define CHECK_SUB_OVERFLOW_UN(a,b) \
1216 (guint32)(a) < (guint32)(b) ? -1 : 0
1218 #define CHECK_ADD_OVERFLOW64(a,b) \
1219 (gint64)(b) >= 0 ? (gint64)(MYGINT64_MAX) - (gint64)(b) < (gint64)(a) ? -1 : 0 \
1220 : (gint64)(MYGINT64_MIN) - (gint64)(b) > (gint64)(a) ? +1 : 0
1222 #define CHECK_SUB_OVERFLOW64(a,b) \
1223 (gint64)(b) < 0 ? (gint64)(MYGINT64_MAX) + (gint64)(b) < (gint64)(a) ? -1 : 0 \
1224 : (gint64)(MYGINT64_MIN) + (gint64)(b) > (gint64)(a) ? +1 : 0
1226 #define CHECK_ADD_OVERFLOW64_UN(a,b) \
1227 (guint64)(MYGUINT64_MAX) - (guint64)(b) < (guint64)(a) ? -1 : 0
1229 #define CHECK_SUB_OVERFLOW64_UN(a,b) \
1230 (guint64)(a) < (guint64)(b) ? -1 : 0
1232 #if SIZEOF_VOID_P == 4
1233 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW(a,b)
1234 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW_UN(a,b)
1236 #define CHECK_ADD_OVERFLOW_NAT(a,b) CHECK_ADD_OVERFLOW64(a,b)
1237 #define CHECK_ADD_OVERFLOW_NAT_UN(a,b) CHECK_ADD_OVERFLOW64_UN(a,b)
1240 /* Resolves to TRUE if the operands would overflow */
1241 #define CHECK_MUL_OVERFLOW(a,b) \
1242 ((gint32)(a) == 0) || ((gint32)(b) == 0) ? 0 : \
1243 (((gint32)(a) > 0) && ((gint32)(b) == -1)) ? FALSE : \
1244 (((gint32)(a) < 0) && ((gint32)(b) == -1)) ? (a == - MYGINT32_MAX) : \
1245 (((gint32)(a) > 0) && ((gint32)(b) > 0)) ? (gint32)(a) > ((MYGINT32_MAX) / (gint32)(b)) : \
1246 (((gint32)(a) > 0) && ((gint32)(b) < 0)) ? (gint32)(a) > ((MYGINT32_MIN) / (gint32)(b)) : \
1247 (((gint32)(a) < 0) && ((gint32)(b) > 0)) ? (gint32)(a) < ((MYGINT32_MIN) / (gint32)(b)) : \
1248 (gint32)(a) < ((MYGINT32_MAX) / (gint32)(b))
1250 #define CHECK_MUL_OVERFLOW_UN(a,b) \
1251 ((guint32)(a) == 0) || ((guint32)(b) == 0) ? 0 : \
1252 (guint32)(b) > ((MYGUINT32_MAX) / (guint32)(a))
1254 #define CHECK_MUL_OVERFLOW64(a,b) \
1255 ((gint64)(a) == 0) || ((gint64)(b) == 0) ? 0 : \
1256 (((gint64)(a) > 0) && ((gint64)(b) == -1)) ? FALSE : \
1257 (((gint64)(a) < 0) && ((gint64)(b) == -1)) ? (a == - MYGINT64_MAX) : \
1258 (((gint64)(a) > 0) && ((gint64)(b) > 0)) ? (gint64)(a) > ((MYGINT64_MAX) / (gint64)(b)) : \
1259 (((gint64)(a) > 0) && ((gint64)(b) < 0)) ? (gint64)(a) > ((MYGINT64_MIN) / (gint64)(b)) : \
1260 (((gint64)(a) < 0) && ((gint64)(b) > 0)) ? (gint64)(a) < ((MYGINT64_MIN) / (gint64)(b)) : \
1261 (gint64)(a) < ((MYGINT64_MAX) / (gint64)(b))
1263 #define CHECK_MUL_OVERFLOW64_UN(a,b) \
1264 ((guint64)(a) == 0) || ((guint64)(b) == 0) ? 0 : \
1265 (guint64)(b) > ((MYGUINT64_MAX) / (guint64)(a))
1267 #if SIZEOF_VOID_P == 4
1268 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW(a,b)
1269 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW_UN(a,b)
1271 #define CHECK_MUL_OVERFLOW_NAT(a,b) CHECK_MUL_OVERFLOW64(a,b)
1272 #define CHECK_MUL_OVERFLOW_NAT_UN(a,b) CHECK_MUL_OVERFLOW64_UN(a,b)
1276 interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoObject **exc, MonoError *error)
1278 MonoInvocation frame;
1279 ThreadContext * volatile context = mono_native_tls_get_value (thread_context_id);
1280 MonoObject *retval = NULL;
1281 MonoMethodSignature *sig = mono_method_signature (method);
1282 MonoClass *klass = mono_class_from_mono_type (sig->ret);
1283 int i, type, isobject = 0;
1286 stackval *args = alloca (sizeof (stackval) * sig->param_count);
1287 ThreadContext context_struct;
1288 MonoInvocation *old_frame = NULL;
1291 mono_error_init (error);
1296 if (context != &context_struct) {
1297 context->domain = mono_domain_get ();
1298 context->current_frame = old_frame;
1299 context->managed_code = 0;
1301 mono_native_tls_set_value (thread_context_id, NULL);
1303 *exc = (MonoObject *)frame.ex;
1307 if (context == NULL) {
1308 context = &context_struct;
1309 context_struct.base_frame = &frame;
1310 context_struct.current_frame = NULL;
1311 context_struct.env_frame = &frame;
1312 context_struct.current_env = &env;
1313 context_struct.search_for_handler = 0;
1314 context_struct.managed_code = 0;
1315 mono_native_tls_set_value (thread_context_id, context);
1318 old_frame = context->current_frame;
1320 context->domain = mono_domain_get ();
1322 switch (sig->ret->type) {
1323 case MONO_TYPE_VOID:
1325 case MONO_TYPE_STRING:
1326 case MONO_TYPE_OBJECT:
1327 case MONO_TYPE_CLASS:
1328 case MONO_TYPE_ARRAY:
1329 case MONO_TYPE_SZARRAY:
1332 case MONO_TYPE_VALUETYPE:
1333 retval = mono_object_new_checked (context->domain, klass, error);
1334 ret = ((char*)retval) + sizeof (MonoObject);
1335 if (!sig->ret->data.klass->enumtype)
1336 result.data.vt = ret;
1339 retval = mono_object_new_checked (context->domain, klass, error);
1340 ret = ((char*)retval) + sizeof (MonoObject);
1344 for (i = 0; i < sig->param_count; ++i) {
1345 if (sig->params [i]->byref) {
1346 args [i].data.p = params [i];
1349 type = sig->params [i]->type;
1354 case MONO_TYPE_BOOLEAN:
1355 args [i].data.i = *(MonoBoolean*)params [i];
1359 case MONO_TYPE_CHAR:
1360 args [i].data.i = *(gint16*)params [i];
1362 #if SIZEOF_VOID_P == 4
1363 case MONO_TYPE_U: /* use VAL_POINTER? */
1368 args [i].data.i = *(gint32*)params [i];
1370 #if SIZEOF_VOID_P == 8
1376 args [i].data.l = *(gint64*)params [i];
1378 case MONO_TYPE_VALUETYPE:
1379 if (sig->params [i]->data.klass->enumtype) {
1380 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
1383 args [i].data.p = params [i];
1386 case MONO_TYPE_STRING:
1387 case MONO_TYPE_CLASS:
1388 case MONO_TYPE_ARRAY:
1389 case MONO_TYPE_SZARRAY:
1390 case MONO_TYPE_OBJECT:
1391 args [i].data.p = params [i];
1394 g_error ("type 0x%x not handled in runtime invoke", sig->params [i]->type);
1398 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
1399 method = mono_marshal_get_native_wrapper (method, FALSE, FALSE);
1400 INIT_FRAME(&frame,context->current_frame,obj,args,&result,mono_get_root_domain (),method,error);
1402 frame.invoke_trap = 1;
1403 context->managed_code = 1;
1404 ves_exec_method_with_context (&frame, context);
1405 context->managed_code = 0;
1406 if (context == &context_struct)
1407 mono_native_tls_set_value (thread_context_id, NULL);
1409 context->current_frame = old_frame;
1410 if (frame.ex != NULL) {
1412 *exc = (MonoObject*) frame.ex;
1415 if (context->current_env != NULL) {
1416 context->env_frame->ex = frame.ex;
1417 longjmp(*context->current_env, 1);
1420 printf("dropped exception...\n");
1422 if (sig->ret->type == MONO_TYPE_VOID && !method->string_ctor)
1424 if (isobject || method->string_ctor)
1425 return result.data.p;
1426 stackval_to_data (sig->ret, &result, ret, sig->pinvoke);
1431 do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
1433 MonoInvocation *old_frame = context->current_frame;
1434 MonoInvocation *old_env_frame = context->env_frame;
1435 jmp_buf *old_env = context->current_env;
1439 context->current_frame = old_frame;
1440 context->env_frame = old_env_frame;
1441 context->current_env = old_env;
1442 context->managed_code = 1;
1446 context->env_frame = context->current_frame;
1447 context->current_env = &env;
1448 context->managed_code = 0;
1451 case MINT_ICALL_V_V: {
1452 void (*func)() = ptr;
1456 case MINT_ICALL_P_V: {
1457 void (*func)(gpointer) = ptr;
1458 func (sp [-1].data.p);
1462 case MINT_ICALL_P_P: {
1463 gpointer (*func)(gpointer) = ptr;
1464 sp [-1].data.p = func (sp [-1].data.p);
1467 case MINT_ICALL_PP_V: {
1468 void (*func)(gpointer,gpointer) = ptr;
1470 func (sp [0].data.p, sp [1].data.p);
1473 case MINT_ICALL_PI_V: {
1474 void (*func)(gpointer,int) = ptr;
1476 func (sp [0].data.p, sp [1].data.i);
1479 case MINT_ICALL_PP_P: {
1480 gpointer (*func)(gpointer,gpointer) = ptr;
1482 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.p);
1485 case MINT_ICALL_PI_P: {
1486 gpointer (*func)(gpointer,int) = ptr;
1488 sp [-1].data.p = func (sp [-1].data.p, sp [0].data.i);
1491 case MINT_ICALL_PPP_V: {
1492 void (*func)(gpointer,gpointer,gpointer) = ptr;
1494 func (sp [0].data.p, sp [1].data.p, sp [2].data.p);
1497 case MINT_ICALL_PPI_V: {
1498 void (*func)(gpointer,gpointer,int) = ptr;
1500 func (sp [0].data.p, sp [1].data.p, sp [2].data.i);
1504 g_assert_not_reached ();
1507 context->env_frame = old_env_frame;
1508 context->current_env = old_env;
1513 static mono_mutex_t create_method_pointer_mutex;
1515 static GHashTable *method_pointer_hash = NULL;
1518 mono_create_method_pointer (MonoMethod *method, MonoError *error)
1522 mono_error_init (error);
1524 mono_os_mutex_lock (&create_method_pointer_mutex);
1525 if (!method_pointer_hash) {
1526 // FIXME: is registering method table as GC root really necessary?
1527 // MONO_GC_REGISTER_ROOT_FIXED (method_pointer_hash);
1528 method_pointer_hash = g_hash_table_new (NULL, NULL);
1530 addr = g_hash_table_lookup (method_pointer_hash, method);
1532 mono_os_mutex_unlock (&create_method_pointer_mutex);
1537 * If it is a static P/Invoke method, we can just return the pointer
1538 * to the method implementation.
1540 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL && ((MonoMethodPInvoke*) method)->addr) {
1541 ji = g_new0 (MonoJitInfo, 1);
1542 ji->d.method = method;
1544 ji->code_start = addr = ((MonoMethodPInvoke*) method)->addr;
1546 mono_jit_info_table_add (mono_get_root_domain (), ji);
1549 g_error ("FIXME: not available? figure out new API");
1551 addr = mono_arch_create_method_pointer (method);
1555 g_hash_table_insert (method_pointer_hash, method, addr);
1556 mono_os_mutex_unlock (&create_method_pointer_mutex);
1562 static int opcode_counts[512];
1564 #define COUNT_OP(op) opcode_counts[op]++
1566 #define COUNT_OP(op)
1570 #define DUMP_INSTR() \
1571 if (tracing > 1) { \
1573 if (sp > frame->stack) { \
1574 ins = dump_stack (frame->stack, sp); \
1576 ins = g_strdup (""); \
1580 g_print ("(%u) ", mono_thread_internal_current ()); \
1581 mono_interp_dis_mintop(rtm->code, ip); \
1582 g_print ("\t%d:%s\n", vt_sp - vtalloc, ins); \
1586 #define DUMP_INSTR()
1590 #define USE_COMPUTED_GOTO 1
1592 #if USE_COMPUTED_GOTO
1593 #define MINT_IN_SWITCH(op) COUNT_OP(op); goto *in_labels[op];
1594 #define MINT_IN_CASE(x) LAB_ ## x:
1596 #define MINT_IN_BREAK if (tracing > 1) goto main_loop; else { COUNT_OP(*ip); goto *in_labels[*ip]; }
1598 #define MINT_IN_BREAK { COUNT_OP(*ip); goto *in_labels[*ip]; }
1600 #define MINT_IN_DEFAULT mint_default: if (0) goto mint_default; /* make gcc shut up */
1602 #define MINT_IN_SWITCH(op) switch (op)
1603 #define MINT_IN_CASE(x) case x:
1604 #define MINT_IN_BREAK break
1605 #define MINT_IN_DEFAULT default:
1609 * Defining this causes register allocation errors in some versions of gcc:
1610 * error: unable to find a register to spill in class `SIREG'
1612 /* #define MINT_USE_DEDICATED_IP_REG */
1615 ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
1617 MonoInvocation child_frame;
1618 GSList *finally_ips = NULL;
1619 const unsigned short *endfinally_ip = NULL;
1620 #if defined(__GNUC__) && defined (i386) && defined (MINT_USE_DEDICATED_IP_REG)
1621 register const unsigned short *ip asm ("%esi");
1623 register const unsigned short *ip;
1625 register stackval *sp;
1628 gint tracing = global_tracing;
1629 unsigned char *vtalloc;
1632 unsigned char *vt_sp;
1633 unsigned char *locals;
1635 MonoObject *o = NULL;
1637 #if USE_COMPUTED_GOTO
1638 static void *in_labels[] = {
1639 #define OPDEF(a,b,c,d) \
1641 #include "mintops.def"
1646 frame->ex_handler = NULL;
1648 context->current_frame = frame;
1651 debug_enter (frame, &tracing);
1654 if (!frame->runtime_method->transformed) {
1655 context->managed_code = 0;
1657 char *mn = mono_method_full_name (frame->runtime_method->method, FALSE);
1658 g_printerr ("(0x%08x) Transforming %s\n", mono_thread_internal_current (), mn);
1661 frame->ex = mono_interp_transform_method (frame->runtime_method, context);
1662 context->managed_code = 1;
1670 rtm = frame->runtime_method;
1671 frame->args = alloca (rtm->alloca_size);
1672 sp = frame->stack = (stackval *)((char *)frame->args + rtm->args_size);
1675 memset(sp, 0, rtm->stack_size);
1677 vt_sp = (unsigned char *) sp + rtm->stack_size;
1681 locals = (unsigned char *) vt_sp + rtm->vt_stack_size;
1683 child_frame.parent = frame;
1689 * using while (ip < end) may result in a 15% performance drop,
1690 * but it may be useful for debug
1694 /* g_assert (sp >= frame->stack); */
1695 /* g_assert(vt_sp - vtalloc <= rtm->vt_stack_size); */
1697 MINT_IN_SWITCH (*ip) {
1698 MINT_IN_CASE(MINT_INITLOCALS)
1699 memset (locals, 0, rtm->locals_size);
1702 MINT_IN_CASE(MINT_NOP)
1705 MINT_IN_CASE(MINT_BREAK)
1707 G_BREAKPOINT (); /* this is not portable... */
1709 MINT_IN_CASE(MINT_LDNULL)
1714 MINT_IN_CASE(MINT_VTRESULT) {
1715 int ret_size = * (guint16 *)(ip + 1);
1716 unsigned char *ret_vt_sp = vt_sp;
1717 vt_sp -= READ32(ip + 2);
1719 memmove (vt_sp, ret_vt_sp, ret_size);
1720 vt_sp += (ret_size + 7) & ~7;
1725 #define LDC(n) do { sp->data.i = (n); ++ip; ++sp; } while (0)
1726 MINT_IN_CASE(MINT_LDC_I4_M1)
1729 MINT_IN_CASE(MINT_LDC_I4_0)
1732 MINT_IN_CASE(MINT_LDC_I4_1)
1735 MINT_IN_CASE(MINT_LDC_I4_2)
1738 MINT_IN_CASE(MINT_LDC_I4_3)
1741 MINT_IN_CASE(MINT_LDC_I4_4)
1744 MINT_IN_CASE(MINT_LDC_I4_5)
1747 MINT_IN_CASE(MINT_LDC_I4_6)
1750 MINT_IN_CASE(MINT_LDC_I4_7)
1753 MINT_IN_CASE(MINT_LDC_I4_8)
1756 MINT_IN_CASE(MINT_LDC_I4_S)
1757 sp->data.i = *(const short *)(ip + 1);
1761 MINT_IN_CASE(MINT_LDC_I4)
1763 sp->data.i = READ32 (ip);
1767 MINT_IN_CASE(MINT_LDC_I8)
1769 sp->data.l = READ64 (ip);
1773 MINT_IN_CASE(MINT_LDC_R4) {
1777 sp->data.f = * (float *)&val;
1782 MINT_IN_CASE(MINT_LDC_R8)
1783 sp->data.l = READ64 (ip + 1); /* note union usage */
1787 MINT_IN_CASE(MINT_DUP)
1792 MINT_IN_CASE(MINT_DUP_VT)
1793 i32 = READ32 (ip + 1);
1795 memcpy(sp->data.p, sp [-1].data.p, i32);
1796 vt_sp += (i32 + 7) & ~7;
1800 MINT_IN_CASE(MINT_POP)
1804 MINT_IN_CASE(MINT_JMP) {
1805 RuntimeMethod *new_method = rtm->data_items [* (guint16 *)(ip + 1)];
1806 if (!new_method->transformed) {
1808 frame->ex = mono_interp_transform_method (new_method, context);
1813 if (new_method->alloca_size > rtm->alloca_size)
1814 g_error ("MINT_JMP to method which needs more stack space (%d > %d)", new_method->alloca_size, rtm->alloca_size);
1815 rtm = frame->runtime_method = new_method;
1816 vt_sp = (unsigned char *) sp + rtm->stack_size;
1820 locals = vt_sp + rtm->vt_stack_size;
1821 ip = rtm->new_body_start; /* bypass storing input args from callers frame */
1824 MINT_IN_CASE(MINT_CALLI) {
1825 MonoMethodSignature *csignature;
1826 stackval *endsp = sp;
1830 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1834 child_frame.runtime_method = sp->data.p;
1837 child_frame.retval = sp;
1838 /* decrement by the actual number of args */
1839 sp -= csignature->param_count;
1840 child_frame.stack_args = sp;
1841 if (csignature->hasthis) {
1843 child_frame.obj = sp->data.p;
1845 child_frame.obj = NULL;
1847 if (csignature->hasthis && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1848 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1849 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1850 } else if (child_frame.runtime_method->method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL) {
1851 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_native_wrapper (child_frame.runtime_method->method, FALSE, FALSE), &error);
1852 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1855 ves_exec_method_with_context (&child_frame, context);
1857 context->current_frame = frame;
1859 if (child_frame.ex) {
1861 * An exception occurred, need to run finally, fault and catch handlers..
1863 frame->ex = child_frame.ex;
1864 goto handle_finally;
1867 /* need to handle typedbyref ... */
1868 if (csignature->ret->type != MONO_TYPE_VOID) {
1874 MINT_IN_CASE(MINT_CALLI_NAT) {
1875 MonoMethodSignature *csignature;
1876 stackval *endsp = sp;
1877 unsigned char *code = NULL;
1881 csignature = rtm->data_items [* (guint16 *)(ip + 1)];
1886 child_frame.runtime_method = NULL;
1889 child_frame.retval = sp;
1890 /* decrement by the actual number of args */
1891 sp -= csignature->param_count;
1892 child_frame.stack_args = sp;
1893 if (csignature->hasthis) {
1895 child_frame.obj = sp->data.p;
1897 child_frame.obj = NULL;
1899 ves_pinvoke_method (&child_frame, csignature, (MonoFuncV) code, FALSE, context);
1901 context->current_frame = frame;
1903 if (child_frame.ex) {
1905 * An exception occurred, need to run finally, fault and catch handlers..
1907 frame->ex = child_frame.ex;
1908 if (context->search_for_handler) {
1909 context->search_for_handler = 0;
1910 goto handle_exception;
1912 goto handle_finally;
1915 /* need to handle typedbyref ... */
1916 if (csignature->ret->type != MONO_TYPE_VOID) {
1922 MINT_IN_CASE(MINT_CALL) {
1923 stackval *endsp = sp;
1927 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1930 child_frame.retval = sp;
1931 /* decrement by the actual number of args */
1932 sp -= child_frame.runtime_method->param_count;
1933 child_frame.stack_args = sp;
1934 if (child_frame.runtime_method->hasthis) {
1936 child_frame.obj = sp->data.p;
1938 child_frame.obj = NULL;
1940 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1941 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1942 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1944 ves_exec_method_with_context (&child_frame, context);
1946 context->current_frame = frame;
1948 if (child_frame.ex) {
1950 * An exception occurred, need to run finally, fault and catch handlers..
1952 frame->ex = child_frame.ex;
1953 goto handle_finally;
1956 /* need to handle typedbyref ... */
1961 MINT_IN_CASE(MINT_VCALL) {
1964 child_frame.runtime_method = rtm->data_items [* (guint16 *)(ip + 1)];
1968 child_frame.retval = sp;
1969 /* decrement by the actual number of args */
1970 sp -= child_frame.runtime_method->param_count;
1971 child_frame.stack_args = sp;
1972 if (child_frame.runtime_method->hasthis) {
1974 child_frame.obj = sp->data.p;
1976 child_frame.obj = NULL;
1979 if (child_frame.runtime_method->hasthis && !child_frame.runtime_method->valuetype && ((MonoObject *)child_frame.obj)->vtable->klass == mono_defaults.transparent_proxy_class) {
1980 child_frame.runtime_method = mono_interp_get_runtime_method (context->domain, mono_marshal_get_remoting_invoke (child_frame.runtime_method->method), &error);
1981 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
1984 ves_exec_method_with_context (&child_frame, context);
1986 context->current_frame = frame;
1988 if (child_frame.ex) {
1990 * An exception occurred, need to run finally, fault and catch handlers..
1992 frame->ex = child_frame.ex;
1993 goto handle_finally;
1997 MINT_IN_CASE(MINT_CALLVIRT) {
1998 stackval *endsp = sp;
1999 MonoObject *this_arg;
2004 token = * (unsigned short *)(ip + 1);
2006 child_frame.runtime_method = rtm->data_items [token];
2008 child_frame.retval = sp;
2010 /* decrement by the actual number of args */
2011 sp -= child_frame.runtime_method->param_count;
2012 child_frame.stack_args = sp;
2014 child_frame.obj = this_arg = sp->data.p;
2016 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2017 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2019 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2020 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2023 ves_exec_method_with_context (&child_frame, context);
2025 context->current_frame = frame;
2027 if (child_frame.ex) {
2029 * An exception occurred, need to run finally, fault and catch handlers..
2031 frame->ex = child_frame.ex;
2032 if (context->search_for_handler) {
2033 context->search_for_handler = 0;
2034 goto handle_exception;
2036 goto handle_finally;
2039 /* need to handle typedbyref ... */
2044 MINT_IN_CASE(MINT_VCALLVIRT) {
2045 MonoObject *this_arg;
2050 token = * (unsigned short *)(ip + 1);
2052 child_frame.runtime_method = rtm->data_items [token];
2054 child_frame.retval = sp;
2056 /* decrement by the actual number of args */
2057 sp -= child_frame.runtime_method->param_count;
2058 child_frame.stack_args = sp;
2060 child_frame.obj = this_arg = sp->data.p;
2062 THROW_EX (mono_get_exception_null_reference(), ip - 2);
2063 child_frame.runtime_method = get_virtual_method (context->domain, child_frame.runtime_method, this_arg);
2065 if (this_arg->vtable->klass->valuetype && child_frame.runtime_method->valuetype) {
2066 child_frame.obj = (char *)this_arg + sizeof(MonoObject);
2069 ves_exec_method_with_context (&child_frame, context);
2071 context->current_frame = frame;
2073 if (child_frame.ex) {
2075 * An exception occurred, need to run finally, fault and catch handlers..
2077 frame->ex = child_frame.ex;
2078 if (context->search_for_handler) {
2079 context->search_for_handler = 0;
2080 goto handle_exception;
2082 goto handle_finally;
2086 MINT_IN_CASE(MINT_CALLINT)
2087 g_printerr ("doing MINT_CALLINT: %p\n", ((MonoMethodPInvoke*) frame->runtime_method->method)->addr);
2088 ves_pinvoke_method (frame, mono_method_signature (frame->runtime_method->method), ((MonoMethodPInvoke*) frame->runtime_method->method)->addr,
2089 frame->runtime_method->method->string_ctor, context);
2092 goto handle_exception;
2095 MINT_IN_CASE(MINT_CALLRUN)
2096 ves_runtime_method (frame, context);
2099 goto handle_exception;
2102 MINT_IN_CASE(MINT_RET)
2104 *frame->retval = *sp;
2105 if (sp > frame->stack)
2106 g_warning ("ret: more values on stack: %d", sp-frame->stack);
2108 MINT_IN_CASE(MINT_RET_VOID)
2109 if (sp > frame->stack)
2110 g_warning ("ret.void: more values on stack: %d", sp-frame->stack);
2112 MINT_IN_CASE(MINT_RET_VT)
2113 i32 = READ32(ip + 1);
2115 memcpy(frame->retval->data.p, sp->data.p, i32);
2116 if (sp > frame->stack)
2117 g_warning ("ret.vt: more values on stack: %d", sp-frame->stack);
2119 MINT_IN_CASE(MINT_BR_S)
2120 ip += (short) *(ip + 1);
2122 MINT_IN_CASE(MINT_BR)
2123 ip += (gint32) READ32(ip + 1);
2125 #define ZEROP_S(datamem, op) \
2127 if (sp->data.datamem op 0) \
2128 ip += * (gint16 *)(ip + 1); \
2132 #define ZEROP(datamem, op) \
2134 if (sp->data.datamem op 0) \
2135 ip += READ32(ip + 1); \
2139 MINT_IN_CASE(MINT_BRFALSE_I4_S)
2142 MINT_IN_CASE(MINT_BRFALSE_I8_S)
2145 MINT_IN_CASE(MINT_BRFALSE_R8_S)
2148 MINT_IN_CASE(MINT_BRFALSE_I4)
2151 MINT_IN_CASE(MINT_BRFALSE_I8)
2154 MINT_IN_CASE(MINT_BRFALSE_R8)
2157 MINT_IN_CASE(MINT_BRTRUE_I4_S)
2160 MINT_IN_CASE(MINT_BRTRUE_I8_S)
2163 MINT_IN_CASE(MINT_BRTRUE_R8_S)
2166 MINT_IN_CASE(MINT_BRTRUE_I4)
2169 MINT_IN_CASE(MINT_BRTRUE_I8)
2172 MINT_IN_CASE(MINT_BRTRUE_R8)
2175 #define CONDBR_S(cond) \
2178 ip += * (gint16 *)(ip + 1); \
2181 #define BRELOP_S(datamem, op) \
2182 CONDBR_S(sp[0].data.datamem op sp[1].data.datamem)
2184 #define CONDBR(cond) \
2187 ip += READ32(ip + 1); \
2191 #define BRELOP(datamem, op) \
2192 CONDBR(sp[0].data.datamem op sp[1].data.datamem)
2194 MINT_IN_CASE(MINT_BEQ_I4_S)
2197 MINT_IN_CASE(MINT_BEQ_I8_S)
2200 MINT_IN_CASE(MINT_BEQ_R8_S)
2201 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2203 MINT_IN_CASE(MINT_BEQ_I4)
2206 MINT_IN_CASE(MINT_BEQ_I8)
2209 MINT_IN_CASE(MINT_BEQ_R8)
2210 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f == sp[1].data.f)
2212 MINT_IN_CASE(MINT_BGE_I4_S)
2215 MINT_IN_CASE(MINT_BGE_I8_S)
2218 MINT_IN_CASE(MINT_BGE_R8_S)
2219 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2221 MINT_IN_CASE(MINT_BGE_I4)
2224 MINT_IN_CASE(MINT_BGE_I8)
2227 MINT_IN_CASE(MINT_BGE_R8)
2228 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f >= sp[1].data.f)
2230 MINT_IN_CASE(MINT_BGT_I4_S)
2233 MINT_IN_CASE(MINT_BGT_I8_S)
2236 MINT_IN_CASE(MINT_BGT_R8_S)
2237 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2239 MINT_IN_CASE(MINT_BGT_I4)
2242 MINT_IN_CASE(MINT_BGT_I8)
2245 MINT_IN_CASE(MINT_BGT_R8)
2246 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f > sp[1].data.f)
2248 MINT_IN_CASE(MINT_BLT_I4_S)
2251 MINT_IN_CASE(MINT_BLT_I8_S)
2254 MINT_IN_CASE(MINT_BLT_R8_S)
2255 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2257 MINT_IN_CASE(MINT_BLT_I4)
2260 MINT_IN_CASE(MINT_BLT_I8)
2263 MINT_IN_CASE(MINT_BLT_R8)
2264 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f < sp[1].data.f)
2266 MINT_IN_CASE(MINT_BLE_I4_S)
2269 MINT_IN_CASE(MINT_BLE_I8_S)
2272 MINT_IN_CASE(MINT_BLE_R8_S)
2273 CONDBR_S(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2275 MINT_IN_CASE(MINT_BLE_I4)
2278 MINT_IN_CASE(MINT_BLE_I8)
2281 MINT_IN_CASE(MINT_BLE_R8)
2282 CONDBR(!isunordered (sp [0].data.f, sp [1].data.f) && sp[0].data.f <= sp[1].data.f)
2284 MINT_IN_CASE(MINT_BNE_UN_I4_S)
2287 MINT_IN_CASE(MINT_BNE_UN_I8_S)
2290 MINT_IN_CASE(MINT_BNE_UN_R8_S)
2291 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2293 MINT_IN_CASE(MINT_BNE_UN_I4)
2296 MINT_IN_CASE(MINT_BNE_UN_I8)
2299 MINT_IN_CASE(MINT_BNE_UN_R8)
2300 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f != sp[1].data.f)
2303 #define BRELOP_S_CAST(datamem, op, type) \
2305 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2306 ip += * (gint16 *)(ip + 1); \
2310 #define BRELOP_CAST(datamem, op, type) \
2312 if ((type) sp[0].data.datamem op (type) sp[1].data.datamem) \
2313 ip += READ32(ip + 1); \
2317 MINT_IN_CASE(MINT_BGE_UN_I4_S)
2318 BRELOP_S_CAST(i, >=, guint32);
2320 MINT_IN_CASE(MINT_BGE_UN_I8_S)
2321 BRELOP_S_CAST(l, >=, guint64);
2323 MINT_IN_CASE(MINT_BGE_UN_R8_S)
2324 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2326 MINT_IN_CASE(MINT_BGE_UN_I4)
2327 BRELOP_CAST(i, >=, guint32);
2329 MINT_IN_CASE(MINT_BGE_UN_I8)
2330 BRELOP_CAST(l, >=, guint64);
2332 MINT_IN_CASE(MINT_BGE_UN_R8)
2333 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f >= sp[1].data.f)
2335 MINT_IN_CASE(MINT_BGT_UN_I4_S)
2336 BRELOP_S_CAST(i, >, guint32);
2338 MINT_IN_CASE(MINT_BGT_UN_I8_S)
2339 BRELOP_S_CAST(l, >, guint64);
2341 MINT_IN_CASE(MINT_BGT_UN_R8_S)
2342 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2344 MINT_IN_CASE(MINT_BGT_UN_I4)
2345 BRELOP_CAST(i, >, guint32);
2347 MINT_IN_CASE(MINT_BGT_UN_I8)
2348 BRELOP_CAST(l, >, guint64);
2350 MINT_IN_CASE(MINT_BGT_UN_R8)
2351 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f > sp[1].data.f)
2353 MINT_IN_CASE(MINT_BLE_UN_I4_S)
2354 BRELOP_S_CAST(i, <=, guint32);
2356 MINT_IN_CASE(MINT_BLE_UN_I8_S)
2357 BRELOP_S_CAST(l, <=, guint64);
2359 MINT_IN_CASE(MINT_BLE_UN_R8_S)
2360 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2362 MINT_IN_CASE(MINT_BLE_UN_I4)
2363 BRELOP_CAST(i, <=, guint32);
2365 MINT_IN_CASE(MINT_BLE_UN_I8)
2366 BRELOP_CAST(l, <=, guint64);
2368 MINT_IN_CASE(MINT_BLE_UN_R8)
2369 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f <= sp[1].data.f)
2371 MINT_IN_CASE(MINT_BLT_UN_I4_S)
2372 BRELOP_S_CAST(i, <, guint32);
2374 MINT_IN_CASE(MINT_BLT_UN_I8_S)
2375 BRELOP_S_CAST(l, <, guint64);
2377 MINT_IN_CASE(MINT_BLT_UN_R8_S)
2378 CONDBR_S(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2380 MINT_IN_CASE(MINT_BLT_UN_I4)
2381 BRELOP_CAST(i, <, guint32);
2383 MINT_IN_CASE(MINT_BLT_UN_I8)
2384 BRELOP_CAST(l, <, guint64);
2386 MINT_IN_CASE(MINT_BLT_UN_R8)
2387 CONDBR(isunordered (sp [0].data.f, sp [1].data.f) || sp[0].data.f < sp[1].data.f)
2389 MINT_IN_CASE(MINT_SWITCH) {
2391 const unsigned short *st;
2397 if ((guint32)sp->data.i < n) {
2399 ip += 2 * (guint32)sp->data.i;
2400 offset = READ32 (ip);
2407 MINT_IN_CASE(MINT_LDIND_I1)
2409 sp[-1].data.i = *(gint8*)sp[-1].data.p;
2411 MINT_IN_CASE(MINT_LDIND_U1)
2413 sp[-1].data.i = *(guint8*)sp[-1].data.p;
2415 MINT_IN_CASE(MINT_LDIND_I2)
2417 sp[-1].data.i = *(gint16*)sp[-1].data.p;
2419 MINT_IN_CASE(MINT_LDIND_U2)
2421 sp[-1].data.i = *(guint16*)sp[-1].data.p;
2423 MINT_IN_CASE(MINT_LDIND_I4) /* Fall through */
2424 MINT_IN_CASE(MINT_LDIND_U4)
2426 sp[-1].data.i = *(gint32*)sp[-1].data.p;
2428 MINT_IN_CASE(MINT_LDIND_I8)
2430 sp[-1].data.l = *(gint64*)sp[-1].data.p;
2432 MINT_IN_CASE(MINT_LDIND_I)
2434 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2436 MINT_IN_CASE(MINT_LDIND_R4)
2438 sp[-1].data.f = *(gfloat*)sp[-1].data.p;
2440 MINT_IN_CASE(MINT_LDIND_R8)
2442 sp[-1].data.f = *(gdouble*)sp[-1].data.p;
2444 MINT_IN_CASE(MINT_LDIND_REF)
2446 sp[-1].data.p = *(gpointer*)sp[-1].data.p;
2448 MINT_IN_CASE(MINT_STIND_REF)
2451 * (gpointer *) sp->data.p = sp[1].data.p;
2453 MINT_IN_CASE(MINT_STIND_I1)
2456 * (gint8 *) sp->data.p = (gint8)sp[1].data.i;
2458 MINT_IN_CASE(MINT_STIND_I2)
2461 * (gint16 *) sp->data.p = (gint16)sp[1].data.i;
2463 MINT_IN_CASE(MINT_STIND_I4)
2466 * (gint32 *) sp->data.p = sp[1].data.i;
2468 MINT_IN_CASE(MINT_STIND_I)
2471 * (mono_i *) sp->data.p = (mono_i)sp[1].data.p;
2473 MINT_IN_CASE(MINT_STIND_I8)
2476 * (gint64 *) sp->data.p = sp[1].data.l;
2478 MINT_IN_CASE(MINT_STIND_R4)
2481 * (float *) sp->data.p = (gfloat)sp[1].data.f;
2483 MINT_IN_CASE(MINT_STIND_R8)
2486 * (double *) sp->data.p = sp[1].data.f;
2488 #define BINOP(datamem, op) \
2490 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.datamem; \
2492 MINT_IN_CASE(MINT_ADD_I4)
2495 MINT_IN_CASE(MINT_ADD_I8)
2498 MINT_IN_CASE(MINT_ADD_R8)
2501 MINT_IN_CASE(MINT_ADD1_I4)
2505 MINT_IN_CASE(MINT_SUB_I4)
2508 MINT_IN_CASE(MINT_SUB_I8)
2511 MINT_IN_CASE(MINT_SUB_R8)
2514 MINT_IN_CASE(MINT_SUB1_I4)
2518 MINT_IN_CASE(MINT_MUL_I4)
2521 MINT_IN_CASE(MINT_MUL_I8)
2524 MINT_IN_CASE(MINT_MUL_R8)
2527 MINT_IN_CASE(MINT_DIV_I4)
2528 if (sp [-1].data.i == 0)
2529 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2530 if (sp [-1].data.i == (-1))
2531 THROW_EX (mono_get_exception_overflow (), ip);
2534 MINT_IN_CASE(MINT_DIV_I8)
2535 if (sp [-1].data.l == 0)
2536 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2537 if (sp [-1].data.l == (-1))
2538 THROW_EX (mono_get_exception_overflow (), ip);
2541 MINT_IN_CASE(MINT_DIV_R8)
2545 #define BINOP_CAST(datamem, op, type) \
2547 sp [-1].data.datamem = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
2549 MINT_IN_CASE(MINT_DIV_UN_I4)
2550 if (sp [-1].data.i == 0)
2551 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2552 BINOP_CAST(i, /, guint32);
2554 MINT_IN_CASE(MINT_DIV_UN_I8)
2555 if (sp [-1].data.l == 0)
2556 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2557 BINOP_CAST(l, /, guint64);
2559 MINT_IN_CASE(MINT_REM_I4)
2560 if (sp [-1].data.i == 0)
2561 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2564 MINT_IN_CASE(MINT_REM_I8)
2565 if (sp [-1].data.l == 0)
2566 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2569 MINT_IN_CASE(MINT_REM_R8)
2570 /* FIXME: what do we actually do here? */
2572 sp [-1].data.f = fmod (sp [-1].data.f, sp [0].data.f);
2575 MINT_IN_CASE(MINT_REM_UN_I4)
2576 if (sp [-1].data.i == 0)
2577 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2578 BINOP_CAST(i, %, guint32);
2580 MINT_IN_CASE(MINT_REM_UN_I8)
2581 if (sp [-1].data.l == 0)
2582 THROW_EX (mono_get_exception_divide_by_zero (), ip);
2583 BINOP_CAST(l, %, guint64);
2585 MINT_IN_CASE(MINT_AND_I4)
2588 MINT_IN_CASE(MINT_AND_I8)
2591 MINT_IN_CASE(MINT_OR_I4)
2594 MINT_IN_CASE(MINT_OR_I8)
2597 MINT_IN_CASE(MINT_XOR_I4)
2600 MINT_IN_CASE(MINT_XOR_I8)
2604 #define SHIFTOP(datamem, op) \
2606 sp [-1].data.datamem = sp [-1].data.datamem op sp [0].data.i; \
2609 MINT_IN_CASE(MINT_SHL_I4)
2612 MINT_IN_CASE(MINT_SHL_I8)
2615 MINT_IN_CASE(MINT_SHR_I4)
2618 MINT_IN_CASE(MINT_SHR_I8)
2621 MINT_IN_CASE(MINT_SHR_UN_I4)
2623 sp [-1].data.i = (guint32)sp [-1].data.i >> sp [0].data.i;
2626 MINT_IN_CASE(MINT_SHR_UN_I8)
2628 sp [-1].data.l = (guint64)sp [-1].data.l >> sp [0].data.i;
2631 MINT_IN_CASE(MINT_NEG_I4)
2632 sp [-1].data.i = - sp [-1].data.i;
2635 MINT_IN_CASE(MINT_NEG_I8)
2636 sp [-1].data.l = - sp [-1].data.l;
2639 MINT_IN_CASE(MINT_NEG_R8)
2640 sp [-1].data.f = - sp [-1].data.f;
2643 MINT_IN_CASE(MINT_NOT_I4)
2644 sp [-1].data.i = ~ sp [-1].data.i;
2647 MINT_IN_CASE(MINT_NOT_I8)
2648 sp [-1].data.l = ~ sp [-1].data.l;
2651 MINT_IN_CASE(MINT_CONV_I1_I4)
2652 sp [-1].data.i = (gint8)sp [-1].data.i;
2655 MINT_IN_CASE(MINT_CONV_I1_I8)
2656 sp [-1].data.i = (gint8)sp [-1].data.l;
2659 MINT_IN_CASE(MINT_CONV_I1_R8)
2660 sp [-1].data.i = (gint8)sp [-1].data.f;
2663 MINT_IN_CASE(MINT_CONV_U1_I4)
2664 sp [-1].data.i = (guint8)sp [-1].data.i;
2667 MINT_IN_CASE(MINT_CONV_U1_I8)
2668 sp [-1].data.i = (guint8)sp [-1].data.l;
2671 MINT_IN_CASE(MINT_CONV_U1_R8)
2672 sp [-1].data.i = (guint8)sp [-1].data.f;
2675 MINT_IN_CASE(MINT_CONV_I2_I4)
2676 sp [-1].data.i = (gint16)sp [-1].data.i;
2679 MINT_IN_CASE(MINT_CONV_I2_I8)
2680 sp [-1].data.i = (gint16)sp [-1].data.l;
2683 MINT_IN_CASE(MINT_CONV_I2_R8)
2684 sp [-1].data.i = (gint16)sp [-1].data.f;
2687 MINT_IN_CASE(MINT_CONV_U2_I4)
2688 sp [-1].data.i = (guint16)sp [-1].data.i;
2691 MINT_IN_CASE(MINT_CONV_U2_I8)
2692 sp [-1].data.i = (guint16)sp [-1].data.l;
2695 MINT_IN_CASE(MINT_CONV_U2_R8)
2696 sp [-1].data.i = (guint16)sp [-1].data.f;
2699 MINT_IN_CASE(MINT_CONV_I4_R8)
2700 sp [-1].data.i = (gint32)sp [-1].data.f;
2703 MINT_IN_CASE(MINT_CONV_U4_I8)
2704 MINT_IN_CASE(MINT_CONV_I4_I8)
2705 sp [-1].data.i = (gint32)sp [-1].data.l;
2708 MINT_IN_CASE(MINT_CONV_I4_I8_SP)
2709 sp [-2].data.i = (gint32)sp [-2].data.l;
2712 MINT_IN_CASE(MINT_CONV_U4_R8)
2713 sp [-1].data.i = (guint32)sp [-1].data.f;
2716 MINT_IN_CASE(MINT_CONV_I8_I4)
2717 sp [-1].data.l = sp [-1].data.i;
2720 MINT_IN_CASE(MINT_CONV_I8_I4_SP)
2721 sp [-2].data.l = sp [-2].data.i;
2724 MINT_IN_CASE(MINT_CONV_I8_U4)
2725 sp [-1].data.l = (guint32)sp [-1].data.i;
2728 MINT_IN_CASE(MINT_CONV_I8_R8)
2729 sp [-1].data.l = (gint64)sp [-1].data.f;
2732 MINT_IN_CASE(MINT_CONV_R4_I4)
2733 sp [-1].data.f = (float)sp [-1].data.i;
2736 MINT_IN_CASE(MINT_CONV_R4_I8)
2737 sp [-1].data.f = (float)sp [-1].data.l;
2740 MINT_IN_CASE(MINT_CONV_R4_R8)
2741 sp [-1].data.f = (float)sp [-1].data.f;
2744 MINT_IN_CASE(MINT_CONV_R8_I4)
2745 sp [-1].data.f = (double)sp [-1].data.i;
2748 MINT_IN_CASE(MINT_CONV_R8_I8)
2749 sp [-1].data.f = (double)sp [-1].data.l;
2752 MINT_IN_CASE(MINT_CONV_U8_I4)
2753 sp [-1].data.l = sp [-1].data.i & 0xffffffff;
2756 MINT_IN_CASE(MINT_CONV_U8_R8)
2757 sp [-1].data.l = (guint64)sp [-1].data.f;
2761 MINT_IN_CASE(MINT_CPOBJ) {
2764 vtklass = rtm->data_items[READ32 (ip)];
2767 memcpy (sp [0].data.p, sp [1].data.p, mono_class_value_size (vtklass, NULL));
2771 MINT_IN_CASE(MINT_LDOBJ) {
2774 c = rtm->data_items[* (guint16 *)(ip + 1)];
2776 if (c->byval_arg.type != MONO_TYPE_VALUETYPE || c->byval_arg.data.klass->enumtype) {
2778 stackval_from_data (&c->byval_arg, &sp [-1], p, FALSE);
2780 size = mono_class_value_size (c, NULL);
2782 sp [-1].data.p = vt_sp;
2783 memcpy(vt_sp, p, size);
2784 vt_sp += (size + 7) & ~7;
2788 MINT_IN_CASE(MINT_LDSTR)
2789 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
2793 MINT_IN_CASE(MINT_NEWOBJ) {
2794 MonoClass *newobj_class;
2795 MonoMethodSignature *csig;
2796 stackval valuetype_this;
2802 token = * (guint16 *)(ip + 1);
2805 child_frame.runtime_method = rtm->data_items [token];
2806 csig = mono_method_signature (child_frame.runtime_method->method);
2807 newobj_class = child_frame.runtime_method->method->klass;
2808 /*if (profiling_classes) {
2809 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
2811 g_hash_table_insert (profiling_classes, newobj_class, GUINT_TO_POINTER (count));
2815 if (newobj_class->parent == mono_defaults.array_class) {
2816 sp -= csig->param_count;
2817 o = ves_array_create (context->domain, newobj_class, csig, sp);
2818 goto array_constructed;
2822 * First arg is the object.
2824 if (newobj_class->valuetype) {
2825 if (!newobj_class->enumtype && (newobj_class->byval_arg.type == MONO_TYPE_VALUETYPE)) {
2826 child_frame.obj = vt_sp;
2827 valuetype_this.data.p = vt_sp;
2829 memset (&valuetype_this, 0, sizeof (stackval));
2830 child_frame.obj = &valuetype_this;
2833 if (newobj_class != mono_defaults.string_class) {
2834 context->managed_code = 0;
2835 o = mono_object_new_checked (context->domain, newobj_class, &error);
2836 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2837 context->managed_code = 1;
2838 if (*abort_requested)
2839 mono_thread_interruption_checkpoint ();
2840 child_frame.obj = o;
2842 child_frame.retval = &retval;
2846 if (csig->param_count) {
2847 sp -= csig->param_count;
2848 child_frame.stack_args = sp;
2850 child_frame.stack_args = NULL;
2853 g_assert (csig->call_convention == MONO_CALL_DEFAULT);
2855 child_frame.ip = NULL;
2856 child_frame.ex = NULL;
2858 ves_exec_method_with_context (&child_frame, context);
2860 context->current_frame = frame;
2862 if (child_frame.ex) {
2864 * An exception occurred, need to run finally, fault and catch handlers..
2866 frame->ex = child_frame.ex;
2867 goto handle_finally;
2870 * a constructor returns void, but we need to return the object we created
2873 if (newobj_class->valuetype && !newobj_class->enumtype) {
2874 *sp = valuetype_this;
2875 } else if (newobj_class == mono_defaults.string_class) {
2883 MINT_IN_CASE(MINT_CASTCLASS)
2884 c = rtm->data_items [*(guint16 *)(ip + 1)];
2885 if ((o = sp [-1].data.p)) {
2886 if (c->marshalbyref) {
2887 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2888 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2890 THROW_EX (mono_get_exception_invalid_cast (), ip);
2892 MonoVTable *vt = o->vtable;
2893 MonoClass *oklass = vt->klass;
2894 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2895 g_error ("FIXME: interface method lookup");
2896 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2897 THROW_EX (mono_get_exception_invalid_cast (), ip);
2899 } else if (c->rank) {
2900 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2901 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2903 THROW_EX (mono_get_exception_invalid_cast (), ip);
2904 } else if (!mono_class_has_parent (oklass, c)) {
2905 THROW_EX (mono_get_exception_invalid_cast (), ip);
2911 MINT_IN_CASE(MINT_ISINST)
2912 c = rtm->data_items [*(guint16 *)(ip + 1)];
2913 if ((o = sp [-1].data.p)) {
2914 if (c->marshalbyref) {
2915 MonoObject *isinst_obj = mono_object_isinst_mbyref_checked (o, c, &error);
2916 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2918 sp [-1].data.p = NULL;
2920 MonoVTable *vt = o->vtable;
2921 MonoClass *oklass = vt->klass;
2922 if (c->flags & TYPE_ATTRIBUTE_INTERFACE) {
2923 g_error ("FIXME: interface method lookup");
2924 if (c->interface_id > vt->max_interface_id /* || vt->interface_offsets [c->interface_id] == 0 */) {
2925 sp [-1].data.p = NULL;
2927 } else if (c->rank) {
2928 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2929 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2931 sp [-1].data.p = NULL;
2932 } else if (!mono_class_has_parent (oklass, c)) {
2933 sp [-1].data.p = NULL;
2939 MINT_IN_CASE(MINT_CONV_R_UN_I4)
2940 sp [-1].data.f = (double)(guint32)sp [-1].data.i;
2943 MINT_IN_CASE(MINT_CONV_R_UN_I8)
2944 sp [-1].data.f = (double)(guint64)sp [-1].data.l;
2947 MINT_IN_CASE(MINT_UNBOX)
2948 c = rtm->data_items[*(guint16 *)(ip + 1)];
2952 THROW_EX (mono_get_exception_null_reference (), ip);
2954 MonoObject *isinst_obj = mono_object_isinst_checked (o, c, &error);
2955 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
2956 if (!(isinst_obj || ((o->vtable->klass->rank == 0) && (o->vtable->klass->element_class == c->element_class))))
2957 THROW_EX (mono_get_exception_invalid_cast (), ip);
2959 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
2960 g_error ("unbox: implement vt");
2962 stackval_from_data (&c->byval_arg, &sp [-1], mono_object_unbox (o), FALSE);
2966 MINT_IN_CASE(MINT_THROW)
2968 frame->ex_handler = NULL;
2970 sp->data.p = mono_get_exception_null_reference ();
2971 THROW_EX ((MonoException *)sp->data.p, ip);
2973 MINT_IN_CASE(MINT_LDFLDA)
2976 THROW_EX (mono_get_exception_null_reference (), ip);
2977 sp[-1].data.p = (char *)o + * (guint16 *)(ip + 1);
2980 MINT_IN_CASE(MINT_CKNULL)
2983 THROW_EX (mono_get_exception_null_reference (), ip);
2987 #define LDFLD(datamem, fieldtype) \
2988 o = sp [-1].data.p; \
2990 THROW_EX (mono_get_exception_null_reference (), ip); \
2991 sp[-1].data.datamem = * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) ; \
2994 MINT_IN_CASE(MINT_LDFLD_I1) LDFLD(i, gint8); MINT_IN_BREAK;
2995 MINT_IN_CASE(MINT_LDFLD_U1) LDFLD(i, guint8); MINT_IN_BREAK;
2996 MINT_IN_CASE(MINT_LDFLD_I2) LDFLD(i, gint16); MINT_IN_BREAK;
2997 MINT_IN_CASE(MINT_LDFLD_U2) LDFLD(i, guint16); MINT_IN_BREAK;
2998 MINT_IN_CASE(MINT_LDFLD_I4) LDFLD(i, gint32); MINT_IN_BREAK;
2999 MINT_IN_CASE(MINT_LDFLD_I8) LDFLD(l, gint64); MINT_IN_BREAK;
3000 MINT_IN_CASE(MINT_LDFLD_R4) LDFLD(f, float); MINT_IN_BREAK;
3001 MINT_IN_CASE(MINT_LDFLD_R8) LDFLD(f, double); MINT_IN_BREAK;
3002 MINT_IN_CASE(MINT_LDFLD_O) LDFLD(p, gpointer); MINT_IN_BREAK;
3003 MINT_IN_CASE(MINT_LDFLD_P) LDFLD(p, gpointer); MINT_IN_BREAK;
3005 MINT_IN_CASE(MINT_LDFLD_VT)
3008 THROW_EX (mono_get_exception_null_reference (), ip);
3009 i32 = READ32(ip + 2);
3010 sp [-1].data.p = vt_sp;
3011 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3012 vt_sp += (i32 + 7) & ~7;
3016 MINT_IN_CASE(MINT_LDRMFLD) {
3018 MonoClassField *field;
3023 THROW_EX (mono_get_exception_null_reference (), ip);
3024 field = rtm->data_items[* (guint16 *)(ip + 1)];
3026 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3027 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3029 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3030 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3032 addr = (char*)o + field->offset;
3035 stackval_from_data (field->type, &sp [-1], addr, FALSE);
3039 MINT_IN_CASE(MINT_LDRMFLD_VT) {
3040 MonoClassField *field;
3046 THROW_EX (mono_get_exception_null_reference (), ip);
3047 field = rtm->data_items[* (guint16 *)(ip + 1)];
3048 i32 = READ32(ip + 2);
3050 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3051 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3052 addr = mono_load_remote_field_checked (o, klass, field, &tmp, &error);
3053 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3055 addr = (char*)o + field->offset;
3058 sp [-1].data.p = vt_sp;
3059 memcpy(sp [-1].data.p, (char *)o + * (guint16 *)(ip + 1), i32);
3060 vt_sp += (i32 + 7) & ~7;
3061 memcpy(sp [-1].data.p, addr, i32);
3065 #define STFLD(datamem, fieldtype) \
3066 o = sp [-2].data.p; \
3068 THROW_EX (mono_get_exception_null_reference (), ip); \
3070 * (fieldtype *)((char *)o + * (guint16 *)(ip + 1)) = sp[1].data.datamem; \
3073 MINT_IN_CASE(MINT_STFLD_I1) STFLD(i, gint8); MINT_IN_BREAK;
3074 MINT_IN_CASE(MINT_STFLD_U1) STFLD(i, guint8); MINT_IN_BREAK;
3075 MINT_IN_CASE(MINT_STFLD_I2) STFLD(i, gint16); MINT_IN_BREAK;
3076 MINT_IN_CASE(MINT_STFLD_U2) STFLD(i, guint16); MINT_IN_BREAK;
3077 MINT_IN_CASE(MINT_STFLD_I4) STFLD(i, gint32); MINT_IN_BREAK;
3078 MINT_IN_CASE(MINT_STFLD_I8) STFLD(l, gint64); MINT_IN_BREAK;
3079 MINT_IN_CASE(MINT_STFLD_R4) STFLD(f, float); MINT_IN_BREAK;
3080 MINT_IN_CASE(MINT_STFLD_R8) STFLD(f, double); MINT_IN_BREAK;
3081 MINT_IN_CASE(MINT_STFLD_O) STFLD(p, gpointer); MINT_IN_BREAK;
3082 MINT_IN_CASE(MINT_STFLD_P) STFLD(p, gpointer); MINT_IN_BREAK;
3084 MINT_IN_CASE(MINT_STFLD_VT)
3087 THROW_EX (mono_get_exception_null_reference (), ip);
3088 i32 = READ32(ip + 2);
3090 memcpy((char *)o + * (guint16 *)(ip + 1), sp [1].data.p, i32);
3091 vt_sp -= (i32 + 7) & ~7;
3095 MINT_IN_CASE(MINT_STRMFLD) {
3096 MonoClassField *field;
3100 THROW_EX (mono_get_exception_null_reference (), ip);
3102 field = rtm->data_items[* (guint16 *)(ip + 1)];
3105 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3106 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3107 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3108 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3110 stackval_to_data (field->type, &sp [-1], (char*)o + field->offset, FALSE);
3115 MINT_IN_CASE(MINT_STRMFLD_VT) {
3116 MonoClassField *field;
3120 THROW_EX (mono_get_exception_null_reference (), ip);
3121 field = rtm->data_items[* (guint16 *)(ip + 1)];
3122 i32 = READ32(ip + 2);
3125 if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
3126 MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
3127 mono_store_remote_field_checked (o, klass, field, &sp [-1].data, &error);
3128 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3130 memcpy((char*)o + field->offset, sp [-1].data.p, i32);
3133 vt_sp -= (i32 + 7) & ~7;
3136 MINT_IN_CASE(MINT_LDSFLDA) {
3137 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3138 MonoVTable *vt = mono_class_vtable (context->domain, field->parent);
3141 if (!vt->initialized) {
3143 mono_runtime_class_init_full (vt, &error);
3144 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3148 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3149 sp->data.p = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3151 sp->data.p = (char*)(vt->vtable) + field->offset;
3155 MINT_IN_CASE(MINT_LDSFLD) {
3157 MonoClassField *field;
3160 field = rtm->data_items[*(guint16 *)(ip + 1)];
3161 vt = rtm->data_items [*(guint16 *)(ip + 2)];
3162 if (!vt->initialized) {
3164 mono_runtime_class_init_full (vt, &error);
3165 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3168 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3169 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3171 addr = (char*)(vt->vtable) + field->offset;
3173 stackval_from_data (field->type, sp, addr, FALSE);
3177 MINT_IN_CASE(MINT_LDSFLD_I4) {
3178 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3179 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3180 if (!vt->initialized) {
3182 mono_runtime_class_init_full (vt, &error);
3183 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3186 sp->data.i = * (gint32 *)((char*)(vt->vtable) + field->offset);
3190 MINT_IN_CASE(MINT_LDSFLD_O) {
3191 MonoClassField *field = rtm->data_items[*(guint16 *)(ip + 1)];
3192 MonoVTable *vt = rtm->data_items [*(guint16 *)(ip + 2)];
3193 if (!vt->initialized) {
3195 mono_runtime_class_init_full (vt, &error);
3196 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3199 sp->data.p = * (gpointer *)((char*)(vt->vtable) + field->offset);
3203 MINT_IN_CASE(MINT_LDSFLD_VT) {
3205 MonoClassField *field;
3210 token = * (guint16 *)(ip + 1);
3211 size = READ32(ip + 2);
3212 field = rtm->data_items[token];
3215 vt = mono_class_vtable (context->domain, field->parent);
3216 if (!vt->initialized) {
3218 mono_runtime_class_init_full (vt, &error);
3219 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3222 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3223 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3225 addr = (char*)(vt->vtable) + field->offset;
3228 vt_sp += (size + 7) & ~7;
3229 stackval_from_data (field->type, sp, addr, FALSE);
3233 MINT_IN_CASE(MINT_STSFLD) {
3235 MonoClassField *field;
3239 token = * (guint16 *)(ip + 1);
3240 field = rtm->data_items[token];
3244 vt = mono_class_vtable (context->domain, field->parent);
3245 if (!vt->initialized) {
3247 mono_runtime_class_init_full (vt, &error);
3248 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3251 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3252 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3254 addr = (char*)(vt->vtable) + field->offset;
3256 stackval_to_data (field->type, sp, addr, FALSE);
3259 MINT_IN_CASE(MINT_STSFLD_VT) {
3261 MonoClassField *field;
3266 token = * (guint16 *)(ip + 1);
3267 size = READ32(ip + 2);
3268 field = rtm->data_items[token];
3271 vt = mono_class_vtable (context->domain, field->parent);
3272 if (!vt->initialized) {
3274 mono_runtime_class_init_full (vt, &error);
3275 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3278 if (context->domain->special_static_fields && (addr = g_hash_table_lookup (context->domain->special_static_fields, field)))
3279 addr = mono_get_special_static_data (GPOINTER_TO_UINT (addr));
3281 addr = (char*)(vt->vtable) + field->offset;
3283 stackval_to_data (field->type, sp, addr, FALSE);
3284 vt_sp -= (size + 7) & ~7;
3287 MINT_IN_CASE(MINT_STOBJ_VT) {
3289 c = rtm->data_items[* (guint16 *)(ip + 1)];
3291 size = mono_class_value_size (c, NULL);
3292 memcpy(sp [-2].data.p, sp [-1].data.p, size);
3293 vt_sp -= (size + 7) & ~7;
3297 MINT_IN_CASE(MINT_STOBJ) {
3299 c = rtm->data_items[* (guint16 *)(ip + 1)];
3301 size = mono_class_value_size (c, NULL);
3302 memcpy(sp [-2].data.p, &sp [-1].data, size);
3306 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_R8)
3307 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3308 THROW_EX (mono_get_exception_overflow (), ip);
3309 sp [-1].data.i = (guint32)sp [-1].data.f;
3312 MINT_IN_CASE(MINT_CONV_OVF_U8_I4)
3313 if (sp [-1].data.i < 0)
3314 THROW_EX (mono_get_exception_overflow (), ip);
3315 sp [-1].data.l = sp [-1].data.i;
3318 MINT_IN_CASE(MINT_CONV_OVF_U8_R8)
3319 MINT_IN_CASE(MINT_CONV_OVF_I8_UN_R8)
3320 if (sp [-1].data.f < 0 || sp [-1].data.f > 9223372036854775807LL)
3321 THROW_EX (mono_get_exception_overflow (), ip);
3322 sp [-1].data.l = (guint64)sp [-1].data.f;
3325 MINT_IN_CASE(MINT_CONV_OVF_I8_R8)
3326 if (sp [-1].data.f < MYGINT64_MIN || sp [-1].data.f > MYGINT64_MAX)
3327 THROW_EX (mono_get_exception_overflow (), ip);
3328 sp [-1].data.l = (gint64)sp [-1].data.f;
3331 MINT_IN_CASE(MINT_CONV_OVF_I4_UN_I8)
3332 if ((mono_u)sp [-1].data.l > MYGUINT32_MAX)
3333 THROW_EX (mono_get_exception_overflow (), ip);
3334 sp [-1].data.i = (mono_u)sp [-1].data.l;
3337 MINT_IN_CASE(MINT_BOX)
3338 c = rtm->data_items [* (guint16 *)(ip + 1)];
3340 if (c->byval_arg.type == MONO_TYPE_VALUETYPE && !c->enumtype) {
3341 int size = mono_class_value_size (c, NULL);
3342 sp [-1].data.p = mono_value_box_checked (context->domain, c, sp [-1].data.p, &error);
3343 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3344 size = (size + 7) & ~7;
3348 stackval_to_data (&c->byval_arg, &sp [-1], (char*)&sp [-1], FALSE);
3349 sp [-1].data.p = mono_value_box_checked (context->domain, c, &sp [-1], &error);
3350 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3354 MINT_IN_CASE(MINT_NEWARR)
3355 sp [-1].data.p = (MonoObject*) mono_array_new_checked (context->domain, rtm->data_items[*(guint16 *)(ip + 1)], sp [-1].data.i, &error);
3356 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3358 /*if (profiling_classes) {
3359 guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, o->vtable->klass));
3361 g_hash_table_insert (profiling_classes, o->vtable->klass, GUINT_TO_POINTER (count));
3365 MINT_IN_CASE(MINT_LDLEN)
3368 THROW_EX (mono_get_exception_null_reference (), ip);
3369 sp [-1].data.nati = mono_array_length ((MonoArray *)o);
3372 MINT_IN_CASE(MINT_GETCHR) {
3376 THROW_EX (mono_get_exception_null_reference (), ip);
3377 i32 = sp [-1].data.i;
3378 if (i32 < 0 || i32 >= mono_string_length (s))
3379 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3381 sp [-1].data.i = mono_string_chars(s)[i32];
3385 MINT_IN_CASE(MINT_STRLEN)
3387 sp [-1].data.i = mono_string_length ((MonoString*)sp [-1].data.p);
3389 MINT_IN_CASE(MINT_ARRAY_RANK)
3392 THROW_EX (mono_get_exception_null_reference (), ip);
3393 sp [-1].data.i = mono_object_class (sp [-1].data.p)->rank;
3396 MINT_IN_CASE(MINT_LDELEMA) {
3400 /*token = READ32 (ip)*/;
3406 aindex = sp [1].data.i;
3407 if (aindex >= mono_array_length ((MonoArray *) o))
3408 THROW_EX (mono_get_exception_index_out_of_range (), ip - 2);
3410 /* check the array element corresponds to token */
3411 esize = mono_array_element_size (((MonoArray *) o)->obj.vtable->klass);
3413 sp->data.p = mono_array_addr_with_size ((MonoArray *) o, esize, aindex);
3417 MINT_IN_CASE(MINT_LDELEM_I1) /* fall through */
3418 MINT_IN_CASE(MINT_LDELEM_U1) /* fall through */
3419 MINT_IN_CASE(MINT_LDELEM_I2) /* fall through */
3420 MINT_IN_CASE(MINT_LDELEM_U2) /* fall through */
3421 MINT_IN_CASE(MINT_LDELEM_I4) /* fall through */
3422 MINT_IN_CASE(MINT_LDELEM_U4) /* fall through */
3423 MINT_IN_CASE(MINT_LDELEM_I8) /* fall through */
3424 MINT_IN_CASE(MINT_LDELEM_I) /* fall through */
3425 MINT_IN_CASE(MINT_LDELEM_R4) /* fall through */
3426 MINT_IN_CASE(MINT_LDELEM_R8) /* fall through */
3427 MINT_IN_CASE(MINT_LDELEM_REF) {
3435 THROW_EX (mono_get_exception_null_reference (), ip);
3437 aindex = sp [1].data.i;
3438 if (aindex >= mono_array_length (o))
3439 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3442 * FIXME: throw mono_get_exception_array_type_mismatch () if needed
3445 case MINT_LDELEM_I1:
3446 sp [0].data.i = mono_array_get (o, gint8, aindex);
3448 case MINT_LDELEM_U1:
3449 sp [0].data.i = mono_array_get (o, guint8, aindex);
3451 case MINT_LDELEM_I2:
3452 sp [0].data.i = mono_array_get (o, gint16, aindex);
3454 case MINT_LDELEM_U2:
3455 sp [0].data.i = mono_array_get (o, guint16, aindex);
3458 sp [0].data.nati = mono_array_get (o, mono_i, aindex);
3460 case MINT_LDELEM_I4:
3461 sp [0].data.i = mono_array_get (o, gint32, aindex);
3463 case MINT_LDELEM_U4:
3464 sp [0].data.i = mono_array_get (o, guint32, aindex);
3466 case MINT_LDELEM_I8:
3467 sp [0].data.l = mono_array_get (o, guint64, aindex);
3469 case MINT_LDELEM_R4:
3470 sp [0].data.f = mono_array_get (o, float, aindex);
3472 case MINT_LDELEM_R8:
3473 sp [0].data.f = mono_array_get (o, double, aindex);
3475 case MINT_LDELEM_REF:
3476 sp [0].data.p = mono_array_get (o, gpointer, aindex);
3486 MINT_IN_CASE(MINT_STELEM_I) /* fall through */
3487 MINT_IN_CASE(MINT_STELEM_I1) /* fall through */
3488 MINT_IN_CASE(MINT_STELEM_I2) /* fall through */
3489 MINT_IN_CASE(MINT_STELEM_I4) /* fall through */
3490 MINT_IN_CASE(MINT_STELEM_I8) /* fall through */
3491 MINT_IN_CASE(MINT_STELEM_R4) /* fall through */
3492 MINT_IN_CASE(MINT_STELEM_R8) /* fall through */
3493 MINT_IN_CASE(MINT_STELEM_REF) {
3500 THROW_EX (mono_get_exception_null_reference (), ip);
3502 aindex = sp [1].data.i;
3503 if (aindex >= mono_array_length ((MonoArray *)o))
3504 THROW_EX (mono_get_exception_index_out_of_range (), ip);
3508 mono_array_set ((MonoArray *)o, mono_i, aindex, sp [2].data.nati);
3510 case MINT_STELEM_I1:
3511 mono_array_set ((MonoArray *)o, gint8, aindex, sp [2].data.i);
3513 case MINT_STELEM_I2:
3514 mono_array_set ((MonoArray *)o, gint16, aindex, sp [2].data.i);
3516 case MINT_STELEM_I4:
3517 mono_array_set ((MonoArray *)o, gint32, aindex, sp [2].data.i);
3519 case MINT_STELEM_I8:
3520 mono_array_set ((MonoArray *)o, gint64, aindex, sp [2].data.l);
3522 case MINT_STELEM_R4:
3523 mono_array_set ((MonoArray *)o, float, aindex, sp [2].data.f);
3525 case MINT_STELEM_R8:
3526 mono_array_set ((MonoArray *)o, double, aindex, sp [2].data.f);
3528 case MINT_STELEM_REF: {
3529 MonoObject *isinst_obj = mono_object_isinst_checked (sp [2].data.p, mono_object_class (o)->element_class, &error);
3530 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3531 if (sp [2].data.p && !isinst_obj)
3532 THROW_EX (mono_get_exception_array_type_mismatch (), ip);
3533 mono_array_set ((MonoArray *)o, gpointer, aindex, sp [2].data.p);
3542 MINT_IN_CASE(MINT_CONV_OVF_I4_U4)
3543 if (sp [-1].data.i < 0)
3544 THROW_EX (mono_get_exception_overflow (), ip);
3547 MINT_IN_CASE(MINT_CONV_OVF_I4_I8)
3548 if (sp [-1].data.l < MYGINT32_MIN || sp [-1].data.l > MYGINT32_MAX)
3549 THROW_EX (mono_get_exception_overflow (), ip);
3550 sp [-1].data.i = (gint32) sp [-1].data.l;
3553 MINT_IN_CASE(MINT_CONV_OVF_I4_R8)
3554 if (sp [-1].data.f < MYGINT32_MIN || sp [-1].data.f > MYGINT32_MAX)
3555 THROW_EX (mono_get_exception_overflow (), ip);
3556 sp [-1].data.i = (gint32) sp [-1].data.f;
3559 MINT_IN_CASE(MINT_CONV_OVF_U4_I4)
3560 if (sp [-1].data.i < 0)
3561 THROW_EX (mono_get_exception_overflow (), ip);
3564 MINT_IN_CASE(MINT_CONV_OVF_U4_I8)
3565 if (sp [-1].data.l < 0 || sp [-1].data.l > MYGUINT32_MAX)
3566 THROW_EX (mono_get_exception_overflow (), ip);
3567 sp [-1].data.i = (guint32) sp [-1].data.l;
3570 MINT_IN_CASE(MINT_CONV_OVF_U4_R8)
3571 if (sp [-1].data.f < 0 || sp [-1].data.f > MYGUINT32_MAX)
3572 THROW_EX (mono_get_exception_overflow (), ip);
3573 sp [-1].data.i = (guint32) sp [-1].data.f;
3576 MINT_IN_CASE(MINT_CONV_OVF_I2_I4)
3577 if (sp [-1].data.i < -32768 || sp [-1].data.i > 32767)
3578 THROW_EX (mono_get_exception_overflow (), ip);
3581 MINT_IN_CASE(MINT_CONV_OVF_I2_I8)
3582 if (sp [-1].data.l < -32768 || sp [-1].data.l > 32767)
3583 THROW_EX (mono_get_exception_overflow (), ip);
3584 sp [-1].data.i = (gint16) sp [-1].data.l;
3587 MINT_IN_CASE(MINT_CONV_OVF_I2_R8)
3588 if (sp [-1].data.f < -32768 || sp [-1].data.f > 32767)
3589 THROW_EX (mono_get_exception_overflow (), ip);
3590 sp [-1].data.i = (gint16) sp [-1].data.f;
3593 MINT_IN_CASE(MINT_CONV_OVF_U2_I4)
3594 if (sp [-1].data.i < 0 || sp [-1].data.i > 65535)
3595 THROW_EX (mono_get_exception_overflow (), ip);
3598 MINT_IN_CASE(MINT_CONV_OVF_U2_I8)
3599 if (sp [-1].data.l < 0 || sp [-1].data.l > 65535)
3600 THROW_EX (mono_get_exception_overflow (), ip);
3601 sp [-1].data.i = (guint16) sp [-1].data.l;
3604 MINT_IN_CASE(MINT_CONV_OVF_U2_R8)
3605 if (sp [-1].data.f < 0 || sp [-1].data.f > 65535)
3606 THROW_EX (mono_get_exception_overflow (), ip);
3607 sp [-1].data.i = (guint16) sp [-1].data.f;
3610 MINT_IN_CASE(MINT_CONV_OVF_I1_I4)
3611 if (sp [-1].data.i < -128 || sp [-1].data.i > 127)
3612 THROW_EX (mono_get_exception_overflow (), ip);
3615 MINT_IN_CASE(MINT_CONV_OVF_I1_I8)
3616 if (sp [-1].data.l < -128 || sp [-1].data.l > 127)
3617 THROW_EX (mono_get_exception_overflow (), ip);
3618 sp [-1].data.i = (gint8) sp [-1].data.l;
3621 MINT_IN_CASE(MINT_CONV_OVF_I1_R8)
3622 if (sp [-1].data.f < -128 || sp [-1].data.f > 127)
3623 THROW_EX (mono_get_exception_overflow (), ip);
3624 sp [-1].data.i = (gint8) sp [-1].data.f;
3627 MINT_IN_CASE(MINT_CONV_OVF_U1_I4)
3628 if (sp [-1].data.i < 0 || sp [-1].data.i > 255)
3629 THROW_EX (mono_get_exception_overflow (), ip);
3632 MINT_IN_CASE(MINT_CONV_OVF_U1_I8)
3633 if (sp [-1].data.l < 0 || sp [-1].data.l > 255)
3634 THROW_EX (mono_get_exception_overflow (), ip);
3635 sp [-1].data.i = (guint8) sp [-1].data.l;
3638 MINT_IN_CASE(MINT_CONV_OVF_U1_R8)
3639 if (sp [-1].data.f < 0 || sp [-1].data.f > 255)
3640 THROW_EX (mono_get_exception_overflow (), ip);
3641 sp [-1].data.i = (guint8) sp [-1].data.f;
3645 MINT_IN_CASE(MINT_LDELEM)
3646 MINT_IN_CASE(MINT_STELEM)
3647 MINT_IN_CASE(MINT_UNBOX_ANY)
3649 MINT_IN_CASE(MINT_REFANYVAL) ves_abort(); MINT_IN_BREAK;
3651 MINT_IN_CASE(MINT_CKFINITE)
3652 if (!isfinite(sp [-1].data.f))
3653 THROW_EX (mono_get_exception_arithmetic (), ip);
3657 MINT_IN_CASE(MINT_MKREFANY) ves_abort(); MINT_IN_BREAK;
3659 MINT_IN_CASE(MINT_LDTOKEN)
3662 * (gpointer *)sp->data.p = rtm->data_items[*(guint16 *)(ip + 1)];
3666 MINT_IN_CASE(MINT_ADD_OVF_I4)
3667 if (CHECK_ADD_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3668 THROW_EX (mono_get_exception_overflow (), ip);
3671 MINT_IN_CASE(MINT_ADD_OVF_I8)
3672 if (CHECK_ADD_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3673 THROW_EX (mono_get_exception_overflow (), ip);
3676 MINT_IN_CASE(MINT_ADD_OVF_UN_I4)
3677 if (CHECK_ADD_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3678 THROW_EX (mono_get_exception_overflow (), ip);
3679 BINOP_CAST(i, +, guint32);
3681 MINT_IN_CASE(MINT_ADD_OVF_UN_I8)
3682 if (CHECK_ADD_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3683 THROW_EX (mono_get_exception_overflow (), ip);
3684 BINOP_CAST(l, +, guint64);
3686 MINT_IN_CASE(MINT_MUL_OVF_I4)
3687 if (CHECK_MUL_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3688 THROW_EX (mono_get_exception_overflow (), ip);
3691 MINT_IN_CASE(MINT_MUL_OVF_I8)
3692 if (CHECK_MUL_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3693 THROW_EX (mono_get_exception_overflow (), ip);
3696 MINT_IN_CASE(MINT_MUL_OVF_UN_I4)
3697 if (CHECK_MUL_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3698 THROW_EX (mono_get_exception_overflow (), ip);
3699 BINOP_CAST(i, *, guint32);
3701 MINT_IN_CASE(MINT_MUL_OVF_UN_I8)
3702 if (CHECK_MUL_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3703 THROW_EX (mono_get_exception_overflow (), ip);
3704 BINOP_CAST(l, *, guint64);
3706 MINT_IN_CASE(MINT_SUB_OVF_I4)
3707 if (CHECK_SUB_OVERFLOW (sp [-2].data.i, sp [-1].data.i))
3708 THROW_EX (mono_get_exception_overflow (), ip);
3711 MINT_IN_CASE(MINT_SUB_OVF_I8)
3712 if (CHECK_SUB_OVERFLOW64 (sp [-2].data.l, sp [-1].data.l))
3713 THROW_EX (mono_get_exception_overflow (), ip);
3716 MINT_IN_CASE(MINT_SUB_OVF_UN_I4)
3717 if (CHECK_SUB_OVERFLOW_UN (sp [-2].data.i, sp [-1].data.i))
3718 THROW_EX (mono_get_exception_overflow (), ip);
3719 BINOP_CAST(i, -, guint32);
3721 MINT_IN_CASE(MINT_SUB_OVF_UN_I8)
3722 if (CHECK_SUB_OVERFLOW64_UN (sp [-2].data.l, sp [-1].data.l))
3723 THROW_EX (mono_get_exception_overflow (), ip);
3724 BINOP_CAST(l, -, guint64);
3726 MINT_IN_CASE(MINT_ENDFINALLY)
3728 ip = finally_ips->data;
3729 finally_ips = g_slist_remove (finally_ips, ip);
3736 MINT_IN_CASE(MINT_LEAVE) /* Fall through */
3737 MINT_IN_CASE(MINT_LEAVE_S)
3738 while (sp > frame->stack) {
3742 if (*ip == MINT_LEAVE_S) {
3743 ip += (short) *(ip + 1);
3745 ip += (gint32) READ32 (ip + 1);
3748 if (frame->ex_handler != NULL && MONO_OFFSET_IN_HANDLER(frame->ex_handler, frame->ip - rtm->code)) {
3749 frame->ex_handler = NULL;
3752 goto handle_finally;
3754 MINT_IN_CASE(MINT_ICALL_V_V)
3755 MINT_IN_CASE(MINT_ICALL_P_V)
3756 MINT_IN_CASE(MINT_ICALL_P_P)
3757 MINT_IN_CASE(MINT_ICALL_PP_V)
3758 MINT_IN_CASE(MINT_ICALL_PI_V)
3759 MINT_IN_CASE(MINT_ICALL_PP_P)
3760 MINT_IN_CASE(MINT_ICALL_PI_P)
3761 MINT_IN_CASE(MINT_ICALL_PPP_V)
3762 MINT_IN_CASE(MINT_ICALL_PPI_V)
3763 sp = do_icall (context, *ip, sp, rtm->data_items [*(guint16 *)(ip + 1)]);
3764 if (frame->ex != NULL)
3765 goto handle_exception;
3768 MINT_IN_CASE(MINT_MONO_LDPTR)
3769 sp->data.p = rtm->data_items [*(guint16 *)(ip + 1)];
3773 MINT_IN_CASE(MINT_MONO_NEWOBJ)
3774 sp->data.p = mono_object_new_checked (context->domain, rtm->data_items [*(guint16 *)(ip + 1)], &error);
3775 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
3779 MINT_IN_CASE(MINT_MONO_FREE)
3782 g_error ("that doesn't seem right");
3783 g_free (sp->data.p);
3785 MINT_IN_CASE(MINT_MONO_RETOBJ)
3788 stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
3789 mono_method_signature (frame->runtime_method->method)->pinvoke);
3790 if (sp > frame->stack)
3791 g_warning ("retobj: more values on stack: %d", sp-frame->stack);
3794 #define RELOP(datamem, op) \
3796 sp [-1].data.i = sp [-1].data.datamem op sp [0].data.datamem; \
3798 MINT_IN_CASE(MINT_CEQ_I4)
3801 MINT_IN_CASE(MINT_CEQ0_I4)
3802 sp [-1].data.i = (sp [-1].data.i == 0);
3805 MINT_IN_CASE(MINT_CEQ_I8)
3808 MINT_IN_CASE(MINT_CEQ_R8)
3810 if (isunordered (sp [-1].data.f, sp [0].data.f))
3813 sp [-1].data.i = sp [-1].data.f == sp [0].data.f;
3816 MINT_IN_CASE(MINT_CGT_I4)
3819 MINT_IN_CASE(MINT_CGT_I8)
3822 MINT_IN_CASE(MINT_CGT_R8)
3824 if (isunordered (sp [-1].data.f, sp [0].data.f))
3827 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3831 #define RELOP_CAST(datamem, op, type) \
3833 sp [-1].data.i = (type)sp [-1].data.datamem op (type)sp [0].data.datamem; \
3836 MINT_IN_CASE(MINT_CGT_UN_I4)
3837 RELOP_CAST(i, >, guint32);
3839 MINT_IN_CASE(MINT_CGT_UN_I8)
3840 RELOP_CAST(l, >, guint64);
3842 MINT_IN_CASE(MINT_CGT_UN_R8)
3844 if (isunordered (sp [-1].data.f, sp [0].data.f))
3847 sp [-1].data.i = sp [-1].data.f > sp [0].data.f;
3850 MINT_IN_CASE(MINT_CLT_I4)
3853 MINT_IN_CASE(MINT_CLT_I8)
3856 MINT_IN_CASE(MINT_CLT_R8)
3858 if (isunordered (sp [-1].data.f, sp [0].data.f))
3861 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3864 MINT_IN_CASE(MINT_CLT_UN_I4)
3865 RELOP_CAST(i, <, guint32);
3867 MINT_IN_CASE(MINT_CLT_UN_I8)
3868 RELOP_CAST(l, <, guint64);
3870 MINT_IN_CASE(MINT_CLT_UN_R8)
3872 if (isunordered (sp [-1].data.f, sp [0].data.f))
3875 sp [-1].data.i = sp [-1].data.f < sp [0].data.f;
3878 MINT_IN_CASE(MINT_LDFTN) {
3879 sp->data.p = rtm->data_items [* (guint16 *)(ip + 1)];
3884 MINT_IN_CASE(MINT_LDVIRTFTN) {
3885 RuntimeMethod *m = rtm->data_items [* (guint16 *)(ip + 1)];
3889 THROW_EX (mono_get_exception_null_reference (), ip - 2);
3891 sp->data.p = get_virtual_method (context->domain, m, sp->data.p);
3896 MINT_IN_CASE(MINT_LDTHIS)
3897 sp->data.p = frame->obj;
3901 MINT_IN_CASE(MINT_STTHIS)
3903 frame->obj = sp->data.p;
3906 MINT_IN_CASE(MINT_LDTHISA)
3907 sp->data.p = &frame->obj;
3912 #define LDARG(datamem, argtype) \
3913 sp->data.datamem = * (argtype *)(frame->args + * (guint16 *)(ip + 1)); \
3917 MINT_IN_CASE(MINT_LDARG_I1) LDARG(i, gint8); MINT_IN_BREAK;
3918 MINT_IN_CASE(MINT_LDARG_U1) LDARG(i, guint8); MINT_IN_BREAK;
3919 MINT_IN_CASE(MINT_LDARG_I2) LDARG(i, gint16); MINT_IN_BREAK;
3920 MINT_IN_CASE(MINT_LDARG_U2) LDARG(i, guint16); MINT_IN_BREAK;
3921 MINT_IN_CASE(MINT_LDARG_I4) LDARG(i, gint32); MINT_IN_BREAK;
3922 MINT_IN_CASE(MINT_LDARG_I8) LDARG(l, gint64); MINT_IN_BREAK;
3923 MINT_IN_CASE(MINT_LDARG_R4) LDARG(f, float); MINT_IN_BREAK;
3924 MINT_IN_CASE(MINT_LDARG_R8) LDARG(f, double); MINT_IN_BREAK;
3925 MINT_IN_CASE(MINT_LDARG_O) LDARG(p, gpointer); MINT_IN_BREAK;
3926 MINT_IN_CASE(MINT_LDARG_P) LDARG(p, gpointer); MINT_IN_BREAK;
3928 MINT_IN_CASE(MINT_LDARG_VT)
3930 i32 = READ32(ip + 2);
3931 memcpy(sp->data.p, frame->args + * (guint16 *)(ip + 1), i32);
3932 vt_sp += (i32 + 7) & ~7;
3937 #define STARG(datamem, argtype) \
3939 * (argtype *)(frame->args + * (guint16 *)(ip + 1)) = sp->data.datamem; \
3942 MINT_IN_CASE(MINT_STARG_I1) STARG(i, gint8); MINT_IN_BREAK;
3943 MINT_IN_CASE(MINT_STARG_U1) STARG(i, guint8); MINT_IN_BREAK;
3944 MINT_IN_CASE(MINT_STARG_I2) STARG(i, gint16); MINT_IN_BREAK;
3945 MINT_IN_CASE(MINT_STARG_U2) STARG(i, guint16); MINT_IN_BREAK;
3946 MINT_IN_CASE(MINT_STARG_I4) STARG(i, gint32); MINT_IN_BREAK;
3947 MINT_IN_CASE(MINT_STARG_I8) STARG(l, gint64); MINT_IN_BREAK;
3948 MINT_IN_CASE(MINT_STARG_R4) STARG(f, float); MINT_IN_BREAK;
3949 MINT_IN_CASE(MINT_STARG_R8) STARG(f, double); MINT_IN_BREAK;
3950 MINT_IN_CASE(MINT_STARG_O) STARG(p, gpointer); MINT_IN_BREAK;
3951 MINT_IN_CASE(MINT_STARG_P) STARG(p, gpointer); MINT_IN_BREAK;
3953 MINT_IN_CASE(MINT_STARG_VT)
3954 i32 = READ32(ip + 2);
3956 memcpy(frame->args + * (guint16 *)(ip + 1), sp->data.p, i32);
3957 vt_sp -= (i32 + 7) & ~7;
3961 #define STINARG(datamem, argtype) \
3963 int n = * (guint16 *)(ip + 1); \
3964 * (argtype *)(frame->args + rtm->arg_offsets [n]) = frame->stack_args [n].data.datamem; \
3968 MINT_IN_CASE(MINT_STINARG_I1) STINARG(i, gint8); MINT_IN_BREAK;
3969 MINT_IN_CASE(MINT_STINARG_U1) STINARG(i, guint8); MINT_IN_BREAK;
3970 MINT_IN_CASE(MINT_STINARG_I2) STINARG(i, gint16); MINT_IN_BREAK;
3971 MINT_IN_CASE(MINT_STINARG_U2) STINARG(i, guint16); MINT_IN_BREAK;
3972 MINT_IN_CASE(MINT_STINARG_I4) STINARG(i, gint32); MINT_IN_BREAK;
3973 MINT_IN_CASE(MINT_STINARG_I8) STINARG(l, gint64); MINT_IN_BREAK;
3974 MINT_IN_CASE(MINT_STINARG_R4) STINARG(f, float); MINT_IN_BREAK;
3975 MINT_IN_CASE(MINT_STINARG_R8) STINARG(f, double); MINT_IN_BREAK;
3976 MINT_IN_CASE(MINT_STINARG_O) STINARG(p, gpointer); MINT_IN_BREAK;
3977 MINT_IN_CASE(MINT_STINARG_P) STINARG(p, gpointer); MINT_IN_BREAK;
3979 MINT_IN_CASE(MINT_STINARG_VT) {
3980 int n = * (guint16 *)(ip + 1);
3981 i32 = READ32(ip + 2);
3982 memcpy (frame->args + rtm->arg_offsets [n], frame->stack_args [n].data.p, i32);
3987 MINT_IN_CASE(MINT_LDARGA)
3988 sp->data.p = frame->args + * (guint16 *)(ip + 1);
3993 #define LDLOC(datamem, argtype) \
3994 sp->data.datamem = * (argtype *)(locals + * (guint16 *)(ip + 1)); \
3998 MINT_IN_CASE(MINT_LDLOC_I1) LDLOC(i, gint8); MINT_IN_BREAK;
3999 MINT_IN_CASE(MINT_LDLOC_U1) LDLOC(i, guint8); MINT_IN_BREAK;
4000 MINT_IN_CASE(MINT_LDLOC_I2) LDLOC(i, gint16); MINT_IN_BREAK;
4001 MINT_IN_CASE(MINT_LDLOC_U2) LDLOC(i, guint16); MINT_IN_BREAK;
4002 MINT_IN_CASE(MINT_LDLOC_I4) LDLOC(i, gint32); MINT_IN_BREAK;
4003 MINT_IN_CASE(MINT_LDLOC_I8) LDLOC(l, gint64); MINT_IN_BREAK;
4004 MINT_IN_CASE(MINT_LDLOC_R4) LDLOC(f, float); MINT_IN_BREAK;
4005 MINT_IN_CASE(MINT_LDLOC_R8) LDLOC(f, double); MINT_IN_BREAK;
4006 MINT_IN_CASE(MINT_LDLOC_O) LDLOC(p, gpointer); MINT_IN_BREAK;
4007 MINT_IN_CASE(MINT_LDLOC_P) LDLOC(p, gpointer); MINT_IN_BREAK;
4009 MINT_IN_CASE(MINT_LDLOC_VT)
4011 i32 = READ32(ip + 2);
4012 memcpy(sp->data.p, locals + * (guint16 *)(ip + 1), i32);
4013 vt_sp += (i32 + 7) & ~7;
4018 MINT_IN_CASE(MINT_LDLOCA_S)
4019 sp->data.p = locals + * (guint16 *)(ip + 1);
4024 #define STLOC(datamem, argtype) \
4026 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp->data.datamem; \
4029 MINT_IN_CASE(MINT_STLOC_I1) STLOC(i, gint8); MINT_IN_BREAK;
4030 MINT_IN_CASE(MINT_STLOC_U1) STLOC(i, guint8); MINT_IN_BREAK;
4031 MINT_IN_CASE(MINT_STLOC_I2) STLOC(i, gint16); MINT_IN_BREAK;
4032 MINT_IN_CASE(MINT_STLOC_U2) STLOC(i, guint16); MINT_IN_BREAK;
4033 MINT_IN_CASE(MINT_STLOC_I4) STLOC(i, gint32); MINT_IN_BREAK;
4034 MINT_IN_CASE(MINT_STLOC_I8) STLOC(l, gint64); MINT_IN_BREAK;
4035 MINT_IN_CASE(MINT_STLOC_R4) STLOC(f, float); MINT_IN_BREAK;
4036 MINT_IN_CASE(MINT_STLOC_R8) STLOC(f, double); MINT_IN_BREAK;
4037 MINT_IN_CASE(MINT_STLOC_O) STLOC(p, gpointer); MINT_IN_BREAK;
4038 MINT_IN_CASE(MINT_STLOC_P) STLOC(p, gpointer); MINT_IN_BREAK;
4040 #define STLOC_NP(datamem, argtype) \
4041 * (argtype *)(locals + * (guint16 *)(ip + 1)) = sp [-1].data.datamem; \
4044 MINT_IN_CASE(MINT_STLOC_NP_I4) STLOC_NP(i, gint32); MINT_IN_BREAK;
4045 MINT_IN_CASE(MINT_STLOC_NP_O) STLOC_NP(p, gpointer); MINT_IN_BREAK;
4047 MINT_IN_CASE(MINT_STLOC_VT)
4048 i32 = READ32(ip + 2);
4050 memcpy(locals + * (guint16 *)(ip + 1), sp->data.p, i32);
4051 vt_sp -= (i32 + 7) & ~7;
4055 MINT_IN_CASE(MINT_LOCALLOC)
4056 if (sp != frame->stack + 1) /*FIX?*/
4057 THROW_EX (mono_get_exception_execution_engine (NULL), ip);
4058 sp [-1].data.p = alloca (sp [-1].data.i);
4062 MINT_IN_CASE(MINT_ENDFILTER) ves_abort(); MINT_IN_BREAK;
4064 MINT_IN_CASE(MINT_INITOBJ)
4066 memset (sp->data.vt, 0, READ32(ip + 1));
4069 MINT_IN_CASE(MINT_CPBLK)
4071 if (!sp [0].data.p || !sp [1].data.p)
4072 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4074 /* FIXME: value and size may be int64... */
4075 memcpy (sp [0].data.p, sp [1].data.p, sp [2].data.i);
4078 MINT_IN_CASE(MINT_CONSTRAINED_) {
4080 /* FIXME: implement */
4082 token = READ32 (ip);
4087 MINT_IN_CASE(MINT_INITBLK)
4090 THROW_EX (mono_get_exception_null_reference(), ip - 1);
4092 /* FIXME: value and size may be int64... */
4093 memset (sp [0].data.p, sp [1].data.i, sp [2].data.i);
4096 MINT_IN_CASE(MINT_NO_)
4097 /* FIXME: implement */
4101 MINT_IN_CASE(MINT_RETHROW)
4103 * need to clarify what this should actually do:
4104 * start the search from the last found handler in
4105 * this method or continue in the caller or what.
4106 * Also, do we need to run finally/fault handlers after a retrow?
4107 * Well, this implementation will follow the usual search
4108 * for an handler, considering the current ip as throw spot.
4109 * We need to NULL frame->ex_handler for the later code to
4110 * actually run the new found handler.
4112 frame->ex_handler = NULL;
4113 THROW_EX (frame->ex, ip - 1);
4116 g_print ("Unimplemented opcode: %04x %s at 0x%x\n", *ip, mono_interp_opname[*ip], ip-rtm->code);
4117 THROW_EX (mono_get_exception_execution_engine ("Unimplemented opcode"), ip);
4121 g_assert_not_reached ();
4123 * Exception handling code.
4124 * The exception object is stored in frame->ex.
4131 MonoInvocation *inv;
4132 MonoExceptionClause *clause;
4138 g_print ("* Handling exception '%s' at IL_%04x\n",
4139 frame->ex == NULL ? "** Unknown **" : mono_object_class (frame->ex)->name,
4140 rtm == NULL ? 0 : frame->ip - rtm->code);
4142 if (die_on_exception)
4145 for (inv = frame; inv; inv = inv->parent) {
4147 if (inv->runtime_method == NULL)
4149 method = inv->runtime_method->method;
4150 if (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4152 if (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))
4154 if (inv->ip == NULL)
4156 ip_offset = inv->ip - inv->runtime_method->code;
4157 inv->ex_handler = NULL; /* clear this in case we are trhowing an exception while handling one - this one wins */
4158 for (i = 0; i < inv->runtime_method->num_clauses; ++i) {
4159 clause = &inv->runtime_method->clauses [i];
4160 if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4161 if (!clause->flags) {
4162 MonoObject *isinst_obj = mono_object_isinst_checked ((MonoObject*)frame->ex, clause->data.catch_class, &error);
4163 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4166 * OK, we found an handler, now we need to execute the finally
4167 * and fault blocks before branching to the handler code.
4169 inv->ex_handler = clause;
4172 g_print ("* Found handler at '%s'\n", method->name);
4174 goto handle_finally;
4177 /* FIXME: handle filter clauses */
4184 * If we get here, no handler was found: print a stack trace.
4186 for (inv = frame; inv; inv = inv->parent) {
4187 if (inv->invoke_trap)
4188 goto handle_finally;
4191 ex_obj = (MonoObject*)frame->ex;
4192 mono_unhandled_exception (ex_obj);
4199 MonoExceptionClause *clause;
4200 GSList *old_list = finally_ips;
4201 MonoMethod *method = frame->runtime_method->method;
4202 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4203 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4207 g_print ("* Handle finally IL_%04x\n", endfinally_ip == NULL ? 0 : endfinally_ip - rtm->code);
4209 if (rtm == NULL || (method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL)
4210 || (method->iflags & (METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL | METHOD_IMPL_ATTRIBUTE_RUNTIME))) {
4213 ip_offset = frame->ip - rtm->code;
4215 if (endfinally_ip != NULL)
4216 finally_ips = g_slist_prepend(finally_ips, (void *)endfinally_ip);
4217 for (i = 0; i < header->num_clauses; ++i)
4218 if (frame->ex_handler == &rtm->clauses [i])
4222 clause = &rtm->clauses [i];
4223 if (MONO_OFFSET_IN_CLAUSE (clause, ip_offset) && (endfinally_ip == NULL || !(MONO_OFFSET_IN_CLAUSE (clause, endfinally_ip - rtm->code)))) {
4224 if (clause->flags == MONO_EXCEPTION_CLAUSE_FINALLY) {
4225 ip = rtm->code + clause->handler_offset;
4226 finally_ips = g_slist_prepend (finally_ips, (gpointer) ip);
4229 g_print ("* Found finally at IL_%04x with exception: %s\n", clause->handler_offset, frame->ex? "yes": "no");
4235 endfinally_ip = NULL;
4237 if (old_list != finally_ips && finally_ips) {
4238 ip = finally_ips->data;
4239 finally_ips = g_slist_remove (finally_ips, ip);
4240 sp = frame->stack; /* spec says stack should be empty at endfinally so it should be at the start too */
4245 * If an exception is set, we need to execute the fault handler, too,
4246 * otherwise, we continue normally.
4256 MonoExceptionClause *clause;
4257 MonoMethod *method = frame->runtime_method->method;
4258 MonoMethodHeader *header = mono_method_get_header_checked (method, &error);
4259 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4263 g_print ("* Handle fault\n");
4265 ip_offset = frame->ip - rtm->code;
4266 for (i = 0; i < header->num_clauses; ++i) {
4267 clause = &rtm->clauses [i];
4268 if (clause->flags == MONO_EXCEPTION_CLAUSE_FAULT && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
4269 ip = rtm->code + clause->handler_offset;
4272 g_print ("* Executing handler at IL_%04x\n", clause->handler_offset);
4278 * If the handler for the exception was found in this method, we jump
4279 * to it right away, otherwise we return and let the caller run
4280 * the finally, fault and catch blocks.
4281 * This same code should be present in the endfault opcode, but it
4282 * is corrently not assigned in the ECMA specs: LAMESPEC.
4284 if (frame->ex_handler) {
4287 g_print ("* Executing handler at IL_%04x\n", frame->ex_handler->handler_offset);
4289 ip = rtm->code + frame->ex_handler->handler_offset;
4291 vt_sp = (unsigned char *) sp + rtm->stack_size;
4292 sp->data.p = frame->ex;
4303 ves_exec_method (MonoInvocation *frame)
4305 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4306 ThreadContext context_struct;
4313 mono_unhandled_exception ((MonoObject*)frame->ex);
4316 if (context == NULL) {
4317 context = &context_struct;
4318 context_struct.domain = mono_domain_get ();
4319 context_struct.base_frame = frame;
4320 context_struct.current_frame = NULL;
4321 context_struct.env_frame = frame;
4322 context_struct.current_env = &env;
4323 context_struct.search_for_handler = 0;
4324 context_struct.managed_code = 0;
4325 mono_native_tls_set_value (thread_context_id, context);
4328 frame->parent = context->current_frame;
4329 frame->runtime_method = mono_interp_get_runtime_method (context->domain, frame->method, &error);
4330 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4331 context->managed_code = 1;
4332 ves_exec_method_with_context (frame, context);
4333 context->managed_code = 0;
4335 if (context != &context_struct && context->current_env) {
4336 context->env_frame->ex = frame->ex;
4337 longjmp (*context->current_env, 1);
4340 mono_unhandled_exception ((MonoObject*)frame->ex);
4342 if (context->base_frame == frame)
4343 mono_native_tls_set_value (thread_context_id, NULL);
4345 context->current_frame = frame->parent;
4349 ves_exec (MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4351 MonoImage *image = mono_assembly_get_image (assembly);
4356 method = mono_get_method_checked (image, mono_image_get_entry_point (image), NULL, NULL, &error);
4357 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4360 g_error ("No entry point method found in %s", mono_image_get_filename (image));
4362 rval = mono_runtime_run_main_checked (method, argc, argv, &error);
4363 return_val_and_set_pending_if_nok (&error, rval);
4370 "mint %s, the Mono ECMA CLI interpreter, (C) 2001, 2002 Ximian, Inc.\n\n"
4371 "Usage is: mint [options] executable args...\n\n", VERSION);
4373 "Runtime Debugging:\n"
4378 " --noptr\t\t\tdon't print pointer addresses in trace output\n"
4381 " --traceclassinit\n"
4384 " --debug method_name\n"
4391 " --config filename load the specified config file instead of the default\n"
4392 " --workers n maximum number of worker threads\n"
4398 add_signal_handler (int signo, void (*handler)(int))
4401 signal (signo, handler);
4403 struct sigaction sa;
4405 sa.sa_handler = handler;
4406 sigemptyset (&sa.sa_mask);
4409 g_assert (sigaction (signo, &sa, NULL) != -1);
4414 segv_handler (int signum)
4416 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4417 MonoException *segv_exception;
4419 if (context == NULL)
4421 segv_exception = mono_get_exception_null_reference ();
4422 segv_exception->message = mono_string_new (mono_domain_get (), "Null Reference (SIGSEGV)");
4423 mono_raise_exception (segv_exception);
4428 quit_handler (int signum)
4430 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4431 MonoException *quit_exception;
4433 if (context == NULL)
4435 quit_exception = mono_get_exception_execution_engine ("Interrupted (SIGQUIT).");
4436 mono_raise_exception (quit_exception);
4440 abrt_handler (int signum)
4442 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4443 MonoException *abrt_exception;
4445 if (context == NULL)
4447 abrt_exception = mono_get_exception_execution_engine ("Abort (SIGABRT).");
4448 mono_raise_exception (abrt_exception);
4453 thread_abort_handler (int signum)
4455 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4458 if (context == NULL)
4461 exc = mono_thread_request_interruption (context->managed_code);
4462 if (exc) mono_raise_exception (exc);
4467 ves_icall_get_frame_info (gint32 skip, MonoBoolean need_file_info,
4468 MonoReflectionMethod **method,
4469 gint32 *iloffset, gint32 *native_offset,
4470 MonoString **file, gint32 *line, gint32 *column)
4472 ThreadContext *context = mono_native_tls_get_value (thread_context_id);
4473 MonoInvocation *inv = context->current_frame;
4477 for (i = 0; inv && i < skip; inv = inv->parent)
4478 if (inv->runtime_method != NULL)
4489 *method = mono_method_get_object_checked (context->domain, inv->runtime_method->method, NULL, &error);
4490 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4495 if (need_file_info) {
4499 *file = mono_string_new (mono_domain_get (), "unknown");
4506 ves_icall_get_trace (MonoException *exc, gint32 skip, MonoBoolean need_file_info)
4508 MonoDomain *domain = mono_domain_get ();
4510 MonoArray *ta = exc->trace_ips;
4515 /* Exception is not thrown yet */
4516 MonoArray *array = mono_array_new_checked (domain, mono_defaults.stack_frame_class, 0, &error);
4517 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4521 len = mono_array_length (ta);
4523 res = mono_array_new_checked (domain, mono_defaults.stack_frame_class, len > skip ? len - skip : 0, &error);
4524 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4526 for (i = skip; i < len / 2; i++) {
4527 MonoStackFrame *sf = (MonoStackFrame *)mono_object_new_checked (domain, mono_defaults.stack_frame_class, &error);
4528 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4529 gushort *ip = mono_array_get (ta, gpointer, 2 * i + 1);
4530 RuntimeMethod *rtm = mono_array_get (ta, gpointer, 2 * i);
4533 sf->method = mono_method_get_object_checked (domain, rtm->method, NULL, &error);
4534 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4535 sf->native_offset = ip - rtm->code;
4539 sf->il_offset = mono_debug_il_offset_from_address (ji->method, sf->native_offset, domain);
4541 if (need_file_info) {
4544 filename = mono_debug_source_location_from_address (ji->method, sf->native_offset, &sf->line, domain);
4546 sf->filename = filename? mono_string_new (domain, filename): NULL;
4553 mono_array_set (res, gpointer, i, sf);
4560 ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, MonoObject *target, MonoReflectionMethod *info)
4562 MonoClass *delegate_class = mono_class_from_mono_type (type->type);
4563 MonoObject *delegate;
4566 g_assert (delegate_class->parent == mono_defaults.multicastdelegate_class);
4568 delegate = mono_object_new_checked (mono_object_domain (type), delegate_class, &error);
4569 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4571 interp_delegate_ctor (mono_object_domain (type), delegate, target, mono_interp_get_runtime_method (mono_get_root_domain (), info->method, &error));
4572 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4581 int enable_debugging;
4587 static void main_thread_handler (gpointer user_data)
4589 MainThreadArgs *main_args=(MainThreadArgs *)user_data;
4590 MonoAssembly *assembly;
4592 if (main_args->enable_debugging) {
4593 mono_debug_init (MONO_DEBUG_FORMAT_MONO);
4596 assembly = mono_domain_assembly_open (main_args->domain, main_args->file);
4599 fprintf (stderr, "Can not open image %s\n", main_args->file);
4603 ves_exec (main_args->domain, assembly, main_args->argc, main_args->argv);
4607 mono_runtime_install_handlers (void)
4609 add_signal_handler (SIGSEGV, segv_handler);
4610 add_signal_handler (SIGINT, quit_handler);
4611 add_signal_handler (SIGABRT, abrt_handler);
4613 add_signal_handler (mono_thread_get_abort_signal (), thread_abort_handler);
4618 quit_function (MonoDomain *domain, gpointer user_data)
4620 mono_profiler_shutdown ();
4622 mono_runtime_cleanup (domain);
4623 mono_domain_free (domain, TRUE);
4628 mono_interp_cleanup(MonoDomain *domain)
4630 quit_function (domain, NULL);
4634 mono_interp_exec(MonoDomain *domain, MonoAssembly *assembly, int argc, char *argv[])
4636 return ves_exec (domain, assembly, argc, argv);
4640 interp_get_imt_trampoline (MonoVTable *vtable, int imt_slot_index)
4642 // FIXME: implement me
4647 interp_create_ftnptr (MonoDomain *domain, gpointer addr)
4649 // FIXME: true on all arch?
4654 mono_current_thread_has_handle_block_guard (void)
4660 mono_interp_init(const char *file)
4663 MonoRuntimeCallbacks callbacks;
4664 MonoRuntimeExceptionHandlingCallbacks ecallbacks;
4667 g_log_set_always_fatal (G_LOG_LEVEL_ERROR);
4668 g_log_set_fatal_mask (G_LOG_DOMAIN, G_LOG_LEVEL_ERROR);
4670 mono_native_tls_alloc (&thread_context_id, NULL);
4671 mono_native_tls_set_value (thread_context_id, NULL);
4672 mono_os_mutex_init_recursive (&runtime_method_lookup_section);
4673 mono_os_mutex_init_recursive (&create_method_pointer_mutex);
4675 // TODO: use callbacks?
4676 mono_runtime_install_handlers ();
4677 mono_interp_transform_init ();
4679 memset (&callbacks, 0, sizeof (callbacks));
4680 // TODO: replace with `mono_install_callbacks`
4681 callbacks.compile_method = mono_create_method_pointer;
4682 callbacks.runtime_invoke = interp_mono_runtime_invoke;
4683 callbacks.get_imt_trampoline = interp_get_imt_trampoline;
4684 callbacks.create_ftnptr = interp_create_ftnptr;
4685 #ifndef DISABLE_REMOTING
4686 mono_install_remoting_trampoline (interp_create_remoting_trampoline);
4688 callbacks.create_jit_trampoline = interp_create_trampoline;
4689 mono_install_callbacks (&callbacks);
4692 memset (&ecallbacks, 0, sizeof (ecallbacks));
4693 ecallbacks.mono_raise_exception = interp_ex_handler;
4694 ecallbacks.mono_current_thread_has_handle_block_guard = mono_current_thread_has_handle_block_guard;
4697 mono_install_stack_walk (interp_walk_stack);
4699 mono_install_eh_callbacks (&ecallbacks);
4701 mono_install_runtime_cleanup (quit_function);
4703 abort_requested = mono_thread_interruption_request_flag ();
4705 domain = mono_init_from_assembly (file, file);
4706 #ifdef __hpux /* generates very big stack frames */
4707 mono_threads_set_default_stacksize(32*1024*1024);
4710 mono_add_internal_call ("System.Diagnostics.StackFrame::get_frame_info", ves_icall_get_frame_info);
4711 mono_add_internal_call ("System.Diagnostics.StackTrace::get_trace", ves_icall_get_trace);
4712 mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers", mono_runtime_install_handlers);
4713 mono_add_internal_call ("System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal);
4715 mono_register_jit_icall (mono_thread_interruption_checkpoint, "mono_thread_interruption_checkpoint", mono_create_icall_signature ("void"), FALSE);
4717 mono_runtime_init_checked (domain, NULL, NULL, &error);
4718 mono_error_cleanup (&error); /* FIXME: don't swallow the error */
4720 mono_thread_attach (domain);
4724 typedef int (*TestMethod) (void);
4727 interp_regression_step (MonoImage *image, int verbose, int *total_run, int *total, GTimer *timer, MonoDomain *domain)
4729 int result, expected, failed, cfailed, run;
4731 double elapsed, transform_time, start_time;
4733 MonoObject *result_obj;
4734 static gboolean filter_method_init = FALSE;
4735 static gchar *filter_method = NULL;
4737 g_print ("Test run: image=%s\n", mono_image_get_filename (image));
4738 cfailed = failed = run = 0;
4739 transform_time = elapsed = 0.0;
4742 /* fixme: ugly hack - delete all previously compiled methods */
4743 if (domain_jit_info (domain)) {
4744 g_hash_table_destroy (domain_jit_info (domain)->jit_trampoline_hash);
4745 domain_jit_info (domain)->jit_trampoline_hash = g_hash_table_new (mono_aligned_addr_hash, NULL);
4746 mono_internal_hash_table_destroy (&(domain->jit_code_hash));
4747 mono_jit_code_hash_init (&(domain->jit_code_hash));
4751 g_timer_start (timer);
4752 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4754 MonoMethod *method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4756 mono_error_cleanup (&error); /* FIXME don't swallow the error */
4760 if (!filter_method_init) {
4761 filter_method = g_getenv ("INTERP_FILTER_METHOD");
4762 filter_method_init = TRUE;
4764 gboolean filter = FALSE;
4765 if (filter_method) {
4766 const char *name = filter_method;
4768 if ((strchr (name, '.') > name) || strchr (name, ':')) {
4769 MonoMethodDesc *desc = mono_method_desc_new (name, TRUE);
4770 filter = mono_method_desc_full_match (desc, method);
4771 mono_method_desc_free (desc);
4773 filter = strcmp (method->name, name) == 0;
4775 } else { // no filter
4778 if (strncmp (method->name, "test_", 5) == 0 && filter) {
4779 MonoError interp_error;
4780 RuntimeMethod *runtime_method;
4781 MonoInvocation frame;
4782 ThreadContext context;
4783 stackval frame_result;
4784 MonoObject *exc = NULL;
4786 result_obj = interp_mono_runtime_invoke (method, NULL, NULL, &exc, &interp_error);
4787 if (!mono_error_ok (&interp_error)) {
4789 g_print ("Test '%s' execution failed.\n", method->name);
4790 } else if (exc != NULL) {
4791 g_print ("Exception in Test '%s' occured:\n", method->name);
4792 mono_object_describe (exc);
4796 result = *(gint32 *) mono_object_unbox (result_obj);
4797 expected = atoi (method->name + 5); // FIXME: oh no.
4800 if (result != expected) {
4802 g_print ("Test '%s' failed result (got %d, expected %d).\n", method->name, result, expected);
4807 g_timer_stop (timer);
4808 elapsed = g_timer_elapsed (timer, NULL);
4809 if (failed > 0 || cfailed > 0){
4810 g_print ("Results: total tests: %d, failed: %d, cfailed: %d (pass: %.2f%%)\n",
4811 run, failed, cfailed, 100.0*(run-failed-cfailed)/run);
4813 g_print ("Results: total tests: %d, all pass \n", run);
4816 g_print ("Elapsed time: %f secs (%f, %f)\n\n", elapsed,
4817 elapsed - transform_time, transform_time);
4818 *total += failed + cfailed;
4822 interp_regression (MonoImage *image, int verbose, int *total_run)
4826 GTimer *timer = g_timer_new ();
4827 MonoDomain *domain = mono_domain_get ();
4828 guint32 i, exclude = 0;
4831 /* load the metadata */
4832 for (i = 0; i < mono_image_get_table_rows (image, MONO_TABLE_METHOD); ++i) {
4834 method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error);
4836 mono_error_cleanup (&error);
4839 mono_class_init (method->klass);
4844 interp_regression_step (image, verbose, total_run, &total, timer, domain);
4846 g_timer_destroy (timer);
4851 interp_regression_list (int verbose, int count, char *images [])
4853 int i, total, total_run, run;
4855 total_run = total = 0;
4856 for (i = 0; i < count; ++i) {
4857 MonoAssembly *ass = mono_assembly_open (images [i], NULL);
4859 g_warning ("failed to load assembly: %s", images [i]);
4862 total += interp_regression (mono_assembly_get_image (ass), verbose, &run);
4866 g_print ("Overall results: tests: %d, failed: %d (pass: %.2f%%)\n", total_run, total, 100.0*(total_run-total)/total_run);
4868 g_print ("Overall results: tests: %d, 100%% pass\n", total_run);