MapUserPhysicalPagesScatter
関数シグネチャ
// KERNEL32.dll
#include <windows.h>
BOOL MapUserPhysicalPagesScatter(
void** VirtualAddresses,
UINT_PTR NumberOfPages,
UINT_PTR* PageArray // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| VirtualAddresses | void** | in | 再マップするメモリ領域の開始アドレスの配列へのポインター。 VirtualAddresses の各エントリは、Address Windowing Extensions (AWE) 領域を割り当てる際に VirtualAlloc 関数が返すアドレス範囲内になければなりません。NumberOfPages の値が配列のサイズを示します。エントリは複数の Address Windowing Extensions (AWE) 領域にまたがって指定できます。 |
| NumberOfPages | UINT_PTR | in | 変換を確立する対象となる物理メモリおよび仮想アドレス空間のサイズ(ページ単位)。 VirtualAddresses の配列が仮想アドレス範囲を指定します。 |
| PageArray | UINT_PTR* | inoptional | VirtualAddresses 内の対応する各ページをどのように扱うかを示す値の配列へのポインター。 0(ゼロ)は VirtualAddresses 内の対応するエントリのマップを解除することを示し、0 以外の値はそのページをマップすることを示します。 このパラメーターが NULL の場合、VirtualAddresses 配列内のすべてのアドレスのマップが解除されます。 NumberOfPages の値が配列のサイズを示します。 |
戻り値の型: BOOL
公式ドキュメント
以前に割り当てた物理メモリページを、Address Windowing Extensions (AWE) 領域内の指定したアドレスにマップします。(MapUserPhysicalPagesScatter)
戻り値
関数が成功した場合、戻り値は TRUE です。
関数が失敗した場合、戻り値は FALSE となり、関数は部分的にもそれ以外でもマップやマップ解除を行いません。拡張エラー情報を取得するには、 GetLastError を呼び出します。
解説(Remarks)
物理ページはマップ解除される場合がありますが、解放はされません。物理ページを解放するには FreeUserPhysicalPages を呼び出す必要があります。
物理メモリページの数は任意に指定できますが、そのメモリは VirtualAlloc によって割り当てられた仮想アドレス空間の外に及ぶことはできません。既存のアドレスマップは新しい変換によって自動的に上書きされ、古い変換はマップ解除されます。
AllocateUserPhysicalPages で指定された範囲外の物理メモリページはマップできません。複数の領域を同時にマップできますが、それらは重なってはなりません。
物理ページは任意の物理アドレスに配置される可能性がありますが、物理ページが連続しているとは想定しないでください。
マルチプロセッサー環境では、この関数はハードウェアの変換バッファーの一貫性を維持します。この関数から戻った時点で、すべてのプロセッサー上のすべてのスレッドが正しいマッピングを参照することが保証されます。
この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT マクロを 0x0500 以降として定義します。詳細については、Using the Windows Headers を参照してください。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
BOOL MapUserPhysicalPagesScatter(
void** VirtualAddresses,
UINT_PTR NumberOfPages,
UINT_PTR* PageArray // optional
);[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool MapUserPhysicalPagesScatter(
IntPtr VirtualAddresses, // void**
UIntPtr NumberOfPages, // UINT_PTR
IntPtr PageArray // UINT_PTR* optional
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function MapUserPhysicalPagesScatter(
VirtualAddresses As IntPtr, ' void**
NumberOfPages As UIntPtr, ' UINT_PTR
PageArray As IntPtr ' UINT_PTR* optional
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function' VirtualAddresses : void**
' NumberOfPages : UINT_PTR
' PageArray : UINT_PTR* optional
Declare PtrSafe Function MapUserPhysicalPagesScatter Lib "kernel32" ( _
ByVal VirtualAddresses As LongPtr, _
ByVal NumberOfPages As LongPtr, _
ByVal PageArray As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
MapUserPhysicalPagesScatter = ctypes.windll.kernel32.MapUserPhysicalPagesScatter
MapUserPhysicalPagesScatter.restype = wintypes.BOOL
MapUserPhysicalPagesScatter.argtypes = [
ctypes.c_void_p, # VirtualAddresses : void**
ctypes.c_size_t, # NumberOfPages : UINT_PTR
ctypes.POINTER(ctypes.c_size_t), # PageArray : UINT_PTR* optional
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
MapUserPhysicalPagesScatter = Fiddle::Function.new(
lib['MapUserPhysicalPagesScatter'],
[
Fiddle::TYPE_VOIDP, # VirtualAddresses : void**
Fiddle::TYPE_UINTPTR_T, # NumberOfPages : UINT_PTR
Fiddle::TYPE_VOIDP, # PageArray : UINT_PTR* optional
],
Fiddle::TYPE_INT)#[link(name = "kernel32")]
extern "system" {
fn MapUserPhysicalPagesScatter(
VirtualAddresses: *mut *mut (), // void**
NumberOfPages: usize, // UINT_PTR
PageArray: *mut usize // UINT_PTR* optional
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern bool MapUserPhysicalPagesScatter(IntPtr VirtualAddresses, UIntPtr NumberOfPages, IntPtr PageArray);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_MapUserPhysicalPagesScatter' -Namespace Win32 -PassThru
# $api::MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray)#uselib "KERNEL32.dll"
#func global MapUserPhysicalPagesScatter "MapUserPhysicalPagesScatter" sptr, sptr, sptr
; MapUserPhysicalPagesScatter VirtualAddresses, NumberOfPages, varptr(PageArray) ; 戻り値は stat
; VirtualAddresses : void** -> "sptr"
; NumberOfPages : UINT_PTR -> "sptr"
; PageArray : UINT_PTR* optional -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "KERNEL32.dll" #cfunc global MapUserPhysicalPagesScatter "MapUserPhysicalPagesScatter" sptr, sptr, var ; res = MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray) ; VirtualAddresses : void** -> "sptr" ; NumberOfPages : UINT_PTR -> "sptr" ; PageArray : UINT_PTR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global MapUserPhysicalPagesScatter "MapUserPhysicalPagesScatter" sptr, sptr, sptr ; res = MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, varptr(PageArray)) ; VirtualAddresses : void** -> "sptr" ; NumberOfPages : UINT_PTR -> "sptr" ; PageArray : UINT_PTR* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
; BOOL MapUserPhysicalPagesScatter(void** VirtualAddresses, UINT_PTR NumberOfPages, UINT_PTR* PageArray) #uselib "KERNEL32.dll" #cfunc global MapUserPhysicalPagesScatter "MapUserPhysicalPagesScatter" intptr, intptr, var ; res = MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray) ; VirtualAddresses : void** -> "intptr" ; NumberOfPages : UINT_PTR -> "intptr" ; PageArray : UINT_PTR* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; BOOL MapUserPhysicalPagesScatter(void** VirtualAddresses, UINT_PTR NumberOfPages, UINT_PTR* PageArray) #uselib "KERNEL32.dll" #cfunc global MapUserPhysicalPagesScatter "MapUserPhysicalPagesScatter" intptr, intptr, intptr ; res = MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, varptr(PageArray)) ; VirtualAddresses : void** -> "intptr" ; NumberOfPages : UINT_PTR -> "intptr" ; PageArray : UINT_PTR* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procMapUserPhysicalPagesScatter = kernel32.NewProc("MapUserPhysicalPagesScatter")
)
// VirtualAddresses (void**), NumberOfPages (UINT_PTR), PageArray (UINT_PTR* optional)
r1, _, err := procMapUserPhysicalPagesScatter.Call(
uintptr(VirtualAddresses),
uintptr(NumberOfPages),
uintptr(PageArray),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // BOOLfunction MapUserPhysicalPagesScatter(
VirtualAddresses: Pointer; // void**
NumberOfPages: NativeUInt; // UINT_PTR
PageArray: Pointer // UINT_PTR* optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'MapUserPhysicalPagesScatter';result := DllCall("KERNEL32\MapUserPhysicalPagesScatter"
, "Ptr", VirtualAddresses ; void**
, "UPtr", NumberOfPages ; UINT_PTR
, "Ptr", PageArray ; UINT_PTR* optional
, "Int") ; return: BOOL●MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray) = DLL("KERNEL32.dll", "bool MapUserPhysicalPagesScatter(void*, int, void*)")
# 呼び出し: MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray)
# VirtualAddresses : void** -> "void*"
# NumberOfPages : UINT_PTR -> "int"
# PageArray : UINT_PTR* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn MapUserPhysicalPagesScatter(
VirtualAddresses: ?*anyopaque, // void**
NumberOfPages: usize, // UINT_PTR
PageArray: [*c]usize // UINT_PTR* optional
) callconv(std.os.windows.WINAPI) i32;proc MapUserPhysicalPagesScatter(
VirtualAddresses: pointer, # void**
NumberOfPages: uint, # UINT_PTR
PageArray: ptr uint # UINT_PTR* optional
): int32 {.importc: "MapUserPhysicalPagesScatter", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
int MapUserPhysicalPagesScatter(
void** VirtualAddresses, // void**
size_t NumberOfPages, // UINT_PTR
size_t* PageArray // UINT_PTR* optional
);ccall((:MapUserPhysicalPagesScatter, "KERNEL32.dll"), stdcall, Int32,
(Ptr{Cvoid}, Csize_t, Ptr{Csize_t}),
VirtualAddresses, NumberOfPages, PageArray)
# VirtualAddresses : void** -> Ptr{Cvoid}
# NumberOfPages : UINT_PTR -> Csize_t
# PageArray : UINT_PTR* optional -> Ptr{Csize_t}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t MapUserPhysicalPagesScatter(
void** VirtualAddresses,
uintptr_t NumberOfPages,
uintptr_t* PageArray);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray)
-- VirtualAddresses : void**
-- NumberOfPages : UINT_PTR
-- PageArray : UINT_PTR* optional
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const MapUserPhysicalPagesScatter = lib.func('__stdcall', 'MapUserPhysicalPagesScatter', 'int32_t', ['void *', 'uintptr_t', 'uintptr_t *']);
// MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray)
// VirtualAddresses : void** -> 'void *'
// NumberOfPages : UINT_PTR -> 'uintptr_t'
// PageArray : UINT_PTR* optional -> 'uintptr_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
MapUserPhysicalPagesScatter: { parameters: ["pointer", "usize", "pointer"], result: "i32" },
});
// lib.symbols.MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray)
// VirtualAddresses : void** -> "pointer"
// NumberOfPages : UINT_PTR -> "usize"
// PageArray : UINT_PTR* optional -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t MapUserPhysicalPagesScatter(
void** VirtualAddresses,
size_t NumberOfPages,
size_t* PageArray);
C, "KERNEL32.dll");
// $ffi->MapUserPhysicalPagesScatter(VirtualAddresses, NumberOfPages, PageArray);
// VirtualAddresses : void**
// NumberOfPages : UINT_PTR
// PageArray : UINT_PTR* optional
// 構造体/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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
boolean MapUserPhysicalPagesScatter(
Pointer VirtualAddresses, // void**
long NumberOfPages, // UINT_PTR
LongByReference PageArray // UINT_PTR* optional
);
}@[Link("kernel32")]
lib LibKERNEL32
fun MapUserPhysicalPagesScatter = MapUserPhysicalPagesScatter(
VirtualAddresses : Void**, # void**
NumberOfPages : LibC::SizeT, # UINT_PTR
PageArray : LibC::SizeT* # UINT_PTR* optional
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef MapUserPhysicalPagesScatterNative = Int32 Function(Pointer<Void>, UintPtr, Pointer<UintPtr>);
typedef MapUserPhysicalPagesScatterDart = int Function(Pointer<Void>, int, Pointer<UintPtr>);
final MapUserPhysicalPagesScatter = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<MapUserPhysicalPagesScatterNative, MapUserPhysicalPagesScatterDart>('MapUserPhysicalPagesScatter');
// VirtualAddresses : void** -> Pointer<Void>
// NumberOfPages : UINT_PTR -> UintPtr
// PageArray : UINT_PTR* optional -> Pointer<UintPtr>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function MapUserPhysicalPagesScatter(
VirtualAddresses: Pointer; // void**
NumberOfPages: NativeUInt; // UINT_PTR
PageArray: Pointer // UINT_PTR* optional
): BOOL; stdcall;
external 'KERNEL32.dll' name 'MapUserPhysicalPagesScatter';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "MapUserPhysicalPagesScatter"
c_MapUserPhysicalPagesScatter :: Ptr () -> CUIntPtr -> Ptr CUIntPtr -> IO CInt
-- VirtualAddresses : void** -> Ptr ()
-- NumberOfPages : UINT_PTR -> CUIntPtr
-- PageArray : UINT_PTR* optional -> Ptr CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let mapuserphysicalpagesscatter =
foreign "MapUserPhysicalPagesScatter"
((ptr void) @-> size_t @-> (ptr size_t) @-> returning int32_t)
(* VirtualAddresses : void** -> (ptr void) *)
(* NumberOfPages : UINT_PTR -> size_t *)
(* PageArray : UINT_PTR* optional -> (ptr size_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("MapUserPhysicalPagesScatter" map-user-physical-pages-scatter :convention :stdcall) :int32
(virtual-addresses :pointer) ; void**
(number-of-pages :uint64) ; UINT_PTR
(page-array :pointer)) ; UINT_PTR* optional
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $MapUserPhysicalPagesScatter = Win32::API::More->new('KERNEL32',
'BOOL MapUserPhysicalPagesScatter(LPVOID VirtualAddresses, WPARAM NumberOfPages, LPVOID PageArray)');
# my $ret = $MapUserPhysicalPagesScatter->Call($VirtualAddresses, $NumberOfPages, $PageArray);
# VirtualAddresses : void** -> LPVOID
# NumberOfPages : UINT_PTR -> WPARAM
# PageArray : UINT_PTR* optional -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。関連項目
- f AllocateUserPhysicalPages — AWE用に物理メモリページを割り当てる。
- f FreeUserPhysicalPages — AWEで割り当てた物理メモリページを解放する。
- f MapUserPhysicalPages — AWE物理ページを仮想アドレス領域にマップする。