]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Replace the obviously-bogus piece of inline asm with a probably
authorJulian Seward <jseward@acm.org>
Fri, 26 May 2006 11:31:15 +0000 (11:31 +0000)
committerJulian Seward <jseward@acm.org>
Fri, 26 May 2006 11:31:15 +0000 (11:31 +0000)
equally bogus new version.  In fact if I actually understood the
magical "earlyclobber" (&) asm constraint this would probably be
unnecessary, but I don't.  Ah well.

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

coregrind/m_debuglog.c

index 735d0f34650c8419c11fda2f9573f4867c3f1255..5838911f6b62be89e396cd088ff03480288b6a79 100644 (file)
@@ -98,23 +98,33 @@ static UInt local_sys_getpid ( void )
 }
 
 #elif defined(VGP_amd64_linux)
-
+__attribute__((noinline))
 static UInt local_sys_write_stderr ( HChar* buf, Int n )
 {
-   UInt __res;
+   Long block[2];
+   block[0] = (Long)buf;
+   block[1] = n;
    __asm__ volatile (
-      "movq $1, %%rax\n"   /* set %rax = __NR_write */
-      "movq $2, %%rdi\n"   /* set %rdi = stderr */
-      "movq %1, %%rsi\n"   /* set %rsi = buf */
-      "movl %2, %%edx\n"   /* set %edx = n */
-      "syscall\n"          /* write(stderr, buf, n) */
-      "movl %%eax, %0\n"   /* set __res = %eax */
-      : "=mr" (__res)
-      : "g" (buf), "g" (n)
-      : "rax", "rdi", "rsi", "rdx" );
-   if (__res < 0) 
-      __res = -1;
-   return __res;
+      "subq  $256, %%rsp\n"     /* don't trash the stack redzone */
+      "pushq %%r15\n"           /* r15 is callee-save */
+      "movq  %0, %%r15\n"       /* r15 = &block */
+      "pushq %%r15\n"           /* save &block */
+      "movq  $1, %%rax\n"       /* rax = __NR_write */
+      "movq  $2, %%rdi\n"       /* rdi = stderr */
+      "movq  0(%%r15), %%rsi\n" /* rsi = buf */
+      "movq  8(%%r15), %%rdx\n" /* rdx = n */
+      "syscall\n"               /* write(stderr, buf, n) */
+      "popq  %%r15\n"           /* reestablish &block */
+      "movq  %%rax, 0(%%r15)\n" /* block[0] = result */
+      "popq  %%r15\n"           /* restore r15 */
+      "addq  $256, %%rsp\n"     /* restore stack ptr */
+      : /*wr*/
+      : /*rd*/    "g" (block)
+      : /*trash*/ "rax", "rdi", "rsi", "rdx", "memory", "cc"
+   );
+   if (block[0] < 0) 
+      block[0] = -1;
+   return (UInt)block[0];
 }
 
 static UInt local_sys_getpid ( void )