From e88a03323a460707f650aaab8f8bba8d73dc3854 Mon Sep 17 00:00:00 2001 From: Aliaksandr Valialkin Date: Thu, 20 Jun 2019 20:07:10 +0300 Subject: [PATCH] all: initial stubs for Windows support; see https://github.com/VictoriaMetrics/VictoriaMetrics/issues/70 --- lib/filestream/filestream_windows.go | 9 +++++++ lib/memory/memory_windows.go | 40 ++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 lib/filestream/filestream_windows.go create mode 100644 lib/memory/memory_windows.go diff --git a/lib/filestream/filestream_windows.go b/lib/filestream/filestream_windows.go new file mode 100644 index 000000000..040660083 --- /dev/null +++ b/lib/filestream/filestream_windows.go @@ -0,0 +1,9 @@ +package filestream + +func (st *streamTracker) adviseDontNeed(n int, fdatasync bool) error { + return nil +} + +func (st *streamTracker) close() error { + return nil +} diff --git a/lib/memory/memory_windows.go b/lib/memory/memory_windows.go new file mode 100644 index 000000000..6323a62d5 --- /dev/null +++ b/lib/memory/memory_windows.go @@ -0,0 +1,40 @@ +package memory + +import ( + "syscall" + "unsafe" + + "github.com/VictoriaMetrics/VictoriaMetrics/lib/logger" +) + +// This has been adapted from https://github.com/pbnjay/memory. + +type memStatusEx struct { + dwLength uint32 + dwMemoryLoad uint32 + ullTotalPhys uint64 + unused [6]uint64 +} + +func sysTotalMemory() int { + kernel32, err := syscall.LoadDLL("kernel32.dll") + if err != nil { + logger.Panicf("FATAL: cannot load kernel32.dll: %s", err) + } + globalMemoryStatusEx, err := kernel32.FindProc("GlobalMemoryStatusEx") + if err != nil { + logger.Panicf("FATAL: cannot find GlobalMemoryStatusEx: %s", err) + } + msx := &memStatusEx{ + dwLength: uint32(unsafe.Sizeof(memStatusEx{})), + } + r, _, err := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msx))) + if r == 0 { + logger.Panicf("FATAL: error in GlobalMemoryStatusEx: %s", err) + } + n := int(msx.ullTotalPhys) + if uint64(n) != msx.ullTotalPhys { + logger.Panicf("FATAL: int overflow for msx.ullTotalPhys=%d", msx.ullTotalPhys) + } + return n +}