From fb65e3daf495a5f85048fc86b76aca141bf6d712 Mon Sep 17 00:00:00 2001 From: Goutham Veeramachaneni Date: Wed, 14 Mar 2018 13:23:33 +0530 Subject: [PATCH] Use the right sized byte array for large indexes Fixes: https://github.com/prometheus/prometheus/issues/3957 Signed-off-by: Goutham Veeramachaneni --- fileutil/mmap_windows.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/fileutil/mmap_windows.go b/fileutil/mmap_windows.go index 3bee807c2..d1384be2b 100644 --- a/fileutil/mmap_windows.go +++ b/fileutil/mmap_windows.go @@ -19,14 +19,16 @@ import ( "unsafe" ) -func mmap(f *os.File, sz int) ([]byte, error) { - low, high := uint32(sz), uint32(sz>>32) +const maxMapSize = 0xFFFFFFFFFFFF // 256TB + +func mmap(f *os.File, size int) ([]byte, error) { + low, high := uint32(size), uint32(size>>32) h, errno := syscall.CreateFileMapping(syscall.Handle(f.Fd()), nil, syscall.PAGE_READONLY, high, low, nil) if h == 0 { return nil, os.NewSyscallError("CreateFileMapping", errno) } - addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, uintptr(sz)) + addr, errno := syscall.MapViewOfFile(h, syscall.FILE_MAP_READ, 0, 0, uintptr(size)) if addr == 0 { return nil, os.NewSyscallError("MapViewOfFile", errno) } @@ -35,7 +37,7 @@ func mmap(f *os.File, sz int) ([]byte, error) { return nil, os.NewSyscallError("CloseHandle", err) } - return (*[1 << 30]byte)(unsafe.Pointer(addr))[:sz], nil + return (*[maxMapSize]byte)(unsafe.Pointer(addr))[:size], nil } func munmap(b []byte) error {