From bb769afe6b8fdc4a4c07770dde30d129194e8f13 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Tue, 11 May 2021 12:55:10 +0200 Subject: [PATCH] Remove errno dependency from cranelift-jit --- Cargo.lock | 1 - cranelift/jit/Cargo.toml | 1 - cranelift/jit/src/memory.rs | 19 ++++++++----------- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 2551a2e8ee..f8acaf0921 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -633,7 +633,6 @@ dependencies = [ "cranelift-frontend", "cranelift-module", "cranelift-native", - "errno", "libc", "log", "memmap2", diff --git a/cranelift/jit/Cargo.toml b/cranelift/jit/Cargo.toml index 98c8f8e524..5917edbc9d 100644 --- a/cranelift/jit/Cargo.toml +++ b/cranelift/jit/Cargo.toml @@ -17,7 +17,6 @@ cranelift-entity = { path = "../entity", version = "0.73.0" } anyhow = "1.0" region = "2.2.0" libc = { version = "0.2.42" } -errno = "0.2.4" target-lexicon = "0.12" memmap2 = { version = "0.2.1", optional = true } log = { version = "0.4.6", default-features = false } diff --git a/cranelift/jit/src/memory.rs b/cranelift/jit/src/memory.rs index b85d231185..20f6754eb1 100644 --- a/cranelift/jit/src/memory.rs +++ b/cranelift/jit/src/memory.rs @@ -1,6 +1,3 @@ -#[cfg(not(feature = "selinux-fix"))] -use errno; - #[cfg(not(any(feature = "selinux-fix", windows)))] use libc; @@ -9,6 +6,7 @@ use memmap2::MmapMut; use region; use std::convert::TryFrom; +use std::io; use std::mem; use std::ptr; @@ -41,7 +39,7 @@ impl PtrLen { /// Create a new `PtrLen` pointing to at least `size` bytes of memory, /// suitably sized and aligned for memory protection. #[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))] - fn with_size(size: usize) -> Result { + fn with_size(size: usize) -> io::Result { let page_size = region::page::size(); let alloc_size = round_up_to_page_size(size, page_size); let map = MmapMut::map_anon(alloc_size); @@ -56,12 +54,12 @@ impl PtrLen { len: alloc_size, }) } - Err(e) => Err(e.to_string()), + Err(e) => Err(e), } } #[cfg(all(not(target_os = "windows"), not(feature = "selinux-fix")))] - fn with_size(size: usize) -> Result { + fn with_size(size: usize) -> io::Result { let mut ptr = ptr::null_mut(); let page_size = region::page::size(); let alloc_size = round_up_to_page_size(size, page_size); @@ -74,13 +72,13 @@ impl PtrLen { len: alloc_size, }) } else { - Err(errno::Errno(err).to_string()) + Err(io::Error::from_raw_os_error(err)) } } } #[cfg(target_os = "windows")] - fn with_size(size: usize) -> Result { + fn with_size(size: usize) -> io::Result { use winapi::um::memoryapi::VirtualAlloc; use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE}; @@ -101,7 +99,7 @@ impl PtrLen { len: round_up_to_page_size(size, page_size), }) } else { - Err(errno::errno().to_string()) + Err(io::Error::last_os_error()) } } } @@ -149,8 +147,7 @@ impl Memory { self.position = 0; } - /// TODO: Use a proper error type. - pub(crate) fn allocate(&mut self, size: usize, align: u64) -> Result<*mut u8, String> { + pub(crate) fn allocate(&mut self, size: usize, align: u64) -> io::Result<*mut u8> { let align = usize::try_from(align).expect("alignment too big"); if self.position % align != 0 { self.position += align - self.position % align;