|
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 extern "C" { |
|
12 nsresult ATTRIBUTE_USED |
|
13 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) |
|
14 { |
|
15 #define PARAM_BUFFER_COUNT 16 |
|
16 |
|
17 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
18 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
19 const nsXPTMethodInfo* info; |
|
20 uint8_t paramCount; |
|
21 uint8_t i; |
|
22 nsresult result = NS_ERROR_FAILURE; |
|
23 |
|
24 NS_ASSERTION(self,"no self"); |
|
25 |
|
26 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
27 NS_ASSERTION(info,"no method info"); |
|
28 |
|
29 paramCount = info->GetParamCount(); |
|
30 |
|
31 // setup variant array pointer |
|
32 if(paramCount > PARAM_BUFFER_COUNT) |
|
33 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
34 else |
|
35 dispatchParams = paramBuffer; |
|
36 NS_ASSERTION(dispatchParams,"no place for params"); |
|
37 |
|
38 uint32_t* ap = args; |
|
39 for(i = 0; i < paramCount; i++, ap++) |
|
40 { |
|
41 const nsXPTParamInfo& param = info->GetParam(i); |
|
42 const nsXPTType& type = param.GetType(); |
|
43 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
44 |
|
45 if(param.IsOut() || !type.IsArithmetic()) |
|
46 { |
|
47 dp->val.p = (void*) *ap; |
|
48 continue; |
|
49 } |
|
50 |
|
51 switch(type) |
|
52 { |
|
53 // the 8 and 16 bit types will have been promoted to 32 bits before |
|
54 // being pushed onto the stack. Since the 68k is big endian, we |
|
55 // need to skip over the leading high order bytes. |
|
56 case nsXPTType::T_I8 : dp->val.i8 = *(((int8_t*) ap) + 3); break; |
|
57 case nsXPTType::T_I16 : dp->val.i16 = *(((int16_t*) ap) + 1); break; |
|
58 case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break; |
|
59 case nsXPTType::T_I64 : dp->val.i64 = *((int64_t*) ap); ap++; break; |
|
60 case nsXPTType::T_U8 : dp->val.u8 = *(((uint8_t*) ap) + 3); break; |
|
61 case nsXPTType::T_U16 : dp->val.u16 = *(((uint16_t*)ap) + 1); break; |
|
62 case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break; |
|
63 case nsXPTType::T_U64 : dp->val.u64 = *((uint64_t*)ap); ap++; break; |
|
64 case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break; |
|
65 case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break; |
|
66 case nsXPTType::T_BOOL : dp->val.b = *((uint32_t* ap); break; |
|
67 case nsXPTType::T_CHAR : dp->val.c = *(((char*) ap) + 3); break; |
|
68 case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break; |
|
69 default: |
|
70 NS_ERROR("bad type"); |
|
71 break; |
|
72 } |
|
73 } |
|
74 |
|
75 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams); |
|
76 |
|
77 if(dispatchParams != paramBuffer) |
|
78 delete [] dispatchParams; |
|
79 |
|
80 return result; |
|
81 } |
|
82 } |
|
83 |
|
84 #define STUB_ENTRY(n) \ |
|
85 nsresult nsXPTCStubBase::Stub##n() \ |
|
86 { \ |
|
87 void *frame = __builtin_frame_address(0); \ |
|
88 return PrepareAndDispatch(this, n, (uint32_t*)frame + 3); \ |
|
89 } |
|
90 |
|
91 #define SENTINEL_ENTRY(n) \ |
|
92 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
93 { \ |
|
94 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
95 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
96 } |
|
97 |
|
98 #include "xptcstubsdef.inc" |