Skip to content

Commit a266811

Browse files
committed
🦫 mmap: move away from calling Fd() directly on windows
Starting from Go 1.25, Fd() on windows will have the same side effect of turning the file into blocking mode. We don't open the file in non-blocking mode, but we also don't like the new side effect. Nonetheless, it's never a bad thing to unify the implementations.
1 parent 0bb1f47 commit a266811

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

mmap/mmap_windows.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,19 @@ import (
88
)
99

1010
func readFile(f *os.File, size uintptr) (addr unsafe.Pointer, close func() error, err error) {
11-
handle, err := windows.CreateFileMapping(windows.Handle(f.Fd()), nil, windows.PAGE_READONLY, 0, 0, nil)
11+
rawConn, err := f.SyscallConn()
12+
if err != nil {
13+
return nil, nil, err
14+
}
15+
16+
var handle windows.Handle
17+
18+
if cerr := rawConn.Control(func(fd uintptr) {
19+
handle, err = windows.CreateFileMapping(windows.Handle(fd), nil, windows.PAGE_READONLY, 0, 0, nil)
20+
}); cerr != nil {
21+
return nil, nil, cerr
22+
}
23+
1224
if err != nil {
1325
return nil, nil, os.NewSyscallError("CreateFileMappingW", err)
1426
}

0 commit comments

Comments
 (0)