Hi Neil.

I spoke to soon about this working perfectly.  It seemed fine at first glance, but now it's crashing fairly regularly, but not always at the same spot.  I found this post of yours from last year:

http://news.palmos.com/read/messages?id=192785

You list your PilotMain logic as the following:

1) call _CW_SetupExpandedMode ( )
2) Get Reference count for App // Should be zero if we have just been
launched
3) Inc and save Reference Count
4) If launched without globals, and ref count = 1 (i.e. this is not a
nested launch) call MTWK::__LoadAndRelocate__ to relocate extra segments
5) Do Main program logic
6) Dec and save Reference Count
7) if RefCount 0 && lunched without globals call
MTWK::__LoadAndRelocate__ again to clean up
8) exit


Is this still how you do things?  If so, do you just create a ref count and store it in a db somewhere (since you don't have globals)?  Did you ever figure out whether you were supposed to call
_CW_SetupExpandedMode on nested launches?

Thanks again,
Gary



Neil Whitworth wrote:
Which version of CW do you have.

We have done this successfully with CW 9.3.

__LoadAndRelocate__() should not access globas.

Our start up code looks like this:-

_CW_SetupExpandedMode ( );

if ( !(launchFlags & sysAppLaunchFlagNewGlobals) )
{
    SysAppInfoType *appInfoP = NULL;
    SysAppInfoType *rootAppInfoP = NULL;

    appInfoP = SysGetAppInfo(&rootAppInfoP, &appInfoP);
           
    /* Relocate multi-segment applications */
    MTWK::__LoadAndRelocate__(true, appInfoP->codeH);
}


Ralf Dietrich wrote:
I have also tried the suggested way:

a) Patch "PalmOS_Startup.cpp" from runtime to remove "static" from __LoadAndRelocate__() and export __LoadAndRelocate__() in  CWPalmOS.h
Recompile CWs "Palm OS Runtime".
Is there a easier way to get access to __LoadAndRelocate__() ?

b) Call __LoadAndRelocate__() in a single-segment-situation (e.g. sysAppLaunchCmdNotify):

SysAppInfoType *appInfoP = NULL;
SysAppInfoType *rootAppInfoP = NULL;

appInfoP = SysGetAppInfo(&rootAppInfoP, &appInfoP);        MTWK::__LoadAndRelocate__(true, appInfoP->codeH); // load segments
AcceesFunctionFromSecondSegement(); // <- crashes!
MTWK::__LoadAndRelocate__(false, appInfoP->codeH); // unload segments

Any function call to segment two crashes. Anyone can outline this?
Note: The Emulator report accese to globals in __LoadAndRelocate__()

Enviroment:
CW 9.3 Pro

Neil Whitworth wrote:

Gary wrote:

Thanks very much Neil.  I don't actually need globals, so assuming this works I should be all set to go!

Thanks,
Gary

Its a trick we use in all our apps. I'd recommend reading the code in the runtime library, as there are some situations when you don't need to call it as the runtime does itself (normal launch being one), and you should only  ever call it once. Calling it a second time will cause problems as the inter-segment jump tables get corrupted. (We have some re-entrant launch codes that caused problems)





--
For information on using the PalmSource Developer Forums, or to unsubscribe, please see http://www.palmos.com/dev/support/forums/

Reply via email to