src/SDL_fatal.c
changeset 1330 450721ad5436
parent 1312 c9b51268668f
child 1402 d910939febfa
equal deleted inserted replaced
1329:bc67bbf87818 1330:450721ad5436
    18 
    18 
    19     Sam Lantinga
    19     Sam Lantinga
    20     slouken@libsdl.org
    20     slouken@libsdl.org
    21 */
    21 */
    22 
    22 
    23 #ifdef _WIN32_WCE
       
    24 #define NO_SIGNAL_H
       
    25 #endif
       
    26  
       
    27 /* General fatal signal handling code for SDL */
    23 /* General fatal signal handling code for SDL */
    28 
    24 
    29 #ifdef NO_SIGNAL_H
    25 #include "SDL_config.h"
    30 
    26 
    31 /* No signals on this platform, nothing to do.. */
    27 #ifdef HAVE_SIGNAL_H
    32 
    28 
    33 void SDL_InstallParachute(void)
       
    34 {
       
    35 	return;
       
    36 }
       
    37 
       
    38 void SDL_UninstallParachute(void)
       
    39 {
       
    40 	return;
       
    41 }
       
    42 
       
    43 #else
       
    44 
       
    45 #include <stdlib.h>
       
    46 #include <stdio.h>
       
    47 #include <signal.h>
    29 #include <signal.h>
    48 #include <string.h>
       
    49 
    30 
    50 #include "SDL.h"
    31 #include "SDL.h"
    51 #include "SDL_fatal.h"
    32 #include "SDL_fatal.h"
    52 
       
    53 #ifdef __CYGWIN__
       
    54 #define DISABLE_STDIO
       
    55 #endif
       
    56 
    33 
    57 /* This installs some signal handlers for the more common fatal signals,
    34 /* This installs some signal handlers for the more common fatal signals,
    58    so that if the programmer is lazy, the app doesn't die so horribly if
    35    so that if the programmer is lazy, the app doesn't die so horribly if
    59    the program crashes.
    36    the program crashes.
    60 */
    37 */
    61 
    38 
    62 static void print_msg(const char *text)
       
    63 {
       
    64 #ifndef DISABLE_STDIO
       
    65 	fprintf(stderr, "%s", text);
       
    66 #endif
       
    67 }
       
    68 
       
    69 static void SDL_Parachute(int sig)
    39 static void SDL_Parachute(int sig)
    70 {
    40 {
    71 	signal(sig, SIG_DFL);
    41 	signal(sig, SIG_DFL);
    72 	print_msg("Fatal signal: ");
       
    73 	switch (sig) {
       
    74 		case SIGSEGV:
       
    75 			print_msg("Segmentation Fault");
       
    76 			break;
       
    77 #ifdef SIGBUS
       
    78 #if SIGBUS != SIGSEGV
       
    79 		case SIGBUS:
       
    80 			print_msg("Bus Error");
       
    81 			break;
       
    82 #endif
       
    83 #endif /* SIGBUS */
       
    84 #ifdef SIGFPE
       
    85 		case SIGFPE:
       
    86 			print_msg("Floating Point Exception");
       
    87 			break;
       
    88 #endif /* SIGFPE */
       
    89 #ifdef SIGQUIT
       
    90 		case SIGQUIT:
       
    91 			print_msg("Keyboard Quit");
       
    92 			break;
       
    93 #endif /* SIGQUIT */
       
    94 #ifdef SIGPIPE
       
    95 		case SIGPIPE:
       
    96 			print_msg("Broken Pipe");
       
    97 			break;
       
    98 #endif /* SIGPIPE */
       
    99 		default:
       
   100 #ifndef DISABLE_STDIO
       
   101 			fprintf(stderr, "# %d", sig);
       
   102 #endif
       
   103 			break;
       
   104 	}
       
   105 	print_msg(" (SDL Parachute Deployed)\n");
       
   106 	SDL_Quit();
    42 	SDL_Quit();
   107 	exit(-sig);
    43 	raise(sig);
   108 }
    44 }
   109 
    45 
   110 static int SDL_fatal_signals[] = {
    46 static int SDL_fatal_signals[] = {
   111 	SIGSEGV,
    47 	SIGSEGV,
   112 #ifdef SIGBUS
    48 #ifdef SIGBUS
   180 		}
   116 		}
   181 	}
   117 	}
   182 #endif /* HAVE_SIGACTION */
   118 #endif /* HAVE_SIGACTION */
   183 }
   119 }
   184 
   120 
   185 #endif /* NO_SIGNAL_H */
   121 #else
       
   122 
       
   123 /* No signals on this platform, nothing to do.. */
       
   124 
       
   125 void SDL_InstallParachute(void)
       
   126 {
       
   127 	return;
       
   128 }
       
   129 
       
   130 void SDL_UninstallParachute(void)
       
   131 {
       
   132 	return;
       
   133 }
       
   134 
       
   135 #endif /* HAVE_SIGNAL_H */