[alt.msdos.programmer] termination handler address

venkat@matrix.UUCP (D Venkatrangan) (05/04/90)

I am attempting to trap the exit of a program so I can clean up things
that DOS would not clean up (such as interrupt vectors that were changed).
As per well-documented sources, I am replacing int 1bh, int 22h and int 23h
vector entries.

After initializations, I do see that these entries are changed to entry
points within the code.  When the program exits (through an exit() call from
a C function), I see that my handlers are not being called.  I can trace
up to the int 21 (function 4ch) instruction without my handlers being called.
Are they called as part of the 4ch function processing?  In my handler,
I do the cleanup that I need to do and then jump to the handler value that
I saved before installing my entry.  (this old handler I guess is supposed to
copy the old values for the int 22h/23h etc. from the PSP of the program).

If instead the program does a terminate and stay resident (function 31h), will
my termination handler be called as well?  If so, is there a way to distinguish
whether the call to an exit handler is from function 31h as opposed to
function 4ch?  If it is the stay resident case, I do not want to do the
cleanups.

Is there an established way to do this correctly?

dixon@sagittarius.crd.ge.com (walt dixon) (05/04/90)

In a previous article D Venkatrangan writes:

.I am attempting to trap the exit of a program so I can clean up things
.that DOS would not clean up (such as interrupt vectors that were changed).
.As per well-documented sources, I am replacing int 1bh, int 22h and int 23h
.vector entries.
.
.After initializations, I do see that these entries are changed to entry
.points within the code.  When the program exits (through an exit() call from
.a C function), I see that my handlers are not being called.  I can trace
.up to the int 21 (function 4ch) instruction without my handlers being called.
.Are they called as part of the 4ch function processing?  In my handler,
.I do the cleanup that I need to do and then jump to the handler value that
.I saved before installing my entry.  (this old handler I guess is supposed to
.copy the old values for the int 22h/23h etc. from the PSP of the program).

.If instead the program does a terminate and stay resident (function 31h), will
.my termination handler be called as well?  f so, is there a way to distinguish
.whether the call to an exit handler is from function 31h as opposed to
.function 4ch?  If it is the stay resident case, I do not want to do the
.cleanups.

The termination address (at least in DOS 3.x) is designed to return control
to the *PARENT* process.  One of the very first things done in the terminate
(Ah=4c)/abort(ah=0) code is to restore the terminate, break, and critical
error handler addresses FROM THE PSP TO THE IVT.  Terminate and stay resident
(ah=31h) updates the size of the PSP before restoring the handler addresses.
Omiting some details,  the common termination code deallocates all MCBs
owned by the terminating process and closes all open files (unless executing
a TSR request) and returns to the PARENT at the termination address.

As far as telling whether a TSR or normal Terminate was invoked,  look at
the Job File Table.  Terminate closes all files.

I hope this helps.

Walt Dixon	{internet:	dixon@crd.ge.com	}
		{us mail:	ge crd			}
		{		po box 8		}
		{		schenecdady, ny 12301	}
		{phone:		518-387-5798		}
Walt Dixon dixon@crd.ge.com