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