src/SDL_fatal.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 06 May 2004 15:55:06 +0000
changeset 886 05c551e5bc64
parent 861 863da1c38c7e
child 1152 51a8702d8ecd
permissions -rw-r--r--
Date: Sat, 24 Apr 2004 15:13:32 +0300
From: "Mike Gorchak"
Subject: SDL updates for the QNX6

1. Updated the README.QNX
2. Updated libtool scripts, which are shipped with SDL for QNX6 support.
3. Added some code to support the new QNX 6.3.0, which is in beta now.
4. Added code to detect the hw features, which driver supports.
5. Added hw alpha blits code.
6. Fixed bug when application switches to fullscreen more the 2 times. (afte\
r that window becames always stay on top).
7. Updated a bit README for the tests.
8. Added information about acceleration show in the testalpha.c test.
9. Added small fixes to the testoverlay2.c test.
10. Added alpha and cc+alpha blits benchmarks to the testvidinfo.c test.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@769
     3
    Copyright (C) 1997-2004 Sam Lantinga
slouken@0
     4
slouken@0
     5
    This library is free software; you can redistribute it and/or
slouken@0
     6
    modify it under the terms of the GNU Library General Public
slouken@0
     7
    License as published by the Free Software Foundation; either
slouken@0
     8
    version 2 of the License, or (at your option) any later version.
slouken@0
     9
slouken@0
    10
    This library is distributed in the hope that it will be useful,
slouken@0
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@0
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@0
    13
    Library General Public License for more details.
slouken@0
    14
slouken@0
    15
    You should have received a copy of the GNU Library General Public
slouken@0
    16
    License along with this library; if not, write to the Free
slouken@0
    17
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
slouken@0
    18
slouken@0
    19
    Sam Lantinga
slouken@252
    20
    slouken@libsdl.org
slouken@0
    21
*/
slouken@0
    22
slouken@0
    23
#ifdef SAVE_RCSID
slouken@0
    24
static char rcsid =
slouken@0
    25
 "@(#) $Id$";
slouken@0
    26
#endif
slouken@0
    27
slouken@0
    28
/* General fatal signal handling code for SDL */
slouken@0
    29
slouken@0
    30
#ifdef NO_SIGNAL_H
slouken@0
    31
slouken@0
    32
/* No signals on this platform, nothing to do.. */
slouken@0
    33
slouken@0
    34
void SDL_InstallParachute(void)
slouken@0
    35
{
slouken@0
    36
	return;
slouken@0
    37
}
slouken@0
    38
slouken@0
    39
void SDL_UninstallParachute(void)
slouken@0
    40
{
slouken@0
    41
	return;
slouken@0
    42
}
slouken@0
    43
slouken@0
    44
#else
slouken@0
    45
slouken@0
    46
#include <stdlib.h>
slouken@0
    47
#include <stdio.h>
slouken@0
    48
#include <signal.h>
slouken@0
    49
#include <string.h>
slouken@0
    50
slouken@0
    51
#include "SDL.h"
slouken@0
    52
#include "SDL_fatal.h"
slouken@0
    53
slouken@1
    54
#ifdef __CYGWIN__
slouken@1
    55
#define DISABLE_STDIO
slouken@1
    56
#endif
slouken@1
    57
slouken@0
    58
/* This installs some signal handlers for the more common fatal signals,
slouken@0
    59
   so that if the programmer is lazy, the app doesn't die so horribly if
slouken@0
    60
   the program crashes.
slouken@0
    61
*/
slouken@0
    62
slouken@1
    63
static void print_msg(const char *text)
slouken@1
    64
{
slouken@1
    65
#ifndef DISABLE_STDIO
slouken@1
    66
	fprintf(stderr, "%s", text);
slouken@1
    67
#endif
slouken@1
    68
}
slouken@1
    69
slouken@0
    70
static void SDL_Parachute(int sig)
slouken@0
    71
{
slouken@0
    72
	signal(sig, SIG_DFL);
slouken@1
    73
	print_msg("Fatal signal: ");
slouken@0
    74
	switch (sig) {
slouken@0
    75
		case SIGSEGV:
slouken@1
    76
			print_msg("Segmentation Fault");
slouken@0
    77
			break;
slouken@0
    78
#ifdef SIGBUS
slouken@0
    79
#if SIGBUS != SIGSEGV
slouken@0
    80
		case SIGBUS:
slouken@1
    81
			print_msg("Bus Error");
slouken@0
    82
			break;
slouken@0
    83
#endif
slouken@0
    84
#endif /* SIGBUS */
slouken@0
    85
#ifdef SIGFPE
slouken@0
    86
		case SIGFPE:
slouken@1
    87
			print_msg("Floating Point Exception");
slouken@0
    88
			break;
slouken@0
    89
#endif /* SIGFPE */
slouken@0
    90
#ifdef SIGQUIT
slouken@0
    91
		case SIGQUIT:
slouken@1
    92
			print_msg("Keyboard Quit");
slouken@0
    93
			break;
slouken@0
    94
#endif /* SIGQUIT */
slouken@0
    95
#ifdef SIGPIPE
slouken@0
    96
		case SIGPIPE:
slouken@1
    97
			print_msg("Broken Pipe");
slouken@0
    98
			break;
slouken@0
    99
#endif /* SIGPIPE */
slouken@0
   100
		default:
slouken@1
   101
#ifndef DISABLE_STDIO
slouken@0
   102
			fprintf(stderr, "# %d", sig);
slouken@1
   103
#endif
slouken@0
   104
			break;
slouken@0
   105
	}
slouken@1
   106
	print_msg(" (SDL Parachute Deployed)\n");
slouken@0
   107
	SDL_Quit();
slouken@0
   108
	exit(-sig);
slouken@0
   109
}
slouken@0
   110
slouken@0
   111
static int SDL_fatal_signals[] = {
slouken@0
   112
	SIGSEGV,
slouken@0
   113
#ifdef SIGBUS
slouken@0
   114
	SIGBUS,
slouken@0
   115
#endif
slouken@0
   116
#ifdef SIGFPE
slouken@0
   117
	SIGFPE,
slouken@0
   118
#endif
slouken@0
   119
#ifdef SIGQUIT
slouken@0
   120
	SIGQUIT,
slouken@0
   121
#endif
slouken@0
   122
	0
slouken@0
   123
};
slouken@0
   124
slouken@0
   125
void SDL_InstallParachute(void)
slouken@0
   126
{
slouken@814
   127
	/* Set a handler for any fatal signal not already handled */
slouken@0
   128
	int i;
slouken@814
   129
#ifdef HAVE_SIGACTION
slouken@814
   130
	struct sigaction action;
slouken@814
   131
slouken@814
   132
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
slouken@814
   133
		sigaction(SDL_fatal_signals[i], NULL, &action);
slouken@814
   134
		if ( action.sa_handler == SIG_DFL ) {
slouken@814
   135
			action.sa_handler = SDL_Parachute;
slouken@814
   136
			sigaction(SDL_fatal_signals[i], &action, NULL);
slouken@814
   137
		}
slouken@814
   138
	}
slouken@814
   139
#ifdef SIGALRM
slouken@814
   140
	/* Set SIGALRM to be ignored -- necessary on Solaris */
slouken@814
   141
	sigaction(SIGALRM, NULL, &action);
slouken@814
   142
	if ( action.sa_handler == SIG_DFL ) {
slouken@814
   143
		action.sa_handler = SIG_IGN;
slouken@861
   144
		sigaction(SIGALRM, &action, NULL);
slouken@814
   145
	}
slouken@814
   146
#endif
slouken@814
   147
#else
slouken@0
   148
	void (*ohandler)(int);
slouken@0
   149
slouken@0
   150
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
slouken@0
   151
		ohandler = signal(SDL_fatal_signals[i], SDL_Parachute);
slouken@0
   152
		if ( ohandler != SIG_DFL ) {
slouken@0
   153
			signal(SDL_fatal_signals[i], ohandler);
slouken@0
   154
		}
slouken@0
   155
	}
slouken@814
   156
#endif /* HAVE_SIGACTION */
slouken@0
   157
	return;
slouken@0
   158
}
slouken@0
   159
slouken@0
   160
void SDL_UninstallParachute(void)
slouken@0
   161
{
slouken@814
   162
	/* Remove a handler for any fatal signal handled */
slouken@0
   163
	int i;
slouken@814
   164
#ifdef HAVE_SIGACTION
slouken@814
   165
	struct sigaction action;
slouken@814
   166
slouken@814
   167
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
slouken@814
   168
		sigaction(SDL_fatal_signals[i], NULL, &action);
slouken@814
   169
		if ( action.sa_handler == SDL_Parachute ) {
slouken@814
   170
			action.sa_handler = SIG_DFL;
slouken@814
   171
			sigaction(SDL_fatal_signals[i], &action, NULL);
slouken@814
   172
		}
slouken@814
   173
	}
slouken@814
   174
#else
slouken@0
   175
	void (*ohandler)(int);
slouken@0
   176
slouken@0
   177
	for ( i=0; SDL_fatal_signals[i]; ++i ) {
slouken@0
   178
		ohandler = signal(SDL_fatal_signals[i], SIG_DFL);
slouken@0
   179
		if ( ohandler != SDL_Parachute ) {
slouken@0
   180
			signal(SDL_fatal_signals[i], ohandler);
slouken@0
   181
		}
slouken@0
   182
	}
slouken@814
   183
#endif /* HAVE_SIGACTION */
slouken@0
   184
}
slouken@0
   185
slouken@0
   186
#endif /* NO_SIGNAL_H */