Mail Archives: djgpp/1998/12/27/07:16:27
On Tue, 22 Dec 1998, jp-morris wrote:
> I use atexit() to catch the program ending, and it calls the MIDAS
> functions to shut down the interrupt processes safely.
This is not a good solution. When a program is aborted (by a call to
`abort') or crashes, the call to `exit' is bypassed, and so your
cleanup function is not called.
In general, if you need to make sure something is done before the
program exits, no matter how hard did it crash, you need to install a
signal handler for every possible signal, and make it either call
`exit' or invoke your cleanup function and call `_exit'. The signals
you should care in particular are SIGINT, SIGQUIT, SIGABRT, SIGSEGV,
SIGTRAP, SIGILL, and SIGFPE.
Alternatively, you could declare your cleanup function with
__attribute__((destructor)), which will cause GCC to generate code
that causes this function to be called just before the program
finishes. However, this method is specific to GCC.
> This has worked perfectly in 2.01, but it is causing havoc in 2.02.
That's because in v2.01, programs were aborted with a call to `exit',
whereas in v2.02, they don't. This change is a feature: bypassing
`exit' leaves the things as they were at the moment of crash (e.g.,
temporary files are not removed), so you can debug the program easier.
> This means that if my program crashes or causes an int 3 to get a stack
> trace, the clock and the DMA processes seem to be still running even
> when the program has finished and is back in DOS.
> I end up with a GPF or PAGEFAULT in RMCB and the system clock stops.
Sure thing: you leave the timer pointing to the void, so the system
will wedge immediately.
- Raw text -