Newsgroups: comp.sys.mac.programmer Path: utzoo!utgpu!news-server.csri.toronto.edu!mailrus!wuarchive!psuvax1!xavier!jackiw From: jackiw@cs.swarthmore.edu (Nick Jackiw) Message-ID: <5YDJD23@xavier.swarthmore.edu> Sender: jeremy@xavier.swarthmore.edu (Jeremy Brest) Reply-To: jackiw@cs.swarthmore.edu (Nick Jackiw) Organization: Visual Geometry Project, Swarthmore College, PA References: <11608@unix.SRI.COM> Date: Wed, 2 May 90 14:47:28 GMT mxmora@sri-unix.sri.com (Matt Mora) writes: > is this crude outline correct? > > init31 loads my init into memory > recover handle to myself > lockmyself Lock your INIT resource (with ResEdit) instead. > newtrapadd=(load the new code into systemheap,lockit and return the address) > > oldtrap=GetTrapAddress(trapNum); > SetTrapAddress(NewtrapAddr, trapNum); {set new add} > > BlockMove(@oldtrap,@newtrapadd+2,4); {save the old add into the new code} > > > In the new trap code, do I jsr or jmp to the old address? JMP. JSR would imply that the trap will eventually return to your patch, the cancerous blight known as tail patching. This looks good. Though the way you've outlined it, your trap patch is treated by the loader as data, and therefore, not subject to control cache problems, it can't hurt to say that writing self-modifying code is bad practice in many instances. So, rather than do something like this LOADER: lea ,A0 move.l A0, ... CODE: jmpInst: JMP xxxxxx ; Jump to the old address which writes the address to jump to into your code, it's preferable to do LOADER: lea ,A0 move.l A0, CODE: MOVE.L ,A0 JMP (A0) dataSpace: DCB.L 1 which keeps the variable-and-therefore-potentially-cached address outside of the control thread of your program. > > > Thanks > > -- > ___________________________________________________________ > Matthew Mora > SRI International mxmora@unix.sri.com > ___________________________________________________________ -- ------------------------ Nick Jackiw jackiw@cs.swarthmore.edu "Every minute of the future Visual Geometry Project jackiw@swarthmr.bitnet is a memory of the past." Swarthmore College, PA 19081-1397 -Laivach