Sat, 03 Jan 2015 20:18:00 +0100
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.
1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 // Implement shared vtbl methods.
9 // Keep this in sync with the linux version.
11 #include "xptcprivate.h"
12 #include "xptiprivate.h"
14 // The Darwin/x86-64 ABI passes the first 6 integer parameters and the
15 // first 8 floating point parameters in registers (rdi, rsi, rdx, rcx,
16 // r8, r9 and xmm0-xmm7), no stack space is allocated for these by the
17 // caller. The rest of the parameters are passed in the callers stack
18 // area.
20 const uint32_t PARAM_BUFFER_COUNT = 16;
21 const uint32_t GPR_COUNT = 6;
22 const uint32_t FPR_COUNT = 8;
24 // PrepareAndDispatch() is called by SharedStub() and calls the actual method.
25 //
26 // - 'args[]' contains the arguments passed on stack
27 // - 'gpregs[]' contains the arguments passed in integer registers
28 // - 'fpregs[]' contains the arguments passed in floating point registers
29 //
30 // The parameters are mapped into an array of type 'nsXPTCMiniVariant'
31 // and then the method gets called.
33 extern "C" nsresult ATTRIBUTE_USED
34 PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex,
35 uint64_t * args, uint64_t * gpregs, double *fpregs)
36 {
37 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
38 nsXPTCMiniVariant* dispatchParams = nullptr;
39 const nsXPTMethodInfo* info;
40 uint32_t paramCount;
41 uint32_t i;
42 nsresult result = NS_ERROR_FAILURE;
44 NS_ASSERTION(self,"no self");
46 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
47 NS_ASSERTION(info,"no method info");
48 if (!info)
49 return NS_ERROR_UNEXPECTED;
51 paramCount = info->GetParamCount();
53 // setup variant array pointer
54 if (paramCount > PARAM_BUFFER_COUNT)
55 dispatchParams = new nsXPTCMiniVariant[paramCount];
56 else
57 dispatchParams = paramBuffer;
59 NS_ASSERTION(dispatchParams,"no place for params");
60 if (!dispatchParams)
61 return NS_ERROR_OUT_OF_MEMORY;
63 uint64_t* ap = args;
64 uint32_t nr_gpr = 1; // skip one GPR register for 'that'
65 uint32_t nr_fpr = 0;
66 uint64_t value;
68 for (i = 0; i < paramCount; i++) {
69 const nsXPTParamInfo& param = info->GetParam(i);
70 const nsXPTType& type = param.GetType();
71 nsXPTCMiniVariant* dp = &dispatchParams[i];
73 if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
74 if (nr_fpr < FPR_COUNT)
75 dp->val.d = fpregs[nr_fpr++];
76 else
77 dp->val.d = *(double*) ap++;
78 continue;
79 }
80 else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
81 if (nr_fpr < FPR_COUNT)
82 // The value in %xmm register is already prepared to
83 // be retrieved as a float. Therefore, we pass the
84 // value verbatim, as a double without conversion.
85 dp->val.d = fpregs[nr_fpr++];
86 else
87 dp->val.f = *(float*) ap++;
88 continue;
89 }
90 else {
91 if (nr_gpr < GPR_COUNT)
92 value = gpregs[nr_gpr++];
93 else
94 value = *ap++;
95 }
97 if (param.IsOut() || !type.IsArithmetic()) {
98 dp->val.p = (void*) value;
99 continue;
100 }
102 switch (type) {
103 case nsXPTType::T_I8: dp->val.i8 = (int8_t) value; break;
104 case nsXPTType::T_I16: dp->val.i16 = (int16_t) value; break;
105 case nsXPTType::T_I32: dp->val.i32 = (int32_t) value; break;
106 case nsXPTType::T_I64: dp->val.i64 = (int64_t) value; break;
107 case nsXPTType::T_U8: dp->val.u8 = (uint8_t) value; break;
108 case nsXPTType::T_U16: dp->val.u16 = (uint16_t) value; break;
109 case nsXPTType::T_U32: dp->val.u32 = (uint32_t) value; break;
110 case nsXPTType::T_U64: dp->val.u64 = (uint64_t) value; break;
111 // Cast to uint8_t first, to remove garbage on upper 56 bits.
112 case nsXPTType::T_BOOL: dp->val.b = (bool)(uint8_t) value; break;
113 case nsXPTType::T_CHAR: dp->val.c = (char) value; break;
114 case nsXPTType::T_WCHAR: dp->val.wc = (wchar_t) value; break;
116 default:
117 NS_ERROR("bad type");
118 break;
119 }
120 }
122 result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams);
124 if (dispatchParams != paramBuffer)
125 delete [] dispatchParams;
127 return result;
128 }
130 // Darwin/x86-64 uses gcc >= 4.2
132 #define STUB_ENTRY(n) \
133 asm(".section __TEXT,__text\n\t" \
134 ".align 3\n\t" \
135 ".if " #n " < 10\n\t" \
136 ".globl __ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
137 "__ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
138 ".elseif " #n " < 100\n\t" \
139 ".globl __ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
140 "__ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
141 ".elseif " #n " < 1000\n\t" \
142 ".globl __ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
143 "__ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
144 ".else\n\t" \
145 ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \
146 ".endif\n\t" \
147 "movl $" #n ", %eax\n\t" \
148 "jmp SharedStub\n\t");
150 // static nsresult SharedStub(uint32_t methodIndex)
151 asm(".section __TEXT,__text\n\t"
152 ".align 3\n\t"
153 "SharedStub:\n\t"
154 // make room for gpregs (48), fpregs (64)
155 "pushq %rbp\n\t"
156 "movq %rsp,%rbp\n\t"
157 "subq $112,%rsp\n\t"
158 // save GP registers
159 "movq %rdi,-112(%rbp)\n\t"
160 "movq %rsi,-104(%rbp)\n\t"
161 "movq %rdx, -96(%rbp)\n\t"
162 "movq %rcx, -88(%rbp)\n\t"
163 "movq %r8 , -80(%rbp)\n\t"
164 "movq %r9 , -72(%rbp)\n\t"
165 "leaq -112(%rbp),%rcx\n\t"
166 // save FP registers
167 "movsd %xmm0,-64(%rbp)\n\t"
168 "movsd %xmm1,-56(%rbp)\n\t"
169 "movsd %xmm2,-48(%rbp)\n\t"
170 "movsd %xmm3,-40(%rbp)\n\t"
171 "movsd %xmm4,-32(%rbp)\n\t"
172 "movsd %xmm5,-24(%rbp)\n\t"
173 "movsd %xmm6,-16(%rbp)\n\t"
174 "movsd %xmm7, -8(%rbp)\n\t"
175 "leaq -64(%rbp),%r8\n\t"
176 // rdi has the 'self' pointer already
177 "movl %eax,%esi\n\t"
178 "leaq 16(%rbp),%rdx\n\t"
179 "call _PrepareAndDispatch\n\t"
180 "leave\n\t"
181 "ret\n\t");
183 #define SENTINEL_ENTRY(n) \
184 nsresult nsXPTCStubBase::Sentinel##n() \
185 { \
186 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
187 return NS_ERROR_NOT_IMPLEMENTED; \
188 }
190 #include "xptcstubsdef.inc"