diff --git a/Cargo.lock b/Cargo.lock index 1c86abcb285..d98275a0d17 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -738,7 +738,7 @@ dependencies = [ "crossbeam-channel", "libc", "log", - "mach2", + "mach2 0.6.0", "nix", "rustc-demangle", "rustc-hash 2.1.1", @@ -776,7 +776,7 @@ dependencies = [ "ipc-channel", "libc", "log", - "mach2", + "mach2 0.6.0", "malloc_size_of_derive", "parking_lot", "rayon", @@ -4731,7 +4731,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "617ee6cf8e3f66f3b4ea67a4058564628cde41901316e19f559e14c7c72c5e7b" dependencies = [ "core-foundation-sys", - "mach2", + "mach2 0.4.3", ] [[package]] @@ -5283,6 +5283,12 @@ dependencies = [ "libc", ] +[[package]] +name = "mach2" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dae608c151f68243f2b000364e1f7b186d9c29845f7d2d85bd31b9ad77ad552b" + [[package]] name = "malloc_buf" version = "0.0.6" @@ -6915,13 +6921,13 @@ dependencies = [ "ipc-channel", "libc", "log", + "mach2 0.6.0", "profile_traits", "regex", "serde", "serde_json", "servo_allocator", "servo_config", - "task_info", "tikv-jemalloc-sys", "time", ] @@ -7471,7 +7477,7 @@ dependencies = [ "security-framework", "security-framework-sys", "webpki-root-certs", - "windows-sys 0.52.0", + "windows-sys 0.61.2", ] [[package]] @@ -8998,13 +9004,6 @@ version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e502f78cdbb8ba4718f566c418c52bc729126ffd16baee5baa718cf25dd5a69a" -[[package]] -name = "task_info" -version = "0.0.1" -dependencies = [ - "cc", -] - [[package]] name = "tempfile" version = "3.23.0" diff --git a/Cargo.toml b/Cargo.toml index 987e4358045..7fdf45527c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -104,7 +104,7 @@ kurbo = { version = "0.12", features = ["euclid"] } layout_api = { path = "components/shared/layout" } libc = "0.2" log = "0.4.29" -mach2 = "0.4" +mach2 = "0.6" malloc_size_of = { package = "servo_malloc_size_of", path = "components/malloc_size_of" } malloc_size_of_derive = "0.1" markup5ever = "0.36.1" diff --git a/components/profile/Cargo.toml b/components/profile/Cargo.toml index 381218c5e32..61dd10eaa9e 100644 --- a/components/profile/Cargo.toml +++ b/components/profile/Cargo.toml @@ -23,7 +23,7 @@ servo_config = { path = "../config" } time = { workspace = true } [target.'cfg(target_os = "macos")'.dependencies] -task_info = { path = "../../support/rust-task_info" } +mach2 = { workspace = true } [target.'cfg(target_os = "linux")'.dependencies] regex = { workspace = true } diff --git a/components/profile/system_reporter.rs b/components/profile/system_reporter.rs index 42ece16fa51..455868268ae 100644 --- a/components/profile/system_reporter.rs +++ b/components/profile/system_reporter.rs @@ -15,8 +15,6 @@ use libc::c_int; use libc::{c_void, size_t}; use profile_traits::mem::{ProcessReports, Report, ReportKind, ReporterRequest}; use profile_traits::path; -#[cfg(target_os = "macos")] -use task_info::task_basic_info::{resident_size, virtual_size}; const JEMALLOC_HEAP_ALLOCATED_STR: &str = "jemalloc-heap-allocated"; const SYSTEM_HEAP_ALLOCATED_STR: &str = "system-heap-allocated"; @@ -221,14 +219,37 @@ fn proportional_set_size() -> Option { None } +#[cfg(target_os = "macos")] +fn task_basic_info() -> Option { + use mach2::kern_return::KERN_SUCCESS; + use mach2::task::task_info; + use mach2::task_info::{TASK_BASIC_INFO, TASK_BASIC_INFO_COUNT, task_basic_info}; + use mach2::traps::mach_task_self; + + let mut info = task_basic_info::default(); + let mut count = TASK_BASIC_INFO_COUNT; + if unsafe { + task_info( + mach_task_self(), + TASK_BASIC_INFO, + std::ptr::from_mut(&mut info).cast(), + std::ptr::from_mut(&mut count), + ) + } != KERN_SUCCESS + { + return None; + } + Some(info) +} + #[cfg(target_os = "macos")] fn vsize() -> Option { - virtual_size() + task_basic_info().map(|task_basic_info| task_basic_info.virtual_size) } #[cfg(target_os = "macos")] fn resident() -> Option { - resident_size() + task_basic_info().map(|task_basic_info| task_basic_info.resident_size) } #[cfg(not(any(target_os = "linux", target_os = "macos")))] diff --git a/deny.toml b/deny.toml index b229cd19a31..9dbc3db53cf 100644 --- a/deny.toml +++ b/deny.toml @@ -122,8 +122,9 @@ skip = [ # rust-content-security-policy uses newest base64. "base64", - # gilrs is on 0.10.0, but Servo is still on 0.9.4 + # Duplicated by gilrs. "core-foundation", + "mach2", # wgpu crates still depend on 1.1.0 "rustc-hash", diff --git a/support/rust-task_info/Cargo.toml b/support/rust-task_info/Cargo.toml deleted file mode 100644 index aec91b1f966..00000000000 --- a/support/rust-task_info/Cargo.toml +++ /dev/null @@ -1,12 +0,0 @@ -[package] -name = "task_info" -version.workspace = true -authors.workspace = true -license.workspace = true -edition.workspace = true -publish.workspace = true -rust-version.workspace = true -build = "build.rs" - -[build-dependencies] -cc = "1.0" diff --git a/support/rust-task_info/build.rs b/support/rust-task_info/build.rs deleted file mode 100644 index 73d68fdd54b..00000000000 --- a/support/rust-task_info/build.rs +++ /dev/null @@ -1,13 +0,0 @@ -/* This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at https://mozilla.org/MPL/2.0/. */ - -fn main() { - let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); - - if target_os == "macos" { - cc::Build::new() - .file("src/task_info.c") - .compile("libtask_info.a"); - } -} diff --git a/support/rust-task_info/src/lib.rs b/support/rust-task_info/src/lib.rs deleted file mode 100644 index c2bef92feef..00000000000 --- a/support/rust-task_info/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. -//! A helper crate to get task information on macos. - -#[cfg(target_os = "macos")] -pub mod task_basic_info; diff --git a/support/rust-task_info/src/task_basic_info.rs b/support/rust-task_info/src/task_basic_info.rs deleted file mode 100644 index 2e6f657c515..00000000000 --- a/support/rust-task_info/src/task_basic_info.rs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright 2014 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Interface to the measurements in the task_basic_info struct, gathered by -//! invoking `task_info()` with the `TASK_BASIC_INFO` flavor. - -use std::os::raw::c_int; - -#[allow(non_camel_case_types)] -type size_t = usize; - -/// Obtains task_basic_info::virtual_size. -pub fn virtual_size() -> Option { - let mut virtual_size: size_t = 0; - let rv = unsafe { TaskBasicInfoVirtualSize(&mut virtual_size) }; - if rv == 0 { - Some(virtual_size as usize) - } else { - None - } -} - -/// Obtains task_basic_info::resident_size. -pub fn resident_size() -> Option { - let mut resident_size: size_t = 0; - let rv = unsafe { TaskBasicInfoResidentSize(&mut resident_size) }; - if rv == 0 { - Some(resident_size as usize) - } else { - None - } -} - -unsafe extern "C" { - fn TaskBasicInfoVirtualSize(virtual_size: *mut size_t) -> c_int; - fn TaskBasicInfoResidentSize(resident_size: *mut size_t) -> c_int; -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_stuff() { - // In theory these can fail to return a value, but in practice they - // don't unless something really bizarre has happened with the OS. So - // assume they succeed. The returned values are non-deterministic, but - // check they're non-zero as a basic sanity test. - assert!(virtual_size().unwrap() > 0); - assert!(resident_size().unwrap() > 0); - } -} diff --git a/support/rust-task_info/src/task_info.c b/support/rust-task_info/src/task_info.c deleted file mode 100644 index 476551c063b..00000000000 --- a/support/rust-task_info/src/task_info.c +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2013 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#include -#include - -static int -TaskBasicInfo(struct task_basic_info* info) -{ - mach_msg_type_number_t count = TASK_BASIC_INFO_COUNT; - kern_return_t kr = task_info(mach_task_self(), TASK_BASIC_INFO, - (task_info_t)info, &count); - return kr == KERN_SUCCESS ? 0 : -1; -} - -int -TaskBasicInfoVirtualSize(size_t* virtualSize) -{ - struct task_basic_info ti; - int rv = TaskBasicInfo(&ti); - *virtualSize = (rv == 0) ? ti.virtual_size : 0; - return rv; -} - -int -TaskBasicInfoResidentSize(size_t* residentSize) -{ - struct task_basic_info ti; - int rv = TaskBasicInfo(&ti); - *residentSize = (rv == 0) ? ti.resident_size : 0; - return rv; -} -