为什么跳过仅对动态方法允许的可见性检查? [英] Why is skipping visibility checks only allowed for dynamic methods?

查看:54
本文介绍了为什么跳过仅对动态方法允许的可见性检查?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在移植广泛使用 DynamicMethod 的代码,以允许进行预编译,以获得更好的冷启动性能.我注意到 DynamicMethod 可以被JITted并在跳过可见性检查的情况下执行,这使它们可以访问私有嵌套类型,而普通程序集则不能(或者它们不能吗?我看不到任何明显的方法)加载程序选项).此设计决定的依据是什么?

I am porting code which uses DynamicMethods extensively to allow for precompilation, for better cold startup performance. I noticed that DynamicMethods can be JITted and executed with visibility checks skipped, which allows them to access private nested types, yet normal assemblies can not (or can't they? I don't see any obvious loader option). What is the rationale behind this design decision?

推荐答案

我需要挥手示意这个问题,因为CAS永远都是复杂的.skipVisibility参数与生成在沙箱中执行的代码的受信任主机应用程序有关.在这种情况下,由于执行环境错误,因此不适合在生成方法时执行检查.它需要在沙箱中的方法执行时发生.在沙盒中进行常规CAS检查的地方.

I need to wave my hands a bit answering this question, CAS is forever complicated. The skipVisibility argument is relevant to trusted host applications that generate code that executes in a sandbox. In such a case, it is not appropriate to perform checks when the method is generated since the execution environment is wrong. It needs to happen when the method executes inside the sandbox. Where it is subjected to the normal CAS checks performed by the sandbox.

实际上将参数设置为true 增加对ReflectionPermissionFlag.MemberAccess的许可需求,需要对生成方法进行尝试.

Setting the argument to true in fact adds a permission demand for ReflectionPermissionFlag.MemberAccess, required to have a shot at getting the method generated.

乱七八糟.此MSDN文章,将RestrictedMemberAccess添加到沙盒域中"中有一些背景信息.部分.

Topsy-turvy. There's some background info in this MSDN article, "Adding RestrictedMemberAccess to Sandboxed Domains" section.

这篇关于为什么跳过仅对动态方法允许的可见性检查?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆