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

mercurial