Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rust で Hypervisor.framework を 触ってみた(DOS編)
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Satoshi Moriai
January 27, 2020
Technology
650
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Rust で Hypervisor.framework を 触ってみた(DOS編)
Rust で macOS の Hypervisor.framework をちらっと触ってみて、DOSエミュレータをつなげた話です。
Satoshi Moriai
January 27, 2020
Other Decks in Technology
See All in Technology
秘密度ラベル初心者が第1歩でつまづかないための「設計・運用」ポイント
seafay
PRO
1
550
MySQL & MySQL HeatWave Report - June 2026
freshdaz
0
270
スタートアップにおけるアジャイルの実践について #shibuyagile
murabayashi
3
1.8k
BPaaSで進むAIオペレーションの現在地 AI実装が効く領域とスケーラビリティの選定と実装
kentarofujii
0
250
「軸足」は 固定しなくていい - 熱量と強みで描く、しなやかなキャリアの形
kakehashi
PRO
1
320
從觀望到全公司落地:AI Agentic Coding 導入實戰 — 流程整合與安全治理
appleboy
1
420
AWS Summit の片隅で、体育座りしながらコミュニティがにぎわう理由を考えた
k_adachi_01
2
330
4人目のSREはAgent
tanimuyk
0
350
“全部コピーしない”ファイルデータの活用 : — FSx for ONTAP × S3 Tables × Icebergで作るメタデータカタログ
yoshiki0705
0
210
時期が悪い!それでもRaspberry Piを買って遊んで活用するには / 20260627-osc26do-rpi-jikigawarui
akkiesoft
1
960
Kotlin 開発のツラミを爆破した話! / Explode the difficulty of Kotlin dev!
eller86
0
130
40代で“やっとエンジニアになれた”――閉じた学びを開き、空の青さを知る / 20260628 Naoki Takahashi
shift_evolve
PRO
4
1.5k
Featured
See All Featured
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
500
KATA
mclloyd
PRO
35
15k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
231
55k
Product Roadmaps are Hard
iamctodd
PRO
55
12k
Imperfection Machines: The Place of Print at Facebook
scottboms
270
14k
Test your architecture with Archunit
thirion
1
2.3k
Designing for Performance
lara
611
70k
Discover your Explorer Soul
emna__ayadi
2
1.2k
How STYLIGHT went responsive
nonsquared
100
6.2k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
38
2.9k
RailsConf 2023
tenderlove
30
1.5k
So, you think you're a good person
axbom
PRO
2
2.1k
Transcript
Rust Ͱ Hypervisor.framework Λ ৮ͬͯΈͨ ʙ ͦͷ̍ʙ ʙ DOS Λಈ͔ͯ͠Έͨ
ʙ 2020/1/27 Rust LT #8 @moriai19
ࣗݾհ • ߹ හʢSatoshi Moriai / Shiisaa Moriaiʣ • https://github.com/moriai
• https://twitter.com/moriai19 • ੲ OSʢMach / Real-Time Mach, Linuxʣ ʢࢄʣϑΝΠϧγεςϜͷ։ൃΛ͍ͯͨ͠ • ࠓ … • झຯͰ Rust Swift ͱٔΕΔ
ͬͯΈ͍ͨ͜ͱ • Rust ࠷৽ٕज़Ͱࢄܕ OS ͷ։ൃ͕গָ͠ʹͳΔ͔ • Mach Λ C
Ͱ։ൃ͢Δͷେมͩͬͨ • ΠϯλʔϑΣʔε͕ໃ६ͨ͠ίʔυͰϏϧυͰ͖ɺ σόοάʹແବͳ࿑ྗΛඅͨ͠ • ϑϧϏϧυ͔͔࣌ؒΓ͗͢ɺΠϯΫϦϝϯλϧϏϧυ ෆશ • macOS ͕͖ͳͷͰɺͬͱ࿔ΜͰΈ͍ͨ
ͱ͍͏͜ͱͰɺ Rust Ͱ macOS ͷ Hypervisor framework Λ ৮ͬͯΈΔ͜ͱʹͨ͠
macOS Hypervisor framework ͱ Virtual Memory Threads Mach AppleHV.kext hv_task_trap()
hv_thread_trap() VMX Driver Hypervisor Virtualized XXX ʢԾϚγϯɺԾOSͳͲʣ Ϣʔβϓϩηε ʢϢʔβλεΫʣ Rust crate xhypervisor crate hypervisor ͋Δ͕ ϝϯς͞Εͯͳ͍༷ Apple ͔Βఏڙ͞ΕΔ API C, Swift macOS kernel ʢDarwinʣ ɾɾɾ BSD • ԾԽͷͨΊͷܰྔͳϋΠύόΠβϑϨʔϜϫʔΫ • Intel VMX ΛϢʔβϓϩηε͔Β؆୯ʹར༻Ͱ͖Δ • ΧʔωϧΤΫεςϯγϣϯ AppleHV ͷڮ͠Λ͢Δ Hypervisor.framework
ϋΠύόΠβΛϓϩάϥϜͯ͠ΈΔ
ɹfn main() -> Result<(),Error> { ɹ create_vm()?; ɹ let mut
mem = vec![0u8; MEMSIZE]; ɹ map_mem(&mem, 0, &perm)?; ɹ let handle = thread::spawn(|| { // VCPU͕ෳͳΒɺͦͷͷεϨουΛىಈ ɹ let vcpu = vCPU::new()?; ɹ VCPUͷઃఆ; ϝϞϦ্ʹϓϩάϥϜσʔλΛஔ; Ϩδελͷઃఆ; ɹ loop { ɹ vcpu.run(); // VMENTER → VCPUͷ࣮ߦ → VMEXIT ɹ match vcpu.read_vmcs(VMCS_RO_EXIT_REASON)? { ɹ vmx_exit::VMX_REASON_EXC_NMI => ྫ֎NMIͷॲཧ, ɹ vmx_exit::VMX_REASON_HLT => break, ɹ ... ɹ } ɹ } ɹ vcpu.destroy()?; ɹ }); ɹ handle.join()?; ɹ unmap_mem(0, MEMSIZE)?; ɹ destroy_vm()?; ɹ}
DOSΛಈ͔ͯ͠ΈΔ • C++ DOS ΤϛϡϨʔλʢhttps://github.com/mist64/hvdos.gitʣΛར༻ • ϋΠύόΠβͱಉۭؒ͡Ͱಈ࡞ • DOSγεςϜίʔϧʢINT xxH,
AH=yyʣ૬Λ Unix γεςϜίʔϧͰ࣮ • DOS 2.x γεςϜίʔϧ 87 ݸͷ͏ͪ 29 ݸΛ࣮ʢΦϦδφϧʹ̏ݸՃʣ • ϋΠύόΠβʢRustʣ • VCPU Λ 16bit ϦΞϧϞʔυ༻ʹઃఆ͠ɺDOS ϓϩάϥϜΛϝϞϦʹషΓ͚ɺIP ͱ SP Λઃఆͯ͠ɺvcpu.run() • INT ͕ൃੜ → VMEXIT → ׂΓࠐΈ൪߸ΛऔΓग़͠ɺϥούʔܦ༝ͰDOS ΤϛϡϨʔ λΛݺͼग़͢ → vcpu.run()
DOSϓϩάϥϜ͕ಈ͖·ͨ͠ • ωοτ্Ͱݟ͚ͭͨόΠφϦ͕ಈ͖·ͨ͠ • HELLO.COM • MORE.COM • COMP.COM •
PKUNZJR.COM
• ιʔείʔυ github Ͱެ։ • https://github.com/moriai/hvdos.rs.git • ࣍ճ͏গ͠ Rust ͷεϥΠυΛ૿͍ͨ͠
• 64bit OS & શ Rust ԽʹτϥΠʁ • Ͱɺطʹ noah ͕͋Δ͠ … ͓ΘΓʹ