Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!unmvax!unm-la!lanl!cmcl2!ccnysci!alexis From: alexis@ccnysci.UUCP (Alexis Rosen) Newsgroups: comp.sys.mac.programmer Subject: Re: Legal Tail Patches Message-ID: <1285@ccnysci.UUCP> Date: 17 Feb 89 07:21:49 GMT Reply-To: alexis@ccnysci.UUCP (Alexis Rosen) Organization: City College of New York Lines: 43 I'm astonished that I've only gotten one letter (and no flames) asking "how does this scheme overcome the problem with tail patches, since the problem is a come-from address check?" The answer is, it doesn't. I've got to admit, it was pretty harebrained. Especially the business about going through the trap dispatcher twice. HOWEVER- when I first thought of the idea, I got it right (I think). When I sat down to type it up my mind had wandered (_far_away_). The revised scheme, with better explanation: This method is not 100% general, in that the patch won't always execute. It will execute when it knows that your application called it, otherwise not. This may be a significant restriction, but I think it's still useful. 1) Test if the caller is the application 2) If it is, save the return address off of the stack, and JSR to the original routine 3) Otherwise, JMP to the original routine 4) Return to the caller The tricky part is #1, but since you are writing your application, you have a priori knowledge of where your app lives (usually in the app heap). So it shouldn't be too dificult to tell when to do what. Anything calling from the Application heap is OK. Anything else is verboten. I wonder how useful this would be for INITs and such. After all, they can't always be certain who is calling the trap, but it seems that anything sitting in the application heap or above MemTop should be OK. The system heap is out (that's where Apple's patches go, right?). Also, if the trap you are patching has a true ROM address, it can't have the kind of come-from checking code that tail patches break, so it should be OK to patch regardless of who calls it. (This assumes that Apple won't ship ROMs that have these ugly-but-useful hacks- they only get installed as bug fixes in the System Software). That would seem to leave a lot of room open for INITs. On the other hand, I've never written an INIT that does anything, so I'm not sure... Now, what say you? (this time :-) Alexis Rosen alexis@ccnysci.uucp