aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@golang.org>2020-09-21 17:05:11 -0700
committerIan Lance Taylor <iant@golang.org>2020-09-24 19:57:55 +0000
commitfa01c8a14eeb760c58c5cd09afec327fdd392b2c (patch)
treeb691d490d5e2e44f7d87118221f316233e881be6
parentb1be1428dc7d988c2be9006b1cbdf3e513d299b6 (diff)
downloadgo-fa01c8a14eeb760c58c5cd09afec327fdd392b2c.tar.gz
go-fa01c8a14eeb760c58c5cd09afec327fdd392b2c.zip
[release-branch.go1.15] internal/poll: adjust ignoringEINTR to avoid slice escape
The 1.15 compiler is not quite smart enough to see that the byte slice passed to ignoringEINTR does not escape. This ripples back up to user code which would see a byte slice passed to os.(*File).Write escape, which did not happen in 1.14. Rather than backport some moderately complex compiler fixes, rewrite the code slightly so that the 1.15 compiler is able to see that the slice does not escape. This is not a backport from tip, where the code is already different. The test for this will be on tip, where we will most likely change the compiler to understand this kind of code. Fixes #41543 For #41474 Change-Id: I6c78164229fea7794e7edba512bfd7034a0b91c3 Reviewed-on: https://go-review.googlesource.com/c/go/+/256418 Trust: Ian Lance Taylor <iant@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
-rw-r--r--src/internal/poll/fd_unix.go12
-rw-r--r--src/runtime/trace/trace_stack_test.go1
2 files changed, 7 insertions, 6 deletions
diff --git a/src/internal/poll/fd_unix.go b/src/internal/poll/fd_unix.go
index 4872fa9851..61ffa82b14 100644
--- a/src/internal/poll/fd_unix.go
+++ b/src/internal/poll/fd_unix.go
@@ -152,7 +152,7 @@ func (fd *FD) Read(p []byte) (int, error) {
p = p[:maxRW]
}
for {
- n, err := ignoringEINTR(syscall.Read, fd.Sysfd, p)
+ n, err := ignoringEINTR(func() (int, error) { return syscall.Read(fd.Sysfd, p) })
if err != nil {
n = 0
if err == syscall.EAGAIN && fd.pd.pollable() {
@@ -264,7 +264,7 @@ func (fd *FD) Write(p []byte) (int, error) {
if fd.IsStream && max-nn > maxRW {
max = nn + maxRW
}
- n, err := ignoringEINTR(syscall.Write, fd.Sysfd, p[nn:max])
+ n, err := ignoringEINTR(func() (int, error) { return syscall.Write(fd.Sysfd, p[nn:max]) })
if n > 0 {
nn += n
}
@@ -423,7 +423,7 @@ func (fd *FD) ReadDirent(buf []byte) (int, error) {
}
defer fd.decref()
for {
- n, err := ignoringEINTR(syscall.ReadDirent, fd.Sysfd, buf)
+ n, err := ignoringEINTR(func() (int, error) { return syscall.ReadDirent(fd.Sysfd, buf) })
if err != nil {
n = 0
if err == syscall.EAGAIN && fd.pd.pollable() {
@@ -514,7 +514,7 @@ func (fd *FD) WriteOnce(p []byte) (int, error) {
return 0, err
}
defer fd.writeUnlock()
- return ignoringEINTR(syscall.Write, fd.Sysfd, p)
+ return ignoringEINTR(func() (int, error) { return syscall.Write(fd.Sysfd, p) })
}
// RawRead invokes the user-defined function f for a read operation.
@@ -562,9 +562,9 @@ func (fd *FD) RawWrite(f func(uintptr) bool) error {
// installed without setting SA_RESTART. None of these are the common case,
// but there are enough of them that it seems that we can't avoid
// an EINTR loop.
-func ignoringEINTR(fn func(fd int, p []byte) (int, error), fd int, p []byte) (int, error) {
+func ignoringEINTR(fn func() (int, error)) (int, error) {
for {
- n, err := fn(fd, p)
+ n, err := fn()
if err != syscall.EINTR {
return n, err
}
diff --git a/src/runtime/trace/trace_stack_test.go b/src/runtime/trace/trace_stack_test.go
index cfc0419b72..f856fdcd01 100644
--- a/src/runtime/trace/trace_stack_test.go
+++ b/src/runtime/trace/trace_stack_test.go
@@ -252,6 +252,7 @@ func TestTraceSymbolize(t *testing.T) {
{trace.EvGoSysCall, []frame{
{"syscall.read", 0},
{"syscall.Read", 0},
+ {"internal/poll.(*FD).Read.func1", 0},
{"internal/poll.ignoringEINTR", 0},
{"internal/poll.(*FD).Read", 0},
{"os.(*File).read", 0},