]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/link: flush file mapping before unmapping
authorCherry Zhang <cherryyz@google.com>
Fri, 29 May 2020 05:59:09 +0000 (01:59 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 1 Jun 2020 20:38:23 +0000 (20:38 +0000)
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 #38440.

Change-Id: I05352f15d9305e6e7086a002f61802f74036b710
Reviewed-on: https://go-review.googlesource.com/c/go/+/235639
Reviewed-by: Austin Clements <austin@google.com>
Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
src/cmd/link/internal/ld/outbuf_windows.go

index a7140cce388964750c87892a9859053ad41115af..807c0e227d2a6d5e5d3369f35c2387d4b91f205c 100644 (file)
@@ -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)