Date: Sun, 27 Dec 1998 14:16:40 +0200 (IST) From: Eli Zaretskii X-Sender: eliz AT is To: jp-morris cc: djgpp AT delorie DOT com Subject: Re: 2.02 - atexit and exceptions? In-Reply-To: <36802506.8847AB34@uwe.ac.uk> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com 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.