www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/12/27/07:16:27

Date: Sun, 27 Dec 1998 14:16:40 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
X-Sender: eliz AT is
To: jp-morris <Joseph DOT Morris AT uwe DOT ac DOT uk>
cc: djgpp AT delorie DOT com
Subject: Re: 2.02 - atexit and exceptions?
In-Reply-To: <36802506.8847AB34@uwe.ac.uk>
Message-ID: <Pine.SUN.3.91.981227141259.434D-100000@is>
MIME-Version: 1.0
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.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019