From cc01e8ff05d2461d7bd9c14281057254429518c0 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Wed, 23 Nov 2005 19:55:06 +0100 Subject: [PATCH] Preserve 16-byte stack alignment in the various assembly functions. Needed for MacOSX. --- dlls/kernel/relay16.c | 21 +++++++++++++++------ dlls/msvcrt/misc.c | 3 ++- dlls/ntdll/loader.c | 1 + dlls/ntdll/relay.c | 21 +++++++++++++++------ dlls/ntdll/resource.c | 21 +++++++++++---------- dlls/ntdll/signal_i386.c | 2 ++ dlls/user/winproc.c | 1 + libs/wine/port.c | 2 ++ loader/preloader.c | 2 +- tools/winebuild/import.c | 1 + 10 files changed, 51 insertions(+), 24 deletions(-) diff --git a/dlls/kernel/relay16.c b/dlls/kernel/relay16.c index ff229000461..1ba36a518fb 100644 --- a/dlls/kernel/relay16.c +++ b/dlls/kernel/relay16.c @@ -285,14 +285,23 @@ extern int call_entry_point( void *func, int nb_args, const int *args ); __ASM_GLOBAL_FUNC( call_entry_point, "\tpushl %ebp\n" "\tmovl %esp,%ebp\n" + "\tpushl %esi\n" + "\tpushl %edi\n" + "\tmovl 12(%ebp),%edx\n" + "\tshll $2,%edx\n" + "\tjz 1f\n" + "\tsubl %edx,%esp\n" + "\tandl $~15,%esp\n" "\tmovl 12(%ebp),%ecx\n" - "\tmovl 16(%ebp),%edx\n" - "\tjecxz 1f\n" - "2:\tpushl -4(%edx,%ecx,4)\n" - "\tloop 2b\n" + "\tmovl 16(%ebp),%esi\n" + "\tmovl %esp,%edi\n" + "\tcld\n" + "\trep; movsl\n" "1:\tcall *8(%ebp)\n" - "\tmovl %ebp,%esp\n" - "\tleave\n" + "\tleal -8(%ebp),%esp\n" + "\tpopl %edi\n" + "\tpopl %esi\n" + "\tpopl %ebp\n" "\tret" ); diff --git a/dlls/msvcrt/misc.c b/dlls/msvcrt/misc.c index fd7e0a38790..83f798dcda3 100644 --- a/dlls/msvcrt/misc.c +++ b/dlls/msvcrt/misc.c @@ -125,6 +125,7 @@ __ASM_GLOBAL_FUNC(_chkesp, "ret\n" "1:\tpushl %ebp\n\t" "movl %esp,%ebp\n\t" + "subl $12,%esp\n\t" "pushl %eax\n\t" "pushl %ecx\n\t" "pushl %edx\n\t" @@ -132,7 +133,7 @@ __ASM_GLOBAL_FUNC(_chkesp, "popl %edx\n\t" "popl %ecx\n\t" "popl %eax\n\t" - "popl %ebp\n\t" + "leave\n\t" "ret"); void MSVCRT_chkesp_fail(void) diff --git a/dlls/ntdll/loader.c b/dlls/ntdll/loader.c index ee951dd848c..6deaad5c92e 100644 --- a/dlls/ntdll/loader.c +++ b/dlls/ntdll/loader.c @@ -144,6 +144,7 @@ __ASM_GLOBAL_FUNC(call_dll_entry_point, "pushl %ebp\n\t" "movl %esp,%ebp\n\t" "pushl %ebx\n\t" + "subl $8,%esp\n\t" "pushl 20(%ebp)\n\t" "pushl 16(%ebp)\n\t" "pushl 12(%ebp)\n\t" diff --git a/dlls/ntdll/relay.c b/dlls/ntdll/relay.c index 2130c190c47..32da763142e 100644 --- a/dlls/ntdll/relay.c +++ b/dlls/ntdll/relay.c @@ -451,14 +451,23 @@ extern LONGLONG call_entry_point( void *func, int nb_args, const int *args ); __ASM_GLOBAL_FUNC( call_entry_point, "\tpushl %ebp\n" "\tmovl %esp,%ebp\n" + "\tpushl %esi\n" + "\tpushl %edi\n" + "\tmovl 12(%ebp),%edx\n" + "\tshll $2,%edx\n" + "\tjz 1f\n" + "\tsubl %edx,%esp\n" + "\tandl $~15,%esp\n" "\tmovl 12(%ebp),%ecx\n" - "\tmovl 16(%ebp),%edx\n" - "\tjecxz 1f\n" - "2:\tpushl -4(%edx,%ecx,4)\n" - "\tloop 2b\n" + "\tmovl 16(%ebp),%esi\n" + "\tmovl %esp,%edi\n" + "\tcld\n" + "\trep; movsl\n" "1:\tcall *8(%ebp)\n" - "\tmovl %ebp,%esp\n" - "\tleave\n" + "\tleal -8(%ebp),%esp\n" + "\tpopl %edi\n" + "\tpopl %esi\n" + "\tpopl %ebp\n" "\tret" ); diff --git a/dlls/ntdll/resource.c b/dlls/ntdll/resource.c index 9cdad3b7009..056ab0d91ce 100644 --- a/dlls/ntdll/resource.c +++ b/dlls/ntdll/resource.c @@ -364,16 +364,17 @@ static inline NTSTATUS access_resource( HMODULE hmod, const IMAGE_RESOURCE_DATA_ #ifdef __i386__ /* Shrinker depends on the "call access_resource" instruction being there */ __ASM_GLOBAL_FUNC( LdrAccessResource, - "pushl %ebp\n" - "movl %esp, %ebp\n" - "pushl 24(%ebp)\n" - "pushl 20(%ebp)\n" - "pushl 16(%ebp)\n" - "pushl 12(%ebp)\n" - "pushl 8(%ebp)\n" - "call " __ASM_NAME("access_resource") "\n" - "leave\n" - "ret $16\n" + "pushl %ebp\n\t" + "movl %esp, %ebp\n\t" + "subl $4,%esp\n\t" + "pushl 24(%ebp)\n\t" + "pushl 20(%ebp)\n\t" + "pushl 16(%ebp)\n\t" + "pushl 12(%ebp)\n\t" + "pushl 8(%ebp)\n\t" + "call " __ASM_NAME("access_resource") "\n\t" + "leave\n\t" + "ret $16" ); #else NTSTATUS WINAPI LdrAccessResource( HMODULE hmod, const IMAGE_RESOURCE_DATA_ENTRY *entry, diff --git a/dlls/ntdll/signal_i386.c b/dlls/ntdll/signal_i386.c index e4ab3fef1dc..3cc54af1817 100644 --- a/dlls/ntdll/signal_i386.c +++ b/dlls/ntdll/signal_i386.c @@ -1450,6 +1450,7 @@ __ASM_GLOBAL_FUNC( DbgUserBreakPoint, "int $3; ret"); __ASM_GLOBAL_FUNC( EXC_CallHandler, " pushl %ebp\n" " movl %esp, %ebp\n" +" subl $4,%esp\n" " movl 28(%ebp), %edx\n" /* ugly hack to pass the 6th param needed because of Shrinker */ " pushl 24(%ebp)\n" " pushl 20(%ebp)\n" @@ -1463,6 +1464,7 @@ __ASM_GLOBAL_FUNC( EXC_CallHandler, __ASM_GLOBAL_FUNC(call_exception_handler, " pushl %ebp\n" " movl %esp, %ebp\n" +" subl $12,%esp\n" " pushl 12(%ebp)\n" /* make any exceptions in this... */ " pushl %edx\n" /* handler be handled by... */ " .byte 0x64\n" diff --git a/dlls/user/winproc.c b/dlls/user/winproc.c index f283856599e..ff5ceaf72cd 100644 --- a/dlls/user/winproc.c +++ b/dlls/user/winproc.c @@ -270,6 +270,7 @@ __ASM_GLOBAL_FUNC( WINPROC_wrapper, "pushl %edi\n\t" "pushl %esi\n\t" "pushl %ebx\n\t" + "subl $12,%esp\n\t" "pushl 24(%ebp)\n\t" "pushl 20(%ebp)\n\t" "pushl 16(%ebp)\n\t" diff --git a/libs/wine/port.c b/libs/wine/port.c index 234f1461c62..c6827376ff7 100644 --- a/libs/wine/port.c +++ b/libs/wine/port.c @@ -59,6 +59,8 @@ __ASM_GLOBAL_FUNC( wine_switch_to_stack, "movl 4(%esp),%ecx\n\t" /* func */ "movl 8(%esp),%edx\n\t" /* arg */ "movl 12(%esp),%esp\n\t" /* stack */ + "andl $~15,%esp\n\t" + "subl $12,%esp\n\t" "pushl %edx\n\t" "xorl %ebp,%ebp\n\t" "call *%ecx\n\t" diff --git a/loader/preloader.c b/loader/preloader.c index f2898b2df0c..f4343a79520 100644 --- a/loader/preloader.c +++ b/loader/preloader.c @@ -166,7 +166,7 @@ void _start(); extern char _end[]; __ASM_GLOBAL_FUNC(_start, "\tmovl %esp,%eax\n" - "\tleal -128(%esp),%esp\n" /* allocate some space for extra aux values */ + "\tleal -136(%esp),%esp\n" /* allocate some space for extra aux values */ "\tpushl %eax\n" /* orig stack pointer */ "\tpushl %esp\n" /* ptr to orig stack pointer */ "\tcall wld_start\n" diff --git a/tools/winebuild/import.c b/tools/winebuild/import.c index 6a2f8f512e5..c90bb7b1f4b 100644 --- a/tools/winebuild/import.c +++ b/tools/winebuild/import.c @@ -1186,6 +1186,7 @@ void output_stubs( FILE *outfile, DLLSPEC *spec ) fprintf( outfile, "\t.align %d\n", get_alignment(4) ); fprintf( outfile, "\t%s\n", func_declaration(name) ); fprintf( outfile, "%s:\n", asm_name(name) ); + fprintf( outfile, "\tsubl $4,%%esp\n" ); if (UsePIC) {