331827 Runtime crash due to xptcall not aligning stack when running on Mac OS X with gtk2. Align stack in xptcall for all $(OS_ARCH) == "Darwin". r=josh sr=shaver

This commit is contained in:
mark%moxienet.com 2006-03-28 20:03:50 +00:00
parent db71fd8af2
commit 4177a92379
3 changed files with 34 additions and 34 deletions

View File

@ -65,6 +65,9 @@ include $(topsrcdir)/config/config.mk
ifneq (,$(filter FreeBSD NetBSD OpenBSD BSD_OS Darwin,$(OS_ARCH)))
ifeq (86,$(findstring 86,$(OS_TEST)))
CPPSRCS := xptcinvoke_unixish_x86.cpp xptcstubs_unixish_x86.cpp
ifeq (Darwin,$(OS_ARCH))
DEFINES += -DKEEP_STACK_16_BYTE_ALIGNED
endif
endif
endif
#

View File

@ -159,11 +159,3 @@
#if defined(THUNK_BASED_THIS_ADJUST) && defined(CFRONT_STYLE_THIS_ADJUST)
#error "need to define only ONE 'this' adjust scheme"
#endif
/* Define KEEP_STACK_16_BYTE_ALIGNED if the stack needs to maintain alignment
* in a CALL for some good reason (like ABI compliance). */
#ifdef XP_MACOSX
/* http://developer.apple.com/documentation/DeveloperTools/Conceptual/LowLevelABI/Articles/IA32.html */
#define KEEP_STACK_16_BYTE_ALIGNED
#endif

View File

@ -104,34 +104,38 @@ PrepareAndDispatch(nsXPTCStubBase* self, uint32 methodIndex, PRUint32* args)
#ifdef __GNUC__ /* Gnu Compiler. */
#ifdef XP_MACOSX
#ifdef KEEP_STACK_16_BYTE_ALIGNED
/* Make sure the stack is 16-byte aligned. Do that by aligning to 16 bytes and
* then subtracting 4 so the three subsequent pushes result in a 16-byte aligned
* stack. */
#define ALIGN_STACK \
"addl $0x4, %%esp\n\t" \
"andl $0xfffffff0, %%esp\n\t" \
"subl $0x4, %%esp\n\t"
#define ALIGN_STACK_DECL \
unsigned int saved_esp;
#define REGS_TRASHED \
, "%esp"
#define ALIGN_STACK_SAVE \
"movl %%esp, %3\n\t"
#define SAVE_STACK \
unsigned int saved_esp; \
__asm__ __volatile__( \
"movl %%esp, %0\n\t" \
: "=r"(saved_esp));
#define ALIGN_STACK_ALIGN \
"addl $0x4, %%esp\n\t" \
"andl $0xfffffff0, %%esp\n\t" \
"subl $0x4, %%esp\n\t"
#define STACK_RESTORE \
"movl %3, %%esp\n"
#define ALIGN_STACK_REGS_IN \
, "=r"(saved_esp) /* 3 */
#define ALIGN_STACK_REGS_OUT \
, "3"(saved_esp)
#define RESTORE_STACK \
__asm__ __volatile__( \
"movl %0, %%esp\n\t" \
: \
: "r"(saved_esp));
#else
#define ALIGN_STACK
#define REGS_TRASHED
#define SAVE_STACK
#define RESTORE_STACK
#define ALIGN_STACK_DECL
#define ALIGN_STACK_SAVE
#define ALIGN_STACK_ALIGN
#define STACK_RESTORE \
"addl $12, %%esp\n"
#define ALIGN_STACK_REGS_IN
#define ALIGN_STACK_REGS_OUT
#endif
#define STUB_ENTRY(n) \
@ -140,24 +144,25 @@ nsresult nsXPTCStubBase::Stub##n() \
register nsresult (*method) (nsXPTCStubBase *, uint32, PRUint32 *) = PrepareAndDispatch; \
int temp0, temp1; \
register nsresult result; \
SAVE_STACK \
ALIGN_STACK_DECL \
__asm__ __volatile__( \
ALIGN_STACK \
ALIGN_STACK_SAVE \
ALIGN_STACK_ALIGN \
"leal 0x0c(%%ebp), %%ecx\n\t" /* args */ \
"pushl %%ecx\n\t" \
"pushl $"#n"\n\t" /* method index */ \
"movl 0x08(%%ebp), %%ecx\n\t" /* this */ \
"pushl %%ecx\n\t" \
"call *%%edx\n\t" /* PrepareAndDispatch */ \
"addl $12, %%esp" \
STACK_RESTORE /* "addl $12, %%esp" or restore saved */ \
: "=a" (result), /* %0 */ \
"=&c" (temp0), /* %1 */ \
"=d" (temp1) /* %2 */ \
ALIGN_STACK_REGS_IN \
: "2" (method) /* %2 */ \
ALIGN_STACK_REGS_OUT \
: "memory" \
REGS_TRASHED \
); \
RESTORE_STACK \
return result; \
}