xpcom/reflect/xptcall/src/md/unix/xptcstubs_gcc_x86_unix.cpp

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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 #include "xptc_gcc_x86_unix.h"
michael@0 11
michael@0 12 extern "C" {
michael@0 13 static nsresult ATTRIBUTE_USED
michael@0 14 __attribute__ ((regparm (3)))
michael@0 15 PrepareAndDispatch(uint32_t methodIndex, nsXPTCStubBase* self, uint32_t* args)
michael@0 16 {
michael@0 17 #define PARAM_BUFFER_COUNT 16
michael@0 18
michael@0 19 nsXPTCMiniVariant paramBuffer[PARAM_BUFFER_COUNT];
michael@0 20 nsXPTCMiniVariant* dispatchParams = nullptr;
michael@0 21 const nsXPTMethodInfo* info;
michael@0 22 uint8_t paramCount;
michael@0 23 uint8_t i;
michael@0 24 nsresult result = NS_ERROR_FAILURE;
michael@0 25
michael@0 26 NS_ASSERTION(self,"no self");
michael@0 27
michael@0 28 self->mEntry->GetMethodInfo(uint16_t(methodIndex), &info);
michael@0 29 paramCount = info->GetParamCount();
michael@0 30
michael@0 31 // setup variant array pointer
michael@0 32 if(paramCount > PARAM_BUFFER_COUNT)
michael@0 33 dispatchParams = new nsXPTCMiniVariant[paramCount];
michael@0 34 else
michael@0 35 dispatchParams = paramBuffer;
michael@0 36 NS_ASSERTION(dispatchParams,"no place for params");
michael@0 37
michael@0 38 uint32_t* ap = args;
michael@0 39 for(i = 0; i < paramCount; i++, ap++)
michael@0 40 {
michael@0 41 const nsXPTParamInfo& param = info->GetParam(i);
michael@0 42 const nsXPTType& type = param.GetType();
michael@0 43 nsXPTCMiniVariant* dp = &dispatchParams[i];
michael@0 44
michael@0 45 if(param.IsOut() || !type.IsArithmetic())
michael@0 46 {
michael@0 47 dp->val.p = (void*) *ap;
michael@0 48 continue;
michael@0 49 }
michael@0 50 // else
michael@0 51 dp->val.p = (void*) *ap;
michael@0 52 switch(type)
michael@0 53 {
michael@0 54 case nsXPTType::T_I64 : dp->val.i64 = *((int64_t*) ap); ap++; break;
michael@0 55 case nsXPTType::T_U64 : dp->val.u64 = *((uint64_t*)ap); ap++; break;
michael@0 56 case nsXPTType::T_DOUBLE : dp->val.d = *((double*) ap); ap++; break;
michael@0 57 }
michael@0 58 }
michael@0 59
michael@0 60 result = self->mOuter->CallMethod((uint16_t)methodIndex, info, dispatchParams);
michael@0 61
michael@0 62 if(dispatchParams != paramBuffer)
michael@0 63 delete [] dispatchParams;
michael@0 64
michael@0 65 return result;
michael@0 66 }
michael@0 67 } // extern "C"
michael@0 68
michael@0 69 #if !defined(XP_MACOSX)
michael@0 70
michael@0 71 #define STUB_HEADER(a, b) ".hidden " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase" #a "Stub" #b "Ev\n\t" \
michael@0 72 ".type " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase" #a "Stub" #b "Ev,@function\n"
michael@0 73
michael@0 74 #define STUB_SIZE(a, b) ".size " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase" #a "Stub" #b "Ev,.-" SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase" #a "Stub" #b "Ev\n\t"
michael@0 75
michael@0 76 #else
michael@0 77
michael@0 78 #define STUB_HEADER(a, b)
michael@0 79 #define STUB_SIZE(a, b)
michael@0 80
michael@0 81 #endif
michael@0 82
michael@0 83 // gcc3 mangling tends to insert the length of the method name
michael@0 84 #define STUB_ENTRY(n) \
michael@0 85 asm(".text\n\t" \
michael@0 86 ".align 2\n\t" \
michael@0 87 ".if " #n " < 10\n\t" \
michael@0 88 ".globl " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev\n\t" \
michael@0 89 STUB_HEADER(5, n) \
michael@0 90 SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase5Stub" #n "Ev:\n\t" \
michael@0 91 ".elseif " #n " < 100\n\t" \
michael@0 92 ".globl " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev\n\t" \
michael@0 93 STUB_HEADER(6, n) \
michael@0 94 SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase6Stub" #n "Ev:\n\t" \
michael@0 95 ".elseif " #n " < 1000\n\t" \
michael@0 96 ".globl " SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev\n\t" \
michael@0 97 STUB_HEADER(7, n) \
michael@0 98 SYMBOL_UNDERSCORE "_ZN14nsXPTCStubBase7Stub" #n "Ev:\n\t" \
michael@0 99 ".else\n\t" \
michael@0 100 ".err \"stub number " #n " >= 1000 not yet supported\"\n\t" \
michael@0 101 ".endif\n\t" \
michael@0 102 "movl $" #n ", %eax\n\t" \
michael@0 103 "jmp " SYMBOL_UNDERSCORE "SharedStub\n\t" \
michael@0 104 ".if " #n " < 10\n\t" \
michael@0 105 STUB_SIZE(5, n) \
michael@0 106 ".elseif " #n " < 100\n\t" \
michael@0 107 STUB_SIZE(6, n) \
michael@0 108 ".else\n\t" \
michael@0 109 STUB_SIZE(7, n) \
michael@0 110 ".endif");
michael@0 111
michael@0 112 // static nsresult SharedStub(uint32_t methodIndex) __attribute__((regparm(1)))
michael@0 113 asm(".text\n\t"
michael@0 114 ".align 2\n\t"
michael@0 115 #if !defined(XP_MACOSX)
michael@0 116 ".type " SYMBOL_UNDERSCORE "SharedStub,@function\n\t"
michael@0 117 #endif
michael@0 118 SYMBOL_UNDERSCORE "SharedStub:\n\t"
michael@0 119 "leal 0x08(%esp), %ecx\n\t"
michael@0 120 "movl 0x04(%esp), %edx\n\t"
michael@0 121 "jmp " SYMBOL_UNDERSCORE "PrepareAndDispatch\n\t"
michael@0 122 #if !defined(XP_MACOSX)
michael@0 123 ".size " SYMBOL_UNDERSCORE "SharedStub,.-" SYMBOL_UNDERSCORE "SharedStub"
michael@0 124 #endif
michael@0 125 );
michael@0 126
michael@0 127 #define SENTINEL_ENTRY(n) \
michael@0 128 nsresult nsXPTCStubBase::Sentinel##n() \
michael@0 129 { \
michael@0 130 NS_ERROR("nsXPTCStubBase::Sentinel called"); \
michael@0 131 return NS_ERROR_NOT_IMPLEMENTED; \
michael@0 132 }
michael@0 133
michael@0 134 #include "xptcstubsdef.inc"
michael@0 135
michael@0 136 void
michael@0 137 xptc_dummy()
michael@0 138 {
michael@0 139 }

mercurial