Remove errno dependency from cranelift-jit
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -633,7 +633,6 @@ dependencies = [
|
|||||||
"cranelift-frontend",
|
"cranelift-frontend",
|
||||||
"cranelift-module",
|
"cranelift-module",
|
||||||
"cranelift-native",
|
"cranelift-native",
|
||||||
"errno",
|
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
"memmap2",
|
"memmap2",
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ cranelift-entity = { path = "../entity", version = "0.73.0" }
|
|||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
region = "2.2.0"
|
region = "2.2.0"
|
||||||
libc = { version = "0.2.42" }
|
libc = { version = "0.2.42" }
|
||||||
errno = "0.2.4"
|
|
||||||
target-lexicon = "0.12"
|
target-lexicon = "0.12"
|
||||||
memmap2 = { version = "0.2.1", optional = true }
|
memmap2 = { version = "0.2.1", optional = true }
|
||||||
log = { version = "0.4.6", default-features = false }
|
log = { version = "0.4.6", default-features = false }
|
||||||
|
|||||||
@@ -1,6 +1,3 @@
|
|||||||
#[cfg(not(feature = "selinux-fix"))]
|
|
||||||
use errno;
|
|
||||||
|
|
||||||
#[cfg(not(any(feature = "selinux-fix", windows)))]
|
#[cfg(not(any(feature = "selinux-fix", windows)))]
|
||||||
use libc;
|
use libc;
|
||||||
|
|
||||||
@@ -9,6 +6,7 @@ use memmap2::MmapMut;
|
|||||||
|
|
||||||
use region;
|
use region;
|
||||||
use std::convert::TryFrom;
|
use std::convert::TryFrom;
|
||||||
|
use std::io;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
|
|
||||||
@@ -41,7 +39,7 @@ impl PtrLen {
|
|||||||
/// Create a new `PtrLen` pointing to at least `size` bytes of memory,
|
/// Create a new `PtrLen` pointing to at least `size` bytes of memory,
|
||||||
/// suitably sized and aligned for memory protection.
|
/// suitably sized and aligned for memory protection.
|
||||||
#[cfg(all(not(target_os = "windows"), feature = "selinux-fix"))]
|
#[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 page_size = region::page::size();
|
||||||
let alloc_size = round_up_to_page_size(size, page_size);
|
let alloc_size = round_up_to_page_size(size, page_size);
|
||||||
let map = MmapMut::map_anon(alloc_size);
|
let map = MmapMut::map_anon(alloc_size);
|
||||||
@@ -56,12 +54,12 @@ impl PtrLen {
|
|||||||
len: alloc_size,
|
len: alloc_size,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => Err(e.to_string()),
|
Err(e) => Err(e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(all(not(target_os = "windows"), not(feature = "selinux-fix")))]
|
#[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 mut ptr = ptr::null_mut();
|
||||||
let page_size = region::page::size();
|
let page_size = region::page::size();
|
||||||
let alloc_size = round_up_to_page_size(size, page_size);
|
let alloc_size = round_up_to_page_size(size, page_size);
|
||||||
@@ -74,13 +72,13 @@ impl PtrLen {
|
|||||||
len: alloc_size,
|
len: alloc_size,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(errno::Errno(err).to_string())
|
Err(io::Error::from_raw_os_error(err))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[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::memoryapi::VirtualAlloc;
|
||||||
use winapi::um::winnt::{MEM_COMMIT, MEM_RESERVE, PAGE_READWRITE};
|
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),
|
len: round_up_to_page_size(size, page_size),
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
Err(errno::errno().to_string())
|
Err(io::Error::last_os_error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,8 +147,7 @@ impl Memory {
|
|||||||
self.position = 0;
|
self.position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// TODO: Use a proper error type.
|
pub(crate) fn allocate(&mut self, size: usize, align: u64) -> io::Result<*mut u8> {
|
||||||
pub(crate) fn allocate(&mut self, size: usize, align: u64) -> Result<*mut u8, String> {
|
|
||||||
let align = usize::try_from(align).expect("alignment too big");
|
let align = usize::try_from(align).expect("alignment too big");
|
||||||
if self.position % align != 0 {
|
if self.position % align != 0 {
|
||||||
self.position += align - self.position % align;
|
self.position += align - self.position % align;
|
||||||
|
|||||||
Reference in New Issue
Block a user