syscall: Plan 9: use lightweight errstr in entersyscall mode

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
diff --git a/src/pkg/runtime/sys_plan9_amd64.s b/src/pkg/runtime/sys_plan9_amd64.s
index b34f98a..68563f3 100644
--- a/src/pkg/runtime/sys_plan9_amd64.s
+++ b/src/pkg/runtime/sys_plan9_amd64.s
@@ -206,3 +206,24 @@
 	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