rmal@cernvax.UUCP (richard lucock) (04/11/90)
Does anyone know if there is a procedure that can be called to set up an exit-handler ? - ie to declare a user routine that will be called before the program is removed from the system (even in event of an exception such as address error, etc). Or, failing this, does anyone know *how* a program is cleaned up ? (ie what part do compiler suplied routines play, what part do system routines play, etc). Thanks, Richard
mks@cbmvax.commodore.com (Michael Sinz - CATS) (04/12/90)
In article <1720@cernvax.UUCP> rmal@cernvax.UUCP (richard lucock) writes: >Does anyone know if there is a procedure that can be called to set up >an exit-handler ? - ie to declare a user routine that will be called >before the program is removed from the system (even in event of an >exception such as address error, etc). Just write a routine that calls the normal entry point. Exiting a program is done by doing an RTS. > >Or, failing this, does anyone know *how* a program is cleaned up ? >(ie what part do compiler suplied routines play, what part do system >routines play, etc). Thanks, This depends on if the program ran from WorkBench or the CLI. However, the compiler stuff is always the same. The SYSTEM (the OS) will cleanup the task structure (process structure) and any CLI stuff. It will also unload the code segments (via UnLoadSeg()) if your code was not resident. It will also free the memory for the task (or process) structure, the stack, and anything else that is in the task structure's tc_MemEntry memory list. (They can be allocated via AllocEntry and AddHead() (or AddTail()) to the tc_MemEntry list.) The compiler (or the standard library code) must free anything that it allocates and does not link in with the system. This usually goes for any memory from malloc() (and its varients), file handles from open() and fopen() (all level 1 and level 2 I/O, not the AmigaDos Open()) and any other thing that is done with standard library calls. AmigaExec calls to things such as AllocMem() are the responsibility of the programmer. They may be items that are linked to the tc_MemEntry of the task or they are things that the programmer calls the correct deallocation routines for. /----------------------------------------------------------------------\ | /// Michael Sinz -- CATS/Amiga Software Engineer | | /// PHONE 215-431-9422 UUCP ( uunet | rutgers ) !cbmvax!mks | | /// | |\\\/// "I don't think so," said Ren'e Descartes. | | \XX/ Just then, he vanished. | \----------------------------------------------------------------------/