Back to index

lightning-sunbird  0.9+nobinonly
xptcinvoke.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 /* Platform specific code to invoke XPCOM methods on native objects */
00039 
00040 #include "xptcprivate.h"
00041 
00042 #ifndef WIN32
00043 #error "This code is for Win32 only"
00044 #endif
00045 
00046 static void __fastcall
00047 invoke_copy_to_stack(PRUint32* d, PRUint32 paramCount, nsXPTCVariant* s)
00048 {
00049     for(; paramCount > 0; paramCount--, d++, s++)
00050     {
00051         if(s->IsPtrData())
00052         {
00053             *((void**)d) = s->ptr;
00054             continue;
00055         }
00056         switch(s->type)
00057         {
00058         case nsXPTType::T_I8     : *((PRInt8*)  d) = s->val.i8;          break;
00059         case nsXPTType::T_I16    : *((PRInt16*) d) = s->val.i16;         break;
00060         case nsXPTType::T_I32    : *((PRInt32*) d) = s->val.i32;         break;
00061         case nsXPTType::T_I64    : *((PRInt64*) d) = s->val.i64; d++;    break;
00062         case nsXPTType::T_U8     : *((PRUint8*) d) = s->val.u8;          break;
00063         case nsXPTType::T_U16    : *((PRUint16*)d) = s->val.u16;         break;
00064         case nsXPTType::T_U32    : *((PRUint32*)d) = s->val.u32;         break;
00065         case nsXPTType::T_U64    : *((PRUint64*)d) = s->val.u64; d++;    break;
00066         case nsXPTType::T_FLOAT  : *((float*)   d) = s->val.f;           break;
00067         case nsXPTType::T_DOUBLE : *((double*)  d) = s->val.d;   d++;    break;
00068         case nsXPTType::T_BOOL   : *((PRBool*)  d) = s->val.b;           break;
00069         case nsXPTType::T_CHAR   : *((char*)    d) = s->val.c;           break;
00070         case nsXPTType::T_WCHAR  : *((wchar_t*) d) = s->val.wc;          break;
00071         default:
00072             // all the others are plain pointer types
00073             *((void**)d) = s->val.p;
00074             break;
00075         }
00076     }
00077 }
00078 
00079 #pragma warning(disable : 4035) // OK to have no return value
00080 __declspec(naked) XPTC_PUBLIC_API(nsresult)
00081 XPTC_InvokeByIndex(nsISupports* that, PRUint32 methodIndex,
00082                    PRUint32 paramCount, nsXPTCVariant* params)
00083 {
00084     __asm {
00085         push    ebp
00086         mov     ebp,esp
00087         mov     edx,paramCount      // Save paramCount for later
00088         test    edx,edx             // maybe we don't have any params to copy
00089         jz      noparams
00090         mov     eax,edx             
00091         shl     eax,3               // *= 8 (max possible param size)
00092         sub     esp,eax             // make space for params
00093         mov     ecx,esp
00094         push    params
00095         call    invoke_copy_to_stack // fastcall, ecx = d, edx = paramCount, params is on the stack
00096 noparams:
00097         mov     ecx,that            // instance in ecx
00098         push    ecx                 // push this
00099         mov     edx,[ecx]           // vtable in edx
00100         mov     eax,methodIndex
00101         call    [edx][eax*4]        // stdcall, i.e. callee cleans up stack.
00102         mov     esp,ebp
00103         pop     ebp
00104         ret
00105     }
00106 }
00107 #pragma warning(default : 4035) // restore default