[corlib] Improve System.Security.Claims. Fixes #22282
[mono.git] / mono / interpreter / interp.c
index 22295a46095383fb6a41a170feff13d4efc766fc..4525ff69ab35c533d92938550de86dddec4ed887 100644 (file)
@@ -24,7 +24,7 @@
 #include <math.h>
 #include <locale.h>
 
-#include <mono/os/gc_wrapper.h>
+#include <mono/utils/gc_wrapper.h>
 
 #ifdef HAVE_ALLOCA_H
 #   include <alloca.h>
@@ -249,12 +249,12 @@ ves_real_abort (int line, MonoMethod *mh,
        } while (0);
 
 static gpointer
-interp_create_remoting_trampoline (MonoMethod *method)
+interp_create_remoting_trampoline (MonoMethod *method, MonoRemotingTarget target)
 {
-       return mono_interp_get_runtime_method (mono_marshal_get_remoting_invoke (method));
+       return mono_interp_get_runtime_method (mono_marshal_get_remoting_invoke_for_target (method, target));
 }
 
-static CRITICAL_SECTION runtime_method_lookup_section;
+static mono_mutex_t runtime_method_lookup_section;
 
 RuntimeMethod*
 mono_interp_get_runtime_method (MonoMethod *method)
@@ -262,19 +262,19 @@ mono_interp_get_runtime_method (MonoMethod *method)
        MonoDomain *domain = mono_domain_get ();
        RuntimeMethod *rtm;
 
-       EnterCriticalSection (&runtime_method_lookup_section);
-       if ((rtm = g_hash_table_lookup (domain->jit_code_hash, method))) {
-               LeaveCriticalSection (&runtime_method_lookup_section);
+       mono_mutex_lock (&runtime_method_lookup_section);
+       if ((rtm = mono_internal_hash_table_lookup (&domain->jit_code_hash, method))) {
+               mono_mutex_unlock (&runtime_method_lookup_section);
                return rtm;
        }
        rtm = mono_mempool_alloc (domain->mp, sizeof (RuntimeMethod));
        memset (rtm, 0, sizeof (*rtm));
        rtm->method = method;
-       rtm->param_count = method->signature->param_count;
-       rtm->hasthis = method->signature->hasthis;
+       rtm->param_count = mono_method_signature (method)->param_count;
+       rtm->hasthis = mono_method_signature (method)->hasthis;
        rtm->valuetype = method->klass->valuetype;
-       g_hash_table_insert (domain->jit_code_hash, method, rtm);
-       LeaveCriticalSection (&runtime_method_lookup_section);
+       mono_internal_hash_table_insert (&domain->jit_code_hash, method, rtm);
+       mono_mutex_unlock (&runtime_method_lookup_section);
 
        return rtm;
 }
@@ -578,7 +578,7 @@ ves_array_set (MonoInvocation *frame)
        esize = mono_array_element_size (ac);
        ea = mono_array_addr_with_size (ao, esize, pos);
 
-       mt = frame->runtime_method->method->signature->params [ac->rank];
+       mt = mono_method_signature (frame->runtime_method->method)->params [ac->rank];
        stackval_to_data (mt, &sp [ac->rank], ea, FALSE);
 }
 
@@ -622,7 +622,7 @@ ves_array_get (MonoInvocation *frame)
        esize = mono_array_element_size (ac);
        ea = mono_array_addr_with_size (ao, esize, pos);
 
-       mt = frame->runtime_method->method->signature->ret;
+       mt = mono_method_signature (frame->runtime_method->method)->ret;
        stackval_from_data (mt, frame->retval, ea, FALSE);
 }
 
@@ -833,7 +833,7 @@ dump_stack (stackval *stack, stackval *sp)
                return g_string_free (str, FALSE);
        
        while (s < sp) {
-               g_string_sprintfa (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
+               g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
                ++s;
        }
        return g_string_free (str, FALSE);
@@ -851,7 +851,7 @@ dump_stackval (GString *str, stackval *s, MonoType *type)
        case MONO_TYPE_U4:
        case MONO_TYPE_CHAR:
        case MONO_TYPE_BOOLEAN:
-               g_string_sprintfa (str, "[%d] ", s->data.i);
+               g_string_append_printf (str, "[%d] ", s->data.i);
                break;
        case MONO_TYPE_STRING:
        case MONO_TYPE_SZARRAY:
@@ -861,22 +861,22 @@ dump_stackval (GString *str, stackval *s, MonoType *type)
        case MONO_TYPE_PTR:
        case MONO_TYPE_I:
        case MONO_TYPE_U:
-               g_string_sprintfa (str, "[%p] ", s->data.p);
+               g_string_append_printf (str, "[%p] ", s->data.p);
                break;
        case MONO_TYPE_VALUETYPE:
                if (type->data.klass->enumtype)
-                       g_string_sprintfa (str, "[%d] ", s->data.i);
+                       g_string_append_printf (str, "[%d] ", s->data.i);
                else
-                       g_string_sprintfa (str, "[vt:%p] ", s->data.p);
+                       g_string_append_printf (str, "[vt:%p] ", s->data.p);
                break;
        case MONO_TYPE_R4:
        case MONO_TYPE_R8:
-               g_string_sprintfa (str, "[%g] ", s->data.f);
+               g_string_append_printf (str, "[%g] ", s->data.f);
                break;
        case MONO_TYPE_I8:
        case MONO_TYPE_U8:
        default:
-               g_string_sprintfa (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
+               g_string_append_printf (str, "[%lld/0x%0llx] ", s->data.l, s->data.l);
                break;
        }
 }
@@ -886,13 +886,13 @@ dump_args (MonoInvocation *inv)
 {
        GString *str = g_string_new ("");
        int i;
-       MonoMethodSignature *signature = inv->runtime_method->method->signature;
+       MonoMethodSignature *signature = mono_method_signature (inv->runtime_method->method);
        
        if (signature->param_count == 0)
                return g_string_free (str, FALSE);
 
        if (signature->hasthis)
-               g_string_sprintfa (str, "%p ", inv->obj);
+               g_string_append_printf (str, "%p ", inv->obj);
 
        for (i = 0; i < signature->param_count; ++i)
                dump_stackval (str, inv->stack_args + i, signature->params [i]);
@@ -904,7 +904,7 @@ static char*
 dump_retval (MonoInvocation *inv)
 {
        GString *str = g_string_new ("");
-       MonoType *ret = inv->runtime_method->method->signature->ret;
+       MonoType *ret = mono_method_signature (inv->runtime_method->method)->ret;
 
        if (ret->type != MONO_TYPE_VOID)
                dump_stackval (str, inv->retval, ret);
@@ -947,10 +947,10 @@ dump_frame (MonoInvocation *inv)
                        args = dump_args (inv);
                        name = mono_method_full_name (method, TRUE);
                        if (source)
-                               g_string_sprintfa (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname,
+                               g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s) at %s\n", i, codep, opname,
                                                   name, args, source);
                        else
-                               g_string_sprintfa (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname,
+                               g_string_append_printf (str, "#%d: 0x%05x %-10s in %s (%s)\n", i, codep, opname,
                                                   name, args);
                        g_free (name);
                        g_free (args);
@@ -1071,7 +1071,7 @@ interp_mono_runtime_invoke (MonoMethod *method, void *obj, void **params, MonoOb
        MonoInvocation frame;
        ThreadContext * volatile context = TlsGetValue (thread_context_id);
        MonoObject *retval = NULL;
-       MonoMethodSignature *sig = method->signature;
+       MonoMethodSignature *sig = mono_method_signature (method);
        MonoClass *klass = mono_class_from_mono_type (sig->ret);
        int i, type, isobject = 0;
        void *ret = NULL;
@@ -1239,6 +1239,11 @@ do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
        context->managed_code = 0;
 
        switch (op) {
+       case MINT_ICALL_V_V: {
+               void (*func)() = ptr;
+               func ();
+               break;
+       }
        case MINT_ICALL_P_V: {
                void (*func)(gpointer) = ptr;
                func (sp [-1].data.p);
@@ -1296,7 +1301,7 @@ do_icall (ThreadContext *context, int op, stackval *sp, gpointer ptr)
        return sp;
 }
 
-static CRITICAL_SECTION create_method_pointer_mutex;
+static mono_mutex_t create_method_pointer_mutex;
 
 static MonoGHashTable *method_pointer_hash = NULL;
 
@@ -1306,14 +1311,14 @@ mono_create_method_pointer (MonoMethod *method)
        gpointer addr;
        MonoJitInfo *ji;
 
-       EnterCriticalSection (&create_method_pointer_mutex);
+       mono_mutex_lock (&create_method_pointer_mutex);
        if (!method_pointer_hash) {
                MONO_GC_REGISTER_ROOT (method_pointer_hash);
                method_pointer_hash = mono_g_hash_table_new (NULL, NULL);
        }
        addr = mono_g_hash_table_lookup (method_pointer_hash, method);
        if (addr) {
-               LeaveCriticalSection (&create_method_pointer_mutex);
+               mono_mutex_unlock (&create_method_pointer_mutex);
                return addr;
        }
 
@@ -1333,7 +1338,7 @@ mono_create_method_pointer (MonoMethod *method)
                addr = mono_arch_create_method_pointer (method);
 
        mono_g_hash_table_insert (method_pointer_hash, method, addr);
-       LeaveCriticalSection (&create_method_pointer_mutex);
+       mono_mutex_unlock (&create_method_pointer_mutex);
 
        return addr;
 }
@@ -1858,7 +1863,7 @@ ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
                        MINT_IN_BREAK;
                }
                MINT_IN_CASE(MINT_CALLINT)
-                       ves_pinvoke_method (frame, frame->runtime_method->method->signature, ((MonoMethodPInvoke*) frame->runtime_method->method)->addr, 
+                       ves_pinvoke_method (frame, mono_method_signature (frame->runtime_method->method), ((MonoMethodPInvoke*) frame->runtime_method->method)->addr, 
                                    frame->runtime_method->method->string_ctor, context);
                        if (frame->ex) {
                                rtm = NULL;
@@ -2572,7 +2577,7 @@ ves_exec_method_with_context (MonoInvocation *frame, ThreadContext *context)
                        ip += 2;
 
                        child_frame.runtime_method = rtm->data_items [token];
-                       csig = child_frame.runtime_method->method->signature;
+                       csig = mono_method_signature (child_frame.runtime_method->method);
                        newobj_class = child_frame.runtime_method->method->klass;
                        /*if (profiling_classes) {
                                guint count = GPOINTER_TO_UINT (g_hash_table_lookup (profiling_classes, newobj_class));
@@ -2770,6 +2775,7 @@ array_constructed:
                        MINT_IN_BREAK;
 
                MINT_IN_CASE(MINT_LDRMFLD) {
+                       gpointer tmp;
                        MonoClassField *field;
                        char *addr;
 
@@ -2780,7 +2786,8 @@ array_constructed:
                        ip += 2;
                        if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
                                MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
-                               addr = mono_load_remote_field (o, klass, field, NULL);
+
+                               addr = mono_load_remote_field (o, klass, field, &tmp);
                        } else {
                                addr = (char*)o + field->offset;
                        }                               
@@ -2792,6 +2799,7 @@ array_constructed:
                MINT_IN_CASE(MINT_LDRMFLD_VT) {
                        MonoClassField *field;
                        char *addr;
+                       gpointer tmp;
 
                        o = sp [-1].data.p;
                        if (!o)
@@ -2801,7 +2809,7 @@ array_constructed:
                        ip += 4;
                        if (o->vtable->klass == mono_defaults.transparent_proxy_class) {
                                MonoClass *klass = ((MonoTransparentProxy*)o)->remote_class->proxy_class;
-                               addr = mono_load_remote_field (o, klass, field, NULL);
+                               addr = mono_load_remote_field (o, klass, field, &tmp);
                        } else {
                                addr = (char*)o + field->offset;
                        }                               
@@ -3488,6 +3496,7 @@ array_constructed:
                        }
                        goto handle_finally;
                        MINT_IN_BREAK;
+               MINT_IN_CASE(MINT_ICALL_V_V) 
                MINT_IN_CASE(MINT_ICALL_P_V) 
                MINT_IN_CASE(MINT_ICALL_P_P)
                MINT_IN_CASE(MINT_ICALL_PP_V)
@@ -3519,7 +3528,8 @@ array_constructed:
                MINT_IN_CASE(MINT_MONO_RETOBJ)
                        ++ip;
                        sp--;
-                       stackval_from_data (frame->runtime_method->method->signature->ret, frame->retval, sp->data.p, frame->runtime_method->method->signature->pinvoke);
+                       stackval_from_data (mono_method_signature (frame->runtime_method->method)->ret, frame->retval, sp->data.p,
+                            mono_method_signature (frame->runtime_method->method)->pinvoke);
                        if (sp > frame->stack)
                                g_warning ("retobj: more values on stack: %d", sp-frame->stack);
                        goto exit_frame;
@@ -3892,7 +3902,7 @@ array_constructed:
                                clause = &inv->runtime_method->clauses [i];
                                if (clause->flags <= 1 && MONO_OFFSET_IN_CLAUSE (clause, ip_offset)) {
                                        if (!clause->flags) {
-                                               if (mono_object_isinst ((MonoObject*)frame->ex, mono_class_get (method->klass->image, clause->token_or_filter))) {
+                                               if (mono_object_isinst ((MonoObject*)frame->ex, clause->data.catch_class)) {
                                                        /* 
                                                         * OK, we found an handler, now we need to execute the finally
                                                         * and fault blocks before branching to the handler code.
@@ -4138,7 +4148,7 @@ test_load_class (MonoImage* image)
 static void
 add_signal_handler (int signo, void (*handler)(int))
 {
-#ifdef PLATFORM_WIN32
+#ifdef HOST_WIN32
        signal (signo, handler);
 #else
        struct sigaction sa;
@@ -4384,8 +4394,8 @@ mono_interp_init(const char *file)
 
        thread_context_id = TlsAlloc ();
        TlsSetValue (thread_context_id, NULL);
-       InitializeCriticalSection (&runtime_method_lookup_section);
-       InitializeCriticalSection (&create_method_pointer_mutex);
+       mono_mutex_init_recursive (&runtime_method_lookup_section);
+       mono_mutex_init_recursive (&create_method_pointer_mutex);
 
        mono_runtime_install_handlers ();
        mono_interp_transform_init ();
@@ -4396,21 +4406,24 @@ mono_interp_init(const char *file)
 
        mono_install_handler (interp_ex_handler);
        mono_install_stack_walk (interp_walk_stack);
-       mono_runtime_install_cleanup (quit_function);
+       mono_install_runtime_cleanup (quit_function);
        abort_requested = mono_thread_interruption_request_flag ();
 
        domain = mono_init_from_assembly (file, file);
 #ifdef __hpux /* generates very big stack frames */
        mono_threads_set_default_stacksize(32*1024*1024);
 #endif
-       mono_init_icall ();
+       mono_icall_init ();
        mono_add_internal_call ("System.Diagnostics.StackFrame::get_frame_info", ves_icall_get_frame_info);
        mono_add_internal_call ("System.Diagnostics.StackTrace::get_trace", ves_icall_get_trace);
        mono_add_internal_call ("Mono.Runtime::mono_runtime_install_handlers", mono_runtime_install_handlers);
        mono_add_internal_call ("System.Delegate::CreateDelegate_internal", ves_icall_System_Delegate_CreateDelegate_internal);
 
+       mono_register_jit_icall (mono_thread_interruption_checkpoint, "mono_thread_interruption_checkpoint", mono_create_icall_signature ("void"), FALSE);
+
        mono_runtime_init (domain, NULL, NULL);
 
+
        mono_thread_attach (domain);
        return domain;
 }
@@ -4450,11 +4463,6 @@ mono_main (int argc, char *argv [])
                        mono_profiler_load (NULL);
                if (strcmp (argv [i], "--config") == 0)
                        config_file = argv [++i];
-               if (strcmp (argv [i], "--workers") == 0) {
-                       mono_max_worker_threads = atoi (argv [++i]);
-                       if (mono_max_worker_threads < 1)
-                               mono_max_worker_threads = 1;
-               }
                if (strcmp (argv [i], "--help") == 0)
                        usage ();
 #if DEBUG_INTERP