Path: utzoo!utgpu!water!watmath!clyde!att!gargoyle!tank!nucsrl!bob From: bob@eecs.nwu.edu (Bob Hablutzel) Newsgroups: comp.sys.mac.programmer Subject: Re: Multifinder: how do I patch GetNextEvent? Message-ID: <10050025@eecs.nwu.edu> Date: 11 Oct 88 13:17:32 GMT References: <747@ttrdf.UUCP> Organization: Northwestern U, Evanston IL, USA Lines: 41 >>> What is the proper way to patch the GetNextEvent() trap for >>> compatibility with MultiFinder?. I have created an INIT that >> [ bunch of stuff deleted ] >> >>The problem here is that you have written a "tail patch". This is a critter >>that does it's work _after_ the original ROM routine. These are verboten, since >>some of Apple's patches to the OS rely on the return address of the call. >What I'm still trying to figure out is this: Why does Apple persist in >forbidding a very useful type of patch? Just so they can continue to use >a kludge in their own patches? The necessity of such a proscription has >still not been explained to my satisfaction. The reason is that the OS is burned into ROMs. ROMs have the annoying property of being hard to patch at startup time. Thus, is a bug is found in the ROM code, Apple is left with two choices: 1) Patch the entire trap the bug is in. This is, of course, the best idea, and the reason that _GetTrapAddress /_SetTrapAddress were originally included in the system. However, there are cases when the trap to be patched is very large (in terms of ROM code), and the patch would eat up an equal amount of RAM. This is especially the case when the bug is in the middle, or toward the end, of large traps. In this case, route 2 is taken: 2) Find some small trap called at about the area of the bug in the large trap, and patch this trap to check to see where it's called from, and if it's called from the buggy large trap, do some additional work for the buggy trap (to fix the bug), and maybe even change the return address to bypass the buggy code. This, needless to say, saves space in RAM, but has the unpleasant side affect of requiring the trap return address to be constant (remember, we're dealing with ROM addresses here) for the patch to work. Thus, tail patching will cause the patch to fail, and possibly bring back old bugs from the dead. Bob Hablutzel BOB@NUACC.ACNS.NWU.EDU Disclaimer: Night of the unliving bug. Scary thought, eh?