$30 off During Our Annual Pro Sale. View Details »
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
Lookerで実現するセキュアな外部データ提供
zozotech
PRO
0
200
ソフトウェアエンジニアとAIエンジニアの役割分担についてのある事例
kworkdev
PRO
0
150
Entity Framework Core におけるIN句クエリ最適化について
htkym
0
110
アプリにAIを正しく組み込むための アーキテクチャ── 国産LLMの現実と実践
kohju
0
200
意外と知らない状態遷移テストの世界
nihonbuson
PRO
1
210
【U/Day Tokyo 2025】Cygames流 最新スマートフォンゲームの技術設計 〜『Shadowverse: Worlds Beyond』におけるアーキテクチャ再設計の挑戦~
cygames
PRO
2
1.4k
ExpoのインダストリーブースでみたAWSが見せる製造業の未来
hamadakoji
0
190
フィッシュボウルのやり方 / How to do a fishbowl
pauli
2
360
AWSの新機能をフル活用した「re:Inventエージェント」開発秘話
minorun365
2
400
日本Rubyの会: これまでとこれから
snoozer05
PRO
5
220
なぜ あなたはそんなに re:Invent に行くのか?
miu_crescent
PRO
0
130
普段使ってるClaude Skillsの紹介(by Notebooklm)
zerebom
8
2k
Featured
See All Featured
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
42
Faster Mobile Websites
deanohume
310
31k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
254
22k
Data-driven link building: lessons from a $708K investment (BrightonSEO talk)
szymonslowik
1
850
How To Stay Up To Date on Web Technology
chriscoyier
791
250k
Jamie Indigo - Trashchat’s Guide to Black Boxes: Technical SEO Tactics for LLMs
techseoconnect
PRO
0
29
Bash Introduction
62gerente
615
210k
GitHub's CSS Performance
jonrohan
1032
470k
We Are The Robots
honzajavorek
0
120
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
2
3.4k
The SEO Collaboration Effect
kristinabergwall1
0
300
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
26
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 ͕͋Δ͠ … ͓ΘΓʹ