]> Cypherpunks repositories - gostls13.git/commitdiff
syscall: Plan 9: use lightweight errstr in entersyscall mode
authorAkshat Kumar <seed@mail.nanosouffle.net>
Thu, 7 Mar 2013 23:54:44 +0000 (00:54 +0100)
committerRon Minnich <rminnich@gmail.com>
Thu, 7 Mar 2013 23:54:44 +0000 (00:54 +0100)
Change 231af8ac63aa (CL 7314062) made runtime.enteryscall()
set m->mcache = nil, which means that we can no longer use
syscall.errstr in syscall.Syscall and syscall.Syscall6, since it
requires a new buffer to be allocated for holding the error string.
Instead, we use pre-allocated per-M storage to hold error strings
from syscalls made while in entersyscall mode, and call
runtime.findnull to calculate the lengths.

Fixes #4994.

R=rsc, rminnich, ality, dvyukov, rminnich, r
CC=golang-dev
https://golang.org/cl/7567043

src/pkg/runtime/runtime.h
src/pkg/runtime/sys_plan9_386.s
src/pkg/runtime/sys_plan9_amd64.s
src/pkg/runtime/thread_plan9.c
src/pkg/syscall/asm_plan9_386.s
src/pkg/syscall/asm_plan9_amd64.s

index e44064f1ae8fecaca31c4e9317bfd7a992dbde25..66bcf603bd58b2f324abef6342816d70b4f0d3c6 100644 (file)
@@ -320,6 +320,7 @@ struct      M
 #endif
 #ifdef GOOS_plan9
        int8*           notesig;
+       byte*   errstr;
 #endif
        SEH*    seh;
        uintptr end[];
index 3385b083a12f3b52001bb4d68ca3732484fc4351..09211e8807fc6646217bca6e51771a37e0b75a33 100644 (file)
@@ -170,3 +170,23 @@ TEXT runtime·sigtramp(SB),7,$0
 // Only used by the 64-bit runtime.
 TEXT runtime·setfpmasks(SB),7,$0
        RET
+
+#define ERRMAX 128     /* from os_plan9.h */
+
+// func errstr() String
+// Only used by package syscall.
+// Grab error string due to a syscall made
+// in entersyscall mode, without going
+// through the allocator (issue 4994).
+// See ../syscall/asm_plan9_386.s:/·Syscall/
+TEXT runtime·errstr(SB),7,$0
+       get_tls(AX)
+       MOVL    m(AX), BX
+       MOVL    m_errstr(BX), CX
+       MOVL    CX, 4(SP)
+       MOVL    $ERRMAX, 8(SP)
+       MOVL    $41, AX
+       INT     $64
+       CALL    runtime·findnull(SB)
+       MOVL    AX, 8(SP)
+       RET
index b34f98a6855f9081d49d3ebc63871ee0851b0d67..68563f3e3ca2ede31048d9eaed7adb5d5e6c2578 100644 (file)
@@ -206,3 +206,24 @@ TEXT runtime·setfpmasks(SB),7,$8
        MOVL    AX, 0(SP)
        LDMXCSR 0(SP)
        RET
+
+#define ERRMAX 128     /* from os_plan9.h */
+
+// func errstr() String
+// Only used by package syscall.
+// Grab error string due to a syscall made
+// in entersyscall mode, without going
+// through the allocator (issue 4994).
+// See ../syscall/asm_plan9_386.s:/·Syscall/
+TEXT runtime·errstr(SB),7,$0
+       get_tls(AX)
+       MOVQ    m(AX), BX
+       MOVQ    m_errstr(BX), CX
+       MOVQ    CX, 8(SP)
+       MOVQ    $ERRMAX, 16(SP)
+       MOVQ    $0x8000, AX
+       MOVQ    $41, BP
+       SYSCALL
+       CALL    runtime·findnull(SB)
+       MOVQ    AX, 16(SP)
+       RET
index 7f94623e7bb4022fbf79204b3c1bcae19ae9fff9..524dbf69254fd454d6671ba77e3840907d97c5f3 100644 (file)
@@ -19,6 +19,10 @@ runtime·mpreinit(M *mp)
        // Initialize stack and goroutine for note handling.
        mp->gsignal = runtime·malg(32*1024);
        mp->notesig = (int8*)runtime·malloc(ERRMAX*sizeof(int8));
+
+       // Initialize stack for handling strings from the
+       // errstr system call, as used in package syscall.
+       mp->errstr = (byte*)runtime·malloc(ERRMAX*sizeof(byte));
 }
 
 // Called to initialize a new m (including the bootstrap m).
index 2ba13760812454e6b5e27e0b3590ff6f90b65519..0ae20f5682530082b1cd08e8c3bb1527aef4f6d0 100644 (file)
@@ -29,7 +29,7 @@ TEXT  ·Syscall(SB),7,$0
        JNE     ok3
 
        SUBL    $8, SP
-       CALL    syscall·errstr(SB)
+       CALL    runtime·errstr(SB)
        MOVL    SP, SI
        ADDL    $8, SP
        JMP     copyresult3
@@ -67,7 +67,7 @@ TEXT  ·Syscall6(SB),7,$0
        JNE     ok4
        
        SUBL    $8, SP
-       CALL    syscall·errstr(SB)
+       CALL    runtime·errstr(SB)
        MOVL    SP, SI
        ADDL    $8, SP
        JMP     copyresult4
index e363b743c1e6568e1b300f6731d4e7d4c5830ea8..40cc12642067fe0869ccf42859d3cc4b5490b54b 100644 (file)
@@ -32,7 +32,7 @@ TEXT  ·Syscall(SB),7,$0
        JNE     ok3
 
        SUBQ    $16, SP
-       CALL    syscall·errstr(SB)
+       CALL    runtime·errstr(SB)
        MOVQ    SP, SI
        ADDQ    $16, SP
        JMP     copyresult3
@@ -71,7 +71,7 @@ TEXT  ·Syscall6(SB),7,$0
        JNE     ok4
        
        SUBQ    $16, SP
-       CALL    syscall·errstr(SB)
+       CALL    runtime·errstr(SB)
        MOVQ    SP, SI
        ADDQ    $16, SP
        JMP     copyresult4