mirror of
https://github.com/servo/servo.git
synced 2025-07-01 12:33:40 +01:00
Round hashglobe allocations up to the nearest page size.
MozReview-Commit-ID: 34KFtcwCkBB
This commit is contained in:
parent
98f370130d
commit
ef042899d2
8 changed files with 29 additions and 1 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -3231,6 +3231,7 @@ dependencies = [
|
|||
"env_logger 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"euclid 0.15.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"geckoservo 0.0.1",
|
||||
"hashglobe 0.1.0",
|
||||
"libc 0.2.23 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"malloc_size_of 0.0.1",
|
||||
|
|
|
@ -52,3 +52,6 @@ impl fmt::Display for FailedAllocationError {
|
|||
self.reason.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
// The size of memory pages on this system. Set when initializing geckolib.
|
||||
pub static SYSTEM_PAGE_SIZE: ::std::sync::atomic::AtomicUsize = ::std::sync::atomic::ATOMIC_USIZE_INIT;
|
||||
|
|
|
@ -777,7 +777,7 @@ impl<K, V> RawTable<K, V> {
|
|||
|
||||
|
||||
// FORK NOTE: Uses alloc shim instead of Heap.alloc
|
||||
let buffer = alloc(size, alignment);
|
||||
let buffer = alloc(round_up_to_page_size(size), alignment);
|
||||
|
||||
if buffer.is_null() {
|
||||
|
||||
|
@ -1201,3 +1201,19 @@ impl<K, V> Drop for RawTable<K, V> {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Force all allocations to fill their pages for the duration of the mprotect
|
||||
// experiment.
|
||||
#[inline]
|
||||
fn round_up_to_page_size(size: usize) -> usize {
|
||||
let page_size = ::SYSTEM_PAGE_SIZE.load(::std::sync::atomic::Ordering::Relaxed);
|
||||
debug_assert!(page_size != 0);
|
||||
let mut result = size;
|
||||
let remainder = size % page_size;
|
||||
if remainder != 0 {
|
||||
result += page_size - remainder;
|
||||
}
|
||||
debug_assert!(result % page_size == 0);
|
||||
debug_assert!(result - size < page_size);
|
||||
result
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ gecko_debug = ["style/gecko_debug"]
|
|||
atomic_refcell = "0.1"
|
||||
cssparser = "0.21.1"
|
||||
env_logger = {version = "0.4", default-features = false} # disable `regex` to reduce code size
|
||||
hashglobe = {path = "../../components/hashglobe"}
|
||||
libc = "0.2"
|
||||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||
malloc_size_of = {path = "../../components/malloc_size_of"}
|
||||
|
|
|
@ -181,6 +181,10 @@ pub extern "C" fn Servo_Initialize(dummy_url_data: *mut URLExtraData) {
|
|||
|
||||
// Initialize the dummy url data
|
||||
unsafe { DUMMY_URL_DATA = dummy_url_data; }
|
||||
|
||||
// Set the system page size.
|
||||
let page_size = unsafe { bindings::Gecko_GetSystemPageSize() };
|
||||
::hashglobe::SYSTEM_PAGE_SIZE.store(page_size, ::std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
extern crate cssparser;
|
||||
extern crate env_logger;
|
||||
extern crate hashglobe;
|
||||
extern crate libc;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate malloc_size_of;
|
||||
|
|
|
@ -17,6 +17,7 @@ cssparser = "0.21.1"
|
|||
env_logger = "0.4"
|
||||
euclid = "0.15"
|
||||
geckoservo = {path = "../../../ports/geckolib"}
|
||||
hashglobe = {path = "../../../components/hashglobe"}
|
||||
libc = "0.2"
|
||||
log = {version = "0.3.5", features = ["release_max_level_info"]}
|
||||
malloc_size_of = {path = "../../../components/malloc_size_of"}
|
||||
|
|
|
@ -6,6 +6,7 @@ extern crate atomic_refcell;
|
|||
extern crate cssparser;
|
||||
extern crate env_logger;
|
||||
extern crate geckoservo;
|
||||
extern crate hashglobe;
|
||||
#[macro_use] extern crate log;
|
||||
extern crate malloc_size_of;
|
||||
extern crate selectors;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue