mirror of
https://github.com/fluencelabs/wasmer
synced 2025-03-16 16:20:49 +00:00
Share some more code in runtime-core::sys
This commit is contained in:
parent
5dfa61e30a
commit
2c45106ae0
@ -80,3 +80,15 @@ impl<'de> Deserialize<'de> for Memory {
|
||||
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::MemoryProtectionError;
|
||||
use crate::sys::{round_down_to_page_size, round_up_to_page_size};
|
||||
use errno;
|
||||
use nix::libc;
|
||||
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::MemoryProtectionError;
|
||||
use crate::sys::{round_down_to_page_size, round_up_to_page_size};
|
||||
use page_size;
|
||||
use std::ops::{Bound, RangeBounds};
|
||||
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)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
Loading…
x
Reference in New Issue
Block a user