{"record":{"id":"3280310e88cc15a0","repo":"golang/go","slug":"mapviewoffile-s-w","errorCode":null,"errorMessage":"MapViewOfFile %s: %w","messagePattern":"MapViewOfFile (.+?): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/go/internal/mmap/mmap_windows.go","lineNumber":32,"sourceCode":")\n\nfunc mmapFile(f *os.File) (Data, error) {\n\tst, err := f.Stat()\n\tif err != nil {\n\t\treturn Data{}, err\n\t}\n\tsize := st.Size()\n\tif size == 0 {\n\t\treturn Data{f, nil}, nil\n\t}\n\th, err := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, 0, 0, nil)\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"CreateFileMapping %s: %w\", f.Name(), err)\n\t}\n\n\taddr, err := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, 0)\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"MapViewOfFile %s: %w\", f.Name(), err)\n\t}\n\tvar info windows.MemoryBasicInformation\n\terr = windows.VirtualQuery(addr, &info, unsafe.Sizeof(info))\n\tif err != nil {\n\t\treturn Data{}, fmt.Errorf(\"VirtualQuery %s: %w\", f.Name(), err)\n\t}\n\tdata := unsafe.Slice((*byte)(unsafe.Pointer(addr)), int(info.RegionSize))\n\tif len(data) < int(size) {\n\t\t// In some cases, especially on 386, we may not receive a in incomplete mapping:\n\t\t// one that is shorter than the file itself. Return an error in those cases because\n\t\t// incomplete mappings are not useful.\n\t\treturn Data{}, fmt.Errorf(\"mmapFile: received incomplete mapping of file\")\n\t}\n\treturn Data{f, data[:int(size)]}, nil\n}\n","sourceCodeStart":14,"sourceCodeEnd":48,"githubUrl":"https://github.com/golang/go/blob/b6b368adc57c96c3151d224d172029f233ead2c3/src/cmd/go/internal/mmap/mmap_windows.go#L14-L48","documentation":"Windows mmap helper: `syscall.MapViewOfFile` failed mapping the file view into the process address space after a successful `CreateFileMapping`. The wrapped error is the syscall result; the usual cause is insufficient reservable address space, prominent on 32-bit Windows.","triggerScenarios":"Mapping a large file when the process address space is exhausted or fragmented; 32-bit process near the 2 GiB user-space ceiling.","commonSituations":"32-bit (`GOARCH=386`) Windows builds; very large module files; address-space fragmentation from prior allocations.","solutions":["Use a 64-bit Go build (`GOARCH=amd64`).","Clear the cache (`go clean -modcache`) to avoid the large file.","Reduce concurrent allocations / dependency count on 32-bit."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"// Retry address-space pressure on Windows; clear cache if it persists.\nfor i := 0; i < 2; i++ {\n    if err := runGoCmd(); err == nil || !isMapFailure(err) { return err }\n    if i == 1 { _ = exec.Command(\"go\", \"clean\", \"-modcache\").Run() }\n}","preventionTips":["Use a 64-bit Go build on Windows for large module trees.","Close other memory-heavy processes during big builds.","Shrink the cache periodically to reduce mapping size."],"tags":["go-toolchain","mmap","windows","memory"],"analyzedSha":"b6b368adc57c96c3151d224d172029f233ead2c3","analyzedAt":"2026-08-12T00:22:02.250Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}