[squeak-dev] Re: shared object between main.exe and Squeak.dll

Igor Stasenko siguctua at gmail.com
Sat May 8 17:23:17 UTC 2010


On 8 May 2010 19:54, Ang BeePeng <beepeng86 at yahoo.com> wrote:
>
> Hi,
>
> I have a primitive like this.
>
> sqInt primitiveReturnString(void){
>        sqInt* tempPtr = 0x111EB8D4;
>        sqInt temp;
>
>        temp = popStack();
>        if(isIntegerObject(temp))
>                dllMemory[dllResult] = temp;
>        else{
>                *tempPtr = temp;
>                dllMemory[dllResult] = temp; //I'm not sure what to do with this yet
>                addGCRoot(tempPtr);
>        }
>        pop(1);
>        interpReturn = 1;
> }
>

what does that constant (0x111EB8D4) means?

Anyways, when you calling addCGRoot with it, it means that VM will
look for an oop at address
0x111EB8D4
is this what you intend?

Also, you should not call addCGRoot() multiple times with same address.
Do it only once, at your / VM initialization stage.
Extra roots table is finite, and if you using this prim in a loop, you
will just fill out the extra roots table
with same values (0x111EB8D4, in your case).

Here , what i'd probably do on your place (its still unclear what you want.. ):

sqInt primitiveReturnString(void){

    static sqInt myRoot;
    static int initialized = 0;

// also, you better add GC root only once, because a size of extra
roots table is finite

  if ( initialized == 0)  {
    initialized = 1;
    myRoot = intepreterProxy->nilObject().   // just put nil object initially
    addGCRoot(&myRoot);
  }

// now, all you need to do in your prim is just set the myRoot value:
   myRoot = popStack();

// and then,  pass an _address_ to the root, _not_ oop itself:

  dllMemory[dllResult] = &myRoot.
}

so, your code (somewhere outside , i guess) can safely access the oop
value using:

oop = * ((sqInt*)dllMemory[dllResult])


> I start up SqueakVM, and execute primitiveReturnString() with a float on top
> of the stack. After this primitive, SqueakVM is allow to run on its own. And
> then I got an access violation, with call stack look like this.
>
>        Squeak4.dll!markAndTrace(int oop=0)  Line 11883 + 0x3 bytes     C
>        Squeak4.dll!markPhase()  Line 12221 + 0x9 bytes C
>        Squeak4.dll!incrementalGC()  Line 5578  C
>        Squeak4.dll!instantiateContextsizeInBytes(int classPointer=275821428, int
> sizeInBytes=92)  Line 6218      C
>        Squeak4.dll!allocateOrRecycleContext(int needsLarge=0)  Line 2553 + 0x10
> bytes   C
>        Squeak4.dll!interpret(int * sharedMemory=0x0015fabc, int rcvr=0, char *
> selector=0x0015fc54, int arg=1, int result=2)  Line 8485 + 0xc bytes    C
>        Squeak4.dll!SqueakInterp2(int * sharedMemory=0x0015fabc, int rcvr=0, char
> * selector=0x0015fc54, int arg=1, int result=2)  Line 10 + 0x19 bytes   C
>        MainProgram.exe!main()  Line 49 + 0x19 bytes    C
>        MainProgram.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes      C
>        MainProgram.exe!mainCRTStartup()  Line 403      C
>        kernel32.dll!76b91194()
>        [Frames below may be incorrect and/or missing, no symbols loaded for
> kernel32.dll]
>        ntdll.dll!7767b435()
>        ntdll.dll!7767b408()
>
> or sometimes, it is like this:
>
>        Squeak4.dll!incCompMakeFwd()  Line 5368 + 0xc bytes     C
>        Squeak4.dll!incCompBody()  Line 5260 + 0x5 bytes        C
>        Squeak4.dll!incrementalGC()  Line 5588  C
>        Squeak4.dll!sufficientSpaceAfterGC(unsigned int minFree=202504)  Line
> 23654   C
>        Squeak4.dll!primitiveNew()  Line 17781 + 0x9 bytes      C
>>       Squeak4.dll!dispatchFunctionPointer(void * aFunctionPointer=0x100403c5)
> Line 4097       C
>        Squeak4.dll!interpret(int * sharedMemory=0x001dfd48, int rcvr=0, char *
> selector=0x001dfee0, int arg=1, int result=2)  Line 8458 + 0xb bytes    C
>        Squeak4.dll!SqueakInterp2(int * sharedMemory=0x001dfd48, int rcvr=0, char
> * selector=0x001dfee0, int arg=1, int result=2)  Line 10 + 0x19 bytes   C
>        MainProgram.exe!main()  Line 49 + 0x19 bytes    C
>        MainProgram.exe!__tmainCRTStartup()  Line 586 + 0x19 bytes      C
>        MainProgram.exe!mainCRTStartup()  Line 403      C
>        kernel32.dll!76b91194()
>        [Frames below may be incorrect and/or missing, no symbols loaded for
> kernel32.dll]
>        ntdll.dll!7767b435()
>        ntdll.dll!7767b408()
>
>
> sometimes, it is at remap() as I mention earlier.
>
> At extraRoots[1] I can see 0x111EB8D4, which is still tempPtr. But at
> 0x111EB8D4, I see some non address value which is for example 0x00000002.
>
> Thanks.
>
> Ang Beepeng
> --
> View this message in context: http://forum.world.st/shared-object-between-main-exe-and-Squeak-dll-tp2023185p2136285.html
> Sent from the Squeak - Dev mailing list archive at Nabble.com.
>
>



-- 
Best regards,
Igor Stasenko AKA sig.



More information about the Squeak-dev mailing list