2008-01-02 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / corlib / System.Security / SecurityFrame.cs
index 2d620fd0d5123a8ad6de2520b95ce0415f00b65c..7824e0880dd768a80eefb96900e08f78ee7fc1c8 100644 (file)
@@ -31,6 +31,7 @@ using System.Globalization;
 using System.Reflection;
 using System.Runtime.CompilerServices;
 using System.Security.Permissions;
+using System.Text;
 
 namespace System.Security {
 
@@ -43,6 +44,7 @@ namespace System.Security {
 
        // Must match MonoSecurityFrame in /mono/mini/declsec.h
        internal class RuntimeSecurityFrame {
+               public AppDomain domain;
                public MethodInfo method;
                public RuntimeDeclSecurityEntry assert;
                public RuntimeDeclSecurityEntry deny;
@@ -51,6 +53,7 @@ namespace System.Security {
 
        internal struct SecurityFrame {
 
+               private AppDomain _domain;
                private MethodInfo _method;
                private PermissionSet _assert;
                private PermissionSet _deny;
@@ -64,6 +67,7 @@ namespace System.Security {
 
                internal SecurityFrame (RuntimeSecurityFrame frame)
                {
+                       _domain = null;
                        _method = null;
                        _assert = null;
                        _deny = null;
@@ -73,6 +77,7 @@ namespace System.Security {
 
                internal SecurityFrame (int skip)
                {
+                       _domain = null;
                        _method = null;
                        _assert = null;
                        _deny = null;
@@ -87,6 +92,7 @@ namespace System.Security {
                // ends up making an icall
                internal void InitFromRuntimeFrame (RuntimeSecurityFrame frame)
                {
+                       _domain = frame.domain;
                        _method = frame.method;
 
                        if (frame.assert.size > 0) {
@@ -104,6 +110,10 @@ namespace System.Security {
                        get { return _method.ReflectedType.Assembly; }
                }
 
+               public AppDomain Domain {
+                       get { return _domain; }
+               }
+
                public MethodInfo Method {
                        get { return _method; }
                }
@@ -126,6 +136,8 @@ namespace System.Security {
 
                public bool Equals (SecurityFrame sf)
                {
+                       if (!Object.ReferenceEquals (_domain, sf.Domain))
+                               return false;
                        if (Assembly.ToString () != sf.Assembly.ToString ())
                                return false;
                        if (Method.ToString () != sf.Method.ToString ())
@@ -141,12 +153,31 @@ namespace System.Security {
                        return true;
                }
 
+               public override string ToString ()
+               {
+                       StringBuilder sb = new StringBuilder ();
+                       sb.AppendFormat ("Frame: {0}{1}", _method, Environment.NewLine);
+                       sb.AppendFormat ("\tAppDomain: {0}{1}", Domain, Environment.NewLine);
+                       sb.AppendFormat ("\tAssembly: {0}{1}", Assembly, Environment.NewLine);
+                       if (_assert != null)
+                               sb.AppendFormat ("\tAssert: {0}{1}", _assert, Environment.NewLine);
+                       if (_deny != null)
+                               sb.AppendFormat ("\tDeny: {0}{1}", _deny, Environment.NewLine);
+                       if (_permitonly != null)
+                               sb.AppendFormat ("\tPermitOnly: {0}{1}", _permitonly, Environment.NewLine);
+                       return sb.ToString ();
+               }
+
                static public ArrayList GetStack (int skipFrames)
                {
                        Array stack = _GetSecurityStack (skipFrames+2);
-                       ArrayList al = new ArrayList (stack.Length);
-                       foreach (RuntimeSecurityFrame frame in stack) {
-                               al.Add (new SecurityFrame (frame));
+                       ArrayList al = new ArrayList ();
+                       for (int i = 0; i < stack.Length; i++) {
+                               object o = stack.GetValue (i);
+                               // null are unused slots allocated in the runtime
+                               if (o == null)
+                                       break;
+                               al.Add (new SecurityFrame ((RuntimeSecurityFrame)o));
                        }
                        return al;
                }