Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!news.funet.fi!fuug!clinet!dix From: dix@clinet.fi (Risto Kaivola) Newsgroups: comp.sys.amiga.programmer Subject: Creating a 'Front-End' For Library Functions Keywords: system integrity, libraries, SetFunction Message-ID: <1991Jun25.084622.13642@clinet.fi> Date: 25 Jun 91 08:46:22 GMT Organization: City Lines Oy, Helsinki, Finland Lines: 40 In a recent project I've had to create a front-end for certain dos.library functions, meaning that first I patch a piece of code so that it will jump to the library routine in question, and then change the library jump vector so that it will jump to my code. So far, no problem (provided, of course, that I remember to call the appropriate cache-handling library routines). But when I'm finished, and want to remove the front-ends, and thus return the system to the state in which it was earlier on, problems arise. Obviously, I can't just return the library jump vector to its earlier state, and then free the memory allocated for my code. If I did that, I would take the chance that the system crashes when some task is executing off non-allocated memory, and some other task allocates this memory block then placing its data in this block. The possible solutions I've thought of are as follows: (a) Create a front-end for the OpenLibrary function, and implement my own version of resource tracking. The front-ends for the dos.library functions will not be freed until all processes that have opened the dos.library after I inserted the front-end have closed the dos.library. To prevent the same kind of system malfunction as with the dos.library functions in the first-mentioned scenario, leave this front-end there when we're finished. Not very clean, but there isn't so much memory lost. (b) Do not fiddle with any other routines (like OpenLibrary), but rather, when finished, first make the library jump vector point to the real library routine, and then Forbid task switching. Check each processes task structure to determine whether it's executing my code. If there is a process that is doing so, wait for a while, then do the same check again. When there no longer are processes executing my code, free the memory block allocated for the code. (c) Do not worry about the memory loss caused by leaving the front-end or front-ends hanging around. This is no real solution. Please tell me your suggestions and opinions on the issue. I apologize for the lengthy posting. Risto -- Risto Kaivola (dix@clinet.fi) or (Risto.Kaivola@f123.n220.z2.FIDONET.ORG)