home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Datafile PD-CD 4
/
DATAFILE_PDCD4.iso
/
unix
/
unixlib36d
/
src
/
sys
/
c
/
signal
< prev
next >
Wrap
Text File
|
1994-03-08
|
5KB
|
250 lines
static char sccs_id[] = "@(#) signal.c 3.3 " __DATE__ " HJR";
/* signal.c (c) Copyright 1990 H.Rogers */
#include <signal.h>
#include <stdio.h>
#include "sys/syslib.h"
#include "sys/unix.h"
#include "sys/os.h"
#include "errno.h"
void (*__sigvec[NSIG]) (int);
void (*__sigdfl[NSIG]) (int) =
{
SIG_IGN, /* 0 SIG0 */
SIG_IGN, /* 1 SIGHUP */
SIG_EXIT, /* 2 SIGINT */
SIG_CORE, /* 3 SIGQUIT */
SIG_CORE, /* 4 SIGILL */
SIG_CORE, /* 5 SIGTRAP */
SIG_EXIT, /* 6 SIGABRT */
SIG_CORE, /* 7 SIGEMT */
SIG_CORE, /* 8 SIGFPE */
SIG_EXIT, /* 9 SIGKILL */
SIG_CORE, /* 10 SIGBUS */
SIG_CORE, /* 11 SIGSEGV */
SIG_CORE, /* 12 SIGSYS */
SIG_IGN, /* 13 SIGPIPE */
SIG_IGN, /* 14 SIGALRM */
SIG_EXIT, /* 15 SIGTERM */
SIG_IGN, /* 16 SIGUSR1 */
SIG_IGN, /* 17 SIGUSR2 */
SIG_IGN, /* 18 SIGCLD */
SIG_EXIT, /* 19 SIGPWR */
SIG_IGN /* 20 SIGERR */
};
static void __sigign (int); /* null handler */
static void __sigerr (int); /* error handler */
static void __sigcore (int); /* core dump handler */
static void __sigexit (int); /* exit handler */
static void (*__sigjmp[4]) (int) =
{
__sigign,
__sigerr,
__sigexit,
__sigcore
};
void (*signal (register int sig, register void (*f) (int))) (int)
{
register void (*o) (int);
if (sig < 0 || sig >= NSIG)
return (SIG_ERR);
if ((int) f < 0)
f = __sigdfl[sig];
o = __sigvec[sig];
if ((int) o < 4)
o = __sigjmp[(int) o];
__sigvec[sig] = f;
return (o);
}
/* If we get called due to a lack of stack,
stack checking could cause problems !!!
so disable it.
*/
#pragma no_check_stack
int
__raise (register int sig)
{
register void (*f) (int);
if (sig < 0 || sig >= NSIG)
return (-1);
#ifdef GCC_DEBUG
os_print ("\r\n");
os_print (sys_siglist[sig]);
os_print ("\r\n\n");
__core (0);
#endif
f = __sigvec[sig];
if ((int) f < 4)
f = __sigjmp[(int) f];
else
__sigvec[sig] = __sigdfl[sig];
(*f) (sig);
return (0);
}
int sys_nsig = NSIG;
char *sys_siglist[NSIG] =
{
"SIGSTAK - Stack overflow",
"SIGHUP - Terminal hangup",
"SIGINT - Terminal interrupt",
"SIGQUIT - Terminal quit",
"SIGILL - Illegal instruction (FPE ?)",
"SIGTRAP - Trace trap",
"SIGABRT - Abort",
"SIGEMT - EMT trap",
"SIGFPE - Floating point exception",
"SIGKILL - Kill",
"SIGBUS - Bus error",
"SIGSEGV - Segmentation violation",
"SIGSYS - System call error (bad SWI)",
"SIGPIPE - Broken pipe",
"SIGALRM - Alarm",
"SIGTERM - Termination signal",
"SIGUSR1 - User signal 1",
"SIGUSR2 - User signal 2",
"SIGCLD - Child process dead",
"SIGPWR - Power failure",
"SIGERR - RiscOS Error"
};
volatile int __sigrec;
static void
__sigign (register int sig)
{
sig = sig;
}
static void
__sigerr (register int sig)
{
sig = sig;
errno = ESIG;
}
static void
__sigexit (register int sig)
{
os_print ("\r\n");
os_print (sys_siglist[sig]);
os_print ("\r\n\n");
if (__sigrec & (1 << sig))
{
__u = 0;
_exit (0);
}
__sigrec |= (1 << sig);
_exit (0);
}
static void
__sigcore (register int sig)
{
os_print ("\r\n");
os_print (sys_siglist[sig]);
os_print ("\r\n\n");
if (__sigrec & (1 << sig))
{
__u = 0;
_exit (0);
}
__sigrec |= (1 << sig);
__core (sig);
_exit (0);
}
static char *__rname[16] =
{
"a1", "a2", "a3", "a4",
"v1", "v2", "v3", "v4", "v5", "v6",
"sl", "fp", "ip", "sp", "lr", "pc"
};
void
__backtrace (register unsigned int *fp)
{
register struct trace *f;
register unsigned int *pc;
register int i;
register char *n;
os_print ("\rbacktrace:\r\n\n");
while (fp)
{
f = (struct trace *) (fp - 3);
pc = (unsigned int *) ((unsigned int) f->pc & 0x03fffffcU);
if ((unsigned int) (f->fp) & 0x80000000U)
{
os_print ("\r\n\n pc: ");
os_prhex ((int) pc);
os_print (" sp: ");
os_prhex ((int) f->sp);
n = "?"; /* SJC */
for (i = -3; i > -7; i--)
if ((pc[i] & 0xffffff00U) == 0xff000000U)
{
n = (char *) (pc + i) - (pc[i] & 0xffU);
break;
}
os_print (" ");
os_print (n); /* SJC */
os_print ("()\r\n");
fp++;
for (i = 0; i < 16; i++)
{
if (!(i & 3))
os_print ("\r\n ");
os_print (__rname[i]);
os_print (": ");
os_prhex (fp[i]);
os_print (" ");
}
os_print ("\r\n\n\n");
fp = (unsigned int *) ((unsigned int) (f->fp) & ~0x80000000U);
}
else
{
n = "?";
for (i = -3; i > -7; i--)
if ((pc[i] & 0xffffff00U) == 0xff000000U)
{
n = (char *) (pc + i) - (pc[i] & 0xffU);
break;
}
os_print (" pc: ");
os_prhex ((int) pc);
os_print (" sp: ");
os_prhex ((int) f->sp);
os_print (" ");
os_print (n);
os_print ("()\r\n");
fp = f->fp;
}
}
os_print ("\r\n");
}
#pragma check_stack