xpcom/reflect/xptcall/src/md/unix/xptcstubs_x86_64_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.

     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 darwin version.
    11 #include "xptcprivate.h"
    12 #include "xptiprivate.h"
    14 // The Linux/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 // Linux/x86-64 uses gcc >= 3.1
   131 #define STUB_ENTRY(n) \
   132 asm(".section	\".text\"\n\t" \
   133     ".align	2\n\t" \
   134     ".if	" #n " < 10\n\t" \
   135     ".globl	_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   136     ".hidden	_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   137     ".type	_ZN14nsXPTCStubBase5Stub" #n "Ev,@function\n" \
   138     "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
   139     ".elseif	" #n " < 100\n\t" \
   140     ".globl	_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   141     ".hidden	_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   142     ".type	_ZN14nsXPTCStubBase6Stub" #n "Ev,@function\n" \
   143     "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
   144     ".elseif    " #n " < 1000\n\t" \
   145     ".globl     _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   146     ".hidden    _ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   147     ".type      _ZN14nsXPTCStubBase7Stub" #n "Ev,@function\n" \
   148     "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
   149     ".else\n\t" \
   150     ".err	\"stub number " #n " >= 1000 not yet supported\"\n\t" \
   151     ".endif\n\t" \
   152     "movl	$" #n ", %eax\n\t" \
   153     "jmp	SharedStub\n\t" \
   154     ".if	" #n " < 10\n\t" \
   155     ".size	_ZN14nsXPTCStubBase5Stub" #n "Ev,.-_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
   156     ".elseif	" #n " < 100\n\t" \
   157     ".size	_ZN14nsXPTCStubBase6Stub" #n "Ev,.-_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
   158     ".else\n\t" \
   159     ".size	_ZN14nsXPTCStubBase7Stub" #n "Ev,.-_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
   160     ".endif");
   162 // static nsresult SharedStub(uint32_t methodIndex)
   163 asm(".section   \".text\"\n\t"
   164     ".align     2\n\t"
   165     ".type      SharedStub,@function\n\t"
   166     "SharedStub:\n\t"
   167     // make room for gpregs (48), fpregs (64)
   168     "pushq      %rbp\n\t"
   169     "movq       %rsp,%rbp\n\t"
   170     "subq       $112,%rsp\n\t"
   171     // save GP registers
   172     "movq       %rdi,-112(%rbp)\n\t"
   173     "movq       %rsi,-104(%rbp)\n\t"
   174     "movq       %rdx, -96(%rbp)\n\t"
   175     "movq       %rcx, -88(%rbp)\n\t"
   176     "movq       %r8 , -80(%rbp)\n\t"
   177     "movq       %r9 , -72(%rbp)\n\t"
   178     "leaq       -112(%rbp),%rcx\n\t"
   179     // save FP registers
   180     "movsd      %xmm0,-64(%rbp)\n\t"
   181     "movsd      %xmm1,-56(%rbp)\n\t"
   182     "movsd      %xmm2,-48(%rbp)\n\t"
   183     "movsd      %xmm3,-40(%rbp)\n\t"
   184     "movsd      %xmm4,-32(%rbp)\n\t"
   185     "movsd      %xmm5,-24(%rbp)\n\t"
   186     "movsd      %xmm6,-16(%rbp)\n\t"
   187     "movsd      %xmm7, -8(%rbp)\n\t"
   188     "leaq       -64(%rbp),%r8\n\t"
   189     // rdi has the 'self' pointer already
   190     "movl       %eax,%esi\n\t"
   191     "leaq       16(%rbp),%rdx\n\t"
   192     "call       PrepareAndDispatch@plt\n\t"
   193     "leave\n\t"
   194     "ret\n\t"
   195     ".size      SharedStub,.-SharedStub");
   197 #define SENTINEL_ENTRY(n) \
   198 nsresult nsXPTCStubBase::Sentinel##n() \
   199 { \
   200     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
   201     return NS_ERROR_NOT_IMPLEMENTED; \
   202 }
   204 #include "xptcstubsdef.inc"

mercurial