mirror of https://github.com/golang/go.git
[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>
This commit is contained in:
parent
b1be1428dc
commit
fa01c8a14e
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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},
|
||||
|
|
|
|||
Loading…
Reference in New Issue