Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* Platform specific code to invoke XPCOM methods on native objects */ |
michael@0 | 7 | |
michael@0 | 8 | #include "xptcprivate.h" |
michael@0 | 9 | |
michael@0 | 10 | #ifndef WIN32 |
michael@0 | 11 | #error "This code is for Win32 only" |
michael@0 | 12 | #endif |
michael@0 | 13 | |
michael@0 | 14 | static void __fastcall |
michael@0 | 15 | invoke_copy_to_stack(uint32_t* d, uint32_t paramCount, nsXPTCVariant* s) |
michael@0 | 16 | { |
michael@0 | 17 | for(; paramCount > 0; paramCount--, d++, s++) |
michael@0 | 18 | { |
michael@0 | 19 | if(s->IsPtrData()) |
michael@0 | 20 | { |
michael@0 | 21 | *((void**)d) = s->ptr; |
michael@0 | 22 | continue; |
michael@0 | 23 | } |
michael@0 | 24 | switch(s->type) |
michael@0 | 25 | { |
michael@0 | 26 | case nsXPTType::T_I8 : *((int8_t*) d) = s->val.i8; break; |
michael@0 | 27 | case nsXPTType::T_I16 : *((int16_t*) d) = s->val.i16; break; |
michael@0 | 28 | case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; |
michael@0 | 29 | case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; |
michael@0 | 30 | case nsXPTType::T_U8 : *((uint8_t*) d) = s->val.u8; break; |
michael@0 | 31 | case nsXPTType::T_U16 : *((uint16_t*)d) = s->val.u16; break; |
michael@0 | 32 | case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; |
michael@0 | 33 | case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; |
michael@0 | 34 | case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; |
michael@0 | 35 | case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; |
michael@0 | 36 | case nsXPTType::T_BOOL : *((bool*) d) = s->val.b; break; |
michael@0 | 37 | case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break; |
michael@0 | 38 | case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; |
michael@0 | 39 | default: |
michael@0 | 40 | // all the others are plain pointer types |
michael@0 | 41 | *((void**)d) = s->val.p; |
michael@0 | 42 | break; |
michael@0 | 43 | } |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | |
michael@0 | 47 | #pragma warning(disable : 4035) // OK to have no return value |
michael@0 | 48 | // Tell the PDB file this function has a standard frame pointer, and not to use |
michael@0 | 49 | // a custom FPO program. |
michael@0 | 50 | #pragma optimize( "y", off ) |
michael@0 | 51 | extern "C" NS_EXPORT nsresult NS_FROZENCALL |
michael@0 | 52 | NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
michael@0 | 53 | uint32_t paramCount, nsXPTCVariant* params) |
michael@0 | 54 | { |
michael@0 | 55 | __asm { |
michael@0 | 56 | mov edx,paramCount // Save paramCount for later |
michael@0 | 57 | test edx,edx // maybe we don't have any params to copy |
michael@0 | 58 | jz noparams |
michael@0 | 59 | mov eax,edx |
michael@0 | 60 | shl eax,3 // *= 8 (max possible param size) |
michael@0 | 61 | sub esp,eax // make space for params |
michael@0 | 62 | mov ecx,esp |
michael@0 | 63 | push params |
michael@0 | 64 | call invoke_copy_to_stack // fastcall, ecx = d, edx = paramCount, params is on the stack |
michael@0 | 65 | noparams: |
michael@0 | 66 | mov ecx,that // instance in ecx |
michael@0 | 67 | push ecx // push this |
michael@0 | 68 | mov edx,[ecx] // vtable in edx |
michael@0 | 69 | mov eax,methodIndex |
michael@0 | 70 | call [edx][eax*4] // stdcall, i.e. callee cleans up stack. |
michael@0 | 71 | mov esp,ebp |
michael@0 | 72 | } |
michael@0 | 73 | } |
michael@0 | 74 | #pragma warning(default : 4035) // restore default |