1 
2 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3  *
4  * This Source Code Form is subject to the terms of the Mozilla Public
5  * License, v. 2.0. If a copy of the MPL was not distributed with this
6  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 
8 
9 #include "xptcprivate.h"
10 
11 #include <stddef.h>
12 #include <stdlib.h>
13 #include <stdint.h>
14 
15 // "This code is for IA64 only"
16 
17 /* Implement shared vtbl methods. */
18 
19 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint64_t * intargs,uint64_t * floatargs,uint64_t * restargs)20 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex,
21   uint64_t* intargs, uint64_t* floatargs, uint64_t* restargs)
22 {
23 
24 #define PARAM_BUFFER_COUNT     16
25 
26   nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
27   nsXPTCMiniVariant* dispatchParams = nullptr;
28   const nsXPTMethodInfo* info;
29   uint64_t* iargs = intargs;
30   uint64_t* fargs = floatargs;
31   uint8_t paramCount;
32   uint8_t i;
33 
34   NS_ASSERTION(self,"no self");
35 
36   self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
37   NS_ASSERTION(info,"no method info");
38   if (! info)
39       return NS_ERROR_UNEXPECTED;
40 
41   paramCount = info->GetParamCount();
42 
43   // setup variant array pointer
44   if(paramCount > PARAM_BUFFER_COUNT)
45     dispatchParams = new nsXPTCMiniVariant[paramCount];
46   else
47     dispatchParams = paramBuffer;
48   NS_ASSERTION(dispatchParams,"no place for params");
49 
50   const uint8_t indexOfJSContext = info->IndexOfJSContext();
51 
52   for(i = 0; i < paramCount; ++i)
53   {
54     int isfloat = 0;
55     const nsXPTParamInfo& param = info->GetParam(i);
56     const nsXPTType& type = param.GetType();
57     nsXPTCMiniVariant* dp = &dispatchParams[i];
58 
59     MOZ_CRASH("NYI: support implicit JSContext*, bug 1475699");
60 
61     if(param.IsOut() || !type.IsArithmetic())
62     {
63 #ifdef __LP64__
64         /* 64 bit pointer mode */
65         dp->val.p = (void*) *iargs;
66 #else
67         /* 32 bit pointer mode */
68         uint32_t* adr = (uint32_t*) iargs;
69         dp->val.p = (void*) (*(adr+1));
70 #endif
71     }
72     else
73     switch(type)
74     {
75     case nsXPTType::T_I8     : dp->val.i8  = *(iargs); break;
76     case nsXPTType::T_I16    : dp->val.i16 = *(iargs); break;
77     case nsXPTType::T_I32    : dp->val.i32 = *(iargs); break;
78     case nsXPTType::T_I64    : dp->val.i64 = *(iargs); break;
79     case nsXPTType::T_U8     : dp->val.u8  = *(iargs); break;
80     case nsXPTType::T_U16    : dp->val.u16 = *(iargs); break;
81     case nsXPTType::T_U32    : dp->val.u32 = *(iargs); break;
82     case nsXPTType::T_U64    : dp->val.u64 = *(iargs); break;
83     case nsXPTType::T_FLOAT  :
84       isfloat = 1;
85       if (i < 7)
86         dp->val.f = (float) *((double*) fargs); /* register */
87       else
88         dp->val.u32 = *(fargs); /* memory */
89       break;
90     case nsXPTType::T_DOUBLE :
91       isfloat = 1;
92       dp->val.u64 = *(fargs);
93       break;
94     case nsXPTType::T_BOOL   : dp->val.b   = *(iargs); break;
95     case nsXPTType::T_CHAR   : dp->val.c   = *(iargs); break;
96     case nsXPTType::T_WCHAR  : dp->val.wc  = *(iargs); break;
97     default:
98       NS_ERROR("bad type");
99       break;
100     }
101     if (i < 7)
102     {
103       /* we are parsing register arguments */
104       if (i == 6)
105       {
106         // run out of register arguments, move on to memory arguments
107         iargs = restargs;
108         fargs = restargs;
109       }
110       else
111       {
112         ++iargs; // advance one integer register slot
113         if (isfloat) ++fargs; // advance float register slot if isfloat
114       }
115     }
116     else
117     {
118       /* we are parsing memory arguments */
119       ++iargs;
120       ++fargs;
121     }
122   }
123 
124   nsresult result = self->mOuter->CallMethod((uint16_t) methodIndex, info,
125                                              dispatchParams);
126 
127   if(dispatchParams != paramBuffer)
128     delete [] dispatchParams;
129 
130   return result;
131 }
132 
133 extern "C" nsresult SharedStub(uint64_t,uint64_t,uint64_t,uint64_t,
134  uint64_t,uint64_t,uint64_t,uint64_t,uint64_t,uint64_t *);
135 
136 /* Variable a0-a7 were put there so we can have access to the 8 input
137    registers on Stubxyz entry */
138 
139 #define STUB_ENTRY(n) \
140 nsresult nsXPTCStubBase::Stub##n(uint64_t a1, \
141 uint64_t a2,uint64_t a3,uint64_t a4,uint64_t a5,uint64_t a6,uint64_t a7, \
142 uint64_t a8) \
143 { uint64_t a0 = (uint64_t) this; \
144  return SharedStub(a0,a1,a2,a3,a4,a5,a6,a7,(uint64_t) n, &a8); \
145 }
146 
147 #define SENTINEL_ENTRY(n) \
148 nsresult nsXPTCStubBase::Sentinel##n() \
149 { \
150     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
151     return NS_ERROR_NOT_IMPLEMENTED; \
152 }
153 
154 #include "xptcstubsdef.inc"
155