Win32 API 日本語リファレンス
ホームSystem.Hypervisor › WHvUnmapGpaRange

WHvUnmapGpaRange

関数
ゲスト物理アドレス範囲のマップを解除する。
DLLWinHvPlatform.dll呼出規約winapi

シグネチャ

// WinHvPlatform.dll
#include <windows.h>

HRESULT WHvUnmapGpaRange(
    WHV_PARTITION_HANDLE Partition,
    ULONGLONG GuestAddress,
    ULONGLONG SizeInBytes
);

パラメーター

名前方向説明
PartitionWHV_PARTITION_HANDLEinメモリ範囲のマップを解除する対象パーティションハンドル。
GuestAddressULONGLONGin解除するゲスト物理アドレス(GPA)の先頭。
SizeInBytesULONGLONGin解除する範囲のサイズをバイト単位で指定する。

戻り値の型: HRESULT

各言語での呼び出し定義

// WinHvPlatform.dll
#include <windows.h>

HRESULT WHvUnmapGpaRange(
    WHV_PARTITION_HANDLE Partition,
    ULONGLONG GuestAddress,
    ULONGLONG SizeInBytes
);
[DllImport("WinHvPlatform.dll", ExactSpelling = true)]
static extern int WHvUnmapGpaRange(
    IntPtr Partition,   // WHV_PARTITION_HANDLE
    ulong GuestAddress,   // ULONGLONG
    ulong SizeInBytes   // ULONGLONG
);
<DllImport("WinHvPlatform.dll", ExactSpelling:=True)>
Public Shared Function WHvUnmapGpaRange(
    Partition As IntPtr,   ' WHV_PARTITION_HANDLE
    GuestAddress As ULong,   ' ULONGLONG
    SizeInBytes As ULong   ' ULONGLONG
) As Integer
End Function
' Partition : WHV_PARTITION_HANDLE
' GuestAddress : ULONGLONG
' SizeInBytes : ULONGLONG
Declare PtrSafe Function WHvUnmapGpaRange Lib "winhvplatform" ( _
    ByVal Partition As LongPtr, _
    ByVal GuestAddress As LongLong, _
    ByVal SizeInBytes As LongLong) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

WHvUnmapGpaRange = ctypes.windll.winhvplatform.WHvUnmapGpaRange
WHvUnmapGpaRange.restype = ctypes.c_int
WHvUnmapGpaRange.argtypes = [
    ctypes.c_ssize_t,  # Partition : WHV_PARTITION_HANDLE
    ctypes.c_ulonglong,  # GuestAddress : ULONGLONG
    ctypes.c_ulonglong,  # SizeInBytes : ULONGLONG
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WinHvPlatform.dll')
WHvUnmapGpaRange = Fiddle::Function.new(
  lib['WHvUnmapGpaRange'],
  [
    Fiddle::TYPE_INTPTR_T,  # Partition : WHV_PARTITION_HANDLE
    -Fiddle::TYPE_LONG_LONG,  # GuestAddress : ULONGLONG
    -Fiddle::TYPE_LONG_LONG,  # SizeInBytes : ULONGLONG
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhvplatform")]
extern "system" {
    fn WHvUnmapGpaRange(
        Partition: isize,  // WHV_PARTITION_HANDLE
        GuestAddress: u64,  // ULONGLONG
        SizeInBytes: u64  // ULONGLONG
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WinHvPlatform.dll")]
public static extern int WHvUnmapGpaRange(IntPtr Partition, ulong GuestAddress, ulong SizeInBytes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinHvPlatform_WHvUnmapGpaRange' -Namespace Win32 -PassThru
# $api::WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
#uselib "WinHvPlatform.dll"
#func global WHvUnmapGpaRange "WHvUnmapGpaRange" sptr, sptr, sptr
; WHvUnmapGpaRange Partition, GuestAddress, SizeInBytes   ; 戻り値は stat
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; GuestAddress : ULONGLONG -> "sptr"
; SizeInBytes : ULONGLONG -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
#uselib "WinHvPlatform.dll"
#cfunc global WHvUnmapGpaRange "WHvUnmapGpaRange" sptr, int64, int64
; res = WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; GuestAddress : ULONGLONG -> "int64"
; SizeInBytes : ULONGLONG -> "int64"
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
; HRESULT WHvUnmapGpaRange(WHV_PARTITION_HANDLE Partition, ULONGLONG GuestAddress, ULONGLONG SizeInBytes)
#uselib "WinHvPlatform.dll"
#cfunc global WHvUnmapGpaRange "WHvUnmapGpaRange" intptr, int64, int64
; res = WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
; Partition : WHV_PARTITION_HANDLE -> "intptr"
; GuestAddress : ULONGLONG -> "int64"
; SizeInBytes : ULONGLONG -> "int64"
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhvplatform = windows.NewLazySystemDLL("WinHvPlatform.dll")
	procWHvUnmapGpaRange = winhvplatform.NewProc("WHvUnmapGpaRange")
)

// Partition (WHV_PARTITION_HANDLE), GuestAddress (ULONGLONG), SizeInBytes (ULONGLONG)
r1, _, err := procWHvUnmapGpaRange.Call(
	uintptr(Partition),
	uintptr(GuestAddress),
	uintptr(SizeInBytes),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // HRESULT
function WHvUnmapGpaRange(
  Partition: NativeInt;   // WHV_PARTITION_HANDLE
  GuestAddress: UInt64;   // ULONGLONG
  SizeInBytes: UInt64   // ULONGLONG
): Integer; stdcall;
  external 'WinHvPlatform.dll' name 'WHvUnmapGpaRange';
result := DllCall("WinHvPlatform\WHvUnmapGpaRange"
    , "Ptr", Partition   ; WHV_PARTITION_HANDLE
    , "Int64", GuestAddress   ; ULONGLONG
    , "Int64", SizeInBytes   ; ULONGLONG
    , "Int")   ; return: HRESULT
●WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes) = DLL("WinHvPlatform.dll", "int WHvUnmapGpaRange(int, qword, qword)")
# 呼び出し: WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
# Partition : WHV_PARTITION_HANDLE -> "int"
# GuestAddress : ULONGLONG -> "qword"
# SizeInBytes : ULONGLONG -> "qword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

extern "winhvplatform" fn WHvUnmapGpaRange(
    Partition: isize, // WHV_PARTITION_HANDLE
    GuestAddress: u64, // ULONGLONG
    SizeInBytes: u64 // ULONGLONG
) callconv(std.os.windows.WINAPI) i32;
proc WHvUnmapGpaRange(
    Partition: int,  # WHV_PARTITION_HANDLE
    GuestAddress: uint64,  # ULONGLONG
    SizeInBytes: uint64  # ULONGLONG
): int32 {.importc: "WHvUnmapGpaRange", stdcall, dynlib: "WinHvPlatform.dll".}
pragma(lib, "winhvplatform");
extern(Windows)
int WHvUnmapGpaRange(
    ptrdiff_t Partition,   // WHV_PARTITION_HANDLE
    ulong GuestAddress,   // ULONGLONG
    ulong SizeInBytes   // ULONGLONG
);
ccall((:WHvUnmapGpaRange, "WinHvPlatform.dll"), stdcall, Int32,
      (Int, UInt64, UInt64),
      Partition, GuestAddress, SizeInBytes)
# Partition : WHV_PARTITION_HANDLE -> Int
# GuestAddress : ULONGLONG -> UInt64
# SizeInBytes : ULONGLONG -> UInt64
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WHvUnmapGpaRange(
    intptr_t Partition,
    uint64_t GuestAddress,
    uint64_t SizeInBytes);
]]
local winhvplatform = ffi.load("winhvplatform")
-- winhvplatform.WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
-- Partition : WHV_PARTITION_HANDLE
-- GuestAddress : ULONGLONG
-- SizeInBytes : ULONGLONG
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WinHvPlatform.dll');
const WHvUnmapGpaRange = lib.func('__stdcall', 'WHvUnmapGpaRange', 'int32_t', ['intptr_t', 'uint64_t', 'uint64_t']);
// WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
// Partition : WHV_PARTITION_HANDLE -> 'intptr_t'
// GuestAddress : ULONGLONG -> 'uint64_t'
// SizeInBytes : ULONGLONG -> 'uint64_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WinHvPlatform.dll", {
  WHvUnmapGpaRange: { parameters: ["isize", "u64", "u64"], result: "i32" },
});
// lib.symbols.WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes)
// Partition : WHV_PARTITION_HANDLE -> "isize"
// GuestAddress : ULONGLONG -> "u64"
// SizeInBytes : ULONGLONG -> "u64"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WHvUnmapGpaRange(
    intptr_t Partition,
    uint64_t GuestAddress,
    uint64_t SizeInBytes);
C, "WinHvPlatform.dll");
// $ffi->WHvUnmapGpaRange(Partition, GuestAddress, SizeInBytes);
// Partition : WHV_PARTITION_HANDLE
// GuestAddress : ULONGLONG
// SizeInBytes : ULONGLONG
// 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
// WINAPI(stdcall): x64 では呼出規約が統一されるため問題なし。x86 では __stdcall 対応のラッパが必要な場合あり。
import com.sun.jna.*;
import com.sun.jna.ptr.*;
import com.sun.jna.win32.StdCallLibrary;
import com.sun.jna.win32.W32APIOptions;

public interface Winhvplatform extends StdCallLibrary {
    Winhvplatform INSTANCE = Native.load("winhvplatform", Winhvplatform.class);
    int WHvUnmapGpaRange(
        long Partition,   // WHV_PARTITION_HANDLE
        long GuestAddress,   // ULONGLONG
        long SizeInBytes   // ULONGLONG
    );
}
@[Link("winhvplatform")]
lib LibWinHvPlatform
  fun WHvUnmapGpaRange = WHvUnmapGpaRange(
    Partition : LibC::SSizeT,   # WHV_PARTITION_HANDLE
    GuestAddress : UInt64,   # ULONGLONG
    SizeInBytes : UInt64   # ULONGLONG
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WHvUnmapGpaRangeNative = Int32 Function(IntPtr, Uint64, Uint64);
typedef WHvUnmapGpaRangeDart = int Function(int, int, int);
final WHvUnmapGpaRange = DynamicLibrary.open('WinHvPlatform.dll')
    .lookupFunction<WHvUnmapGpaRangeNative, WHvUnmapGpaRangeDart>('WHvUnmapGpaRange');
// Partition : WHV_PARTITION_HANDLE -> IntPtr
// GuestAddress : ULONGLONG -> Uint64
// SizeInBytes : ULONGLONG -> Uint64
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WHvUnmapGpaRange(
  Partition: NativeInt;   // WHV_PARTITION_HANDLE
  GuestAddress: UInt64;   // ULONGLONG
  SizeInBytes: UInt64   // ULONGLONG
): Integer; stdcall;
  external 'WinHvPlatform.dll' name 'WHvUnmapGpaRange';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WHvUnmapGpaRange"
  c_WHvUnmapGpaRange :: CIntPtr -> Word64 -> Word64 -> IO Int32
-- Partition : WHV_PARTITION_HANDLE -> CIntPtr
-- GuestAddress : ULONGLONG -> Word64
-- SizeInBytes : ULONGLONG -> Word64
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let whvunmapgparange =
  foreign "WHvUnmapGpaRange"
    (intptr_t @-> uint64_t @-> uint64_t @-> returning int32_t)
(* Partition : WHV_PARTITION_HANDLE -> intptr_t *)
(* GuestAddress : ULONGLONG -> uint64_t *)
(* SizeInBytes : ULONGLONG -> uint64_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhvplatform (t "WinHvPlatform.dll"))
(cffi:use-foreign-library winhvplatform)

(cffi:defcfun ("WHvUnmapGpaRange" whv-unmap-gpa-range :convention :stdcall) :int32
  (partition :int64)   ; WHV_PARTITION_HANDLE
  (guest-address :uint64)   ; ULONGLONG
  (size-in-bytes :uint64))   ; ULONGLONG
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WHvUnmapGpaRange = Win32::API::More->new('WinHvPlatform',
    'int WHvUnmapGpaRange(LPARAM Partition, UINT64 GuestAddress, UINT64 SizeInBytes)');
# my $ret = $WHvUnmapGpaRange->Call($Partition, $GuestAddress, $SizeInBytes);
# Partition : WHV_PARTITION_HANDLE -> LPARAM
# GuestAddress : ULONGLONG -> UINT64
# SizeInBytes : ULONGLONG -> UINT64
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。