xpcom/reflect/xptcall/src/md/unix/xptcstubs_ppc64_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 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 // Implement shared vtbl methods.
     8 #include "xptcprivate.h"
     9 #include "xptiprivate.h"
    11 // The Linux/PPC64 ABI passes the first 8 integral
    12 // parameters and the first 13 floating point parameters in registers
    13 // (r3-r10 and f1-f13), no stack space is allocated for these by the
    14 // caller.  The rest of the parameters are passed in the caller's stack
    15 // area. The stack pointer has to retain 16-byte alignment.
    17 // The PowerPC64 platform ABI can be found here:
    18 // http://www.freestandards.org/spec/ELF/ppc64/
    19 // and in particular:
    20 // http://www.freestandards.org/spec/ELF/ppc64/PPC-elf64abi-1.9.html#FUNC-CALL
    22 #define PARAM_BUFFER_COUNT      16
    23 #define GPR_COUNT                7
    24 #define FPR_COUNT               13
    26 // PrepareAndDispatch() is called by SharedStub() and calls the actual method.
    27 //
    28 // - 'args[]' contains the arguments passed on stack
    29 // - 'gprData[]' contains the arguments passed in integer registers
    30 // - 'fprData[]' contains the arguments passed in floating point registers
    31 // 
    32 // The parameters are mapped into an array of type 'nsXPTCMiniVariant'
    33 // and then the method gets called.
    34 #include <stdio.h>
    35 extern "C" nsresult ATTRIBUTE_USED
    36 PrepareAndDispatch(nsXPTCStubBase* self,
    37                    uint64_t methodIndex,
    38                    uint64_t* args,
    39                    uint64_t *gprData,
    40                    double *fprData)
    41 {
    42     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
    43     nsXPTCMiniVariant* dispatchParams = nullptr;
    44     const nsXPTMethodInfo* info;
    45     uint32_t paramCount;
    46     uint32_t i;
    47     nsresult result = NS_ERROR_FAILURE;
    49     NS_ASSERTION(self,"no self");
    51     self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
    52     NS_ASSERTION(info,"no method info");
    53     if (! info)
    54         return NS_ERROR_UNEXPECTED;
    56     paramCount = info->GetParamCount();
    58     // setup variant array pointer
    59     if(paramCount > PARAM_BUFFER_COUNT)
    60         dispatchParams = new nsXPTCMiniVariant[paramCount];
    61     else
    62         dispatchParams = paramBuffer;
    64     NS_ASSERTION(dispatchParams,"no place for params");
    65     if (! dispatchParams)
    66         return NS_ERROR_OUT_OF_MEMORY;
    68     uint64_t* ap = args;
    69     uint64_t tempu64;
    71     for(i = 0; i < paramCount; i++) {
    72         const nsXPTParamInfo& param = info->GetParam(i);
    73         const nsXPTType& type = param.GetType();
    74         nsXPTCMiniVariant* dp = &dispatchParams[i];
    76         if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
    77             if (i < FPR_COUNT)
    78                 dp->val.d = fprData[i];
    79             else
    80                 dp->val.d = *(double*) ap;
    81         } else if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
    82             if (i < FPR_COUNT)
    83                 dp->val.f = (float) fprData[i]; // in registers floats are passed as doubles
    84             else {
    85                 float *p = (float *)ap;
    86 #ifndef __LITTLE_ENDIAN__
    87                 p++;
    88 #endif
    89                 dp->val.f = *p;
    90             }
    91         } else { /* integer type or pointer */
    92             if (i < GPR_COUNT)
    93                 tempu64 = gprData[i];
    94             else
    95                 tempu64 = *ap;
    97             if (param.IsOut() || !type.IsArithmetic())
    98                 dp->val.p = (void*) tempu64;
    99             else if (type == nsXPTType::T_I8)
   100                 dp->val.i8  = (int8_t)   tempu64;
   101             else if (type == nsXPTType::T_I16)
   102                 dp->val.i16 = (int16_t)  tempu64;
   103             else if (type == nsXPTType::T_I32)
   104                 dp->val.i32 = (int32_t)  tempu64;
   105             else if (type == nsXPTType::T_I64)
   106                 dp->val.i64 = (int64_t)  tempu64;
   107             else if (type == nsXPTType::T_U8)
   108                 dp->val.u8  = (uint8_t)  tempu64;
   109             else if (type == nsXPTType::T_U16)
   110                 dp->val.u16 = (uint16_t) tempu64;
   111             else if (type == nsXPTType::T_U32)
   112                 dp->val.u32 = (uint32_t) tempu64;
   113             else if (type == nsXPTType::T_U64)
   114                 dp->val.u64 = (uint64_t) tempu64;
   115             else if (type == nsXPTType::T_BOOL)
   116                 dp->val.b   = (bool)   tempu64;
   117             else if (type == nsXPTType::T_CHAR)
   118                 dp->val.c   = (char)     tempu64;
   119             else if (type == nsXPTType::T_WCHAR)
   120                 dp->val.wc  = (wchar_t)  tempu64;
   121             else
   122                 NS_ERROR("bad type");
   123         }
   125         if (i >= 7)
   126             ap++;
   127     }
   129     result = self->mOuter->CallMethod((uint16_t) methodIndex, info,
   130                                       dispatchParams);
   132     if (dispatchParams != paramBuffer)
   133         delete [] dispatchParams;
   135     return result;
   136 }
   138 // Load r11 with the constant 'n' and branch to SharedStub().
   139 //
   140 // XXX Yes, it's ugly that we're relying on gcc's name-mangling here;
   141 // however, it's quick, dirty, and'll break when the ABI changes on
   142 // us, which is what we want ;-).
   145 // gcc-3 version
   146 //
   147 // As G++3 ABI contains the length of the functionname in the mangled
   148 // name, it is difficult to get a generic assembler mechanism like
   149 // in the G++ 2.95 case.
   150 // Create names would be like:
   151 // _ZN14nsXPTCStubBase5Stub1Ev
   152 // _ZN14nsXPTCStubBase6Stub12Ev
   153 // _ZN14nsXPTCStubBase7Stub123Ev
   154 // _ZN14nsXPTCStubBase8Stub1234Ev
   155 // etc.
   156 // Use assembler directives to get the names right...
   158 #if _CALL_ELF == 2
   159 # define STUB_ENTRY(n)                                                  \
   160 __asm__ (                                                               \
   161         ".section \".text\" \n\t"                                       \
   162         ".align 2 \n\t"                                                 \
   163         ".if "#n" < 10 \n\t"                                            \
   164         ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
   165         ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
   166 "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
   167         "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   168         "addi     2,2,.TOC.-0b@l \n\t"                                  \
   169         ".localentry _ZN14nsXPTCStubBase5Stub"#n"Ev,.-_ZN14nsXPTCStubBase5Stub"#n"Ev \n\t" \
   170                                                                         \
   171         ".elseif "#n" < 100 \n\t"                                       \
   172         ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
   173         ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
   174 "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
   175         "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   176         "addi     2,2,.TOC.-0b@l \n\t"                                  \
   177         ".localentry _ZN14nsXPTCStubBase6Stub"#n"Ev,.-_ZN14nsXPTCStubBase6Stub"#n"Ev \n\t" \
   178                                                                         \
   179         ".elseif "#n" < 1000 \n\t"                                      \
   180         ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t"                    \
   181         ".type  _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n"          \
   182 "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                  \
   183         "0: addis 2,12,.TOC.-0b@ha \n\t"                                \
   184         "addi     2,2,.TOC.-0b@l \n\t"                                  \
   185         ".localentry _ZN14nsXPTCStubBase7Stub"#n"Ev,.-_ZN14nsXPTCStubBase7Stub"#n"Ev \n\t" \
   186                                                                         \
   187         ".else  \n\t"                                                   \
   188         ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
   189         ".endif \n\t"                                                   \
   190                                                                         \
   191         "li     11,"#n" \n\t"                                           \
   192         "b      SharedStub \n"                                          \
   193 );
   194 #else
   195 # define STUB_ENTRY(n)                                                  \
   196 __asm__ (                                                               \
   197         ".section \".toc\",\"aw\" \n\t"                                 \
   198         ".section \".text\" \n\t"                                       \
   199         ".align 2 \n\t"                                                 \
   200         ".if "#n" < 10 \n\t"                                            \
   201         ".globl _ZN14nsXPTCStubBase5Stub"#n"Ev \n\t"                    \
   202         ".section \".opd\",\"aw\" \n\t"                                 \
   203         ".align 3 \n\t"                                                 \
   204 "_ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                  \
   205         ".quad  ._ZN14nsXPTCStubBase5Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   206         ".previous \n\t"                                                \
   207         ".type  _ZN14nsXPTCStubBase5Stub"#n"Ev,@function \n\n"          \
   208 "._ZN14nsXPTCStubBase5Stub"#n"Ev: \n\t"                                 \
   209                                                                         \
   210         ".elseif "#n" < 100 \n\t"                                       \
   211         ".globl _ZN14nsXPTCStubBase6Stub"#n"Ev \n\t"                    \
   212         ".section \".opd\",\"aw\" \n\t"                                 \
   213         ".align 3 \n\t"                                                 \
   214 "_ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                  \
   215         ".quad  ._ZN14nsXPTCStubBase6Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   216         ".previous \n\t"                                                \
   217         ".type  _ZN14nsXPTCStubBase6Stub"#n"Ev,@function \n\n"          \
   218 "._ZN14nsXPTCStubBase6Stub"#n"Ev: \n\t"                                 \
   219                                                                         \
   220         ".elseif "#n" < 1000 \n\t"                                      \
   221         ".globl _ZN14nsXPTCStubBase7Stub"#n"Ev \n\t"                    \
   222         ".section \".opd\",\"aw\" \n\t"                                 \
   223         ".align 3 \n\t"                                                 \
   224 "_ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                  \
   225         ".quad  ._ZN14nsXPTCStubBase7Stub"#n"Ev,.TOC.@tocbase \n\t"     \
   226         ".previous \n\t"                                                \
   227         ".type  _ZN14nsXPTCStubBase7Stub"#n"Ev,@function \n\n"          \
   228 "._ZN14nsXPTCStubBase7Stub"#n"Ev: \n\t"                                 \
   229                                                                         \
   230         ".else  \n\t"                                                   \
   231         ".err   \"stub number "#n" >= 1000 not yet supported\"\n"       \
   232         ".endif \n\t"                                                   \
   233                                                                         \
   234         "li     11,"#n" \n\t"                                           \
   235         "b      SharedStub \n"                                          \
   236 );
   237 #endif
   239 #define SENTINEL_ENTRY(n)                                               \
   240 nsresult nsXPTCStubBase::Sentinel##n()                                  \
   241 {                                                                       \
   242     NS_ERROR("nsXPTCStubBase::Sentinel called");                  \
   243     return NS_ERROR_NOT_IMPLEMENTED;                                    \
   244 }
   246 #include "xptcstubsdef.inc"

mercurial