1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/win32/xptcstubs_x86_64.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,197 @@ 1.4 +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 + 1.9 +/* Implement shared vtbl methods. */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 +#include "xptiprivate.h" 1.13 + 1.14 +/* 1.15 + * This is for Windows XP 64-Bit Edition / Server 2003 for AMD64 or later. 1.16 + */ 1.17 + 1.18 +extern "C" nsresult 1.19 +PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args, 1.20 + uint64_t *gprData, double *fprData) 1.21 +{ 1.22 +#define PARAM_BUFFER_COUNT 16 1.23 +// 1.24 +// "this" pointer is first parameter, so parameter count is 3. 1.25 +// 1.26 +#define PARAM_GPR_COUNT 3 1.27 +#define PARAM_FPR_COUNT 3 1.28 + 1.29 + nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; 1.30 + nsXPTCMiniVariant* dispatchParams = nullptr; 1.31 + const nsXPTMethodInfo* info = nullptr; 1.32 + uint8_t paramCount; 1.33 + uint8_t i; 1.34 + nsresult result = NS_ERROR_FAILURE; 1.35 + 1.36 + NS_ASSERTION(self,"no self"); 1.37 + 1.38 + self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); 1.39 + NS_ASSERTION(info,"no method info"); 1.40 + 1.41 + paramCount = info->GetParamCount(); 1.42 + 1.43 + // 1.44 + // setup variant array pointer 1.45 + // 1.46 + 1.47 + if(paramCount > PARAM_BUFFER_COUNT) 1.48 + dispatchParams = new nsXPTCMiniVariant[paramCount]; 1.49 + else 1.50 + dispatchParams = paramBuffer; 1.51 + 1.52 + NS_ASSERTION(dispatchParams,"no place for params"); 1.53 + 1.54 + uint64_t* ap = args; 1.55 + uint32_t iCount = 0; 1.56 + 1.57 + for(i = 0; i < paramCount; i++) 1.58 + { 1.59 + const nsXPTParamInfo& param = info->GetParam(i); 1.60 + const nsXPTType& type = param.GetType(); 1.61 + nsXPTCMiniVariant* dp = &dispatchParams[i]; 1.62 + 1.63 + if(param.IsOut() || !type.IsArithmetic()) 1.64 + { 1.65 + if (iCount < PARAM_GPR_COUNT) 1.66 + dp->val.p = (void*)gprData[iCount++]; 1.67 + else 1.68 + dp->val.p = (void*)*ap++; 1.69 + 1.70 + continue; 1.71 + } 1.72 + // else 1.73 + switch(type) 1.74 + { 1.75 + case nsXPTType::T_I8: 1.76 + if (iCount < PARAM_GPR_COUNT) 1.77 + dp->val.i8 = (int8_t)gprData[iCount++]; 1.78 + else 1.79 + dp->val.i8 = *((int8_t*)ap++); 1.80 + break; 1.81 + 1.82 + case nsXPTType::T_I16: 1.83 + if (iCount < PARAM_GPR_COUNT) 1.84 + dp->val.i16 = (int16_t)gprData[iCount++]; 1.85 + else 1.86 + dp->val.i16 = *((int16_t*)ap++); 1.87 + break; 1.88 + 1.89 + case nsXPTType::T_I32: 1.90 + if (iCount < PARAM_GPR_COUNT) 1.91 + dp->val.i32 = (int32_t)gprData[iCount++]; 1.92 + else 1.93 + dp->val.i32 = *((int32_t*)ap++); 1.94 + break; 1.95 + 1.96 + case nsXPTType::T_I64: 1.97 + if (iCount < PARAM_GPR_COUNT) 1.98 + dp->val.i64 = (int64_t)gprData[iCount++]; 1.99 + else 1.100 + dp->val.i64 = *((int64_t*)ap++); 1.101 + break; 1.102 + 1.103 + case nsXPTType::T_U8: 1.104 + if (iCount < PARAM_GPR_COUNT) 1.105 + dp->val.u8 = (uint8_t)gprData[iCount++]; 1.106 + else 1.107 + dp->val.u8 = *((uint8_t*)ap++); 1.108 + break; 1.109 + 1.110 + case nsXPTType::T_U16: 1.111 + if (iCount < PARAM_GPR_COUNT) 1.112 + dp->val.u16 = (uint16_t)gprData[iCount++]; 1.113 + else 1.114 + dp->val.u16 = *((uint16_t*)ap++); 1.115 + break; 1.116 + 1.117 + case nsXPTType::T_U32: 1.118 + if (iCount < PARAM_GPR_COUNT) 1.119 + dp->val.u32 = (uint32_t)gprData[iCount++]; 1.120 + else 1.121 + dp->val.u32 = *((uint32_t*)ap++); 1.122 + break; 1.123 + 1.124 + case nsXPTType::T_U64: 1.125 + if (iCount < PARAM_GPR_COUNT) 1.126 + dp->val.u64 = (uint64_t)gprData[iCount++]; 1.127 + else 1.128 + dp->val.u64 = *((uint64_t*)ap++); 1.129 + break; 1.130 + 1.131 + case nsXPTType::T_FLOAT: 1.132 + if (iCount < PARAM_FPR_COUNT) 1.133 + // The value in xmm register is already prepared to 1.134 + // be retrieved as a float. Therefore, we pass the 1.135 + // value verbatim, as a double without conversion. 1.136 + dp->val.d = (double)fprData[iCount++]; 1.137 + else 1.138 + dp->val.f = *((float*)ap++); 1.139 + break; 1.140 + 1.141 + case nsXPTType::T_DOUBLE: 1.142 + if (iCount < PARAM_FPR_COUNT) 1.143 + dp->val.d = (double)fprData[iCount++]; 1.144 + else 1.145 + dp->val.d = *((double*)ap++); 1.146 + break; 1.147 + 1.148 + case nsXPTType::T_BOOL: 1.149 + if (iCount < PARAM_GPR_COUNT) 1.150 + // We need cast to uint8_t to remove garbage on upper 56-bit 1.151 + // at first. 1.152 + dp->val.b = (bool)(uint8_t)gprData[iCount++]; 1.153 + else 1.154 + dp->val.b = *((bool*)ap++); 1.155 + break; 1.156 + 1.157 + case nsXPTType::T_CHAR: 1.158 + if (iCount < PARAM_GPR_COUNT) 1.159 + dp->val.c = (char)gprData[iCount++]; 1.160 + else 1.161 + dp->val.c = *((char*)ap++); 1.162 + break; 1.163 + 1.164 + case nsXPTType::T_WCHAR: 1.165 + if (iCount < PARAM_GPR_COUNT) 1.166 + dp->val.wc = (wchar_t)gprData[iCount++]; 1.167 + else 1.168 + dp->val.wc = *((wchar_t*)ap++); 1.169 + break; 1.170 + 1.171 + default: 1.172 + NS_ERROR("bad type"); 1.173 + break; 1.174 + } 1.175 + } 1.176 + 1.177 + result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); 1.178 + 1.179 + if(dispatchParams != paramBuffer) 1.180 + delete [] dispatchParams; 1.181 + 1.182 + return result; 1.183 +} 1.184 + 1.185 +#define STUB_ENTRY(n) /* defined in the assembly file */ 1.186 + 1.187 +#define SENTINEL_ENTRY(n) \ 1.188 +nsresult nsXPTCStubBase::Sentinel##n() \ 1.189 +{ \ 1.190 + NS_ERROR("nsXPTCStubBase::Sentinel called"); \ 1.191 + return NS_ERROR_NOT_IMPLEMENTED; \ 1.192 +} 1.193 + 1.194 +#include "xptcstubsdef.inc" 1.195 + 1.196 +void 1.197 +xptc_dummy() 1.198 +{ 1.199 +} 1.200 +