2010-05-12 04:27:20 +08:00
|
|
|
/*
|
|
|
|
FUNCTION
|
|
|
|
<<strsignal>>---convert signal number to string
|
|
|
|
|
|
|
|
INDEX
|
|
|
|
strsignal
|
|
|
|
|
2017-11-30 16:20:06 +08:00
|
|
|
SYNOPSIS
|
2010-05-12 04:27:20 +08:00
|
|
|
#include <string.h>
|
|
|
|
char *strsignal(int <[signal]>);
|
|
|
|
|
|
|
|
DESCRIPTION
|
|
|
|
<<strsignal>> converts the signal number <[signal]> into a
|
|
|
|
string. If <[signal]> is not a known signal number, the result
|
|
|
|
will be of the form "Unknown signal NN" where NN is the <[signal]>
|
|
|
|
is a decimal number.
|
|
|
|
|
|
|
|
RETURNS
|
|
|
|
This function returns a pointer to a string. Your application must
|
|
|
|
not modify that string.
|
|
|
|
|
|
|
|
PORTABILITY
|
|
|
|
POSIX.1-2008 C requires <<strsignal>>, but does not specify the strings used
|
|
|
|
for each signal number.
|
|
|
|
|
|
|
|
<<strsignal>> requires no supporting OS subroutines.
|
|
|
|
|
|
|
|
QUICKREF
|
|
|
|
strsignal pure
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Written by Joel Sherrill <joel.sherrill@OARcorp.com>.
|
|
|
|
*
|
2017-03-16 01:04:22 +08:00
|
|
|
* COPYRIGHT (c) 2010, 2017.
|
2010-05-12 04:27:20 +08:00
|
|
|
* On-Line Applications Research Corporation (OAR).
|
|
|
|
*
|
|
|
|
* Permission to use, copy, modify, and distribute this software for any
|
|
|
|
* purpose without fee is hereby granted, provided that this entire notice
|
|
|
|
* is included in all copies of any software which is or includes a copy
|
|
|
|
* or modification of this software.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
|
|
|
|
* WARRANTY. IN PARTICULAR, THE AUTHOR MAKES NO REPRESENTATION
|
|
|
|
* OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY OF THIS
|
|
|
|
* SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
Add missing headers to fix implicit function defns
A few files were missing headers for memset/malloc, likely missed
because the files don't directly call the functions, rather they
come in via macros in libc/include/sys/reent.h:
#define _REENT_CHECK(var, what, type, size, init) do { \
struct _reent *_r = (var); \
if (_r->what == NULL) { \
_r->what = (type)malloc(size); \
#define _REENT_CHECK_ASCTIME_BUF(var) \
_REENT_CHECK(var, _asctime_buf, char *, _REENT_ASCTIME_SIZE, \
memset((var)->_asctime_buf, 0, _REENT_ASCTIME_SIZE))
Without these fixes, implicit function signatures are provided,
which gcc warns could cause aliasing issues down the line:
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'memset' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: return value type mismatch
_PTR _EXFUN(memset,(_PTR, int, size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: 'memset' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/string.h:29:7: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/asctime.c:62:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/time/lcltime.c:58:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
../../../../../../../newlib-2.5.0/newlib/libc/string/strsignal.c:70:3: warning: type of 'malloc' does not match original declaration [-Wlto-type-mismatch]
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: return value type mismatch
extern _PTR malloc _PARAMS ((size_t));
^
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: 'malloc' was previously declared here
/Volumes/code/external/newlib-cygwin/newlib/libc/include/malloc.h:37:13: note: code may be misoptimized unless -fno-strict-aliasing is used
Including the proper headers elminates the implicit function
signatures and these warnings.
2017-01-16 08:12:02 +08:00
|
|
|
#include <stdlib.h>
|
2010-05-12 04:27:20 +08:00
|
|
|
#include <reent.h>
|
|
|
|
|
Add --enable-newlib-reent-thread-local option
By default, Newlib uses a huge object of type struct _reent to store
thread-specific data. This object is returned by __getreent() if the
__DYNAMIC_REENT__ Newlib configuration option is defined.
The reentrancy structure contains for example errno and the standard input,
output, and error file streams. This means that if an application only uses
errno it has a dependency on the file stream support even if it does not use
it. This is an issue for lower end targets and applications which need to
qualify the software according to safety standards (for example ECSS-E-ST-40C,
ECSS-Q-ST-80C, IEC 61508, ISO 26262, DO-178, DO-330, DO-333).
If the new _REENT_THREAD_LOCAL configuration option is enabled, then struct
_reent is replaced by dedicated thread-local objects for each struct _reent
member. The thread-local objects are defined in translation units which use
the corresponding object.
2022-05-16 17:51:54 +08:00
|
|
|
#ifdef _REENT_THREAD_LOCAL
|
|
|
|
_Thread_local char _tls_signal_buf[_REENT_SIGNAL_SIZE];
|
|
|
|
#endif
|
|
|
|
|
2010-05-12 04:27:20 +08:00
|
|
|
char *
|
2017-12-04 11:43:30 +08:00
|
|
|
strsignal (int signal)
|
2010-05-12 04:27:20 +08:00
|
|
|
{
|
|
|
|
char *buffer;
|
|
|
|
struct _reent *ptr;
|
|
|
|
|
|
|
|
ptr = _REENT;
|
|
|
|
|
|
|
|
_REENT_CHECK_SIGNAL_BUF(ptr);
|
|
|
|
buffer = _REENT_SIGNAL_BUF(ptr);
|
|
|
|
|
|
|
|
#if defined(SIGRTMIN) && defined(SIGRTMAX)
|
2017-03-16 01:04:22 +08:00
|
|
|
if ((signal >= SIGRTMIN) && (signal <= SIGRTMAX)) {
|
2010-05-12 04:27:20 +08:00
|
|
|
siprintf (buffer, "Real-time signal %d", signal - SIGRTMIN);
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
switch (signal) {
|
|
|
|
#ifdef SIGHUP
|
|
|
|
case SIGHUP:
|
|
|
|
buffer = "Hangup";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGINT
|
|
|
|
case SIGINT:
|
|
|
|
buffer = "Interrupt";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGQUIT
|
|
|
|
case SIGQUIT:
|
|
|
|
buffer = "Quit";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGILL
|
|
|
|
case SIGILL:
|
|
|
|
buffer = "Illegal instruction";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTRAP
|
|
|
|
case SIGTRAP:
|
|
|
|
buffer = "Trace/breakpoint trap";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGIOT
|
|
|
|
#if defined(SIGABRT) && (SIGIOT != SIGABRT)
|
|
|
|
case SIGABRT:
|
|
|
|
#endif
|
|
|
|
case SIGIOT:
|
|
|
|
buffer = "IOT trap";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGEMT
|
|
|
|
case SIGEMT:
|
|
|
|
buffer = "EMT trap";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGFPE
|
|
|
|
case SIGFPE:
|
|
|
|
buffer = "Floating point exception";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGKILL
|
|
|
|
case SIGKILL:
|
|
|
|
buffer = "Killed";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGBUS
|
|
|
|
case SIGBUS:
|
|
|
|
buffer = "Bus error";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSEGV
|
|
|
|
case SIGSEGV:
|
|
|
|
buffer = "Segmentation fault";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSYS
|
|
|
|
case SIGSYS:
|
|
|
|
buffer = "Bad system call";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPIPE
|
|
|
|
case SIGPIPE:
|
|
|
|
buffer = "Broken pipe";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGALRM
|
|
|
|
case SIGALRM:
|
|
|
|
buffer = "Alarm clock";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTERM
|
|
|
|
case SIGTERM:
|
|
|
|
buffer = "Terminated";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGURG
|
|
|
|
case SIGURG:
|
|
|
|
buffer = "Urgent I/O condition";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGSTOP
|
|
|
|
case SIGSTOP:
|
|
|
|
buffer = "Stopped (signal)";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTSTP
|
|
|
|
case SIGTSTP:
|
|
|
|
buffer = "Stopped";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCONT
|
|
|
|
case SIGCONT:
|
|
|
|
buffer = "Continued";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGCHLD
|
|
|
|
#if defined(SIGCLD) && (SIGCHLD != SIGCLD)
|
|
|
|
case SIGCLD:
|
|
|
|
#endif
|
|
|
|
case SIGCHLD:
|
|
|
|
buffer = "Child exited";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTIN
|
|
|
|
case SIGTTIN:
|
|
|
|
buffer = "Stopped (tty input)";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGTTOUT
|
|
|
|
case SIGTTOUT:
|
|
|
|
buffer = "Stopped (tty output)";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGIO
|
|
|
|
#if defined(SIGPOLL) && (SIGIO != SIGPOLL)
|
|
|
|
case SIGPOLL:
|
|
|
|
#endif
|
|
|
|
case SIGIO:
|
|
|
|
buffer = "I/O possible";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGWINCH
|
|
|
|
case SIGWINCH:
|
|
|
|
buffer = "Window changed";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR1
|
|
|
|
case SIGUSR1:
|
|
|
|
buffer = "User defined signal 1";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGUSR2
|
|
|
|
case SIGUSR2:
|
|
|
|
buffer = "User defined signal 2";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPWR
|
|
|
|
case SIGPWR:
|
|
|
|
buffer = "Power Failure";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXCPU
|
|
|
|
case SIGXCPU:
|
|
|
|
buffer = "CPU time limit exceeded";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGXFSZ
|
|
|
|
case SIGXFSZ:
|
|
|
|
buffer = "File size limit exceeded";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGVTALRM
|
|
|
|
case SIGVTALRM :
|
|
|
|
buffer = "Virtual timer expired";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef SIGPROF
|
|
|
|
case SIGPROF:
|
|
|
|
buffer = "Profiling timer expired";
|
|
|
|
break;
|
|
|
|
#endif
|
2010-05-18 22:52:38 +08:00
|
|
|
#if defined(SIGLOST) && SIGLOST != SIGPWR
|
2010-05-12 04:27:20 +08:00
|
|
|
case SIGLOST:
|
|
|
|
buffer = "Resource lost";
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
default:
|
|
|
|
siprintf (buffer, "Unknown signal %d", signal);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer;
|
|
|
|
}
|