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
Satoshi Moriai
January 27, 2020
Technology
0
640
Rust で Hypervisor.framework を 触ってみた(DOS編)
Rust で macOS の Hypervisor.framework をちらっと触ってみて、DOSエミュレータをつなげた話です。
Satoshi Moriai
January 27, 2020
Tweet
Share
Other Decks in Technology
See All in Technology
AIに視覚を与えモバイルアプリケーション開発をより円滑に行う
lycorptech_jp
PRO
1
780
OSSで構築するIT基盤管理実践事例: NetBox・Snipe-IT・FreeRADIUS+PrivacyIDEA / Practical Case Studies of IT Infrastructure Management Using OSS
nttcom
0
190
Windows ネットワークを再確認する
murachiakira
PRO
0
250
EMからICへ、二周目人材としてAI全振りのプロダクト開発で見つけた武器
yug1224
3
190
大規模な組織におけるAI Agent活用の促進と課題
lycorptech_jp
PRO
6
7.7k
名刺メーカーDevグループ 紹介資料
sansan33
PRO
0
1.1k
Agentic Software Modernization - Back to the Roots (Zürich Agentic Coding and Architectures, März 2026)
feststelltaste
1
140
Digitization部 紹介資料
sansan33
PRO
1
7k
実録・Platform Engineering 失敗から学び、AI時代の波を乗りこなす技術
sansantech
PRO
1
100
Introduction to Sansan Meishi Maker Development Engineer
sansan33
PRO
0
360
「ヒットする」+「近い」を同時にかなえるスマートサジェストの作り方.pdf
nakasho
0
100
【PyCon mini Shizuoka 2026】生成AI時代に画像処理やオーディオ処理のノードエディターを作る理由
kazuhitotakahashi
0
280
Featured
See All Featured
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
The Limits of Empathy - UXLibs8
cassininazir
1
240
Scaling GitHub
holman
464
140k
How STYLIGHT went responsive
nonsquared
100
6k
B2B Lead Gen: Tactics, Traps & Triumph
marketingsoph
0
65
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
68
A designer walks into a library…
pauljervisheath
210
24k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
26
3.4k
Building Flexible Design Systems
yeseniaperezcruz
330
40k
Agile that works and the tools we love
rasmusluckow
331
21k
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
0
590
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
190
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 ͕͋Δ͠ … ͓ΘΓʹ