ホーム › System.Diagnostics.Debug › RtlUnwindEx
RtlUnwindEx
関数指定フレームまで例外処理のスタック巻き戻しを実行する。
シグネチャ
// KERNEL32.dll
#include <windows.h>
void RtlUnwindEx(
void* TargetFrame, // optional
void* TargetIp, // optional
EXCEPTION_RECORD* ExceptionRecord, // optional
void* ReturnValue,
CONTEXT* ContextRecord,
UNWIND_HISTORY_TABLE* HistoryTable // optional
);パラメーター
| 名前 | 型 | 方向 |
|---|---|---|
| TargetFrame | void* | inoptional |
| TargetIp | void* | inoptional |
| ExceptionRecord | EXCEPTION_RECORD* | inoptional |
| ReturnValue | void* | in |
| ContextRecord | CONTEXT* | in |
| HistoryTable | UNWIND_HISTORY_TABLE* | inoptional |
戻り値の型: void
各言語での呼び出し定義
// KERNEL32.dll
#include <windows.h>
void RtlUnwindEx(
void* TargetFrame, // optional
void* TargetIp, // optional
EXCEPTION_RECORD* ExceptionRecord, // optional
void* ReturnValue,
CONTEXT* ContextRecord,
UNWIND_HISTORY_TABLE* HistoryTable // optional
);[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern void RtlUnwindEx(
IntPtr TargetFrame, // void* optional
IntPtr TargetIp, // void* optional
IntPtr ExceptionRecord, // EXCEPTION_RECORD* optional
IntPtr ReturnValue, // void*
IntPtr ContextRecord, // CONTEXT*
IntPtr HistoryTable // UNWIND_HISTORY_TABLE* optional
);<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Sub RtlUnwindEx(
TargetFrame As IntPtr, ' void* optional
TargetIp As IntPtr, ' void* optional
ExceptionRecord As IntPtr, ' EXCEPTION_RECORD* optional
ReturnValue As IntPtr, ' void*
ContextRecord As IntPtr, ' CONTEXT*
HistoryTable As IntPtr ' UNWIND_HISTORY_TABLE* optional
)
End Sub' TargetFrame : void* optional
' TargetIp : void* optional
' ExceptionRecord : EXCEPTION_RECORD* optional
' ReturnValue : void*
' ContextRecord : CONTEXT*
' HistoryTable : UNWIND_HISTORY_TABLE* optional
Declare PtrSafe Sub RtlUnwindEx Lib "kernel32" ( _
ByVal TargetFrame As LongPtr, _
ByVal TargetIp As LongPtr, _
ByVal ExceptionRecord As LongPtr, _
ByVal ReturnValue As LongPtr, _
ByVal ContextRecord As LongPtr, _
ByVal HistoryTable As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。import ctypes
from ctypes import wintypes
RtlUnwindEx = ctypes.windll.kernel32.RtlUnwindEx
RtlUnwindEx.restype = None
RtlUnwindEx.argtypes = [
ctypes.POINTER(None), # TargetFrame : void* optional
ctypes.POINTER(None), # TargetIp : void* optional
ctypes.c_void_p, # ExceptionRecord : EXCEPTION_RECORD* optional
ctypes.POINTER(None), # ReturnValue : void*
ctypes.c_void_p, # ContextRecord : CONTEXT*
ctypes.c_void_p, # HistoryTable : UNWIND_HISTORY_TABLE* optional
]require 'fiddle'
require 'fiddle/import'
lib = Fiddle.dlopen('KERNEL32.dll')
RtlUnwindEx = Fiddle::Function.new(
lib['RtlUnwindEx'],
[
Fiddle::TYPE_VOIDP, # TargetFrame : void* optional
Fiddle::TYPE_VOIDP, # TargetIp : void* optional
Fiddle::TYPE_VOIDP, # ExceptionRecord : EXCEPTION_RECORD* optional
Fiddle::TYPE_VOIDP, # ReturnValue : void*
Fiddle::TYPE_VOIDP, # ContextRecord : CONTEXT*
Fiddle::TYPE_VOIDP, # HistoryTable : UNWIND_HISTORY_TABLE* optional
],
Fiddle::TYPE_VOID)#[link(name = "kernel32")]
extern "system" {
fn RtlUnwindEx(
TargetFrame: *mut (), // void* optional
TargetIp: *mut (), // void* optional
ExceptionRecord: *mut EXCEPTION_RECORD, // EXCEPTION_RECORD* optional
ReturnValue: *mut (), // void*
ContextRecord: *mut CONTEXT, // CONTEXT*
HistoryTable: *mut UNWIND_HISTORY_TABLE // UNWIND_HISTORY_TABLE* optional
);
}
// crates: windows-sys provides ready-made bindings for this API.$sig = @"
[DllImport("KERNEL32.dll")]
public static extern void RtlUnwindEx(IntPtr TargetFrame, IntPtr TargetIp, IntPtr ExceptionRecord, IntPtr ReturnValue, IntPtr ContextRecord, IntPtr HistoryTable);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlUnwindEx' -Namespace Win32 -PassThru
# $api::RtlUnwindEx(TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable)#uselib "KERNEL32.dll"
#func global RtlUnwindEx "RtlUnwindEx" sptr, sptr, sptr, sptr, sptr, sptr
; RtlUnwindEx TargetFrame, TargetIp, varptr(ExceptionRecord), ReturnValue, varptr(ContextRecord), varptr(HistoryTable)
; TargetFrame : void* optional -> "sptr"
; TargetIp : void* optional -> "sptr"
; ExceptionRecord : EXCEPTION_RECORD* optional -> "sptr"
; ReturnValue : void* -> "sptr"
; ContextRecord : CONTEXT* -> "sptr"
; HistoryTable : UNWIND_HISTORY_TABLE* optional -> "sptr"出力引数:
#uselib "KERNEL32.dll" #func global RtlUnwindEx "RtlUnwindEx" sptr, sptr, var, sptr, var, var ; RtlUnwindEx TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable ; TargetFrame : void* optional -> "sptr" ; TargetIp : void* optional -> "sptr" ; ExceptionRecord : EXCEPTION_RECORD* optional -> "var" ; ReturnValue : void* -> "sptr" ; ContextRecord : CONTEXT* -> "var" ; HistoryTable : UNWIND_HISTORY_TABLE* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。#uselib "KERNEL32.dll" #func global RtlUnwindEx "RtlUnwindEx" sptr, sptr, sptr, sptr, sptr, sptr ; RtlUnwindEx TargetFrame, TargetIp, varptr(ExceptionRecord), ReturnValue, varptr(ContextRecord), varptr(HistoryTable) ; TargetFrame : void* optional -> "sptr" ; TargetIp : void* optional -> "sptr" ; ExceptionRecord : EXCEPTION_RECORD* optional -> "sptr" ; ReturnValue : void* -> "sptr" ; ContextRecord : CONTEXT* -> "sptr" ; HistoryTable : UNWIND_HISTORY_TABLE* optional -> "sptr" ; ※出力/バッファ引数はポインタ方式(token=sptr / 呼び出しは varptr(変数))。
出力引数:
; void RtlUnwindEx(void* TargetFrame, void* TargetIp, EXCEPTION_RECORD* ExceptionRecord, void* ReturnValue, CONTEXT* ContextRecord, UNWIND_HISTORY_TABLE* HistoryTable) #uselib "KERNEL32.dll" #func global RtlUnwindEx "RtlUnwindEx" intptr, intptr, var, intptr, var, var ; RtlUnwindEx TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable ; TargetFrame : void* optional -> "intptr" ; TargetIp : void* optional -> "intptr" ; ExceptionRecord : EXCEPTION_RECORD* optional -> "var" ; ReturnValue : void* -> "intptr" ; ContextRecord : CONTEXT* -> "var" ; HistoryTable : UNWIND_HISTORY_TABLE* optional -> "var" ; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。; void RtlUnwindEx(void* TargetFrame, void* TargetIp, EXCEPTION_RECORD* ExceptionRecord, void* ReturnValue, CONTEXT* ContextRecord, UNWIND_HISTORY_TABLE* HistoryTable) #uselib "KERNEL32.dll" #func global RtlUnwindEx "RtlUnwindEx" intptr, intptr, intptr, intptr, intptr, intptr ; RtlUnwindEx TargetFrame, TargetIp, varptr(ExceptionRecord), ReturnValue, varptr(ContextRecord), varptr(HistoryTable) ; TargetFrame : void* optional -> "intptr" ; TargetIp : void* optional -> "intptr" ; ExceptionRecord : EXCEPTION_RECORD* optional -> "intptr" ; ReturnValue : void* -> "intptr" ; ContextRecord : CONTEXT* -> "intptr" ; HistoryTable : UNWIND_HISTORY_TABLE* optional -> "intptr" ; ※出力/バッファ引数はポインタ方式(token=intptr / 呼び出しは varptr(変数))。
import (
"golang.org/x/sys/windows"
"unsafe"
)
var (
kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
procRtlUnwindEx = kernel32.NewProc("RtlUnwindEx")
)
// TargetFrame (void* optional), TargetIp (void* optional), ExceptionRecord (EXCEPTION_RECORD* optional), ReturnValue (void*), ContextRecord (CONTEXT*), HistoryTable (UNWIND_HISTORY_TABLE* optional)
r1, _, err := procRtlUnwindEx.Call(
uintptr(TargetFrame),
uintptr(TargetIp),
uintptr(ExceptionRecord),
uintptr(ReturnValue),
uintptr(ContextRecord),
uintptr(HistoryTable),
)
_ = err // syscall.Errno (valid when the call sets last-error)
_ = r1 // voidprocedure RtlUnwindEx(
TargetFrame: Pointer; // void* optional
TargetIp: Pointer; // void* optional
ExceptionRecord: Pointer; // EXCEPTION_RECORD* optional
ReturnValue: Pointer; // void*
ContextRecord: Pointer; // CONTEXT*
HistoryTable: Pointer // UNWIND_HISTORY_TABLE* optional
); stdcall;
external 'KERNEL32.dll' name 'RtlUnwindEx';result := DllCall("KERNEL32\RtlUnwindEx"
, "Ptr", TargetFrame ; void* optional
, "Ptr", TargetIp ; void* optional
, "Ptr", ExceptionRecord ; EXCEPTION_RECORD* optional
, "Ptr", ReturnValue ; void*
, "Ptr", ContextRecord ; CONTEXT*
, "Ptr", HistoryTable ; UNWIND_HISTORY_TABLE* optional
, "Int") ; return: void●RtlUnwindEx(TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable) = DLL("KERNEL32.dll", "int RtlUnwindEx(void*, void*, void*, void*, void*, void*)")
# 呼び出し: RtlUnwindEx(TargetFrame, TargetIp, ExceptionRecord, ReturnValue, ContextRecord, HistoryTable)
# TargetFrame : void* optional -> "void*"
# TargetIp : void* optional -> "void*"
# ExceptionRecord : EXCEPTION_RECORD* optional -> "void*"
# ReturnValue : void* -> "void*"
# ContextRecord : CONTEXT* -> "void*"
# HistoryTable : UNWIND_HISTORY_TABLE* optional -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。