ホーム › System.Environment › EnclaveCopyOutOfEnclave
EnclaveCopyOutOfEnclave
関数エンクレーブ内から非保護領域へデータをコピーする。
シグネチャ
// vertdll.dll
#include <windows.h>
HRESULT EnclaveCopyOutOfEnclave(
void* UnsecureAddress,
const void* EnclaveAddress,
UINT_PTR NumberOfBytes
);パラメーター
| 名前 | 型 | 方向 | 説明 |
|---|---|---|---|
| UnsecureAddress | void* | out | コピー先となる非セキュア(通常)メモリのアドレス。 |
| EnclaveAddress | void* | in | コピー元となるエンクレーブ内のアドレス。 |
| NumberOfBytes | UINT_PTR | in | コピーするバイト数。 |
戻り値の型: HRESULT
各言語での呼び出し定義
// vertdll.dll
#include <windows.h>
HRESULT EnclaveCopyOutOfEnclave(
void* UnsecureAddress,
const void* EnclaveAddress,
UINT_PTR NumberOfBytes
);[DllImport("vertdll.dll", ExactSpelling = true)]
static extern int EnclaveCopyOutOfEnclave(
IntPtr UnsecureAddress, // void* out
IntPtr EnclaveAddress, // void*
UIntPtr NumberOfBytes // UINT_PTR
);<DllImport("vertdll.dll", ExactSpelling:=True)>
Public Shared Function EnclaveCopyOutOfEnclave(
UnsecureAddress As IntPtr, ' void* out
EnclaveAddress As IntPtr, ' void*
NumberOfBytes As UIntPtr ' UINT_PTR
) As Integer
End Function' UnsecureAddress : void* out
' EnclaveAddress : void*
' NumberOfBytes : UINT_PTR
Declare PtrSafe Function EnclaveCopyOutOfEnclave Lib "vertdll" ( _
ByVal UnsecureAddress As LongPtr, _
ByVal EnclaveAddress As LongPtr, _
ByVal NumberOfBytes As LongPtr) As Long
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
EnclaveCopyOutOfEnclave = ctypes.windll.vertdll.EnclaveCopyOutOfEnclave
EnclaveCopyOutOfEnclave.restype = ctypes.c_int
EnclaveCopyOutOfEnclave.argtypes = [
ctypes.POINTER(None), # UnsecureAddress : void* out
ctypes.POINTER(None), # EnclaveAddress : void*
ctypes.c_size_t, # NumberOfBytes : UINT_PTR
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('vertdll.dll')
EnclaveCopyOutOfEnclave = Fiddle::Function.new(
lib['EnclaveCopyOutOfEnclave'],
[
Fiddle::TYPE_VOIDP, # UnsecureAddress : void* out
Fiddle::TYPE_VOIDP, # EnclaveAddress : void*
Fiddle::TYPE_UINTPTR_T, # NumberOfBytes : UINT_PTR
],
Fiddle::TYPE_INT)#[link(name = "vertdll")]
extern "system" {
fn EnclaveCopyOutOfEnclave(
UnsecureAddress: *mut (), // void* out
EnclaveAddress: *const (), // void*
NumberOfBytes: usize // UINT_PTR
) -> i32;
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("vertdll.dll")]
public static extern int EnclaveCopyOutOfEnclave(IntPtr UnsecureAddress, IntPtr EnclaveAddress, UIntPtr NumberOfBytes);
"@
$api = Add-Type -MemberDefinition $sig -Name 'vertdll_EnclaveCopyOutOfEnclave' -Namespace Win32 -PassThru
# $api::EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)#uselib "vertdll.dll"
#func global EnclaveCopyOutOfEnclave "EnclaveCopyOutOfEnclave" sptr, sptr, sptr
; EnclaveCopyOutOfEnclave UnsecureAddress, EnclaveAddress, NumberOfBytes ; 戻り値は stat
; UnsecureAddress : void* out -> "sptr"
; EnclaveAddress : void* -> "sptr"
; NumberOfBytes : UINT_PTR -> "sptr"
; ※HSP3.7は #func のため戻り値はシステム変数 stat に格納されます。#uselib "vertdll.dll"
#cfunc global EnclaveCopyOutOfEnclave "EnclaveCopyOutOfEnclave" sptr, sptr, sptr
; res = EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
; UnsecureAddress : void* out -> "sptr"
; EnclaveAddress : void* -> "sptr"
; NumberOfBytes : UINT_PTR -> "sptr"; HRESULT EnclaveCopyOutOfEnclave(void* UnsecureAddress, void* EnclaveAddress, UINT_PTR NumberOfBytes)
#uselib "vertdll.dll"
#cfunc global EnclaveCopyOutOfEnclave "EnclaveCopyOutOfEnclave" intptr, intptr, intptr
; res = EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
; UnsecureAddress : void* out -> "intptr"
; EnclaveAddress : void* -> "intptr"
; NumberOfBytes : UINT_PTR -> "intptr"import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
vertdll = windows.NewLazySystemDLL("vertdll.dll")
procEnclaveCopyOutOfEnclave = vertdll.NewProc("EnclaveCopyOutOfEnclave")
)
// UnsecureAddress (void* out), EnclaveAddress (void*), NumberOfBytes (UINT_PTR)
r1, _, err := procEnclaveCopyOutOfEnclave.Call(
uintptr(UnsecureAddress),
uintptr(EnclaveAddress),
uintptr(NumberOfBytes),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // HRESULTfunction EnclaveCopyOutOfEnclave(
UnsecureAddress: Pointer; // void* out
EnclaveAddress: Pointer; // void*
NumberOfBytes: NativeUInt // UINT_PTR
): Integer; stdcall;
external 'vertdll.dll' name 'EnclaveCopyOutOfEnclave';result := DllCall("vertdll\EnclaveCopyOutOfEnclave"
, "Ptr", UnsecureAddress ; void* out
, "Ptr", EnclaveAddress ; void*
, "UPtr", NumberOfBytes ; UINT_PTR
, "Int") ; return: HRESULT●EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes) = DLL("vertdll.dll", "int EnclaveCopyOutOfEnclave(void*, void*, int)")
# 呼び出し: EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
# UnsecureAddress : void* out -> "void*"
# EnclaveAddress : void* -> "void*"
# NumberOfBytes : UINT_PTR -> "int"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。const std = @import("std");
extern "vertdll" fn EnclaveCopyOutOfEnclave(
UnsecureAddress: ?*anyopaque, // void* out
EnclaveAddress: ?*anyopaque, // void*
NumberOfBytes: usize // UINT_PTR
) callconv(std.os.windows.WINAPI) i32;proc EnclaveCopyOutOfEnclave(
UnsecureAddress: pointer, # void* out
EnclaveAddress: pointer, # void*
NumberOfBytes: uint # UINT_PTR
): int32 {.importc: "EnclaveCopyOutOfEnclave", stdcall, dynlib: "vertdll.dll".}pragma(lib, "vertdll");
extern(Windows)
int EnclaveCopyOutOfEnclave(
void* UnsecureAddress, // void* out
void* EnclaveAddress, // void*
size_t NumberOfBytes // UINT_PTR
);ccall((:EnclaveCopyOutOfEnclave, "vertdll.dll"), stdcall, Int32,
(Ptr{Cvoid}, Ptr{Cvoid}, Csize_t),
UnsecureAddress, EnclaveAddress, NumberOfBytes)
# UnsecureAddress : void* out -> Ptr{Cvoid}
# EnclaveAddress : void* -> Ptr{Cvoid}
# NumberOfBytes : UINT_PTR -> Csize_t
# stdcall は 32bit のみ意味を持つ(x64 では無視)。local ffi = require("ffi")
ffi.cdef[[
int32_t EnclaveCopyOutOfEnclave(
void* UnsecureAddress,
void* EnclaveAddress,
uintptr_t NumberOfBytes);
]]
local vertdll = ffi.load("vertdll")
-- vertdll.EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
-- UnsecureAddress : void* out
-- EnclaveAddress : void*
-- NumberOfBytes : UINT_PTR
-- 構造体/GUIDへのポインタは cdef が通るよう void* で表記(実型は各引数コメント参照)。値渡し構造体・enum は対応する typedef を cdef に追加すること。const koffi = require('koffi');
const lib = koffi.load('vertdll.dll');
const EnclaveCopyOutOfEnclave = lib.func('__stdcall', 'EnclaveCopyOutOfEnclave', 'int32_t', ['void *', 'void *', 'uintptr_t']);
// EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
// UnsecureAddress : void* out -> 'void *'
// EnclaveAddress : void* -> 'void *'
// NumberOfBytes : UINT_PTR -> 'uintptr_t'
// 出力ポインタは koffi.out(...) で包む。構造体は koffi.struct で定義。const lib = Deno.dlopen("vertdll.dll", {
EnclaveCopyOutOfEnclave: { parameters: ["pointer", "pointer", "usize"], result: "i32" },
});
// lib.symbols.EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes)
// UnsecureAddress : void* out -> "pointer"
// EnclaveAddress : void* -> "pointer"
// NumberOfBytes : UINT_PTR -> "usize"
// 文字列引数は "buffer"(NUL 終端のバイト列を Uint8Array で渡す)。
// 値渡し構造体は { struct: [ ...field types... ] } を使用。<?php
$ffi = FFI::cdef(<<<C
int32_t EnclaveCopyOutOfEnclave(
void* UnsecureAddress,
void* EnclaveAddress,
size_t NumberOfBytes);
C, "vertdll.dll");
// $ffi->EnclaveCopyOutOfEnclave(UnsecureAddress, EnclaveAddress, NumberOfBytes);
// UnsecureAddress : void* out
// EnclaveAddress : void*
// NumberOfBytes : UINT_PTR
// 構造体/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 Vertdll extends StdCallLibrary {
Vertdll INSTANCE = Native.load("vertdll", Vertdll.class);
int EnclaveCopyOutOfEnclave(
Pointer UnsecureAddress, // void* out
Pointer EnclaveAddress, // void*
long NumberOfBytes // UINT_PTR
);
}@[Link("vertdll")]
lib Libvertdll
fun EnclaveCopyOutOfEnclave = EnclaveCopyOutOfEnclave(
UnsecureAddress : Void*, # void* out
EnclaveAddress : Void*, # void*
NumberOfBytes : LibC::SizeT # UINT_PTR
) : Int32
end
# 構造体/GUID/enum は lib 内に対応する型定義が必要。
# 呼出規約: x64 は規約統一のため OK。x86(32bit)は WINAPI=stdcall だが Crystal の fun に stdcall 付与構文がなく非対応。import 'dart:ffi';
import 'package:ffi/ffi.dart';
typedef EnclaveCopyOutOfEnclaveNative = Int32 Function(Pointer<Void>, Pointer<Void>, UintPtr);
typedef EnclaveCopyOutOfEnclaveDart = int Function(Pointer<Void>, Pointer<Void>, int);
final EnclaveCopyOutOfEnclave = DynamicLibrary.open('vertdll.dll')
.lookupFunction<EnclaveCopyOutOfEnclaveNative, EnclaveCopyOutOfEnclaveDart>('EnclaveCopyOutOfEnclave');
// UnsecureAddress : void* out -> Pointer<Void>
// EnclaveAddress : void* -> Pointer<Void>
// NumberOfBytes : UINT_PTR -> UintPtr
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。{$mode objfpc}{$H+}
function EnclaveCopyOutOfEnclave(
UnsecureAddress: Pointer; // void* out
EnclaveAddress: Pointer; // void*
NumberOfBytes: NativeUInt // UINT_PTR
): Integer; stdcall;
external 'vertdll.dll' name 'EnclaveCopyOutOfEnclave';import Foreign
import Foreign.C.Types
import Foreign.C.String
foreign import stdcall safe "EnclaveCopyOutOfEnclave"
c_EnclaveCopyOutOfEnclave :: Ptr () -> Ptr () -> CUIntPtr -> IO Int32
-- UnsecureAddress : void* out -> Ptr ()
-- EnclaveAddress : void* -> Ptr ()
-- NumberOfBytes : UINT_PTR -> CUIntPtr
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。open Ctypes
open Foreign
let enclavecopyoutofenclave =
foreign "EnclaveCopyOutOfEnclave"
((ptr void) @-> (ptr void) @-> size_t @-> returning int32_t)
(* UnsecureAddress : void* out -> (ptr void) *)
(* EnclaveAddress : void* -> (ptr void) *)
(* NumberOfBytes : UINT_PTR -> size_t *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)(cffi:define-foreign-library vertdll (t "vertdll.dll"))
(cffi:use-foreign-library vertdll)
(cffi:defcfun ("EnclaveCopyOutOfEnclave" enclave-copy-out-of-enclave :convention :stdcall) :int32
(unsecure-address :pointer) ; void* out
(enclave-address :pointer) ; void*
(number-of-bytes :uint64)) ; UINT_PTR
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。use Win32::API;
my $EnclaveCopyOutOfEnclave = Win32::API::More->new('vertdll',
'int EnclaveCopyOutOfEnclave(LPVOID UnsecureAddress, LPVOID EnclaveAddress, WPARAM NumberOfBytes)');
# my $ret = $EnclaveCopyOutOfEnclave->Call($UnsecureAddress, $EnclaveAddress, $NumberOfBytes);
# UnsecureAddress : void* out -> LPVOID
# EnclaveAddress : void* -> LPVOID
# NumberOfBytes : UINT_PTR -> WPARAM
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。