Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
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 | |
michael@0 | 10 | extern "C" { |
michael@0 | 11 | void __attribute__ ((__used__)) __attribute__ ((regparm(3))) |
michael@0 | 12 | invoke_copy_to_stack(uint32_t paramCount, nsXPTCVariant* s, uint32_t* d) |
michael@0 | 13 | { |
michael@0 | 14 | for(uint32_t i = paramCount; i >0; i--, d++, s++) |
michael@0 | 15 | { |
michael@0 | 16 | if(s->IsPtrData()) |
michael@0 | 17 | { |
michael@0 | 18 | *((void**)d) = s->ptr; |
michael@0 | 19 | continue; |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | switch(s->type) |
michael@0 | 23 | { |
michael@0 | 24 | case nsXPTType::T_I8 : *((int8_t*) d) = s->val.i8; break; |
michael@0 | 25 | case nsXPTType::T_I16 : *((int16_t*) d) = s->val.i16; break; |
michael@0 | 26 | case nsXPTType::T_I32 : *((int32_t*) d) = s->val.i32; break; |
michael@0 | 27 | case nsXPTType::T_I64 : *((int64_t*) d) = s->val.i64; d++; break; |
michael@0 | 28 | case nsXPTType::T_U8 : *((uint8_t*) d) = s->val.u8; break; |
michael@0 | 29 | case nsXPTType::T_U16 : *((uint16_t*)d) = s->val.u16; break; |
michael@0 | 30 | case nsXPTType::T_U32 : *((uint32_t*)d) = s->val.u32; break; |
michael@0 | 31 | case nsXPTType::T_U64 : *((uint64_t*)d) = s->val.u64; d++; break; |
michael@0 | 32 | case nsXPTType::T_FLOAT : *((float*) d) = s->val.f; break; |
michael@0 | 33 | case nsXPTType::T_DOUBLE : *((double*) d) = s->val.d; d++; break; |
michael@0 | 34 | case nsXPTType::T_BOOL : *((bool*) d) = s->val.b; break; |
michael@0 | 35 | case nsXPTType::T_CHAR : *((char*) d) = s->val.c; break; |
michael@0 | 36 | case nsXPTType::T_WCHAR : *((wchar_t*) d) = s->val.wc; break; |
michael@0 | 37 | default: |
michael@0 | 38 | // all the others are plain pointer types |
michael@0 | 39 | *((void**)d) = s->val.p; |
michael@0 | 40 | break; |
michael@0 | 41 | } |
michael@0 | 42 | } |
michael@0 | 43 | } |
michael@0 | 44 | } // extern "C" |
michael@0 | 45 | |
michael@0 | 46 | /* |
michael@0 | 47 | EXPORT_XPCOM_API(nsresult) |
michael@0 | 48 | NS_InvokeByIndex(nsISupports* that, uint32_t methodIndex, |
michael@0 | 49 | uint32_t paramCount, nsXPTCVariant* params); |
michael@0 | 50 | |
michael@0 | 51 | Each param takes at most two 4-byte words. |
michael@0 | 52 | It doesn't matter if we push too many words, and calculating the exact |
michael@0 | 53 | amount takes time. |
michael@0 | 54 | |
michael@0 | 55 | that = ebp + 0x08 |
michael@0 | 56 | methodIndex = ebp + 0x0c |
michael@0 | 57 | paramCount = ebp + 0x10 |
michael@0 | 58 | params = ebp + 0x14 |
michael@0 | 59 | |
michael@0 | 60 | */ |
michael@0 | 61 | |
michael@0 | 62 | __asm__ ( |
michael@0 | 63 | ".text\n\t" |
michael@0 | 64 | /* alignment here seems unimportant here; this was 16, now it's 2 which |
michael@0 | 65 | is what xptcstubs uses. */ |
michael@0 | 66 | ".align 2\n\t" |
michael@0 | 67 | ".globl _NS_InvokeByIndex\n\t" |
michael@0 | 68 | "_NS_InvokeByIndex:\n\t" |
michael@0 | 69 | "pushl %ebp\n\t" |
michael@0 | 70 | "movl %esp, %ebp\n\t" |
michael@0 | 71 | "movl 0x10(%ebp), %eax\n\t" |
michael@0 | 72 | "leal 0(,%eax,8),%edx\n\t" |
michael@0 | 73 | |
michael@0 | 74 | /* set up call frame for method. */ |
michael@0 | 75 | "subl %edx, %esp\n\t" /* make room for params. */ |
michael@0 | 76 | /* Align to maximum x86 data size: 128 bits == 16 bytes == XMM register size. |
michael@0 | 77 | * This is to avoid protection faults where SSE+ alignment of stack pointer |
michael@0 | 78 | * is assumed and required, e.g. by GCC4's -ftree-vectorize option. |
michael@0 | 79 | */ |
michael@0 | 80 | "andl $0xfffffff0, %esp\n\t" /* drop(?) stack ptr to 128-bit align */ |
michael@0 | 81 | /* $esp should be aligned to a 16-byte boundary here (note we include an |
michael@0 | 82 | * additional 4 bytes in a later push instruction). This will ensure $ebp |
michael@0 | 83 | * in the function called below is aligned to a 0x8 boundary. SSE instructions |
michael@0 | 84 | * like movapd/movdqa expect memory operand to be aligned on a 16-byte |
michael@0 | 85 | * boundary. The GCC compiler will generate the memory operand using $ebp |
michael@0 | 86 | * with an 8-byte offset. |
michael@0 | 87 | */ |
michael@0 | 88 | "subl $0xc, %esp\n\t" /* lower again; push/call below will re-align */ |
michael@0 | 89 | "movl %esp, %ecx\n\t" /* ecx = d */ |
michael@0 | 90 | "movl 8(%ebp), %edx\n\t" /* edx = this */ |
michael@0 | 91 | "pushl %edx\n\t" /* push this. esp % 16 == 0 */ |
michael@0 | 92 | |
michael@0 | 93 | "movl 0x14(%ebp), %edx\n\t" |
michael@0 | 94 | "call _invoke_copy_to_stack\n\t" |
michael@0 | 95 | "movl 0x08(%ebp), %ecx\n\t" /* 'that' */ |
michael@0 | 96 | "movl (%ecx), %edx\n\t" |
michael@0 | 97 | "movl 0x0c(%ebp), %eax\n\t" /* function index */ |
michael@0 | 98 | "leal (%edx,%eax,4), %edx\n\t" |
michael@0 | 99 | "call *(%edx)\n\t" |
michael@0 | 100 | "movl %ebp, %esp\n\t" |
michael@0 | 101 | "popl %ebp\n\t" |
michael@0 | 102 | "ret\n" |
michael@0 | 103 | ".section .drectve\n\t" |
michael@0 | 104 | ".ascii \" -export:NS_InvokeByIndex\"\n\t" |
michael@0 | 105 | ".text\n\t" |
michael@0 | 106 | ); |