Back to index

lightning-sunbird  0.9+nobinonly
xptcstubs_x86_solaris.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org Code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1999
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 /* Implement shared vtbl methods. */
00040 
00041 #include "xptcprivate.h"
00042 #include "xptc_platforms_unixish_x86.h"
00043 
00044 #if !defined(__SUNPRO_CC)               /* Sun Workshop Compiler. */
00045 static
00046 #endif
00047 nsresult
00048 PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
00049 {
00050 #define PARAM_BUFFER_COUNT     16
00051 
00052     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
00053     nsXPTCMiniVariant* dispatchParams = NULL;
00054     nsIInterfaceInfo* iface_info = NULL;
00055     const nsXPTMethodInfo* info;
00056     PRUint8 paramCount;
00057     PRUint8 i;
00058     nsresult result = NS_ERROR_FAILURE;
00059 
00060     NS_ASSERTION(self,"no self");
00061 
00062     self->GetInterfaceInfo(&iface_info);
00063     NS_ASSERTION(iface_info,"no interface info");
00064 
00065     iface_info->GetMethodInfo(PRUint16(methodIndex), &info);
00066     NS_ASSERTION(info,"no interface info");
00067 
00068     paramCount = info->GetParamCount();
00069 
00070     // setup variant array pointer
00071     if(paramCount > PARAM_BUFFER_COUNT)
00072         dispatchParams = new nsXPTCMiniVariant[paramCount];
00073     else
00074         dispatchParams = paramBuffer;
00075     NS_ASSERTION(dispatchParams,"no place for params");
00076 
00077     PRUint32* ap = args;
00078     for(i = 0; i < paramCount; i++, ap++)
00079     {
00080         const nsXPTParamInfo& param = info->GetParam(i);
00081         const nsXPTType& type = param.GetType();
00082         nsXPTCMiniVariant* dp = &dispatchParams[i];
00083 
00084         if(param.IsOut() || !type.IsArithmetic())
00085         {
00086             dp->val.p = (void*) *ap;
00087             continue;
00088         }
00089         // else
00090            dp->val.p = (void*) *ap;
00091         switch(type)
00092         {
00093         case nsXPTType::T_I64    : dp->val.i64 = *((PRInt64*) ap); ap++; break;
00094         case nsXPTType::T_U64    : dp->val.u64 = *((PRUint64*)ap); ap++; break;
00095         case nsXPTType::T_DOUBLE : dp->val.d   = *((double*)  ap); ap++; break;
00096         }
00097     }
00098 
00099     result = self->CallMethod((PRUint16)methodIndex, info, dispatchParams);
00100 
00101     NS_RELEASE(iface_info);
00102 
00103     if(dispatchParams != paramBuffer)
00104         delete [] dispatchParams;
00105 
00106     return result;
00107 }
00108 
00109 #ifdef __GNUC__         /* Gnu Compiler. */
00110 #define STUB_ENTRY(n) \
00111 nsresult nsXPTCStubBase::Stub##n() \
00112 { \
00113   register nsresult (*method) (nsXPTCStubBase *, uint32, PRUint32 *) = PrepareAndDispatch; \
00114   int temp0, temp1; \
00115   register nsresult result; \
00116   __asm__ __volatile__( \
00117     "leal   0x0c(%%ebp), %%ecx\n\t"    /* args */ \
00118     "pushl  %%ecx\n\t" \
00119     "pushl  $"#n"\n\t"                 /* method index */ \
00120     "movl   0x08(%%ebp), %%ecx\n\t"    /* this */ \
00121     "pushl  %%ecx\n\t" \
00122     "call   *%%edx\n\t"                /* PrepareAndDispatch */ \
00123     "addl   $12, %%esp" \
00124     : "=a" (result),    /* %0 */ \
00125       "=&c" (temp0),    /* %1 */ \
00126       "=d" (temp1)      /* %2 */ \
00127     : "2" (method)      /* %2 */ \
00128     : "memory" ); \
00129     return result; \
00130 }
00131 
00132 #elif defined(__SUNPRO_CC)           /* Sun Workshop Compiler. */
00133 
00134 #define STUB_ENTRY(n)
00135 
00136 #else
00137 #error "can't find a compiler to use"
00138 #endif /* __GNUC__ */
00139 
00140 #define SENTINEL_ENTRY(n) \
00141 nsresult nsXPTCStubBase::Sentinel##n() \
00142 { \
00143     NS_ASSERTION(0,"nsXPTCStubBase::Sentinel called"); \
00144     return NS_ERROR_NOT_IMPLEMENTED; \
00145 }
00146 
00147 #include "xptcstubsdef.inc"