Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!brutus.cs.uiuc.edu!apple!apple.com!chewy From: chewy@apple.com (Paul Snively) Newsgroups: comp.sys.mac.programmer Subject: Re: Tail patches Message-ID: <5056@internal.Apple.COM> Date: 6 Nov 89 17:01:05 GMT Sender: usenet@Apple.COM Organization: Apple Computer, Inc. Lines: 68 References:<1459@sequent.cs.qmc.ac.uk> <36250@apple.Apple.COM> In article <36250@apple.Apple.COM> marc@Apple.COM (Mark Dawson) writes: > In article <1459@sequent.cs.qmc.ac.uk> jeremyr@cs.qmc.ac.uk (Jeremy Roussak) writes: > > > >I hope the net will pardon my ignorance, but I have seen a few comments > >recently about "tail patching" of traps and have a couple of questions: > > > >1. What exactly are "tail patches"? > >2. If they are what I suspect they are, why are they bad? > > > > 1. There are times that you may wish to replace or modify a Mac trap call > (Say for example, _Write). Suppose you have this horribly gross program > that passes the volume name, instead of the drive # to the _Write call. > You could write an intercept routine that would decode this name into the > correct drive # and drive refnum for the "real" system _Write call. It > would then call the system _Write (This would be a "head" patch). You > could direct the system _Write to return to another piece of code (the > "tail" patch) to do some special cleanup if there was some error. > > The problem with the "tail" patch is that there is some possibility that > an Apple patch to that routine (to fix some bug/enhance it) might be > checking the return address to see if it should do something. Since your > return address would be on the stack first, this check would fail. Before > I worked at Apple I did use both the "head" and "tail" patches; I didn't see > anyway around them. I also never ran into this "return address check". I > am always crossing my fingers, hoping this case will never happen (it would > REALLY break my code). > > Someone else in Apple will have to comment on if they know of any of patches > that DO check the return addresses. I don't know of any, but I don't claim to > know the whole system. Below is a snippet of code to do head & tail patches. [Evil code deleted...] ARRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRGH!!! PLEASE PLEASE PLEASE don't do tail patches! Mark gives a reasonably cogent explanation as to WHY you shouldn't tail patch, and then explains how to do it!? [sigh...] Listen now, and listen hard: you CAN'T KNOW AHEAD OF TIME WHETHER ANY TRAP WILL EVER HAVE "COME-FROM" RETURN-ADDRESS CHECKING OR NOT. Just because it doesn't under System 6.0.3.7.2.1.8 on the Macintosh IIsex doesn't mean that it NEVER has or NEVER will! DON'T TAIL PATCH. __________________________________________________________________________ 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. __________________________________________________________________________