github.com/tailscale/wireguard-go@v0.0.20201119-0.20210522003738-46b531feb08a/tun/wintun/memmod/memmod_windows_64.go (about)

     1  // +build windows,amd64 windows,arm64
     2  
     3  /* SPDX-License-Identifier: MIT
     4   *
     5   * Copyright (C) 2017-2021 WireGuard LLC. All Rights Reserved.
     6   */
     7  
     8  package memmod
     9  
    10  import (
    11  	"fmt"
    12  
    13  	"golang.org/x/sys/windows"
    14  )
    15  
    16  func (opthdr *IMAGE_OPTIONAL_HEADER) imageOffset() uintptr {
    17  	return uintptr(opthdr.ImageBase & 0xffffffff00000000)
    18  }
    19  
    20  func (module *Module) check4GBBoundaries(alignedImageSize uintptr) (err error) {
    21  	for (module.codeBase >> 32) < ((module.codeBase + alignedImageSize) >> 32) {
    22  		node := &addressList{
    23  			next:    module.blockedMemory,
    24  			address: module.codeBase,
    25  		}
    26  		module.blockedMemory = node
    27  		module.codeBase, err = windows.VirtualAlloc(0,
    28  			alignedImageSize,
    29  			windows.MEM_RESERVE|windows.MEM_COMMIT,
    30  			windows.PAGE_READWRITE)
    31  		if err != nil {
    32  			return fmt.Errorf("Error allocating memory block: %w", err)
    33  		}
    34  	}
    35  	return
    36  }