Remove errno dependency from cranelift-jit

This commit is contained in:
bjorn3
2021-05-11 12:55:10 +02:00
parent 5fb2c8c235
commit bb769afe6b
3 changed files with 8 additions and 13 deletions

1
Cargo.lock generated
View File

@@ -633,7 +633,6 @@ dependencies = [
"cranelift-frontend",
"cranelift-module",
"cranelift-native",
"errno",
"libc",
"log",
"memmap2",

View File

@@ -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 }

View File

@@ -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<Self, String> {
fn with_size(size: usize) -> io::Result<Self> {
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<Self, String> {
fn with_size(size: usize) -> io::Result<Self> {
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<Self, String> {
fn with_size(size: usize) -> io::Result<Self> {
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;