diff --git a/Cargo.lock b/Cargo.lock index 6a387d00a07..2c279baf5e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -5475,6 +5475,7 @@ dependencies = [ "log", "raw-window-handle", "servo-media", + "servo_allocator", "shellwords", "sig", "surfman", diff --git a/components/allocator/Cargo.toml b/components/allocator/Cargo.toml index 7a017e4cf92..e6467da3737 100644 --- a/components/allocator/Cargo.toml +++ b/components/allocator/Cargo.toml @@ -9,9 +9,13 @@ publish = false [lib] path = "lib.rs" +[features] +use-system-allocator = ["libc"] + [target.'cfg(not(any(windows, target_os = "android")))'.dependencies] jemallocator = { workspace = true } jemalloc-sys = { workspace = true } +libc = { workspace = true, optional = true } [target.'cfg(windows)'.dependencies] winapi = { workspace = true, features = ["heapapi"] } diff --git a/components/allocator/lib.rs b/components/allocator/lib.rs index 9d7c0b466f0..f6cf47eada5 100644 --- a/components/allocator/lib.rs +++ b/components/allocator/lib.rs @@ -9,7 +9,7 @@ static ALLOC: Allocator = Allocator; pub use crate::platform::*; -#[cfg(not(any(windows, target_os = "android")))] +#[cfg(not(any(windows, target_os = "android", feature = "use-system-allocator")))] mod platform { use std::os::raw::c_void; @@ -28,14 +28,21 @@ mod platform { } } -#[cfg(target_os = "android")] +#[cfg(all( + not(windows), + any(target_os = "android", feature = "use-system-allocator") +))] mod platform { pub use std::alloc::System as Allocator; use std::os::raw::c_void; /// Get the size of a heap block. pub unsafe extern "C" fn usable_size(ptr: *const c_void) -> usize { - libc::malloc_usable_size(ptr) + #[cfg(target_os = "linux")] + return libc::malloc_usable_size(ptr as *mut _); + + #[cfg(not(target_os = "linux"))] + return libc::malloc_usable_size(ptr); } pub mod libc_compat { diff --git a/ports/servoshell/Cargo.toml b/ports/servoshell/Cargo.toml index 1ec6d3c3ec9..432712ca626 100644 --- a/ports/servoshell/Cargo.toml +++ b/ports/servoshell/Cargo.toml @@ -48,6 +48,10 @@ webdriver = ["libservo/webdriver"] webgl_backtrace = ["libservo/webgl_backtrace"] xr-profile = ["libservo/xr-profile"] +[dependencies] +# For optional feature servo_allocator/use-system-allocator +servo_allocator = { path = "../../components/allocator" } + [target.'cfg(not(target_os = "android"))'.dependencies] arboard = "3" backtrace = { workspace = true }