Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!spool.mu.edu!agate!dog.ee.lbl.gov!ux1.lbl.gov!osborn From: osborn@ux1.lbl.gov (James R Osborn) Newsgroups: comp.sys.mac.programmer Subject: Toolbox Patching Summary: What is the preferred method? Keywords: patch Message-ID: <13613@dog.ee.lbl.gov> Date: 28 May 91 17:31:32 GMT References: <1991May28.163618.8353@crash.cts.com> Reply-To: osborn@ux1.lbl.gov (James R Osborn) Organization: Lawrence Berkeley Laboratory Lines: 49 X-Local-Date: Tue, 28 May 91 10:31:32 PDT Just what exactly is the preferred method for applying a tail patch to a Toolbox routine? I've read all sorts of stuff that waves its (metaphorically speaking) hands and never explicitly says how to do it. Maybe I've missed a tech note that describes the process? Here is something that I have done that worked but seems incredibly unelegant and kludgey: using an init (this part seems ok to me): load the patch routine into the system heap with the init DetachResource it HNoPurge it HLock it save original trap address in the patch routine's header set the trap address to point at the patch then in the patch: the patch routine gets passed the appropriate arguments for the trap being patched do my preprocessing, whatever it is set trap address to original trap address (from header) call trap, passing appropriate arguments, and saving result (if necessary) set trap address back to this patch return result (if necessary) Why did I do it this way? Because I used C and was too lazy to figure out how to call the trap routine directly myself using assembly. I presume the preferred method is to push the appropriate arguments onto the stack (pascal fashion) and then JSR to the original trap? Then I wouldn't be SetTrapAddress'ing all over the place. Would my psuedo-code above then be preferred? (Or am I totally or even partially blowing it? 8^) -- James .------------------------------.--------------------------------------. | James R. Osborn | It just goes to show you it's always | | Lawrence Berkeley Laboratory | something. Either it's baffling | | osborn@ux1.lbl.gov | tech notes or your mac is smoking. | | (415) 548-8464 | It's always something... | '------------------------------'--------------------------------------'