From 65e03a918274534015ca189bfadc33cbba9e3ec8 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Fri, 6 Nov 2020 05:24:50 +0100 Subject: wintun: load wintun.dll from RCDATA resource Signed-off-by: Simon Rozman Signed-off-by: Jason A. Donenfeld --- tun/wintun/memmod/memmod_windows_64.go | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 tun/wintun/memmod/memmod_windows_64.go (limited to 'tun/wintun/memmod/memmod_windows_64.go') diff --git a/tun/wintun/memmod/memmod_windows_64.go b/tun/wintun/memmod/memmod_windows_64.go new file mode 100644 index 0000000..46ac677 --- /dev/null +++ b/tun/wintun/memmod/memmod_windows_64.go @@ -0,0 +1,36 @@ +// +build amd64 arm64 + +/* SPDX-License-Identifier: MIT + * + * Copyright (C) 2020 WireGuard LLC. All Rights Reserved. + */ + +package memmod + +import ( + "fmt" + + "golang.org/x/sys/windows" +) + +func (opthdr *IMAGE_OPTIONAL_HEADER) imageOffset() uintptr { + return uintptr(opthdr.ImageBase & 0xffffffff00000000) +} + +func (module *Module) check4GBBoundaries(alignedImageSize uintptr) (err error) { + for (module.codeBase >> 32) < ((module.codeBase + alignedImageSize) >> 32) { + node := &addressList{ + next: module.blockedMemory, + address: module.codeBase, + } + module.blockedMemory = node + module.codeBase, err = windows.VirtualAlloc(0, + alignedImageSize, + windows.MEM_RESERVE|windows.MEM_COMMIT, + windows.PAGE_READWRITE) + if err != nil { + return fmt.Errorf("Error allocating memory block: %v", err) + } + } + return +} -- cgit v1.2.3-59-g8ed1b