question

SndorNyika-8336 avatar image
0 Votes"
SndorNyika-8336 asked Viorel-1 edited

_penter function causes acces violation when using /Gh

Hi!

I'm trying to instrument a multithreaded program using the /Gh compiler option, but I ran into this interesting error. I wrote a simple DLL based on the Interceptor library from PrakaramJoshi, but when atexit() is called Access Violation Exception is thrown in _peneter.

I made a small code to reproduce the problem, here are my remarks:
- The problem occurs when the instrumented program uses static global variables.
- When compiling for debug the problem does not occur.
- When choosing /EHs exception handling model the problem does not occur with global mutex.
- But with /EHs and a global std::vector it is.

This is my project:
Interceptor-Access_Violation

I think this has something to do with static initialization. So my question is how should I solve this problem? Is there any other approach to dodge this?




c++
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

Viorel-1 avatar image
0 Votes"
Viorel-1 answered Viorel-1 edited

Probably it tries executing some unloaded or uninitialised code. If you are not interested in _penter that are invoked during finalisation, you can apply this workaround:

 int main( )
 {
    . . .
    __declspec( dllimport ) bool exiting;
    exiting = true;
    
    return 0;
 }

In Interceptor.h:

 __declspec( dllexport ) bool exiting = false;
    
 extern"C" void on_enter( const void* pa )
 {
    if( exiting ) return;
    
    . . .
 }


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.