]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Bug 368120 - x86_linux asm _start functions do not keep 16-byte
authorJulian Seward <jseward@acm.org>
Wed, 19 Oct 2016 06:00:32 +0000 (06:00 +0000)
committerJulian Seward <jseward@acm.org>
Wed, 19 Oct 2016 06:00:32 +0000 (06:00 +0000)
aligned stack pointer.  Patch from chh@google.com.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@16075

coregrind/m_main.c
coregrind/m_syswrap/syswrap-x86-linux.c

index bb9f33b00886776d18662f4925ebfd53ca026d1f..1a327c1bcce4f0a1fd0b1a586b90bee5c9dfd643 100644 (file)
@@ -2985,12 +2985,13 @@ asm("\n"
     "\tmovl  $vgPlain_interim_stack, %eax\n"
     "\taddl  $"VG_STRINGIFY(VG_STACK_GUARD_SZB)", %eax\n"
     "\taddl  $"VG_STRINGIFY(VG_DEFAULT_STACK_ACTIVE_SZB)", %eax\n"
+    /* allocate at least 16 bytes on the new stack, and aligned */
     "\tsubl  $16, %eax\n"
     "\tandl  $~15, %eax\n"
     /* install it, and collect the original one */
     "\txchgl %eax, %esp\n"
     /* call _start_in_C_linux, passing it the startup %esp */
-    "\tpushl %eax\n"
+    "\tmovl  %eax, (%esp)\n" 
     "\tcall  _start_in_C_linux\n"
     "\thlt\n"
     ".previous\n"
index 5bdf4c7d4b5160002075c8bb5d7de6e4939efc9c..0e5af9830fbf5b44014a70859aa693fca5391760 100644 (file)
@@ -83,8 +83,9 @@ asm(
 ".globl vgModuleLocal_call_on_new_stack_0_1\n"
 "vgModuleLocal_call_on_new_stack_0_1:\n"
 "   movl %esp, %esi\n"     // remember old stack pointer
-"   movl 4(%esi), %esp\n"  // set stack
-"   pushl 16(%esi)\n"      // arg1 to stack
+"   movl 4(%esi), %esp\n"  // set stack, assume %esp is now 16-byte aligned
+"   subl $12, %esp\n"      // skip 12 bytes
+"   pushl 16(%esi)\n"      // arg1 to stack, %esp is 16-byte aligned
 "   pushl  8(%esi)\n"      // retaddr to stack
 "   pushl 12(%esi)\n"      // f to stack
 "   movl $0, %eax\n"       // zero all GP regs
@@ -150,7 +151,8 @@ asm(
 "        movl     4+"FSZ"(%esp), %ecx\n"    /* syscall arg2: child stack */
 "        movl    12+"FSZ"(%esp), %ebx\n"    /* fn arg */
 "        movl     0+"FSZ"(%esp), %eax\n"    /* fn */
-"        lea     -8(%ecx), %ecx\n"          /* make space on stack */
+"        andl    $-16, %ecx\n"              /* align to 16-byte */
+"        lea     -20(%ecx), %ecx\n"         /* allocate 16*n+4 bytes on stack */
 "        movl    %ebx, 4(%ecx)\n"           /*   fn arg */
 "        movl    %eax, 0(%ecx)\n"           /*   fn */
 
@@ -165,7 +167,7 @@ asm(
 "        jnz     1f\n"
 
          /* CHILD - call thread function */
-"        popl    %eax\n"
+"        popl    %eax\n"                    /* child %esp is 16-byte aligned */
 "        call    *%eax\n"                   /* call fn */
 
          /* exit with result */