[Mono-devel-list] CAS Patch for InheritanceDemand
Paolo Molaro
lupus at ximian.com
Thu Feb 17 10:04:21 EST 2005
On 02/15/05 Sebastien Pouliot wrote:
> Index: metadata/class.c
> ===================================================================
> --- metadata/class.c (revision 40693)
> +++ metadata/class.c (working copy)
> @@ -33,6 +33,7 @@
> #include <mono/metadata/debug-helpers.h>
> #include <mono/metadata/reflection.h>
> #include <mono/metadata/mono-debug-debugger.h>
> +#include <mono/metadata/security-manager.h>
> #include <mono/os/gc_wrapper.h>
>
> MonoStats mono_stats;
> @@ -1225,6 +1226,12 @@
> continue;
> if (!strcmp(cm->name, im->name) &&
> mono_metadata_signature_equal (mono_method_signature (cm), mono_method_signature (im))) {
> +
> + /* CAS - SecurityAction.InheritanceDemand on interface */
> + if (mono_is_security_manager_active () && (im->flags & METHOD_ATTRIBUTE_HAS_SECURITY)) {
Please cache the result of mono_is_security_manager_active () in a local
var at the start of the function and use that for the check.
> Index: metadata/security-manager.c
> ===================================================================
> --- metadata/security-manager.c (revision 40693)
> +++ metadata/security-manager.c (working copy)
> @@ -17,7 +17,11 @@
> static MonoBoolean mono_security_manager_enabled = TRUE;
> static MonoBoolean mono_security_manager_execution = TRUE;
>
> +/* defined in metadata/class.c */
> +extern void (*mono_inheritancedemand_class) (MonoClass *klass, MonoClass *parent);
> +extern void (*mono_inheritancedemand_method) (MonoMethod *override, MonoMethod *base);
What is this stuff?
> +static gboolean
> +mono_secman_inheritance_check (MonoClass *klass, MonoDeclSecurityActions *demands)
> +{
> + MonoSecurityManager* secman = mono_security_manager_get_methods ();
> + MonoDomain *domain = mono_domain_get ();
> + MonoAssembly *assembly = mono_image_get_assembly (klass->image);
> + MonoReflectionAssembly *refass = (MonoReflectionAssembly*) mono_assembly_get_object (domain, assembly);
No need for the cast, remove.
> + /* Keep flags in MonoClass to be able to throw a SecurityException later (if required) */
> + klass->exception_type = 1;
Use an enum, not a magic value.
> Index: metadata/class-internals.h
> ===================================================================
> --- metadata/class-internals.h (revision 40693)
> +++ metadata/class-internals.h (working copy)
> @@ -225,7 +232,10 @@
> guint has_references : 1; /* it has GC-tracked references in the instance */
> guint has_static_refs : 1; /* it has static fields that are GC-tracked */
>
> - guint32 declsec_flags; /* declarative security attributes flags */
> + guint32 declsec_flags; /* declarative security attributes flags */
> + guint32 exception_type; /* MONO_EXCEPTION_* */
> + guint32 exception_data; /* Additional information about the exception */
Merge exception_type and exception_data.
> + MonoMethod *exception_method; /* If non-NULL the method responsible for throwing the exception */
Change to a void* and rename to exception_data: the type should be implicitly defined
by exception_type. There are at least 20 types we might want to use, depending on
what failed when loading the class: we can't add 20 different fields to MonoClass.
It is already too big and it needs pruning.
Maybe, while we are at it, define a new API:
gboolean
mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data)
{
if (klass->exception_type)
return FALSE;
klass->exception_type = ex_type;
klass->exception_data = ex_data;
return TRUE;
}
And we could have a function to create the relevant exception object:
MonoException*
mono_class_get_exception_for_Failure (MonoClass *klass)
{
switch (klass->exception_type) {
case ...: create security exception;
case ...: create typeload exception;
...
}
}
Proposals for better names are welcome, too.
Thanks!
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list