Skip to content

Commit 691f540

Browse files
committed
[runtime] Remove more unused CAS code.
1 parent c3cce27 commit 691f540

File tree

8 files changed

+11
-272
lines changed

8 files changed

+11
-272
lines changed

mono/metadata/class-internals.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,6 @@ struct _MonoEvent {
195195
/* type of exception being "on hold" for later processing (see exception_type) */
196196
enum {
197197
MONO_EXCEPTION_NONE = 0,
198-
MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
199-
MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
200198
MONO_EXCEPTION_INVALID_PROGRAM = 3,
201199
MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
202200
MONO_EXCEPTION_MISSING_METHOD = 5,

mono/metadata/class.c

Lines changed: 4 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3909,7 +3909,8 @@ is_wcf_hack_disabled (void)
39093909
}
39103910

39113911
static gboolean
3912-
check_interface_method_override (MonoClass *class, MonoMethod *im, MonoMethod *cm, gboolean require_newslot, gboolean interface_is_explicitly_implemented_by_class, gboolean slot_is_empty, gboolean security_enabled) {
3912+
check_interface_method_override (MonoClass *class, MonoMethod *im, MonoMethod *cm, gboolean require_newslot, gboolean interface_is_explicitly_implemented_by_class, gboolean slot_is_empty)
3913+
{
39133914
MonoMethodSignature *cmsig, *imsig;
39143915
if (strcmp (im->name, cm->name) == 0) {
39153916
if (! (cm->flags & METHOD_ATTRIBUTE_PUBLIC)) {
@@ -3944,11 +3945,6 @@ check_interface_method_override (MonoClass *class, MonoMethod *im, MonoMethod *c
39443945
return FALSE;
39453946
}
39463947
TRACE_INTERFACE_VTABLE (printf ("[SECURITY CHECKS]"));
3947-
/* CAS - SecurityAction.InheritanceDemand on interface */
3948-
if (security_enabled && (im->flags & METHOD_ATTRIBUTE_HAS_SECURITY)) {
3949-
mono_secman_inheritancedemand_method (cm, im);
3950-
}
3951-
39523948
if (mono_security_core_clr_enabled ())
39533949
mono_security_core_clr_check_override (class, cm, im);
39543950

@@ -4030,11 +4026,6 @@ check_interface_method_override (MonoClass *class, MonoMethod *im, MonoMethod *c
40304026
}
40314027

40324028
TRACE_INTERFACE_VTABLE (printf ("[SECURITY CHECKS (INJECTED CASE)]"));
4033-
/* CAS - SecurityAction.InheritanceDemand on interface */
4034-
if (security_enabled && (im->flags & METHOD_ATTRIBUTE_HAS_SECURITY)) {
4035-
mono_secman_inheritancedemand_method (cm, im);
4036-
}
4037-
40384029
if (mono_security_core_clr_enabled ())
40394030
mono_security_core_clr_check_override (class, cm, im);
40404031

@@ -4267,7 +4258,6 @@ mono_class_setup_vtable_general (MonoClass *class, MonoMethod **overrides, int o
42674258
int i, max_vtsize = 0, max_iid, cur_slot = 0;
42684259
GPtrArray *ifaces = NULL;
42694260
GHashTable *override_map = NULL;
4270-
gboolean security_enabled = mono_security_enabled ();
42714261
MonoMethod *cm;
42724262
#if (DEBUG_INTERFACE_VTABLE_CODE|TRACE_INTERFACE_VTABLE_CODE)
42734263
int first_non_interface_slot;
@@ -4511,7 +4501,7 @@ mono_class_setup_vtable_general (MonoClass *class, MonoMethod **overrides, int o
45114501
for (l = virt_methods; l; l = l->next) {
45124502
cm = l->data;
45134503
TRACE_INTERFACE_VTABLE (printf (" For slot %d ('%s'.'%s':'%s'), trying method '%s'.'%s':'%s'... [EXPLICIT IMPLEMENTATION = %d][SLOT IS NULL = %d]", im_slot, ic->name_space, ic->name, im->name, cm->klass->name_space, cm->klass->name, cm->name, interface_is_explicitly_implemented_by_class, (vtable [im_slot] == NULL)));
4514-
if (check_interface_method_override (class, im, cm, TRUE, interface_is_explicitly_implemented_by_class, (vtable [im_slot] == NULL), security_enabled)) {
4504+
if (check_interface_method_override (class, im, cm, TRUE, interface_is_explicitly_implemented_by_class, (vtable [im_slot] == NULL))) {
45154505
TRACE_INTERFACE_VTABLE (printf ("[check ok]: ASSIGNING"));
45164506
vtable [im_slot] = cm;
45174507
/* Why do we need this? */
@@ -4532,7 +4522,7 @@ mono_class_setup_vtable_general (MonoClass *class, MonoMethod **overrides, int o
45324522
MonoMethod *cm = parent->vtable [cm_index];
45334523

45344524
TRACE_INTERFACE_VTABLE ((cm != NULL) && printf (" For slot %d ('%s'.'%s':'%s'), trying (ancestor) method '%s'.'%s':'%s'... ", im_slot, ic->name_space, ic->name, im->name, cm->klass->name_space, cm->klass->name, cm->name));
4535-
if ((cm != NULL) && check_interface_method_override (class, im, cm, FALSE, FALSE, TRUE, security_enabled)) {
4525+
if ((cm != NULL) && check_interface_method_override (class, im, cm, FALSE, FALSE, TRUE)) {
45364526
TRACE_INTERFACE_VTABLE (printf ("[everything ok]: ASSIGNING"));
45374527
vtable [im_slot] = cm;
45384528
/* Why do we need this? */
@@ -4610,11 +4600,6 @@ mono_class_setup_vtable_general (MonoClass *class, MonoMethod **overrides, int o
46104600
if (!strcmp(cm->name, m1->name) &&
46114601
mono_metadata_signature_equal (cmsig, m1sig)) {
46124602

4613-
/* CAS - SecurityAction.InheritanceDemand */
4614-
if (security_enabled && (m1->flags & METHOD_ATTRIBUTE_HAS_SECURITY)) {
4615-
mono_secman_inheritancedemand_method (cm, m1);
4616-
}
4617-
46184603
if (mono_security_core_clr_enabled ())
46194604
mono_security_core_clr_check_override (class, cm, m1);
46204605

@@ -5104,11 +5089,6 @@ mono_class_init (MonoClass *class)
51045089
}
51055090
}
51065091

5107-
/* CAS - SecurityAction.InheritanceDemand */
5108-
if (mono_security_enabled () && class->parent && (class->parent->flags & TYPE_ATTRIBUTE_HAS_SECURITY)) {
5109-
mono_secman_inheritancedemand_class (class, class->parent);
5110-
}
5111-
51125092
mono_stats.initialized_class_count++;
51135093

51145094
if (class->generic_class && !class->generic_class->is_dynamic) {
@@ -9777,24 +9757,6 @@ mono_class_get_exception_for_failure (MonoClass *klass)
97779757
gpointer exception_data = mono_class_get_exception_data (klass);
97789758

97799759
switch (klass->exception_type) {
9780-
#ifndef DISABLE_SECURITY
9781-
case MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND: {
9782-
MonoDomain *domain = mono_domain_get ();
9783-
MonoSecurityManager* secman = mono_security_manager_get_methods ();
9784-
MonoMethod *method = exception_data;
9785-
guint32 error = (method) ? MONO_METADATA_INHERITANCEDEMAND_METHOD : MONO_METADATA_INHERITANCEDEMAND_CLASS;
9786-
MonoObject *exc = NULL;
9787-
gpointer args [4];
9788-
9789-
args [0] = &error;
9790-
args [1] = mono_assembly_get_object (domain, mono_image_get_assembly (klass->image));
9791-
args [2] = mono_type_get_object (domain, &klass->byval_arg);
9792-
args [3] = (method) ? mono_method_get_object (domain, method, NULL) : NULL;
9793-
9794-
mono_runtime_invoke (secman->inheritsecurityexception, NULL, args, &exc);
9795-
return (MonoException*) exc;
9796-
}
9797-
#endif
97989760
case MONO_EXCEPTION_TYPE_LOAD: {
97999761
MonoString *name;
98009762
MonoException *ex;

mono/metadata/icall.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3999,19 +3999,13 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
39993999
if (type->type == MONO_TYPE_CLASS) {
40004000
MonoClass *klass = mono_type_get_class (type);
40014001

4002-
if (mono_security_enabled () && !klass->exception_type)
4003-
/* Some security problems are detected during generic vtable construction */
4004-
mono_class_setup_vtable (klass);
4005-
40064002
/* need to report exceptions ? */
40074003
if (throwOnError && klass->exception_type) {
40084004
/* report SecurityException (or others) that occured when loading the assembly */
40094005
MonoException *exc = mono_class_get_exception_for_failure (klass);
40104006
mono_loader_clear_error ();
40114007
mono_set_pending_exception (exc);
40124008
return NULL;
4013-
} else if (mono_security_enabled () && klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
4014-
return NULL;
40154009
}
40164010
}
40174011

mono/metadata/object.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2197,10 +2197,6 @@ mono_class_create_runtime_vtable (MonoDomain *domain, MonoClass *class, gboolean
21972197
mono_domain_unlock (domain);
21982198
mono_loader_unlock ();
21992199

2200-
/* Initialization is now complete, we can throw if the InheritanceDemand aren't satisfied */
2201-
if (mono_security_enabled () && (class->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) && raise_on_error)
2202-
mono_raise_exception (mono_class_get_exception_for_failure (class));
2203-
22042200
/* make sure the parent is initialized */
22052201
/*FIXME shouldn't this fail the current type?*/
22062202
if (class->parent)

mono/metadata/security-manager.c

Lines changed: 7 additions & 177 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,6 @@
1010
#include "security-manager.h"
1111

1212
static MonoSecurityMode mono_security_mode = MONO_SECURITY_MODE_NONE;
13-
static MonoBoolean mono_security_manager_activated = FALSE;
14-
static MonoBoolean mono_security_manager_enabled = TRUE;
15-
static MonoBoolean mono_security_manager_execution = TRUE;
1613

1714
void
1815
mono_security_set_mode (MonoSecurityMode mode)
@@ -26,22 +23,6 @@ mono_security_get_mode (void)
2623
return mono_security_mode;
2724
}
2825

29-
/*
30-
* Note: The security manager is activate once when executing the Mono. This
31-
* is not meant to be a turn on/off runtime switch.
32-
*/
33-
void
34-
mono_activate_security_manager (void)
35-
{
36-
mono_security_manager_activated = TRUE;
37-
}
38-
39-
gboolean
40-
mono_is_security_manager_active (void)
41-
{
42-
return mono_security_manager_activated;
43-
}
44-
4526
#ifndef DISABLE_SECURITY
4627

4728
static MonoSecurityManager secman;
@@ -59,120 +40,10 @@ mono_security_manager_get_methods (void)
5940
g_assert (secman.securitymanager);
6041
if (!secman.securitymanager->inited)
6142
mono_class_init (secman.securitymanager);
62-
63-
secman.demand = mono_class_get_method_from_name (secman.securitymanager,
64-
"InternalDemand", 2);
65-
g_assert (secman.demand);
66-
67-
secman.demandchoice = mono_class_get_method_from_name (secman.securitymanager,
68-
"InternalDemandChoice", 2);
69-
g_assert (secman.demandchoice);
70-
71-
secman.demandunmanaged = mono_class_get_method_from_name (secman.securitymanager,
72-
"DemandUnmanaged", 0);
73-
g_assert (secman.demandunmanaged);
74-
75-
secman.inheritancedemand = mono_class_get_method_from_name (secman.securitymanager,
76-
"InheritanceDemand", 3);
77-
g_assert (secman.inheritancedemand);
78-
79-
secman.inheritsecurityexception = mono_class_get_method_from_name (secman.securitymanager,
80-
"InheritanceDemandSecurityException", 4);
81-
g_assert (secman.inheritsecurityexception);
82-
83-
secman.linkdemand = mono_class_get_method_from_name (secman.securitymanager,
84-
"LinkDemand", 3);
85-
g_assert (secman.linkdemand);
86-
87-
secman.linkdemandunmanaged = mono_class_get_method_from_name (secman.securitymanager,
88-
"LinkDemandUnmanaged", 1);
89-
g_assert (secman.linkdemandunmanaged);
90-
91-
secman.linkdemandfulltrust = mono_class_get_method_from_name (secman.securitymanager,
92-
"LinkDemandFullTrust", 1);
93-
g_assert (secman.linkdemandfulltrust);
94-
95-
secman.linkdemandsecurityexception = mono_class_get_method_from_name (secman.securitymanager,
96-
"LinkDemandSecurityException", 2);
97-
g_assert (secman.linkdemandsecurityexception);
98-
99-
secman.allowpartiallytrustedcallers = mono_class_from_name (mono_defaults.corlib, "System.Security",
100-
"AllowPartiallyTrustedCallersAttribute");
101-
g_assert (secman.allowpartiallytrustedcallers);
102-
103-
secman.suppressunmanagedcodesecurity = mono_class_from_name (mono_defaults.corlib, "System.Security",
104-
"SuppressUnmanagedCodeSecurityAttribute");
105-
g_assert (secman.suppressunmanagedcodesecurity);
10643

10744
return &secman;
10845
}
10946

110-
static gboolean
111-
mono_secman_inheritance_check (MonoClass *klass, MonoDeclSecurityActions *demands)
112-
{
113-
MonoSecurityManager* secman = mono_security_manager_get_methods ();
114-
MonoDomain *domain = mono_domain_get ();
115-
MonoAssembly *assembly = mono_image_get_assembly (klass->image);
116-
MonoReflectionAssembly *refass = mono_assembly_get_object (domain, assembly);
117-
MonoObject *res;
118-
gpointer args [3];
119-
120-
args [0] = domain->domain;
121-
args [1] = refass;
122-
args [2] = demands;
123-
124-
res = mono_runtime_invoke (secman->inheritancedemand, NULL, args, NULL);
125-
return (*(MonoBoolean *) mono_object_unbox (res));
126-
}
127-
128-
void
129-
mono_secman_inheritancedemand_class (MonoClass *klass, MonoClass *parent)
130-
{
131-
MonoDeclSecurityActions demands;
132-
133-
/* don't hide previous results -and- don't calc everything for nothing */
134-
if (klass->exception_type != 0)
135-
return;
136-
137-
/* short-circuit corlib as it is fully trusted (within itself)
138-
* and because this cause major recursion headaches */
139-
if ((klass->image == mono_defaults.corlib) && (parent->image == mono_defaults.corlib))
140-
return;
141-
142-
/* Check if there are an InheritanceDemand on the parent class */
143-
if (mono_declsec_get_inheritdemands_class (parent, &demands)) {
144-
/* If so check the demands on the klass (inheritor) */
145-
if (!mono_secman_inheritance_check (klass, &demands)) {
146-
/* Keep flags in MonoClass to be able to throw a SecurityException later (if required) */
147-
mono_class_set_failure (klass, MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND, NULL);
148-
}
149-
}
150-
}
151-
152-
void
153-
mono_secman_inheritancedemand_method (MonoMethod *override, MonoMethod *base)
154-
{
155-
MonoDeclSecurityActions demands;
156-
157-
/* don't hide previous results -and- don't calc everything for nothing */
158-
if (override->klass->exception_type != 0)
159-
return;
160-
161-
/* short-circuit corlib as it is fully trusted (within itself)
162-
* and because this cause major recursion headaches */
163-
if ((override->klass->image == mono_defaults.corlib) && (base->klass->image == mono_defaults.corlib))
164-
return;
165-
166-
/* Check if there are an InheritanceDemand on the base (virtual) method */
167-
if (mono_declsec_get_inheritdemands_method (base, &demands)) {
168-
/* If so check the demands on the overriding method */
169-
if (!mono_secman_inheritance_check (override->klass, &demands)) {
170-
/* Keep flags in MonoClass to be able to throw a SecurityException later (if required) */
171-
mono_class_set_failure (override->klass, MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND, base);
172-
}
173-
}
174-
}
175-
17647
#else
17748

17849
MonoSecurityManager*
@@ -181,16 +52,6 @@ mono_security_manager_get_methods (void)
18152
return NULL;
18253
}
18354

184-
void
185-
mono_secman_inheritancedemand_class (MonoClass *klass, MonoClass *parent)
186-
{
187-
}
188-
189-
void
190-
mono_secman_inheritancedemand_method (MonoMethod *override, MonoMethod *base)
191-
{
192-
}
193-
19455
#endif /* DISABLE_SECURITY */
19556

19657
/*
@@ -230,10 +91,8 @@ mono_get_context_capture_method (void)
23091
{
23192
static MonoMethod *method = NULL;
23293

233-
if (!mono_security_manager_activated) {
234-
if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
235-
return NULL;
236-
}
94+
if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
95+
return NULL;
23796

23897
/* older corlib revisions won't have the class (nor the method) */
23998
if (mono_defaults.executioncontext_class && !method) {
@@ -250,59 +109,30 @@ mono_get_context_capture_method (void)
250109
MonoBoolean
251110
ves_icall_System_Security_SecurityManager_get_SecurityEnabled (void)
252111
{
253-
if (!mono_security_manager_activated) {
254-
/* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
255-
* (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
256-
*/
257-
return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
258-
}
259-
return mono_security_manager_enabled;
112+
/* SecurityManager is internal for Moonlight and SecurityEnabled is used to know if CoreCLR is active
113+
* (e.g. plugin executing in the browser) or not (e.g. smcs compiling source code with corlib 2.1)
114+
*/
115+
return (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR);
260116
}
261117

262118
void
263119
ves_icall_System_Security_SecurityManager_set_SecurityEnabled (MonoBoolean value)
264120
{
265-
/* value can be changed only if the security manager is activated */
266-
if (mono_security_manager_activated) {
267-
mono_security_manager_enabled = value;
268-
}
269121
}
270122

271123
MonoBoolean
272124
ves_icall_System_Security_SecurityManager_get_CheckExecutionRights (void)
273125
{
274-
if (!mono_security_manager_activated)
275-
return FALSE;
276-
return mono_security_manager_execution;
126+
return FALSE;
277127
}
278128

279129
void
280130
ves_icall_System_Security_SecurityManager_set_CheckExecutionRights (MonoBoolean value)
281131
{
282-
/* value can be changed only id the security manager is activated */
283-
if (mono_security_manager_activated) {
284-
mono_security_manager_execution = value;
285-
}
286132
}
287133

288134
MonoBoolean
289135
ves_icall_System_Security_SecurityManager_GetLinkDemandSecurity (MonoReflectionMethod *m, MonoDeclSecurityActions *kactions, MonoDeclSecurityActions *mactions)
290136
{
291-
MonoMethod *method = m->method;
292-
/* we want the original as the wrapper is "free" of the security informations */
293-
if (method->wrapper_type == MONO_WRAPPER_MANAGED_TO_NATIVE || method->wrapper_type == MONO_WRAPPER_MANAGED_TO_MANAGED) {
294-
method = mono_marshal_method_from_wrapper (method);
295-
}
296-
297-
mono_class_init (method->klass);
298-
299-
/* if either the method or it's class has security (any type) */
300-
if ((method->flags & METHOD_ATTRIBUTE_HAS_SECURITY) || (method->klass->flags & TYPE_ATTRIBUTE_HAS_SECURITY)) {
301-
memset (kactions, 0, sizeof (MonoDeclSecurityActions));
302-
memset (mactions, 0, sizeof (MonoDeclSecurityActions));
303-
304-
/* get any linkdemand (either on the method or it's class) */
305-
return mono_declsec_get_linkdemands (method, kactions, mactions);
306-
}
307137
return FALSE;
308138
}

0 commit comments

Comments
 (0)