문제

I have .NET assembly that calling functions from unmanaged DLL written in C (without CLR support). Is there any way that unmanaged DLL can determine which assembly calls their code? I'm looking for way without enabling CLR support in unmanaged DLL.

도움이 되었습니까?

해결책

No, you cannot safely perform stackwalks in native code. That's only possible in managed code, it provides stack frame layout guarantees. Required by the garbage collector and CAS checks. C compilers have optimizers that remove such guarantees. They can because the language doesn't support nor require stackwalks.

Even if you de-tune the optimizer, you'll still have the significant obstacle of walking through the stack frames of the pinvoke marshaller and mapping a guessed address of just-in-time generated machine code to an assembly. Only the CLR knows how to do that. You cannot make this work.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top