From 550a1794e9460467c474d56554b62942bf911a9c Mon Sep 17 00:00:00 2001 From: johannst Date: Fri, 13 Dec 2024 22:47:47 +0000 Subject: deploy: 869761849ff64669244b6cbb79cac41f66654041 --- src/juicebox_asm/rt.rs.html | 42 ++++++++++++++++++++---------------------- 1 file changed, 20 insertions(+), 22 deletions(-) (limited to 'src/juicebox_asm/rt.rs.html') 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 @@ 265 266 267 -268 -269
//! Simple `mmap`ed runtime.
+268
//! 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 @@
 #[cfg(not(target_os = "linux"))]
 compile_error!("This runtime is only supported on linux");
 
-use nix::sys::mman::{mmap, mprotect, munmap, MapFlags, ProtFlags};
-
 mod perf {
     use std::fs;
     use std::io::Write;
@@ -298,7 +295,7 @@
     impl PerfMap {
         /// Create an empty perf map file.
         pub(super) fn new() -> Self {
-            let name = format!("/tmp/perf-{}.map", nix::unistd::getpid());
+            let name = format!("/tmp/perf-{}.map", unsafe { libc::getpid() });
             let file = fs::OpenOptions::new()
                 .truncate(true)
                 .create(true)
@@ -338,22 +335,26 @@
     /// Panics if the `mmap` call fails.
     pub fn new() -> Runtime {
         // Allocate a single page.
-        let len = core::num::NonZeroUsize::new(4096).expect("Value is non zero");
+        let len = 4096;
         let buf = unsafe {
-            mmap(
-                None,
+            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,
                 0, /* fd */
                 0, /* off */
-            )
-            .expect("Failed to mmap runtime code page") as *mut u8
+            ) as *mut u8
         };
+        assert_ne!(
+            buf.cast(),
+            libc::MAP_FAILED,
+            "Failed to mmap runtime code page"
+        );
 
         Runtime {
             buf,
-            len: len.get(),
+            len,
             idx: 0,
             perf: None,
         }
@@ -455,12 +456,8 @@
     fn protect(&mut self) {
         unsafe {
             // Remove write permissions from code page and allow to read-execute from it.
-            mprotect(
-                self.buf.cast(),
-                self.len,
-                ProtFlags::PROT_READ | ProtFlags::PROT_EXEC,
-            )
-            .expect("Failed to RX mprotect runtime code page");
+            let ret = libc::mprotect(self.buf.cast(), self.len, libc::PROT_READ | libc::PROT_EXEC);
+            assert_eq!(ret, 0, "Failed to RX mprotect runtime code page");
         }
     }
 
@@ -472,8 +469,8 @@
     fn unprotect(&mut self) {
         unsafe {
             // Add write permissions to code page.
-            mprotect(self.buf.cast(), self.len, ProtFlags::PROT_WRITE)
-                .expect("Failed to W mprotect runtime code page");
+            let ret = libc::mprotect(self.buf.cast(), self.len, libc::PROT_WRITE);
+            assert_eq!(ret, 0, "Failed to W mprotect runtime code page");
         }
     }
 }
@@ -483,7 +480,8 @@
     /// [`Runtime::add_code`].
     fn drop(&mut self) {
         unsafe {
-            munmap(self.buf.cast(), self.len).expect("Failed to munmap runtime");
+            let ret = libc::munmap(self.buf.cast(), self.len);
+            assert_eq!(ret, 0, "Failed to munmap runtime");
         }
     }
 }
-- 
cgit v1.2.3