diff options
author | Benoit Germain <bnt.germain@gmail.com> | 2013-11-16 10:42:04 +0100 |
---|---|---|
committer | Benoit Germain <bnt.germain@gmail.com> | 2013-11-16 10:42:04 +0100 |
commit | 4e1519fa6c29a4453ffb8a395bba2aa1fa2d501a (patch) | |
tree | e88cf6f7fef450c0b04f87f95690c141ef23b225 /src | |
parent | 3300bf6d0a7914d1e0914f90fdd5d968fcbfe010 (diff) | |
download | lanes-4e1519fa6c29a4453ffb8a395bba2aa1fa2d501a.tar.gz lanes-4e1519fa6c29a4453ffb8a395bba2aa1fa2d501a.tar.bz2 lanes-4e1519fa6c29a4453ffb8a395bba2aa1fa2d501a.zip |
EnableCrashingOnCrashes changes
* make EnableCrashingOnCrashes a one-time operation
* attempt to catch SIGABRT
Diffstat (limited to 'src')
-rw-r--r-- | src/lanes.c | 59 |
1 files changed, 43 insertions, 16 deletions
diff --git a/src/lanes.c b/src/lanes.c index b0e5d76..c853c8d 100644 --- a/src/lanes.c +++ b/src/lanes.c | |||
@@ -2939,33 +2939,60 @@ LUAG_FUNC( configure) | |||
2939 | return 1; | 2939 | return 1; |
2940 | } | 2940 | } |
2941 | 2941 | ||
2942 | // helper to have correct callstacks when crashing a Win32 running on 64 bits Windows | ||
2943 | // don't forget to toggle Debug/Exceptions/Win32 in visual Studio too! | ||
2944 | static void EnableCrashingOnCrashes( void) | ||
2945 | { | ||
2946 | #if defined PLATFORM_WIN32 && !defined NDEBUG | 2942 | #if defined PLATFORM_WIN32 && !defined NDEBUG |
2947 | typedef BOOL (WINAPI *tGetPolicy)(LPDWORD lpFlags); | 2943 | #include <signal.h> |
2948 | typedef BOOL (WINAPI *tSetPolicy)(DWORD dwFlags); | 2944 | #include <conio.h> |
2949 | const DWORD EXCEPTION_SWALLOWING = 0x1; | ||
2950 | 2945 | ||
2951 | HMODULE kernel32 = LoadLibraryA("kernel32.dll"); | 2946 | void signal_handler( int signal) |
2952 | tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); | 2947 | { |
2953 | tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); | 2948 | if( signal == SIGABRT) |
2954 | if( pGetPolicy && pSetPolicy) | ||
2955 | { | 2949 | { |
2956 | DWORD dwFlags; | 2950 | _cprintf( "caught abnormal termination!"); |
2957 | if( pGetPolicy( &dwFlags)) | 2951 | abort(); |
2952 | } | ||
2953 | } | ||
2954 | |||
2955 | // helper to have correct callstacks when crashing a Win32 running on 64 bits Windows | ||
2956 | // don't forget to toggle Debug/Exceptions/Win32 in visual Studio too! | ||
2957 | static volatile long s_ecoc_initCount = 0; | ||
2958 | static volatile int s_ecoc_go_ahead = 0; | ||
2959 | static void EnableCrashingOnCrashes( void) | ||
2960 | { | ||
2961 | if( InterlockedCompareExchange( &s_ecoc_initCount, 1, 0) == 0) | ||
2962 | { | ||
2963 | typedef BOOL (WINAPI* tGetPolicy)( LPDWORD lpFlags); | ||
2964 | typedef BOOL (WINAPI* tSetPolicy)( DWORD dwFlags); | ||
2965 | typedef void (* SignalHandlerPointer)( int); | ||
2966 | SignalHandlerPointer previousHandler = signal( SIGABRT, signal_handler); | ||
2967 | const DWORD EXCEPTION_SWALLOWING = 0x1; | ||
2968 | |||
2969 | HMODULE kernel32 = LoadLibraryA("kernel32.dll"); | ||
2970 | tGetPolicy pGetPolicy = (tGetPolicy)GetProcAddress(kernel32, "GetProcessUserModeExceptionPolicy"); | ||
2971 | tSetPolicy pSetPolicy = (tSetPolicy)GetProcAddress(kernel32, "SetProcessUserModeExceptionPolicy"); | ||
2972 | if( pGetPolicy && pSetPolicy) | ||
2958 | { | 2973 | { |
2959 | // Turn off the filter | 2974 | DWORD dwFlags; |
2960 | pSetPolicy( dwFlags & ~EXCEPTION_SWALLOWING); | 2975 | if( pGetPolicy( &dwFlags)) |
2976 | { | ||
2977 | // Turn off the filter | ||
2978 | pSetPolicy( dwFlags & ~EXCEPTION_SWALLOWING); | ||
2979 | } | ||
2961 | } | 2980 | } |
2981 | |||
2982 | s_ecoc_go_ahead = 1; // let others pass | ||
2983 | } | ||
2984 | else | ||
2985 | { | ||
2986 | while( !s_ecoc_go_ahead) { Sleep(1); } // changes threads | ||
2962 | } | 2987 | } |
2963 | #endif // PLATFORM_WIN32 | ||
2964 | } | 2988 | } |
2989 | #endif // PLATFORM_WIN32 | ||
2965 | 2990 | ||
2966 | int LANES_API luaopen_lanes_core( lua_State* L) | 2991 | int LANES_API luaopen_lanes_core( lua_State* L) |
2967 | { | 2992 | { |
2993 | #if defined PLATFORM_WIN32 && !defined NDEBUG | ||
2968 | EnableCrashingOnCrashes(); | 2994 | EnableCrashingOnCrashes(); |
2995 | #endif // defined PLATFORM_WIN32 && !defined NDEBUG | ||
2969 | 2996 | ||
2970 | STACK_GROW( L, 4); | 2997 | STACK_GROW( L, 4); |
2971 | STACK_CHECK( L); | 2998 | STACK_CHECK( L); |