Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!apple!shebanow From: shebanow@Apple.COM (Andrew Shebanow) Newsgroups: comp.sys.mac.programmer Subject: Re: Tail patches Message-ID: <5063@internal.Apple.COM> Date: 6 Nov 89 18:51:25 GMT References: <1459@sequent.cs.qmc.ac.uk> Organization: Apple Computer Inc, Cupertino, CA Lines: 41 Tail patches are trap patchs which do processing after calling the original trap, or modify the stack before calling the original patch. They're called tail patches because the typically look like this: LEA origTrapAddress,A0 ; do preprocessing JSR (A0) ; do postprocessing Since the bad part is at the end of the patch, its a tail patch. A "clean" patch will have a format like this: ; do processing LEA origTrapAddr,A0 JMP (A0) Tail patching is bad because of the techniques that Apple uses in its System Software to fix bugs. Sometimes, a trap (lets call it _TrapA) has bugs in it which would be very difficult to fix without rewriting the trap's entire code. Rather than do that, Apple will sometimes patch a different trap (_TrapB) which is called by the broken trap (_TrapA). _TrapB will check the address of the caller on the stack and compare it to the hardcoded address of _TrapA's call, and, if the addresses match, behave in a different manner to fix the bug. This can cause a huge savings in speed and memory usage, but it prevents the use of tail patches. Continuing our example, if you patch _TrapA and then JSR to the original _TrapA code, you will have changed the contents of the stack. And believe it or not, some of the patches are involved enough that they look two or three stack levels high. Hope this clears it up, Andy Shebanow Mr. Clean, MacDTS Apple Computer, Inc.