Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!usc!snorkelwacker!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: How do I expand system heap from an INIT? Message-ID: <9726@goofy.Apple.COM> Date: 13 Aug 90 21:07:17 GMT References: Organization: Apple Computer Inc., Cupertino, CA Lines: 53 In article mrr@mrsoft.Newport.RI.US (Mark Rinfret) writes: >I've written a device driver which supports inter-application messages and >symbol management. It works great under MultiFinder and it also works >great under Finder when TMON is running :-). When run with Finder sans >TMON, the system usually crashes on my first attempt to start an >application. > >The problem, I'm certain, is that it requires more system heap than is >available from the standard system. I don't want to modify the boot >blocks, so I need a way for the INIT (which installs the driver) to expand >the system heap. > >I gather (from some snooping through TMON Startup) that the way to do this >is roughly as follows: > > - Copy the INIT resource onto the stack. I believe this is necessary > since the current application zone will be trashed when the heap > is expanded (right?). > - adjust the stack pointer (saving original) > - jump into relocated code at next instruction (_ReleaseResource) > - call SetAppBase with (ApplZone + additional size) > - perform other chores (install driver, etc.) > - restore stack pointer > - return > >Everything works fine (or appears to) until I restore the stack pointer. >It appears to be off by a longword (no simple explanation - I've done my >"stack arithmetic") and I end up back at the top of the INIT code. Forcing >the stack pointer to the correct value (tried it once) caused a crash. > >I've spent a fair amount of time tracking this problem. Before I pursue it >further, I'd like to know if I'm on the right track with regard to system >heap expansion. If anyone has some sample code for "doing it right", I'd >very much appreciate it if you'd send me a copy. Thanks very much. Another way that doesn't require programming gymnastics is to include a 'sysz' resource ID=0 in your INIT file. The resource contains a single longint that tells how much to grow the system heap if there isn't already enough space available. INIT 31 will then handle this for you before your INIT starts executing... steve -- ____________________________________________________________________ Steve Christensen Internet: stevec@goofy.apple.com Apple Computer, Inc. AppleLink: STEVEC 20525 Mariani Ave, MS 81-CS CompuServe: 76174,1712 Cupertino, CA 95014 "You just contradicted me." "No I didn't." ____________________________________________________________________