xpcom/reflect/xptcall/src/md/unix/xptcstubs_arm.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 #if !defined(__arm__) && !(defined(LINUX) || defined(ANDROID))
michael@0 12 #error "This code is for Linux ARM only. Please check if it works for you, too.\nDepends strongly on gcc behaviour."
michael@0 13 #endif
michael@0 14
michael@0 15 /* Specify explicitly a symbol for this function, don't try to guess the c++ mangled symbol. */
michael@0 16 static nsresult PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args) asm("_PrepareAndDispatch")
michael@0 17 ATTRIBUTE_USED;
michael@0 18
michael@0 19 #ifdef __ARM_EABI__
michael@0 20 #define DOUBLEWORD_ALIGN(p) ((uint32_t *)((((uint32_t)(p)) + 7) & 0xfffffff8))
michael@0 21 #else
michael@0 22 #define DOUBLEWORD_ALIGN(p) (p)
michael@0 23 #endif
michael@0 24
michael@0 25 // Apple's iOS toolchain is lame and does not support .cfi directives.
michael@0 26 #ifdef __APPLE__
michael@0 27 #define CFI(str)
michael@0 28 #else
michael@0 29 #define CFI(str) str
michael@0 30 #endif
michael@0 31
michael@0 32 static nsresult
michael@0 33 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex, uint32_t* args)
michael@0 34 {
michael@0 35 #define PARAM_BUFFER_COUNT 16
michael@0 36
michael@0 37 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
michael@0 38 nsXPTCMiniVariant* dispatchParams = nullptr;
michael@0 39 const nsXPTMethodInfo* info;
michael@0 40 uint8_t paramCount;
michael@0 41 uint8_t i;
michael@0 42 nsresult result = NS_ERROR_FAILURE;
michael@0 43
michael@0 44 NS_ASSERTION(self,"no self");
michael@0 45
michael@0 46 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
michael@0 47 paramCount = info->GetParamCount();
michael@0 48
michael@0 49 // setup variant array pointer
michael@0 50 if(paramCount > PARAM_BUFFER_COUNT)
michael@0 51 dispatchParams = new nsXPTCMiniVariant[paramCount];
michael@0 52 else
michael@0 53 dispatchParams = paramBuffer;
michael@0 54 NS_ASSERTION(dispatchParams,"no place for params");
michael@0 55
michael@0 56 uint32_t* ap = args;
michael@0 57 for(i = 0; i < paramCount; i++, ap++)
michael@0 58 {
michael@0 59 const nsXPTParamInfo& param = info->GetParam(i);
michael@0 60 const nsXPTType& type = param.GetType();
michael@0 61 nsXPTCMiniVariant* dp = &dispatchParams[i];
michael@0 62
michael@0 63 if(param.IsOut() || !type.IsArithmetic())
michael@0 64 {
michael@0 65 dp->val.p = (void*) *ap;
michael@0 66 continue;
michael@0 67 }
michael@0 68 // else
michael@0 69 switch(type)
michael@0 70 {
michael@0 71 case nsXPTType::T_I8 : dp->val.i8 = *((int8_t*) ap); break;
michael@0 72 case nsXPTType::T_I16 : dp->val.i16 = *((int16_t*) ap); break;
michael@0 73 case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break;
michael@0 74 case nsXPTType::T_I64 : ap = DOUBLEWORD_ALIGN(ap);
michael@0 75 dp->val.i64 = *((int64_t*) ap); ap++; break;
michael@0 76 case nsXPTType::T_U8 : dp->val.u8 = *((uint8_t*) ap); break;
michael@0 77 case nsXPTType::T_U16 : dp->val.u16 = *((uint16_t*)ap); break;
michael@0 78 case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break;
michael@0 79 case nsXPTType::T_U64 : ap = DOUBLEWORD_ALIGN(ap);
michael@0 80 dp->val.u64 = *((uint64_t*)ap); ap++; break;
michael@0 81 case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
michael@0 82 case nsXPTType::T_DOUBLE : ap = DOUBLEWORD_ALIGN(ap);
michael@0 83 dp->val.d = *((double*) ap); ap++; break;
michael@0 84 case nsXPTType::T_BOOL : dp->val.b = *((bool*) ap); break;
michael@0 85 case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
michael@0 86 case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
michael@0 87 default:
michael@0 88 NS_ERROR("bad type");
michael@0 89 break;
michael@0 90 }
michael@0 91 }
michael@0 92
michael@0 93 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams);
michael@0 94
michael@0 95 if(dispatchParams != paramBuffer)
michael@0 96 delete [] dispatchParams;
michael@0 97
michael@0 98 return result;
michael@0 99 }
michael@0 100
michael@0 101 /*
michael@0 102 * This is our shared stub.
michael@0 103 *
michael@0 104 * r0 = Self.
michael@0 105 *
michael@0 106 * The Rules:
michael@0 107 * We pass an (undefined) number of arguments into this function.
michael@0 108 * The first 3 C++ arguments are in r1 - r3, the rest are built
michael@0 109 * by the calling function on the stack.
michael@0 110 *
michael@0 111 * We are allowed to corrupt r0 - r3, ip, and lr.
michael@0 112 *
michael@0 113 * Other Info:
michael@0 114 * We pass the stub number in using `ip'.
michael@0 115 *
michael@0 116 * Implementation:
michael@0 117 * - We save r1 to r3 inclusive onto the stack, which will be
michael@0 118 * immediately below the caller saved arguments.
michael@0 119 * - setup r2 (PrepareAndDispatch's args pointer) to point at
michael@0 120 * the base of all these arguments
michael@0 121 * - Save LR (for the return address)
michael@0 122 * - Set r1 (PrepareAndDispatch's methodindex argument) from ip
michael@0 123 * - r0 is passed through (self)
michael@0 124 * - Call PrepareAndDispatch
michael@0 125 * - When the call returns, we return by loading the PC off the
michael@0 126 * stack, and undoing the stack (one instruction)!
michael@0 127 *
michael@0 128 */
michael@0 129 __asm__ ("\n"
michael@0 130 ".text\n"
michael@0 131 ".align 2\n"
michael@0 132 "SharedStub:\n"
michael@0 133 ".fnstart\n"
michael@0 134 CFI(".cfi_startproc\n")
michael@0 135 "stmfd sp!, {r1, r2, r3}\n"
michael@0 136 ".save {r1, r2, r3}\n"
michael@0 137 CFI(".cfi_def_cfa_offset 12\n")
michael@0 138 CFI(".cfi_offset r3, -4\n")
michael@0 139 CFI(".cfi_offset r2, -8\n")
michael@0 140 CFI(".cfi_offset r1, -12\n")
michael@0 141 "mov r2, sp\n"
michael@0 142 "str lr, [sp, #-4]!\n"
michael@0 143 ".save {lr}\n"
michael@0 144 CFI(".cfi_def_cfa_offset 16\n")
michael@0 145 CFI(".cfi_offset lr, -16\n")
michael@0 146 "mov r1, ip\n"
michael@0 147 "bl _PrepareAndDispatch\n"
michael@0 148 "ldr pc, [sp], #16\n"
michael@0 149 CFI(".cfi_endproc\n")
michael@0 150 ".fnend");
michael@0 151
michael@0 152 /*
michael@0 153 * Create sets of stubs to call the SharedStub.
michael@0 154 * We don't touch the stack here, nor any registers, other than IP.
michael@0 155 * IP is defined to be corruptable by a called function, so we are
michael@0 156 * safe to use it.
michael@0 157 *
michael@0 158 * This will work with or without optimisation.
michael@0 159 */
michael@0 160
michael@0 161 /*
michael@0 162 * Note : As G++3 ABI contains the length of the functionname in the
michael@0 163 * mangled name, it is difficult to get a generic assembler mechanism like
michael@0 164 * in the G++ 2.95 case.
michael@0 165 * Create names would be like :
michael@0 166 * _ZN14nsXPTCStubBase5Stub9Ev
michael@0 167 * _ZN14nsXPTCStubBase6Stub13Ev
michael@0 168 * _ZN14nsXPTCStubBase7Stub144Ev
michael@0 169 * Use the assembler directives to get the names right...
michael@0 170 */
michael@0 171
michael@0 172 #define STUB_ENTRY(n) \
michael@0 173 __asm__( \
michael@0 174 ".section \".text\"\n" \
michael@0 175 " .align 2\n" \
michael@0 176 " .iflt ("#n" - 10)\n" \
michael@0 177 " .globl _ZN14nsXPTCStubBase5Stub"#n"Ev\n" \
michael@0 178 " .type _ZN14nsXPTCStubBase5Stub"#n"Ev,#function\n" \
michael@0 179 "_ZN14nsXPTCStubBase5Stub"#n"Ev:\n" \
michael@0 180 " .else\n" \
michael@0 181 " .iflt ("#n" - 100)\n" \
michael@0 182 " .globl _ZN14nsXPTCStubBase6Stub"#n"Ev\n" \
michael@0 183 " .type _ZN14nsXPTCStubBase6Stub"#n"Ev,#function\n" \
michael@0 184 "_ZN14nsXPTCStubBase6Stub"#n"Ev:\n" \
michael@0 185 " .else\n" \
michael@0 186 " .iflt ("#n" - 1000)\n" \
michael@0 187 " .globl _ZN14nsXPTCStubBase7Stub"#n"Ev\n" \
michael@0 188 " .type _ZN14nsXPTCStubBase7Stub"#n"Ev,#function\n" \
michael@0 189 "_ZN14nsXPTCStubBase7Stub"#n"Ev:\n" \
michael@0 190 " .else\n" \
michael@0 191 " .err \"stub number "#n"> 1000 not yet supported\"\n" \
michael@0 192 " .endif\n" \
michael@0 193 " .endif\n" \
michael@0 194 " .endif\n" \
michael@0 195 " mov ip, #"#n"\n" \
michael@0 196 " b SharedStub\n\t");
michael@0 197
michael@0 198 #if 0
michael@0 199 /*
michael@0 200 * This part is left in as comment : this is how the method definition
michael@0 201 * should look like.
michael@0 202 */
michael@0 203
michael@0 204 #define STUB_ENTRY(n) \
michael@0 205 nsresult nsXPTCStubBase::Stub##n () \
michael@0 206 { \
michael@0 207 __asm__ ( \
michael@0 208 " mov ip, #"#n"\n" \
michael@0 209 " b SharedStub\n\t"); \
michael@0 210 return 0; /* avoid warnings */ \
michael@0 211 }
michael@0 212 #endif
michael@0 213
michael@0 214
michael@0 215 #define SENTINEL_ENTRY(n) \
michael@0 216 nsresult nsXPTCStubBase::Sentinel##n() \
michael@0 217 { \
michael@0 218 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
michael@0 219 return NS_ERROR_NOT_IMPLEMENTED; \
michael@0 220 }
michael@0 221
michael@0 222 #include "xptcstubsdef.inc"

mercurial