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
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
「使いにくい」も「運用疲れ」も卒業する UIデザイナーとエンジニアが創る持続可能な内製開発
nrinetcom
PRO
1
770
Oracle Cloud Infrastructure:2026年2月度サービス・アップデート
oracle4engineer
PRO
0
200
Introduction to Sansan, inc / Sansan Global Development Center, Inc.
sansan33
PRO
0
3k
パネルディスカッション資料 (at Tableau Now! - 2026-02-26)
yoshitakaarakawa
0
1.1k
LINE Messengerの次世代ストレージ選定
lycorptech_jp
PRO
19
7.2k
「データとの対話」の現在地と未来
kobakou
0
1.3k
競争優位を生み出す戦略的内製開発の実践技法
masuda220
PRO
2
530
大規模サービスにおける レガシーコードからReactへの移行
magicpod
1
110
AI Coding Agentの地殻変動 ~ ai-coding.info の定点観測 ~
kotauchisunsun
1
510
類似画像検索モデルの開発ノウハウ
lycorptech_jp
PRO
2
590
Agentic Software Modernization - Back to the Roots (Zürich Agentic Coding and Architectures, März 2026)
feststelltaste
1
130
Windows ネットワークを再確認する
murachiakira
PRO
0
250
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
75
11k
What the history of the web can teach us about the future of AI
inesmontani
PRO
1
450
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
122
21k
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
400
VelocityConf: Rendering Performance Case Studies
addyosmani
333
24k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
35
3.4k
Ecommerce SEO: The Keys for Success Now & Beyond - #SERPConf2024
aleyda
1
1.8k
Hiding What from Whom? A Critical Review of the History of Programming languages for Music
tomoyanonymous
2
480
Statistics for Hackers
jakevdp
799
230k
Skip the Path - Find Your Career Trail
mkilby
1
72
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
220
The Invisible Side of Design
smashingmag
302
51k
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 ͕͋Δ͠ … ͓ΘΓʹ