Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
カーネルランド Rust 勉強会 #2; Rust の unsafe
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shin-ya Koga
June 18, 2026
Technology
95
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
カーネルランド Rust 勉強会 #2; Rust の unsafe
5/28 に開催した「カーネルランド Rust 勉強会 #2」で使ったスライドに加筆したもの。Rust の unsafe の説明と、形式的検証の取組を紹介しました。
Shin-ya Koga
June 18, 2026
More Decks by Shin-ya Koga
See All by Shin-ya Koga
カーネルランド Rust 勉強会 #4: Zephyr で Rust を使う前に
shkoga
0
57
カーネルランド Rust 勉強会 #3: 並行処理における安全性
shkoga
1
81
Firecracker のソースを読んでみた
shkoga
1
240
2025-02-18.slide_revised
shkoga
0
130
2024-09-27 リファクタリング勉強会
shkoga
0
130
仮想化って何だろう
shkoga
0
250
Other Decks in Technology
See All in Technology
Essential architectural thinking (revised edition)
ufried
0
110
しろおびから始める!ログ活用の第一歩
shumei_ito
0
720
ファミコンでPHPを動かす / PHP on the Famicom side b
tomzoh
0
140
事業活動を AI Ready にする攻めと守りのデータエンジニアリング / data-engineering-for-ai-ready-business
pei0804
5
2.1k
メルペイ 会計システム概要と歴史
mewuto
0
200
スキルを作る、その前に!複数人で使われるスキルを 作るためのプロセス
junkifurukawa
2
360
AI 時代の Azure エンジニアリング ~ 私たちは何を磨き、何を任せるのか ~
chack411
1
540
Incremental HTTP
kazuho
5
2.1k
ビジネスを止めない技術的負債の返済のための戦略とその手法 - 技術的負債と向き合う / Complexity and Simplicity
soudai
PRO
3
670
AI駆動開発の時代になったのでトヨタ生産方式から見直す
terurou
4
5.1k
不可逆な意思決定を避けながら10億超の顧客データを AI Ready にするデータ基盤設計
baseballyama
1
190
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
330
Featured
See All Featured
Skip the Path - Find Your Career Trail
mkilby
1
250
4 Signs Your Business is Dying
shpigford
187
23k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
550
Game over? The fight for quality and originality in the time of robots
wayneb77
1
300
AI: The stuff that nobody shows you
jnunemaker
PRO
10
1.1k
SEO Brein meetup: CTRL+C is not how to scale international SEO
lindahogenes
2
2.9k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
Code Review Best Practice
trishagee
74
20k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
The Art of Delivering Value - GDevCon NA Keynote
reverentgeek
16
2.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
3k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
1.4k
Transcript
カーネルランド Rust 勉強会 #2 古賀信哉 株式会社アットマークテクノ
今日のネタ Rust の安全性と unsafe contract と仕様駆動開発 Rust と形式的検証 (formal verification)
Rust の安全性と unsafe カーネルランドでは避けられない unsafe Rust の安全性とは何か unsafe は、どのように安全じゃないのか Rust
の言語仕様が提供する仕組み 静的型付けによる静的検査 メモリ操作の制約(GC 無しのメモリ管理)
Rust の安全性と unsafe メモリ操作の制約(GC 無しのメモリ管理) mutable な大域変数のアクセスを禁止 ポインタの間接参照(逆参照)を禁止 値(メモリ領域)の所有者とスコープ 値(メモリ領域)の参照とスコープ
Rust の安全性と unsafe メモリ操作の制約(GC 無しのメモリ管理) mutable な大域変数のアクセスを禁止 ポインタの間接参照(逆参照)を禁止 値(メモリ領域)の所有者とスコープ 値(メモリ領域)の参照とスコープ
複数スレッド間のデータアクセス 競合問題を排除
Rust の安全性と unsafe メモリ操作の制約(GC 無しのメモリ管理) mutable な大域変数のアクセスを禁止 ポインタの間接参照(逆参照)を禁止 値(メモリ領域)の所有者とスコープ 値(メモリ領域)の参照とスコープ
ポインタ型の値を作ることはできる: ・値の参照からポインタ値を作る ・ポインタ変数に数値を代入する しかし、ポインタの逆参照は禁止。
Rust の安全性と unsafe 値(メモリ領域)のスコープと所有者 構文スコープによる値の生存スコープ 単一の所有者と、代入による所有先の移動 明示的な参照カウンタ型 基本型に対するコピーのセマンティクス Copy trait:
コピーセマンティクスの宣言
Rust の安全性と unsafe 値(メモリ領域)の参照とスコープ 参照の生存期間と値の生存期間 共有参照と変更可能な参照 (shared, mutable) 参照の借用 (borrow)
関数の入出力引数 変更参照のエイリアスを禁止 ・同じ値に対する参照と変更可能な参照 ・同じ値に対する複数の変更参照
Rust の安全性と unsafe unsafe だと許されること ポインタの逆参照 mutable な大域変数のアクセス unsafe な関数の呼び出し
unsafe な trait の実装 カーネルランドでは必須! 標準ライブラリ内部でも必要
Rust の安全性と unsafe Rust の unsafe の考え方(C# と比較) C#(の現在の)仕様 ⚫
unsafe な executable は全て unsafe Rust の仕様 ⚫ unsafe を safe なコードが内包できる! モジュールの public でない部分のみ unsafe に推奨される作法: ・contract の記述(事前条件、事後条件) C++ における例外仕様に通じる? C# の新仕様でも
Rust の安全性と unsafe Rust に導入されつつある contract 関数の属性/アノテーションとして記述 requires, ensures, invariant
⚫ 関数の仕様記述としての contract contract の情報を利用して、呼出し側と 呼び出される側の正しさをそれぞれ検証 できればベスト。 標準ライブラリの実装に対する検証の活動(後述)
contract と仕様駆動開発 AI 支援 SDD のテクニカルペーパー https://arxiv.org/html/2602.00180v1#S6 仕様としての contract ⚫
API 仕様化ツール (OpenAPI) ⚫ BDD (Behavior Driven Dev.) のシナリオ ⚫ ユースケース記述(事前条件、事後条件) 曖昧さのない、必要最小限の仕様: 生成 AI に、明確な context で指示することにより、 出力されるコードの精度が上がる。 ←間違いを最大50%削減できるという研究結果あり。
Rust と形式的検証 Rust Foundation によるinitiative 標準ライブラリの検証 検証ツールの導入 ⚫ Kani ⚫
GOTO-Transcoder ⚫ ESBMC model checker ⚫ VeriFast ⚫ Flux
Rust と形式的検証 Rust Foundation によるinitiative 標準ライブラリの検証 検証ツールの導入 ⚫ Kani ⚫
GOTO-Transcoder ⚫ ESBMC model checker ⚫ VeriFast ⚫ Flux https://model-checking.github.io/verify- rust-std/intro.html https://github.com/model-checking/verify- rust-std unsafe なコードに対する 検証
Rust と形式的検証 Rust Foundation によるinitiative 標準ライブラリの検証 検証ツールの導入 ⚫ Kani ⚫
GOTO-Transcoder ⚫ ESBMC model checker ⚫ VeriFast ⚫ Flux https://github.com/model-checking/kani https://github.com/esbmc/goto- transcoder/blob/main/docs/Architecture.md https://github.com/esbmc/esbmc https://github.com/verifast/verifas https://flux-rs.github.io/flux/
Rust と形式的検証 その他の形式的検証ツール Creusot ⚫ Coma(中間検証言語) ⚫ Why3(演繹的な検証器) rocq-of-rust ⚫
Rocq(以前の Coq)を利用 ⚫ Rust の型付き中間言語から Rocq に変換 ⚫ その後は手作業を交えて(?)検証 https://github.com/creusot-rs/creusot https://coma.paulpatault.fr/ https://why3.org/ https://github.com/formal-land/rocq-of-rust