[EMAIL PROTECTED] wrote:

> It calls SysGetStackInfo to get the low-end of the stack, takes the address of a
> local variable to get something close to the current stack pointer, and compares
> the two.
>
> But what confuses me is why Poser wouldn't report the problem first. Version
> 3.0a4 checks for this.

Thanks for the info. Does the above check guarantee that the local variable is 
actually allocated on the stack? With respect, what
if the compiler was using a register to store the local variable? Why not use the 
value of the A7 register instead?

Anyway, confession time! I'm actually allocating my own stack prior to calling 
TimSetSeconds. If I don't then I actually get the
stack overflow error at some point later via gremlins.

I'd certainly appreciate finding out exactly why the NotifyMgr is having a hard time. 
Perhaps someone could ship me the actual
code for PrvCheckStackSpace (I signed all the stuff for OS source and do have the 3.0 
source).

Anyhow here's the code that I use to allocate my stack and call TimSetSeconds. Maybe 
there's something obvious that I'm doing
wrong:

*****
#pragma stack_cleanup on

void Teenee::TimSetSecondsWithNewStack(ULong inSetSeconds) Throw_()
{
 /*
  * Ensure that the param is register based and not on the stack given that the stack
  * will be unreferencable shortly.
  */

 register ULong thePassedInSeconds = inSetSeconds;

 /*
  * Allocate a new stack and continue if we're successful.
  */

 const int theNewStackSize = 2.5 * 1024;
 register Ptr theNewStackStartP = static_cast<Ptr>(::MemPtrNew(theNewStackSize));
 if (theNewStackStartP)
 {
  /*
   * Calculate the end of the stack (the top) and initialise it with something
   * that PalmOS wants to see.
   */

  Ptr theNewStackEndP = theNewStackStartP + (theNewStackSize - sizeof(long));
  ::MemSet(theNewStackStartP, theNewStackSize, 0xFE);

  /*
   * If we're OS 3 or more then we must preserve app preferences given that checks
   * against the stack pointers are made by some OS functions.
   */

  DWord theRomVersion = 0;
  ::FtrGet(sysFtrCreator, sysFtrNumROMVersion, &theRomVersion);
  register bool theOSIsV3 = (theRomVersion >= sysMakeROMVersion(3, 0, 0, 0, 0));

  register SysAppInfoPtr theAppInfoP;
  register Ptr theOldStackStartP;
  if (theOSIsV3)
  {
   SysAppInfoPtr theUnusedAppInfoP;
   theAppInfoP = ::SysGetAppInfo(
          &theUnusedAppInfoP,
          &theUnusedAppInfoP
          );
   if (!theAppInfoP->stackP)
    theAppInfoP = theAppInfoP->rootP;
     // If we don't have a stack then we're using our parents.

   theOldStackStartP = theAppInfoP->stackP;
   theAppInfoP->stackP = theNewStackStartP;
   theAppInfoP->stackEndP = theNewStackEndP;
  }

  /*
   * Assign the new stack
   */

  register Ptr theOldStackEndP = static_cast<Ptr>(SetA7(theNewStackEndP));

  /*
   * Do what we came to do
   */

  ::TimSetSeconds(thePassedInSeconds);

  /*
   * Restore our world and free the stack that we created
   */

  SetA7(theOldStackEndP);
  if (theOSIsV3)
  {
   theAppInfoP->stackP = theOldStackStartP;
   theAppInfoP->stackEndP = theOldStackEndP;
  }

  ::MemPtrFree(theNewStackStartP);
 }
}

#pragma stack_cleanup reset
*****

Incidentally if anyone wants to get into a philosophical discussion as to why I 
shouldn't be allocating my own stack then please
do so in a new thread entitled, 'stack philosophy'; I really want to solve the above 
problem in isolation!  :-)

Kind regards,
Christopher
--
Christopher Hunt
Class Action Pty. Ltd.

Complete time zone management for the Palm(tm) connected organizer.
Check out http://www.classactionpl.com/


-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palm.com/devzone/mailinglists.html

Reply via email to