Win32 API 日本語リファレンス
ホームSystem.Diagnostics.Debug › RtlUnwind

RtlUnwind

関数
指定フレームまで例外処理のスタック巻き戻しを実行する。
DLLKERNEL32.dll呼出規約winapi対応OSWindows XP 以降

シグネチャ

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

void RtlUnwind(
    void* TargetFrame,   // optional
    void* TargetIp,   // optional
    EXCEPTION_RECORD* ExceptionRecord,   // optional
    void* ReturnValue
);

パラメーター

名前方向説明
TargetFramevoid*inoptionalアンワインドの対象となる呼び出しフレームへのポインター。このパラメーターが NULL の場合、関数は終了アンワインドを実行します。
TargetIpvoid*inoptionalアンワインドの継続アドレス。TargetFrameNULL の場合、このパラメーターは無視されます。
ExceptionRecordEXCEPTION_RECORD*inoptionalEXCEPTION_RECORD 構造体へのポインター。
ReturnValuevoid*in実行を継続する前に整数関数の戻り値レジスタに設定される値。

戻り値の型: void

公式ドキュメント

プロシージャ呼び出しフレームのアンワインドを開始します。(RtlUnwind)

戻り値

この関数は値を返しません。

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

各言語での呼び出し定義

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

void RtlUnwind(
    void* TargetFrame,   // optional
    void* TargetIp,   // optional
    EXCEPTION_RECORD* ExceptionRecord,   // optional
    void* ReturnValue
);
[DllImport("KERNEL32.dll", ExactSpelling = true)]
static extern void RtlUnwind(
    IntPtr TargetFrame,   // void* optional
    IntPtr TargetIp,   // void* optional
    IntPtr ExceptionRecord,   // EXCEPTION_RECORD* optional
    IntPtr ReturnValue   // void*
);
<DllImport("KERNEL32.dll", ExactSpelling:=True)>
Public Shared Sub RtlUnwind(
    TargetFrame As IntPtr,   ' void* optional
    TargetIp As IntPtr,   ' void* optional
    ExceptionRecord As IntPtr,   ' EXCEPTION_RECORD* optional
    ReturnValue As IntPtr   ' void*
)
End Sub
' TargetFrame : void* optional
' TargetIp : void* optional
' ExceptionRecord : EXCEPTION_RECORD* optional
' ReturnValue : void*
Declare PtrSafe Sub RtlUnwind Lib "kernel32" ( _
    ByVal TargetFrame As LongPtr, _
    ByVal TargetIp As LongPtr, _
    ByVal ExceptionRecord As LongPtr, _
    ByVal ReturnValue As LongPtr)
' VBA7前提(PtrSafe)。32bit Office では LongPtr→Long。Integer=16bit / Long=32bit / LongLong=64bit。
import ctypes
from ctypes import wintypes

RtlUnwind = ctypes.windll.kernel32.RtlUnwind
RtlUnwind.restype = None
RtlUnwind.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*
]
require 'fiddle'
require 'fiddle/import'

lib = Fiddle.dlopen('KERNEL32.dll')
RtlUnwind = Fiddle::Function.new(
  lib['RtlUnwind'],
  [
    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_VOID)
#[link(name = "kernel32")]
extern "system" {
    fn RtlUnwind(
        TargetFrame: *mut (),  // void* optional
        TargetIp: *mut (),  // void* optional
        ExceptionRecord: *mut EXCEPTION_RECORD,  // EXCEPTION_RECORD* optional
        ReturnValue: *mut ()  // void*
    );
}
// crates: windows-sys provides ready-made bindings for this API.
$sig = @"
[DllImport("KERNEL32.dll")]
public static extern void RtlUnwind(IntPtr TargetFrame, IntPtr TargetIp, IntPtr ExceptionRecord, IntPtr ReturnValue);
"@
$api = Add-Type -MemberDefinition $sig -Name 'KERNEL32_RtlUnwind' -Namespace Win32 -PassThru
# $api::RtlUnwind(TargetFrame, TargetIp, ExceptionRecord, ReturnValue)
#uselib "KERNEL32.dll"
#func global RtlUnwind "RtlUnwind" sptr, sptr, sptr, sptr
; RtlUnwind TargetFrame, TargetIp, varptr(ExceptionRecord), ReturnValue
; TargetFrame : void* optional -> "sptr"
; TargetIp : void* optional -> "sptr"
; ExceptionRecord : EXCEPTION_RECORD* optional -> "sptr"
; ReturnValue : void* -> "sptr"
出力引数:
#uselib "KERNEL32.dll"
#func global RtlUnwind "RtlUnwind" sptr, sptr, var, sptr
; RtlUnwind TargetFrame, TargetIp, ExceptionRecord, ReturnValue
; TargetFrame : void* optional -> "sptr"
; TargetIp : void* optional -> "sptr"
; ExceptionRecord : EXCEPTION_RECORD* optional -> "var"
; ReturnValue : void* -> "sptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
出力引数:
; void RtlUnwind(void* TargetFrame, void* TargetIp, EXCEPTION_RECORD* ExceptionRecord, void* ReturnValue)
#uselib "KERNEL32.dll"
#func global RtlUnwind "RtlUnwind" intptr, intptr, var, intptr
; RtlUnwind TargetFrame, TargetIp, ExceptionRecord, ReturnValue
; TargetFrame : void* optional -> "intptr"
; TargetIp : void* optional -> "intptr"
; ExceptionRecord : EXCEPTION_RECORD* optional -> "var"
; ReturnValue : void* -> "intptr"
; ※出力/バッファ引数は var 方式(変数を直接渡す)。varptr 方式にも切替可。
import (
	"golang.org/x/sys/windows"
	"unsafe"
)

var (
	kernel32 = windows.NewLazySystemDLL("KERNEL32.dll")
	procRtlUnwind = kernel32.NewProc("RtlUnwind")
)

// TargetFrame (void* optional), TargetIp (void* optional), ExceptionRecord (EXCEPTION_RECORD* optional), ReturnValue (void*)
r1, _, err := procRtlUnwind.Call(
	uintptr(TargetFrame),
	uintptr(TargetIp),
	uintptr(ExceptionRecord),
	uintptr(ReturnValue),
)
_ = err  // syscall.Errno (valid when the call sets last-error)
_ = r1   // void
procedure RtlUnwind(
  TargetFrame: Pointer;   // void* optional
  TargetIp: Pointer;   // void* optional
  ExceptionRecord: Pointer;   // EXCEPTION_RECORD* optional
  ReturnValue: Pointer   // void*
); stdcall;
  external 'KERNEL32.dll' name 'RtlUnwind';
result := DllCall("KERNEL32\RtlUnwind"
    , "Ptr", TargetFrame   ; void* optional
    , "Ptr", TargetIp   ; void* optional
    , "Ptr", ExceptionRecord   ; EXCEPTION_RECORD* optional
    , "Ptr", ReturnValue   ; void*
    , "Int")   ; return: void
●RtlUnwind(TargetFrame, TargetIp, ExceptionRecord, ReturnValue) = DLL("KERNEL32.dll", "int RtlUnwind(void*, void*, void*, void*)")
# 呼び出し: RtlUnwind(TargetFrame, TargetIp, ExceptionRecord, ReturnValue)
# TargetFrame : void* optional -> "void*"
# TargetIp : void* optional -> "void*"
# ExceptionRecord : EXCEPTION_RECORD* optional -> "void*"
# ReturnValue : void* -> "void*"
# なでしこ1は32bit・ANSI(Shift_JIS)。文字列=char*(ANSI)、ポインタ/ハンドル=void*(4byte)。
const std = @import("std");

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

typedef RtlUnwindNative = Void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
typedef RtlUnwindDart = void Function(Pointer<Void>, Pointer<Void>, Pointer<Void>, Pointer<Void>);
final RtlUnwind = DynamicLibrary.open('KERNEL32.dll')
    .lookupFunction<RtlUnwindNative, RtlUnwindDart>('RtlUnwind');
// TargetFrame : void* optional -> Pointer<Void>
// TargetIp : void* optional -> Pointer<Void>
// ExceptionRecord : EXCEPTION_RECORD* optional -> Pointer<Void>
// ReturnValue : void* -> Pointer<Void>
// 文字列は package:ffi の "...".toNativeUtf16()/toNativeUtf8() で変換。
{$mode objfpc}{$H+}
procedure RtlUnwind(
  TargetFrame: Pointer;   // void* optional
  TargetIp: Pointer;   // void* optional
  ExceptionRecord: Pointer;   // EXCEPTION_RECORD* optional
  ReturnValue: Pointer   // void*
); stdcall;
  external 'KERNEL32.dll' name 'RtlUnwind';
import Foreign
import Foreign.C.Types
import Foreign.C.String

foreign import stdcall safe "RtlUnwind"
  c_RtlUnwind :: Ptr () -> Ptr () -> Ptr () -> Ptr () -> IO ()
-- TargetFrame : void* optional -> Ptr ()
-- TargetIp : void* optional -> Ptr ()
-- ExceptionRecord : EXCEPTION_RECORD* optional -> Ptr ()
-- ReturnValue : void* -> Ptr ()
-- 要 GHC(Windows)。stdcall は x64 では ccall として扱われる。ブロックする API は safe 呼び出し推奨。
open Ctypes
open Foreign

let rtlunwind =
  foreign "RtlUnwind"
    ((ptr void) @-> (ptr void) @-> (ptr void) @-> (ptr void) @-> returning void)
(* TargetFrame : void* optional -> (ptr void) *)
(* TargetIp : void* optional -> (ptr void) *)
(* ExceptionRecord : EXCEPTION_RECORD* optional -> (ptr void) *)
(* ReturnValue : void* -> (ptr void) *)
(* foreign は cdecl 前提。x64 Windows では WINAPI と一致。構造体は ctypes structure を定義のこと。 *)
(cffi:define-foreign-library kernel32 (t "KERNEL32.dll"))
(cffi:use-foreign-library kernel32)

(cffi:defcfun ("RtlUnwind" rtl-unwind :convention :stdcall) :void
  (target-frame :pointer)   ; void* optional
  (target-ip :pointer)   ; void* optional
  (exception-record :pointer)   ; EXCEPTION_RECORD* optional
  (return-value :pointer))   ; void*
; isize/usize(INT_PTR/SIZE_T)は x64 前提で :int64/:uint64。x86 では :int32/:uint32。
use Win32::API;
my $RtlUnwind = Win32::API::More->new('KERNEL32',
    'void RtlUnwind(LPVOID TargetFrame, LPVOID TargetIp, LPVOID ExceptionRecord, LPVOID ReturnValue)');
# my $ret = $RtlUnwind->Call($TargetFrame, $TargetIp, $ExceptionRecord, $ReturnValue);
# TargetFrame : void* optional -> LPVOID
# TargetIp : void* optional -> LPVOID
# ExceptionRecord : EXCEPTION_RECORD* optional -> LPVOID
# ReturnValue : void* -> LPVOID
# 値渡し構造体は pack() した文字列、または Win32::API::Struct を使用。

関連項目

類似 API
使用する型