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

AllocateUserPhysicalPagesNuma

関数
指定NUMAノードからAWE用物理メモリページを割り当てる。
DLLKERNEL32.dll呼出規約winapiSetLastErrorあり対応OSWindows Vista 以降

シグネチャ

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

BOOL AllocateUserPhysicalPagesNuma(
    HANDLE hProcess,
    UINT_PTR* NumberOfPages,
    UINT_PTR* PageArray,
    DWORD nndPreferred
);

パラメーター

名前方向説明
hProcessHANDLEin

プロセスへのハンドル。

この関数は、後でこのプロセスの仮想アドレス空間内にマップできるメモリを割り当てます。このハンドルには PROCESS_VM_OPERATION アクセス権が必要です。詳細については、Process Security and Access Rights を参照してください。

NumberOfPagesUINT_PTR*inout

割り当てる物理メモリのサイズ (ページ単位)。

コンピューターのページ サイズを確認するには、GetSystemInfo 関数を使用します。出力時には、このパラメーターは実際に割り当てられたページ数を受け取りますが、これは要求された数より少ない場合があります。

PageArrayUINT_PTR*out

割り当てられたメモリのページ フレーム番号を格納する配列へのポインター。

割り当てる配列のサイズは、少なくとも NumberOfPagesULONG_PTR データ型のサイズを掛けた値である必要があります。

注意 このバッファーを変更しようとしないでください。このバッファーにはオペレーティング システムのデータが含まれており、破損すると致命的な結果になる可能性があります。バッファー内の情報はアプリケーションにとって有用ではありません。
nndPreferredDWORDin物理メモリを配置する NUMA ノード。

戻り値の型: BOOL

公式ドキュメント

指定したプロセスの Address Windowing Extensions (AWE) 領域内でマップおよびアンマップする物理メモリ ページを割り当て、その物理メモリの NUMA ノードを指定します。

戻り値

関数が成功した場合、戻り値は TRUE です。

要求された数より少ないページが割り当てられる場合があります。呼び出し元は、戻り時に NumberOfPages パラメーターの値を確認して、割り当てられたページ数を調べる必要があります。割り当てられたすべてのページ フレーム番号は、PageArray パラメーターが指すメモリに順番に配置されます。

関数が失敗した場合、戻り値は FALSE で、フレームは割り当てられません。拡張エラー情報を取得するには、GetLastError 関数を呼び出します。

解説(Remarks)

AllocateUserPhysicalPagesNuma 関数は、後でプロセスの仮想アドレス空間内にマップできる物理メモリを NUMA ノード内に割り当てるために使用されます。呼び出し元のトークンで SeLockMemoryPrivilege 特権が有効になっている必要があり、そうでない場合、関数は ERROR_PRIVILEGE_NOT_HELD で失敗します。詳細については、Privilege Constants を参照してください。

この関数によって割り当てられるメモリは、システム上に物理的に存在している必要があります。メモリが割り当てられると、ロックされ、仮想メモリ管理システムの他の部分からは使用できなくなります。

物理ページを同時に複数の仮想アドレスにマップすることはできません。

物理ページは任意の物理アドレスに配置できます。物理ページの連続性については何も想定しないでください。

この関数を使用するアプリケーションをコンパイルするには、_WIN32_WINNT を 0x0600 以降として定義します。

出典・ライセンス: 上記「公式ドキュメント」の内容は Microsoft の Win32 API ドキュメント(MicrosoftDocs/sdk-api)を日本語に翻訳・改変したものです。© Microsoft Corporation. CC BY 4.0 で提供。
Microsoft 公式リファレンス: 英語 (en-us) · 日本語 (ja-jp) · 原文ソース (GitHub)

各言語での呼び出し定義

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

BOOL AllocateUserPhysicalPagesNuma(
    HANDLE hProcess,
    UINT_PTR* NumberOfPages,
    UINT_PTR* PageArray,
    DWORD nndPreferred
);
[return: MarshalAs(UnmanagedType.Bool)]
[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool AllocateUserPhysicalPagesNuma(
    IntPtr hProcess,   // HANDLE
    ref UIntPtr NumberOfPages,   // UINT_PTR* in/out
    out UIntPtr PageArray,   // UINT_PTR* out
    uint nndPreferred   // DWORD
);
<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function AllocateUserPhysicalPagesNuma(
    hProcess As IntPtr,   ' HANDLE
    ByRef NumberOfPages As UIntPtr,   ' UINT_PTR* in/out
    <Out> ByRef PageArray As UIntPtr,   ' UINT_PTR* out
    nndPreferred As UInteger   ' DWORD
) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
' hProcess : HANDLE
' NumberOfPages : UINT_PTR* in/out
' PageArray : UINT_PTR* out
' nndPreferred : DWORD
Declare PtrSafe Function AllocateUserPhysicalPagesNuma Lib "kernel32" ( _
    ByVal hProcess As LongPtr, _
    ByRef NumberOfPages As LongPtr, _
    ByRef PageArray As LongPtr, _
    ByVal nndPreferred As Long) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

AllocateUserPhysicalPagesNuma = ctypes.windll.kernel32.AllocateUserPhysicalPagesNuma
AllocateUserPhysicalPagesNuma.restype = wintypes.BOOL
AllocateUserPhysicalPagesNuma.argtypes = [
    wintypes.HANDLE,  # hProcess : HANDLE
    ctypes.POINTER(ctypes.c_size_t),  # NumberOfPages : UINT_PTR* in/out
    ctypes.POINTER(ctypes.c_size_t),  # PageArray : UINT_PTR* out
    wintypes.DWORD,  # nndPreferred : DWORD
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
AllocateUserPhysicalPagesNuma = Fiddle::Function.new(
  lib['AllocateUserPhysicalPagesNuma'],
  [
    Fiddle::TYPE_VOIDP,  # hProcess : HANDLE
    Fiddle::TYPE_VOIDP,  # NumberOfPages : UINT_PTR* in/out
    Fiddle::TYPE_VOIDP,  # PageArray : UINT_PTR* out
    -Fiddle::TYPE_INT,  # nndPreferred : DWORD
  ],
  Fiddle::TYPE_INT)
#[link(name = "kernel32")]
extern "system" {
    fn AllocateUserPhysicalPagesNuma(
        hProcess: *mut core::ffi::c_void,  // HANDLE
        NumberOfPages: *mut usize,  // UINT_PTR* in/out
        PageArray: *mut usize,  // UINT_PTR* out
        nndPreferred: u32  // DWORD
    ) -> 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 AllocateUserPhysicalPagesNuma(IntPtr hProcess, ref UIntPtr NumberOfPages, out UIntPtr PageArray, uint nndPreferred);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_AllocateUserPhysicalPagesNuma' -Namespace Win32 -PassThru
# $api::AllocateUserPhysicalPagesNuma(hProcess, NumberOfPages, PageArray, nndPreferred)
#uselib "KERNEL32.dll"
#func global AllocateUserPhysicalPagesNuma "AllocateUserPhysicalPagesNuma" sptr, sptr, sptr, sptr
; AllocateUserPhysicalPagesNuma hProcess, varptr(NumberOfPages), varptr(PageArray), nndPreferred   ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; NumberOfPages : UINT_PTR* in/out -> "sptr"
; PageArray : UINT_PTR* out -> "sptr"
; nndPreferred : DWORD -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。
出力引数:
#uselib "KERNEL32.dll"
#cfunc global AllocateUserPhysicalPagesNuma "AllocateUserPhysicalPagesNuma" sptr, var, var, int
; res = AllocateUserPhysicalPagesNuma(hProcess, NumberOfPages, PageArray, nndPreferred)
; hProcess : HANDLE -> "sptr"
; NumberOfPages : UINT_PTR* in/out -> "var"
; PageArray : UINT_PTR* out -> "var"
; nndPreferred : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; BOOL AllocateUserPhysicalPagesNuma(HANDLE hProcess, UINT_PTR* NumberOfPages, UINT_PTR* PageArray, DWORD nndPreferred)
#uselib "KERNEL32.dll"
#cfunc global AllocateUserPhysicalPagesNuma "AllocateUserPhysicalPagesNuma" intptr, var, var, int
; res = AllocateUserPhysicalPagesNuma(hProcess, NumberOfPages, PageArray, nndPreferred)
; hProcess : HANDLE -> "intptr"
; NumberOfPages : UINT_PTR* in/out -> "var"
; PageArray : UINT_PTR* out -> "var"
; nndPreferred : DWORD -> "int"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procAllocateUserPhysicalPagesNuma = kernel32.NewProc("AllocateUserPhysicalPagesNuma")
)

// hProcess (HANDLE), NumberOfPages (UINT_PTR* in/out), PageArray (UINT_PTR* out), nndPreferred (DWORD)
r1, _, err := procAllocateUserPhysicalPagesNuma.Call(
	uintptr(hProcess),
	uintptr(NumberOfPages),
	uintptr(PageArray),
	uintptr(nndPreferred),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // BOOL
function AllocateUserPhysicalPagesNuma(
  hProcess: THandle;   // HANDLE
  NumberOfPages: Pointer;   // UINT_PTR* in/out
  PageArray: Pointer;   // UINT_PTR* out
  nndPreferred: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'AllocateUserPhysicalPagesNuma';
result := DllCall("KERNEL32\AllocateUserPhysicalPagesNuma"
    , "Ptr", hProcess   ; HANDLE
    , "Ptr", NumberOfPages   ; UINT_PTR* in/out
    , "Ptr", PageArray   ; UINT_PTR* out
    , "UInt", nndPreferred   ; DWORD
    , "Int")   ; return: BOOL
●AllocateUserPhysicalPagesNuma(hProcess, NumberOfPages, PageArray, nndPreferred) = DLL("KERNEL32.dll", "bool AllocateUserPhysicalPagesNuma(void*, void*, void*, dword)")
# 呼び出し: AllocateUserPhysicalPagesNuma(hProcess, NumberOfPages, PageArray, nndPreferred)
# hProcess : HANDLE -> "void*"
# NumberOfPages : UINT_PTR* in/out -> "void*"
# PageArray : UINT_PTR* out -> "void*"
# nndPreferred : DWORD -> "dword"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef AllocateUserPhysicalPagesNumaNative = Int32 Function(Pointer<Void>, Pointer<UintPtr>, Pointer<UintPtr>, Uint32);
typedef AllocateUserPhysicalPagesNumaDart = int Function(Pointer<Void>, Pointer<UintPtr>, Pointer<UintPtr>, int);
final AllocateUserPhysicalPagesNuma = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<AllocateUserPhysicalPagesNumaNative, AllocateUserPhysicalPagesNumaDart>('AllocateUserPhysicalPagesNuma');
// hProcess : HANDLE -> Pointer<Void>
// NumberOfPages : UINT_PTR* in/out -> Pointer<UintPtr>
// PageArray : UINT_PTR* out -> Pointer<UintPtr>
// nndPreferred : DWORD -> Uint32
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
function AllocateUserPhysicalPagesNuma(
  hProcess: THandle;   // HANDLE
  NumberOfPages: Pointer;   // UINT_PTR* in/out
  PageArray: Pointer;   // UINT_PTR* out
  nndPreferred: DWORD   // DWORD
): BOOL; stdcall;
  external 'KERNEL32.dll' name 'AllocateUserPhysicalPagesNuma';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "AllocateUserPhysicalPagesNuma"
  c_AllocateUserPhysicalPagesNuma :: Ptr () -> Ptr CUIntPtr -> Ptr CUIntPtr -> Word32 -> IO CInt
-- hProcess : HANDLE -> Ptr ()
-- NumberOfPages : UINT_PTR* in/out -> Ptr CUIntPtr
-- PageArray : UINT_PTR* out -> Ptr CUIntPtr
-- nndPreferred : DWORD -> Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let allocateuserphysicalpagesnuma =
  foreign "AllocateUserPhysicalPagesNuma"
    ((ptr void) @-> (ptr size_t) @-> (ptr size_t) @-> uint32_t @-> returning int32_t)
(* hProcess : HANDLE -> (ptr void) *)
(* NumberOfPages : UINT_PTR* in/out -> (ptr size_t) *)
(* PageArray : UINT_PTR* out -> (ptr size_t) *)
(* nndPreferred : DWORD -> uint32_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("AllocateUserPhysicalPagesNuma" allocate-user-physical-pages-numa :convention :stdcall) :int32
  (h-process :pointer)   ; HANDLE
  (number-of-pages :pointer)   ; UINT_PTR* in/out
  (page-array :pointer)   ; UINT_PTR* out
  (nnd-preferred :uint32))   ; DWORD
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $AllocateUserPhysicalPagesNuma = Win32::API::More->new('KERNEL32',
    'BOOL AllocateUserPhysicalPagesNuma(HANDLE hProcess, LPVOID NumberOfPages, LPVOID PageArray, DWORD nndPreferred)');
# my $ret = $AllocateUserPhysicalPagesNuma->Call($hProcess, $NumberOfPages, $PageArray, $nndPreferred);
# hProcess : HANDLE -> HANDLE
# NumberOfPages : UINT_PTR* in/out -> LPVOID
# PageArray : UINT_PTR* out -> LPVOID
# nndPreferred : DWORD -> DWORD
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

公式の関連項目