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と新時代を切り拓く。これからのSREとメルカリIBISの挑戦
0gm
2
3.1k
usermode linux without MMU - fosdem2026 kernel devroom
thehajime
0
240
Bedrock PolicyでAmazon Bedrock Guardrails利用を強制してみた
yuu551
0
260
量子クラウドサービスの裏側 〜Deep Dive into OQTOPUS〜
oqtopus
0
140
Frontier Agents (Kiro autonomous agent / AWS Security Agent / AWS DevOps Agent) の紹介
msysh
3
180
10Xにおける品質保証活動の全体像と改善 #no_more_wait_for_test
nihonbuson
PRO
2
330
CDK対応したAWS DevOps Agentを試そう_20260201
masakiokuda
1
380
What happened to RubyGems and what can we learn?
mikemcquaid
0
310
インフラエンジニア必見!Kubernetesを用いたクラウドネイティブ設計ポイント大全
daitak
1
380
マーケットプレイス版Oracle WebCenter Content For OCI
oracle4engineer
PRO
5
1.6k
【Oracle Cloud ウェビナー】[Oracle AI Database + AWS] Oracle Database@AWSで広がるクラウドの新たな選択肢とAI時代のデータ戦略
oracle4engineer
PRO
2
180
Oracle AI Database移行・アップグレード勉強会 - RAT活用編
oracle4engineer
PRO
0
110
Featured
See All Featured
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
5.8k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
190
Rails Girls Zürich Keynote
gr2m
96
14k
We Are The Robots
honzajavorek
0
170
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
1
750
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1k
Leo the Paperboy
mayatellez
4
1.4k
Six Lessons from altMBA
skipperchong
29
4.2k
Balancing Empowerment & Direction
lara
5
890
Kristin Tynski - Automating Marketing Tasks With AI
techseoconnect
PRO
0
150
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
25
1.7k
How to build a perfect <img>
jonoalderson
1
4.9k
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 ͕͋Δ͠ … ͓ΘΓʹ