Move alignment config from declare_data to define_data
This commit is contained in:
@@ -25,9 +25,9 @@ use target_lexicon::PointerWidth;
|
||||
#[cfg(windows)]
|
||||
use winapi;
|
||||
|
||||
const EXECUTABLE_DATA_ALIGNMENT: u8 = 0x10;
|
||||
const WRITABLE_DATA_ALIGNMENT: u8 = 0x8;
|
||||
const READONLY_DATA_ALIGNMENT: u8 = 0x1;
|
||||
const EXECUTABLE_DATA_ALIGNMENT: u64 = 0x10;
|
||||
const WRITABLE_DATA_ALIGNMENT: u64 = 0x8;
|
||||
const READONLY_DATA_ALIGNMENT: u64 = 0x1;
|
||||
|
||||
/// A builder for `SimpleJITBackend`.
|
||||
pub struct SimpleJITBuilder {
|
||||
@@ -415,12 +415,11 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
linkage: Linkage,
|
||||
writable: bool,
|
||||
tls: bool,
|
||||
align: Option<u8>,
|
||||
) -> ModuleResult<DataId> {
|
||||
assert!(!tls, "SimpleJIT doesn't yet support TLS");
|
||||
let (id, _decl) = self
|
||||
.declarations
|
||||
.declare_data(name, linkage, writable, tls, align)?;
|
||||
.declare_data(name, linkage, writable, tls)?;
|
||||
Ok(id)
|
||||
}
|
||||
|
||||
@@ -542,18 +541,19 @@ impl<'simple_jit_backend> Backend for SimpleJITBackend {
|
||||
ref function_relocs,
|
||||
ref data_relocs,
|
||||
custom_segment_section: _,
|
||||
align,
|
||||
} = data.description();
|
||||
|
||||
let size = init.size();
|
||||
let storage = if decl.writable {
|
||||
self.memory
|
||||
.writable
|
||||
.allocate(size, decl.align.unwrap_or(WRITABLE_DATA_ALIGNMENT))
|
||||
.allocate(size, align.unwrap_or(WRITABLE_DATA_ALIGNMENT))
|
||||
.expect("TODO: handle OOM etc.")
|
||||
} else {
|
||||
self.memory
|
||||
.readonly
|
||||
.allocate(size, decl.align.unwrap_or(READONLY_DATA_ALIGNMENT))
|
||||
.allocate(size, align.unwrap_or(READONLY_DATA_ALIGNMENT))
|
||||
.expect("TODO: handle OOM etc.")
|
||||
};
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use libc;
|
||||
use memmap::MmapMut;
|
||||
|
||||
use region;
|
||||
use std::convert::TryFrom;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
@@ -149,10 +150,11 @@ impl Memory {
|
||||
}
|
||||
|
||||
/// TODO: Use a proper error type.
|
||||
pub fn allocate(&mut self, size: usize, align: u8) -> Result<*mut u8, String> {
|
||||
if self.position % align as usize != 0 {
|
||||
self.position += align as usize - self.position % align as usize;
|
||||
debug_assert!(self.position % align as usize == 0);
|
||||
pub fn allocate(&mut self, size: usize, align: u64) -> Result<*mut u8, String> {
|
||||
let align = usize::try_from(align).expect("alignment too big");
|
||||
if self.position % align != 0 {
|
||||
self.position += align - self.position % align;
|
||||
debug_assert!(self.position % align == 0);
|
||||
}
|
||||
|
||||
if size <= self.current.len - self.position {
|
||||
|
||||
Reference in New Issue
Block a user