19.7 Deinstalling TSRs

A TSR should provide a means for the user to remove or “deinstall” it from memory. Deinstallation returns occupied memory to the system, offering these benefits:

The freed memory becomes available to subsequent programs which may require additional memory space.

Deinstallation restores the system to a normal state. This allows sensitive programs that may be incompatible with TSRs a chance to execute without the presence of installed routines.

A deinstallation program must first locate the TSR in memory, usually by requesting an address from the TSR's multiplex handler. When it has located the TSR, the deinstallation program should then compare addresses in the vector table with the addresses of the TSR's handlers. A mismatch indicates that another TSR has chained a handler to the interrupt routine. In this case, the deinstallation program should deny the request to deinstall. If the addresses of the TSR's handlers match those in the vector table, deinstallation can safely continue.

Deinstall the TSR in three steps:

1.Restore to the vector table the original interrupt vectors replaced by the handler addresses.

2.Read the segment address stored at offset 2Ch of the resident TSR's program segment prefix (PSP). This address points to the TSR's “environment block,” a list of environment variables that DOS copies into memory when it loads a program. Place the block's address in the ES register and call DOS Function 49h (Release Memory Block) to return the block's memory to the operating system.

3.Place the resident PSP segment address in ES and again call Function 49h. This call releases the block of memory occupied by the TSR's code and data.

The example program in the next section demonstrates how to locate a resident TSR through its multiplex handler and deinstall it from memory.