diff options
author | Ian Lance Taylor <iant@golang.org> | 2019-04-05 11:42:37 -0700 |
---|---|---|
committer | Ian Lance Taylor <iant@golang.org> | 2019-10-21 14:07:34 +0000 |
commit | b653c878b1ad8d1b4f8d7b04201d0cb0a4156ead (patch) | |
tree | 3f4189ae0a4f5c61ae8fc0badf402d2016533289 /src/runtime/crash_unix_test.go | |
parent | 6917b3c839af615e22ef479b23983d186e578bd6 (diff) | |
download | go-b653c878b1ad8d1b4f8d7b04201d0cb0a4156ead.tar.gz go-b653c878b1ad8d1b4f8d7b04201d0cb0a4156ead.zip |
runtime: change read and write to return negative errno value
The internal read and write functions used to return -1 on error;
change them to return a negative errno value instead.
This will be used by later CLs in this series.
For most targets this is a simplification, although for ones that call
into libc it is a complication.
Updates #27707
Change-Id: Id02bf9487f03e7e88e4f2b85e899e986738697ad
Reviewed-on: https://go-review.googlesource.com/c/go/+/171823
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Diffstat (limited to 'src/runtime/crash_unix_test.go')
-rw-r--r-- | src/runtime/crash_unix_test.go | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/runtime/crash_unix_test.go b/src/runtime/crash_unix_test.go index ce227feebd..4be4962f90 100644 --- a/src/runtime/crash_unix_test.go +++ b/src/runtime/crash_unix_test.go @@ -18,6 +18,7 @@ import ( "strings" "syscall" "testing" + "unsafe" ) // sigquit is the signal to send to kill a hanging testdata program. @@ -33,6 +34,29 @@ func init() { } } +func TestBadOpen(t *testing.T) { + // make sure we get the correct error code if open fails. Same for + // read/write/close on the resulting -1 fd. See issue 10052. + nonfile := []byte("/notreallyafile") + fd := runtime.Open(&nonfile[0], 0, 0) + if fd != -1 { + t.Errorf("open(%q)=%d, want -1", nonfile, fd) + } + var buf [32]byte + r := runtime.Read(-1, unsafe.Pointer(&buf[0]), int32(len(buf))) + if got, want := r, -int32(syscall.EBADF); got != want { + t.Errorf("read()=%d, want %d", got, want) + } + w := runtime.Write(^uintptr(0), unsafe.Pointer(&buf[0]), int32(len(buf))) + if got, want := w, -int32(syscall.EBADF); got != want { + t.Errorf("write()=%d, want %d", got, want) + } + c := runtime.Close(-1) + if c != -1 { + t.Errorf("close()=%d, want -1", c) + } +} + func TestCrashDumpsAllThreads(t *testing.T) { if *flagQuick { t.Skip("-quick") |