home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / gcl-1.000 / gcl-1 / gcl-1.0 / c / unixint.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-05-07  |  3.5 KB  |  167 lines

  1. /*
  2.  Copyright (C) 1994 M. Hagiya, W. Schelter, T. Yuasa
  3.  
  4. This file is part of GNU Common Lisp, herein referred to as GCL
  5.  
  6. GCL is free software; you can redistribute it and/or modify it under
  7. the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GCL is distributed in the hope that it will be useful, but WITHOUT
  12. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public 
  14. License for more details.
  15.  
  16. You should have received a copy of the GNU Library General Public License 
  17. along with GCL; see the file COPYING.  If not, write to the Free Software
  18. Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  
  20. */
  21.  
  22. /*
  23.     unixint.c
  24. */
  25.  
  26. #include "include.h"
  27. #include <signal.h>
  28. #include "page.h"
  29.   
  30. #define SS1(a,b) b = a ;
  31. #define RS1(a,b) a = b ;
  32.  
  33. #define SAVE_STATE \
  34.  { struct call_data fd1; \
  35.   struct bds_bd bd1,*bd1p; \
  36.   object* vs_top1,*vs_base1,vs_top_val ; \
  37.      SS1(bds_top,bd1p) \
  38.      SS1(*bd1p, bd1) \
  39.      SS1(vs_base,vs_base1) \
  40.      SS1( vs_top ,vs_top1) \
  41.      SS1(*vs_top1, vs_top_val) \
  42.      SS1(fcall, fd1) \
  43.        ;
  44.  
  45.              
  46. #define RESTORE_STATE \
  47.      RS1(bds_top,bd1p) \
  48.      RS1(*bd1p, bd1) \
  49.      RS1(vs_base,vs_base1) \
  50.      RS1( vs_top ,vs_top1) \
  51.      RS1(*vs_top1, vs_top_val) \
  52.      RS1(fcall, fd1) \
  53.               }
  54.  
  55.              
  56. object SVinterrupt_enable;
  57.  
  58. sigalrm()
  59. {
  60.     if (interrupt_flag) {
  61.         interrupt_flag = FALSE;
  62.         SAVE_STATE
  63.         terminal_interrupt(TRUE);
  64.         RESTORE_STATE
  65.     }
  66. }
  67.  
  68. sigint()
  69. {
  70.     if (!interrupt_enable || interrupt_flag) {
  71.  
  72.         if (!interrupt_enable)
  73.             {fprintf(stdout, "\n;;Interrupt delayed.\n");
  74.              fflush(stdout);
  75.              interrupt_flag=TRUE;}
  76.  
  77.         gcl_signal(SIGINT, sigint);
  78.         return;
  79.     }
  80.     if (symbol_value(SVinterrupt_enable) == Cnil) {
  81.         SVinterrupt_enable->s.s_dbind = Ct;
  82.         gcl_signal(SIGINT, sigint);
  83.         return;
  84.     }
  85. #ifdef DOS
  86.     if(interrupt_flag)
  87.       { sigalrm();}
  88. #endif
  89.     interrupt_flag = TRUE;
  90.     gcl_signal(SIGALRM, sigalrm);
  91.     alarm(1);
  92.     gcl_signal(SIGINT, sigint);
  93. }
  94.  
  95. sigfpe()
  96. {
  97.     gcl_signal(SIGFPE, sigfpe);
  98.     FEerror("Floating-point exception.", 0);
  99. }
  100.  
  101. #ifdef BSD
  102. signal_catcher(sig, code, scp)
  103. {
  104.     char str[64];
  105.  
  106.     if (!interrupt_enable) {
  107.         sprintf(str, "signal %d caught (during GBC)", sig);
  108.         error(str);
  109.     } else {
  110.         vs_push(make_fixnum(sig));
  111.         FEerror("Signal ~D caught.~%\
  112. The internal memory may be broken.~%\
  113. You should check the signal and exit from Lisp.", 1, vs_head);
  114.     }
  115. }
  116.  
  117. #ifndef SIGPROTV
  118. #define SIGPROTV SIGSEGV
  119. #endif
  120.  
  121. siLcatch_bad_signals()
  122. {
  123.     check_arg(0);
  124.  
  125.     gcl_signal(SIGILL, signal_catcher);
  126.     gcl_signal(SIGIOT, signal_catcher);
  127.     gcl_signal(SIGEMT, signal_catcher);
  128.     if (SIGPROTV != SIGBUS || !sgc_enabled)
  129.        gcl_signal(SIGBUS, signal_catcher);
  130.      if(SIGPROTV != SIGSEGV || !sgc_enabled)
  131.        gcl_signal(SIGSEGV, signal_catcher);
  132.     gcl_signal(SIGSYS, signal_catcher);
  133.     vs_push(Ct);
  134. }
  135.  
  136. siLuncatch_bad_signals()
  137. {
  138.     check_arg(0);
  139.  
  140.     gcl_signal(SIGILL, SIG_DFL);
  141.     gcl_signal(SIGIOT, SIG_DFL);
  142.     gcl_signal(SIGEMT, SIG_DFL);
  143.      if(SIGPROTV != SIGBUS || !sgc_enabled)
  144.        gcl_signal(SIGBUS, SIG_DFL);
  145.      if(SIGPROTV != SIGSEGV || !sgc_enabled)
  146.        gcl_signal(SIGSEGV, SIG_DFL);    
  147.     gcl_signal(SIGSYS, SIG_DFL);
  148.     vs_push(Ct);
  149. }
  150. #endif
  151.  
  152. init_interrupt()
  153. {
  154.     gcl_signal(SIGFPE, sigfpe);
  155.     gcl_signal(SIGINT, sigint);
  156. }
  157.  
  158. init_interrupt1()
  159. {
  160.     SVinterrupt_enable
  161.     = make_si_special("*INTERRUPT-ENABLE*", Ct);
  162. #ifdef BSD
  163.     make_si_function("CATCH-BAD-SIGNALS", siLcatch_bad_signals);
  164.     make_si_function("UNCATCH-BAD-SIGNALS", siLuncatch_bad_signals);
  165. #endif
  166. }
  167.