Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
703 serge 1
/****************************************************************************
2
*
3
*                            Open Watcom Project
4
*
5
*    Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
6
*
7
*  ========================================================================
8
*
9
*    This file contains Original Code and/or Modifications of Original
10
*    Code as defined in and that are subject to the Sybase Open Watcom
11
*    Public License version 1.0 (the 'License'). You may not use this file
12
*    except in compliance with the License. BY USING THIS FILE YOU AGREE TO
13
*    ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
14
*    provided with the Original Code and Modifications, and is also
15
*    available at www.sybase.com/developer/opensource.
16
*
17
*    The Original Code and all software distributed under the License are
18
*    distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
19
*    EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
20
*    ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
21
*    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
22
*    NON-INFRINGEMENT. Please see the License for the specific language
23
*    governing rights and limitations under the License.
24
*
25
*  ========================================================================
26
*
27
* Description:  signal handling ( for DOS, Windows 3.x and ? Netware )
28
*
29
****************************************************************************/
30
 
31
 
32
#include "variety.h"
33
#include 
34
#include 
35
  //#include 
36
#include 
37
#include 
38
#include "rtdata.h"
39
#include "sigtab.h"
40
#include "sigfunc.h"
41
#include "seterrno.h"
42
 
43
#ifndef __WINDOWS_386__
44
#ifndef __NETWARE__
45
//extern      void    __grab_int23( void );
46
//extern      void    __restore_int23( void );
47
//extern      void    __grab_int_ctrl_break( void );
48
//extern      void    __restore_int_ctrl_break( void );
49
#endif
50
#endif
51
 
52
#define __SIGLAST       SIGIOVFL
53
 
54
static __sig_func SignalTable[] = {
55
    SIG_IGN,        /* unused  */
56
    SIG_DFL,        /* SIGABRT */
57
    SIG_DFL,        /* SIGFPE  */
58
    SIG_DFL,        /* SIGILL  */
59
    SIG_DFL,        /* SIGINT  */
60
    SIG_DFL,        /* SIGSEGV */
61
    SIG_DFL,        /* SIGTERM */
62
    SIG_DFL,        /* SIGBREAK */
63
    SIG_IGN,        /* SIGUSR1 */
64
    SIG_IGN,        /* SIGUSR2 */
65
    SIG_IGN,        /* SIGUSR3 */
66
    SIG_DFL,        /* SIGIDIVZ */
67
    SIG_DFL         /* SIGIOVFL */
68
};
69
 
70
static FPEhandler   *__old_FPE_handler = NULL;
71
 
72
void __sigabort( void )
73
{
74
    raise( SIGABRT );
75
}
76
 
77
//extern void _fpmath( void );
78
//#pragma aux _fpmath "__fpmath";
79
 
80
_WCRTLINK void __sigfpe_handler( int fpe_type )
81
{
82
    __sig_func  func;
83
 
84
    func = SignalTable[ SIGFPE ];
85
    if( func != SIG_IGN  &&  func != SIG_DFL  &&  func != SIG_ERR ) {
86
        SignalTable[ SIGFPE ] = SIG_DFL;      /* 09-nov-87 FWC */
87
        (*(__sigfpe_func)func)( SIGFPE, fpe_type );        /* so we can pass 2'nd parm */
88
    }
89
}
90
 
91
_WCRTLINK __sig_func signal( int sig, __sig_func func )
92
{
93
    __sig_func  prev_func;
94
 
95
    if(( sig < 1 ) || ( sig > __SIGLAST )) {
96
        __set_errno( EINVAL );
97
        return( SIG_ERR );
98
    }
99
    _RWD_abort = __sigabort;           /* change the abort rtn address */
100
 
101
    if( sig == SIGINT ) {
102
        if( func == SIG_DFL ) {
103
    //        __restore_int23();
104
        } else if( func != SIG_ERR ) {
105
    //        __grab_int23();
106
        }
107
    } else if( sig == SIGBREAK ) {
108
        if( func == SIG_DFL ) {
109
    //        __restore_int_ctrl_break();
110
        } else if( func != SIG_ERR ) {
111
    //        __grab_int_ctrl_break();
112
        }
113
    } else if( sig == SIGFPE ) {
114
        if( func == SIG_DFL ) {
115
            __restore_FPE_handler();
116
        } else if( func != SIG_ERR ) {
117
            __grab_FPE_handler();
118
        }
119
    }
120
    prev_func = _RWD_sigtab[ sig ];
121
    _RWD_sigtab[ sig ] = func;
122
    return( prev_func );
123
}
124
 
125
 
126
_WCRTLINK int raise( int sig )
127
{
128
    __sig_func  func;
129
 
130
    func = _RWD_sigtab[ sig ];
131
    switch( sig ) {
132
    case SIGFPE:
133
        __sigfpe_handler( FPE_EXPLICITGEN );
134
        break;
135
    case SIGABRT:
136
        if( func == SIG_DFL ) {
137
            __terminate();
138
        }
139
    case SIGINT:
140
        if( func != SIG_IGN  &&  func != SIG_DFL  &&  func != SIG_ERR ) {
141
            _RWD_sigtab[ sig ] = SIG_DFL;      /* 09-nov-87 FWC */
142
        //    __restore_int23();
143
            (*func)( sig );
144
        }
145
        break;
146
    case SIGBREAK:
147
        if( func != SIG_IGN  &&  func != SIG_DFL  &&  func != SIG_ERR ) {
148
            _RWD_sigtab[ sig ] = SIG_DFL;      /* 09-nov-87 FWC */
149
        //    __restore_int_ctrl_break();
150
            (*func)( sig );
151
        }
152
        break;
153
    case SIGILL:
154
    case SIGSEGV:
155
    case SIGTERM:
156
    case SIGUSR1:
157
    case SIGUSR2:
158
    case SIGUSR3:
159
    case SIGIDIVZ:
160
    case SIGIOVFL:
161
        if( func != SIG_IGN  &&  func != SIG_DFL  &&  func != SIG_ERR ) {
162
            _RWD_sigtab[ sig ] = SIG_DFL;      /* 09-nov-87 FWC */
163
            (*func)( sig );
164
        }
165
        break;
166
    default:
167
        return( -1 );
168
    }
169
    return( 0 );
170
}
171
 
172
void __restore_FPE_handler( void )
173
{
174
    if( __old_FPE_handler == NULL ) {
175
        return;
176
    }
177
    __FPE_handler = __old_FPE_handler;
178
    __old_FPE_handler = NULL;
179
}
180
 
181
void __grab_FPE_handler( void )
182
{
183
    if( __old_FPE_handler == NULL ) {
184
        __old_FPE_handler = __FPE_handler;
185
        __FPE_handler = __sigfpe_handler;
186
    }
187
}