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 /* Implement shared vtbl methods. */
9 
10 #include "xptcprivate.h"
11 #include "xptiprivate.h"
12 
13 #if _HPUX
14 #error "This code is for HP-PA RISC 32 bit mode only"
15 #endif
16 
17 extern "C" nsresult ATTRIBUTE_USED
PrepareAndDispatch(nsXPTCStubBase * self,uint32_t methodIndex,uint32_t * args,uint32_t * floatargs)18 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex,
19   uint32_t* args, uint32_t* floatargs)
20 {
21 
22   typedef struct {
23     uint32_t hi;
24     uint32_t lo;
25   } DU;
26 
27 #define PARAM_BUFFER_COUNT     16
28 
29   nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
30   nsXPTCMiniVariant* dispatchParams = nullptr;
31   const nsXPTMethodInfo* info;
32   int32_t regwords = 1; /* self pointer is not in the variant records */
33   nsresult result = NS_ERROR_FAILURE;
34   uint8_t paramCount;
35   uint8_t i;
36 
37   NS_ASSERTION(self,"no self");
38 
39   self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
40   NS_ASSERTION(info,"no method info");
41   if (!info)
42     return NS_ERROR_UNEXPECTED;
43 
44   paramCount = info->GetParamCount();
45 
46   // setup variant array pointer
47   if(paramCount > PARAM_BUFFER_COUNT)
48     dispatchParams = new nsXPTCMiniVariant[paramCount];
49   else
50     dispatchParams = paramBuffer;
51   NS_ASSERTION(dispatchParams,"no place for params");
52   if (!dispatchParams)
53     return NS_ERROR_OUT_OF_MEMORY;
54 
55   for(i = 0; i < paramCount; ++i, --args)
56   {
57     const nsXPTParamInfo& param = info->GetParam(i);
58     const nsXPTType& type = param.GetType();
59     nsXPTCMiniVariant* dp = &dispatchParams[i];
60 
61     if(param.IsOut() || !type.IsArithmetic())
62     {
63       dp->val.p = (void*) *args;
64       ++regwords;
65       continue;
66     }
67     switch(type)
68     {
69     case nsXPTType::T_I8     : dp->val.i8  = *((int32_t*) args); break;
70     case nsXPTType::T_I16    : dp->val.i16 = *((int32_t*) args); break;
71     case nsXPTType::T_I32    : dp->val.i32 = *((int32_t*) args); break;
72     case nsXPTType::T_DOUBLE :
73                                if (regwords & 1)
74                                {
75                                  ++regwords; /* align on double word */
76                                  --args;
77                                }
78                                if (regwords == 0 || regwords == 2)
79                                {
80                                  dp->val.d=*((double*) (floatargs + regwords));
81                                  --args;
82                                }
83                                else
84                                {
85                                  dp->val.d = *((double*) --args);
86                                }
87                                regwords += 2;
88                                continue;
89     case nsXPTType::T_U64    :
90     case nsXPTType::T_I64    :
91                                if (regwords & 1)
92                                {
93                                  ++regwords; /* align on double word */
94                                  --args;
95                                }
96                                ((DU *)dp)->lo = *((uint32_t*) args);
97                                ((DU *)dp)->hi = *((uint32_t*) --args);
98                                regwords += 2;
99                                continue;
100     case nsXPTType::T_FLOAT  :
101                                if (regwords >= 4)
102                                  dp->val.f = *((float*) args);
103                                else
104                                  dp->val.f = *((float*) floatargs+4+regwords);
105                                break;
106     case nsXPTType::T_U8     : dp->val.u8  = *((uint32_t*) args); break;
107     case nsXPTType::T_U16    : dp->val.u16 = *((uint32_t*) args); break;
108     case nsXPTType::T_U32    : dp->val.u32 = *((uint32_t*) args); break;
109     case nsXPTType::T_BOOL   : dp->val.b   = *((uint32_t*) args); break;
110     case nsXPTType::T_CHAR   : dp->val.c   = *((uint32_t*) args); break;
111     case nsXPTType::T_WCHAR  : dp->val.wc  = *((int32_t*)  args); break;
112     default:
113       NS_ERROR("bad type");
114       break;
115     }
116     ++regwords;
117   }
118 
119   result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams);
120 
121   if(dispatchParams != paramBuffer)
122     delete [] dispatchParams;
123 
124   return result;
125 }
126 
127 extern "C" nsresult SharedStub(int);
128 
129 #define STUB_ENTRY(n)       \
130 nsresult nsXPTCStubBase::Stub##n()  \
131 {                           \
132     return SharedStub(n);   \
133 }
134 
135 #define SENTINEL_ENTRY(n) \
136 nsresult nsXPTCStubBase::Sentinel##n() \
137 { \
138     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
139     return NS_ERROR_NOT_IMPLEMENTED; \
140 }
141 
142 #include "xptcstubsdef.inc"
143 
144