supressing runtime security checks in C++

G

Guest

How can I supress runtime security checks in a mixed-mode C++ assembly?

SuppressUnmanagedCodeSecurityAttribute apparently only works for P/Invoke
and COM interop.

I've got a somewhat chatty interface and can clearly see these checks being
made using PerfMon. In this context I can't reduce the chattiness...

Ideas?

Nick Hodapp
 
W

Willy Denoyette [MVP]

Not sure what counter you are looking at, but IJW should not perform a
stackwalk as the target function is already part of a managed assembly.
In contrast COM and PInvoke interop always calls to an unmanaged assembly,
so here you see security stackwalks unless you suppress them.

Willy.
 
J

Jochen Kalmbach

Willy said:
Not sure what counter you are looking at, but IJW should not perform a
stackwalk as the target function is already part of a managed
assembly. In contrast COM and PInvoke interop always calls to an
unmanaged assembly, so here you see security stackwalks unless you
suppress them.

Normally you have an managed c++ assembly only for this reason, that you
either want to call Win32-APIs directly or want to make COM.

And here is the question: How to avoid Runtime-Security cheks in this
transition from managed C++ to the unmanaged world.


--
Greetings
Jochen

My blog about Win32 and .NET
http://blog.kalmbachnet.de/
 
W

Willy Denoyette [MVP]

Jochen Kalmbach said:
Normally you have an managed c++ assembly only for this reason, that you
either want to call Win32-APIs directly or want to make COM.

And here is the question: How to avoid Runtime-Security cheks in this
transition from managed C++ to the unmanaged world.
Consider following sample, here I'm calling into unmanaged code
(_Fillbuffer) and this function calls StringCbCopyW (a safestring function
from safestr.lib).
So there a two transitions from managed to unmanaged code using the IJW
thunk - NOT a PInvoke thunk.
When running this and watching the perfmon counter "CLR security stackwalks"
I see this remain at 0.

//
#include <strsafe.h> // used by safe string functions (strsafe.lib)
#pragma unmanaged
void _FillBuffer(int i)
{
wchar_t *buff = new wchar_t[ 200 ];
// copy some text using safe string functions
StringCbCopyW( ch, 200, L"This text is safely copied to buff");
}
#pragma managed
void main()
System::Console::ReadLine(); // pause to select perfom counters
{
for (int i = 0; i < 10 ; i++)
{
_FillBuffer(i);
}
}

Willy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top