home *** CD-ROM | disk | FTP | other *** search
/ PC Extra Super CD 1998 January / PCPLUS131.iso / DJGPP / V2 / DJLSR201.ZIP / src / libc / go32 / dpmiexcp.txh < prev    next >
Encoding:
Text File  |  1996-09-11  |  10.1 KB  |  296 lines

  1. @c ----------------------------------------------------------------------
  2. @node raise, signal
  3. @subheading Syntax
  4.  
  5. @example
  6. #include <signal.h>
  7.  
  8. int    raise(int sig);
  9. @end example
  10.  
  11. @subheading Description
  12.  
  13. This function raises the given signal @var{sig}.
  14. @xref{signal, the list of possible signals}.
  15.  
  16. @subheading Return Value
  17.  
  18. 0 on success, -1 for illegal value of @var{sig}.
  19.  
  20. @c ----------------------------------------------------------------------
  21.  
  22. @node signal, signal
  23. @subheading Syntax
  24.  
  25. @example
  26. #include <signal.h>
  27.  
  28. void    (*signal(int sig, void (*func)(int)))(int);
  29. @end example
  30.  
  31. @subheading Description
  32.  
  33. Signals are generated in response to some exceptional behavior of the
  34. program, such as division by 0.  A signal can also report some
  35. asynchronous event outside the program, such as someone pressing a
  36. Ctrl-Break key combination.
  37.  
  38. Signals are numbered 0..255 for software interrupts and 256..287 for
  39. exceptions (exception number plus 256); other implementation-specific
  40. codes are specified in @code{<signal.h>} (see below).  Every signal is
  41. given a mnemonic which you should use for portable programs.
  42.  
  43. The default handling for all the signals is to print a traceback (a
  44. stack dump which describes the sequence of function calls leading to the
  45. generation of the signal) and abort the program.
  46.  
  47. This function allows you to change the default behavior for a specific
  48. signal.  It registers @var{func} as a signal handler for signal number
  49. @var{sig}.  After you register your function as the handler for a
  50. particular signal, it will be called when that signal occurs.  The
  51. execution of the program will be suspended until the handler returns or
  52. calls @code{longjmp} (@pxref{longjmp}).
  53.  
  54. You may pass SIG_DFL as the value of @var{func} to reset the signal
  55. handling for the signal @var{sig} to default (also
  56. @xref{__djgpp_exception_toggle}, for a quick way to restore all the
  57. signals' handling to default), SIG_ERR to force an error when that
  58. signal happens, or SIG_IGN to ignore that signal.  Signal handlers that
  59. you write are regular C functions, and may call any function that the
  60. ANSI/POSIX specs say are valid for signal handlers.  For maximum
  61. portability, a handler for hardware interrupts and processor exceptions
  62. should only make calls to @code{signal}, assign values to data objects
  63. of type @code{volatile sig_atomic_t} (defined as @code{int} on
  64. @code{<signal.h>}) and return.  Handlers for hardware interrupts need
  65. also be locked in memory (so that the operation of virtual memory
  66. mechanism won't swap them out), @xref{__dpmi_lock_linear_region, 
  67. locking memory regions}.  Handlers for software interrupts can also
  68. terminate by calling @code{abort}, @code{exit} or @code{longjmp}.
  69.  
  70. The following signals are defined on @code{<signal.h>}:
  71.  
  72. @table @code
  73.  
  74. @item SIGABRT
  75.  
  76. The Abort signal.  Currently only used by the @code{assert} macro to
  77. terminate the program when an assertion fails (@pxref{assert}).
  78.  
  79. @item SIGFPE
  80.  
  81. The Floating Point Error signal.  Generated in case of divide by zero
  82. exception (Int 00h), overflow exception (Int 04h), and any x87
  83. co-processor exception, either generated by the CPU (Int 10h), or by the
  84. co-processor itself (Int 75h).
  85.  
  86. @item SIGILL
  87.  
  88. The Invalid Execution signal.  Currently only generated for
  89. unknown/invalid exceptions.
  90.  
  91. @item SIGINT
  92.  
  93. The Interrupt signal.  Generated when a @kbd{Ctrl-C} or @kbd{Ctrl-Break}
  94. (Int 1Bh) key is hit.  Note that when you open the console in binary
  95. mode, or switch it to binary mode by a call to @code{setmode}
  96. (@pxref{setmode}), generation of @code{SIGINT} as result of @kbd{Ctrl-C}
  97. key is disabled.  This is so for programs (such as Emacs) which want to
  98. be able to read the @samp{^C} character as any other character.  Use the
  99. library function @code{__djgpp_set_ctrl_c} to restore @code{SIGINT}
  100. generation when @kbd{Ctrl-C} is hit, if you need this.
  101. @xref{__djgpp_set_ctrl_c}, for details on how this should be done.
  102. @kbd{Ctrl-Break} always generates @code{SIGINT}.
  103.  
  104. DJGPP hooks the keyboard hardware interrupt (Int 09h) to be able to
  105. generate @code{SIGINT} in response to @kbd{Ctrl-C} key; you should be
  106. aware of this when you install a handler for the keyboard interrupt.
  107.  
  108. @item SIGSEGV
  109.  
  110. The invalid storage access (Segmentation Violation) signal.  Generated
  111. in response to any of the following exceptions: Bound range exceeded in
  112. BOUND instruction (Int 05h), Double Exception or an exception in the
  113. exception handler (Int 08h), Segment Boundary violation by co-processor
  114. (Int 09h), Segment Not Present (Int 0Bh), Stack Fault (Int 0Ch), General
  115. Protection Violation (Int 0Dh), or Page Fault (Int 0Eh).  Note that Int
  116. 09h is only generated on 80386 processor; i486 and later CPUs cause Int
  117. 0Dh when the co-processor accesses memory out of bounds.
  118.  
  119. @item SIGTERM
  120.  
  121. The Termination Request signal.  Currently unused.
  122.  
  123.  
  124. The signals below this are not defined by ANSI C, and cannot be used
  125. when compiling under @samp{-ansi} option to @samp{gcc}.
  126.  
  127.  
  128. @item SIGALRM
  129.  
  130. The Alarm signal.  Generated after certain time period has passed after
  131. a call to @code{alarm} library function (@pxref{alarm}).
  132.  
  133. @item SIGHUP
  134.  
  135. The Hang-up signal.  Currently unused.
  136.  
  137. @item SIGKILL
  138.  
  139. The Kill signal.  Currently unused.
  140.  
  141. @item SIGPIPE
  142.  
  143. The Broken Pipe signal.  Currently unused.
  144.  
  145. @item SIGQUIT
  146.  
  147. The Quit signal.  Currently unused.
  148.  
  149. @item SIGUSR1
  150.  
  151. User-defined signal no. 1.
  152.  
  153. @item SIGUSR2
  154.  
  155. User-defined signal no. 2.
  156.  
  157.  
  158. The signals below are not defined by ANSI C and POSIX, and cannot be
  159. used when compiling under either @samp{-ansi} or @samp{-posix} options
  160. to @samp{gcc}.
  161.  
  162.  
  163. @item SIGTRAP
  164.  
  165. The Trap Instruction signal.  Generated in response to the Debugger
  166. Exception (Int 01h) or Breakpoint Exception (Int 03h).
  167.  
  168. @item SIGNOFP
  169.  
  170. The No Co-processor signal.  Generated if a co-processor (floating-point)
  171. instruction is encountered when no co-processor is installed (Int 07h).
  172.  
  173. @item SIGTIMR
  174.  
  175. The Timer signal.  Used by the @code{setitimer} and @code{alarm} functions
  176. (@xref{setitimer}, @xref{alarm}).
  177.  
  178. @item SIGPROF
  179.  
  180. The Profiler signal.  Used by the execution profile gathering code in a
  181. program compiled with @samp{-pg} option to @samp{gcc}.
  182.  
  183. @end table
  184.  
  185.  
  186. @subheading Return Value
  187.  
  188. The previous handler for signal @var{sig}, or @code{SIG_ERR} if the
  189. value of @var{sig} is outside legal limits.
  190.  
  191. @subheading Signal Mechanism Implementation Notes
  192.  
  193. Due to subtle aspects of protected-mode programs operation under MS-DOS,
  194. signal handlers cannot be safely called from hardware interrupt
  195. handlers.  Therefore, DJGPP exception-handling mechanism arranges for
  196. the signal handler to be called on the first occasion that the program
  197. is in protected mode and touches any of its data.  This means that if
  198. the exception occurs while the processor is in real mode, like when your
  199. program calls some DOS service, the signal handler won't be called until
  200. that call returns.  For instance, if you call @code{read} (or
  201. @code{scanf}, or @code{gets}) to read text from the console and press
  202. @kbd{Ctrl-C}, you will have to press @kbd{Enter} to terminate the
  203. @code{read} call to cause the signal handler for @code{SIGINT} to be
  204. called.  Another significant implication of this implementation is that
  205. when the program isn't touching any of its data (like in very tight
  206. loops which only use values in the registers), it cannot be interrupted.
  207.  
  208. @c -------------------------------------------------------------------------
  209.  
  210. @node __djgpp_set_ctrl_c, signal
  211. @subheading Syntax
  212.  
  213. @example
  214. #include <sys/exceptn.h>
  215.  
  216. int __djgpp_set_ctrl_c(int enable);
  217. @end example
  218.  
  219. @subheading Description
  220.  
  221. This function sets and resets the bit which controls whether
  222. @code{SIGINT} (@pxref{signal, SIGINT}) will be raised when you press
  223. @kbd{Ctrl-C}.  By default @kbd{Ctrl-C} generates an interrupt signal
  224. which, if uncaught by a signal handler, will abort your program.
  225. However, when you call the @code{setmode} library function to switch the
  226. console reads to binary mode, or open the console in binary mode for
  227. reading, this generation of interrupt signal is turned off, because some
  228. programs want to get the @samp{^C} characters as any other character and
  229. handle them by themselves.
  230.  
  231. @code{__djgpp_set_ctrl_c} lets you explicitly determine the effect of
  232. @kbd{Ctrl-C}.  When called with non-zero value of @var{enable}, it
  233. arranges for @kbd{Ctrl-C} to generate an interrupt; if you call it with
  234. a zero in @var{enable}, @kbd{Ctrl-C} are treated as normal characters.
  235.  
  236. Note that the effect of @kbd{Ctrl-Break} key is unaffected by this
  237. function; use the @code{_go32_want_ctrl_break} library function to
  238. control it.
  239.  
  240. Also note that in DJGPP, the effect of the interrupt signal will only be
  241. seen when the program is in protected mode (@xref{signal, Signal Mechanism},
  242. for more details).  Thus, if you press @kbd{Ctrl-C} while your
  243. program calls DOS (e.g., when reading from the console), the
  244. @code{SIGINT} signal handler will only be called after that call
  245. returns.
  246.  
  247. @subheading Return Value
  248.  
  249. The previous state of the @kbd{Ctrl-C} effect: 0 if the generation of
  250. @code{SIGINT} by @kbd{Ctrl-C} was disabled, 1 if it was enabled.
  251.  
  252. @subheading Example
  253.  
  254. @example
  255.  
  256.   setmode(fileno(stdin), O_BINARY);
  257.   if (isatty(fileno(stdin)));
  258.     __djgpp_set_ctrl_c(1);
  259.  
  260. @end example
  261.  
  262. @c -------------------------------------------------------------------------
  263.  
  264. @node __djgpp_exception_toggle, signal
  265. @subheading Syntax
  266.  
  267. @example
  268.  
  269. #include <sys/exceptn.h>
  270.  
  271. void __djgpp_exception_toggle(void);
  272.  
  273. @end example
  274.  
  275.  
  276. @subheading Description
  277.  
  278. This function is automatically called when the program exits, to restore
  279. handling of all the exceptions to their normal state.  You may also call
  280. it from your program, around the code fragments where you need to
  281. temporarily restore @strong{all} the exceptions to their default
  282. handling.  One example of such case might be a call to a library
  283. functions that spawn child programs, when you don't want to handle
  284. signals generated while the child runs (by default, those signals are
  285. also passed to the parent).
  286.  
  287. @subheading Example
  288.  
  289. @example
  290.  
  291.   __djgpp_exception_toggle();
  292.   system("myprog");
  293.   __djgpp_exception_toggle();
  294.  
  295. @end example
  296.