comparison packages/language/c/libc/signals/current/include/signal.inl @ 115:6ed91473a1cd ecos-sw-2000-08-21

Merge from eCos master repository on 2000-08-21-22:40:54-BST
author jlarmour
date Fri, 25 Aug 2000 17:32:38 +0000
parents
children e0c0827131d1
comparison
equal deleted inserted replaced
114:5ad2b71d525e 115:6ed91473a1cd
1 #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 //####COPYRIGHTBEGIN####
11 //
12 // -------------------------------------------
13 // The contents of this file are subject to the Red Hat eCos Public License
14 // Version 1.1 (the "License"); you may not use this file except in
15 // compliance with the License. You may obtain a copy of the License at
16 // http://www.redhat.com/
17 //
18 // Software distributed under the License is distributed on an "AS IS"
19 // basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
20 // License for the specific language governing rights and limitations under
21 // the License.
22 //
23 // The Original Code is eCos - Embedded Configurable Operating System,
24 // released September 30, 1998.
25 //
26 // The Initial Developer of the Original Code is Red Hat.
27 // Portions created by Red Hat are
28 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
29 // All Rights Reserved.
30 // -------------------------------------------
31 //
32 //####COPYRIGHTEND####
33 //========================================================================
34 //#####DESCRIPTIONBEGIN####
35 //
36 // Author(s): jlarmour
37 // Contributors:
38 // Date: 2000-04-18
39 // Purpose: Implements required inline functions of ISO C and
40 // POSIX 1003.1 signals
41 // Description:
42 // Usage: Do not include this file directly, instead use <signal.h>
43 //
44 //####DESCRIPTIONEND####
45 //
46 //========================================================================
47
48 // CONFIGURATION
49
50 #include <pkgconf/libc_signals.h> // libc signals configuration
51
52 // INCLUDES
53
54 #include <signal.h> // Header for this file, just in case
55 #include <cyg/infra/cyg_ass.h> // Assertion infrastructure
56 #include <cyg/infra/cyg_trac.h> // Tracing infrastructure
57
58 // GLOBALS
59
60 extern __sighandler_t cyg_libc_signal_handlers[];
61 #ifdef CYGDBG_USE_TRACING
62 extern cyg_uint8 cyg_libc_signals_raise_trace_level;
63 #endif
64
65 // DEFINES
66
67 // The following are overriden by the libc implementation to get a non-inline
68 // version to prevent duplication of code
69 #ifndef CYGPRI_LIBC_SIGNALS_RAISE_INLINE
70 # define CYGPRI_LIBC_SIGNALS_RAISE_INLINE extern __inline__
71 #endif
72
73 #ifndef CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE
74 # define CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE extern __inline__
75 #endif
76
77 // FUNCTION PROTOTYPES
78
79 #ifdef __cplusplus
80 extern "C" {
81 #endif
82
83 // Default signal handler - SIG_DFL
84 extern void cyg_libc_signals_default_handler(int __sig);
85
86 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
87 extern cyg_bool cyg_libc_signals_lock_do_lock(void);
88 extern void cyg_libc_signals_lock_do_unlock(void);
89 #endif
90
91 // INLINE FUNCTIONS
92
93 /////////////////////////////
94 // cyg_libc_signals_lock() //
95 /////////////////////////////
96
97 static inline cyg_bool
98 cyg_libc_signals_lock(void)
99 {
100 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
101 return cyg_libc_signals_lock_do_lock();
102 #else
103 return true;
104 #endif
105 } // cyg_libc_signals_lock()
106
107 ///////////////////////////////
108 // cyg_libc_signals_unlock() //
109 ///////////////////////////////
110
111 static inline void
112 cyg_libc_signals_unlock(void)
113 {
114 #ifdef CYGSEM_LIBC_SIGNALS_THREAD_SAFE
115 cyg_libc_signals_lock_do_unlock();
116 #else
117 return;
118 #endif
119 } // cyg_libc_signals_unlock()
120
121 // ISO C functions
122
123 //////////////////////////////
124 // signal() - ISO C 7.7.1 //
125 //////////////////////////////
126
127
128 #ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
129
130 #ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
131 # include <errno.h> // errno
132 #endif
133
134 CYGPRI_LIBC_SIGNALS_SIGNAL_INLINE __sighandler_t
135 signal(int __sig, __sighandler_t __handler)
136 {
137 __sighandler_t __old_handler;
138 CYG_REPORT_FUNCNAMETYPE( "__signal", "returning %08x" );
139
140 CYG_REPORT_FUNCARG2( "signal number = %d, requested handler is at %08x",
141 __sig, __handler );
142
143 // check valid signal - raise should not raise the null signal either
144 if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
145
146 #ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
147 CYG_FAIL("__signal() passed bad signal number");
148 #else
149 # ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
150 errno = EINVAL;
151 # endif
152 return SIG_ERR;
153 #endif
154 }
155
156 // paranoia
157 CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
158 "signal handler array is invalid!" );
159 if ( (__handler != SIG_IGN) && (__handler != SIG_DFL) )
160 CYG_CHECK_FUNC_PTR( __handler, "__signal() passed invalid handler");
161
162 if (!cyg_libc_signals_lock()) {
163 #ifdef CYGSEM_LIBC_SIGNALS_SIGNAL_SETS_ERRNO
164 errno = EINTR;
165 #endif
166 return SIG_ERR;
167 } // if
168
169 __old_handler = cyg_libc_signal_handlers[__sig];
170 cyg_libc_signal_handlers[__sig] = __handler;
171
172 cyg_libc_signals_unlock();
173
174 CYG_REPORT_RETVAL( __old_handler );
175
176 return __old_handler;
177 } // signal()
178 #endif // ifdef CYGIMP_LIBC_SIGNALS_SIGNAL_INLINE
179
180
181 ///////////////////////////
182 // raise() - ISO C 7.7.2 //
183 ///////////////////////////
184
185 #ifdef CYGIMP_LIBC_SIGNALS_RAISE_INLINE
186
187 #ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
188 # include <errno.h> // errno
189 #endif
190
191 CYGPRI_LIBC_SIGNALS_RAISE_INLINE int
192 raise(int __sig)
193 {
194 int __ret=0;
195 __sighandler_t __sigfun;
196
197 CYG_REPORT_FUNCNAMETYPE( "__raise", "returning %d" );
198
199 CYG_REPORT_FUNCARG1( "signal number = %d", __sig );
200
201 // check valid signal - raise should not raise the null signal either
202 if ( (__sig >= CYGNUM_LIBC_SIGNALS) || (__sig <= 0) ) {
203
204 #ifdef CYGSEM_LIBC_SIGNALS_BAD_SIGNAL_FATAL
205 CYG_FAIL("__raise() passed bad signal number");
206 #else
207 # ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
208 errno = EINVAL;
209 # endif
210 return -1;
211 #endif
212 }
213
214 // paranoia
215 CYG_CHECK_DATA_PTR( cyg_libc_signal_handlers,
216 "signal handler array is invalid!" );
217
218 if (!cyg_libc_signals_lock()) {
219 #ifdef CYGSEM_LIBC_SIGNALS_RAISE_SETS_ERRNO
220 errno = EINTR;
221 #endif
222 return -1;
223 } // if
224
225 __sigfun = cyg_libc_signal_handlers[__sig];
226
227 switch ( (CYG_ADDRESS)__sigfun ) {
228
229 case (CYG_ADDRESS)SIG_DFL:
230 CYG_TRACE0(cyg_libc_signals_raise_trace_level,
231 "signal handler returned is SIG_DFL");
232 cyg_libc_signals_unlock();
233 cyg_libc_signals_default_handler(__sig);
234 break;
235
236 case (CYG_ADDRESS)SIG_IGN:
237 CYG_TRACE0(cyg_libc_signals_raise_trace_level,
238 "signal handler returned is SIG_IGN");
239 cyg_libc_signals_unlock();
240
241 break;
242
243 default:
244 CYG_TRACE1(cyg_libc_signals_raise_trace_level,
245 "signal handler returned is at %08x", __sigfun);
246 // call the signal handler directly
247 cyg_libc_signal_handlers[__sig] = SIG_DFL;
248
249 cyg_libc_signals_unlock();
250 CYG_CHECK_FUNC_PTR( __sigfun, "returned signal handler invalid!");
251
252 (*__sigfun)(__sig);
253 break;
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