[comp.sys.mac.programmer] Q: patching traps

sl161022@silver.bacs.indiana.edu (01/30/89)

I am currently writing a CDEV (in assembly language) and want to
make sure I am doing memory allocation correctly.

In the CDEV is an INIT resource.  It installs a routine in memory
which is to remain for as long as the Mac is turned on.  (The routine
is a patch for a particular trap, and thus the routine must stay in
memory once it is installed.)  Normally I would presume the system heap
to be the ideal location.

Inside MacIntosh Vol IV suggests subtracting the amount of room
you need from BufPtr, and then copying whatever you want to that
address and above.  This does NOT appear to me to be in the system heap.

But then IM V says to add an 'sysz' resource to your CDEV, the first
4 bytes of which say how much memory you want for your INIT.  The
INIT 31 resource, which has been executing and has found your sysz
resource, expands the system heap by that amount with SetApplZone.
(Or so I would assume.)

Now this new feature of INIT 31 was apparently not available when
IM IV was published.  Meaning, I guess, that previous versions of the
System don't do this.  In which case, booting up with an earlier
System with my CDEV around might cause problems, since the sysz
resource would be completely ignored, and the system heap just
stays the same size as it was.  Hence my INIT may not find enough
memory available, even if there's RAM to burn.

Secondly, even if we are running with a more recent system, and INIT 31
has expanded the system heap, is there any particular place I should
put my trap patch?  Or should I do it, as I have been, by storing the
patch as a private resource in the CDEV, with its SysHeap and Locked
attributes set, and having my INIT load this in memory with GetResource?

What do the "pros" do?

Thanks in advance...
__________________________________________________________________

"May the forces of evil become confused on the way to your house."

Sincerely,                                        -- George Carlin
           Phaedrus
           (aka Colin Klipsch)
           sl161022@silver.bacs.indiana.edu
           Indiana University at Bloomington