xpcom/reflect/xptcall/src/md/win32/xptcstubs.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 #ifndef WIN32
michael@0 12 #error "This code is for Win32 only"
michael@0 13 #endif
michael@0 14
michael@0 15 extern "C" {
michael@0 16
michael@0 17 #ifndef __GNUC__
michael@0 18 static
michael@0 19 #endif
michael@0 20 nsresult __stdcall
michael@0 21 PrepareAndDispatch(nsXPTCStubBase* self, uint32_t methodIndex,
michael@0 22 uint32_t* args, uint32_t* stackBytesToPop)
michael@0 23 {
michael@0 24 #define PARAM_BUFFER_COUNT 16
michael@0 25
michael@0 26 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
michael@0 27 nsXPTCMiniVariant* dispatchParams = nullptr;
michael@0 28 const nsXPTMethodInfo* info = nullptr;
michael@0 29 uint8_t paramCount;
michael@0 30 uint8_t i;
michael@0 31 nsresult result = NS_ERROR_FAILURE;
michael@0 32
michael@0 33 // If anything fails before stackBytesToPop can be set then
michael@0 34 // the failure is completely catastrophic!
michael@0 35
michael@0 36 NS_ASSERTION(self,"no self");
michael@0 37
michael@0 38 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
michael@0 39 NS_ASSERTION(info,"no method info");
michael@0 40
michael@0 41 paramCount = info->GetParamCount();
michael@0 42
michael@0 43 // setup variant array pointer
michael@0 44 if(paramCount > PARAM_BUFFER_COUNT)
michael@0 45 dispatchParams = new nsXPTCMiniVariant[paramCount];
michael@0 46 else
michael@0 47 dispatchParams = paramBuffer;
michael@0 48 NS_ASSERTION(dispatchParams,"no place for params");
michael@0 49
michael@0 50 uint32_t* ap = args;
michael@0 51 for(i = 0; i < paramCount; i++, ap++)
michael@0 52 {
michael@0 53 const nsXPTParamInfo& param = info->GetParam(i);
michael@0 54 const nsXPTType& type = param.GetType();
michael@0 55 nsXPTCMiniVariant* dp = &dispatchParams[i];
michael@0 56
michael@0 57 if(param.IsOut() || !type.IsArithmetic())
michael@0 58 {
michael@0 59 dp->val.p = (void*) *ap;
michael@0 60 continue;
michael@0 61 }
michael@0 62 // else
michael@0 63 switch(type)
michael@0 64 {
michael@0 65 case nsXPTType::T_I8 : dp->val.i8 = *((int8_t*) ap); break;
michael@0 66 case nsXPTType::T_I16 : dp->val.i16 = *((int16_t*) ap); break;
michael@0 67 case nsXPTType::T_I32 : dp->val.i32 = *((int32_t*) ap); break;
michael@0 68 case nsXPTType::T_I64 : dp->val.i64 = *((int64_t*) ap); ap++; break;
michael@0 69 case nsXPTType::T_U8 : dp->val.u8 = *((uint8_t*) ap); break;
michael@0 70 case nsXPTType::T_U16 : dp->val.u16 = *((uint16_t*)ap); break;
michael@0 71 case nsXPTType::T_U32 : dp->val.u32 = *((uint32_t*)ap); break;
michael@0 72 case nsXPTType::T_U64 : dp->val.u64 = *((uint64_t*)ap); ap++; break;
michael@0 73 case nsXPTType::T_FLOAT : dp->val.f = *((float*) ap); break;
michael@0 74 case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
michael@0 75 case nsXPTType::T_BOOL : dp->val.b = *((bool*) ap); break;
michael@0 76 case nsXPTType::T_CHAR : dp->val.c = *((char*) ap); break;
michael@0 77 case nsXPTType::T_WCHAR : dp->val.wc = *((wchar_t*) ap); break;
michael@0 78 default:
michael@0 79 NS_ERROR("bad type");
michael@0 80 break;
michael@0 81 }
michael@0 82 }
michael@0 83 *stackBytesToPop = ((uint32_t)ap) - ((uint32_t)args);
michael@0 84
michael@0 85 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams);
michael@0 86
michael@0 87 if(dispatchParams != paramBuffer)
michael@0 88 delete [] dispatchParams;
michael@0 89
michael@0 90 return result;
michael@0 91 }
michael@0 92
michael@0 93 } // extern "C"
michael@0 94
michael@0 95 // declspec(naked) is broken in gcc
michael@0 96 #ifndef __GNUC__
michael@0 97 static
michael@0 98 __declspec(naked)
michael@0 99 void SharedStub(void)
michael@0 100 {
michael@0 101 __asm {
michael@0 102 push ebp // set up simple stack frame
michael@0 103 mov ebp, esp // stack has: ebp/vtbl_index/retaddr/this/args
michael@0 104 push ecx // make room for a ptr
michael@0 105 lea eax, [ebp-4] // pointer to stackBytesToPop
michael@0 106 push eax
michael@0 107 lea eax, [ebp+12] // pointer to args
michael@0 108 push eax
michael@0 109 push ecx // vtbl_index
michael@0 110 mov eax, [ebp+8] // this
michael@0 111 push eax
michael@0 112 call PrepareAndDispatch
michael@0 113 mov edx, [ebp+4] // return address
michael@0 114 mov ecx, [ebp-4] // stackBytesToPop
michael@0 115 add ecx, 8 // for 'this' and return address
michael@0 116 mov esp, ebp
michael@0 117 pop ebp
michael@0 118 add esp, ecx // fix up stack pointer
michael@0 119 jmp edx // simulate __stdcall return
michael@0 120 }
michael@0 121 }
michael@0 122
michael@0 123 // these macros get expanded (many times) in the file #included below
michael@0 124 #define STUB_ENTRY(n) \
michael@0 125 __declspec(naked) nsresult __stdcall nsXPTCStubBase::Stub##n() \
michael@0 126 { __asm mov ecx, n __asm jmp SharedStub }
michael@0 127
michael@0 128 #else
michael@0 129
michael@0 130 asm(".text\n\t"
michael@0 131 ".align 4\n\t"
michael@0 132 "SharedStub:\n\t"
michael@0 133 "push %ebp\n\t"
michael@0 134 "mov %esp, %ebp\n\t"
michael@0 135 "push %ecx\n\t"
michael@0 136 "lea -4(%ebp), %eax\n\t"
michael@0 137 "push %eax\n\t"
michael@0 138 "lea 12(%ebp), %eax\n\t"
michael@0 139 "push %eax\n\t"
michael@0 140 "push %ecx\n\t"
michael@0 141 "movl 8(%ebp), %eax\n\t"
michael@0 142 "push %eax\n\t"
michael@0 143 "call _PrepareAndDispatch@16\n\t"
michael@0 144 "mov 4(%ebp), %edx\n\t"
michael@0 145 "mov -4(%ebp), %ecx\n\t"
michael@0 146 "add $8, %ecx\n\t"
michael@0 147 "mov %ebp, %esp\n\t"
michael@0 148 "pop %ebp\n\t"
michael@0 149 "add %ecx, %esp\n\t"
michael@0 150 "jmp *%edx"
michael@0 151 );
michael@0 152
michael@0 153 #define STUB_ENTRY(n) \
michael@0 154 asm(".text\n\t" \
michael@0 155 ".align 4\n\t" \
michael@0 156 ".if " #n " < 10\n\t" \
michael@0 157 ".globl __ZN14nsXPTCStubBase5Stub" #n "Ev@4\n\t" \
michael@0 158 ".def __ZN14nsXPTCStubBase5Stub" #n "Ev@4; \n\t" \
michael@0 159 ".scl 3\n\t" \
michael@0 160 ".type 46\n\t" \
michael@0 161 ".endef\n\t" \
michael@0 162 "__ZN14nsXPTCStubBase5Stub" #n "Ev@4:\n\t" \
michael@0 163 ".elseif " #n " < 100\n\t" \
michael@0 164 ".globl __ZN14nsXPTCStubBase6Stub" #n "Ev@4\n\t" \
michael@0 165 ".def __ZN14nsXPTCStubBase6Stub" #n "Ev@4\n\t" \
michael@0 166 ".scl 3\n\t" \
michael@0 167 ".type 46\n\t" \
michael@0 168 ".endef\n\t" \
michael@0 169 "__ZN14nsXPTCStubBase6Stub" #n "Ev@4:\n\t" \
michael@0 170 ".elseif " #n " < 1000\n\t" \
michael@0 171 ".globl __ZN14nsXPTCStubBase7Stub" #n "Ev@4\n\t" \
michael@0 172 ".def __ZN14nsXPTCStubBase7Stub" #n "Ev@4\n\t" \
michael@0 173 ".scl 3\n\t" \
michael@0 174 ".type 46\n\t" \
michael@0 175 ".endef\n\t" \
michael@0 176 "__ZN14nsXPTCStubBase7Stub" #n "Ev@4:\n\t" \
michael@0 177 ".else\n\t" \
michael@0 178 ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \
michael@0 179 ".endif\n\t" \
michael@0 180 "mov $" #n ", %ecx\n\t" \
michael@0 181 "jmp SharedStub");
michael@0 182
michael@0 183 #endif /* __GNUC__ */
michael@0 184
michael@0 185 #define SENTINEL_ENTRY(n) \
michael@0 186 nsresult __stdcall nsXPTCStubBase::Sentinel##n() \
michael@0 187 { \
michael@0 188 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
michael@0 189 return NS_ERROR_NOT_IMPLEMENTED; \
michael@0 190 }
michael@0 191
michael@0 192 #ifdef _MSC_VER
michael@0 193 #pragma warning(disable : 4035) // OK to have no return value
michael@0 194 #endif
michael@0 195 #include "xptcstubsdef.inc"
michael@0 196 #ifdef _MSC_VER
michael@0 197 #pragma warning(default : 4035) // restore default
michael@0 198 #endif
michael@0 199
michael@0 200 void
michael@0 201 #ifdef __GNUC__
michael@0 202 __cdecl
michael@0 203 #endif
michael@0 204 xptc_dummy()
michael@0 205 {
michael@0 206 }

mercurial