ホーム › System.Environment › CreateEnclave
CreateEnclave
関数プロセス内に指定種別のセキュアエンクレーブを作成する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
void* CreateEnclave(
HANDLE hProcess,
void* lpAddress, // optional
UINT_PTR dwSize,
UINT_PTR dwInitialCommitment,
DWORD flEnclaveType,
const void* lpEnclaveInformation,
DWORD dwInfoLength,
DWORD* lpEnclaveError // optional
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| hProcess | HANDLE | in | エンクレーブを作成する対象プロセスのハンドル。 |
| lpAddress | void* | inoptional | エンクレーブを配置する希望アドレス。任意の場合はNULL可。 |
| dwSize | UINT_PTR | in | エンクレーブ用に予約する仮想アドレス空間のサイズ(バイト)。 |
| dwInitialCommitment | UINT_PTR | in | 初期コミットするバイト数。 |
| flEnclaveType | DWORD | in | 作成するエンクレーブの種別(ENCLAVE_TYPE_SGX等)。 |
| lpEnclaveInformation | void* | in | 種別固有の構成情報を格納した構造体へのポインタ。 |
| dwInfoLength | DWORD | in | lpEnclaveInformationのサイズ(バイト)。 |
| lpEnclaveError | DWORD* | outoptional | 種別固有のエラーコードを受け取るDWORDへのポインタ。NULL可。 |
戻り値の型: void*
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
void* CreateEnclave(
HANDLE hProcess,
void* lpAddress, // optional
UINT_PTR dwSize,
UINT_PTR dwInitialCommitment,
DWORD flEnclaveType,
const void* lpEnclaveInformation,
DWORD dwInfoLength,
DWORD* lpEnclaveError // optional
);[DllImport("KERNEL32.dll", SetLastError = true, ExactSpelling = true)]
static extern IntPtr CreateEnclave(
IntPtr hProcess, // HANDLE
IntPtr lpAddress, // void* optional
UIntPtr dwSize, // UINT_PTR
UIntPtr dwInitialCommitment, // UINT_PTR
uint flEnclaveType, // DWORD
IntPtr lpEnclaveInformation, // void*
uint dwInfoLength, // DWORD
IntPtr lpEnclaveError // DWORD* optional, out
);<DllImport("KERNEL32.dll", SetLastError:=True, ExactSpelling:=True)>
Public Shared Function CreateEnclave(
hProcess As IntPtr, ' HANDLE
lpAddress As IntPtr, ' void* optional
dwSize As UIntPtr, ' UINT_PTR
dwInitialCommitment As UIntPtr, ' UINT_PTR
flEnclaveType As UInteger, ' DWORD
lpEnclaveInformation As IntPtr, ' void*
dwInfoLength As UInteger, ' DWORD
lpEnclaveError As IntPtr ' DWORD* optional, out
) As IntPtr
End Function' hProcess : HANDLE
' lpAddress : void* optional
' dwSize : UINT_PTR
' dwInitialCommitment : UINT_PTR
' flEnclaveType : DWORD
' lpEnclaveInformation : void*
' dwInfoLength : DWORD
' lpEnclaveError : DWORD* optional, out
Declare PtrSafe Function CreateEnclave Lib "kernel32" ( _
ByVal hProcess As LongPtr, _
ByVal lpAddress As LongPtr, _
ByVal dwSize As LongPtr, _
ByVal dwInitialCommitment As LongPtr, _
ByVal flEnclaveType As Long, _
ByVal lpEnclaveInformation As LongPtr, _
ByVal dwInfoLength As Long, _
ByVal lpEnclaveError As LongPtr) As LongPtr
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
CreateEnclave = ctypes.windll.kernel32.CreateEnclave
CreateEnclave.restype = ctypes.c_void_p
CreateEnclave.argtypes = [
wintypes.HANDLE, # hProcess : HANDLE
ctypes.POINTER(None), # lpAddress : void* optional
ctypes.c_size_t, # dwSize : UINT_PTR
ctypes.c_size_t, # dwInitialCommitment : UINT_PTR
wintypes.DWORD, # flEnclaveType : DWORD
ctypes.POINTER(None), # lpEnclaveInformation : void*
wintypes.DWORD, # dwInfoLength : DWORD
ctypes.POINTER(wintypes.DWORD), # lpEnclaveError : DWORD* optional, out
]
# GetLastError: use ctypes.GetLastError() (or ctypes.WinDLL(use_last_error=True))require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
CreateEnclave = Fiddle::Function.new(
lib['CreateEnclave'],
[
Fiddle::TYPE_VOIDP, # hProcess : HANDLE
Fiddle::TYPE_VOIDP, # lpAddress : void* optional
Fiddle::TYPE_UINTPTR_T, # dwSize : UINT_PTR
Fiddle::TYPE_UINTPTR_T, # dwInitialCommitment : UINT_PTR
-Fiddle::TYPE_INT, # flEnclaveType : DWORD
Fiddle::TYPE_VOIDP, # lpEnclaveInformation : void*
-Fiddle::TYPE_INT, # dwInfoLength : DWORD
Fiddle::TYPE_VOIDP, # lpEnclaveError : DWORD* optional, out
],
Fiddle::TYPE_VOIDP)#[link(name = "kernel32")]
extern "system" {
fn CreateEnclave(
hProcess: *mut core::ffi::c_void, // HANDLE
lpAddress: *mut (), // void* optional
dwSize: usize, // UINT_PTR
dwInitialCommitment: usize, // UINT_PTR
flEnclaveType: u32, // DWORD
lpEnclaveInformation: *const (), // void*
dwInfoLength: u32, // DWORD
lpEnclaveError: *mut u32 // DWORD* optional, out
) -> *mut ();
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll", SetLastError = true)]
public static extern IntPtr CreateEnclave(IntPtr hProcess, IntPtr lpAddress, UIntPtr dwSize, UIntPtr dwInitialCommitment, uint flEnclaveType, IntPtr lpEnclaveInformation, uint dwInfoLength, IntPtr lpEnclaveError);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_CreateEnclave' -Namespace Win32 -PassThru
# $api::CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)#uselib "KERNEL32.dll"
#func global CreateEnclave "CreateEnclave" sptr, sptr, sptr, sptr, sptr, sptr, sptr, sptr
; CreateEnclave hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError) ; 戻り値は stat
; hProcess : HANDLE -> "sptr"
; lpAddress : void* optional -> "sptr"
; dwSize : UINT_PTR -> "sptr"
; dwInitialCommitment : UINT_PTR -> "sptr"
; flEnclaveType : DWORD -> "sptr"
; lpEnclaveInformation : void* -> "sptr"
; dwInfoLength : DWORD -> "sptr"
; lpEnclaveError : DWORD* optional, out -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。出力引数:
#uselib "KERNEL32.dll" #cfunc global CreateEnclave "CreateEnclave" sptr, sptr, sptr, sptr, int, sptr, int, var ; res = CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* optional -> "sptr" ; dwSize : UINT_PTR -> "sptr" ; dwInitialCommitment : UINT_PTR -> "sptr" ; flEnclaveType : DWORD -> "int" ; lpEnclaveInformation : void* -> "sptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #cfunc global CreateEnclave "CreateEnclave" sptr, sptr, sptr, sptr, int, sptr, int, sptr ; res = CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError)) ; hProcess : HANDLE -> "sptr" ; lpAddress : void* optional -> "sptr" ; dwSize : UINT_PTR -> "sptr" ; dwInitialCommitment : UINT_PTR -> "sptr" ; flEnclaveType : DWORD -> "int" ; lpEnclaveInformation : void* -> "sptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void* CreateEnclave(HANDLE hProcess, void* lpAddress, UINT_PTR dwSize, UINT_PTR dwInitialCommitment, DWORD flEnclaveType, void* lpEnclaveInformation, DWORD dwInfoLength, DWORD* lpEnclaveError) #uselib "KERNEL32.dll" #cfunc global CreateEnclave "CreateEnclave" intptr, intptr, intptr, intptr, int, intptr, int, var ; res = CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* optional -> "intptr" ; dwSize : UINT_PTR -> "intptr" ; dwInitialCommitment : UINT_PTR -> "intptr" ; flEnclaveType : DWORD -> "int" ; lpEnclaveInformation : void* -> "intptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void* CreateEnclave(HANDLE hProcess, void* lpAddress, UINT_PTR dwSize, UINT_PTR dwInitialCommitment, DWORD flEnclaveType, void* lpEnclaveInformation, DWORD dwInfoLength, DWORD* lpEnclaveError) #uselib "KERNEL32.dll" #cfunc global CreateEnclave "CreateEnclave" intptr, intptr, intptr, intptr, int, intptr, int, intptr ; res = CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, varptr(lpEnclaveError)) ; hProcess : HANDLE -> "intptr" ; lpAddress : void* optional -> "intptr" ; dwSize : UINT_PTR -> "intptr" ; dwInitialCommitment : UINT_PTR -> "intptr" ; flEnclaveType : DWORD -> "int" ; lpEnclaveInformation : void* -> "intptr" ; dwInfoLength : DWORD -> "int" ; lpEnclaveError : DWORD* optional, out -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procCreateEnclave = kernel32.NewProc("CreateEnclave")
)
// hProcess (HANDLE), lpAddress (void* optional), dwSize (UINT_PTR), dwInitialCommitment (UINT_PTR), flEnclaveType (DWORD), lpEnclaveInformation (void*), dwInfoLength (DWORD), lpEnclaveError (DWORD* optional, out)
r1, _, err := procCreateEnclave.Call(
uintptr(hProcess),
uintptr(lpAddress),
uintptr(dwSize),
uintptr(dwInitialCommitment),
uintptr(flEnclaveType),
uintptr(lpEnclaveInformation),
uintptr(dwInfoLength),
uintptr(lpEnclaveError),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // void*function CreateEnclave(
hProcess: THandle; // HANDLE
lpAddress: Pointer; // void* optional
dwSize: NativeUInt; // UINT_PTR
dwInitialCommitment: NativeUInt; // UINT_PTR
flEnclaveType: DWORD; // DWORD
lpEnclaveInformation: Pointer; // void*
dwInfoLength: DWORD; // DWORD
lpEnclaveError: Pointer // DWORD* optional, out
): Pointer; stdcall;
external 'KERNEL32.dll' name 'CreateEnclave';result := DllCall("KERNEL32\CreateEnclave"
, "Ptr", hProcess ; HANDLE
, "Ptr", lpAddress ; void* optional
, "UPtr", dwSize ; UINT_PTR
, "UPtr", dwInitialCommitment ; UINT_PTR
, "UInt", flEnclaveType ; DWORD
, "Ptr", lpEnclaveInformation ; void*
, "UInt", dwInfoLength ; DWORD
, "Ptr", lpEnclaveError ; DWORD* optional, out
, "Ptr") ; return: void*●CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError) = DLL("KERNEL32.dll", "void* CreateEnclave(void*, void*, int, int, dword, void*, dword, void*)")
# 呼び出し: CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
# hProcess : HANDLE -> "void*"
# lpAddress : void* optional -> "void*"
# dwSize : UINT_PTR -> "int"
# dwInitialCommitment : UINT_PTR -> "int"
# flEnclaveType : DWORD -> "dword"
# lpEnclaveInformation : void* -> "void*"
# dwInfoLength : DWORD -> "dword"
# lpEnclaveError : DWORD* optional, out -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "kernel32" fn CreateEnclave(
hProcess: ?*anyopaque, // HANDLE
lpAddress: ?*anyopaque, // void* optional
dwSize: usize, // UINT_PTR
dwInitialCommitment: usize, // UINT_PTR
flEnclaveType: u32, // DWORD
lpEnclaveInformation: ?*anyopaque, // void*
dwInfoLength: u32, // DWORD
lpEnclaveError: [*c]u32 // DWORD* optional, out
) callconv(std.os.windows.WINAPI) ?*anyopaque;proc CreateEnclave(
hProcess: pointer, # HANDLE
lpAddress: pointer, # void* optional
dwSize: uint, # UINT_PTR
dwInitialCommitment: uint, # UINT_PTR
flEnclaveType: uint32, # DWORD
lpEnclaveInformation: pointer, # void*
dwInfoLength: uint32, # DWORD
lpEnclaveError: ptr uint32 # DWORD* optional, out
): pointer {.importc: "CreateEnclave", stdcall, dynlib: "KERNEL32.dll".}pragma(lib, "kernel32");
extern(Windows)
void* CreateEnclave(
void* hProcess, // HANDLE
void* lpAddress, // void* optional
size_t dwSize, // UINT_PTR
size_t dwInitialCommitment, // UINT_PTR
uint flEnclaveType, // DWORD
void* lpEnclaveInformation, // void*
uint dwInfoLength, // DWORD
uint* lpEnclaveError // DWORD* optional, out
);ccall((:CreateEnclave, "KERNEL32.dll"), stdcall, Ptr{Cvoid},
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t, Csize_t, UInt32, Ptr{Cvoid}, UInt32, Ptr{UInt32}),
hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
# hProcess : HANDLE -> Ptr{Cvoid}
# lpAddress : void* optional -> Ptr{Cvoid}
# dwSize : UINT_PTR -> Csize_t
# dwInitialCommitment : UINT_PTR -> Csize_t
# flEnclaveType : DWORD -> UInt32
# lpEnclaveInformation : void* -> Ptr{Cvoid}
# dwInfoLength : DWORD -> UInt32
# lpEnclaveError : DWORD* optional, out -> Ptr{UInt32}
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
void* CreateEnclave(
void* hProcess,
void* lpAddress,
uintptr_t dwSize,
uintptr_t dwInitialCommitment,
uint32_t flEnclaveType,
void* lpEnclaveInformation,
uint32_t dwInfoLength,
uint32_t* lpEnclaveError);
]]
local kernel32 = ffi.load("kernel32")
-- kernel32.CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
-- hProcess : HANDLE
-- lpAddress : void* optional
-- dwSize : UINT_PTR
-- dwInitialCommitment : UINT_PTR
-- flEnclaveType : DWORD
-- lpEnclaveInformation : void*
-- dwInfoLength : DWORD
-- lpEnclaveError : DWORD* optional, out
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('KERNEL32.dll');
const CreateEnclave = lib.func('__stdcall', 'CreateEnclave', 'void *', ['void *', 'void *', 'uintptr_t', 'uintptr_t', 'uint32_t', 'void *', 'uint32_t', 'uint32_t *']);
// CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
// hProcess : HANDLE -> 'void *'
// lpAddress : void* optional -> 'void *'
// dwSize : UINT_PTR -> 'uintptr_t'
// dwInitialCommitment : UINT_PTR -> 'uintptr_t'
// flEnclaveType : DWORD -> 'uint32_t'
// lpEnclaveInformation : void* -> 'void *'
// dwInfoLength : DWORD -> 'uint32_t'
// lpEnclaveError : DWORD* optional, out -> 'uint32_t *'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("KERNEL32.dll", {
CreateEnclave: { parameters: ["pointer", "pointer", "usize", "usize", "u32", "pointer", "u32", "pointer"], result: "pointer" },
});
// lib.symbols.CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError)
// hProcess : HANDLE -> "pointer"
// lpAddress : void* optional -> "pointer"
// dwSize : UINT_PTR -> "usize"
// dwInitialCommitment : UINT_PTR -> "usize"
// flEnclaveType : DWORD -> "u32"
// lpEnclaveInformation : void* -> "pointer"
// dwInfoLength : DWORD -> "u32"
// lpEnclaveError : DWORD* optional, out -> "pointer"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
void* CreateEnclave(
void* hProcess,
void* lpAddress,
size_t dwSize,
size_t dwInitialCommitment,
uint32_t flEnclaveType,
void* lpEnclaveInformation,
uint32_t dwInfoLength,
uint32_t* lpEnclaveError);
C, "KERNEL32.dll");
// $ffi->CreateEnclave(hProcess, lpAddress, dwSize, dwInitialCommitment, flEnclaveType, lpEnclaveInformation, dwInfoLength, lpEnclaveError);
// hProcess : HANDLE
// lpAddress : void* optional
// dwSize : UINT_PTR
// dwInitialCommitment : UINT_PTR
// flEnclaveType : DWORD
// lpEnclaveInformation : void*
// dwInfoLength : DWORD
// lpEnclaveError : DWORD* optional, 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 Kernel32 extends StdCallLibrary {
Kernel32 INSTANCE = Native.load("kernel32", Kernel32.class);
Pointer CreateEnclave(
Pointer hProcess, // HANDLE
Pointer lpAddress, // void* optional
long dwSize, // UINT_PTR
long dwInitialCommitment, // UINT_PTR
int flEnclaveType, // DWORD
Pointer lpEnclaveInformation, // void*
int dwInfoLength, // DWORD
IntByReference lpEnclaveError // DWORD* optional, out
);
}@[Link("kernel32")]
lib LibKERNEL32
fun CreateEnclave = CreateEnclave(
hProcess : Void*, # HANDLE
lpAddress : Void*, # void* optional
dwSize : LibC::SizeT, # UINT_PTR
dwInitialCommitment : LibC::SizeT, # UINT_PTR
flEnclaveType : UInt32, # DWORD
lpEnclaveInformation : Void*, # void*
dwInfoLength : UInt32, # DWORD
lpEnclaveError : UInt32* # DWORD* optional, out
) : Void*
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef CreateEnclaveNative = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, UintPtr, UintPtr, Uint32, Pointer<Void>, Uint32, Pointer<Uint32>);
typedef CreateEnclaveDart = Pointer<Void> Function(Pointer<Void>, Pointer<Void>, int, int, int, Pointer<Void>, int, Pointer<Uint32>);
final CreateEnclave = DynamicLibrary.open('KERNEL32.dll')
.lookupFunction<CreateEnclaveNative, CreateEnclaveDart>('CreateEnclave');
// hProcess : HANDLE -> Pointer<Void>
// lpAddress : void* optional -> Pointer<Void>
// dwSize : UINT_PTR -> UintPtr
// dwInitialCommitment : UINT_PTR -> UintPtr
// flEnclaveType : DWORD -> Uint32
// lpEnclaveInformation : void* -> Pointer<Void>
// dwInfoLength : DWORD -> Uint32
// lpEnclaveError : DWORD* optional, out -> Pointer<Uint32>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function CreateEnclave(
hProcess: THandle; // HANDLE
lpAddress: Pointer; // void* optional
dwSize: NativeUInt; // UINT_PTR
dwInitialCommitment: NativeUInt; // UINT_PTR
flEnclaveType: DWORD; // DWORD
lpEnclaveInformation: Pointer; // void*
dwInfoLength: DWORD; // DWORD
lpEnclaveError: Pointer // DWORD* optional, out
): Pointer; stdcall;
external 'KERNEL32.dll' name 'CreateEnclave';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "CreateEnclave"
c_CreateEnclave :: Ptr () -> Ptr () -> CUIntPtr -> CUIntPtr -> Word32 -> Ptr () -> Word32 -> Ptr Word32 -> IO (Ptr ())
-- hProcess : HANDLE -> Ptr ()
-- lpAddress : void* optional -> Ptr ()
-- dwSize : UINT_PTR -> CUIntPtr
-- dwInitialCommitment : UINT_PTR -> CUIntPtr
-- flEnclaveType : DWORD -> Word32
-- lpEnclaveInformation : void* -> Ptr ()
-- dwInfoLength : DWORD -> Word32
-- lpEnclaveError : DWORD* optional, out -> Ptr Word32
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let createenclave =
foreign "CreateEnclave"
((ptr void) @-> (ptr void) @-> size_t @-> size_t @-> uint32_t @-> (ptr void) @-> uint32_t @-> (ptr uint32_t) @-> returning (ptr void))
(* hProcess : HANDLE -> (ptr void) *)
(* lpAddress : void* optional -> (ptr void) *)
(* dwSize : UINT_PTR -> size_t *)
(* dwInitialCommitment : UINT_PTR -> size_t *)
(* flEnclaveType : DWORD -> uint32_t *)
(* lpEnclaveInformation : void* -> (ptr void) *)
(* dwInfoLength : DWORD -> uint32_t *)
(* lpEnclaveError : DWORD* optional, out -> (ptr uint32_t) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)
(cffi:defcfun ("CreateEnclave" create-enclave :convention :stdcall) :pointer
(h-process :pointer) ; HANDLE
(lp-address :pointer) ; void* optional
(dw-size :uint64) ; UINT_PTR
(dw-initial-commitment :uint64) ; UINT_PTR
(fl-enclave-type :uint32) ; DWORD
(lp-enclave-information :pointer) ; void*
(dw-info-length :uint32) ; DWORD
(lp-enclave-error :pointer)) ; DWORD* optional, out
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $CreateEnclave = Win32::API::More->new('KERNEL32',
'LPVOID CreateEnclave(HANDLE hProcess, LPVOID lpAddress, WPARAM dwSize, WPARAM dwInitialCommitment, DWORD flEnclaveType, LPVOID lpEnclaveInformation, DWORD dwInfoLength, LPVOID lpEnclaveError)');
# my $ret = $CreateEnclave->Call($hProcess, $lpAddress, $dwSize, $dwInitialCommitment, $flEnclaveType, $lpEnclaveInformation, $dwInfoLength, $lpEnclaveError);
# hProcess : HANDLE -> HANDLE
# lpAddress : void* optional -> LPVOID
# dwSize : UINT_PTR -> WPARAM
# dwInitialCommitment : UINT_PTR -> WPARAM
# flEnclaveType : DWORD -> DWORD
# lpEnclaveInformation : void* -> LPVOID
# dwInfoLength : DWORD -> DWORD
# lpEnclaveError : DWORD* optional, out -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。