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

STACKFRAME64

構造体
サイズx64: 264 バイト / x86: 264 バイト

サイズ=各フィールドのバイト数(x64/x86 で異なる場合は x64/x86 と併記)。x64/x86 列=フィールドのバイトオフセット(HSPで dupptr / lpoke / wpoke 等に使用)。

フィールド

フィールドサイズx64x86説明
AddrPCADDRESS6416+0+0プログラムカウンタ(命令ポインタ)のアドレスを示す。
AddrReturnADDRESS6416+16+16リターンアドレスを示す。
AddrFrameADDRESS6416+32+32フレームポインタのアドレスを示す。
AddrStackADDRESS6416+48+48スタックポインタのアドレスを示す。
AddrBStoreADDRESS6416+64+64バッキングストアのアドレスを示す。主に Itanium 用。
FuncTableEntryvoid*8/4+80+80関数テーブルエントリ(FPO/PDATA 等)を指すポインタ。
ParamsULONGLONG32+88+88関数の引数値(最初の4つ)を保持する配列。
FarBOOL4+120+120ファーコールかどうかを示すフラグ。
VirtualBOOL4+124+124仮想フレームかどうかを示すフラグ。
ReservedULONGLONG24+128+128予約フィールド。使用しない。
KdHelpKDHELP64112+152+152カーネルデバッグ補助情報(KDHELP64)を保持する。

各言語での定義

#include <windows.h>

// ADDRESS64  (x64 16 / x86 16 バイト)
typedef struct ADDRESS64 {
    ULONGLONG Offset;
    WORD Segment;
    ADDRESS_MODE Mode;
} ADDRESS64;

// KDHELP64  (x64 112 / x86 112 バイト)
typedef struct KDHELP64 {
    ULONGLONG Thread;
    DWORD ThCallbackStack;
    DWORD ThCallbackBStore;
    DWORD NextCallback;
    DWORD FramePointer;
    ULONGLONG KiCallUserMode;
    ULONGLONG KeUserCallbackDispatcher;
    ULONGLONG SystemRangeStart;
    ULONGLONG KiUserExceptionDispatcher;
    ULONGLONG StackBase;
    ULONGLONG StackLimit;
    DWORD BuildVersion;
    DWORD RetpolineStubFunctionTableSize;
    ULONGLONG RetpolineStubFunctionTable;
    DWORD RetpolineStubOffset;
    DWORD RetpolineStubSize;
    ULONGLONG Reserved0[2];
} KDHELP64;

// STACKFRAME64  (x64 264 / x86 264 バイト)
typedef struct STACKFRAME64 {
    ADDRESS64 AddrPC;
    ADDRESS64 AddrReturn;
    ADDRESS64 AddrFrame;
    ADDRESS64 AddrStack;
    ADDRESS64 AddrBStore;
    void* FuncTableEntry;
    ULONGLONG Params[4];
    BOOL Far;
    BOOL Virtual;
    ULONGLONG Reserved[3];
    KDHELP64 KdHelp;
} STACKFRAME64;
using System;
using System.Runtime.InteropServices;

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct ADDRESS64
{
    public ulong Offset;
    public ushort Segment;
    public int Mode;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct KDHELP64
{
    public ulong Thread;
    public uint ThCallbackStack;
    public uint ThCallbackBStore;
    public uint NextCallback;
    public uint FramePointer;
    public ulong KiCallUserMode;
    public ulong KeUserCallbackDispatcher;
    public ulong SystemRangeStart;
    public ulong KiUserExceptionDispatcher;
    public ulong StackBase;
    public ulong StackLimit;
    public uint BuildVersion;
    public uint RetpolineStubFunctionTableSize;
    public ulong RetpolineStubFunctionTable;
    public uint RetpolineStubOffset;
    public uint RetpolineStubSize;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 2)] public ulong[] Reserved0;
}

[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct STACKFRAME64
{
    public ADDRESS64 AddrPC;
    public ADDRESS64 AddrReturn;
    public ADDRESS64 AddrFrame;
    public ADDRESS64 AddrStack;
    public ADDRESS64 AddrBStore;
    public IntPtr FuncTableEntry;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 4)] public ulong[] Params;
    [MarshalAs(UnmanagedType.Bool)] public bool Far;
    [MarshalAs(UnmanagedType.Bool)] public bool Virtual;
    [MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)] public ulong[] Reserved;
    public KDHELP64 KdHelp;
}
Imports System.Runtime.InteropServices

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure ADDRESS64
    Public Offset As ULong
    Public Segment As UShort
    Public Mode As Integer
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure KDHELP64
    Public Thread As ULong
    Public ThCallbackStack As UInteger
    Public ThCallbackBStore As UInteger
    Public NextCallback As UInteger
    Public FramePointer As UInteger
    Public KiCallUserMode As ULong
    Public KeUserCallbackDispatcher As ULong
    Public SystemRangeStart As ULong
    Public KiUserExceptionDispatcher As ULong
    Public StackBase As ULong
    Public StackLimit As ULong
    Public BuildVersion As UInteger
    Public RetpolineStubFunctionTableSize As UInteger
    Public RetpolineStubFunctionTable As ULong
    Public RetpolineStubOffset As UInteger
    Public RetpolineStubSize As UInteger
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=2)> Public Reserved0() As ULong
End Structure

<StructLayout(LayoutKind.Sequential, CharSet:=CharSet.Unicode)>
Public Structure STACKFRAME64
    Public AddrPC As ADDRESS64
    Public AddrReturn As ADDRESS64
    Public AddrFrame As ADDRESS64
    Public AddrStack As ADDRESS64
    Public AddrBStore As ADDRESS64
    Public FuncTableEntry As IntPtr
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=4)> Public Params() As ULong
    <MarshalAs(UnmanagedType.Bool)> Public Far As Boolean
    <MarshalAs(UnmanagedType.Bool)> Public Virtual As Boolean
    <MarshalAs(UnmanagedType.ByValArray, SizeConst:=3)> Public Reserved() As ULong
    Public KdHelp As KDHELP64
End Structure
import ctypes
from ctypes import wintypes

class ADDRESS64(ctypes.Structure):
    _fields_ = [
        ("Offset", ctypes.c_ulonglong),
        ("Segment", ctypes.c_ushort),
        ("Mode", ctypes.c_int),
    ]

class KDHELP64(ctypes.Structure):
    _fields_ = [
        ("Thread", ctypes.c_ulonglong),
        ("ThCallbackStack", wintypes.DWORD),
        ("ThCallbackBStore", wintypes.DWORD),
        ("NextCallback", wintypes.DWORD),
        ("FramePointer", wintypes.DWORD),
        ("KiCallUserMode", ctypes.c_ulonglong),
        ("KeUserCallbackDispatcher", ctypes.c_ulonglong),
        ("SystemRangeStart", ctypes.c_ulonglong),
        ("KiUserExceptionDispatcher", ctypes.c_ulonglong),
        ("StackBase", ctypes.c_ulonglong),
        ("StackLimit", ctypes.c_ulonglong),
        ("BuildVersion", wintypes.DWORD),
        ("RetpolineStubFunctionTableSize", wintypes.DWORD),
        ("RetpolineStubFunctionTable", ctypes.c_ulonglong),
        ("RetpolineStubOffset", wintypes.DWORD),
        ("RetpolineStubSize", wintypes.DWORD),
        ("Reserved0", ctypes.c_ulonglong * 2),
    ]

class STACKFRAME64(ctypes.Structure):
    _fields_ = [
        ("AddrPC", ADDRESS64),
        ("AddrReturn", ADDRESS64),
        ("AddrFrame", ADDRESS64),
        ("AddrStack", ADDRESS64),
        ("AddrBStore", ADDRESS64),
        ("FuncTableEntry", ctypes.c_void_p),
        ("Params", ctypes.c_ulonglong * 4),
        ("Far", wintypes.BOOL),
        ("Virtual", wintypes.BOOL),
        ("Reserved", ctypes.c_ulonglong * 3),
        ("KdHelp", KDHELP64),
    ]
#[repr(C)]
pub struct ADDRESS64 {
    pub Offset: u64,
    pub Segment: u16,
    pub Mode: i32,
}

#[repr(C)]
pub struct KDHELP64 {
    pub Thread: u64,
    pub ThCallbackStack: u32,
    pub ThCallbackBStore: u32,
    pub NextCallback: u32,
    pub FramePointer: u32,
    pub KiCallUserMode: u64,
    pub KeUserCallbackDispatcher: u64,
    pub SystemRangeStart: u64,
    pub KiUserExceptionDispatcher: u64,
    pub StackBase: u64,
    pub StackLimit: u64,
    pub BuildVersion: u32,
    pub RetpolineStubFunctionTableSize: u32,
    pub RetpolineStubFunctionTable: u64,
    pub RetpolineStubOffset: u32,
    pub RetpolineStubSize: u32,
    pub Reserved0: [u64; 2],
}

#[repr(C)]
pub struct STACKFRAME64 {
    pub AddrPC: ADDRESS64,
    pub AddrReturn: ADDRESS64,
    pub AddrFrame: ADDRESS64,
    pub AddrStack: ADDRESS64,
    pub AddrBStore: ADDRESS64,
    pub FuncTableEntry: *mut core::ffi::c_void,
    pub Params: [u64; 4],
    pub Far: i32,
    pub Virtual: i32,
    pub Reserved: [u64; 3],
    pub KdHelp: KDHELP64,
}
import "golang.org/x/sys/windows"

type ADDRESS64 struct {
	Offset uint64
	Segment uint16
	Mode int32
}

type KDHELP64 struct {
	Thread uint64
	ThCallbackStack uint32
	ThCallbackBStore uint32
	NextCallback uint32
	FramePointer uint32
	KiCallUserMode uint64
	KeUserCallbackDispatcher uint64
	SystemRangeStart uint64
	KiUserExceptionDispatcher uint64
	StackBase uint64
	StackLimit uint64
	BuildVersion uint32
	RetpolineStubFunctionTableSize uint32
	RetpolineStubFunctionTable uint64
	RetpolineStubOffset uint32
	RetpolineStubSize uint32
	Reserved0 [2]uint64
}

type STACKFRAME64 struct {
	AddrPC ADDRESS64
	AddrReturn ADDRESS64
	AddrFrame ADDRESS64
	AddrStack ADDRESS64
	AddrBStore ADDRESS64
	FuncTableEntry uintptr
	Params [4]uint64
	Far int32
	Virtual int32
	Reserved [3]uint64
	KdHelp KDHELP64
}
type
  ADDRESS64 = record
    Offset: UInt64;
    Segment: Word;
    Mode: Integer;
  end;

  KDHELP64 = record
    Thread: UInt64;
    ThCallbackStack: DWORD;
    ThCallbackBStore: DWORD;
    NextCallback: DWORD;
    FramePointer: DWORD;
    KiCallUserMode: UInt64;
    KeUserCallbackDispatcher: UInt64;
    SystemRangeStart: UInt64;
    KiUserExceptionDispatcher: UInt64;
    StackBase: UInt64;
    StackLimit: UInt64;
    BuildVersion: DWORD;
    RetpolineStubFunctionTableSize: DWORD;
    RetpolineStubFunctionTable: UInt64;
    RetpolineStubOffset: DWORD;
    RetpolineStubSize: DWORD;
    Reserved0: array[0..1] of UInt64;
  end;

  STACKFRAME64 = record
    AddrPC: ADDRESS64;
    AddrReturn: ADDRESS64;
    AddrFrame: ADDRESS64;
    AddrStack: ADDRESS64;
    AddrBStore: ADDRESS64;
    FuncTableEntry: Pointer;
    Params: array[0..3] of UInt64;
    Far: BOOL;
    Virtual: BOOL;
    Reserved: array[0..2] of UInt64;
    KdHelp: KDHELP64;
  end;
const ADDRESS64 = extern struct {
    Offset: u64,
    Segment: u16,
    Mode: i32,
};

const KDHELP64 = extern struct {
    Thread: u64,
    ThCallbackStack: u32,
    ThCallbackBStore: u32,
    NextCallback: u32,
    FramePointer: u32,
    KiCallUserMode: u64,
    KeUserCallbackDispatcher: u64,
    SystemRangeStart: u64,
    KiUserExceptionDispatcher: u64,
    StackBase: u64,
    StackLimit: u64,
    BuildVersion: u32,
    RetpolineStubFunctionTableSize: u32,
    RetpolineStubFunctionTable: u64,
    RetpolineStubOffset: u32,
    RetpolineStubSize: u32,
    Reserved0: [2]u64,
};

const STACKFRAME64 = extern struct {
    AddrPC: ADDRESS64,
    AddrReturn: ADDRESS64,
    AddrFrame: ADDRESS64,
    AddrStack: ADDRESS64,
    AddrBStore: ADDRESS64,
    FuncTableEntry: ?*anyopaque,
    Params: [4]u64,
    Far: i32,
    Virtual: i32,
    Reserved: [3]u64,
    KdHelp: KDHELP64,
};
type
  ADDRESS64 {.bycopy.} = object
    Offset: uint64
    Segment: uint16
    Mode: int32

  KDHELP64 {.bycopy.} = object
    Thread: uint64
    ThCallbackStack: uint32
    ThCallbackBStore: uint32
    NextCallback: uint32
    FramePointer: uint32
    KiCallUserMode: uint64
    KeUserCallbackDispatcher: uint64
    SystemRangeStart: uint64
    KiUserExceptionDispatcher: uint64
    StackBase: uint64
    StackLimit: uint64
    BuildVersion: uint32
    RetpolineStubFunctionTableSize: uint32
    RetpolineStubFunctionTable: uint64
    RetpolineStubOffset: uint32
    RetpolineStubSize: uint32
    Reserved0: array[2, uint64]

  STACKFRAME64 {.bycopy.} = object
    AddrPC: ADDRESS64
    AddrReturn: ADDRESS64
    AddrFrame: ADDRESS64
    AddrStack: ADDRESS64
    AddrBStore: ADDRESS64
    FuncTableEntry: pointer
    Params: array[4, uint64]
    Far: int32
    Virtual: int32
    Reserved: array[3, uint64]
    KdHelp: KDHELP64
struct ADDRESS64
{
    ulong Offset;
    ushort Segment;
    int Mode;
}

struct KDHELP64
{
    ulong Thread;
    uint ThCallbackStack;
    uint ThCallbackBStore;
    uint NextCallback;
    uint FramePointer;
    ulong KiCallUserMode;
    ulong KeUserCallbackDispatcher;
    ulong SystemRangeStart;
    ulong KiUserExceptionDispatcher;
    ulong StackBase;
    ulong StackLimit;
    uint BuildVersion;
    uint RetpolineStubFunctionTableSize;
    ulong RetpolineStubFunctionTable;
    uint RetpolineStubOffset;
    uint RetpolineStubSize;
    ulong[2] Reserved0;
}

struct STACKFRAME64
{
    ADDRESS64 AddrPC;
    ADDRESS64 AddrReturn;
    ADDRESS64 AddrFrame;
    ADDRESS64 AddrStack;
    ADDRESS64 AddrBStore;
    void* FuncTableEntry;
    ulong[4] Params;
    int Far;
    int Virtual;
    ulong[3] Reserved;
    KDHELP64 KdHelp;
}

HSP用 定義

HSP3.7/3.8 は構造体機能が無いため4byte整数配列(dim)+peek/poke で操作(32/64bitでサイズ・位置が異なる場合はタブで分割)。IronHSP は NSTRUCT(#defstruct/stdim/->)で32/64bit共通。

; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x86 レイアウト)
; STACKFRAME64 サイズ: 264 バイト(x86)
dim st, 66    ; 4byte整数×66(構造体サイズ 264 / 4 切り上げ)
; AddrPC : ADDRESS64 (+0, 16byte)  varptr(st)+0 を基点に操作(16byte:入れ子/配列)
; AddrReturn : ADDRESS64 (+16, 16byte)  varptr(st)+16 を基点に操作(16byte:入れ子/配列)
; AddrFrame : ADDRESS64 (+32, 16byte)  varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; AddrStack : ADDRESS64 (+48, 16byte)  varptr(st)+48 を基点に操作(16byte:入れ子/配列)
; AddrBStore : ADDRESS64 (+64, 16byte)  varptr(st)+64 を基点に操作(16byte:入れ子/配列)
; FuncTableEntry : void* (+80, 4byte)  st.20 = 値  /  値 = st.20   (lpoke/lpeek も可)
; Params : ULONGLONG (+88, 32byte)  varptr(st)+88 を基点に操作(32byte:入れ子/配列)
; Far : BOOL (+120, 4byte)  st.30 = 値  /  値 = st.30   (lpoke/lpeek も可)
; Virtual : BOOL (+124, 4byte)  st.31 = 値  /  値 = st.31   (lpoke/lpeek も可)
; Reserved : ULONGLONG (+128, 24byte)  varptr(st)+128 を基点に操作(24byte:入れ子/配列)
; KdHelp : KDHELP64 (+152, 112byte)  varptr(st)+152 を基点に操作(112byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; HSP3.7/3.8 は構造体機能が無いため、4byte整数の配列変数で操作します。(x64 レイアウト)
; STACKFRAME64 サイズ: 264 バイト(x64)
dim st, 66    ; 4byte整数×66(構造体サイズ 264 / 4 切り上げ)
; AddrPC : ADDRESS64 (+0, 16byte)  varptr(st)+0 を基点に操作(16byte:入れ子/配列)
; AddrReturn : ADDRESS64 (+16, 16byte)  varptr(st)+16 を基点に操作(16byte:入れ子/配列)
; AddrFrame : ADDRESS64 (+32, 16byte)  varptr(st)+32 を基点に操作(16byte:入れ子/配列)
; AddrStack : ADDRESS64 (+48, 16byte)  varptr(st)+48 を基点に操作(16byte:入れ子/配列)
; AddrBStore : ADDRESS64 (+64, 16byte)  varptr(st)+64 を基点に操作(16byte:入れ子/配列)
; FuncTableEntry : void* (+80, 8byte)  qpoke st,80,値 / qpeek(st,80)  ※IronHSPのみ。3.7/3.8は lpoke st,80,下位 : lpoke st,84,上位
; Params : ULONGLONG (+88, 32byte)  varptr(st)+88 を基点に操作(32byte:入れ子/配列)
; Far : BOOL (+120, 4byte)  st.30 = 値  /  値 = st.30   (lpoke/lpeek も可)
; Virtual : BOOL (+124, 4byte)  st.31 = 値  /  値 = st.31   (lpoke/lpeek も可)
; Reserved : ULONGLONG (+128, 24byte)  varptr(st)+128 を基点に操作(24byte:入れ子/配列)
; KdHelp : KDHELP64 (+152, 112byte)  varptr(st)+152 を基点に操作(112byte:入れ子/配列)
; ※4byte境界の整数は添字 st.N(N=オフセット/4)で読み書き可。それ以外は peek/poke 系を使用。
; IronHSP は NSTRUCT(構造体)をサポート。32bit/64bit どちらでも同じコードで動作します。
; ※GUID・入れ子構造体はデフォルト型でないため、依存する #defstruct を先に定義(下記に同梱)。
#defstruct global ADDRESS64
    #field int64 Offset
    #field short Segment
    #field int Mode
#endstruct

#defstruct global KDHELP64
    #field int64 Thread
    #field int ThCallbackStack
    #field int ThCallbackBStore
    #field int NextCallback
    #field int FramePointer
    #field int64 KiCallUserMode
    #field int64 KeUserCallbackDispatcher
    #field int64 SystemRangeStart
    #field int64 KiUserExceptionDispatcher
    #field int64 StackBase
    #field int64 StackLimit
    #field int BuildVersion
    #field int RetpolineStubFunctionTableSize
    #field int64 RetpolineStubFunctionTable
    #field int RetpolineStubOffset
    #field int RetpolineStubSize
    #field int64 Reserved0 2
#endstruct

#defstruct global STACKFRAME64
    #field ADDRESS64 AddrPC
    #field ADDRESS64 AddrReturn
    #field ADDRESS64 AddrFrame
    #field ADDRESS64 AddrStack
    #field ADDRESS64 AddrBStore
    #field intptr FuncTableEntry
    #field int64 Params 4
    #field bool Far
    #field bool Virtual
    #field int64 Reserved 3
    #field KDHELP64 KdHelp
#endstruct

stdim st, STACKFRAME64        ; NSTRUCT 変数を確保
st->Far = 100
mes "Far=" + st->Far