aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Faller <jeremy@golang.org>2020-03-30 10:45:26 -0400
committerJeremy Faller <jeremy@golang.org>2020-04-01 15:46:28 +0000
commit4ec5e7c50fb2d7fb158578e620e026779c3aafe3 (patch)
treeb77b3649819b9aea00b637535bfc75131ae4fe39
parent1cb582fe026d22cc886634f49ec0be63bcca911f (diff)
downloadgo-4ec5e7c50fb2d7fb158578e620e026779c3aafe3.tar.gz
go-4ec5e7c50fb2d7fb158578e620e026779c3aafe3.zip
[dev.link] cmd/link: fix mmapping OutBuf on windows
We got the permissions wrong on the mmapped region. Change-Id: Ica6372fd9d9a787ab20a763e5785fb9fb34ff623 Reviewed-on: https://go-review.googlesource.com/c/go/+/226366 Run-TryBot: Jeremy Faller <jeremy@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Cherry Zhang <cherryyz@google.com>
-rw-r--r--src/cmd/link/internal/ld/outbuf_test.go30
-rw-r--r--src/cmd/link/internal/ld/outbuf_windows.go2
2 files changed, 31 insertions, 1 deletions
diff --git a/src/cmd/link/internal/ld/outbuf_test.go b/src/cmd/link/internal/ld/outbuf_test.go
new file mode 100644
index 0000000000..512238f39a
--- /dev/null
+++ b/src/cmd/link/internal/ld/outbuf_test.go
@@ -0,0 +1,30 @@
+// Copyright 2020 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package ld
+
+import (
+ "os"
+ "runtime"
+ "testing"
+)
+
+// TestMMap ensures that we can actually mmap on every supported platform.
+func TestMMap(t *testing.T) {
+ switch runtime.GOOS {
+ default:
+ t.Skip("unsupported OS")
+ case "darwin", "dragonfly", "freebsd", "linux", "openbsd", "windows":
+ }
+ filename := "foo.out"
+ ob := NewOutBuf(nil)
+ if err := ob.Open(filename); err != nil {
+ t.Errorf("error opening file: %v", err)
+ }
+ defer os.RemoveAll(filename)
+ defer ob.Close()
+ if err := ob.Mmap(1 << 20); err != nil {
+ t.Errorf("error mmapping file %v", err)
+ }
+}
diff --git a/src/cmd/link/internal/ld/outbuf_windows.go b/src/cmd/link/internal/ld/outbuf_windows.go
index e7cda75fc0..f745a5cb22 100644
--- a/src/cmd/link/internal/ld/outbuf_windows.go
+++ b/src/cmd/link/internal/ld/outbuf_windows.go
@@ -17,7 +17,7 @@ func (out *OutBuf) Mmap(filesize uint64) error {
}
low, high := uint32(filesize), uint32(filesize>>32)
- fmap, err := syscall.CreateFileMapping(syscall.Handle(out.f.Fd()), nil, syscall.PAGE_READONLY, high, low, nil)
+ fmap, err := syscall.CreateFileMapping(syscall.Handle(out.f.Fd()), nil, syscall.PAGE_READWRITE, high, low, nil)
if err != nil {
return err
}