Sounds like you are misunderstanding how the thunk fits in.

Let's see if I can get this right...

The goal is to adjust the 'this' pointer in certain multiple inheritance cases. Using thunks is only one solution. The thunks are a preferred modern solution because they are transparent to the call sites; i.e. the caller does not know or care whether it is calling via a thunk or not.

The older CFront based solution was to require the caller to apply an offset to the 'this' pointer for each call.

In either case the compiler is generating code or data related to the called object. In the thunk case the compiler generates a thunk (or not) when it generates the called object. In the CFront style case the compiler generates an offset value related to the called object that the caller is required to apply during all call invocations.

I'm not sure what problem you are having, but in thunk cases there is nothing special that your caller needs to do.

mozilla's Windows version of such invocations is in: http://lxr.mozilla.org/seamonkey/source/xpcom/reflect/xptcall/src/md/win32/xptcinvoke.cpp

Our Windows compiles use only thunk based 'this' adjustment. So, this is relatively simple stuff.

You can look at a more generic solution for x86 Unix variants that has compile time #ifdefs to support the two styles at:
http://lxr.mozilla.org/seamonkey/source/xpcom/reflect/xptcall/src/md/unix/xptcinvoke_unixish_x86.cpp


Note the "#ifdef CFRONT_STYLE_THIS_ADJUST" block of code.

Also note that the code in your message with a 'jmp' is not what either of these implementations actually do.

Googling for words like: "this pointer adjustment thunk" finds various documents that you might find interesting. One of those documents includes excerpts from Stanley B. Lippman's book _Inside The C++ Object Model_. I found the pertinent chapters in this book very useful when I was first writing this stuff.

Another thing to play with is compiling appropriate snippets of C++ and disassembling the compiler output to see what it actually does.

John.

sriram neelakandan wrote:
I understand that there is something called thunk adjustment for this pointer required in mulitple inheritance case .. but i donot exactly follow the implementation for example ..

a regular vtable call can be

XPTC_InvokeMethodByIndex( nsISupport *that, int methodIndex)
{
...
// assuming Vtable starts at *that ..
func = *(int*)that  + (methodIndex *4);
invoke_ copy_to_stack();
// then call func()
asm("jmp %1" :: func);
}

Now this fails for thnuked calls ..
Basically what is the 'C' equivlaent to access the vtable for a thunk call ?



_______________________________________________ Mozilla-xpcom mailing list [email protected] http://mail.mozilla.org/listinfo/mozilla-xpcom

Reply via email to