LCOV - code coverage report
Current view: top level - xpcom/reflect/xptcall/md/unix - xptcstubs_x86_64_linux.cpp (source / functions) Hit Total Coverage
Test: output.info Lines: 37 57 64.9 %
Date: 2017-07-14 16:53:18 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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/. */
       6             : 
       7             : // Implement shared vtbl methods.
       8             : 
       9             : // Keep this in sync with the darwin version.
      10             : 
      11             : #include "xptcprivate.h"
      12             : #include "xptiprivate.h"
      13             : 
      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.
      19             : 
      20             : const uint32_t PARAM_BUFFER_COUNT   = 16;
      21             : const uint32_t GPR_COUNT            = 6;
      22             : const uint32_t FPR_COUNT            = 8;
      23             : 
      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.
      32             : 
      33             : extern "C" nsresult ATTRIBUTE_USED
      34         680 : PrepareAndDispatch(nsXPTCStubBase * self, uint32_t methodIndex,
      35             :                    uint64_t * args, uint64_t * gpregs, double *fpregs)
      36             : {
      37         680 :     nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
      38         680 :     nsXPTCMiniVariant* dispatchParams = nullptr;
      39             :     const nsXPTMethodInfo* info;
      40             :     uint32_t paramCount;
      41             :     uint32_t i;
      42         680 :     nsresult result = NS_ERROR_FAILURE;
      43             : 
      44         680 :     NS_ASSERTION(self,"no self");
      45             : 
      46         680 :     self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
      47         680 :     NS_ASSERTION(info,"no method info");
      48         680 :     if (!info)
      49           0 :         return NS_ERROR_UNEXPECTED;
      50             : 
      51         680 :     paramCount = info->GetParamCount();
      52             : 
      53             :     // setup variant array pointer
      54         680 :     if (paramCount > PARAM_BUFFER_COUNT)
      55           0 :         dispatchParams = new nsXPTCMiniVariant[paramCount];
      56             :     else
      57         680 :         dispatchParams = paramBuffer;
      58             : 
      59         680 :     NS_ASSERTION(dispatchParams,"no place for params");
      60         680 :     if (!dispatchParams)
      61           0 :         return NS_ERROR_OUT_OF_MEMORY;
      62             : 
      63         680 :     uint64_t* ap = args;
      64         680 :     uint32_t nr_gpr = 1;    // skip one GPR register for 'that'
      65         680 :     uint32_t nr_fpr = 0;
      66             :     uint64_t value;
      67             : 
      68        2277 :     for (i = 0; i < paramCount; i++) {
      69        1597 :         const nsXPTParamInfo& param = info->GetParam(i);
      70        1597 :         const nsXPTType& type = param.GetType();
      71        1597 :         nsXPTCMiniVariant* dp = &dispatchParams[i];
      72             : 
      73        1597 :         if (!param.IsOut() && type == nsXPTType::T_DOUBLE) {
      74           0 :             if (nr_fpr < FPR_COUNT)
      75           0 :                 dp->val.d = fpregs[nr_fpr++];
      76             :             else
      77           0 :                 dp->val.d = *(double*)ap++;
      78           0 :             continue;
      79             :         }
      80        1597 :         if (!param.IsOut() && type == nsXPTType::T_FLOAT) {
      81           0 :             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           0 :                 dp->val.d = fpregs[nr_fpr++];
      86             :             else
      87           0 :                 dp->val.f = *(float*)ap++;
      88           0 :             continue;
      89             :         }
      90        1597 :         if (nr_gpr < GPR_COUNT)
      91        1570 :             value = gpregs[nr_gpr++];
      92             :         else
      93          27 :             value = *ap++;
      94             : 
      95        1597 :         if (param.IsOut() || !type.IsArithmetic()) {
      96        1466 :             dp->val.p = (void*) value;
      97        1466 :             continue;
      98             :         }
      99             : 
     100         131 :         switch (type) {
     101           0 :         case nsXPTType::T_I8:      dp->val.i8  = (int8_t)   value; break;
     102           0 :         case nsXPTType::T_I16:     dp->val.i16 = (int16_t)  value; break;
     103          28 :         case nsXPTType::T_I32:     dp->val.i32 = (int32_t)  value; break;
     104          18 :         case nsXPTType::T_I64:     dp->val.i64 = (int64_t)  value; break;
     105           0 :         case nsXPTType::T_U8:      dp->val.u8  = (uint8_t)  value; break;
     106          10 :         case nsXPTType::T_U16:     dp->val.u16 = (uint16_t) value; break;
     107          65 :         case nsXPTType::T_U32:     dp->val.u32 = (uint32_t) value; break;
     108           0 :         case nsXPTType::T_U64:     dp->val.u64 = (uint64_t) value; break;
     109             :         // Cast to uint8_t first, to remove garbage on upper 56 bits.
     110          10 :         case nsXPTType::T_BOOL:    dp->val.b   = (bool)(uint8_t)   value; break;
     111           0 :         case nsXPTType::T_CHAR:    dp->val.c   = (char)     value; break;
     112           0 :         case nsXPTType::T_WCHAR:   dp->val.wc  = (wchar_t)  value; break;
     113             : 
     114             :         default:
     115           0 :             NS_ERROR("bad type");
     116           0 :             break;
     117             :         }
     118             :     }
     119             : 
     120         680 :     result = self->mOuter->CallMethod((uint16_t) methodIndex, info, dispatchParams);
     121             : 
     122         680 :     if (dispatchParams != paramBuffer)
     123           0 :         delete [] dispatchParams;
     124             : 
     125         680 :     return result;
     126             : }
     127             : 
     128             : // Linux/x86-64 uses gcc >= 3.1
     129             : // We don't include .cfi_startproc/endproc directives for the individual stubs
     130             : // because there's no extra CFI bits to define beyond the default CIE.
     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");
     161             : 
     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             :     ".cfi_startproc\n\t"
     168             :     // make room for gpregs (48), fpregs (64)
     169             :     "pushq      %rbp\n\t"
     170             :     ".cfi_def_cfa_offset 16\n\t"
     171             :     ".cfi_offset 6, -16\n\t"
     172             :     "movq       %rsp,%rbp\n\t"
     173             :     ".cfi_def_cfa_register 6\n\t"
     174             :     "subq       $112,%rsp\n\t"
     175             :     // save GP registers
     176             :     "movq       %rdi,-112(%rbp)\n\t"
     177             :     "movq       %rsi,-104(%rbp)\n\t"
     178             :     "movq       %rdx, -96(%rbp)\n\t"
     179             :     "movq       %rcx, -88(%rbp)\n\t"
     180             :     "movq       %r8 , -80(%rbp)\n\t"
     181             :     "movq       %r9 , -72(%rbp)\n\t"
     182             :     ".cfi_offset 5, -24\n\t"  // rdi
     183             :     ".cfi_offset 4, -32\n\t"  // rsi
     184             :     ".cfi_offset 1, -40\n\t"  // rdx
     185             :     ".cfi_offset 2, -48\n\t"  // rcx
     186             :     ".cfi_offset 8, -56\n\t"  // r8
     187             :     ".cfi_offset 9, -64\n\t"  // r9
     188             :     "leaq       -112(%rbp),%rcx\n\t"
     189             :     // save FP registers
     190             :     "movsd      %xmm0,-64(%rbp)\n\t"
     191             :     "movsd      %xmm1,-56(%rbp)\n\t"
     192             :     "movsd      %xmm2,-48(%rbp)\n\t"
     193             :     "movsd      %xmm3,-40(%rbp)\n\t"
     194             :     "movsd      %xmm4,-32(%rbp)\n\t"
     195             :     "movsd      %xmm5,-24(%rbp)\n\t"
     196             :     "movsd      %xmm6,-16(%rbp)\n\t"
     197             :     "movsd      %xmm7, -8(%rbp)\n\t"
     198             :     "leaq       -64(%rbp),%r8\n\t"
     199             :     // rdi has the 'self' pointer already
     200             :     "movl       %eax,%esi\n\t"
     201             :     "leaq       16(%rbp),%rdx\n\t"
     202             :     "call       PrepareAndDispatch@plt\n\t"
     203             :     "leave\n\t"
     204             :     ".cfi_def_cfa 7, 8\n\t"
     205             :     "ret\n\t"
     206             :     ".cfi_endproc\n\t"
     207             :     ".size      SharedStub,.-SharedStub");
     208             : 
     209             : #define SENTINEL_ENTRY(n) \
     210             : nsresult nsXPTCStubBase::Sentinel##n() \
     211             : { \
     212             :     NS_ERROR("nsXPTCStubBase::Sentinel called"); \
     213             :     return NS_ERROR_NOT_IMPLEMENTED; \
     214             : }
     215             : 
     216             : #include "xptcstubsdef.inc"

Generated by: LCOV version 1.13