]> Cypherpunks repositories - gostls13.git/commitdiff
runtime: move runtime.write back to C
authorRuss Cox <rsc@golang.org>
Fri, 9 Mar 2012 05:10:34 +0000 (00:10 -0500)
committerRuss Cox <rsc@golang.org>
Fri, 9 Mar 2012 05:10:34 +0000 (00:10 -0500)
It may have to switch stacks, since we are calling
a DLL instead of a system call.

badcallback says where it is, because it is being called
on a Windows stack already.

R=golang-dev, alex.brainman
CC=golang-dev
https://golang.org/cl/5782060

src/pkg/runtime/sys_windows_386.s
src/pkg/runtime/sys_windows_amd64.s
src/pkg/runtime/thread_windows.c

index c62715dbd715e2deb0b18405fefc1ed638857ddd..0c5ede4b72078c11fe25f4d23331c43e73eebc97 100644 (file)
@@ -38,33 +38,13 @@ TEXT runtime·asmstdcall(SB),7,$0
 
        RET
 
-TEXT   runtime·write(SB),7,$24
-       // write only writes to stderr; ignore fd
-       MOVL    $-12, 0(SP)
-       MOVL    SP, BP
-       CALL    *runtime·GetStdHandle(SB)
-       MOVL    BP, SP
-       
-       MOVL    AX, 0(SP)       // handle
-       MOVL    buf+4(FP), DX // pointer
-       MOVL    DX, 4(SP)
-       MOVL    count+8(FP), DX // count
-       MOVL    DX, 8(SP)
-       LEAL    20(SP), DX  // written count
-       MOVL    $0, 0(DX)
-       MOVL    DX, 12(SP)
-       MOVL    $0, 16(SP) // overlapped
-       CALL    *runtime·WriteFile(SB)
-       MOVL    BP, SI
-       RET
-
 TEXT   runtime·badcallback(SB),7,$24
-       // write only writes to stderr; ignore fd
+       // stderr
        MOVL    $-12, 0(SP)
        MOVL    SP, BP
        CALL    *runtime·GetStdHandle(SB)
        MOVL    BP, SP
-       
+
        MOVL    AX, 0(SP)       // handle
        MOVL    $runtime·badcallbackmsg(SB), DX // pointer
        MOVL    DX, 4(SP)
index 73dc542aac79a47bbaf9275ae9fef8d4d89c5cd7..c6a37c3453693cb6302099abb83929273862daca 100644 (file)
@@ -60,29 +60,8 @@ loadregs:
 
        RET
 
-TEXT runtime·write(SB),7,$48
-       // write only ever writes to stderr; ignore fd
-       MOVQ    $-12, CX // stderr
-       MOVQ    CX, 0(SP)
-       MOVQ    runtime·GetStdHandle(SB), AX
-       CALL    AX
-
-       MOVQ    AX, CX  // handle
-       MOVQ    CX, 0(SP)
-       MOVQ    buf+8(FP), DX // pointer
-       MOVQ    DX, 8(SP)
-       MOVL    count+16(FP), R8 // count
-       MOVQ    R8, 16(SP)
-       LEAQ    40(SP), R9  // written count
-       MOVQ    $0, 0(R9)
-       MOVQ    R9, 24(SP)
-       MOVQ    $0, 32(SP)      // overlapped
-       MOVQ    runtime·WriteFile(SB), AX
-       CALL    AX
-       
-       RET
-
 TEXT runtime·badcallback(SB),7,$48
+       // stderr
        MOVQ    $-12, CX // stderr
        MOVQ    CX, 0(SP)
        MOVQ    runtime·GetStdHandle(SB), AX
index 49beba5dc14b762cc24314d82f0dd33708da71a9..83d1edc32d4a52e88eecd0e2efde6861a415101f 100644 (file)
@@ -114,6 +114,27 @@ runtime·exit(int32 code)
        runtime·stdcall(runtime·ExitProcess, 1, (uintptr)code);
 }
 
+int32
+runtime·write(int32 fd, void *buf, int32 n)
+{
+       void *handle;
+       uint32 written;
+
+       written = 0;
+       switch(fd) {
+       case 1:
+               handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-11);
+               break;
+       case 2:
+               handle = runtime·stdcall(runtime·GetStdHandle, 1, (uintptr)-12);
+               break;
+       default:
+               return -1;
+       }
+       runtime·stdcall(runtime·WriteFile, 5, handle, buf, (uintptr)n, &written, (uintptr)0);
+       return written;
+}
+
 void
 runtime·osyield(void)
 {