Wed, 31 Dec 2014 06:09:35 +0100
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 | /* Platform specific code to invoke XPCOM methods on native objects */ |
michael@0 | 7 | |
michael@0 | 8 | #include "xptcprivate.h" |
michael@0 | 9 | #include "xptc_gcc_x86_unix.h" |
michael@0 | 10 | |
michael@0 | 11 | extern "C" { |
michael@0 | 12 | static void ATTRIBUTE_USED __attribute__ ((regparm(3))) |
michael@0 | 13 | invoke_copy_to_stack(uint32_t paramCount, nsXPTCVariant* s, uint32_t* d) |
michael@0 | 14 | { |
michael@0 | 15 | for(uint32_t i = paramCount; i >0; i--, d++, s++) |
michael@0 | 16 | { |
michael@0 | 17 | if(s->IsPtrData()) |
michael@0 | 18 | { |
michael@0 | 19 | *((void**)d) = s->ptr; |
michael@0 | 20 | continue; |
michael@0 | 21 | } |
michael@0 | 22 | |
michael@0 | 23 | switch(s->type) |
michael@0 | 24 | { |
michael@0 | 25 | case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; |
michael@0 | 26 | case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; |
michael@0 | 27 | case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; |
michael@0 | 28 | default : *((void**)d) = s->val.p; break; |
michael@0 | 29 | } |
michael@0 | 30 | } |
michael@0 | 31 | } |
michael@0 | 32 | } // extern "C" |
michael@0 | 33 | |
michael@0 | 34 | /* |
michael@0 | 35 | EXPORT_XPCOM_API(nsresult) |
michael@0 | 36 | NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
michael@0 | 37 | uint32_t paramCount, nsXPTCVariant* params); |
michael@0 | 38 | |
michael@0 | 39 | Each param takes at most two 4-byte words. |
michael@0 | 40 | It doesn't matter if we push too many words, and calculating the exact |
michael@0 | 41 | amount takes time. |
michael@0 | 42 | |
michael@0 | 43 | that = ebp + 0x08 |
michael@0 | 44 | methodIndex = ebp + 0x0c |
michael@0 | 45 | paramCount = ebp + 0x10 |
michael@0 | 46 | params = ebp + 0x14 |
michael@0 | 47 | |
michael@0 | 48 | */ |
michael@0 | 49 | |
michael@0 | 50 | __asm__ ( |
michael@0 | 51 | ".text\n\t" |
michael@0 | 52 | /* alignment here seems unimportant here; this was 16, now it's 2 which |
michael@0 | 53 | is what xptcstubs uses. */ |
michael@0 | 54 | ".align 2\n\t" |
michael@0 | 55 | ".globl " SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t" |
michael@0 | 56 | #ifndef XP_MACOSX |
michael@0 | 57 | ".type " SYMBOL_UNDERSCORE "NS_InvokeByIndex,@function\n" |
michael@0 | 58 | #endif |
michael@0 | 59 | SYMBOL_UNDERSCORE "NS_InvokeByIndex:\n\t" |
michael@0 | 60 | "pushl %ebp\n\t" |
michael@0 | 61 | "movl %esp, %ebp\n\t" |
michael@0 | 62 | "movl 0x10(%ebp), %eax\n\t" |
michael@0 | 63 | "leal 0(,%eax,8),%edx\n\t" |
michael@0 | 64 | |
michael@0 | 65 | /* set up call frame for method. */ |
michael@0 | 66 | "subl %edx, %esp\n\t" /* make room for params. */ |
michael@0 | 67 | /* Align to maximum x86 data size: 128 bits == 16 bytes == XMM register size. |
michael@0 | 68 | * This is to avoid protection faults where SSE+ alignment of stack pointer |
michael@0 | 69 | * is assumed and required, e.g. by GCC4's -ftree-vectorize option. |
michael@0 | 70 | */ |
michael@0 | 71 | "andl $0xfffffff0, %esp\n\t" /* drop(?) stack ptr to 128-bit align */ |
michael@0 | 72 | /* $esp should be aligned to a 16-byte boundary here (note we include an |
michael@0 | 73 | * additional 4 bytes in a later push instruction). This will ensure $ebp |
michael@0 | 74 | * in the function called below is aligned to a 0x8 boundary. SSE instructions |
michael@0 | 75 | * like movapd/movdqa expect memory operand to be aligned on a 16-byte |
michael@0 | 76 | * boundary. The GCC compiler will generate the memory operand using $ebp |
michael@0 | 77 | * with an 8-byte offset. |
michael@0 | 78 | */ |
michael@0 | 79 | "subl $0xc, %esp\n\t" /* lower again; push/call below will re-align */ |
michael@0 | 80 | "movl %esp, %ecx\n\t" /* ecx = d */ |
michael@0 | 81 | "movl 8(%ebp), %edx\n\t" /* edx = this */ |
michael@0 | 82 | "pushl %edx\n\t" /* push this. esp % 16 == 0 */ |
michael@0 | 83 | |
michael@0 | 84 | "movl 0x14(%ebp), %edx\n\t" |
michael@0 | 85 | "call " SYMBOL_UNDERSCORE "invoke_copy_to_stack\n\t" |
michael@0 | 86 | "movl 0x08(%ebp), %ecx\n\t" /* 'that' */ |
michael@0 | 87 | "movl (%ecx), %edx\n\t" |
michael@0 | 88 | "movl 0x0c(%ebp), %eax\n\t" /* function index */ |
michael@0 | 89 | "leal (%edx,%eax,4), %edx\n\t" |
michael@0 | 90 | "call *(%edx)\n\t" |
michael@0 | 91 | "movl %ebp, %esp\n\t" |
michael@0 | 92 | "popl %ebp\n\t" |
michael@0 | 93 | "ret\n" |
michael@0 | 94 | #ifndef XP_MACOSX |
michael@0 | 95 | ".size " SYMBOL_UNDERSCORE "NS_InvokeByIndex, . -" SYMBOL_UNDERSCORE "NS_InvokeByIndex\n\t" |
michael@0 | 96 | #endif |
michael@0 | 97 | ); |