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

WHvMapVpciDeviceMmioRanges

関数
仮想PCIデバイスのMMIO範囲をマップする。
DLLWinHvPlatform.dll呼出規約winapi

シグネチャ

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

HRESULT WHvMapVpciDeviceMmioRanges(
    WHV_PARTITION_HANDLE Partition,
    ULONGLONG LogicalDeviceId,
    DWORD* MappingCount,
    WHV_VPCI_MMIO_MAPPING** Mappings
);

パラメーター

名前方向説明
PartitionWHV_PARTITION_HANDLEin対象パーティションのハンドルを指定する。
LogicalDeviceIdULONGLONGin対象とする仮想PCIデバイスの論理デバイスIDを指定する。
MappingCountDWORD*out返されるMMIOマッピングの個数を受け取る出力ポインタ。
MappingsWHV_VPCI_MMIO_MAPPING**outMMIOマッピング配列を受け取る出力ポインタ。割り当て領域は呼び出し側が解放する。

戻り値の型: HRESULT

各言語での呼び出し定義

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

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

WHvMapVpciDeviceMmioRanges = ctypes.windll.winhvplatform.WHvMapVpciDeviceMmioRanges
WHvMapVpciDeviceMmioRanges.restype = ctypes.c_int
WHvMapVpciDeviceMmioRanges.argtypes = [
    ctypes.c_ssize_t,  # Partition : WHV_PARTITION_HANDLE
    ctypes.c_ulonglong,  # LogicalDeviceId : ULONGLONG
    ctypes.POINTER(wintypes.DWORD),  # MappingCount : DWORD* out
    ctypes.c_void_p,  # Mappings : WHV_VPCI_MMIO_MAPPING** out
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('WinHvPlatform.dll')
WHvMapVpciDeviceMmioRanges = Fiddle::Function.new(
  lib['WHvMapVpciDeviceMmioRanges'],
  [
    Fiddle::TYPE_INTPTR_T,  # Partition : WHV_PARTITION_HANDLE
    -Fiddle::TYPE_LONG_LONG,  # LogicalDeviceId : ULONGLONG
    Fiddle::TYPE_VOIDP,  # MappingCount : DWORD* out
    Fiddle::TYPE_VOIDP,  # Mappings : WHV_VPCI_MMIO_MAPPING** out
  ],
  Fiddle::TYPE_INT)
#[link(name = "winhvplatform")]
extern "system" {
    fn WHvMapVpciDeviceMmioRanges(
        Partition: isize,  // WHV_PARTITION_HANDLE
        LogicalDeviceId: u64,  // ULONGLONG
        MappingCount: *mut u32,  // DWORD* out
        Mappings: *mut *mut WHV_VPCI_MMIO_MAPPING  // WHV_VPCI_MMIO_MAPPING** out
    ) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("WinHvPlatform.dll")]
public static extern int WHvMapVpciDeviceMmioRanges(IntPtr Partition, ulong LogicalDeviceId, out uint MappingCount, IntPtr Mappings);
"@
$api = Add-Type -MemberDefinition $sig -Name 'WinHvPlatform_WHvMapVpciDeviceMmioRanges' -Namespace Win32 -PassThru
# $api::WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
#uselib "WinHvPlatform.dll"
#func global WHvMapVpciDeviceMmioRanges "WHvMapVpciDeviceMmioRanges" sptr, sptr, sptr, sptr
; WHvMapVpciDeviceMmioRanges Partition, LogicalDeviceId, varptr(MappingCount), varptr(Mappings)   ; 戻り値は stat
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; LogicalDeviceId : ULONGLONG -> "sptr"
; MappingCount : DWORD* out -> "sptr"
; Mappings : WHV_VPCI_MMIO_MAPPING** out -> "sptr"
; ※HSP3.7は int64 引数(64bit値渡し)に非対応です。
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "WinHvPlatform.dll"
#cfunc global WHvMapVpciDeviceMmioRanges "WHvMapVpciDeviceMmioRanges" sptr, int64, var, var
; res = WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
; Partition : WHV_PARTITION_HANDLE -> "sptr"
; LogicalDeviceId : ULONGLONG -> "int64"
; MappingCount : DWORD* out -> "var"
; Mappings : WHV_VPCI_MMIO_MAPPING** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
; ※int64 引数の DLL 値渡しは x64 ランタイム(hsp3_64)のみ対応(x86 は未対応)。
出力引数:
; HRESULT WHvMapVpciDeviceMmioRanges(WHV_PARTITION_HANDLE Partition, ULONGLONG LogicalDeviceId, DWORD* MappingCount, WHV_VPCI_MMIO_MAPPING** Mappings)
#uselib "WinHvPlatform.dll"
#cfunc global WHvMapVpciDeviceMmioRanges "WHvMapVpciDeviceMmioRanges" intptr, int64, var, var
; res = WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
; Partition : WHV_PARTITION_HANDLE -> "intptr"
; LogicalDeviceId : ULONGLONG -> "int64"
; MappingCount : DWORD* out -> "var"
; Mappings : WHV_VPCI_MMIO_MAPPING** out -> "var"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	winhvplatform = windows.NewLazySystemDLL("WinHvPlatform.dll")
	procWHvMapVpciDeviceMmioRanges = winhvplatform.NewProc("WHvMapVpciDeviceMmioRanges")
)

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

extern "winhvplatform" fn WHvMapVpciDeviceMmioRanges(
    Partition: isize, // WHV_PARTITION_HANDLE
    LogicalDeviceId: u64, // ULONGLONG
    MappingCount: [*c]u32, // DWORD* out
    Mappings: [*c][*c]WHV_VPCI_MMIO_MAPPING // WHV_VPCI_MMIO_MAPPING** out
) callconv(std.os.windows.WINAPI) i32;
proc WHvMapVpciDeviceMmioRanges(
    Partition: int,  # WHV_PARTITION_HANDLE
    LogicalDeviceId: uint64,  # ULONGLONG
    MappingCount: ptr uint32,  # DWORD* out
    Mappings: ptr WHV_VPCI_MMIO_MAPPING  # WHV_VPCI_MMIO_MAPPING** out
): int32 {.importc: "WHvMapVpciDeviceMmioRanges", stdcall, dynlib: "WinHvPlatform.dll".}
pragma(lib, "winhvplatform");
extern(Windows)
int WHvMapVpciDeviceMmioRanges(
    ptrdiff_t Partition,   // WHV_PARTITION_HANDLE
    ulong LogicalDeviceId,   // ULONGLONG
    uint* MappingCount,   // DWORD* out
    WHV_VPCI_MMIO_MAPPING** Mappings   // WHV_VPCI_MMIO_MAPPING** out
);
ccall((:WHvMapVpciDeviceMmioRanges, "WinHvPlatform.dll"), stdcall, Int32,
      (Int, UInt64, Ptr{UInt32}, Ptr{WHV_VPCI_MMIO_MAPPING}),
      Partition, LogicalDeviceId, MappingCount, Mappings)
# Partition : WHV_PARTITION_HANDLE -> Int
# LogicalDeviceId : ULONGLONG -> UInt64
# MappingCount : DWORD* out -> Ptr{UInt32}
# Mappings : WHV_VPCI_MMIO_MAPPING** out -> Ptr{WHV_VPCI_MMIO_MAPPING}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。
local ffi = require("ffi")
ffi.cdef[[
int32_t WHvMapVpciDeviceMmioRanges(
    intptr_t Partition,
    uint64_t LogicalDeviceId,
    uint32_t* MappingCount,
    void* Mappings);
]]
local winhvplatform = ffi.load("winhvplatform")
-- winhvplatform.WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
-- Partition : WHV_PARTITION_HANDLE
-- LogicalDeviceId : ULONGLONG
-- MappingCount : DWORD* out
-- Mappings : WHV_VPCI_MMIO_MAPPING** out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。
const koffi = require('koffi');
const lib = koffi.load('WinHvPlatform.dll');
const WHvMapVpciDeviceMmioRanges = lib.func('__stdcall', 'WHvMapVpciDeviceMmioRanges', 'int32_t', ['intptr_t', 'uint64_t', 'uint32_t *', 'void *']);
// WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
// Partition : WHV_PARTITION_HANDLE -> 'intptr_t'
// LogicalDeviceId : ULONGLONG -> 'uint64_t'
// MappingCount : DWORD* out -> 'uint32_t *'
// Mappings : WHV_VPCI_MMIO_MAPPING** out -> 'void *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。
const lib = Deno.dlopen("WinHvPlatform.dll", {
  WHvMapVpciDeviceMmioRanges: { parameters: ["isize", "u64", "pointer", "pointer"], result: "i32" },
});
// lib.symbols.WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings)
// Partition : WHV_PARTITION_HANDLE -> "isize"
// LogicalDeviceId : ULONGLONG -> "u64"
// MappingCount : DWORD* out -> "pointer"
// Mappings : WHV_VPCI_MMIO_MAPPING** out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。
<?php
$ffi = FFI::cdef(<<<C
int32_t WHvMapVpciDeviceMmioRanges(
    intptr_t Partition,
    uint64_t LogicalDeviceId,
    uint32_t* MappingCount,
    void* Mappings);
C, "WinHvPlatform.dll");
// $ffi->WHvMapVpciDeviceMmioRanges(Partition, LogicalDeviceId, MappingCount, Mappings);
// Partition : WHV_PARTITION_HANDLE
// LogicalDeviceId : ULONGLONG
// MappingCount : DWORD* out
// Mappings : WHV_VPCI_MMIO_MAPPING** out
// 構造体/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 WHvMapVpciDeviceMmioRanges(
        long Partition,   // WHV_PARTITION_HANDLE
        long LogicalDeviceId,   // ULONGLONG
        IntByReference MappingCount,   // DWORD* out
        Pointer Mappings   // WHV_VPCI_MMIO_MAPPING** out
    );
}
@[Link("winhvplatform")]
lib LibWinHvPlatform
  fun WHvMapVpciDeviceMmioRanges = WHvMapVpciDeviceMmioRanges(
    Partition : LibC::SSizeT,   # WHV_PARTITION_HANDLE
    LogicalDeviceId : UInt64,   # ULONGLONG
    MappingCount : UInt32*,   # DWORD* out
    Mappings : WHV_VPCI_MMIO_MAPPING**   # WHV_VPCI_MMIO_MAPPING** out
  ) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。
import 'dart:ffi';
import 'package:ffi/ffi.dart';

typedef WHvMapVpciDeviceMmioRangesNative = Int32 Function(IntPtr, Uint64, Pointer<Uint32>, Pointer<Void>);
typedef WHvMapVpciDeviceMmioRangesDart = int Function(int, int, Pointer<Uint32>, Pointer<Void>);
final WHvMapVpciDeviceMmioRanges = DynamicLibrary.open('WinHvPlatform.dll')
    .lookupFunction<WHvMapVpciDeviceMmioRangesNative, WHvMapVpciDeviceMmioRangesDart>('WHvMapVpciDeviceMmioRanges');
// Partition : WHV_PARTITION_HANDLE -> IntPtr
// LogicalDeviceId : ULONGLONG -> Uint64
// MappingCount : DWORD* out -> Pointer<Uint32>
// Mappings : WHV_VPCI_MMIO_MAPPING** out -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function WHvMapVpciDeviceMmioRanges(
  Partition: NativeInt;   // WHV_PARTITION_HANDLE
  LogicalDeviceId: UInt64;   // ULONGLONG
  MappingCount: Pointer;   // DWORD* out
  Mappings: Pointer   // WHV_VPCI_MMIO_MAPPING** out
): Integer; stdcall;
  external 'WinHvPlatform.dll' name 'WHvMapVpciDeviceMmioRanges';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "WHvMapVpciDeviceMmioRanges"
  c_WHvMapVpciDeviceMmioRanges :: CIntPtr -> Word64 -> Ptr Word32 -> Ptr () -> IO Int32
-- Partition : WHV_PARTITION_HANDLE -> CIntPtr
-- LogicalDeviceId : ULONGLONG -> Word64
-- MappingCount : DWORD* out -> Ptr Word32
-- Mappings : WHV_VPCI_MMIO_MAPPING** out -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let whvmapvpcidevicemmioranges =
  foreign "WHvMapVpciDeviceMmioRanges"
    (intptr_t @-> uint64_t @-> (ptr uint32_t) @-> (ptr void) @-> returning int32_t)
(* Partition : WHV_PARTITION_HANDLE -> intptr_t *)
(* LogicalDeviceId : ULONGLONG -> uint64_t *)
(* MappingCount : DWORD* out -> (ptr uint32_t) *)
(* Mappings : WHV_VPCI_MMIO_MAPPING** out -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library winhvplatform (t "WinHvPlatform.dll"))
(cffi:use-foreign-library winhvplatform)

(cffi:defcfun ("WHvMapVpciDeviceMmioRanges" whv-map-vpci-device-mmio-ranges :convention :stdcall) :int32
  (partition :int64)   ; WHV_PARTITION_HANDLE
  (logical-device-id :uint64)   ; ULONGLONG
  (mapping-count :pointer)   ; DWORD* out
  (mappings :pointer))   ; WHV_VPCI_MMIO_MAPPING** out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $WHvMapVpciDeviceMmioRanges = Win32::API::More->new('WinHvPlatform',
    'int WHvMapVpciDeviceMmioRanges(LPARAM Partition, UINT64 LogicalDeviceId, LPVOID MappingCount, LPVOID Mappings)');
# my $ret = $WHvMapVpciDeviceMmioRanges->Call($Partition, $LogicalDeviceId, $MappingCount, $Mappings);
# Partition : WHV_PARTITION_HANDLE -> LPARAM
# LogicalDeviceId : ULONGLONG -> UINT64
# MappingCount : DWORD* out -> LPVOID
# Mappings : WHV_VPCI_MMIO_MAPPING** out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

使用する型