mirror of
https://github.com/fluencelabs/wasmer
synced 2025-06-24 22:21:32 +00:00
Share some more code in runtime-core::sys
This commit is contained in:
@ -80,3 +80,15 @@ impl<'de> Deserialize<'de> for Memory {
|
|||||||
deserializer.deserialize_struct("Memory", &["protection", "data"], MemoryVisitor)
|
deserializer.deserialize_struct("Memory", &["protection", "data"], MemoryVisitor)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Round `size` up to the nearest multiple of `page_size`.
|
||||||
|
fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
|
||||||
|
assert!(page_size.is_power_of_two());
|
||||||
|
(size + (page_size - 1)) & !(page_size - 1)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Round `size` down to the nearest multiple of `page_size`.
|
||||||
|
fn round_down_to_page_size(size: usize, page_size: usize) -> usize {
|
||||||
|
assert!(page_size.is_power_of_two());
|
||||||
|
size & !(page_size - 1)
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::error::MemoryCreationError;
|
use crate::error::MemoryCreationError;
|
||||||
use crate::error::MemoryProtectionError;
|
use crate::error::MemoryProtectionError;
|
||||||
|
use crate::sys::{round_down_to_page_size, round_up_to_page_size};
|
||||||
use errno;
|
use errno;
|
||||||
use nix::libc;
|
use nix::libc;
|
||||||
use page_size;
|
use page_size;
|
||||||
@ -313,15 +314,3 @@ impl Drop for RawFd {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Round `size` up to the nearest multiple of `page_size`.
|
|
||||||
fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
|
|
||||||
assert!(page_size.is_power_of_two());
|
|
||||||
(size + (page_size - 1)) & !(page_size - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Round `size` down to the nearest multiple of `page_size`.
|
|
||||||
fn round_down_to_page_size(size: usize, page_size: usize) -> usize {
|
|
||||||
assert!(page_size.is_power_of_two());
|
|
||||||
size & !(page_size - 1)
|
|
||||||
}
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
use crate::error::MemoryCreationError;
|
use crate::error::MemoryCreationError;
|
||||||
use crate::error::MemoryProtectionError;
|
use crate::error::MemoryProtectionError;
|
||||||
|
use crate::sys::{round_down_to_page_size, round_up_to_page_size};
|
||||||
use page_size;
|
use page_size;
|
||||||
use std::ops::{Bound, RangeBounds};
|
use std::ops::{Bound, RangeBounds};
|
||||||
use std::{ptr, slice};
|
use std::{ptr, slice};
|
||||||
@ -243,16 +244,6 @@ impl Protect {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Round `size` up to the nearest multiple of `page_size`.
|
|
||||||
fn round_up_to_page_size(size: usize, page_size: usize) -> usize {
|
|
||||||
(size + (page_size - 1)) & !(page_size - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Round `size` down to the nearest multiple of `page_size`.
|
|
||||||
fn round_down_to_page_size(size: usize, page_size: usize) -> usize {
|
|
||||||
size & !(page_size - 1)
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
Reference in New Issue
Block a user