|
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 /* Implement shared vtbl methods. */ |
|
7 |
|
8 #include "xptcprivate.h" |
|
9 #include "xptiprivate.h" |
|
10 |
|
11 /* |
|
12 * This is for Windows XP 64-Bit Edition / Server 2003 for AMD64 or later. |
|
13 */ |
|
14 |
|
15 extern "C" nsresult |
|
16 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint64_t* args, |
|
17 uint64_t *gprData, double *fprData) |
|
18 { |
|
19 #define PARAM_BUFFER_COUNT 16 |
|
20 // |
|
21 // "this" pointer is first parameter, so parameter count is 3. |
|
22 // |
|
23 #define PARAM_GPR_COUNT 3 |
|
24 #define PARAM_FPR_COUNT 3 |
|
25 |
|
26 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
27 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
28 const nsXPTMethodInfo* info = nullptr; |
|
29 uint8_t paramCount; |
|
30 uint8_t i; |
|
31 nsresult result = NS_ERROR_FAILURE; |
|
32 |
|
33 NS_ASSERTION(self,"no self"); |
|
34 |
|
35 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
36 NS_ASSERTION(info,"no method info"); |
|
37 |
|
38 paramCount = info->GetParamCount(); |
|
39 |
|
40 // |
|
41 // setup variant array pointer |
|
42 // |
|
43 |
|
44 if(paramCount > PARAM_BUFFER_COUNT) |
|
45 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
46 else |
|
47 dispatchParams = paramBuffer; |
|
48 |
|
49 NS_ASSERTION(dispatchParams,"no place for params"); |
|
50 |
|
51 uint64_t* ap = args; |
|
52 uint32_t iCount = 0; |
|
53 |
|
54 for(i = 0; i < paramCount; i++) |
|
55 { |
|
56 const nsXPTParamInfo& param = info->GetParam(i); |
|
57 const nsXPTType& type = param.GetType(); |
|
58 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
59 |
|
60 if(param.IsOut() || !type.IsArithmetic()) |
|
61 { |
|
62 if (iCount < PARAM_GPR_COUNT) |
|
63 dp->val.p = (void*)gprData[iCount++]; |
|
64 else |
|
65 dp->val.p = (void*)*ap++; |
|
66 |
|
67 continue; |
|
68 } |
|
69 // else |
|
70 switch(type) |
|
71 { |
|
72 case nsXPTType::T_I8: |
|
73 if (iCount < PARAM_GPR_COUNT) |
|
74 dp->val.i8 = (int8_t)gprData[iCount++]; |
|
75 else |
|
76 dp->val.i8 = *((int8_t*)ap++); |
|
77 break; |
|
78 |
|
79 case nsXPTType::T_I16: |
|
80 if (iCount < PARAM_GPR_COUNT) |
|
81 dp->val.i16 = (int16_t)gprData[iCount++]; |
|
82 else |
|
83 dp->val.i16 = *((int16_t*)ap++); |
|
84 break; |
|
85 |
|
86 case nsXPTType::T_I32: |
|
87 if (iCount < PARAM_GPR_COUNT) |
|
88 dp->val.i32 = (int32_t)gprData[iCount++]; |
|
89 else |
|
90 dp->val.i32 = *((int32_t*)ap++); |
|
91 break; |
|
92 |
|
93 case nsXPTType::T_I64: |
|
94 if (iCount < PARAM_GPR_COUNT) |
|
95 dp->val.i64 = (int64_t)gprData[iCount++]; |
|
96 else |
|
97 dp->val.i64 = *((int64_t*)ap++); |
|
98 break; |
|
99 |
|
100 case nsXPTType::T_U8: |
|
101 if (iCount < PARAM_GPR_COUNT) |
|
102 dp->val.u8 = (uint8_t)gprData[iCount++]; |
|
103 else |
|
104 dp->val.u8 = *((uint8_t*)ap++); |
|
105 break; |
|
106 |
|
107 case nsXPTType::T_U16: |
|
108 if (iCount < PARAM_GPR_COUNT) |
|
109 dp->val.u16 = (uint16_t)gprData[iCount++]; |
|
110 else |
|
111 dp->val.u16 = *((uint16_t*)ap++); |
|
112 break; |
|
113 |
|
114 case nsXPTType::T_U32: |
|
115 if (iCount < PARAM_GPR_COUNT) |
|
116 dp->val.u32 = (uint32_t)gprData[iCount++]; |
|
117 else |
|
118 dp->val.u32 = *((uint32_t*)ap++); |
|
119 break; |
|
120 |
|
121 case nsXPTType::T_U64: |
|
122 if (iCount < PARAM_GPR_COUNT) |
|
123 dp->val.u64 = (uint64_t)gprData[iCount++]; |
|
124 else |
|
125 dp->val.u64 = *((uint64_t*)ap++); |
|
126 break; |
|
127 |
|
128 case nsXPTType::T_FLOAT: |
|
129 if (iCount < PARAM_FPR_COUNT) |
|
130 // The value in xmm register is already prepared to |
|
131 // be retrieved as a float. Therefore, we pass the |
|
132 // value verbatim, as a double without conversion. |
|
133 dp->val.d = (double)fprData[iCount++]; |
|
134 else |
|
135 dp->val.f = *((float*)ap++); |
|
136 break; |
|
137 |
|
138 case nsXPTType::T_DOUBLE: |
|
139 if (iCount < PARAM_FPR_COUNT) |
|
140 dp->val.d = (double)fprData[iCount++]; |
|
141 else |
|
142 dp->val.d = *((double*)ap++); |
|
143 break; |
|
144 |
|
145 case nsXPTType::T_BOOL: |
|
146 if (iCount < PARAM_GPR_COUNT) |
|
147 // We need cast to uint8_t to remove garbage on upper 56-bit |
|
148 // at first. |
|
149 dp->val.b = (bool)(uint8_t)gprData[iCount++]; |
|
150 else |
|
151 dp->val.b = *((bool*)ap++); |
|
152 break; |
|
153 |
|
154 case nsXPTType::T_CHAR: |
|
155 if (iCount < PARAM_GPR_COUNT) |
|
156 dp->val.c = (char)gprData[iCount++]; |
|
157 else |
|
158 dp->val.c = *((char*)ap++); |
|
159 break; |
|
160 |
|
161 case nsXPTType::T_WCHAR: |
|
162 if (iCount < PARAM_GPR_COUNT) |
|
163 dp->val.wc = (wchar_t)gprData[iCount++]; |
|
164 else |
|
165 dp->val.wc = *((wchar_t*)ap++); |
|
166 break; |
|
167 |
|
168 default: |
|
169 NS_ERROR("bad type"); |
|
170 break; |
|
171 } |
|
172 } |
|
173 |
|
174 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); |
|
175 |
|
176 if(dispatchParams != paramBuffer) |
|
177 delete [] dispatchParams; |
|
178 |
|
179 return result; |
|
180 } |
|
181 |
|
182 #define STUB_ENTRY(n) /* defined in the assembly file */ |
|
183 |
|
184 #define SENTINEL_ENTRY(n) \ |
|
185 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
186 { \ |
|
187 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
188 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
189 } |
|
190 |
|
191 #include "xptcstubsdef.inc" |
|
192 |
|
193 void |
|
194 xptc_dummy() |
|
195 { |
|
196 } |
|
197 |