diff options
Diffstat (limited to 'src/kvm_rs')
-rw-r--r-- | src/kvm_rs/cap.rs.html | 75 | ||||
-rw-r--r-- | src/kvm_rs/fmt.rs.html | 38 | ||||
-rw-r--r-- | src/kvm_rs/kvm.rs.html | 82 | ||||
-rw-r--r-- | src/kvm_rs/kvm_sys.rs.html | 46 | ||||
-rw-r--r-- | src/kvm_rs/lib.rs.html | 84 | ||||
-rw-r--r-- | src/kvm_rs/vcpu.rs.html | 60 | ||||
-rw-r--r-- | src/kvm_rs/vm.rs.html | 32 | ||||
-rw-r--r-- | src/kvm_rs/x86_64.rs.html | 4 |
8 files changed, 270 insertions, 151 deletions
diff --git a/src/kvm_rs/cap.rs.html b/src/kvm_rs/cap.rs.html new file mode 100644 index 0000000..72b076d --- /dev/null +++ b/src/kvm_rs/cap.rs.html @@ -0,0 +1,75 @@ +<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/cap.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>cap.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> +<link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> + <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> +<span id="2"> 2</span> +<span id="3"> 3</span> +<span id="4"> 4</span> +<span id="5"> 5</span> +<span id="6"> 6</span> +<span id="7"> 7</span> +<span id="8"> 8</span> +<span id="9"> 9</span> +<span id="10">10</span> +<span id="11">11</span> +<span id="12">12</span> +<span id="13">13</span> +<span id="14">14</span> +<span id="15">15</span> +<span id="16">16</span> +<span id="17">17</span> +<span id="18">18</span> +<span id="19">19</span> +<span id="20">20</span> +<span id="21">21</span> +<span id="22">22</span> +<span id="23">23</span> +<span id="24">24</span> +<span id="25">25</span> +<span id="26">26</span> +<span id="27">27</span> +<span id="28">28</span> +<span id="29">29</span> +<span id="30">30</span> +<span id="31">31</span> +<span id="32">32</span> +<span id="33">33</span> +<span id="34">34</span> +</pre><div class="example-wrap"><pre class="rust "> +<span class="doccomment">//! Definitions of KVM capabilities.</span> + +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::kvm_sys</span>; +<span class="kw">use</span> <span class="ident">std::convert::Into</span>; + +<span class="doccomment">/// Definition of capabilities that return a bool value indicating whether the capability is</span> +<span class="doccomment">/// supported or not.</span> +<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">u64</span>)]</span> +<span class="kw">pub</span> <span class="kw">enum</span> <span class="ident">CapBool</span> { + <span class="doccomment">/// Check if capabilities can be queried on VM fds (`KVM_CAP_CHECK_EXTENSION_VM`).</span> + <span class="ident">CheckExtensionVm</span> <span class="op">=</span> <span class="ident">kvm_sys::KVM_CAP_CHECK_EXTENSION_VM</span>, +} + +<span class="kw">impl</span> <span class="ident">Into</span><span class="op"><</span><span class="ident">u64</span><span class="op">></span> <span class="kw">for</span> <span class="ident">CapBool</span> { + <span class="kw">fn</span> <span class="ident">into</span>(<span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">u64</span> { + <span class="self">self</span> <span class="kw">as</span> <span class="ident">u64</span> + } +} + +<span class="doccomment">/// Definition of capabilities that return an integer value indicating the amount of the queried</span> +<span class="doccomment">/// capability.</span> +<span class="attribute">#[<span class="ident">repr</span>(<span class="ident">u64</span>)]</span> +<span class="kw">pub</span> <span class="kw">enum</span> <span class="ident">CapInt</span> { + <span class="doccomment">/// Get the recommended max VPCUs (`KVM_CAP_NR_VCPUS`).</span> + <span class="ident">NrVcpus</span> <span class="op">=</span> <span class="ident">kvm_sys::KVM_CAP_NR_VCPUS</span>, + <span class="doccomment">/// Get the possible max VPCUs (`KVM_CAP_MAX_VCPUS`).</span> + <span class="ident">MaxVcpus</span> <span class="op">=</span> <span class="ident">kvm_sys::KVM_CAP_MAX_VCPUS</span>, +} + +<span class="kw">impl</span> <span class="ident">Into</span><span class="op"><</span><span class="ident">u64</span><span class="op">></span> <span class="kw">for</span> <span class="ident">CapInt</span> { + <span class="kw">fn</span> <span class="ident">into</span>(<span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">u64</span> { + <span class="self">self</span> <span class="kw">as</span> <span class="ident">u64</span> + } +} +</pre></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> + <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/fmt.rs.html b/src/kvm_rs/fmt.rs.html index ec871ef..006e8c1 100644 --- a/src/kvm_rs/fmt.rs.html +++ b/src/kvm_rs/fmt.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/fmt.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>fmt.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -131,14 +131,14 @@ <span id="128">128</span> <span id="129">129</span> </pre><div class="example-wrap"><pre class="rust "> -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fmt</span>; +<span class="kw">use</span> <span class="ident">std::fmt</span>; -<span class="kw">use</span> <span class="kw">crate</span>::<span class="ident">kvm_sys</span>::{<span class="ident">kvm_dtable</span>, <span class="ident">kvm_regs</span>, <span class="ident">kvm_segment</span>, <span class="ident">kvm_sregs</span>}; -<span class="kw">use</span> <span class="kw">crate</span>::<span class="ident">x86_64</span>::<span class="kw-2">*</span>; +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::kvm_sys</span>::{<span class="ident">kvm_dtable</span>, <span class="ident">kvm_regs</span>, <span class="ident">kvm_segment</span>, <span class="ident">kvm_sregs</span>}; +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::x86_64</span>::<span class="kw-2">*</span>; -<span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Display</span> <span class="kw">for</span> <span class="ident">kvm_regs</span> { - <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { - <span class="macro">write</span><span class="macro">!</span>( +<span class="kw">impl</span> <span class="ident">fmt::Display</span> <span class="kw">for</span> <span class="ident">kvm_regs</span> { + <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> { + <span class="macro">write!</span>( <span class="ident">f</span>, <span class="string">"rax: {:#018x} rbx: {:#018x} rcx: {:#018x} rdx: {:#018x}\n\ rsi: {:#018x} rdi: {:#018x}\n\ @@ -175,12 +175,12 @@ } } -<span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Display</span> <span class="kw">for</span> <span class="ident">kvm_segment</span> { - <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { +<span class="kw">impl</span> <span class="ident">fmt::Display</span> <span class="kw">for</span> <span class="ident">kvm_segment</span> { + <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> { <span class="kw">if</span> <span class="self">self</span>.<span class="ident">present</span> <span class="op">=</span><span class="op">=</span> <span class="number">0</span> { - <span class="macro">write</span><span class="macro">!</span>(<span class="ident">f</span>, <span class="string">"{:#04x} P(0)"</span>, <span class="self">self</span>.<span class="ident">selector</span>) + <span class="macro">write!</span>(<span class="ident">f</span>, <span class="string">"{:#04x} P(0)"</span>, <span class="self">self</span>.<span class="ident">selector</span>) } <span class="kw">else</span> { - <span class="macro">write</span><span class="macro">!</span>( + <span class="macro">write!</span>( <span class="ident">f</span>, <span class="string">"{:#06x} T({}) RPL({}) BASE({:#010x}) LIMIT({:#07x}) P(1) S({}) DPL({}) DB({}) L({}) TYPE({})"</span>, <span class="self">self</span>.<span class="ident">selector</span>, @@ -213,22 +213,22 @@ <span class="number">13</span> <span class="op">=</span><span class="op">></span> <span class="string">"C:X-AC"</span>, <span class="number">14</span> <span class="op">=</span><span class="op">></span> <span class="string">"C:XR-C"</span>, <span class="number">15</span> <span class="op">=</span><span class="op">></span> <span class="string">"C:XRAC"</span>, - <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable</span><span class="macro">!</span>(), + <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable!</span>(), } ) } } } -<span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Display</span> <span class="kw">for</span> <span class="ident">kvm_dtable</span> { - <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { - <span class="macro">write</span><span class="macro">!</span>(<span class="ident">f</span>, <span class="string">"BASE({:#018x}) LIMIT({:#07x})"</span>, <span class="self">self</span>.<span class="ident">base</span>, <span class="self">self</span>.<span class="ident">limit</span>) +<span class="kw">impl</span> <span class="ident">fmt::Display</span> <span class="kw">for</span> <span class="ident">kvm_dtable</span> { + <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> { + <span class="macro">write!</span>(<span class="ident">f</span>, <span class="string">"BASE({:#018x}) LIMIT({:#07x})"</span>, <span class="self">self</span>.<span class="ident">base</span>, <span class="self">self</span>.<span class="ident">limit</span>) } } -<span class="kw">impl</span> <span class="ident">fmt</span>::<span class="ident">Display</span> <span class="kw">for</span> <span class="ident">kvm_sregs</span> { - <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt</span>::<span class="ident">Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt</span>::<span class="prelude-ty">Result</span> { - <span class="macro">write</span><span class="macro">!</span>( +<span class="kw">impl</span> <span class="ident">fmt::Display</span> <span class="kw">for</span> <span class="ident">kvm_sregs</span> { + <span class="kw">fn</span> <span class="ident">fmt</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">f</span>: <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">fmt::Formatter</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span>) <span class="op">-</span><span class="op">></span> <span class="ident">fmt::Result</span> { + <span class="macro">write!</span>( <span class="ident">f</span>, <span class="string">"cs : {}\n\ ds : {}\n\ @@ -261,5 +261,5 @@ } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/kvm.rs.html b/src/kvm_rs/kvm.rs.html index ccd6c37..43a3f1e 100644 --- a/src/kvm_rs/kvm.rs.html +++ b/src/kvm_rs/kvm.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/kvm.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>kvm.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -53,15 +53,37 @@ <span id="50">50</span> <span id="51">51</span> <span id="52">52</span> +<span id="53">53</span> +<span id="54">54</span> +<span id="55">55</span> +<span id="56">56</span> +<span id="57">57</span> +<span id="58">58</span> +<span id="59">59</span> +<span id="60">60</span> +<span id="61">61</span> +<span id="62">62</span> +<span id="63">63</span> +<span id="64">64</span> +<span id="65">65</span> +<span id="66">66</span> +<span id="67">67</span> +<span id="68">68</span> +<span id="69">69</span> +<span id="70">70</span> +<span id="71">71</span> +<span id="72">72</span> +<span id="73">73</span> </pre><div class="example-wrap"><pre class="rust "> <span class="doccomment">//! KVM system ioctls.</span> -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">io</span>::<span class="ident">FromRawFd</span>; +<span class="kw">use</span> <span class="ident">std::fs</span>; +<span class="kw">use</span> <span class="ident">std::io</span>; +<span class="kw">use</span> <span class="ident">std::os::unix::io::FromRawFd</span>; -<span class="kw">use</span> <span class="kw">crate</span>::{<span class="ident">libcret</span>, <span class="ident">ioctl</span>, <span class="ident">kvm_sys</span>}; -<span class="kw">use</span> <span class="kw">crate</span>::<span class="ident">vm</span>::<span class="ident">Vm</span>; +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::cap</span>::{<span class="ident">CapBool</span>, <span class="ident">CapInt</span>}; +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::vm::Vm</span>; +<span class="kw">use</span> <span class="kw">crate</span>::{<span class="ident">ioctl</span>, <span class="ident">kvm_sys</span>, <span class="ident">libcret</span>}; <span class="doccomment">/// Wrapper for `/dev/kvm` ioctls.</span> <span class="doccomment">///</span> @@ -70,42 +92,62 @@ <span class="doccomment">///</span> <span class="doccomment">/// [kvm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#general-description</span> <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Kvm</span> { - <span class="ident">kvm</span>: <span class="ident">fs</span>::<span class="ident">File</span>, + <span class="ident">kvm</span>: <span class="ident">fs::File</span>, } <span class="kw">impl</span> <span class="ident">Kvm</span> { <span class="doccomment">/// Open the `/dev/kvm` device.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>() <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Kvm</span><span class="op">></span> { + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>() <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">Kvm</span><span class="op">></span> { <span class="kw">let</span> <span class="ident">kvm</span> <span class="op">=</span> <span class="ident">libcret</span>(<span class="kw">unsafe</span> { - <span class="ident">libc</span>::<span class="ident">open</span>(<span class="string">"/dev/kvm\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), <span class="ident">libc</span>::<span class="ident">O_RDWR</span> <span class="op">|</span> <span class="ident">libc</span>::<span class="ident">O_CLOEXEC</span>) + <span class="ident">libc::open</span>(<span class="string">"/dev/kvm\0"</span>.<span class="ident">as_ptr</span>().<span class="ident">cast</span>(), <span class="ident">libc::O_RDWR</span> <span class="op">|</span> <span class="ident">libc::O_CLOEXEC</span>) }) - .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs</span>::<span class="ident">File</span>::<span class="ident">from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; + .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs::File::from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; - <span class="macro">assert_eq</span><span class="macro">!</span>( - <span class="ident">kvm_sys</span>::<span class="ident">KVM_API_VERSION</span>, - <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="ident">kvm</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_GET_API_VERSION</span>, <span class="number">0</span>)<span class="question-mark">?</span> + <span class="macro">assert_eq!</span>( + <span class="ident">kvm_sys::KVM_API_VERSION</span>, + <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="ident">kvm</span>, <span class="ident">kvm_sys::KVM_GET_API_VERSION</span>, <span class="number">0</span>)<span class="question-mark">?</span> ); <span class="prelude-val">Ok</span>(<span class="ident">Kvm</span> { <span class="ident">kvm</span> }) } - <span class="kw">fn</span> <span class="ident">get_vpcu_mmap_size</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span> { - <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_GET_VCPU_MMAP_SIZE</span>, <span class="number">0</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">size</span><span class="op">|</span> <span class="ident">size</span> <span class="kw">as</span> <span class="ident">usize</span>) + <span class="kw">fn</span> <span class="ident">get_vpcu_mmap_size</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">usize</span><span class="op">></span> { + <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys::KVM_GET_VCPU_MMAP_SIZE</span>, <span class="number">0</span>).<span class="ident">map</span>(<span class="op">|</span><span class="ident">size</span><span class="op">|</span> <span class="ident">size</span> <span class="kw">as</span> <span class="ident">usize</span>) } <span class="doccomment">/// Create a new virtual machine with the [`KVM_CREATE_VM`][kvm-create-vm] ioctl.</span> <span class="doccomment">/// Returns a wrapper [`vm::Vm`][crate::vm::Vm] representing the VM.</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-create-vm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-create-vm</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">create_vm</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vm</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">vm</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_CREATE_VM</span>, <span class="number">0</span> <span class="comment">/* machine id */</span>) - .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs</span>::<span class="ident">File</span>::<span class="ident">from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">create_vm</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">Vm</span><span class="op">></span> { + <span class="kw">let</span> <span class="ident">vm</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys::KVM_CREATE_VM</span>, <span class="number">0</span> <span class="comment">/* machine id */</span>) + .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs::File::from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">vcpu_mmap_size</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">get_vpcu_mmap_size</span>()<span class="question-mark">?</span>; - <span class="prelude-val">Ok</span>(<span class="ident">Vm</span>::<span class="ident">new</span>(<span class="ident">vm</span>, <span class="ident">vcpu_mmap_size</span>)) + <span class="prelude-val">Ok</span>(<span class="ident">Vm::new</span>(<span class="ident">vm</span>, <span class="ident">vcpu_mmap_size</span>)) + } + + <span class="doccomment">/// Check availability of an extension with the [`KVM_CHECK_EXTENSION`][kvm-check-extension]</span> + <span class="doccomment">/// ioctl.</span> + <span class="doccomment">///</span> + <span class="doccomment">/// [kvm-check-extension]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-check-extension</span> + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">check_extenstion</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">cap</span>: <span class="ident">CapBool</span>) <span class="op">-</span><span class="op">></span> <span class="ident">bool</span> { + <span class="kw">let</span> <span class="ident">ret</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys::KVM_CHECK_EXTENSION</span>, <span class="ident">cap</span>.<span class="ident">into</span>()); + + <span class="macro">matches!</span>(<span class="ident">ret</span>, <span class="prelude-val">Ok</span>(<span class="ident">ret</span>) <span class="kw">if</span> <span class="ident">ret</span> <span class="op">></span> <span class="number">0</span>) + } + + <span class="doccomment">/// Check availability of an extension with the [`KVM_CHECK_EXTENSION`][kvm-check-extension]</span> + <span class="doccomment">/// ioctl.</span> + <span class="doccomment">///</span> + <span class="doccomment">/// [kvm-check-extension]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-check-extension</span> + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">check_extenstion_int</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">cap</span>: <span class="ident">CapInt</span>) <span class="op">-</span><span class="op">></span> <span class="ident">i32</span> { + <span class="kw">let</span> <span class="ident">ret</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">kvm</span>, <span class="ident">kvm_sys::KVM_CHECK_EXTENSION</span>, <span class="ident">cap</span>.<span class="ident">into</span>()); + + <span class="ident">ret</span>.<span class="ident">unwrap_or</span>(<span class="number">0</span>) } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/kvm_sys.rs.html b/src/kvm_rs/kvm_sys.rs.html index 44136b6..9fbbf41 100644 --- a/src/kvm_rs/kvm_sys.rs.html +++ b/src/kvm_rs/kvm_sys.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/kvm_sys.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>kvm_sys.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -208,7 +208,7 @@ <span class="attribute">#![<span class="ident">allow</span>(<span class="ident">dead_code</span>)]</span> <span class="comment">// Generated by `build.rs`.</span> -<span class="macro">include</span><span class="macro">!</span>(<span class="macro">concat</span><span class="macro">!</span>(<span class="macro">env</span><span class="macro">!</span>(<span class="string">"OUT_DIR"</span>), <span class="string">"/kvm_constants.rs"</span>)); +<span class="macro">include!</span>(<span class="macro">concat!</span>(<span class="macro">env!</span>(<span class="string">"OUT_DIR"</span>), <span class="string">"/kvm_constants.rs"</span>)); <span class="attribute">#[<span class="ident">repr</span>(<span class="ident">C</span>)]</span> <span class="attribute">#[<span class="ident">derive</span>(<span class="ident">Default</span>, <span class="ident">Debug</span>)]</span> @@ -345,57 +345,57 @@ <span class="attribute">#[<span class="ident">cfg</span>(<span class="ident">test</span>)]</span> <span class="kw">mod</span> <span class="ident">tests</span> { <span class="kw">use</span> <span class="kw">super</span>::<span class="kw-2">*</span>; - <span class="kw">use</span> <span class="ident">std</span>::<span class="ident">mem</span>; + <span class="kw">use</span> <span class="ident">std::mem</span>; <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_regs</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_regs</span><span class="op">></span>(), <span class="ident">TEST_KVM_REGS_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_regs</span><span class="op">></span>(), <span class="ident">TEST_KVM_REGS_ALIGN</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_regs</span><span class="op">></span>(), <span class="ident">TEST_KVM_REGS_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_regs</span><span class="op">></span>(), <span class="ident">TEST_KVM_REGS_ALIGN</span>); } <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_segment</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_segment</span><span class="op">></span>(), <span class="ident">TEST_KVM_SEGMENT_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_segment</span><span class="op">></span>(), <span class="ident">TEST_KVM_SEGMENT_ALIGN</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_segment</span><span class="op">></span>(), <span class="ident">TEST_KVM_SEGMENT_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_segment</span><span class="op">></span>(), <span class="ident">TEST_KVM_SEGMENT_ALIGN</span>); } <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_dtable</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_dtable</span><span class="op">></span>(), <span class="ident">TEST_KVM_DTABLE_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_dtable</span><span class="op">></span>(), <span class="ident">TEST_KVM_DTABLE_ALIGN</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_dtable</span><span class="op">></span>(), <span class="ident">TEST_KVM_DTABLE_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_dtable</span><span class="op">></span>(), <span class="ident">TEST_KVM_DTABLE_ALIGN</span>); } <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_sregs</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_sregs</span><span class="op">></span>(), <span class="ident">TEST_KVM_SREGS_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_sregs</span><span class="op">></span>(), <span class="ident">TEST_KVM_SREGS_ALIGN</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>( - <span class="ident">mem</span>::<span class="ident">size_of_val</span>(<span class="kw-2">&</span><span class="ident">kvm_sregs</span>::<span class="ident">default</span>().<span class="ident">interrupt_bitmap</span>), + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_sregs</span><span class="op">></span>(), <span class="ident">TEST_KVM_SREGS_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_sregs</span><span class="op">></span>(), <span class="ident">TEST_KVM_SREGS_ALIGN</span>); + <span class="macro">assert_eq!</span>( + <span class="ident">mem::size_of_val</span>(<span class="kw-2">&</span><span class="ident">kvm_sregs::default</span>().<span class="ident">interrupt_bitmap</span>), <span class="ident">TEST_KVM_SREGS_INTERRTUP_BITMAP_SIZE</span> ); } <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_userspace_memory_region</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>( - <span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_userspace_memory_region</span><span class="op">></span>(), + <span class="macro">assert_eq!</span>( + <span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_userspace_memory_region</span><span class="op">></span>(), <span class="ident">TEST_KVM_USERSPACE_MEMORY_REGION_SIZE</span> ); - <span class="macro">assert_eq</span><span class="macro">!</span>( - <span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_userspace_memory_region</span><span class="op">></span>(), + <span class="macro">assert_eq!</span>( + <span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_userspace_memory_region</span><span class="op">></span>(), <span class="ident">TEST_KVM_USERSPACE_MEMORY_REGION_ALIGN</span> ); } <span class="attribute">#[<span class="ident">test</span>]</span> <span class="kw">fn</span> <span class="ident">check_kvm_run</span>() { - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_run</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">align_of</span>::<span class="op"><</span><span class="ident">kvm_run</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_ALIGN</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_run_io</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_IO_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_run_mmio</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_MMIO_SIZE</span>); - <span class="macro">assert_eq</span><span class="macro">!</span>(<span class="ident">mem</span>::<span class="ident">size_of</span>::<span class="op"><</span><span class="ident">kvm_run_union_s</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_UNION_S_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_run</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::align_of</span>::<span class="op"><</span><span class="ident">kvm_run</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_ALIGN</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_run_io</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_IO_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_run_mmio</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_MMIO_SIZE</span>); + <span class="macro">assert_eq!</span>(<span class="ident">mem::size_of</span>::<span class="op"><</span><span class="ident">kvm_run_union_s</span><span class="op">></span>(), <span class="ident">TEST_KVM_RUN_UNION_S_SIZE</span>); } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/lib.rs.html b/src/kvm_rs/lib.rs.html index 8d74487..2e03eed 100644 --- a/src/kvm_rs/lib.rs.html +++ b/src/kvm_rs/lib.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/lib.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>lib.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -166,12 +166,14 @@ <span id="163">163</span> <span id="164">164</span> <span id="165">165</span> +<span id="166">166</span> </pre><div class="example-wrap"><pre class="rust "> -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">convert</span>::{<span class="ident">AsMut</span>, <span class="ident">AsRef</span>}; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">ops</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">io</span>::<span class="ident">AsRawFd</span>; +<span class="kw">use</span> <span class="ident">std::convert</span>::{<span class="ident">AsMut</span>, <span class="ident">AsRef</span>}; +<span class="kw">use</span> <span class="ident">std::io</span>; +<span class="kw">use</span> <span class="ident">std::ops</span>; +<span class="kw">use</span> <span class="ident">std::os::unix::io::AsRawFd</span>; +<span class="kw">pub</span> <span class="kw">mod</span> <span class="ident">cap</span>; <span class="kw">mod</span> <span class="ident">fmt</span>; <span class="kw">pub</span> <span class="kw">mod</span> <span class="ident">kvm</span>; <span class="kw">pub</span> <span class="kw">mod</span> <span class="ident">kvm_sys</span>; @@ -184,9 +186,9 @@ <span class="doccomment">/// Helper to turn libc return values into an [io::Result](std::io::Result). Returns</span> <span class="doccomment">/// [`Error::last_os_error`](std::io::Error::last_os_error) if `ret < 0`.</span> -<span class="kw">fn</span> <span class="ident">libcret</span>(<span class="ident">ret</span>: <span class="ident">libc</span>::<span class="ident">c_int</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">libc</span>::<span class="ident">c_int</span><span class="op">></span> { +<span class="kw">fn</span> <span class="ident">libcret</span>(<span class="ident">ret</span>: <span class="ident">libc::c_int</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">libc::c_int</span><span class="op">></span> { <span class="kw">if</span> <span class="ident">ret</span> <span class="op"><</span> <span class="number">0</span> { - <span class="prelude-val">Err</span>(<span class="ident">io</span>::<span class="ident">Error</span>::<span class="ident">last_os_error</span>()) + <span class="prelude-val">Err</span>(<span class="ident">io::Error::last_os_error</span>()) } <span class="kw">else</span> { <span class="prelude-val">Ok</span>(<span class="ident">ret</span>) } @@ -194,8 +196,8 @@ <span class="doccomment">/// Wrapper of `libc::ioctl` for KVM ioctls with one argument and returning an</span> <span class="doccomment">/// [`io::Result`](std::io::Result).</span> -<span class="kw">fn</span> <span class="ident">ioctl</span><span class="op"><</span><span class="ident">F</span>: <span class="ident">AsRawFd</span><span class="op">></span>(<span class="ident">fd</span>: <span class="kw-2">&</span><span class="ident">F</span>, <span class="ident">cmd</span>: <span class="ident">u64</span>, <span class="ident">arg</span>: <span class="ident">u64</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">libc</span>::<span class="ident">c_int</span><span class="op">></span> { - <span class="ident">libcret</span>(<span class="kw">unsafe</span> { <span class="ident">libc</span>::<span class="ident">ioctl</span>(<span class="ident">fd</span>.<span class="ident">as_raw_fd</span>(), <span class="ident">cmd</span>, <span class="ident">arg</span>) }) +<span class="kw">fn</span> <span class="ident">ioctl</span><span class="op"><</span><span class="ident">F</span>: <span class="ident">AsRawFd</span><span class="op">></span>(<span class="ident">fd</span>: <span class="kw-2">&</span><span class="ident">F</span>, <span class="ident">cmd</span>: <span class="ident">u64</span>, <span class="ident">arg</span>: <span class="ident">u64</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">libc::c_int</span><span class="op">></span> { + <span class="ident">libcret</span>(<span class="kw">unsafe</span> { <span class="ident">libc::ioctl</span>(<span class="ident">fd</span>.<span class="ident">as_raw_fd</span>(), <span class="ident">cmd</span>, <span class="ident">arg</span>) }) } <span class="doccomment">/// Wrapper to safely allocate memory for guest VMs.</span> @@ -211,20 +213,20 @@ <span class="kw">impl</span> <span class="ident">UserMem</span> { <span class="doccomment">/// Allocate a zero-initialized memory region of `len` bytes.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">len</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">UserMem</span><span class="op">></span> { + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">len</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">UserMem</span><span class="op">></span> { <span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">libc</span>::<span class="ident">mmap</span>( - <span class="ident">std</span>::<span class="ident">ptr</span>::<span class="ident">null_mut</span>(), + <span class="ident">libc::mmap</span>( + <span class="ident">std::ptr::null_mut</span>(), <span class="ident">len</span>, - <span class="ident">libc</span>::<span class="ident">PROT_READ</span> <span class="op">|</span> <span class="ident">libc</span>::<span class="ident">PROT_WRITE</span>, - <span class="ident">libc</span>::<span class="ident">MAP_PRIVATE</span> <span class="op">|</span> <span class="ident">libc</span>::<span class="ident">MAP_ANONYMOUS</span>, + <span class="ident">libc::PROT_READ</span> <span class="op">|</span> <span class="ident">libc::PROT_WRITE</span>, + <span class="ident">libc::MAP_PRIVATE</span> <span class="op">|</span> <span class="ident">libc::MAP_ANONYMOUS</span>, <span class="op">-</span><span class="number">1</span>, <span class="number">0</span>, ) }; - <span class="kw">if</span> <span class="ident">ptr</span> <span class="op">=</span><span class="op">=</span> <span class="ident">libc</span>::<span class="ident">MAP_FAILED</span> { - <span class="prelude-val">Err</span>(<span class="ident">io</span>::<span class="ident">Error</span>::<span class="ident">last_os_error</span>()) + <span class="kw">if</span> <span class="ident">ptr</span> <span class="op">=</span><span class="op">=</span> <span class="ident">libc::MAP_FAILED</span> { + <span class="prelude-val">Err</span>(<span class="ident">io::Error::last_os_error</span>()) } <span class="kw">else</span> { <span class="prelude-val">Ok</span>(<span class="ident">UserMem</span> { <span class="ident">ptr</span>: <span class="ident">ptr</span>.<span class="ident">cast</span>(), @@ -239,10 +241,10 @@ <span class="doccomment">/// # Panics</span> <span class="doccomment">///</span> <span class="doccomment">/// Panics if `init_from` is larger than the memory size `len`.</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">with_init</span>(<span class="ident">len</span>: <span class="ident">usize</span>, <span class="ident">init_from</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>]) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">UserMem</span><span class="op">></span> { - <span class="macro">assert</span><span class="macro">!</span>(<span class="ident">len</span> <span class="op">></span><span class="op">=</span> <span class="ident">init_from</span>.<span class="ident">len</span>()); + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">with_init</span>(<span class="ident">len</span>: <span class="ident">usize</span>, <span class="ident">init_from</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>]) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">UserMem</span><span class="op">></span> { + <span class="macro">assert!</span>(<span class="ident">len</span> <span class="op">></span><span class="op">=</span> <span class="ident">init_from</span>.<span class="ident">len</span>()); - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">m</span> <span class="op">=</span> <span class="ident">UserMem</span>::<span class="ident">new</span>(<span class="ident">len</span>)<span class="question-mark">?</span>; + <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">m</span> <span class="op">=</span> <span class="ident">UserMem::new</span>(<span class="ident">len</span>)<span class="question-mark">?</span>; <span class="ident">m</span>.<span class="ident">load</span>(<span class="ident">PhysAddr</span>(<span class="number">0</span>), <span class="ident">init_from</span>); <span class="prelude-val">Ok</span>(<span class="ident">m</span>) } @@ -253,29 +255,29 @@ <span class="doccomment">///</span> <span class="doccomment">/// Panics if `addr + data.len` is larger than the memory size `len`.</span> <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">load</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>, <span class="ident">addr</span>: <span class="ident">PhysAddr</span>, <span class="ident">data</span>: <span class="kw-2">&</span>[<span class="ident">u8</span>]) { - <span class="macro">assert</span><span class="macro">!</span>(<span class="self">self</span>.<span class="ident">len</span> <span class="op">></span><span class="op">=</span> <span class="ident">addr</span>.<span class="number">0</span> <span class="kw">as</span> <span class="ident">usize</span> <span class="op">+</span> <span class="ident">data</span>.<span class="ident">len</span>()); + <span class="macro">assert!</span>(<span class="self">self</span>.<span class="ident">len</span> <span class="op">></span><span class="op">=</span> <span class="ident">addr</span>.<span class="number">0</span> <span class="kw">as</span> <span class="ident">usize</span> <span class="op">+</span> <span class="ident">data</span>.<span class="ident">len</span>()); <span class="kw">let</span> <span class="ident">addr</span> <span class="op">=</span> <span class="ident">addr</span>.<span class="number">0</span> <span class="kw">as</span> <span class="ident">usize</span>; <span class="self">self</span>.<span class="ident">as_mut</span>()[<span class="ident">addr</span>..<span class="ident">addr</span> <span class="op">+</span> <span class="ident">data</span>.<span class="ident">len</span>()].<span class="ident">copy_from_slice</span>(<span class="ident">data</span>); } } -<span class="kw">impl</span> <span class="ident">ops</span>::<span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">UserMem</span> { +<span class="kw">impl</span> <span class="ident">ops::Drop</span> <span class="kw">for</span> <span class="ident">UserMem</span> { <span class="doccomment">/// Free underlying memory.</span> <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">libc</span>::<span class="ident">munmap</span>(<span class="self">self</span>.<span class="ident">ptr</span>.<span class="ident">cast</span>(), <span class="self">self</span>.<span class="ident">len</span>) }; + <span class="kw">unsafe</span> { <span class="ident">libc::munmap</span>(<span class="self">self</span>.<span class="ident">ptr</span>.<span class="ident">cast</span>(), <span class="self">self</span>.<span class="ident">len</span>) }; } } <span class="kw">impl</span> <span class="ident">AsRef</span><span class="op"><</span>[<span class="ident">u8</span>]<span class="op">></span> <span class="kw">for</span> <span class="ident">UserMem</span> { <span class="kw">fn</span> <span class="ident">as_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span>[<span class="ident">u8</span>] { - <span class="kw">unsafe</span> { <span class="ident">std</span>::<span class="ident">slice</span>::<span class="ident">from_raw_parts</span>(<span class="self">self</span>.<span class="ident">ptr</span>, <span class="self">self</span>.<span class="ident">len</span>) } + <span class="kw">unsafe</span> { <span class="ident">std::slice::from_raw_parts</span>(<span class="self">self</span>.<span class="ident">ptr</span>, <span class="self">self</span>.<span class="ident">len</span>) } } } <span class="kw">impl</span> <span class="ident">AsMut</span><span class="op"><</span>[<span class="ident">u8</span>]<span class="op">></span> <span class="kw">for</span> <span class="ident">UserMem</span> { <span class="kw">fn</span> <span class="ident">as_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="kw-2">mut</span> [<span class="ident">u8</span>] { - <span class="kw">unsafe</span> { <span class="ident">std</span>::<span class="ident">slice</span>::<span class="ident">from_raw_parts_mut</span>(<span class="self">self</span>.<span class="ident">ptr</span>, <span class="self">self</span>.<span class="ident">len</span>) } + <span class="kw">unsafe</span> { <span class="ident">std::slice::from_raw_parts_mut</span>(<span class="self">self</span>.<span class="ident">ptr</span>, <span class="self">self</span>.<span class="ident">len</span>) } } } @@ -284,27 +286,27 @@ <span class="doccomment">///</span> <span class="doccomment">/// [kvm_run]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#the-kvm-run-structure</span> <span class="kw">struct</span> <span class="ident">KvmRun</span> { - <span class="ident">ptr</span>: <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span>, + <span class="ident">ptr</span>: <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys::kvm_run</span>, <span class="ident">len</span>: <span class="ident">usize</span>, } <span class="kw">impl</span> <span class="ident">KvmRun</span> { <span class="doccomment">/// Mmap the `struct kvm_run` for a given `VCPU` referenced by the argument file descriptor</span> <span class="doccomment">/// `vcpu`.</span> - <span class="kw">fn</span> <span class="ident">new</span><span class="op"><</span><span class="ident">F</span>: <span class="ident">AsRawFd</span><span class="op">></span>(<span class="ident">vcpu</span>: <span class="kw-2">&</span><span class="ident">F</span>, <span class="ident">len</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">KvmRun</span><span class="op">></span> { + <span class="kw">fn</span> <span class="ident">new</span><span class="op"><</span><span class="ident">F</span>: <span class="ident">AsRawFd</span><span class="op">></span>(<span class="ident">vcpu</span>: <span class="kw-2">&</span><span class="ident">F</span>, <span class="ident">len</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">KvmRun</span><span class="op">></span> { <span class="kw">let</span> <span class="ident">ptr</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">libc</span>::<span class="ident">mmap</span>( - <span class="ident">std</span>::<span class="ident">ptr</span>::<span class="ident">null_mut</span>(), + <span class="ident">libc::mmap</span>( + <span class="ident">std::ptr::null_mut</span>(), <span class="ident">len</span>, - <span class="ident">libc</span>::<span class="ident">PROT_READ</span> <span class="op">|</span> <span class="ident">libc</span>::<span class="ident">PROT_WRITE</span>, - <span class="ident">libc</span>::<span class="ident">MAP_SHARED</span>, + <span class="ident">libc::PROT_READ</span> <span class="op">|</span> <span class="ident">libc::PROT_WRITE</span>, + <span class="ident">libc::MAP_SHARED</span>, <span class="ident">vcpu</span>.<span class="ident">as_raw_fd</span>(), <span class="number">0</span>, ) }; - <span class="kw">if</span> <span class="ident">ptr</span> <span class="op">=</span><span class="op">=</span> <span class="ident">libc</span>::<span class="ident">MAP_FAILED</span> { - <span class="prelude-val">Err</span>(<span class="ident">io</span>::<span class="ident">Error</span>::<span class="ident">last_os_error</span>()) + <span class="kw">if</span> <span class="ident">ptr</span> <span class="op">=</span><span class="op">=</span> <span class="ident">libc::MAP_FAILED</span> { + <span class="prelude-val">Err</span>(<span class="ident">io::Error::last_os_error</span>()) } <span class="kw">else</span> { <span class="prelude-val">Ok</span>(<span class="ident">KvmRun</span> { <span class="ident">ptr</span>: <span class="ident">ptr</span>.<span class="ident">cast</span>(), @@ -314,24 +316,24 @@ } } -<span class="kw">impl</span> <span class="ident">ops</span>::<span class="ident">Drop</span> <span class="kw">for</span> <span class="ident">KvmRun</span> { +<span class="kw">impl</span> <span class="ident">ops::Drop</span> <span class="kw">for</span> <span class="ident">KvmRun</span> { <span class="doccomment">/// Munmap the mmaped `struct kvm_run`.</span> <span class="kw">fn</span> <span class="ident">drop</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) { - <span class="kw">unsafe</span> { <span class="ident">libc</span>::<span class="ident">munmap</span>(<span class="self">self</span>.<span class="ident">ptr</span>.<span class="ident">cast</span>(), <span class="self">self</span>.<span class="ident">len</span>) }; + <span class="kw">unsafe</span> { <span class="ident">libc::munmap</span>(<span class="self">self</span>.<span class="ident">ptr</span>.<span class="ident">cast</span>(), <span class="self">self</span>.<span class="ident">len</span>) }; } } -<span class="kw">impl</span> <span class="ident">AsRef</span><span class="op"><</span><span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span><span class="op">></span> <span class="kw">for</span> <span class="ident">KvmRun</span> { - <span class="kw">fn</span> <span class="ident">as_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span> { - <span class="kw">unsafe</span> { <span class="op">&</span> <span class="kw-2">*</span>(<span class="self">self</span>.<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span>) } +<span class="kw">impl</span> <span class="ident">AsRef</span><span class="op"><</span><span class="ident">kvm_sys::kvm_run</span><span class="op">></span> <span class="kw">for</span> <span class="ident">KvmRun</span> { + <span class="kw">fn</span> <span class="ident">as_ref</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="ident">kvm_sys::kvm_run</span> { + <span class="kw">unsafe</span> { <span class="kw-2">&</span><span class="kw-2">*</span>(<span class="self">self</span>.<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="ident">kvm_sys::kvm_run</span>) } } } -<span class="kw">impl</span> <span class="ident">AsMut</span><span class="op"><</span><span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span><span class="op">></span> <span class="kw">for</span> <span class="ident">KvmRun</span> { - <span class="kw">fn</span> <span class="ident">as_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span> { - <span class="kw">unsafe</span> { <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="kw-2">*</span>(<span class="self">self</span>.<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span>) } +<span class="kw">impl</span> <span class="ident">AsMut</span><span class="op"><</span><span class="ident">kvm_sys::kvm_run</span><span class="op">></span> <span class="kw">for</span> <span class="ident">KvmRun</span> { + <span class="kw">fn</span> <span class="ident">as_mut</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">kvm_sys::kvm_run</span> { + <span class="kw">unsafe</span> { <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="kw-2">*</span>(<span class="self">self</span>.<span class="ident">ptr</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys::kvm_run</span>) } } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/vcpu.rs.html b/src/kvm_rs/vcpu.rs.html index df4a7bc..849f338 100644 --- a/src/kvm_rs/vcpu.rs.html +++ b/src/kvm_rs/vcpu.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/vcpu.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>vcpu.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -140,8 +140,8 @@ </pre><div class="example-wrap"><pre class="rust "> <span class="doccomment">//! VCPU system ioctls.</span> -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>; +<span class="kw">use</span> <span class="ident">std::fs</span>; +<span class="kw">use</span> <span class="ident">std::io</span>; <span class="kw">use</span> <span class="kw">crate</span>::{<span class="ident">ioctl</span>, <span class="ident">kvm_sys</span>, <span class="ident">KvmRun</span>}; @@ -168,12 +168,12 @@ <span class="doccomment">/// [kvm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#general-description</span> <span class="doccomment">/// [kvm-create-vcpu]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-create-vcpu</span> <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Vcpu</span> { - <span class="ident">vcpu</span>: <span class="ident">fs</span>::<span class="ident">File</span>, + <span class="ident">vcpu</span>: <span class="ident">fs::File</span>, <span class="ident">kvm_run</span>: <span class="ident">KvmRun</span>, } <span class="kw">impl</span> <span class="ident">Vcpu</span> { - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">vcpu</span>: <span class="ident">fs</span>::<span class="ident">File</span>, <span class="ident">kvm_run</span>: <span class="ident">KvmRun</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Vcpu</span> { + <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">vcpu</span>: <span class="ident">fs::File</span>, <span class="ident">kvm_run</span>: <span class="ident">KvmRun</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Vcpu</span> { <span class="ident">Vcpu</span> { <span class="ident">vcpu</span>, <span class="ident">kvm_run</span> } } @@ -181,11 +181,11 @@ <span class="doccomment">/// [`kvm_regs`](crate::kvm_sys::kvm_regs).</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-get-regs]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-get-regs</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_regs</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">kvm_sys</span>::<span class="ident">kvm_regs</span><span class="op">></span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">regs</span> <span class="op">=</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_regs</span>::<span class="ident">default</span>(); + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_regs</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">kvm_sys::kvm_regs</span><span class="op">></span> { + <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">regs</span> <span class="op">=</span> <span class="ident">kvm_sys::kvm_regs::default</span>(); <span class="ident">ioctl</span>( <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, - <span class="ident">kvm_sys</span>::<span class="ident">KVM_GET_REGS</span>, + <span class="ident">kvm_sys::KVM_GET_REGS</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">regs</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>, )<span class="question-mark">?</span>; <span class="prelude-val">Ok</span>(<span class="ident">regs</span>) @@ -195,19 +195,19 @@ <span class="doccomment">/// [`kvm_regs`](crate::kvm_sys::kvm_regs).</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-set-regs]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-set-regs</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_regs</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">regs</span>: <span class="ident">kvm_sys</span>::<span class="ident">kvm_regs</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> { - <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_SET_REGS</span>, <span class="kw-2">&</span><span class="ident">regs</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>).<span class="ident">map</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> ()) + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_regs</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">regs</span>: <span class="ident">kvm_sys::kvm_regs</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span> { + <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, <span class="ident">kvm_sys::KVM_SET_REGS</span>, <span class="kw-2">&</span><span class="ident">regs</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>).<span class="ident">map</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> ()) } <span class="doccomment">/// Get the special registers with the [`KVM_GET_SREGS`][kvm-get-sregs] ioctl in form of</span> <span class="doccomment">/// [`kvm_sregs`](crate::kvm_sys::kvm_sregs).</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-get-sregs]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-get-sregs</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_sregs</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">kvm_sys</span>::<span class="ident">kvm_sregs</span><span class="op">></span> { - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">sregs</span> <span class="op">=</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_sregs</span>::<span class="ident">default</span>(); + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">get_sregs</span>(<span class="kw-2">&</span><span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">kvm_sys::kvm_sregs</span><span class="op">></span> { + <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">sregs</span> <span class="op">=</span> <span class="ident">kvm_sys::kvm_sregs::default</span>(); <span class="ident">ioctl</span>( <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, - <span class="ident">kvm_sys</span>::<span class="ident">KVM_GET_SREGS</span>, + <span class="ident">kvm_sys::KVM_GET_SREGS</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">sregs</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>, )<span class="question-mark">?</span>; <span class="prelude-val">Ok</span>(<span class="ident">sregs</span>) @@ -217,10 +217,10 @@ <span class="doccomment">/// [`kvm_sregs`](crate::kvm_sys::kvm_sregs).</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-set-sregs]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-set-sregs</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_sregs</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">sregs</span>: <span class="ident">kvm_sys</span>::<span class="ident">kvm_sregs</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> { + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">set_sregs</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">sregs</span>: <span class="ident">kvm_sys::kvm_sregs</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span> { <span class="ident">ioctl</span>( <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, - <span class="ident">kvm_sys</span>::<span class="ident">KVM_SET_SREGS</span>, + <span class="ident">kvm_sys::KVM_SET_SREGS</span>, <span class="kw-2">&</span><span class="ident">sregs</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>, ) .<span class="ident">map</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> ()) @@ -230,50 +230,50 @@ <span class="doccomment">/// reasons described in [`KvmExit`](crate::vcpu::KvmExit).</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-run]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-run</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">run</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">KvmExit</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span><span class="op">></span> { - <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_RUN</span>, <span class="number">0</span>)<span class="question-mark">?</span>; + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">run</span>(<span class="kw-2">&</span><span class="kw-2">mut</span> <span class="self">self</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">KvmExit</span><span class="op"><</span><span class="lifetime">'_</span><span class="op">></span><span class="op">></span> { + <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vcpu</span>, <span class="ident">kvm_sys::KVM_RUN</span>, <span class="number">0</span>)<span class="question-mark">?</span>; <span class="kw">let</span> <span class="ident">kvm_run</span> <span class="op">=</span> <span class="self">self</span>.<span class="ident">kvm_run</span>.<span class="ident">as_mut</span>(); <span class="kw">match</span> <span class="ident">kvm_run</span>.<span class="ident">exit_reason</span> <span class="kw">as</span> <span class="ident">u64</span> { - <span class="ident">kvm_sys</span>::<span class="ident">KVM_EXIT_HLT</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit</span>::<span class="ident">Halt</span>), - <span class="ident">kvm_sys</span>::<span class="ident">KVM_EXIT_IO</span> <span class="op">=</span><span class="op">></span> { + <span class="ident">kvm_sys::KVM_EXIT_HLT</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit::Halt</span>), + <span class="ident">kvm_sys::KVM_EXIT_IO</span> <span class="op">=</span><span class="op">></span> { <span class="comment">// Safe to use union `io` field, as Kernel instructed us to.</span> <span class="kw">let</span> <span class="ident">io</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="ident">kvm_run</span>.<span class="ident">inner</span>.<span class="ident">io</span> }; - <span class="kw">let</span> <span class="ident">kvm_run_ptr</span> <span class="op">=</span> <span class="ident">kvm_run</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_run</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">u8</span>; + <span class="kw">let</span> <span class="ident">kvm_run_ptr</span> <span class="op">=</span> <span class="ident">kvm_run</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">kvm_sys::kvm_run</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw-2">mut</span> <span class="ident">u8</span>; <span class="comment">// Create IO buffer located at `kvm_run + io.offset`.</span> <span class="kw">let</span> <span class="ident">data</span> <span class="op">=</span> <span class="kw">unsafe</span> { - <span class="ident">std</span>::<span class="ident">slice</span>::<span class="ident">from_raw_parts_mut</span>( + <span class="ident">std::slice::from_raw_parts_mut</span>( <span class="ident">kvm_run_ptr</span>.<span class="ident">offset</span>(<span class="ident">io</span>.<span class="ident">data_offset</span> <span class="kw">as</span> <span class="ident">isize</span>), <span class="ident">io</span>.<span class="ident">count</span> <span class="comment">/* num blocks */</span> <span class="kw">as</span> <span class="ident">usize</span> <span class="op">*</span> <span class="ident">io</span>.<span class="ident">size</span> <span class="comment">/* bytes per block */</span> <span class="kw">as</span> <span class="ident">usize</span>, ) }; <span class="kw">match</span> <span class="ident">io</span>.<span class="ident">direction</span> <span class="kw">as</span> <span class="ident">u64</span> { - <span class="ident">kvm_sys</span>::<span class="ident">KVM_EXIT_IO_IN</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit</span>::<span class="ident">IoIn</span>(<span class="ident">io</span>.<span class="ident">port</span>, <span class="ident">data</span>)), - <span class="ident">kvm_sys</span>::<span class="ident">KVM_EXIT_IO_OUT</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit</span>::<span class="ident">IoOut</span>(<span class="ident">io</span>.<span class="ident">port</span>, <span class="ident">data</span>)), - <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable</span><span class="macro">!</span>(), + <span class="ident">kvm_sys::KVM_EXIT_IO_IN</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit::IoIn</span>(<span class="ident">io</span>.<span class="ident">port</span>, <span class="ident">data</span>)), + <span class="ident">kvm_sys::KVM_EXIT_IO_OUT</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit::IoOut</span>(<span class="ident">io</span>.<span class="ident">port</span>, <span class="ident">data</span>)), + <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable!</span>(), } } - <span class="ident">kvm_sys</span>::<span class="ident">KVM_EXIT_MMIO</span> <span class="op">=</span><span class="op">></span> { + <span class="ident">kvm_sys::KVM_EXIT_MMIO</span> <span class="op">=</span><span class="op">></span> { <span class="comment">// Safe to use union `mmio` filed, as Kernel instructed us to.</span> <span class="kw">let</span> <span class="ident">mmio</span> <span class="op">=</span> <span class="kw">unsafe</span> { <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">kvm_run</span>.<span class="ident">inner</span>.<span class="ident">mmio</span> }; <span class="kw">let</span> <span class="ident">len</span> <span class="op">=</span> <span class="ident">mmio</span>.<span class="ident">len</span> <span class="kw">as</span> <span class="ident">usize</span>; <span class="kw">match</span> <span class="ident">mmio</span>.<span class="ident">is_write</span> { - <span class="number">0</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit</span>::<span class="ident">MmioRead</span>(<span class="ident">mmio</span>.<span class="ident">phys_addr</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">mmio</span>.<span class="ident">data</span>[..<span class="ident">len</span>])), - <span class="number">1</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit</span>::<span class="ident">MmioWrite</span>(<span class="ident">mmio</span>.<span class="ident">phys_addr</span>, <span class="kw-2">&</span><span class="ident">mmio</span>.<span class="ident">data</span>[..<span class="ident">len</span>])), - <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable</span><span class="macro">!</span>(), + <span class="number">0</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit::MmioRead</span>(<span class="ident">mmio</span>.<span class="ident">phys_addr</span>, <span class="kw-2">&</span><span class="kw-2">mut</span> <span class="ident">mmio</span>.<span class="ident">data</span>[..<span class="ident">len</span>])), + <span class="number">1</span> <span class="op">=</span><span class="op">></span> <span class="prelude-val">Ok</span>(<span class="ident">KvmExit::MmioWrite</span>(<span class="ident">mmio</span>.<span class="ident">phys_addr</span>, <span class="kw-2">&</span><span class="ident">mmio</span>.<span class="ident">data</span>[..<span class="ident">len</span>])), + <span class="kw">_</span> <span class="op">=</span><span class="op">></span> <span class="macro">unreachable!</span>(), } } <span class="ident">r</span> @ <span class="kw">_</span> <span class="op">=</span><span class="op">></span> { - <span class="macro">todo</span><span class="macro">!</span>(<span class="string">"KVM_EXIT_... (exit_reason={}) not implemented!"</span>, <span class="ident">r</span>) + <span class="macro">todo!</span>(<span class="string">"KVM_EXIT_... (exit_reason={}) not implemented!"</span>, <span class="ident">r</span>) } } } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/vm.rs.html b/src/kvm_rs/vm.rs.html index 94f2c10..f8f072f 100644 --- a/src/kvm_rs/vm.rs.html +++ b/src/kvm_rs/vm.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/vm.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>vm.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -73,11 +73,11 @@ </pre><div class="example-wrap"><pre class="rust "> <span class="doccomment">//! VM system ioctls.</span> -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">fs</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">io</span>; -<span class="kw">use</span> <span class="ident">std</span>::<span class="ident">os</span>::<span class="ident">unix</span>::<span class="ident">io</span>::<span class="ident">FromRawFd</span>; +<span class="kw">use</span> <span class="ident">std::fs</span>; +<span class="kw">use</span> <span class="ident">std::io</span>; +<span class="kw">use</span> <span class="ident">std::os::unix::io::FromRawFd</span>; -<span class="kw">use</span> <span class="kw">crate</span>::<span class="ident">vcpu</span>::<span class="ident">Vcpu</span>; +<span class="kw">use</span> <span class="kw">crate</span><span class="ident">::vcpu::Vcpu</span>; <span class="kw">use</span> <span class="kw">crate</span>::{<span class="ident">ioctl</span>, <span class="ident">kvm_sys</span>, <span class="ident">KvmRun</span>, <span class="ident">PhysAddr</span>, <span class="ident">UserMem</span>}; <span class="doccomment">/// Wrapper for VM ioctls.</span> @@ -88,12 +88,12 @@ <span class="doccomment">/// [kvm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#general-description</span> <span class="doccomment">/// [kvm-create-vm]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-create-vm</span> <span class="kw">pub</span> <span class="kw">struct</span> <span class="ident">Vm</span> { - <span class="ident">vm</span>: <span class="ident">fs</span>::<span class="ident">File</span>, + <span class="ident">vm</span>: <span class="ident">fs::File</span>, <span class="ident">vcpu_mmap_size</span>: <span class="ident">usize</span>, } <span class="kw">impl</span> <span class="ident">Vm</span> { - <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">vm</span>: <span class="ident">fs</span>::<span class="ident">File</span>, <span class="ident">vcpu_mmap_size</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Vm</span> { + <span class="kw">pub</span>(<span class="kw">crate</span>) <span class="kw">fn</span> <span class="ident">new</span>(<span class="ident">vm</span>: <span class="ident">fs::File</span>, <span class="ident">vcpu_mmap_size</span>: <span class="ident">usize</span>) <span class="op">-</span><span class="op">></span> <span class="ident">Vm</span> { <span class="ident">Vm</span> { <span class="ident">vm</span>, <span class="ident">vcpu_mmap_size</span> } } @@ -112,16 +112,16 @@ <span class="kw-2">&</span><span class="self">self</span>, <span class="ident">phys_addr</span>: <span class="ident">PhysAddr</span>, <span class="ident">mem</span>: <span class="kw-2">&</span><span class="ident">UserMem</span>, - ) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span>()<span class="op">></span> { + ) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span>()<span class="op">></span> { <span class="comment">// Create guest physical memory mapping for `slot : 0` at guest `phys_addr`.</span> - <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">kvm_mem</span> <span class="op">=</span> <span class="ident">kvm_sys</span>::<span class="ident">kvm_userspace_memory_region</span>::<span class="ident">default</span>(); + <span class="kw">let</span> <span class="kw-2">mut</span> <span class="ident">kvm_mem</span> <span class="op">=</span> <span class="ident">kvm_sys::kvm_userspace_memory_region::default</span>(); <span class="ident">kvm_mem</span>.<span class="ident">userspace_addr</span> <span class="op">=</span> <span class="ident">mem</span>.<span class="ident">ptr</span> <span class="kw">as</span> <span class="ident">u64</span>; <span class="ident">kvm_mem</span>.<span class="ident">memory_size</span> <span class="op">=</span> <span class="ident">mem</span>.<span class="ident">len</span> <span class="kw">as</span> <span class="ident">u64</span>; <span class="ident">kvm_mem</span>.<span class="ident">guest_phys_addr</span> <span class="op">=</span> <span class="ident">phys_addr</span>.<span class="number">0</span>; <span class="ident">ioctl</span>( <span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vm</span>, - <span class="ident">kvm_sys</span>::<span class="ident">KVM_SET_USER_MEMORY_REGION</span>, + <span class="ident">kvm_sys::KVM_SET_USER_MEMORY_REGION</span>, <span class="kw-2">&</span><span class="ident">kvm_mem</span> <span class="kw">as</span> <span class="kw-2">*</span><span class="kw">const</span> <span class="kw">_</span> <span class="kw">as</span> <span class="ident">u64</span>, ) .<span class="ident">map</span>(<span class="op">|</span><span class="kw">_</span><span class="op">|</span> ()) @@ -131,15 +131,15 @@ <span class="doccomment">/// Returns a wrapper [`vcpu::Vcpu`][crate::vcpu::Vcpu] representing the VCPU.</span> <span class="doccomment">///</span> <span class="doccomment">/// [kvm-create-vcpu]: https://www.kernel.org/doc/html/latest/virt/kvm/api.html#kvm-create-vcpu</span> - <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">create_vpcu</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">id</span>: <span class="ident">u64</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io</span>::<span class="prelude-ty">Result</span><span class="op"><</span><span class="ident">Vcpu</span><span class="op">></span> { - <span class="kw">let</span> <span class="ident">vcpu</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vm</span>, <span class="ident">kvm_sys</span>::<span class="ident">KVM_CREATE_VCPU</span>, <span class="ident">id</span>) - .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs</span>::<span class="ident">File</span>::<span class="ident">from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; + <span class="kw">pub</span> <span class="kw">fn</span> <span class="ident">create_vpcu</span>(<span class="kw-2">&</span><span class="self">self</span>, <span class="ident">id</span>: <span class="ident">u64</span>) <span class="op">-</span><span class="op">></span> <span class="ident">io::Result</span><span class="op"><</span><span class="ident">Vcpu</span><span class="op">></span> { + <span class="kw">let</span> <span class="ident">vcpu</span> <span class="op">=</span> <span class="ident">ioctl</span>(<span class="kw-2">&</span><span class="self">self</span>.<span class="ident">vm</span>, <span class="ident">kvm_sys::KVM_CREATE_VCPU</span>, <span class="ident">id</span>) + .<span class="ident">map</span>(<span class="op">|</span><span class="ident">fd</span><span class="op">|</span> <span class="kw">unsafe</span> { <span class="ident">fs::File::from_raw_fd</span>(<span class="ident">fd</span>) })<span class="question-mark">?</span>; - <span class="kw">let</span> <span class="ident">kvm_run</span> <span class="op">=</span> <span class="ident">KvmRun</span>::<span class="ident">new</span>(<span class="kw-2">&</span><span class="ident">vcpu</span>, <span class="self">self</span>.<span class="ident">vcpu_mmap_size</span>)<span class="question-mark">?</span>; + <span class="kw">let</span> <span class="ident">kvm_run</span> <span class="op">=</span> <span class="ident">KvmRun::new</span>(<span class="kw-2">&</span><span class="ident">vcpu</span>, <span class="self">self</span>.<span class="ident">vcpu_mmap_size</span>)<span class="question-mark">?</span>; - <span class="prelude-val">Ok</span>(<span class="ident">Vcpu</span>::<span class="ident">new</span>(<span class="ident">vcpu</span>, <span class="ident">kvm_run</span>)) + <span class="prelude-val">Ok</span>(<span class="ident">Vcpu::new</span>(<span class="ident">vcpu</span>, <span class="ident">kvm_run</span>)) } } </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file diff --git a/src/kvm_rs/x86_64.rs.html b/src/kvm_rs/x86_64.rs.html index 5671eba..6204e87 100644 --- a/src/kvm_rs/x86_64.rs.html +++ b/src/kvm_rs/x86_64.rs.html @@ -1,6 +1,6 @@ <!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="rustdoc"><meta name="description" content="Source of the Rust file `src/x86_64.rs`."><meta name="keywords" content="rust, rustlang, rust-lang"><title>x86_64.rs - source</title><link rel="stylesheet" type="text/css" href="../../normalize.css"><link rel="stylesheet" type="text/css" href="../../rustdoc.css" id="mainThemeStyle"><link rel="stylesheet" type="text/css" href="../../light.css" id="themeStyle"><link rel="stylesheet" type="text/css" href="../../dark.css" disabled ><link rel="stylesheet" type="text/css" href="../../ayu.css" disabled ><script id="default-settings"></script><script src="../../storage.js"></script><script src="../../crates.js"></script><noscript><link rel="stylesheet" href="../../noscript.css"></noscript><link rel="icon" type="image/svg+xml" href="../../favicon.svg"> <link rel="alternate icon" type="image/png" href="../../favicon-16x16.png"> -<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 8]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><script src="../../theme.js"></script><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> +<link rel="alternate icon" type="image/png" href="../../favicon-32x32.png"><style type="text/css">#crate-search{background-image:url("../../down-arrow.svg");}</style></head><body class="rustdoc source"><!--[if lte IE 11]><div class="warning">This old browser is unsupported and will most likely display funky things.</div><![endif]--><nav class="sidebar"><div class="sidebar-menu" role="button">☰</div><a href='../../kvm_rs/index.html'><div class='logo-container rust-logo'><img src='../../rust-logo.png' alt='logo'></div></a></nav><div class="theme-picker"><button id="theme-picker" aria-label="Pick another theme!" aria-haspopup="menu"><img src="../../brush.svg" width="18" height="18" alt="Pick another theme!"></button><div id="theme-choices" role="menu"></div></div><nav class="sub"><form class="search-form"><div class="search-container"><div><select id="crate-search"><option value="All crates">All crates</option></select><input class="search-input" name="search" disabled autocomplete="off" spellcheck="false" placeholder="Click or press ‘S’ to search, ‘?’ for more options…" type="search"></div><button type="button" class="help-button">?</button> <a id="settings-menu" href="../../settings.html"><img src="../../wheel.svg" width="18" height="18" alt="Change settings"></a></div></form></nav><section id="main" class="content"><pre class="line-numbers"><span id="1"> 1</span> <span id="2"> 2</span> <span id="3"> 3</span> @@ -311,5 +311,5 @@ <span class="doccomment">/// If set, region reference by paging entry is writeable.</span> <span class="kw">pub</span> <span class="kw">const</span> <span class="ident">PAGE_RENTRY_RW</span> : <span class="ident">u64</span> <span class="op">=</span> <span class="number">1</span> <span class="op"><</span><span class="op"><</span> <span class="number">1</span>; </pre></div> -</section><section id="search" class="content hidden"></section><section class="footer"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-js="../../search-index.js"></div> +</section><section id="search" class="content hidden"></section><div id="rustdoc-vars" data-root-path="../../" data-current-crate="kvm_rs" data-search-index-js="../../search-index.js" data-search-js="../../search.js"></div> <script src="../../main.js"></script><script src="../../source-script.js"></script><script src="../../source-files.js"></script></body></html>
\ No newline at end of file |