diff options
author | Ankit Jain <radical@corewars.org> | 2006-05-26 14:43:30 +0400 |
---|---|---|
committer | Ankit Jain <radical@corewars.org> | 2006-05-26 14:43:30 +0400 |
commit | c366948a9b5e1892118bf0e6b9a86f6b0150cccc (patch) | |
tree | cdef5cbb0dee5fca36fdf4d15c167affd1d0178a /mcs/ilasm | |
parent | bea5feb644aab489a67a64a5ea2c0cc774a3b879 (diff) |
Add support or 2.0 style declarative security attributes.
In ilasm/tests:
* test-perm_pass-3.il: New. Test for 2.0 style declarative security
attributes.
In ilasm/codegen:
* PermissionSet.cs: New.
* Permission.cs: New.
* PermissionMember.cs: New. Classes for 2.0 metadata format of
declarative security.
* DeclSecurity.cs (DeclSecurity.AddPermissionSet): New. Overload for new
PermissionSet class.
(DeclSecurity.AddTo): Add new style PermissionSets also.
* CodeGen.cs (CodeGen.AddPermisson): Handle new PermissionSets also.
* ExternTable.cs (ExternAssembly.AssemblyName): New.
In ilasm/scanner:
* ILTables.cs (keywords): Move 'property' out of NET_2_0 .
In ilasm/parser:
Add support or 2.0 style declarative security attributes.
* ILParser.jay (primitive_type): New. Extracted from 'type'.
(field_init_primitive): New. Extracted from 'field_init', with all
primitive types.
(sec_decl | ..): New rule for 2.0 style permissions.
(permissions):
(permission):
(permission_members):
(permission_member):
(perm_mbr_nameval_pair):
(prop_or_field): New rules for 2.0 style permissions.
(AddSecDecl): New.
In class/PEAPI:
* Metadata.cs (DeclSecurity): Rename to ..
(BaseDeclSecurity): .. this.
(DeclSecurity): New. Derive from BaseDeclSecurity.
(DeclSecurity_20): Likewise. For 2.0 style declaritive security.
(PermissionSet): New.
(Permission): New.
(PermissionMember): New.
(MetaData.AddDeclSecurity): Update to use BaseDeclSecurity.
(MetaData.BuildMetaData): Likewise.
* PEAPI.cs (PEFile.AddDeclSecurity): New overload for new PermissionSet
class.
svn path=/trunk/mcs/; revision=61158
Diffstat (limited to 'mcs/ilasm')
-rw-r--r-- | mcs/ilasm/codegen/ChangeLog | 13 | ||||
-rw-r--r-- | mcs/ilasm/codegen/CodeGen.cs | 35 | ||||
-rw-r--r-- | mcs/ilasm/codegen/DeclSecurity.cs | 56 | ||||
-rw-r--r-- | mcs/ilasm/codegen/ExternTable.cs | 12 | ||||
-rw-r--r-- | mcs/ilasm/codegen/Permission.cs | 81 | ||||
-rw-r--r-- | mcs/ilasm/codegen/PermissionMember.cs | 60 | ||||
-rw-r--r-- | mcs/ilasm/codegen/PermissionSet.cs | 67 | ||||
-rw-r--r-- | mcs/ilasm/ilasm.exe.sources | 3 | ||||
-rw-r--r-- | mcs/ilasm/parser/ChangeLog | 17 | ||||
-rw-r--r-- | mcs/ilasm/parser/ILParser.jay | 181 | ||||
-rw-r--r-- | mcs/ilasm/scanner/ChangeLog | 4 | ||||
-rw-r--r-- | mcs/ilasm/scanner/ILTables.cs | 2 | ||||
-rw-r--r-- | mcs/ilasm/tests/ChangeLog | 5 | ||||
-rw-r--r-- | mcs/ilasm/tests/test-perm_pass-3.il | 60 |
14 files changed, 537 insertions, 59 deletions
diff --git a/mcs/ilasm/codegen/ChangeLog b/mcs/ilasm/codegen/ChangeLog index e47bf30af71..ff553c38b79 100644 --- a/mcs/ilasm/codegen/ChangeLog +++ b/mcs/ilasm/codegen/ChangeLog @@ -1,3 +1,16 @@ +2006-05-26 Ankit Jain <jankit@novell.com> + + * PermissionSet.cs: New. + * Permission.cs: New. + * PermissionMember.cs: New. Classes for 2.0 metadata format of + declarative security. + + * DeclSecurity.cs (DeclSecurity.AddPermissionSet): New. Overload for new + PermissionSet class. + (DeclSecurity.AddTo): Add new style PermissionSets also. + * CodeGen.cs (CodeGen.AddPermisson): Handle new PermissionSets also. + * ExternTable.cs (ExternAssembly.AssemblyName): New. + 2006-05-23 Ankit Jain <jankit@novell.com> * DeclSecurity.cs (IDeclSecurityTarget): Remove AddPermission & diff --git a/mcs/ilasm/codegen/CodeGen.cs b/mcs/ilasm/codegen/CodeGen.cs index eab7668acac..5971e442139 100644 --- a/mcs/ilasm/codegen/CodeGen.cs +++ b/mcs/ilasm/codegen/CodeGen.cs @@ -18,6 +18,8 @@ using System.Reflection.Emit; using System.Text;
using System.Security;
+using SSPermissionSet = System.Security.PermissionSet;
+using MIPermissionSet = Mono.ILASM.PermissionSet;
namespace Mono.ILASM {
@@ -462,11 +464,7 @@ namespace Mono.ILASM { if (assembly_declsec == null)
assembly_declsec = new DeclSecurity ();
- PermissionSet ps = perm as PermissionSet;
- if (ps == null)
- assembly_declsec.AddPermission (sec_action, (IPermission) perm);
- else
- assembly_declsec.AddPermissionSet (sec_action, ps);
+ AddPermission (sec_action, perm, assembly_declsec);
}
public void AddPermission (PEAPI.SecurityAction sec_action, object perm)
@@ -474,11 +472,28 @@ namespace Mono.ILASM { if (CurrentDeclSecurityTarget == null)
return;
- PermissionSet ps = perm as PermissionSet;
- if (ps == null)
- CurrentDeclSecurityTarget.DeclSecurity.AddPermission (sec_action, (IPermission) perm);
- else
- CurrentDeclSecurityTarget.DeclSecurity.AddPermissionSet (sec_action, ps);
+ AddPermission (sec_action, perm, CurrentDeclSecurityTarget.DeclSecurity);
+ }
+
+ private void AddPermission (PEAPI.SecurityAction sec_action, object perm, DeclSecurity decl_sec)
+ {
+ SSPermissionSet ps = perm as SSPermissionSet;
+ if (ps != null) {
+ decl_sec.AddPermissionSet (sec_action, ps);
+ return;
+ }
+
+ IPermission iper = perm as IPermission;
+ if (iper != null) {
+ decl_sec.AddPermission (sec_action, iper);
+ return;
+ }
+
+ MIPermissionSet ps20 = perm as MIPermissionSet;
+ if (ps20 != null) {
+ decl_sec.AddPermissionSet (sec_action, ps20);
+ return;
+ }
}
public void Write ()
diff --git a/mcs/ilasm/codegen/DeclSecurity.cs b/mcs/ilasm/codegen/DeclSecurity.cs index 66e5e9338f6..c318a0f7180 100644 --- a/mcs/ilasm/codegen/DeclSecurity.cs +++ b/mcs/ilasm/codegen/DeclSecurity.cs @@ -13,6 +13,9 @@ using System.Collections; using System.Security; using System.Security.Permissions; +using SSPermissionSet = System.Security.PermissionSet; +using MIPermissionSet = Mono.ILASM.PermissionSet; + namespace Mono.ILASM { public interface IDeclSecurityTarget { @@ -22,6 +25,7 @@ namespace Mono.ILASM { public class DeclSecurity { private Hashtable permissionset_table; + private Hashtable permissionset20_table; public DeclSecurity () { @@ -30,18 +34,18 @@ namespace Mono.ILASM { public void AddPermission (PEAPI.SecurityAction sec_action, IPermission perm) { - PermissionSet ps = (PermissionSet) permissionset_table [sec_action]; + SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action]; if (ps == null) { - ps = new PermissionSet (PermissionState.None); + ps = new SSPermissionSet (PermissionState.None); permissionset_table [sec_action] = ps; } ps.AddPermission (perm); } - public void AddPermissionSet (PEAPI.SecurityAction sec_action, PermissionSet perm_set) + public void AddPermissionSet (PEAPI.SecurityAction sec_action, SSPermissionSet perm_set) { - PermissionSet ps = (PermissionSet) permissionset_table [sec_action]; + SSPermissionSet ps = (SSPermissionSet) permissionset_table [sec_action]; if (ps == null) { permissionset_table [sec_action] = perm_set; return; @@ -50,14 +54,50 @@ namespace Mono.ILASM { foreach (IPermission iper in perm_set) ps.AddPermission (iper); } - + + //Not called by parser for profile != NET_2_0 + public void AddPermissionSet (PEAPI.SecurityAction sec_action, MIPermissionSet perm_set) + { + PermissionSet ps = null; + + if (permissionset20_table == null) + permissionset20_table = new Hashtable (); + else + ps = (MIPermissionSet) permissionset20_table [sec_action]; + + if (ps == null) { + permissionset20_table [sec_action] = perm_set; + return; + } + + foreach (Permission perm in perm_set.Permissions) + ps.AddPermission (perm); + } + public void AddTo (CodeGen code_gen, PEAPI.MetaDataElement elem) { System.Text.UnicodeEncoding ue = new System.Text.UnicodeEncoding (); - foreach (PEAPI.SecurityAction sec_action in permissionset_table.Keys) - code_gen.PEFile.AddDeclSecurity (sec_action, - ue.GetBytes (((PermissionSet) permissionset_table [sec_action]).ToXml ().ToString ()), + foreach (DictionaryEntry entry in permissionset_table) { + PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key; + SSPermissionSet ps = (SSPermissionSet) entry.Value; + + code_gen.PEFile.AddDeclSecurity (sec_action, + ue.GetBytes (ps.ToXml ().ToString ()), + elem); + } + + if (permissionset20_table == null) + return; + + foreach (DictionaryEntry entry in permissionset20_table) { + PEAPI.SecurityAction sec_action = (PEAPI.SecurityAction) entry.Key; + MIPermissionSet ps = (MIPermissionSet) entry.Value; + + code_gen.PEFile.AddDeclSecurity (sec_action, + ps.Resolve (code_gen), elem); + } + } } diff --git a/mcs/ilasm/codegen/ExternTable.cs b/mcs/ilasm/codegen/ExternTable.cs index 7d4dd7da229..69cb3c0eaa9 100644 --- a/mcs/ilasm/codegen/ExternTable.cs +++ b/mcs/ilasm/codegen/ExternTable.cs @@ -11,6 +11,7 @@ using System; using System.Collections; using System.Reflection; using System.Security; +using System.Globalization; namespace Mono.ILASM { @@ -144,10 +145,12 @@ namespace Mono.ILASM { private string locale; private byte [] hash; private DeclSecurity decl_sec; + private AssemblyName asmb_name; public ExternAssembly (string name, AssemblyName asmb_name) : base (name) { this.name = name; + this.asmb_name = asmb_name; major = minor = build = revision = -1; } @@ -159,6 +162,10 @@ namespace Mono.ILASM { } } + public AssemblyName AssemblyName { + get { return asmb_name; } + } + public DeclSecurity DeclSecurity { get { if (decl_sec == null) @@ -207,21 +214,26 @@ namespace Mono.ILASM { this.minor = minor; this.build = build; this.revision = revision; + asmb_name.Version = new Version (major, minor, build, revision); } public void SetPublicKey (byte [] public_key) { this.public_key = public_key; + asmb_name.SetPublicKey (public_key); } public void SetPublicKeyToken (byte [] public_key_token) { this.public_key_token = public_key_token; + asmb_name.SetPublicKey (public_key); } public void SetLocale (string locale) { this.locale = locale; + //FIXME: is this correct? + asmb_name.CultureInfo = new CultureInfo (locale); } public void SetHash (byte [] hash) diff --git a/mcs/ilasm/codegen/Permission.cs b/mcs/ilasm/codegen/Permission.cs new file mode 100644 index 00000000000..4338646d792 --- /dev/null +++ b/mcs/ilasm/codegen/Permission.cs @@ -0,0 +1,81 @@ +// +// Mono.ILASM.Permission +// +// Author(s): +// Ankit Jain <JAnkit@novell.com> +// +// Copyright (C) 2006 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System; +using System.Collections; + +namespace Mono.ILASM { + + public class Permission + { + BaseTypeRef type_ref; + + //PermissionMembers + ArrayList members; + PEAPI.Permission perm; + + public Permission (BaseTypeRef type_ref, ArrayList members) + { + this.type_ref = type_ref; + this.members = members; + } + + public PEAPI.Permission Resolve (CodeGen code_gen) + { + string fname; + + type_ref.Resolve (code_gen); + + if (type_ref is ExternTypeRef) { + ExternAssembly ea = ((ExternTypeRef) type_ref).ExternRef as ExternAssembly; + if (ea == null) + //FIXME: module.. ? + throw new NotImplementedException (); + + string name; + ExternTypeRef etr = type_ref as ExternTypeRef; + if (etr != null) + name = etr.Name; + else + name = type_ref.FullName; + + fname = String.Format ("{0}, {1}", name, ea.AssemblyName.FullName); + } else { + fname = type_ref.FullName; + } + + perm = new PEAPI.Permission (type_ref.PeapiType, fname); + + foreach (PermissionMember member in members) + perm.AddMember (member.Resolve (code_gen)); + + return perm; + } + } + +} diff --git a/mcs/ilasm/codegen/PermissionMember.cs b/mcs/ilasm/codegen/PermissionMember.cs new file mode 100644 index 00000000000..fad69eda984 --- /dev/null +++ b/mcs/ilasm/codegen/PermissionMember.cs @@ -0,0 +1,60 @@ +// +// Mono.ILASM.PermissionMember +// +// Author(s): +// Ankit Jain <JAnkit@novell.com> +// +// Copyright (C) 2006 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Reflection; + +namespace Mono.ILASM { + + public class PermissionMember { + + MemberTypes member_type; + BaseTypeRef type_ref; + string name; + object value; + + PEAPI.PermissionMember member; + + public PermissionMember (MemberTypes member_type, BaseTypeRef type_ref, string name, object value) + { + this.member_type = member_type; + this.type_ref = type_ref; + this.name = name; + this.value = value; + } + + public PEAPI.PermissionMember Resolve (CodeGen code_gen) + { + type_ref.Resolve (code_gen); + + member = new PEAPI.PermissionMember (member_type, type_ref.PeapiType, name, value); + + return member; + } + } + +} diff --git a/mcs/ilasm/codegen/PermissionSet.cs b/mcs/ilasm/codegen/PermissionSet.cs new file mode 100644 index 00000000000..95661661ce2 --- /dev/null +++ b/mcs/ilasm/codegen/PermissionSet.cs @@ -0,0 +1,67 @@ +// +// Mono.ILASM.PermissionSet +// +// Author(s): +// Ankit Jain <JAnkit@novell.com> +// +// Copyright (C) 2006 Novell, Inc (http://www.novell.com) +// +// Permission is hereby granted, free of charge, to any person obtaining +// a copy of this software and associated documentation files (the +// "Software"), to deal in the Software without restriction, including +// without limitation the rights to use, copy, modify, merge, publish, +// distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to +// the following conditions: +// +// The above copyright notice and this permission notice shall be +// included in all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +// + +using System.Collections; + +namespace Mono.ILASM { + + public class PermissionSet + { + PEAPI.SecurityAction sec_action; + ArrayList permissions; + PEAPI.PermissionSet ps; + + public PermissionSet (PEAPI.SecurityAction sec_action, ArrayList permissions) + { + this.sec_action = sec_action; + this.permissions = permissions; + } + + public ArrayList Permissions { + get { return permissions; } + } + + public PEAPI.SecurityAction SecurityAction { + get { return sec_action; } + } + + public void AddPermission (Permission perm) + { + permissions.Add (perm); + } + + public PEAPI.PermissionSet Resolve (CodeGen code_gen) + { + ps = new PEAPI.PermissionSet (sec_action); + foreach (Permission perm in permissions) + ps.AddPermission (perm.Resolve (code_gen)); + + return ps; + } + } +} diff --git a/mcs/ilasm/ilasm.exe.sources b/mcs/ilasm/ilasm.exe.sources index a2e78f04df7..8a82cc9b921 100644 --- a/mcs/ilasm/ilasm.exe.sources +++ b/mcs/ilasm/ilasm.exe.sources @@ -1,6 +1,9 @@ Driver.cs Report.cs AssemblyInfo.cs +codegen/PermissionMember.cs +codegen/PermissionSet.cs +codegen/Permission.cs codegen/CodeGen.cs codegen/Module.cs codegen/DebuggingInfo.cs diff --git a/mcs/ilasm/parser/ChangeLog b/mcs/ilasm/parser/ChangeLog index 81c42a50d95..87fde52d96f 100644 --- a/mcs/ilasm/parser/ChangeLog +++ b/mcs/ilasm/parser/ChangeLog @@ -1,3 +1,20 @@ +2006-05-26 Ankit Jain <jankit@novell.com> + + Add support or 2.0 style declarative security attributes. + * ILParser.jay (primitive_type): New. Extracted from 'type'. + (field_init_primitive): New. Extracted from 'field_init', with all + primitive types. + (sec_decl | ..): New rule for 2.0 style permissions. + + (permissions): + (permission): + (permission_members): + (permission_member): + (perm_mbr_nameval_pair): + (prop_or_field): New rules for 2.0 style permissions. + + (AddSecDecl): New. + 2006-05-11 Ankit Jain <jankit@novell.com> * ILParser.jay (type |type MODREQ ..): Use CustomModifier.modreq . diff --git a/mcs/ilasm/parser/ILParser.jay b/mcs/ilasm/parser/ILParser.jay index c19ae452b55..bf04b9b150a 100644 --- a/mcs/ilasm/parser/ILParser.jay +++ b/mcs/ilasm/parser/ILParser.jay @@ -15,6 +15,9 @@ using System.Reflection; using System.Security;
using System.Security.Permissions;
+using MIPermission = Mono.ILASM.Permission;
+using MIPermissionSet = Mono.ILASM.PermissionSet;
+
namespace Mono.ILASM {
public class ILParser {
@@ -64,6 +67,22 @@ namespace Mono.ILASM { return true;
}
+ public void AddSecDecl (object perm)
+ {
+ PermPair pp = perm as PermPair;
+
+ if (pp == null) {
+ MIPermissionSet ps_20 = (MIPermissionSet) perm;
+ codegen.AddPermission (ps_20.SecurityAction, ps_20);
+ return;
+ }
+
+ if (!CheckSecurityActionValidity ((System.Security.Permissions.SecurityAction) pp.sec_action, false))
+ Report.Error (String.Format ("Invalid security action : {0}", pp.sec_action));
+
+ codegen.AddPermission (pp.sec_action, pp.perm);
+ }
+
public object ClassRefToObject (object class_ref, object val)
{
ExternTypeRef etr = class_ref as ExternTypeRef;
@@ -850,11 +869,7 @@ class_decl : method_all | data_decl
| sec_decl
{
- PermPair pp = (PermPair) $1;
- if (!CheckSecurityActionValidity ((System.Security.Permissions.SecurityAction) (short) pp.sec_action, false))
- Report.Error (String.Format ("Invalid security action : {0}", pp.sec_action));
-
- codegen.AddPermission (pp.sec_action, pp.perm);
+ AddSecDecl ($1);
}
| extsource_spec
| customattr_decl
@@ -907,10 +922,6 @@ type : generic_class_ref {
$$ = new PrimitiveTypeRef (PrimitiveType.Object, "System.Object");
}
- | K_STRING
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.String, "System.String");
- }
| K_VALUE K_CLASS class_ref
{
BaseClassRef class_ref = (BaseClassRef) $3;
@@ -985,28 +996,12 @@ type : generic_class_ref {
$$ = new MethodPointerTypeRef ((CallConv) $2, (BaseTypeRef) $3, (ArrayList) $6);
}
- | K_TYPEDREF
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef,
- "System.TypedReference");
- }
- | K_CHAR
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
- }
- | K_WCHAR
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
- }
- | K_VOID
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void");
- }
- | K_BOOL
- {
- $$ = new PrimitiveTypeRef (PrimitiveType.Boolean, "System.Boolean");
- }
- | K_INT8
+ | primitive_type
+ ;
+
+ ;
+
+primitive_type : K_INT8
{
$$ = new PrimitiveTypeRef (PrimitiveType.Int8, "System.SByte");
}
@@ -1046,7 +1041,6 @@ type : generic_class_ref {
$$ = new PrimitiveTypeRef (PrimitiveType.UInt16, "System.UInt16");
}
-
| K_UNSIGNED K_INT32
{
$$ = new PrimitiveTypeRef (PrimitiveType.UInt32, "System.UInt32");
@@ -1068,7 +1062,6 @@ type : generic_class_ref // TODO: Is this the proper full name
$$ = new PrimitiveTypeRef (PrimitiveType.NativeInt, "System.IntPtr");
}
-
| K_NATIVE K_UNSIGNED K_INT
{
$$ = new PrimitiveTypeRef (PrimitiveType.NativeUInt, "System.UIntPtr");
@@ -1077,6 +1070,31 @@ type : generic_class_ref {
$$ = new PrimitiveTypeRef (PrimitiveType.NativeUInt, "System.UIntPtr");
}
+ | K_TYPEDREF
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.TypedRef,
+ "System.TypedReference");
+ }
+ | K_CHAR
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
+ }
+ | K_WCHAR
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.Char, "System.Char");
+ }
+ | K_VOID
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.Void, "System.Void");
+ }
+ | K_BOOL
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.Boolean, "System.Boolean");
+ }
+ | K_STRING
+ {
+ $$ = new PrimitiveTypeRef (PrimitiveType.String, "System.String");
+ }
;
bounds : bound
@@ -1567,7 +1585,7 @@ init_opt : /* EMPTY */ }
;
-field_init : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
+field_init_primitive : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS
{
$$ = new FloatConst (Convert.ToSingle ($3));
}
@@ -1627,6 +1645,9 @@ field_init : K_FLOAT32 OPEN_PARENS float64 CLOSE_PARENS {
$$ = new BoolConst ((bool) $3);
}
+ ;
+
+field_init : field_init_primitive
| K_BYTEARRAY bytes_list
{
$$ = new ByteArrConst ((byte[]) $2);
@@ -2127,11 +2148,7 @@ method_decl : D_EMITBYTE int32 | instr
| sec_decl
{
- PermPair pp = (PermPair) $1;
- if (!CheckSecurityActionValidity ((System.Security.Permissions.SecurityAction) (short) pp.sec_action, false))
- Report.Error (String.Format ("Invalid security action : {0}", pp.sec_action));
-
- codegen.AddPermission (pp.sec_action, pp.perm);
+ AddSecDecl ($1);
}
| extsource_spec
| language_decl
@@ -2785,6 +2802,84 @@ sec_decl : D_PERMISSION sec_action type_spec OPEN_PARENS nameval_pairs CLOSE_PA psa.XML = (string) $3;
$$ = new PermPair ((PEAPI.SecurityAction) $2, psa.CreatePermissionSet ());
}
+ | D_PERMISSIONSET sec_action ASSIGN OPEN_BRACE permissions CLOSE_BRACE
+ {
+#if NET_2_0
+ $$ = new MIPermissionSet ((PEAPI.SecurityAction) $2, (ArrayList) $5);
+#else
+ Report.Error ("Use ilasm2 for 2.0 style declarative security attributes.");
+#endif
+ }
+ ;
+
+permissions : permission
+ {
+ ArrayList list = new ArrayList ();
+ list.Add ($1);
+ $$ = list;
+ }
+ | permissions COMMA permission
+ {
+ ArrayList list = (ArrayList) $1;
+ list.Add ($3);
+ $$ = list;
+ }
+ ;
+
+permission : class_ref ASSIGN OPEN_BRACE permission_members CLOSE_BRACE
+ {
+ $$ = new MIPermission ((BaseTypeRef) $1, (ArrayList) $4);
+ }
+ ;
+
+permission_members : permission_member
+ {
+ ArrayList list = new ArrayList ();
+ list.Add ($1);
+ $$ = list;
+ }
+ | permission_members permission_member
+ {
+ ArrayList list = (ArrayList) $1;
+ list.Add ($2);
+ $$ = list;
+ }
+ ;
+
+permission_member : prop_or_field primitive_type perm_mbr_nameval_pair
+ {
+ NameValuePair pair = (NameValuePair) $3;
+ $$ = new PermissionMember ((MemberTypes) $1, (BaseTypeRef) $2, pair.Name, pair.Value);
+ }
+ | prop_or_field K_ENUM class_ref perm_mbr_nameval_pair
+ {
+ NameValuePair pair = (NameValuePair) $4;
+ $$ = new PermissionMember ((MemberTypes) $1, (BaseTypeRef) $3, pair.Name, pair.Value);
+ }
+ ;
+
+perm_mbr_nameval_pair : SQSTRING ASSIGN field_init_primitive
+ {
+ $$ = new NameValuePair ((string) $1, (PEAPI.Constant) $3);
+ }
+ | SQSTRING ASSIGN K_BYTEARRAY bytes_list
+ {
+ $$ = new NameValuePair ((string) $1, new ByteArrConst ((byte[]) $4));
+ }
+ | SQSTRING ASSIGN K_STRING OPEN_PARENS SQSTRING CLOSE_PARENS
+ {
+ $$ = new NameValuePair ((string) $1, new StringConst ((string) $5));
+ }
+ ;
+
+prop_or_field : K_PROPERTY
+ {
+ $$ = MemberTypes.Property;
+ }
+ | K_FIELD
+ {
+ $$ = MemberTypes.Field;
+ }
;
nameval_pairs : nameval_pair
@@ -2985,7 +3080,13 @@ assembly_decl : D_PUBLICKEY ASSIGN bytes_list }
| sec_decl
{
- PermPair pp = (PermPair) $1;
+ PermPair pp = $1 as PermPair;
+ if (pp == null) {
+ MIPermissionSet ps_20 = (MIPermissionSet) $1;
+ codegen.AddAssemblyPermission (ps_20.SecurityAction, ps_20);
+ break;
+ }
+
if (!CheckSecurityActionValidity ((System.Security.Permissions.SecurityAction) (short) pp.sec_action, true))
Report.Error (String.Format ("Invalid security action : {0}", pp.sec_action));
diff --git a/mcs/ilasm/scanner/ChangeLog b/mcs/ilasm/scanner/ChangeLog index 4a27fa6a392..064721497aa 100644 --- a/mcs/ilasm/scanner/ChangeLog +++ b/mcs/ilasm/scanner/ChangeLog @@ -1,3 +1,7 @@ +2006-05-26 Ankit Jain <jankit@novell.com> + + * ILTables.cs (keywords): Move 'property' out of NET_2_0 . + 2006-05-11 Ankit Jain <jankit@novell.com> * ILTokenizingExpcetion.cs (Location): Remove. Already inherited from diff --git a/mcs/ilasm/scanner/ILTables.cs b/mcs/ilasm/scanner/ILTables.cs index 34273adefc8..e215ff960ad 100644 --- a/mcs/ilasm/scanner/ILTables.cs +++ b/mcs/ilasm/scanner/ILTables.cs @@ -257,8 +257,8 @@ namespace Mono.ILASM { keywords ["modreq"] = new ILToken (Token.K_MODREQ, "modreq");
keywords ["modopt"] = new ILToken (Token.K_MODOPT, "modopt");
keywords ["typedref"] = new ILToken (Token.K_TYPEDREF, "typedref");
-#if NET_2_0 || BOOTSTRAP_NET_2_0
keywords ["property"] = new ILToken (Token.K_PROPERTY, "property");
+#if NET_2_0 || BOOTSTRAP_NET_2_0
keywords ["type"] = new ILToken (Token.K_TYPE, "type");
#endif
keywords ["refany"] = new ILToken (Token.K_TYPEDREF, "typedref");
diff --git a/mcs/ilasm/tests/ChangeLog b/mcs/ilasm/tests/ChangeLog index 95d5b124e68..92a9ed0d7c6 100644 --- a/mcs/ilasm/tests/ChangeLog +++ b/mcs/ilasm/tests/ChangeLog @@ -1,3 +1,8 @@ +2006-05-26 Ankit Jain <jankit@novell.com> + + * test-perm_pass-3.il: New. Test for 2.0 style declarative security + attributes. + 2006-05-11 Ankit Jain <jankit@novell.com> * test-modifiers.il: New. Test for custom modifiers, modreq & modopt. diff --git a/mcs/ilasm/tests/test-perm_pass-3.il b/mcs/ilasm/tests/test-perm_pass-3.il new file mode 100644 index 00000000000..77e3ffe3450 --- /dev/null +++ b/mcs/ilasm/tests/test-perm_pass-3.il @@ -0,0 +1,60 @@ +.assembly extern mscorlib
+{
+ .ver 2:0:0:0
+}
+.assembly 'test-perm_pass-3'
+{
+ .permissionset reqopt
+ "<PermissionSet class=\"System.Security.PermissionSe"
+ + "t\"\n version=\"1\">\n <IPermission class=\"System"
+ + ".Security.Permissions.SecurityPermission, mscorlib, Version="
+ + "2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\"\n "
+ + " version=\"1\"\n Flags=\"SkipVerifi"
+ + "cation\"/>\n</PermissionSet>\n"
+
+ .permissionset assert = {
+ [mscorlib]System.Security.Permissions.IsolatedStorageFilePermissionAttribute = {
+ property enum [mscorlib]System.Security.Permissions.IsolatedStorageContainment 'UserQuota' = int32 (5)
+ }
+ }
+
+ .ver 0:0:0:0
+}
+
+.module 'test-perm_pass-3.dll'
+.imagebase 0x00400000
+.file alignment 0x00000200
+.stackreserve 0x00100000
+.subsystem 0x0003
+.corflags 0x00000001
+
+.class public foo
+{
+ .permissionset assert = {
+ [mscorlib]System.Security.Permissions.ReflectionPermissionAttribute = {
+ property bool 'MemberAccess' = bool(true)
+ }
+ }
+
+ .method public hidebysig newslot abstract virtual
+ instance void abc() cil managed
+ {
+ .permissionset demand =
+ {
+ [mscorlib]System.Security.Permissions.IsolatedStorageFilePermissionAttribute = {
+ property enum [mscorlib]System.Security.Permissions.IsolatedStorageContainment 'UserQuota' = int32 (50)
+ },
+
+ [mscorlib]System.Security.Permissions.IsolatedStorageFilePermissionAttribute = {
+ property enum [mscorlib]System.Security.Permissions.IsolatedStorageContainment 'UsageAllowed' = int32 (123)
+ },
+
+ [mscorlib]System.Security.Permissions.ReflectionPermissionAttribute = {
+ property char 'MemberAccess' = char (16)
+ }
+ }
+
+
+ }
+
+}
|