1 #ifndef CYGONCE_LIBC_SIGNALS_SIGNAL_INL
2 #define CYGONCE_LIBC_SIGNALS_SIGNAL_INL
3 //========================================================================
7 // Inline functions for implementation of ISO C and POSIX signals
9 //========================================================================
10 //####ECOSGPLCOPYRIGHTBEGIN####
11 // -------------------------------------------
12 // This file is part of eCos, the Embedded Configurable Operating System.
13 // Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
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 version.
19 // eCos is distributed in the hope that it will be useful, but WITHOUT ANY
20 // WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24 // You should have received a copy of the GNU General Public License along
25 // with eCos; if not, write to the Free Software Foundation, Inc.,
26 // 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
28 // As a special exception, if other files instantiate templates or use macros
29 // or inline functions from this file, or you compile this file and link it
30 // with other works to produce a work based on this file, this file does not
31 // by itself cause the resulting work to be covered by the GNU General Public
32 // License. However the source code for this file must still be made available
33 // in accordance with section (3) of the GNU General Public License.
35 // This exception does not invalidate any other reasons why a work based on
36 // this file might be covered by the GNU General Public License.
38 // Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
39 // at http://sources.redhat.com/ecos/ecos-license/
40 // -------------------------------------------
41 //####ECOSGPLCOPYRIGHTEND####
42 //========================================================================
43 //#####DESCRIPTIONBEGIN####
45 // Author(s): jlarmour
48 // Purpose: Implements required inline functions of ISO C and
49 // POSIX 1003.1 signals
51 // Usage: Do not include this file directly, instead use <signal.h>
53 //####DESCRIPTIONEND####
55 //========================================================================
59 #include <pkgconf/libc_signals.h> // libc signals configuration
63 #include <signal.h> // Header for this file, just in case
64 #include <cyg/infra/cyg_ass.h> // Assertion infrastructure
65 #include <cyg/infra/cyg_trac.h> // Tracing infrastructure
69 extern __sighandler_t cyg_libc_signal_handlers[];
70 #ifdef CYGDBG_USE_TRACING
71 extern cyg_uint8 cyg_libc_signals_raise_trace_level;
76 // The following are overriden by the libc implementation to get a non-inline
77 // version to prevent duplication of code
78 #ifndef CYGPRI_LIBC_SIGNALS_RAISE_INLINE
79 # define CYGPRI_LIBC_SIGNALS_RAISE_INLINE extern __inline__
82 #ifndef CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE
83 # define CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE extern __inline__
86 // FUNCTION PROTOTYPES
92 // Default signal handler - SIG_DFL
93 extern void cyg_libc_signals_default_handler(int __sig);
95 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
96 extern cyg_bool cyg_libc_signals_lock_do_lock(void);
97 extern void cyg_libc_signals_lock_do_unlock(void);
102 /////////////////////////////
103 // cyg_libc_signals_lock() //
104 /////////////////////////////
106 static inline cyg_bool
107 cyg_libc_signals_lock(void)
109 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
110 return cyg_libc_signals_lock_do_lock();
114 } // cyg_libc_signals_lock()
116 ///////////////////////////////
117 // cyg_libc_signals_unlock() //
118 ///////////////////////////////
121 cyg_libc_signals_unlock(void)
123 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
124 cyg_libc_signals_lock_do_unlock();
128 } // cyg_libc_signals_unlock()
132 //////////////////////////////
133 // signal() - ISO C 7.7.1 //
134 //////////////////////////////
137 #ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
139 #ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
140 # include <errno.h> // errno
143 CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE __sighandler_t
144 signal(int __sig, __sighandler_t __handler)
146 __sighandler_t __old_handler;
147 CYG_REPORT_FUNCNAMETYPE( "__signal", "returning %08x" );
149 CYG_REPORT_FUNCARG2( "signal number = %d, requested handler is at %08x",
152 // check valid signal - raise should not raise the null signal either
153 if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
155 #ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
156 CYG_FAIL("__signal() passed bad signal number");
158 # ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
166 CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
167 "signal handler array is invalid!" );
168 if ( (__handler != SIG_IGN) && (__handler != SIG_DFL) )
169 CYG_CHECK_FUNC_PTR( __handler, "__signal() passed invalid handler");
171 if (!cyg_libc_signals_lock()) {
172 #ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
178 __old_handler = cyg_libc_signal_handlers[__sig];
179 cyg_libc_signal_handlers[__sig] = __handler;
181 cyg_libc_signals_unlock();
183 CYG_REPORT_RETVAL( __old_handler );
185 return __old_handler;
187 #endif // ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
190 ///////////////////////////
191 // raise() - ISO C 7.7.2 //
192 ///////////////////////////
194 #ifdef CYGIMP_LIBC_SIGNALS_RAISE_INLINE
196 #ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
197 # include <errno.h> // errno
200 CYGPRI_LIBC_SIGNALS_RAISE_INLINE int
204 __sighandler_t __sigfun;
206 CYG_REPORT_FUNCNAMETYPE( "__raise", "returning %d" );
208 CYG_REPORT_FUNCARG1( "signal number = %d", __sig );
210 // check valid signal - raise should not raise the null signal either
211 if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
213 #ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
214 CYG_FAIL("__raise() passed bad signal number");
216 # ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
224 CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
225 "signal handler array is invalid!" );
227 if (!cyg_libc_signals_lock()) {
228 #ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
234 __sigfun = cyg_libc_signal_handlers[__sig];
236 if ( __sigfun == SIG_DFL ) {
237 CYG_TRACE0(cyg_libc_signals_raise_trace_level,
238 "signal handler returned is SIG_DFL");
239 cyg_libc_signals_unlock();
240 cyg_libc_signals_default_handler(__sig);
241 } else if ( __sigfun == SIG_IGN ) {
242 CYG_TRACE0(cyg_libc_signals_raise_trace_level,
243 "signal handler returned is SIG_IGN");
244 cyg_libc_signals_unlock();
246 CYG_TRACE1(cyg_libc_signals_raise_trace_level,
247 "signal handler returned is at %08x", __sigfun);
248 // call the signal handler directly
249 cyg_libc_signal_handlers[__sig] = SIG_DFL;
251 cyg_libc_signals_unlock();
252 CYG_CHECK_FUNC_PTR( __sigfun, "returned signal handler invalid!");
257 CYG_REPORT_RETVAL( __ret );
261 #endif // ifdef CYGIMP_LIBC_SIGNALS_RAISE_INLINE
268 #endif // CYGONCE_LIBC_SIGNALS_SIGNAL_INL multiple inclusion protection