Tcl Source Code

Artifact [7c4faf2ae3]
Login

Artifact 7c4faf2ae35a548bcf0ef16feebabc0136881c80:

Attachment "kai.patch" to ticket [1910041fff] added by ktietz70 2008-03-08 19:10:56.
Index: tclWinChan.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinChan.c,v
retrieving revision 1.49
diff -u -r1.49 tclWinChan.c
--- tclWinChan.c        16 Apr 2007 13:36:36 -0000      1.49
+++ tclWinChan.c        8 Mar 2008 11:46:55 -0000
@@ -1106,6 +1106,7 @@
         * illegal for one asm block to contain a jump to another.
         */

+#ifndef _WIN64
        __asm__ __volatile__ (

            /*
@@ -1178,6 +1179,83 @@
            :
            "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi", "memory"
            );
+#else
+       __asm__ __volatile__ (
+
+           /*
+            * Pick up parameters before messing with the stack
+            */
+
+           "movq       %[dupedHandle], %%rbx"          "\n\t"
+
+           /*
+            * Construct an EXCEPTION_REGISTRATION to protect the call to
+            * CloseHandle.
+            */
+
+           "leaq       %[registration], %%rdx"         "\n\t"
+           "movq       %%gs:0,         %%rax"          "\n\t"
+           "movq       %%rax,          0x0(%%edx)"     "\n\t" /* link */
+           "leaq       1f,             %%rax"          "\n\t"
+           "movq       %%rax,          0x8(%%rdx)"     "\n\t" /* handler */
+           "movq       %%rbp,          0x10(%%rdx)"     "\n\t" /* ebp */
+           "movq       %%rsp,          0x18(%%rdx)"     "\n\t" /* esp */
+           "movl       $0,             0x20(%%rdx)"    "\n\t" /* status */
+
+           /*
+            * Link the EXCEPTION_REGISTRATION on the chain.
+            */
+
+           "movq       %%rdx,          %%gs:0"         "\n\t"
+
+           /*
+            * Call CloseHandle(dupedHandle).
+            */
+
+           "pushq      %%rbx"                        "\n\t"
+           "movq       %%rbx,%%rcx"                  "\n\t"
+           "call       _CloseHandle"                 "\n\t"
+           "addq       $8, %%rsp"                    "\n\t"
+
+
+           /*
+            * Come here on normal exit. Recover the EXCEPTION_REGISTRATION
+            * and put a TRUE status return into it.
+            */
+
+           "movq       %%gs:0,         %%rdx"          "\n\t"
+           "movl       $1,             %%eax"          "\n\t"
+           "movl       %%eax,          0x20(%%rdx)"    "\n\t"
+           "jmp        2f"                             "\n"
+
+           /*
+            * Come here on an exception. Recover the EXCEPTION_REGISTRATION
+            */
+
+           "1:"                                        "\t"
+           "movq       %%gs:0,         %%rdx"          "\n\t"
+           "movq       0x10(%%rdx),     %%rdx"          "\n\t"
+
+           /*
+            * Come here however we exited. Restore context from the
+            * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+            */
+
+           "2:"                                        "\t"
+           "movq       0x18(%%rdx),     %%rsp"          "\n\t"
+           "movq       0x10(%%rdx),     %%rbp"          "\n\t"
+           "movq       0x0(%%rdx),     %%rax"          "\n\t"
+           "movq       %%rax,          %%gs:0"         "\n\t"
+
+           :
+           /* No outputs */
+           :
+           [registration]  "m"     (registration),
+           [dupedHandle]   "m"     (dupedHandle)
+           :
+           "%rax", "%rbx", "%rcx", "%rdx", "%rsi", "%rdi", "memory"
+           );
+#endif
        result = registration.status;

 #endif
Index: tclWinFCmd.c
===================================================================
RCS file: /cvsroot/tcl/tcl/win/tclWinFCmd.c,v
retrieving revision 1.52
diff -u -r1.52 tclWinFCmd.c
--- tclWinFCmd.c        29 Aug 2006 00:36:57 -0000      1.52
+++ tclWinFCmd.c        8 Mar 2008 11:46:56 -0000
@@ -213,6 +213,7 @@
      * for one asm block to contain a jump to another.
      */

+#ifndef _WIN64
     __asm__ __volatile__ (
        /*
         * Pick up params before messing with the stack.
@@ -288,6 +289,85 @@
        :
        "%eax", "%ebx", "%ecx", "%edx", "memory"
        );
+#else
+    __asm__ __volatile__ (
+       /*
+        * Pick up params before messing with the stack.
+        */
+
+       "movq       %[nativeDst],   %%rbx"          "\n\t"
+       "movq       %[nativeSrc],   %%rcx"          "\n\t"
+
+       /*
+        * Construct an EXCEPTION_REGISTRATION to protect the call to
+        * MoveFile.
+        */
+
+       "leaq       %[registration], %%rdx"         "\n\t"
+       "movq       %%gs:0,         %%rax"          "\n\t"
+       "movq       %%rax,          0x0(%%rdx)"     "\n\t" /* link */
+       "leaq       1f,             %%rax"          "\n\t"
+       "movq       %%rax,          0x8(%%rdx)"     "\n\t" /* handler */
+       "movq       %%rbp,          0x10(%%rdx)"            "\n\t" /* ebp */
+       "movq       %%rsp,          0x18(%%rdx)"            "\n\t" /* esp */
+       "movl       $0,             0x20(%%rdx)"    "\n\t" /* status */
+
+       /*
+        * Link the EXCEPTION_REGISTRATION on the chain.
+        */
+
+       "movq       %%rdx,          %%gs:0"         "\n\t"
+
+       /*
+        * Call MoveFile(nativeSrc, nativeDst)
+        */
+
+       "pushq      %%rbx"                          "\n\t"
+       "pushq      %%rcx"                          "\n\t"
+       "movq           %%rbx, %%rdx"               "\n\t"
+       "movq       %[moveFile],    %%rax"          "\n\t"
+       "call       *%%rax"                         "\n\t"
+       "addq       $16, %%rsp"                     "\n\t"
+
+       /*
+        * Come here on normal exit. Recover the EXCEPTION_REGISTRATION and
+        * put the status return from MoveFile into it.
+        */
+
+       "movq       %%gs:0,         %%rdx"          "\n\t"
+       "movl       %%eax,          0x20(%%rdx)"    "\n\t"
+       "jmp        2f"                             "\n"
+
+       /*
+        * Come here on an exception. Recover the EXCEPTION_REGISTRATION
+        */
+
+       "1:"                                        "\t"
+       "movq       %%gs:0,         %%rdx"          "\n\t"
+       "movq       0x10(%%rdx),            %%rdx"          "\n\t"
+
+       /*
+        * Come here however we exited. Restore context from the
+        * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+        */
+
+       "2:"                                        "\t"
+       "movq       0x18(%%rdx),            %%rsp"          "\n\t"
+       "movq       0x10(%%rdx),            %%rbp"          "\n\t"
+       "movq       0x0(%%rdx),     %%rax"          "\n\t"
+       "movq       %%rax,          %%gs:0"         "\n\t"
+
+       :
+       /* No outputs */
+       :
+       [registration]  "m"     (registration),
+       [nativeDst]     "m"     (nativeDst),
+       [nativeSrc]     "m"     (nativeSrc),
+       [moveFile]      "r"     (tclWinProcs->moveFileProc)
+       :
+       "%rax", "%rbx", "%rcx", "%rdx", "memory"
+       );
+#endif
     if (registration.status != FALSE) {
        retval = TCL_OK;
     }
@@ -601,6 +681,7 @@
      * for one asm block to contain a jump to another.
      */

+#ifndef _WIN64
     __asm__ __volatile__ (

        /*
@@ -678,6 +759,88 @@
        :
        "%eax", "%ebx", "%ecx", "%edx", "memory"
        );
+#else
+    __asm__ __volatile__ (
+
+       /*
+        * Pick up parameters before messing with the stack
+        */
+
+       "movq       %[nativeDst],   %%rbx"          "\n\t"
+       "movq       %[nativeSrc],   %%rcx"          "\n\t"
+
+       /*
+        * Construct an EXCEPTION_REGISTRATION to protect the call to
+        * CopyFile.
+        */
+
+       "leaq       %[registration], %%rdx"         "\n\t"
+       "movq       %%gs:0,         %%rax"          "\n\t"
+       "movq       %%rax,          0x0(%%rdx)"     "\n\t" /* link */
+       "leaq       1f,             %%rax"          "\n\t"
+       "movq       %%rax,          0x8(%%rdx)"     "\n\t" /* handler */
+       "movq       %%rbp,          0x10(%%rdx)"            "\n\t" /* ebp */
+       "movq       %%rsp,          0x18(%%rdx)"            "\n\t" /* esp */
+       "movl       $0,         0x20(%%rdx)"    "\n\t" /* status */
+
+       /*
+        * Link the EXCEPTION_REGISTRATION on the chain.
+        */
+
+       "movq       %%rdx,          %%gs:0"         "\n\t"
+
+       /*
+        * Call CopyFile(nativeSrc, nativeDst, 0)
+        */
+
+       "movq       %[copyFile],    %%rax"          "\n\t"
+       "pushq      $0"                             "\n\t"
+       "pushq      %%rbx"                          "\n\t"
+       "pushq      %%rcx"                          "\n\t"
+       "movq           %%rbx, %%rdx"               "\n\t"
+       "subq           %%r8, %%r8"                 "\n\t"
+       "call       *%%rax"                         "\n\t"
+       "addq           $24, %%rsp"                 "\n\t"
+
+       /*
+        * Come here on normal exit. Recover the EXCEPTION_REGISTRATION and
+        * put the status return from CopyFile into it.
+        */
+
+       "movq       %%gs:0,         %%rdx"          "\n\t"
+       "movl       %%eax,          0x20(%%rdx)"    "\n\t"
+       "jmp        2f"                             "\n"
+
+       /*
+        * Come here on an exception. Recover the EXCEPTION_REGISTRATION
+        */
+
+       "1:"                                        "\t"
+       "movq       %%gs:0,         %%rdx"          "\n\t"
+       "movq       0x10(%%rdx),            %%rdx"          "\n\t"
+
+       /*
+        * Come here however we exited. Restore context from the
+        * EXCEPTION_REGISTRATION in case the stack is unbalanced.
+        */
+
+       "2:"                                        "\t"
+       "movq       0x18(%%rdx),            %%rsp"          "\n\t"
+       "movq       0x10(%%rdx),            %%rbp"          "\n\t"
+       "movq       0x0(%%rdx),     %%rax"          "\n\t"
+       "movq       %%rax,          %%gs:0"         "\n\t"
+
+       :
+       /* No outputs */
+       :
+       [registration]  "m"     (registration),
+       [nativeDst]     "m"     (nativeDst),
+       [nativeSrc]     "m"     (nativeSrc),
+       [copyFile]      "r"     (tclWinProcs->copyFileProc)
+       :
+       "%rax", "%rbx", "%rcx", "%rdx", "r8", "memory"
+       );
+#endif
     if (registration.status != FALSE) {
        retval = TCL_OK;
     }