Skip to content

Gendarme.Rules.Interoperability.CentralizePInvokesIntoNativeMethodsTypeRule(2.10)

Sebastien Pouliot edited this page Feb 9, 2011 · 3 revisions

CentralizePInvokesIntoNativeMethodsTypeRule

Assembly: Gendarme.Rules.Interoperability
Version: 2.10

Description

This rule will warn you if p/invoke declarations are found outside some specially named types. The convention makes it easier to know which type of security checks are done (at runtime) and how critical is a security audit for them. In all cases the type should not be visible (i.e. internal in C#) outside the assembly. Note that the type naming itself has no influence on security (either with Code Access Security or with CoreCLR for Silverlight). The naming convention includes the presence or absence of the SuppressUnmanagedCodeSecurity security attribute based on the type name.

  • NativeMethods should not be decorated with a SuppressUnmanagedCodeSecurity. This will let CAS do a stackwalk to ensure the code can be...
  • SafeNativeMethods should be decorated with a [SuppressUnmanagedCodeSecurity] attribute. The attribute means that no stackwalk will occurs.
  • UnsafeNativeMethods should be decorated with a [SuppressUnmanagedCodeSecurity] attribute. The attribute means that no stackwalk will occurs. However since the p/invoke methods are named unsafe then the rule will warn an audit-level defect to review the code.

Examples

Notes

  • This rule is available since Gendarme 2.8
Clone this wiki locally