fault.c revision 965005c81e0f731867d47892b9fb677030b102df
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 1997 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* UNIX shell
*/
#include "defs.h"
#include <siginfo.h>
#include <ucontext.h>
#include <errno.h>
#include <string.h>
static char sigsegv_stack[SIGSTKSZ];
static void fault();
{
0,
0, /* hangup */
0, /* interrupt */
0, /* quit */
0, /* illegal instr */
0, /* trace trap */
0, /* IOT */
0, /* EMT */
0, /* float pt. exp */
0, /* kill */
0, /* bus error */
0, /* memory faults */
0, /* bad sys call */
0, /* bad pipe call */
0, /* alarm */
0, /* software termination */
0, /* unassigned */
0, /* unassigned */
0, /* death of child */
0, /* power fail */
0, /* window size change */
0, /* urgent IO condition */
0, /* pollable event occured */
0, /* stopped by signal */
0, /* stopped by user */
0, /* continued */
0, /* stopped by tty input */
0, /* stopped by tty output */
0, /* virtual timer expired */
0, /* profiling timer expired */
0, /* exceeded cpu limit */
0, /* exceeded file size limit */
0, /* process's lwps are blocked */
0, /* special signal used by thread library */
0, /* check point freeze */
0, /* check point thaw */
};
static void (*(
{
0,
done, /* hangup */
fault, /* interrupt */
fault, /* quit */
done, /* illegal instr */
done, /* trace trap */
done, /* IOT */
done, /* EMT */
done, /* floating pt. exp */
0, /* kill */
done, /* bus error */
sigsegv, /* memory faults */
done, /* bad sys call */
done, /* bad pipe call */
done, /* alarm */
fault, /* software termination */
done, /* unassigned */
done, /* unassigned */
0, /* death of child */
done, /* power fail */
0, /* window size change */
done, /* urgent IO condition */
done, /* pollable event occured */
0, /* uncatchable stop */
0, /* foreground stop */
0, /* stopped process continued */
0, /* background tty read */
0, /* background tty write */
done, /* virtual timer expired */
done, /* profiling timer expired */
done, /* exceeded cpu limit */
done, /* exceeded file size limit */
0, /* process's lwps are blocked */
0, /* special signal used by thread library */
0, /* check point freeze */
0, /* check point thaw */
};
static int
ignoring(int i)
{
return (1);
return (1);
}
return (0);
}
static void
clrsig(i)
int i;
{
if (trapcom[i] != 0) {
trapcom[i] = 0;
}
/*
* If the signal has been set to SIGIGN and we are now
* clearing the disposition of the signal (restoring it
* back to its default value) then we need to clear this
* bit as well
*
*/
}
}
void
{
unsigned char *t;
int savxit;
if (t = trapcom[0])
{
trapcom[0] = 0;
/* Save exit value so trap handler will not change its val */
execexp(t, 0);
free(t);
}
else
chktrap();
rmtemp(0);
rmfunctmp();
#ifdef ACCT
doacct();
#endif
/* in a subshell, need to wait on foreground job */
}
(void) endjobs(0);
if (sig) {
sigemptyset(&set);
}
}
static void
{
int flag;
switch (sig) {
case SIGALRM:
if (sleeping)
return;
break;
}
else
}
int
int sig;
void (*func)();
{
int ret;
return (0);
/*
* Ensure that sigaction is only called with valid signal numbers,
* we can get random values back for oact.sa_handler if the signal
* number is invalid
*
*/
}
/*
* Special case for signal zero, we can not obtain the previos
* action by calling sigaction, instead we save it in the variable
* psig0_func, so we can test it next time through this code
*
*/
if (sig == 0) {
psig0_func = func;
} else {
}
return (ret);
}
void
stdsigs()
{
int i;
int err = 0;
errno = 0;
}
for (i = 1; i < MAXTRAP; i++) {
if (i == rtmin) {
i = rtmax;
continue;
}
if (sigval[i] == 0)
continue;
continue;
}
/*
* handle all the realtime signals
*
*/
}
}
void
oldsigs()
{
int i;
unsigned char *t;
i = MAXTRAP;
while (i--)
{
t = trapcom[i];
if (t == 0 || *t)
clrsig(i);
trapflg[i] = 0;
}
trapnote = 0;
}
/*
* check for traps
*/
void
chktrap()
{
int i = MAXTRAP;
unsigned char *t;
while (--i)
{
{
if (t = trapcom[i])
{
execexp(t, 0);
exitset();
}
}
}
}
void
{
int sig;
if (argc == 1) {
/*
* print out the current action associated with each signal
* handled by the shell
*
*/
}
}
} else {
/*
* set the action for the list of signals
*
*/
if (noa1 == 0)
++argv;
while (*++argv) {
} else if (noa1) {
/*
* no action specifed so reset the siganl
* to its default disposition
*
*/
} else if (*a1) {
/*
* set the action associated with the signal
* to a1
*
*/
}
/*
* set the action associated with the signal
* to SIG_IGN
*
*/
}
}
}
}
void
{
/*
* add SIGALRM to mask
*/
sigemptyset(&set);
/*
* catch SIGALRM
*/
/*
* start alarm and wait for signal
*/
sleeping = 1;
sigsuspend(&oset);
sleeping = 0;
/*
* reset alarm, catcher and mask
*/
alarm(0);
}
void
{
/*
* This should never happen, but if it does this is all we
* can do. It can only happen if sigaction(2) for SIGSEGV
* has been called without SA_SIGINFO being set.
*
*/
} else {
/*
* If we are here then SIGSEGV must have been sent to
* us from a user process NOT as a result of an
* internal error within the shell eg
* kill -SEGV $$
* will bring us here. So do the normal thing.
*
*/
} else {
/*
* If we are here then there must have been an internal
* error within the shell to generate SIGSEGV eg
* the stack is full and we cannot call any more
* functions (Remeber this signal handler is running
* on an alternate stack). So we just exit cleanly
* with an error status (no core file).
*/
}
}
}