How to set SuppressUnmanagedCodeSecurity for callbacks?

When using P / Invoke, adding [SuppressUnmanagedCodeSecurity] allows you to speed up the call from managed code to unmanaged code in trusted scripts.

Is there a way to do the same in the opposite direction to speed things up when I call from unmanaged code back to managed code? Profiling shows much higher overhead in this direction in our application.

+3
source share
2 answers

I didn’t find anything about suppressing code security, maybe because there are no stack checks that are called from the unmanaged side, but how you marshal your types affects performance. Here's a link showing the different ways of marshaling strings, as well as the results: http://blogs.msdn.com/junfeng/archive/2007/07/09/reverse-p-invoke-marshaling-performance.aspx

+3
source

I do not believe that such a security check is from unmanaged to managed.

You can see the security checks counted as they occur if you go to Process Explorer. Find your process, click "Properties", go to the ".NET" tab and select ".NET CLR Security" from the drop-down list.

, , , , . .

[SuppressUnmanagedCodeSecurityAttribute()] --- > , 0.

0

Source: https://habr.com/ru/post/1712690/


All Articles