aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/juicebox_asm/rt.rs.html
diff options
context:
space:
mode:
authorjohannst <johannst@users.noreply.github.com>2024-12-13 22:47:47 +0000
committerjohannst <johannst@users.noreply.github.com>2024-12-13 22:47:47 +0000
commit550a1794e9460467c474d56554b62942bf911a9c (patch)
tree58215b8e6267b7d4b9b690d031bdad07ab34f6c4 /src/juicebox_asm/rt.rs.html
parentdd973aa72be71aac88e5449df3c82d5eeededbb5 (diff)
downloadjuicebox-asm-550a1794e9460467c474d56554b62942bf911a9c.tar.gz
juicebox-asm-550a1794e9460467c474d56554b62942bf911a9c.zip
deploy: 869761849ff64669244b6cbb79cac41f66654041
Diffstat (limited to 'src/juicebox_asm/rt.rs.html')
-rw-r--r--src/juicebox_asm/rt.rs.html42
1 files changed, 20 insertions, 22 deletions
diff --git a/src/juicebox_asm/rt.rs.html b/src/juicebox_asm/rt.rs.html
index 039fa77..b0fad10 100644
--- a/src/juicebox_asm/rt.rs.html
+++ b/src/juicebox_asm/rt.rs.html
@@ -266,8 +266,7 @@
<a href="#265" id="265">265</a>
<a href="#266" id="266">266</a>
<a href="#267" id="267">267</a>
-<a href="#268" id="268">268</a>
-<a href="#269" id="269">269</a></pre></div><pre class="rust"><code><span class="doccomment">//! Simple `mmap`ed runtime.
+<a href="#268" id="268">268</a></pre></div><pre class="rust"><code><span class="doccomment">//! Simple `mmap`ed runtime.
//!
//! This runtime supports adding code to executable pages and turn the added code into user
//! specified function pointer.
@@ -275,8 +274,6 @@
</span><span class="attr">#[cfg(not(target_os = <span class="string">"linux"</span>))]
</span><span class="macro">compile_error!</span>(<span class="string">"This runtime is only supported on linux"</span>);
-<span class="kw">use </span>nix::sys::mman::{mmap, mprotect, munmap, MapFlags, ProtFlags};
-
<span class="kw">mod </span>perf {
<span class="kw">use </span>std::fs;
<span class="kw">use </span>std::io::Write;
@@ -298,7 +295,7 @@
<span class="kw">impl </span>PerfMap {
<span class="doccomment">/// Create an empty perf map file.
</span><span class="kw">pub</span>(<span class="kw">super</span>) <span class="kw">fn </span>new() -&gt; <span class="self">Self </span>{
- <span class="kw">let </span>name = <span class="macro">format!</span>(<span class="string">"/tmp/perf-{}.map"</span>, nix::unistd::getpid());
+ <span class="kw">let </span>name = <span class="macro">format!</span>(<span class="string">"/tmp/perf-{}.map"</span>, <span class="kw">unsafe </span>{ libc::getpid() });
<span class="kw">let </span>file = fs::OpenOptions::new()
.truncate(<span class="bool-val">true</span>)
.create(<span class="bool-val">true</span>)
@@ -338,22 +335,26 @@
/// Panics if the `mmap` call fails.
</span><span class="kw">pub fn </span>new() -&gt; Runtime {
<span class="comment">// Allocate a single page.
- </span><span class="kw">let </span>len = core::num::NonZeroUsize::new(<span class="number">4096</span>).expect(<span class="string">"Value is non zero"</span>);
+ </span><span class="kw">let </span>len = <span class="number">4096</span>;
<span class="kw">let </span>buf = <span class="kw">unsafe </span>{
- mmap(
- <span class="prelude-val">None</span>,
+ libc::mmap(
+ std::ptr::null_mut(),
len,
- ProtFlags::PROT_NONE,
- MapFlags::MAP_PRIVATE | MapFlags::MAP_ANONYMOUS,
+ libc::PROT_NONE,
+ libc::MAP_PRIVATE | libc::MAP_ANONYMOUS,
<span class="number">0</span>, <span class="comment">/* fd */
</span><span class="number">0</span>, <span class="comment">/* off */
- </span>)
- .expect(<span class="string">"Failed to mmap runtime code page"</span>) <span class="kw">as </span><span class="kw-2">*mut </span>u8
+ </span>) <span class="kw">as </span><span class="kw-2">*mut </span>u8
};
+ <span class="macro">assert_ne!</span>(
+ buf.cast(),
+ libc::MAP_FAILED,
+ <span class="string">"Failed to mmap runtime code page"
+ </span>);
Runtime {
buf,
- len: len.get(),
+ len,
idx: <span class="number">0</span>,
perf: <span class="prelude-val">None</span>,
}
@@ -455,12 +456,8 @@
</span><span class="kw">fn </span>protect(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
<span class="comment">// Remove write permissions from code page and allow to read-execute from it.
- </span>mprotect(
- <span class="self">self</span>.buf.cast(),
- <span class="self">self</span>.len,
- ProtFlags::PROT_READ | ProtFlags::PROT_EXEC,
- )
- .expect(<span class="string">"Failed to RX mprotect runtime code page"</span>);
+ </span><span class="kw">let </span>ret = libc::mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, libc::PROT_READ | libc::PROT_EXEC);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to RX mprotect runtime code page"</span>);
}
}
@@ -472,8 +469,8 @@
</span><span class="kw">fn </span>unprotect(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
<span class="comment">// Add write permissions to code page.
- </span>mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, ProtFlags::PROT_WRITE)
- .expect(<span class="string">"Failed to W mprotect runtime code page"</span>);
+ </span><span class="kw">let </span>ret = libc::mprotect(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len, libc::PROT_WRITE);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to W mprotect runtime code page"</span>);
}
}
}
@@ -483,7 +480,8 @@
/// [`Runtime::add_code`].
</span><span class="kw">fn </span>drop(<span class="kw-2">&amp;mut </span><span class="self">self</span>) {
<span class="kw">unsafe </span>{
- munmap(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len).expect(<span class="string">"Failed to munmap runtime"</span>);
+ <span class="kw">let </span>ret = libc::munmap(<span class="self">self</span>.buf.cast(), <span class="self">self</span>.len);
+ <span class="macro">assert_eq!</span>(ret, <span class="number">0</span>, <span class="string">"Failed to munmap runtime"</span>);
}
}
}