summaryrefslogtreecommitdiffstats
path: root/vendor/modernc.org/memory/mmap_windows.go
diff options
context:
space:
mode:
authorWim <wim@42.be>2022-01-31 00:27:37 +0100
committerWim <wim@42.be>2022-03-20 14:57:48 +0100
commite3cafeaf9292f67459ff1d186f68283bfaedf2ae (patch)
treeb69c39620aa91dba695b3b935c6651c0fb37ce75 /vendor/modernc.org/memory/mmap_windows.go
parente7b193788a56ee7cdb02a87a9db0ad6724ef66d5 (diff)
downloadmatterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.gz
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.tar.bz2
matterbridge-msglm-e3cafeaf9292f67459ff1d186f68283bfaedf2ae.zip
Add dependencies/vendor (whatsapp)
Diffstat (limited to 'vendor/modernc.org/memory/mmap_windows.go')
-rw-r--r--vendor/modernc.org/memory/mmap_windows.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/vendor/modernc.org/memory/mmap_windows.go b/vendor/modernc.org/memory/mmap_windows.go
new file mode 100644
index 00000000..3c402039
--- /dev/null
+++ b/vendor/modernc.org/memory/mmap_windows.go
@@ -0,0 +1,49 @@
+// Copyright 2017 The Memory Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package memory // import "modernc.org/memory"
+
+import (
+ "os"
+ "syscall"
+)
+
+const (
+ _MEM_COMMIT = 0x1000
+ _MEM_RESERVE = 0x2000
+ _MEM_DECOMMIT = 0x4000
+ _MEM_RELEASE = 0x8000
+
+ _PAGE_READWRITE = 0x0004
+ _PAGE_NOACCESS = 0x0001
+)
+
+const pageSizeLog = 16
+
+var (
+ modkernel32 = syscall.NewLazyDLL("kernel32.dll")
+ osPageMask = osPageSize - 1
+ osPageSize = os.Getpagesize()
+ procVirtualAlloc = modkernel32.NewProc("VirtualAlloc")
+ procVirtualFree = modkernel32.NewProc("VirtualFree")
+)
+
+// pageSize aligned.
+func mmap(size int) (uintptr, int, error) {
+ size = roundup(size, pageSize)
+ addr, _, err := procVirtualAlloc.Call(0, uintptr(size), _MEM_COMMIT|_MEM_RESERVE, _PAGE_READWRITE)
+ if err.(syscall.Errno) != 0 || addr == 0 {
+ return addr, size, err
+ }
+ return addr, size, nil
+}
+
+func unmap(addr uintptr, size int) error {
+ r, _, err := procVirtualFree.Call(addr, 0, _MEM_RELEASE)
+ if r == 0 {
+ return err
+ }
+
+ return nil
+}