home *** CD-ROM | disk | FTP | other *** search
/ rtsi.com / 2014.01.www.rtsi.com.tar / www.rtsi.com / OS9 / OSK / EFFO / pd6.lzh / SRC / error.c < prev    next >
Text File  |  1990-05-08  |  5KB  |  190 lines

  1. /*
  2.   C BASED FORTH-83 MULTI-TASKING KERNEL ERROR MANAGEMENT 
  3.  
  4.   Copyright (c) 1989 by Mikael Patel
  5.  
  6.   Computer Aided Design Laboratory (CADLAB)
  7.   Department of Computer and Information Science
  8.   Linkoping University
  9.   S-581 83 LINKOPING
  10.   SWEDEN
  11.  
  12.   Email: mip@ida.liu.se
  13.   
  14.   Started on: 7 March 1989
  15.  
  16.   Last updated on: 7 December 1988
  17.  
  18.   Dependencies:
  19.        (cc) signal.h, fcntl.h, kernel.h, memory.h, io.h, and error.h 
  20.  
  21.   Description:
  22.        Handles low level signal to error message conversion and printing.
  23.        Low level signals from run-time environment are transformation
  24.        to forth level exceptions and may be intercepted.
  25.   
  26.   Copying:
  27.        This program is free software; you can redistribute it and/or modify
  28.        it under the terms of the GNU General Public License as published by
  29.        the Free Software Foundation; either version 1, or (at your option)
  30.        any later version.
  31.  
  32.        This program is distributed in the hope that it will be useful,
  33.        but WITHOUT ANY WARRANTY; without even the implied warranty of
  34.        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  35.        GNU General Public License for more details.
  36.  
  37.        You should have received a copy of the GNU General Public License
  38.        along with this program; see the file COPYING.  If not, write to
  39.        the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. 
  40.  
  41. */
  42.  
  43. #include <signal.h>
  44. #ifndef OSK
  45. #  include <fcntl.h>
  46. #endif
  47. #include "kernel.h"
  48. #include "memory.h"
  49. #include "error.h"
  50. #include "io.h"
  51.  
  52.  
  53. /* ENVIRONMENT FOR LONGJMP AND RESTART AFTER ERROR SIGNAL */
  54.  
  55. jmp_buf restart;
  56.  
  57.  
  58. /* SIGNAL MESSAGE TABLE AND SIZE */
  59.  
  60. #define SIGNALMSGSIZE 20
  61.  
  62. static char *signalmsg[SIGNALMSGSIZE] = {
  63.     "io error",
  64.     "hangup",
  65.     "interrupt",
  66.     "quit",
  67.     "illegal instruction",
  68.     "trace trap",
  69.     "abort",
  70.     "emulator trap",
  71.     "arithmetric exception",
  72.     "kill",
  73.     "bus error",
  74.     "segmentation violation",
  75.     "bad argument to system call",
  76.     "write to a pipe or other socket with no one to read it",
  77.     "alarm clock",
  78.     "software termination",
  79.     "urgent condition on IO channel",
  80.     "sendable stop signal not from tty",
  81.     "stop signal from tty",
  82.     "continue after stop"
  83.     };
  84.  
  85. void error_signal(sig)
  86.     long sig;
  87. {
  88.     /* Check which task received the signal */
  89.     if (tp == foreground)
  90.        (void) printf("foreground #%x: ", foreground);
  91.     else
  92.        (void) printf("task #%d: ", tp);
  93.  
  94.     /* Print the signal number and a short description */
  95.     if (sig < SIGNALMSGSIZE)
  96.        (void) printf("signal #%d: %s\n", sig, signalmsg[sig]);
  97.     else
  98.        (void) printf("exception #%d: %s\n", sig, ((ENTRY *) sig) -> name);
  99.  
  100.     /* Abort the current virtual machine call */
  101.     doabort();
  102. }
  103.  
  104. void error_fatal(sig)
  105.     int sig;                   /* Signal number */
  106. {
  107.     /* Notify the error signal */
  108.     error_signal((long) sig);
  109.  
  110.     /* Clean up the mess after all the packages */
  111.     io_finish();
  112.     error_finish();
  113.     kernel_finish();
  114.     memory_finish();
  115.     
  116.     /* Exit and pass on the signal number */
  117.     exit(sig);
  118. }
  119.  
  120. void error_restart(sig)
  121.     int sig;                   /* Signal number */
  122. {
  123. #ifdef OSK
  124.     sigmask(0);
  125.     /* Check the type of signal and perform an appropriate action */
  126.     switch (sig) {
  127. #else
  128.     switch (sig) {
  129.       case SIGTSTP:
  130.        (void) fcntl(STDIN, F_SETFL, 0);
  131.        (void) kill(getpid(), SIGSTOP);
  132.        return;
  133.       case SIGCONT:
  134.        (void) fcntl(STDIN, F_SETFL, FNDELAY);
  135.        return;
  136. #endif
  137.       default:
  138.        /* Check if the lowest file descriptor is a tty */
  139.        if (isatty(io_fstack[0] -> fd)) {
  140.            
  141.            /* Close all other files */
  142.            io_flush();
  143.  
  144.            /* Check for interrupt in input management */
  145.            if (sig == SIGINT && !running) {
  146.  
  147.                /* Notify the type of signal */
  148.                error_signal((long) sig);
  149.            }
  150.            else
  151.                /* Warm start the kernel and pass on the signal number */
  152.                longjmp(restart, sig);  
  153.        }
  154.        else error_fatal(sig);
  155.     }
  156. }
  157.  
  158. void error_initiate()
  159. {
  160.     /* Add error_fatal and error_restart as signal handlers */
  161.     (void) signal(SIGHUP,  error_fatal);
  162.     (void) signal(SIGINT,  error_restart);
  163.     (void) signal(SIGQUIT, error_restart);
  164. #ifndef OSK
  165.     (void) signal(SIGILL,  error_restart);
  166.     (void) signal(SIGTRAP, error_fatal);
  167.     (void) signal(SIGIOT,  error_fatal);
  168.     (void) signal(SIGEMT,  error_fatal);
  169.     (void) signal(SIGFPE,  error_restart);
  170.     (void) signal(SIGBUS,  error_restart);
  171.     (void) signal(SIGSEGV, error_restart);
  172.     (void) signal(SIGSYS,  error_restart);
  173.     (void) signal(SIGPIPE, error_restart);
  174.     (void) signal(SIGALRM, error_restart);
  175.     (void) signal(SIGTERM, error_fatal);
  176.     (void) signal(SIGURG,  error_restart);
  177.     (void) signal(SIGSTOP, error_fatal);
  178.     (void) signal(SIGTSTP, error_restart);
  179.     (void) signal(SIGCONT, error_restart);
  180. #else
  181.     (void) signal(0, error_fatal);
  182. #endif
  183. }
  184.  
  185. void error_finish()
  186. {
  187.     /* Future clean up function for the error package */
  188. }
  189.  
  190.