Path: utzoo!utgpu!water!watmath!clyde!att!pacbell!well!brecher From: brecher@well.UUCP (Steve Brecher) Newsgroups: comp.sys.mac.programmer Subject: Re: Multifinder: how do I patch GetNextEvent? Message-ID: <7409@well.UUCP> Date: 17 Oct 88 19:18:07 GMT References: <747@ttrdf.UUCP> <10050025@eecs.nwu.edu> <2456@spray.CalComp.COM> <7374@well.UUCP> <5654@hoptoad.uucp> Reply-To: brecher@well.UUCP (Steve Brecher) Organization: Software Supply, Sunnyvale, CA Lines: 38 In article <5654@hoptoad.uucp>, tim@hoptoad.uucp (Tim Maroney) writes: > Whether or not there is a tail patch would appear to have no effect on the > return-address Apple hacks. ... A tail patch by definition first calls the > old trap software. Example: Let us presume that (hypothetical) ROM routine RsrcMgrTrap is patched by Apple, and the patch has a "come from" check to see if it is being called by FontMgrTrap. The purpose of the RsrcMgrTrap patch is to fix a bug in FontMgrTrap. Hence Apple's patch for RsrcMgrTrap would look schematically like this: Apple_RsrcMgrTrap_Patch: if return_Address = some_ROM_address_In_FontMgrTrap then do_Something_To_Fix_The_FontMgrTrap_Bug; jump to Original_RsrcMgrTrap_Code Now I as third-party programmer provide an INIT that patches RsrcMgrTrap with a tail patch, i.e., My_RsrcMgrTrap_Patch: Jsr Previous_RsrcMgrTrap ; equivalent to Jsr Apple_RsrcMgrTrap_Patch Do_Some_Stuff FontMgrTrap calls RsrcMgrTrap via an A-line trap instruction which gets the trap address from the dispatch table. My_RsrcMgrTrap_Patch is executed. My patch calls Apple's patch, Apple_RsrcMgrTrap_Patch; that patch sees my return address, not FontMgrTrap's, on the stack, so the bug in FontMgrTrap is not fixed. Note that Apple's patches are installed first (before INITs execute). In the process of installing a patch, the installation code gets the old trap code address via GetTrapAddress, and then installs the new patch via SetTrapAddress. The trap dispatch table thus contains the address of the most recently installed patch. By adding a tail patch to what is in effect a linked list of patches, I invalidate any "come from" patches installed earlier in the list.