Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!uunet!husc6!cmcl2!nrl-cmf!ames!ptsfa!ihnp4!homxb!mtuxo!mtune!westmark!dave From: dave@westmark.UUCP (Dave Levenson) Newsgroups: comp.sys.ibm.pc Subject: Re: MSC medium model TSR questions Message-ID: <263@westmark.UUCP> Date: Sat, 14-Nov-87 10:19:58 EST Article-I.D.: westmark.263 Posted: Sat Nov 14 10:19:58 1987 Date-Received: Sun, 15-Nov-87 20:33:58 EST References: <8711130253.AA04513@decwrl.dec.com> Organization: Westmark, Inc., Warren, NJ, USA Lines: 47 In article <8711130253.AA04513@decwrl.dec.com>, desmond@smaug.dec.com writes: > I am working on a program that I want to terminate and stay resident and > I have several questions that I would like answers to... > 1) How does one figure out where to mark the end of resident memory? I suggest that you call malloc() requesting 16 bytes. That will get you the next available address in the heap above your data. Round that address up to the next paragraph boundary, and pass that as the end-mark in your tsr system call. > 2) Once the program is resident, can it be terminated a second time with > a normal exit thereby releasing all of its memory back to the system? > Or is the only way to get back all available memory a reboot? I know > there are some PD utilities that supposedly remove TSRs but I don't > want to use something like that. I want a way for my program to remove > itself if possible. No, you cannot call exit, unless you want to terminate the process that MS-DOS thinks is running. You can, however, unlink yourself from the interrupt you use to gain control while terminated and kept resident, and then free your memory with memory de-allocation system calls. You must free your PSP and your environment block, to fully clean up. > 3) If after termination, the resident C code does some calls to malloc(), I would recommend doing all of your malloc() calls before you terminate and stay resident. Otherwise, you'll probably get an error return from a malloc() call as some other process will probably have claimed the memory above yours. > I would appreciate any information about these questions and anything else Watch out if you issue MS-DOS system calls from your TSR. In particular, if MS-DOS is already processing a system call, you should wait until it returns to its caller. If you open any files, make your PSP current, or you'll be taking file descriptors from the running process. If you save the previous content of any interrupt vectors, in an attempt to restore them later on, be aware that the TSRs that get loaded after yours does are probably doing the same thing, so you'll have to free your TSR's in the opposite order of that in which they were loaded. -- Dave Levenson Westmark, Inc. A node for news. Warren, NJ USA {rutgers | clyde | mtune | ihnp4}!westmark!dave