1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/xpcom/reflect/xptcall/src/md/win32/xptcinvoke.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,74 @@ 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 +/* Platform specific code to invoke XPCOM methods on native objects */ 1.10 + 1.11 +#include "xptcprivate.h" 1.12 + 1.13 +#ifndef WIN32 1.14 +#error "This code is for Win32 only" 1.15 +#endif 1.16 + 1.17 +static void __fastcall 1.18 +invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s) 1.19 +{ 1.20 + for(; paramCount > 0; paramCount--, d++, s++) 1.21 + { 1.22 + if(s->IsPtrData()) 1.23 + { 1.24 + *((void**)d) = s->ptr; 1.25 + continue; 1.26 + } 1.27 + switch(s->type) 1.28 + { 1.29 + case nsXPTType::T_I8 : *((int8_t*) d) = s->val.i8; break; 1.30 + case nsXPTType::T_I16 : *((int16_t*) d) = s->val.i16; break; 1.31 + case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; 1.32 + case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; 1.33 + case nsXPTType::T_U8 : *((uint8_t*) d) = s->val.u8; break; 1.34 + case nsXPTType::T_U16 : *((uint16_t*)d) = s->val.u16; break; 1.35 + case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; 1.36 + case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; 1.37 + case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; 1.38 + case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; 1.39 + case nsXPTType::T_BOOL : *((bool*) d) = s->val.b; break; 1.40 + case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break; 1.41 + case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; 1.42 + default: 1.43 + // all the others are plain pointer types 1.44 + *((void**)d) = s->val.p; 1.45 + break; 1.46 + } 1.47 + } 1.48 +} 1.49 + 1.50 +#pragma warning(disable : 4035) // OK to have no return value 1.51 +// Tell the PDB file this function has a standard frame pointer, and not to use 1.52 +// a custom FPO program. 1.53 +#pragma optimize( "y", off ) 1.54 +extern "C" NS_EXPORT nsresult NS_FROZENCALL 1.55 +NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, 1.56 + uint32_t paramCount, nsXPTCVariant* params) 1.57 +{ 1.58 + __asm { 1.59 + mov edx,paramCount // Save paramCount for later 1.60 + test edx,edx // maybe we don't have any params to copy 1.61 + jz noparams 1.62 + mov eax,edx 1.63 + shl eax,3 // *= 8 (max possible param size) 1.64 + sub esp,eax // make space for params 1.65 + mov ecx,esp 1.66 + push params 1.67 + call invoke_copy_to_stack // fastcall, ecx = d, edx = paramCount, params is on the stack 1.68 +noparams: 1.69 + mov ecx,that // instance in ecx 1.70 + push ecx // push this 1.71 + mov edx,[ecx] // vtable in edx 1.72 + mov eax,methodIndex 1.73 + call [edx][eax*4] // stdcall, i.e. callee cleans up stack. 1.74 + mov esp,ebp 1.75 + } 1.76 +} 1.77 +#pragma warning(default : 4035) // restore default