Author: spouliot
Date: 2005-03-17 11:18:36 -0500 (Thu, 17 Mar 2005)
New Revision: 41950

Modified:
   trunk/mono/mono/mini/ChangeLog
   trunk/mono/mono/mini/declsec.c
   trunk/mono/mono/mini/mini.c
Log:
2005-03-17  Sebastien Pouliot  <[EMAIL PROTECTED]>

        * declsec.c: Renamed aptc to allowpartiallytrustedcallers.
        * mini.c: Check for p/invoke method when generating code. If a
        p/invoke method, or it's class, isn't decorated with [Suppress
        UnmanagedCodeSecurity] then generate code to call System.Security.
        UnmanagedDemand (only if the security manager is active).



Modified: trunk/mono/mono/mini/ChangeLog
===================================================================
--- trunk/mono/mono/mini/ChangeLog      2005-03-17 16:18:27 UTC (rev 41949)
+++ trunk/mono/mono/mini/ChangeLog      2005-03-17 16:18:36 UTC (rev 41950)
@@ -1,3 +1,11 @@
+2005-03-17  Sebastien Pouliot  <[EMAIL PROTECTED]>
+
+       * declsec.c: Renamed aptc to allowpartiallytrustedcallers.
+       * mini.c: Check for p/invoke method when generating code. If a
+       p/invoke method, or it's class, isn't decorated with [Suppress
+       UnmanagedCodeSecurity] then generate code to call System.Security.
+       UnmanagedDemand (only if the security manager is active).
+
 2005-03-16  Zoltan Varga  <[EMAIL PROTECTED]>
 
        * tramp-amd64.c (create_specific_trampoline): Revert parts of the 

Modified: trunk/mono/mono/mini/declsec.c
===================================================================
--- trunk/mono/mono/mini/declsec.c      2005-03-17 16:18:27 UTC (rev 41949)
+++ trunk/mono/mono/mini/declsec.c      2005-03-17 16:18:36 UTC (rev 41950)
@@ -211,7 +211,7 @@
                secman = mono_security_manager_get_methods ();
                if (secman && cinfo) {
                        /* look for AllowPartiallyTrustedCallersAttribute */
-                       result = mono_custom_attrs_has_attr (cinfo, 
secman->aptc);
+                       result = mono_custom_attrs_has_attr (cinfo, 
secman->allowpartiallytrustedcallers);
                }
                MONO_SECMAN_FLAG_SET_VALUE (assembly->aptc, result);
        }

Modified: trunk/mono/mono/mini/mini.c
===================================================================
--- trunk/mono/mono/mini/mini.c 2005-03-17 16:18:27 UTC (rev 41949)
+++ trunk/mono/mono/mini/mini.c 2005-03-17 16:18:36 UTC (rev 41950)
@@ -3166,7 +3166,8 @@
        int num_calls = 0, inline_costs = 0;
        int breakpoint_id = 0;
        guint real_offset, num_args;
-       MonoBoolean security;
+       MonoBoolean security, pinvoke;
+       MonoSecurityManager* secman = NULL;
        MonoDeclSecurityActions actions;
 
        image = method->klass->image;
@@ -3295,7 +3296,10 @@
                }
        }
 
-       security = mono_use_security_manager && mono_method_has_declsec 
(method);
+       if (mono_use_security_manager)
+               secman = mono_security_manager_get_methods ();
+
+       security = (secman && mono_method_has_declsec (method));
        /* at this point having security doesn't mean we have any code to 
generate */
        if (security && (cfg->method == method)) {
                /* Only Demand, NonCasDemand and DemandChoice requires code 
generation.
@@ -3303,8 +3307,32 @@
                 * have nothing to generate */
                security = mono_declsec_get_demands (method, &actions);
        }
+
+       /* we must Demand SecurityPermission.Unmanaged before P/Invoking */
+       pinvoke = (secman && (method->wrapper_type == 
MONO_WRAPPER_MANAGED_TO_NATIVE));
+       if (pinvoke) {
+               MonoMethod *wrapped = mono_marshal_method_from_wrapper (method);
+               if (wrapped && (wrapped->flags & 
METHOD_ATTRIBUTE_PINVOKE_IMPL)) {
+                       MonoCustomAttrInfo* custom = 
mono_custom_attrs_from_method (wrapped);
+
+                       /* unless the method or it's class has the 
[SuppressUnmanagedCodeSecurity] attribute */
+                       if (custom && mono_custom_attrs_has_attr (custom, 
secman->suppressunmanagedcodesecurity)) {
+                               pinvoke = FALSE;
+                       }
+
+                       if (pinvoke) {
+                               custom = mono_custom_attrs_from_class 
(wrapped->klass);
+                               if (custom && mono_custom_attrs_has_attr 
(custom, secman->suppressunmanagedcodesecurity)) {
+                                       pinvoke = FALSE;
+                               }
+                       }
+               } else {
+                       /* not a P/Invoke after all */
+                       pinvoke = FALSE;
+               }
+       }
        
-       if ((header->init_locals || (cfg->method == method && (cfg->opt & 
MONO_OPT_SHARED))) || mono_compile_aot || security) {
+       if ((header->init_locals || (cfg->method == method && (cfg->opt & 
MONO_OPT_SHARED))) || mono_compile_aot || security || pinvoke) {
                /* we use a separate basic block for the initialization code */
                cfg->bb_init = init_localsbb = NEW_BBLOCK (cfg);
                init_localsbb->real_offset = real_offset;
@@ -3321,7 +3349,6 @@
        /* at this point we know, if security is TRUE, that some code needs to 
be generated */
        if (security && (cfg->method == method)) {
                MonoInst *args [2];
-               MonoSecurityManager* secman = mono_security_manager_get_methods 
();
 
                mono_jit_stats.cas_demand_generation++;
 
@@ -3349,6 +3376,11 @@
                }
        }
 
+       /* we must Demand SecurityPermission.Unmanaged before p/invoking */
+       if (pinvoke) {
+               mono_emit_method_call_spilled (cfg, init_localsbb, 
secman->demandunmanaged, mono_method_signature (secman->demandunmanaged), NULL, 
ip, NULL);
+       }
+
        if (get_basic_blocks (cfg, bbhash, header, real_offset, ip, end, 
&err_pos)) {
                ip = err_pos;
                goto unverified;

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to