|
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
|
2 * |
|
3 * This Source Code Form is subject to the terms of the Mozilla Public |
|
4 * License, v. 2.0. If a copy of the MPL was not distributed with this |
|
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
|
6 |
|
7 // Implement shared vtbl methods. |
|
8 |
|
9 // Keep this in sync with the darwin version. |
|
10 |
|
11 #include "xptcprivate.h" |
|
12 #include "xptiprivate.h" |
|
13 |
|
14 // The Linux/x86-64 ABI passes the first 6 integer parameters and the |
|
15 // first 8 floating point parameters in registers (rdi, rsi, rdx, rcx, |
|
16 // r8, r9 and xmm0-xmm7), no stack space is allocated for these by the |
|
17 // caller. The rest of the parameters are passed in the callers stack |
|
18 // area. |
|
19 |
|
20 const uint32_t PARAM_BUFFER_COUNT = 16; |
|
21 const uint32_t GPR_COUNT = 6; |
|
22 const uint32_t FPR_COUNT = 8; |
|
23 |
|
24 // PrepareAndDispatch() is called by SharedStub() and calls the actual method. |
|
25 // |
|
26 // - 'args[]' contains the arguments passed on stack |
|
27 // - 'gpregs[]' contains the arguments passed in integer registers |
|
28 // - 'fpregs[]' contains the arguments passed in floating point registers |
|
29 // |
|
30 // The parameters are mapped into an array of type 'nsXPTCMiniVariant' |
|
31 // and then the method gets called. |
|
32 |
|
33 extern "C" nsresult ATTRIBUTE_USED |
|
34 PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex, |
|
35 uint64_t * args, uint64_t * gpregs, double *fpregs) |
|
36 { |
|
37 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT]; |
|
38 nsXPTCMiniVariant* dispatchParams = nullptr; |
|
39 const nsXPTMethodInfo* info; |
|
40 uint32_t paramCount; |
|
41 uint32_t i; |
|
42 nsresult result = NS_ERROR_FAILURE; |
|
43 |
|
44 NS_ASSERTION(self,"no self"); |
|
45 |
|
46 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info); |
|
47 NS_ASSERTION(info,"no method info"); |
|
48 if (!info) |
|
49 return NS_ERROR_UNEXPECTED; |
|
50 |
|
51 paramCount = info->GetParamCount(); |
|
52 |
|
53 // setup variant array pointer |
|
54 if (paramCount > PARAM_BUFFER_COUNT) |
|
55 dispatchParams = new nsXPTCMiniVariant[paramCount]; |
|
56 else |
|
57 dispatchParams = paramBuffer; |
|
58 |
|
59 NS_ASSERTION(dispatchParams,"no place for params"); |
|
60 if (!dispatchParams) |
|
61 return NS_ERROR_OUT_OF_MEMORY; |
|
62 |
|
63 uint64_t* ap = args; |
|
64 uint32_t nr_gpr = 1; // skip one GPR register for 'that' |
|
65 uint32_t nr_fpr = 0; |
|
66 uint64_t value; |
|
67 |
|
68 for (i = 0; i < paramCount; i++) { |
|
69 const nsXPTParamInfo& param = info->GetParam(i); |
|
70 const nsXPTType& type = param.GetType(); |
|
71 nsXPTCMiniVariant* dp = &dispatchParams[i]; |
|
72 |
|
73 if (!param.IsOut() && type == nsXPTType::T_DOUBLE) { |
|
74 if (nr_fpr < FPR_COUNT) |
|
75 dp->val.d = fpregs[nr_fpr++]; |
|
76 else |
|
77 dp->val.d = *(double*) ap++; |
|
78 continue; |
|
79 } |
|
80 else if (!param.IsOut() && type == nsXPTType::T_FLOAT) { |
|
81 if (nr_fpr < FPR_COUNT) |
|
82 // The value in %xmm register is already prepared to |
|
83 // be retrieved as a float. Therefore, we pass the |
|
84 // value verbatim, as a double without conversion. |
|
85 dp->val.d = fpregs[nr_fpr++]; |
|
86 else |
|
87 dp->val.f = *(float*) ap++; |
|
88 continue; |
|
89 } |
|
90 else { |
|
91 if (nr_gpr < GPR_COUNT) |
|
92 value = gpregs[nr_gpr++]; |
|
93 else |
|
94 value = *ap++; |
|
95 } |
|
96 |
|
97 if (param.IsOut() || !type.IsArithmetic()) { |
|
98 dp->val.p = (void*) value; |
|
99 continue; |
|
100 } |
|
101 |
|
102 switch (type) { |
|
103 case nsXPTType::T_I8: dp->val.i8 = (int8_t) value; break; |
|
104 case nsXPTType::T_I16: dp->val.i16 = (int16_t) value; break; |
|
105 case nsXPTType::T_I32: dp->val.i32 = (int32_t) value; break; |
|
106 case nsXPTType::T_I64: dp->val.i64 = (int64_t) value; break; |
|
107 case nsXPTType::T_U8: dp->val.u8 = (uint8_t) value; break; |
|
108 case nsXPTType::T_U16: dp->val.u16 = (uint16_t) value; break; |
|
109 case nsXPTType::T_U32: dp->val.u32 = (uint32_t) value; break; |
|
110 case nsXPTType::T_U64: dp->val.u64 = (uint64_t) value; break; |
|
111 // Cast to uint8_t first, to remove garbage on upper 56 bits. |
|
112 case nsXPTType::T_BOOL: dp->val.b = (bool)(uint8_t) value; break; |
|
113 case nsXPTType::T_CHAR: dp->val.c = (char) value; break; |
|
114 case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) value; break; |
|
115 |
|
116 default: |
|
117 NS_ERROR("bad type"); |
|
118 break; |
|
119 } |
|
120 } |
|
121 |
|
122 result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams); |
|
123 |
|
124 if (dispatchParams != paramBuffer) |
|
125 delete [] dispatchParams; |
|
126 |
|
127 return result; |
|
128 } |
|
129 |
|
130 #define STUB_ENTRY(n) |
|
131 |
|
132 #define SENTINEL_ENTRY(n) \ |
|
133 nsresult nsXPTCStubBase::Sentinel##n() \ |
|
134 { \ |
|
135 NS_ERROR("nsXPTCStubBase::Sentinel called"); \ |
|
136 return NS_ERROR_NOT_IMPLEMENTED; \ |
|
137 } |
|
138 |
|
139 #include "xptcstubsdef.inc" |