xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc_linux.cpp

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.

michael@0 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
michael@0 2 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 3 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 5
michael@0 6 // Implement shared vtbl methods.
michael@0 7
michael@0 8 #include "xptcprivate.h"
michael@0 9 #include "xptiprivate.h"
michael@0 10
michael@0 11 // The Linux/PPC ABI (aka PPC/SYSV ABI) passes the first 8 integral
michael@0 12 // parameters and the first 8 floating point parameters in registers
michael@0 13 // (r3-r10 and f1-f8), no stack space is allocated for these by the
michael@0 14 // caller. The rest of the parameters are passed in the callers stack
michael@0 15 // area. The stack pointer has to retain 16-byte alignment, longlongs
michael@0 16 // and doubles are aligned on 8-byte boundaries.
michael@0 17 #ifndef __NO_FPRS__
michael@0 18 #define PARAM_BUFFER_COUNT 16
michael@0 19 #define GPR_COUNT 8
michael@0 20 #define FPR_COUNT 8
michael@0 21 #else
michael@0 22 #define PARAM_BUFFER_COUNT 8
michael@0 23 #define GPR_COUNT 8
michael@0 24 #endif
michael@0 25 // PrepareAndDispatch() is called by SharedStub() and calls the actual method.
michael@0 26 //
michael@0 27 // - 'args[]' contains the arguments passed on stack
michael@0 28 // - 'gprData[]' contains the arguments passed in integer registers
michael@0 29 // - 'fprData[]' contains the arguments passed in floating point registers
michael@0 30 //
michael@0 31 // The parameters are mapped into an array of type 'nsXPTCMiniVariant'
michael@0 32 // and then the method gets called.
michael@0 33
michael@0 34 extern "C" nsresult ATTRIBUTE_USED
michael@0 35 PrepareAndDispatch(nsXPTCStubBase* self,
michael@0 36 uint32_t methodIndex,
michael@0 37 uint32_t* args,
michael@0 38 uint32_t *gprData,
michael@0 39 double *fprData)
michael@0 40 {
michael@0 41 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
michael@0 42 nsXPTCMiniVariant* dispatchParams = nullptr;
michael@0 43 const nsXPTMethodInfo* info = nullptr;
michael@0 44 uint32_t paramCount;
michael@0 45 uint32_t i;
michael@0 46 nsresult result = NS_ERROR_FAILURE;
michael@0 47
michael@0 48 NS_ASSERTION(self,"no self");
michael@0 49
michael@0 50 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
michael@0 51 NS_ASSERTION(info,"no method info");
michael@0 52 if (! info)
michael@0 53 return NS_ERROR_UNEXPECTED;
michael@0 54
michael@0 55 paramCount = info->GetParamCount();
michael@0 56
michael@0 57 // setup variant array pointer
michael@0 58 if(paramCount > PARAM_BUFFER_COUNT)
michael@0 59 dispatchParams = new nsXPTCMiniVariant[paramCount];
michael@0 60 else
michael@0 61 dispatchParams = paramBuffer;
michael@0 62
michael@0 63 NS_ASSERTION(dispatchParams,"no place for params");
michael@0 64 if (! dispatchParams)
michael@0 65 return NS_ERROR_OUT_OF_MEMORY;
michael@0 66
michael@0 67 uint32_t* ap = args;
michael@0 68 uint32_t gpr = 1; // skip one GPR register
michael@0 69 #ifndef __NO_FPRS__
michael@0 70 uint32_t fpr = 0;
michael@0 71 #endif
michael@0 72 uint32_t tempu32;
michael@0 73 uint64_t tempu64;
michael@0 74
michael@0 75 for(i = 0; i < paramCount; i++) {
michael@0 76 const nsXPTParamInfo& param = info->GetParam(i);
michael@0 77 const nsXPTType& type = param.GetType();
michael@0 78 nsXPTCMiniVariant* dp = &dispatchParams[i];
michael@0 79
michael@0 80 if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
michael@0 81 #ifndef __NO_FPRS__
michael@0 82 if (fpr < FPR_COUNT)
michael@0 83 dp->val.d = fprData[fpr++];
michael@0 84 #else
michael@0 85 if (gpr & 1)
michael@0 86 gpr++;
michael@0 87 if (gpr + 1 < GPR_COUNT) {
michael@0 88 dp->val.d = *(double*) &gprData[gpr];
michael@0 89 gpr += 2;
michael@0 90 }
michael@0 91 #endif
michael@0 92 else {
michael@0 93 if ((uint32_t) ap & 4) ap++; // doubles are 8-byte aligned on stack
michael@0 94 dp->val.d = *(double*) ap;
michael@0 95 ap += 2;
michael@0 96 }
michael@0 97 continue;
michael@0 98 }
michael@0 99 else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
michael@0 100 #ifndef __NO_FPRS__
michael@0 101 if (fpr < FPR_COUNT)
michael@0 102 dp->val.f = (float) fprData[fpr++]; // in registers floats are passed as doubles
michael@0 103 #else
michael@0 104 if (gpr < GPR_COUNT)
michael@0 105 dp->val.f = *(float*) &gprData[gpr++];
michael@0 106 #endif
michael@0 107 else
michael@0 108 dp->val.f = *(float*) ap++;
michael@0 109 continue;
michael@0 110 }
michael@0 111 else if (!param.IsOut() && (type == nsXPTType::T_I64
michael@0 112 || type == nsXPTType::T_U64)) {
michael@0 113 if (gpr & 1) gpr++; // longlongs are aligned in odd/even register pairs, eg. r5/r6
michael@0 114 if ((gpr + 1) < GPR_COUNT) {
michael@0 115 tempu64 = *(uint64_t*) &gprData[gpr];
michael@0 116 gpr += 2;
michael@0 117 }
michael@0 118 else {
michael@0 119 if ((uint32_t) ap & 4) ap++; // longlongs are 8-byte aligned on stack
michael@0 120 tempu64 = *(uint64_t*) ap;
michael@0 121 ap += 2;
michael@0 122 }
michael@0 123 }
michael@0 124 else {
michael@0 125 if (gpr < GPR_COUNT)
michael@0 126 tempu32 = gprData[gpr++];
michael@0 127 else
michael@0 128 tempu32 = *ap++;
michael@0 129 }
michael@0 130
michael@0 131 if(param.IsOut() || !type.IsArithmetic()) {
michael@0 132 dp->val.p = (void*) tempu32;
michael@0 133 continue;
michael@0 134 }
michael@0 135
michael@0 136 switch(type) {
michael@0 137 case nsXPTType::T_I8: dp->val.i8 = (int8_t) tempu32; break;
michael@0 138 case nsXPTType::T_I16: dp->val.i16 = (int16_t) tempu32; break;
michael@0 139 case nsXPTType::T_I32: dp->val.i32 = (int32_t) tempu32; break;
michael@0 140 case nsXPTType::T_I64: dp->val.i64 = (int64_t) tempu64; break;
michael@0 141 case nsXPTType::T_U8: dp->val.u8 = (uint8_t) tempu32; break;
michael@0 142 case nsXPTType::T_U16: dp->val.u16 = (uint16_t) tempu32; break;
michael@0 143 case nsXPTType::T_U32: dp->val.u32 = (uint32_t) tempu32; break;
michael@0 144 case nsXPTType::T_U64: dp->val.u64 = (uint64_t) tempu64; break;
michael@0 145 case nsXPTType::T_BOOL: dp->val.b = (bool) tempu32; break;
michael@0 146 case nsXPTType::T_CHAR: dp->val.c = (char) tempu32; break;
michael@0 147 case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) tempu32; break;
michael@0 148
michael@0 149 default:
michael@0 150 NS_ERROR("bad type");
michael@0 151 break;
michael@0 152 }
michael@0 153 }
michael@0 154
michael@0 155 result = self->mOuter->CallMethod((uint16_t)methodIndex,
michael@0 156 info,
michael@0 157 dispatchParams);
michael@0 158
michael@0 159 if (dispatchParams != paramBuffer)
michael@0 160 delete [] dispatchParams;
michael@0 161
michael@0 162 return result;
michael@0 163 }
michael@0 164
michael@0 165 // Load r11 with the constant 'n' and branch to SharedStub().
michael@0 166 //
michael@0 167 // XXX Yes, it's ugly that we're relying on gcc's name-mangling here;
michael@0 168 // however, it's quick, dirty, and'll break when the ABI changes on
michael@0 169 // us, which is what we want ;-).
michael@0 170
michael@0 171 // gcc-3 version
michael@0 172 //
michael@0 173 // As G++3 ABI contains the length of the functionname in the mangled
michael@0 174 // name, it is difficult to get a generic assembler mechanism like
michael@0 175 // in the G++ 2.95 case.
michael@0 176 // Create names would be like:
michael@0 177 // _ZN14nsXPTCStubBase5Stub1Ev
michael@0 178 // _ZN14nsXPTCStubBase6Stub12Ev
michael@0 179 // _ZN14nsXPTCStubBase7Stub123Ev
michael@0 180 // _ZN14nsXPTCStubBase8Stub1234Ev
michael@0 181 // etc.
michael@0 182 // Use assembler directives to get the names right...
michael@0 183
michael@0 184 # define STUB_ENTRY(n) \
michael@0 185 __asm__ ( \
michael@0 186 ".align 2 \n\t" \
michael@0 187 ".if "#n" < 10 \n\t" \
michael@0 188 ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \
michael@0 189 ".type _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n" \
michael@0 190 "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t" \
michael@0 191 \
michael@0 192 ".elseif "#n" < 100 \n\t" \
michael@0 193 ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \
michael@0 194 ".type _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n" \
michael@0 195 "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t" \
michael@0 196 \
michael@0 197 ".elseif "#n" < 1000 \n\t" \
michael@0 198 ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \
michael@0 199 ".type _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n" \
michael@0 200 "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t" \
michael@0 201 \
michael@0 202 ".else \n\t" \
michael@0 203 ".err \"stub number "#n" >= 1000 not yet supported\"\n" \
michael@0 204 ".endif \n\t" \
michael@0 205 \
michael@0 206 "li 11,"#n" \n\t" \
michael@0 207 "b SharedStub@local \n" \
michael@0 208 );
michael@0 209
michael@0 210 #define SENTINEL_ENTRY(n) \
michael@0 211 nsresult nsXPTCStubBase::Sentinel##n() \
michael@0 212 { \
michael@0 213 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
michael@0 214 return NS_ERROR_NOT_IMPLEMENTED; \
michael@0 215 }
michael@0 216
michael@0 217 #include "xptcstubsdef.inc"

mercurial