[runtime] Fix the isinst_with_cache wrapper on 64 bit platforms.
[mono.git] / mono / metadata / security-manager.c
index fb263c45ac6b992113fb3a8e4d8252c4f51b9436..9aec02998bc7334502880d57a1dc3c7d2d5a83f8 100644 (file)
@@ -4,21 +4,47 @@
  * Author:
  *     Sebastien Pouliot  <sebastien@ximian.com>
  *
- * Copyright (C) 2004-2005 Novell, Inc (http://www.novell.com)
+ * Copyright 2005-2009 Novell, Inc (http://www.novell.com)
  */
 
 #include "security-manager.h"
 
-
-/* Internal stuff */
-
-static MonoSecurityManager secman;
+static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
 static MonoBoolean mono_security_manager_activated = FALSE;
 static MonoBoolean mono_security_manager_enabled = TRUE;
 static MonoBoolean mono_security_manager_execution = TRUE;
 
+void
+mono_security_set_mode (MonoSecurityMode mode)
+{
+       mono_security_mode = mode;
+}
+
+MonoSecurityMode
+mono_security_get_mode (void)
+{
+       return mono_security_mode;
+}
+
+/*
+ * Note: The security manager is activate once when executing the Mono. This 
+ * is not meant to be a turn on/off runtime switch.
+ */
+void
+mono_activate_security_manager (void)
+{
+       mono_security_manager_activated = TRUE;
+}
+
+gboolean
+mono_is_security_manager_active (void)
+{
+       return mono_security_manager_activated;
+}
 
-/* Public stuff */
+#ifndef DISABLE_SECURITY
+
+static MonoSecurityManager secman;
 
 MonoSecurityManager*
 mono_security_manager_get_methods (void)
@@ -67,7 +93,7 @@ mono_security_manager_get_methods (void)
        g_assert (secman.linkdemandfulltrust);
 
        secman.linkdemandsecurityexception = mono_class_get_method_from_name (secman.securitymanager,
-               "LinkDemandSecurityException", 3);
+               "LinkDemandSecurityException", 2);
        g_assert (secman.linkdemandsecurityexception);
 
        secman.allowpartiallytrustedcallers = mono_class_from_name (mono_defaults.corlib, "System.Security", 
@@ -118,8 +144,7 @@ mono_secman_inheritancedemand_class (MonoClass *klass, MonoClass *parent)
                /* If so check the demands on the klass (inheritor) */
                if (!mono_secman_inheritance_check (klass, &demands)) {
                        /* Keep flags in MonoClass to be able to throw a SecurityException later (if required) */
-                       klass->exception_type = MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND;
-                       klass->exception_data = NULL;
+                       mono_class_set_failure (klass, MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND, NULL);
                }
        }
 }
@@ -143,29 +168,31 @@ mono_secman_inheritancedemand_method (MonoMethod *override, MonoMethod *base)
                /* If so check the demands on the overriding method */
                if (!mono_secman_inheritance_check (override->klass, &demands)) {
                        /* Keep flags in MonoClass to be able to throw a SecurityException later (if required) */
-                       override->klass->exception_type = MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND;
-                       override->klass->exception_data = base;
+                       mono_class_set_failure (override->klass, MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND, base);
                }
        }
 }
 
+#else
+
+MonoSecurityManager*
+mono_security_manager_get_methods (void)
+{
+       return NULL;
+}
 
-/*
- * Note: The security manager is activate once when executing the Mono. This 
- * is not meant to be a turn on/off runtime switch.
- */
 void
-mono_activate_security_manager (void)
+mono_secman_inheritancedemand_class (MonoClass *klass, MonoClass *parent)
 {
-       mono_security_manager_activated = TRUE;
 }
 
-gboolean
-mono_is_security_manager_active (void)
+void
+mono_secman_inheritancedemand_method (MonoMethod *override, MonoMethod *base)
 {
-       return mono_security_manager_activated;
 }
 
+#endif /* DISABLE_SECURITY */
+
 /*
  * @publickey  An encoded (with header) public key
  * @size       The length of the public key
@@ -223,8 +250,12 @@ mono_get_context_capture_method (void)
 MonoBoolean
 ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
 {
-       if (!mono_security_manager_activated)
-               return FALSE;
+       if (!mono_security_manager_activated) {
+               /* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
+                * (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
+                */
+               return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
+       }
        return mono_security_manager_enabled;
 }