Skip to content

Commit

Permalink
Fix mimirtool build windows (#2273)
Browse files Browse the repository at this point in the history
* Fix mimirtool build on windows.

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>

* CHANGELOG.md

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>

* Move changelog entry to 2.2.0-rc.1 / Mimirtool section.

Signed-off-by: Peter Štibraný <pstibrany@gmail.com>
  • Loading branch information
pstibrany committed Jun 29, 2022
1 parent 57c9678 commit 950ce5c
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.2.0-rc.1

### Mimirtool

* [BUGFIX] Make mimirtool build for Windows work again. #2273

## 2.2.0-rc.0

### Grafana Mimir
Expand Down
11 changes: 11 additions & 0 deletions pkg/storegateway/indexheader/fileutil/mmap_386.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/tsdb/fileutil/mmap_386.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Prometheus Authors.

//go:build windows
// +build windows

package fileutil

const maxMapSize = 0x7FFFFFFF // 2GB
11 changes: 11 additions & 0 deletions pkg/storegateway/indexheader/fileutil/mmap_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/tsdb/fileutil/mmap_amd64.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Prometheus Authors.

//go:build windows
// +build windows

package fileutil

const maxMapSize = 0xFFFFFFFFFFFF // 256TB
11 changes: 11 additions & 0 deletions pkg/storegateway/indexheader/fileutil/mmap_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/tsdb/fileutil/mmap_arm64.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Prometheus Authors.

//go:build windows
// +build windows

package fileutil

const maxMapSize = 0xFFFFFFFFFFFF // 256TB
38 changes: 38 additions & 0 deletions pkg/storegateway/indexheader/fileutil/mmap_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Provenance-includes-location: https://github.com/prometheus/prometheus/blob/main/tsdb/fileutil/mmap_windows.go
// Provenance-includes-license: Apache-2.0
// Provenance-includes-copyright: The Prometheus Authors.

package fileutil

import (
"os"
"syscall"
"unsafe"
)

func mmap(f *os.File, size int, populate bool) ([]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(size))
if addr == 0 {
return nil, os.NewSyscallError("MapViewOfFile", errno)
}

if err := syscall.CloseHandle(syscall.Handle(h)); err != nil {
return nil, os.NewSyscallError("CloseHandle", err)
}

return (*[maxMapSize]byte)(unsafe.Pointer(addr))[:size], nil
}

func munmap(b []byte) error {
if err := syscall.UnmapViewOfFile((uintptr)(unsafe.Pointer(&b[0]))); err != nil {
return os.NewSyscallError("UnmapViewOfFile", err)
}
return nil
}

0 comments on commit 950ce5c

Please sign in to comment.