Skip to content

Commit

Permalink
cmd/link: flush file mapping before unmapping
Browse files Browse the repository at this point in the history
Call FlushViewOfFile before unmapping the output file, for extra
safety. The documentation says the function does not wait for
the data to be written to disk, so it should be cheap.

Fixes golang#38440.

Change-Id: I05352f15d9305e6e7086a002f61802f74036b710
Reviewed-on: https://go-review.googlesource.com/c/go/+/235639
Reviewed-by: Austin Clements <[email protected]>
Reviewed-by: Jason A. Donenfeld <[email protected]>
  • Loading branch information
cherrymui committed Jun 1, 2020
1 parent 8be0de1 commit 13bc6d4
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/cmd/link/internal/ld/outbuf_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ func (out *OutBuf) munmap() {
if out.buf == nil {
return
}
err := syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&out.buf[0])))
// Apparently unmapping without flush may cause ACCESS_DENIED error
// (see issue 38440).
err := syscall.FlushViewOfFile(uintptr(unsafe.Pointer(&out.buf[0])), 0)
if err != nil {
Exitf("FlushViewOfFile failed: %v", err)
}
err = syscall.UnmapViewOfFile(uintptr(unsafe.Pointer(&out.buf[0])))
out.buf = nil
if err != nil {
Exitf("UnmapViewOfFile failed: %v", err)
Expand Down

0 comments on commit 13bc6d4

Please sign in to comment.