yhara.jp

Recent Posts

Crystalと例外

Tech

LLVMと例外

Crystal言語における例外の実装を調査する。

前提知識

  • Crystalの処理系はCrystal自身で書かれている
  • CrystalはC-FFIが言語機能として組み込まれている(Lib)
    • たとえばLLVMの関数はlib_llvm.crでCrystalレベルから呼べるようバインディングされている
  • オーバーロードがある
    • def foo()def foo(a)def foo(a, b)が同時に存在したりするのでコードリーディング時は要注意

Personality function

win32、arm、wasmでない場合 https://github.com/crystal-lang/crystal/blob/5761bbb7aa5e79f4de24837d6007a03a673990f2/src/raise.cr#L185-L199

  # :nodoc:
  fun __crystal_personality(version : Int32, actions : LibUnwind::Action, exception_class : UInt64, exception_object : LibUnwind::Exception*, context : Void*) : LibUnwind::ReasonCode
    start = LibUnwind.get_region_start(context)
    ip = LibUnwind.get_ip(context)
    lsd = LibUnwind.get_language_specific_data(context)

    leb = LEBReader.new(lsd)
    reason = traverse_eh_table(leb, start, ip, actions) do |unwind_ip|
      LibUnwind.set_gr(context, LibUnwind::EH_REGISTER_0, exception_object.address)
      LibUnwind.set_gr(context, LibUnwind::EH_REGISTER_1, exception_object.value.exception_type_id)
      LibUnwind.set_ip(context, unwind_ip)
    end
    return reason if reason

    return LibUnwind::ReasonCode::CONTINUE_UNWIND
  end

traverse_eh_table

More posts

Posts

(more...)

Articles

(more...)

Category

Ads

About

About the author
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy