Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!uwm.edu!cs.utexas.edu!usc!apple!apple.com!chewy From: chewy@apple.com (Paul Snively) Newsgroups: comp.sys.mac.programmer Subject: Re: converting tail patches to head patches... Message-ID: <5437@internal.Apple.COM> Date: 27 Nov 89 23:07:08 GMT References: <63359@tiger.oxy.edu> Sender: usenet@Apple.COM Distribution: usa Organization: Apple Computer, Inc. Lines: 60 First of all, thanks for making the effort to avoid tail-patching! :-) Now, to work: In article <63359@tiger.oxy.edu> sonenbli@oxy.edu (Andrew D. Sonenblick) writes: > Now, how I changed things for to make it a head patchy-watchy... > > myPatch() > { > long rtsAddr; > asm{ > Move.L (SP)+,rtsAddr /* save return address in rtsAddr */ > } > doMyStuff(); > asm{ > Move.L rtsAddr,-(SP) > Lea @1,A0 > Move.L (A0),A0 > Jmp (A0) > } > > } > > Ok, so, what's the ups with this? (I have tried all sorts of things > similar to this--most just make my mac hang, some crash, none works.) > > Needless to say, if anyone has insights into this, I--perhaps others > on the net would too--would appreciate the help. A couple of comments: Since the problem with tail-patching is that the ORIGINAL code that you're calling may check the return address, your approach of removing the return address at the beginning of the patch and replacing it immediately before jumping to the original code doesn't help. In fact, one reason that you're probably crashing is because you've done the same thing (semantically) as if you had simply changed your original JSR to a JMP! Not a good idea. Now for the good news: if you're trying to patch _SystemTask, you can probably get away with it, because I don't believe that _SystemTask is called from within the ROM, which means that it won't be patched by us with this nasty come-from code that's causing all of the headaches. As Larry Rosenstein pointed out, you have a higher probability of being "patch safe" with traps that have a high probability of not being called from ROM. Hope this helps. __________________________________________________________________________ Just because I work for Apple Computer, Inc. doesn't mean that they believe what I believe or vice-versa. __________________________________________________________________________ C++ -- The language in which only friends can access your private members. __________________________________________________________________________