00001 /*-------------------------------------------------------- 00002 * / 00003 * / apeNEXT signal functions for nlcc 00004 * / 00005 * / $Id: signal.h,v 1.14 2005/10/28 12:28:57 morinl Exp $ 00006 * / 00007 * / ISO/IEC 9899:1999 (E) Standard 00008 * / ctype <signal.h> 00009 * / 00010 * / IMPLEMENTATION for APEnext: possible? (signal.h) 00011 * /---------------------------------------------------------------------------------------------*/ 00012 00013 #ifndef _SIGNAL_H 00014 #define _SIGNAL_H 00015 00016 #include <nlibc.h> 00017 00018 /* 00019 Header <signal.h> specifies how the program handles signals while it executes. 00020 A signal can report some exceptional behavior within the program, such as division 00021 by zero. Or a signal can report some asynchronous event outside the program, such 00022 00023 as someone striking an interactive attention key on a keyboard 00024 00025 00026 One can report any signal by calling raise(). Each implementation defines what 00027 signals it generates (if any) and under what circumstances it generates them. 00028 An implementation can define signals other than the ones listed here. 00029 The standard header <signal.h> can define additional macros with names beginning 00030 with SIG to specify the values of additional signals. All such values are 00031 integer constant expressions >= 0. 00032 00033 One can specify a signal handler for each signal. A signal handler is a function 00034 that the target environment calls when the corresponding signal occurs. 00035 The target environment suspends execution of the program until the signal handler 00036 returns or calls longjmp. For maximum portability, an asynchronous signal handler 00037 should only: 00038 -make calls (that succeed) to the function signal 00039 -assign values to objects of type volatile sig_atomic_t 00040 -return control to its caller 00041 00042 If the signal reports an error within the program (and the signal is not asynchronous), 00043 the signal handler can terminate by calling abort, exit, or longjmp. 00044 */ 00045 00046 /*------------------------------------------------------------------------------------------------ 00047 * / NAME 00048 * / sig_atomic_t - typedef i-type 00049 * / 00050 * / SYNOPSIS 00051 * / #include <signal.h> 00052 * / 00053 * / typedef i-type sig_atomic_t 00054 * / 00055 * / DESCRIPTION 00056 * / This type is the integer type i-type for objects whose stored value is 00057 * / altered by an assigning operator as an atomic operation (an operation 00058 * / that never has its execution suspended while partially completed). 00059 * / You declare such objects to communicate between signal handlers and 00060 * / the rest of the program. 00061 * / 00062 * / RETURN VALUE 00063 * / None 00064 * / 00065 * / Notes 00066 * / 00067 * / 00068 * / IMPLEMENTATION for APEnext: possible (i-type sig_atomic_t) 00069 * / --------------------------------------------------------------------------------------------*/ 00070 typedef int sig_atomic_t; 00071 00072 // We need a better explanation of those signals (OK 09.08.02) 00073 // How do such signals occur and do we have them on APEnext ? (OK 09.08.02) 00074 // Answer: No such signals internally, except after explicit checks 00075 // for e.g. exceptions. 00076 // Signals may, however, be sent to the 'OS' (i.e. nose) and 00077 // then passed on to the nodes by stopping the nodes and 00078 // explicitly calling a handler. (NP 29.1.04) 00079 00080 // yields the func argument value to signal to specify default signal handling 00081 #define SIG_DFL 0 // address constant expression 00082 00083 // yields the signal return value to specify an erroneous call. 00084 #define SIG_ERR -1 // address constant expression 00085 00086 // yields the func argument value to signal to specify that the target 00087 // environment is to henceforth ignore the signal 00088 #define SIG_IGN 1 // address constant expression 00089 00090 // yields the sig argument value for the abort signal. 00091 #define SIGABRT 6 // integer constant expression >= 0 00092 00093 // acro yields the sig argument value for the arithmetic error signal, 00094 // such as for division by zero or result out of range. 00095 #define SIGFPE 8 // integer constant expression >= 0 00096 00097 // yields the sig argument value for the invalid execution signal, 00098 // such as for a corrupted function image. 00099 #define SIGILL 4 // integer constant expression >= 0 00100 00101 // yields the sig argument value for the asynchronous interactive 00102 // attention signal. 00103 #define SIGINT 2 // integer constant expression >= 0 00104 00105 // yields the sig argument value for the invalid storage access signal, 00106 // such as for an erroneous lvalue expression. 00107 #define SIGSEGV 11 // integer constant expression >= 0 00108 00109 // yields the sig argument value for the asynchronous termination request signal. 00110 // Do we have such a signal on APEnext ? (OK 09.08.02) 00111 #define SIGTERM 15 // integer constant expression >= 0 00112 00113 00114 /*------------------------------------------------------------------------------------------------ 00115 * / NAME 00116 * / signal - pecifies the new handling for signal sig 00117 * / 00118 * / SYNOPSIS 00119 * / #include <signal.h> 00120 * / 00121 * / void (*signal(int sig, void (*func)(int)))(int) 00122 * / 00123 * / DESCRIPTION 00124 * / This function specifies the new handling for signal sig and returns the 00125 * / previous handling, if successful; otherwise, it returns SIG_ERR. 00126 * / 00127 * / RETURN VALUE 00128 * / None 00129 * / 00130 * / Notes 00131 * / -If func is SIG_DFL, the target environment commences default handling 00132 * / (as defined by the implementation). 00133 * / -If func is SIG_IGN, the target environment ignores subsequent reporting 00134 * / of the signal. 00135 * / -Otherwise, func must be the address of a function returning void that 00136 * / the target environment calls with a single int argument. The target 00137 * / environment calls this function to handle the signal when it is next 00138 * / reported, with the value of the signal as its argument. 00139 * / 00140 * / When the target environment calls a signal handler: 00141 * / -The target environment can block further occurrences of the corresponding 00142 * / signal until the handler returns, calls longjmp, or calls signal for that signal. 00143 * / -The target environment can perform default handling of further occurrences 00144 * / of the corresponding signal. 00145 * / -For signal SIGILL, the target environment can leave handling unchanged for 00146 * / that signal. 00147 * / 00148 * / IMPLEMENTATION for APEnext: possible (signal) 00149 * / --------------------------------------------------------------------------------------------*/ 00150 #ifndef __HAS_MAIN 00151 extern void (*signal(int sig, void (*func)(int)))(int); 00152 #else 00153 #if defined(_uses_signal_signal_h) || !defined(__cflow_processed) 00154 void (*signal(int sig, void (*func)(int)))(int) 00155 { 00156 #ifdef __cflow_processed 00157 # warning "Not fully implemented, always return SIG_ERR" 00158 #endif 00159 return (void (*)(int)) SIG_ERR; 00160 } 00161 #endif // signal() 00162 #endif // Has Main 00163 00164 /*------------------------------------------------------------------------------------------------ 00165 * / NAME 00166 * / raise - sends the signal sig 00167 * / 00168 * / SYNOPSIS 00169 * / #include <signal.h> 00170 * / 00171 * / int raise(int sig) 00172 * / 00173 * / DESCRIPTION 00174 * / This function sends the signal sig. 00175 * / 00176 * / RETURN VALUE 00177 * / Zero if the signal is successfully reported 00178 * / Otherwise non-zero 00179 * / 00180 * / Notes 00181 * / 00182 * / IMPLEMENTATION for APEnext: possible (raise) 00183 * / --------------------------------------------------------------------------------------------*/ 00184 #ifndef __HAS_MAIN 00185 extern int raise(int sig); 00186 #else 00187 #if defined(_uses_raise_signal_h) || !defined(__cflow_processed) 00188 int raise(int sig) 00189 { 00190 #ifdef __cflow_processed 00191 # warning "Not fully implemented, always return -1" 00192 #endif 00193 return -1; 00194 } 00195 #endif // raise() 00196 #endif // Has Main 00197 00198 #endif /* ifndef _SIGNAL_H */ 00199