OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [language/] [c/] [libc/] [signals/] [current/] [include/] [signal.inl] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
#ifndef CYGONCE_LIBC_SIGNALS_SIGNAL_INL
2
#define CYGONCE_LIBC_SIGNALS_SIGNAL_INL
3
//========================================================================
4
//
5
//      signal.inl
6
//
7
//      Inline functions for implementation of ISO C and POSIX signals
8
//
9
//========================================================================
10
// ####ECOSGPLCOPYRIGHTBEGIN####
11
// -------------------------------------------
12
// This file is part of eCos, the Embedded Configurable Operating System.
13
// Copyright (C) 1998, 1999, 2000, 2001, 2002, 2009 Free Software Foundation, Inc.
14
//
15
// eCos is free software; you can redistribute it and/or modify it under
16
// the terms of the GNU General Public License as published by the Free
17
// Software Foundation; either version 2 or (at your option) any later
18
// version.
19
//
20
// eCos is distributed in the hope that it will be useful, but WITHOUT
21
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
22
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
23
// for more details.
24
//
25
// You should have received a copy of the GNU General Public License
26
// along with eCos; if not, write to the Free Software Foundation, Inc.,
27
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
28
//
29
// As a special exception, if other files instantiate templates or use
30
// macros or inline functions from this file, or you compile this file
31
// and link it with other works to produce a work based on this file,
32
// this file does not by itself cause the resulting work to be covered by
33
// the GNU General Public License. However the source code for this file
34
// must still be made available in accordance with section (3) of the GNU
35
// General Public License v2.
36
//
37
// This exception does not invalidate any other reasons why a work based
38
// on this file might be covered by the GNU General Public License.
39
// -------------------------------------------
40
// ####ECOSGPLCOPYRIGHTEND####
41
//========================================================================
42
//#####DESCRIPTIONBEGIN####
43
//
44
// Author(s):     jlarmour
45
// Contributors:
46
// Date:          2000-04-18
47
// Purpose:       Implements required inline functions of ISO C and
48
//                POSIX 1003.1 signals
49
// Description:
50
// Usage:         Do not include this file directly, instead use 
51
//
52
//####DESCRIPTIONEND####
53
//
54
//========================================================================
55
 
56
// CONFIGURATION
57
 
58
#include   // libc signals configuration
59
 
60
// INCLUDES
61
 
62
#include                 // Header for this file, just in case
63
#include      // Assertion infrastructure
64
#include     // Tracing infrastructure
65
 
66
// GLOBALS
67
 
68
extern __sighandler_t cyg_libc_signal_handlers[];
69
#ifdef CYGDBG_USE_TRACING
70
extern cyg_uint8 cyg_libc_signals_raise_trace_level;
71
#endif
72
 
73
// DEFINES
74
 
75
// The following are overriden by the libc implementation to get a non-inline
76
// version to prevent duplication of code
77
#ifndef CYGPRI_LIBC_SIGNALS_RAISE_INLINE
78
# define CYGPRI_LIBC_SIGNALS_RAISE_INLINE extern __inline__
79
#endif
80
 
81
#ifndef CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE
82
# define CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE extern __inline__
83
#endif
84
 
85
// FUNCTION PROTOTYPES
86
 
87
#ifdef __cplusplus
88
extern "C" {
89
#endif
90
 
91
// Default signal handler - SIG_DFL
92
extern void cyg_libc_signals_default_handler(int __sig);
93
 
94
#ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
95
extern cyg_bool cyg_libc_signals_lock_do_lock(void);
96
extern void cyg_libc_signals_lock_do_unlock(void);
97
#endif
98
 
99
// INLINE FUNCTIONS
100
 
101
/////////////////////////////
102
// cyg_libc_signals_lock() //
103
/////////////////////////////
104
 
105
extern __inline__ cyg_bool
106
cyg_libc_signals_lock(void)
107
{
108
#ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
109
    return cyg_libc_signals_lock_do_lock();
110
#else
111
    return true;
112
#endif
113
} // cyg_libc_signals_lock()
114
 
115
///////////////////////////////
116
// cyg_libc_signals_unlock() //
117
///////////////////////////////
118
 
119
extern __inline__ void
120
cyg_libc_signals_unlock(void)
121
{
122
#ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
123
    cyg_libc_signals_lock_do_unlock();
124
#else
125
    return;
126
#endif
127
} // cyg_libc_signals_unlock()
128
 
129
// ISO C functions
130
 
131
//////////////////////////////
132
// signal() - ISO C 7.7.1   //
133
//////////////////////////////
134
 
135
 
136
#ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
137
 
138
#ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
139
# include                  // errno
140
#endif
141
 
142
CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE __sighandler_t
143
signal(int __sig, __sighandler_t __handler)
144
{
145
    __sighandler_t __old_handler;
146
    CYG_REPORT_FUNCNAMETYPE( "__signal", "returning %08x" );
147
 
148
    CYG_REPORT_FUNCARG2( "signal number = %d, requested handler is at %08x",
149
                         __sig, __handler );
150
 
151
    // check valid signal - raise should not raise the null signal either
152
    if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
153
 
154
#ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
155
        CYG_FAIL("__signal() passed bad signal number");
156
#else
157
# ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
158
        errno = EINVAL;
159
# endif
160
        return SIG_ERR;
161
#endif
162
    }
163
 
164
    // paranoia
165
    CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
166
                        "signal handler array is invalid!" );
167
    if ( (__handler != SIG_IGN) && (__handler != SIG_DFL) )
168
        CYG_CHECK_FUNC_PTR( __handler, "__signal() passed invalid handler");
169
 
170
    if (!cyg_libc_signals_lock()) {
171
#ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
172
        errno = EINTR;
173
#endif
174
        return SIG_ERR;
175
    } // if
176
 
177
    __old_handler = cyg_libc_signal_handlers[__sig];
178
    cyg_libc_signal_handlers[__sig] = __handler;
179
 
180
    cyg_libc_signals_unlock();
181
 
182
    CYG_REPORT_RETVAL( __old_handler );
183
 
184
    return __old_handler;
185
} // signal()
186
#endif // ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
187
 
188
 
189
///////////////////////////
190
// raise() - ISO C 7.7.2 //
191
///////////////////////////
192
 
193
#ifdef CYGIMP_LIBC_SIGNALS_RAISE_INLINE
194
 
195
#ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
196
# include                  // errno
197
#endif
198
 
199
CYGPRI_LIBC_SIGNALS_RAISE_INLINE int
200
raise(int __sig)
201
{
202
    int __ret=0;
203
    __sighandler_t __sigfun;
204
 
205
    CYG_REPORT_FUNCNAMETYPE( "__raise", "returning %d" );
206
 
207
    CYG_REPORT_FUNCARG1( "signal number = %d", __sig );
208
 
209
    // check valid signal - raise should not raise the null signal either
210
    if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
211
 
212
#ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
213
        CYG_FAIL("__raise() passed bad signal number");
214
#else
215
# ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
216
        errno = EINVAL;
217
# endif
218
        return -1;
219
#endif
220
    }
221
 
222
    // paranoia
223
    CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
224
                        "signal handler array is invalid!" );
225
 
226
    if (!cyg_libc_signals_lock()) {
227
#ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
228
        errno = EINTR;
229
#endif
230
        return -1;
231
    } // if
232
 
233
    __sigfun = cyg_libc_signal_handlers[__sig];
234
 
235
    if ( __sigfun == SIG_DFL ) {
236
        CYG_TRACE0(cyg_libc_signals_raise_trace_level,
237
                   "signal handler returned is SIG_DFL");
238
        cyg_libc_signals_unlock();
239
        cyg_libc_signals_default_handler(__sig);
240
    } else if ( __sigfun == SIG_IGN ) {
241
        CYG_TRACE0(cyg_libc_signals_raise_trace_level,
242
                   "signal handler returned is SIG_IGN");
243
        cyg_libc_signals_unlock();
244
    } else {
245
        CYG_TRACE1(cyg_libc_signals_raise_trace_level,
246
                   "signal handler returned is at %08x", __sigfun);
247
        // call the signal handler directly
248
        cyg_libc_signal_handlers[__sig] = SIG_DFL;
249
 
250
        cyg_libc_signals_unlock();
251
        CYG_CHECK_FUNC_PTR( __sigfun, "returned signal handler invalid!");
252
 
253
        (*__sigfun)(__sig);
254
    }
255
 
256
    CYG_REPORT_RETVAL( __ret );
257
 
258
    return __ret;
259
} // raise()
260
#endif // ifdef CYGIMP_LIBC_SIGNALS_RAISE_INLINE
261
 
262
 
263
#ifdef __cplusplus
264
} // extern "C"
265
#endif
266
 
267
#endif // CYGONCE_LIBC_SIGNALS_SIGNAL_INL multiple inclusion protection
268
 
269
// EOF signal.inl

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.