diff options
Diffstat (limited to 'www')
64 files changed, 2587 insertions, 40 deletions
diff --git a/www/chromium/Makefile b/www/chromium/Makefile index 1dd3e43c87a9..023f8f9f95f5 100644 --- a/www/chromium/Makefile +++ b/www/chromium/Makefile @@ -1,5 +1,6 @@ PORTNAME= chromium PORTVERSION= 136.0.7103.113 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 CATEGORIES= www wayland diff --git a/www/chromium/files/patch-build_rust_allocator_BUILD.gn b/www/chromium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/chromium/files/patch-build_rust_allocator_DEPS b/www/chromium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/chromium/files/patch-build_rust_allocator_alias.cc b/www/chromium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/chromium/files/patch-build_rust_allocator_alias.h b/www/chromium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include <stddef.h> ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc b/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include <cstddef> ++#include <cstring> ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include <cstdlib> ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls.h b/www/chromium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include <cstddef> ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/chromium/files/patch-build_rust_allocator_compiler__specific.h b/www/chromium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_immediate__crash.h b/www/chromium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/chromium/files/patch-build_rust_allocator_lib.rs b/www/chromium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/chromium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/chromium/files/patch-build_rust_cargo__crate.gni b/www/chromium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/chromium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/chromium/files/patch-build_rust_rust__macro.gni b/www/chromium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/chromium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/chromium/files/patch-build_rust_rust__target.gni b/www/chromium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/chromium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/chromium/files/patch-build_rust_std_BUILD.gn b/www/chromium/files/patch-build_rust_std_BUILD.gn index 0a5335d58d48..c6c2801bd47d 100644 --- a/www/chromium/files/patch-build_rust_std_BUILD.gn +++ b/www/chromium/files/patch-build_rust_std_BUILD.gn @@ -1,6 +1,58 @@ ---- build/rust/std/BUILD.gn.orig 2025-04-05 13:54:50 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", @@ -22,7 +74,7 @@ } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ @@ -30,3 +82,25 @@ "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + } diff --git a/www/gohugo/Makefile b/www/gohugo/Makefile index a998c60d116c..864d6c3004f2 100644 --- a/www/gohugo/Makefile +++ b/www/gohugo/Makefile @@ -1,6 +1,6 @@ PORTNAME= hugo DISTVERSIONPREFIX= v -DISTVERSION= 0.147.3 +DISTVERSION= 0.147.4 PORTEPOCH= 1 CATEGORIES= www PKGNAMEPREFIX= go diff --git a/www/gohugo/distinfo b/www/gohugo/distinfo index 550828130a87..844026f970c7 100644 --- a/www/gohugo/distinfo +++ b/www/gohugo/distinfo @@ -1,5 +1,5 @@ -TIMESTAMP = 1747057537 -SHA256 (go/www_gohugo/hugo-v0.147.3/v0.147.3.mod) = cb41ea476364590e46adc72d923c617f69d99544d2a78c743ae4608f4c43ea25 -SIZE (go/www_gohugo/hugo-v0.147.3/v0.147.3.mod) = 8036 -SHA256 (go/www_gohugo/hugo-v0.147.3/v0.147.3.zip) = 36a1eb90054d1cef4aa8f74a9951e44c211d0d68d0d3fe90a8af4764fa6a0117 -SIZE (go/www_gohugo/hugo-v0.147.3/v0.147.3.zip) = 5734808 +TIMESTAMP = 1747741364 +SHA256 (go/www_gohugo/hugo-v0.147.4/v0.147.4.mod) = cb41ea476364590e46adc72d923c617f69d99544d2a78c743ae4608f4c43ea25 +SIZE (go/www_gohugo/hugo-v0.147.4/v0.147.4.mod) = 8036 +SHA256 (go/www_gohugo/hugo-v0.147.4/v0.147.4.zip) = e723aac853ffa451bac32b823192d8fcb78d18e378437f277e0e4c214bc126c2 +SIZE (go/www_gohugo/hugo-v0.147.4/v0.147.4.zip) = 5736653 diff --git a/www/iridium/Makefile b/www/iridium/Makefile index 40178f0ec7ba..5c87dc11671a 100644 --- a/www/iridium/Makefile +++ b/www/iridium/Makefile @@ -1,5 +1,6 @@ PORTNAME= iridium PORTVERSION= 2025.05.136.2 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 CATEGORIES= www wayland diff --git a/www/iridium/files/patch-build_rust_allocator_BUILD.gn b/www/iridium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/iridium/files/patch-build_rust_allocator_DEPS b/www/iridium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/iridium/files/patch-build_rust_allocator_alias.cc b/www/iridium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/iridium/files/patch-build_rust_allocator_alias.h b/www/iridium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include <stddef.h> ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc b/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include <cstddef> ++#include <cstring> ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include <cstdlib> ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls.h b/www/iridium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include <cstddef> ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/iridium/files/patch-build_rust_allocator_compiler__specific.h b/www/iridium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_immediate__crash.h b/www/iridium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/iridium/files/patch-build_rust_allocator_lib.rs b/www/iridium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/iridium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/iridium/files/patch-build_rust_cargo__crate.gni b/www/iridium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/iridium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/iridium/files/patch-build_rust_rust__macro.gni b/www/iridium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/iridium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/iridium/files/patch-build_rust_rust__target.gni b/www/iridium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/iridium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/iridium/files/patch-build_rust_std_BUILD.gn b/www/iridium/files/patch-build_rust_std_BUILD.gn index d0b722a2cab3..c6c2801bd47d 100644 --- a/www/iridium/files/patch-build_rust_std_BUILD.gn +++ b/www/iridium/files/patch-build_rust_std_BUILD.gn @@ -1,6 +1,58 @@ ---- build/rust/std/BUILD.gn.orig 2025-05-07 06:48:23 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", @@ -22,7 +74,7 @@ } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ @@ -30,3 +82,25 @@ "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + } diff --git a/www/moin2/Makefile b/www/moin2/Makefile index f9cfdc0b4cf6..73c81803afa8 100644 --- a/www/moin2/Makefile +++ b/www/moin2/Makefile @@ -4,7 +4,7 @@ CATEGORIES= www python MASTER_SITES= https://github.com/moinwiki/moin/releases/download/${DISTVERSION}/ PKGNAMESUFFIX= 2 -MAINTAINER= bofh@FreeBSD.org +MAINTAINER= ports@FreeBSD.org COMMENT= Easy to use, full-featured and extensible wiki software package WWW= https://moinmo.in/ diff --git a/www/nextcloud-appointments/Makefile b/www/nextcloud-appointments/Makefile index 251b0f2a29de..0a65342e1a21 100644 --- a/www/nextcloud-appointments/Makefile +++ b/www/nextcloud-appointments/Makefile @@ -1,5 +1,5 @@ PORTNAME= appointments -PORTVERSION= 2.4.3 +PORTVERSION= 2.4.4 CATEGORIES= www MASTER_SITES= https://github.com/${GH_ACCOUNT}/${PORTNAME}/raw/${DISTVERSIONPREFIX}${DISTVERSION}/build/artifacts/appstore/ DISTVERSIONPREFIX= v diff --git a/www/nextcloud-appointments/distinfo b/www/nextcloud-appointments/distinfo index 9305ffefff03..b078a88d6d6f 100644 --- a/www/nextcloud-appointments/distinfo +++ b/www/nextcloud-appointments/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1743615391 -SHA256 (nextcloud/appointments-2.4.3/appointments.tar.gz) = 96cd6b2e7b17ed4f70a365a412dce1aef9624dc59497a2d65e8944ffd7ad27bf -SIZE (nextcloud/appointments-2.4.3/appointments.tar.gz) = 2206164 +TIMESTAMP = 1747764016 +SHA256 (nextcloud/appointments-2.4.4/appointments.tar.gz) = 6b18195db34424edf4dbeab02f83710d19813251c5674f793168935c448b45d5 +SIZE (nextcloud/appointments-2.4.4/appointments.tar.gz) = 2215489 diff --git a/www/proxygen/Makefile b/www/proxygen/Makefile index a97fe5968f2a..e29bf0e39b54 100644 --- a/www/proxygen/Makefile +++ b/www/proxygen/Makefile @@ -1,6 +1,6 @@ PORTNAME= proxygen DISTVERSIONPREFIX= v -DISTVERSION= 2025.05.12.00 +DISTVERSION= 2025.05.19.00 CATEGORIES= www MAINTAINER= yuri@FreeBSD.org diff --git a/www/proxygen/distinfo b/www/proxygen/distinfo index ea2c88d06979..8ff6ca192308 100644 --- a/www/proxygen/distinfo +++ b/www/proxygen/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1747102739 -SHA256 (facebook-proxygen-v2025.05.12.00_GH0.tar.gz) = 1503c296970790e79a543c524185886296e51a01ca27e649c639cb2de9283650 -SIZE (facebook-proxygen-v2025.05.12.00_GH0.tar.gz) = 1217212 +TIMESTAMP = 1747730524 +SHA256 (facebook-proxygen-v2025.05.19.00_GH0.tar.gz) = 9f228584d42be9381bdc044a8289f2a6db34fae2e8f23239e9748fb37938edc6 +SIZE (facebook-proxygen-v2025.05.19.00_GH0.tar.gz) = 1217144 diff --git a/www/selenium/Makefile b/www/selenium/Makefile index e2551097a07f..48dc76afe821 100644 --- a/www/selenium/Makefile +++ b/www/selenium/Makefile @@ -1,8 +1,8 @@ PORTNAME= selenium -PORTVERSION= 4.26.0 +DISTVERSION= 4.32.0 CATEGORIES= www devel java -MASTER_SITES= https://github.com/SeleniumHQ/${PORTNAME}/releases/download/${PORTNAME}-${PORTVERSION}/ -DISTNAME= selenium-server-${PORTVERSION} +MASTER_SITES= https://github.com/SeleniumHQ/${PORTNAME}/releases/download/${PORTNAME}-${DISTVERSION}/ +DISTNAME= selenium-server-${DISTVERSION} EXTRACT_SUFX= .jar EXTRACT_ONLY= @@ -21,7 +21,7 @@ USE_RC_SUBR= selenium NO_ARCH= yes NO_BUILD= yes SUB_LIST+= JAVA_HOME=${JAVA_HOME} \ - SELENIUM_VERSION=${PORTVERSION} + SELENIUM_VERSION=${DISTVERSION} SELENIUM_HOME= ${PREFIX}/selenium diff --git a/www/selenium/distinfo b/www/selenium/distinfo index a9ad3f875f3a..a6af3d02879f 100644 --- a/www/selenium/distinfo +++ b/www/selenium/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1731376689 -SHA256 (selenium-server-4.26.0.jar) = 19138985733452abe00339350fd74571a43d11ef8aad55a29c18d33f326ccf0a -SIZE (selenium-server-4.26.0.jar) = 42632726 +TIMESTAMP = 1747707505 +SHA256 (selenium-server-4.32.0.jar) = a2a40741368a4251b9ba60469a048e4fae9417491171d9faf7ce55cc40320335 +SIZE (selenium-server-4.32.0.jar) = 42675799 diff --git a/www/typo3-12/Makefile b/www/typo3-12/Makefile index a1edb26741b0..debae5bfffd5 100644 --- a/www/typo3-12/Makefile +++ b/www/typo3-12/Makefile @@ -30,7 +30,7 @@ WRKSRC= ${WRKDIR}/${PORTNAME}_src-${DISTVERSION} PORT_V_MAJOR= 12 PORT_V_MINOR= 4 -PORT_V_PATCH= 28 +PORT_V_PATCH= 31 TYPO3DIR= www/${PORTNAME}-${PORT_V_MAJOR} diff --git a/www/typo3-12/distinfo b/www/typo3-12/distinfo index 7ecfc3395f59..8ba5a3b50a56 100644 --- a/www/typo3-12/distinfo +++ b/www/typo3-12/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1742309083 -SHA256 (typo3_src-12.4.28.tar.gz) = 000c7dd6cb940592ce83c683837862086d29d8809aca7bd5cc92180c8e94b2cc -SIZE (typo3_src-12.4.28.tar.gz) = 26593637 +TIMESTAMP = 1747746945 +SHA256 (typo3_src-12.4.31.tar.gz) = 69e71c0be15291eb56db09ab305c942b499da434a9d9042b9e0662b1a9783681 +SIZE (typo3_src-12.4.31.tar.gz) = 26607292 diff --git a/www/typo3-13/Makefile b/www/typo3-13/Makefile index 651851cca9e2..7ed4243700ca 100644 --- a/www/typo3-13/Makefile +++ b/www/typo3-13/Makefile @@ -1,6 +1,6 @@ PORTNAME= typo3 DISTVERSION= ${PORT_V_MAJOR}.${PORT_V_MINOR}.${PORT_V_PATCH} -PORTREVISION= 1 +#PORTREVISION= 1 CATEGORIES= www MASTER_SITES= https://cdn.typo3.com/typo3/${DISTVERSION}/ PKGNAMESUFFIX= -${PORT_V_MAJOR}${PHP_PKGNAMESUFFIX} @@ -32,7 +32,7 @@ SUB_LIST+= PREFIX=${PREFIX} \ PORT_V_MAJOR= 13 PORT_V_MINOR= 4 -PORT_V_PATCH= 8 +PORT_V_PATCH= 12 TYPO3DIR= www/${PORTNAME}-${PORT_V_MAJOR} diff --git a/www/typo3-13/distinfo b/www/typo3-13/distinfo index e0f4de0680f6..2b6bd6c63362 100644 --- a/www/typo3-13/distinfo +++ b/www/typo3-13/distinfo @@ -1,3 +1,3 @@ -TIMESTAMP = 1742309756 -SHA256 (typo3_src-13.4.8.tar.gz) = f851dc46e54d3997c5de16133a41d32283ccc49049882a4d8b97a60e87aa02cf -SIZE (typo3_src-13.4.8.tar.gz) = 25531952 +TIMESTAMP = 1747749336 +SHA256 (typo3_src-13.4.12.tar.gz) = 6d6cbf20c0941592a0c4d85aa540e25564e06de05b33b77f322fee7d42396481 +SIZE (typo3_src-13.4.12.tar.gz) = 25573553 diff --git a/www/ungoogled-chromium/Makefile b/www/ungoogled-chromium/Makefile index 11d2fde1f6f1..1c0da59d7a65 100644 --- a/www/ungoogled-chromium/Makefile +++ b/www/ungoogled-chromium/Makefile @@ -1,5 +1,6 @@ PORTNAME= ungoogled-chromium PORTVERSION= 136.0.7103.113 +PORTREVISION= 1 PULSEMV= 16 PULSEV= ${PULSEMV}.1 UGVERSION= ${DISTVERSION}-1 diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn b/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn new file mode 100644 index 000000000000..cb1633140dcc --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_BUILD.gn @@ -0,0 +1,109 @@ +--- build/rust/allocator/BUILD.gn.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/BUILD.gn +@@ -0,0 +1,106 @@ ++# Copyright 2025 The Chromium Authors ++# Use of this source code is governed by a BSD-style license that can be ++# found in the LICENSE file. ++ ++import("//build/buildflag_header.gni") ++import("//build/config/rust.gni") ++import("//build/rust/rust_static_library.gni") ++ ++rust_allocator_uses_partition_alloc = false ++if (build_with_chromium) { ++ import("//base/allocator/partition_allocator/partition_alloc.gni") ++ rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc ++} ++ ++# In ASAN builds, PartitionAlloc-Everywhere is disabled, meaning malloc() and ++# friends in C++ do not go to PartitionAlloc. So we also don't point the Rust ++# allocation functions at PartitionAlloc. Generally, this means we just direct ++# them to the Standard Library's allocator. ++# ++# However, on Windows the Standard Library uses HeapAlloc() and Windows ASAN ++# does *not* hook that method, so ASAN does not get to hear about allocations ++# made in Rust. To resolve this, we redirect allocation to _aligned_malloc ++# which Windows ASAN *does* hook. ++# ++# Note that there is a runtime option to make ASAN hook HeapAlloc() but ++# enabling it breaks Win32 APIs like CreateProcess: ++# https://crbug.com/368070343#comment29 ++rust_allocator_uses_aligned_malloc = false ++if (!rust_allocator_uses_partition_alloc && is_win && is_asan) { ++ rust_allocator_uses_aligned_malloc = true ++} ++ ++rust_allocator_uses_allocator_impls_h = ++ rust_allocator_uses_partition_alloc || rust_allocator_uses_aligned_malloc ++ ++buildflag_header("buildflags") { ++ header = "buildflags.h" ++ flags = [ ++ "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", ++ "RUST_ALLOCATOR_USES_ALIGNED_MALLOC=$rust_allocator_uses_aligned_malloc", ++ ] ++ visibility = [ ":*" ] ++} ++ ++if (toolchain_has_rust) { ++ # All targets which depend on Rust code but are not linked by rustc must ++ # depend on this. Usually, this dependency will come from the rust_target() GN ++ # template. However, cargo_crate() does *not* include this dependency so any ++ # C++ targets which directly depend on a cargo_crate() must depend on this. ++ rust_static_library("allocator") { ++ sources = [ "lib.rs" ] ++ crate_root = "lib.rs" ++ cxx_bindings = [ "lib.rs" ] ++ ++ deps = [ ":alloc_error_handler_impl" ] ++ if (rust_allocator_uses_allocator_impls_h) { ++ deps += [ ":allocator_impls" ] ++ } ++ ++ no_chromium_prelude = true ++ no_allocator_crate = true ++ allow_unsafe = true ++ ++ rustflags = [] ++ if (rust_allocator_uses_allocator_impls_h) { ++ rustflags += [ "--cfg=rust_allocator_uses_allocator_impls_h" ] ++ cxx_bindings += [ "allocator_impls_ffi.rs" ] ++ sources += [ "allocator_impls_ffi.rs" ] ++ } ++ ++ # TODO(https://crbug.com/410596442): Stop using unstable features here. ++ configs -= [ "//build/config/compiler:disallow_unstable_features" ] ++ } ++ ++ if (rust_allocator_uses_allocator_impls_h) { ++ static_library("allocator_impls") { ++ public_deps = [] ++ if (rust_allocator_uses_partition_alloc) { ++ public_deps += ++ [ "//base/allocator/partition_allocator:partition_alloc" ] ++ } ++ ++ sources = [ ++ "allocator_impls.cc", ++ "allocator_impls.h", ++ ] ++ deps = [ ":buildflags" ] ++ visibility = [ ":*" ] ++ } ++ } ++ ++ static_library("alloc_error_handler_impl") { ++ sources = [ ++ # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been ++ # copied from `//base`. ++ # TODO(crbug.com/40279749): Avoid duplication / reuse code. ++ "alias.cc", ++ "alias.h", ++ "alloc_error_handler_impl.cc", ++ "alloc_error_handler_impl.h", ++ "compiler_specific.h", ++ "immediate_crash.h", ++ ] ++ visibility = [ ":*" ] ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS b/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS new file mode 100644 index 000000000000..74bb2d6c2421 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_DEPS @@ -0,0 +1,12 @@ +--- build/rust/allocator/DEPS.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/DEPS +@@ -0,0 +1,9 @@ ++include_rules = [ ++ "-base", ++] ++ ++specific_include_rules = { ++ "allocator_impls.cc" : [ ++ "+partition_alloc" ++ ] ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc new file mode 100644 index 000000000000..5280641f27e1 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.cc @@ -0,0 +1,25 @@ +--- build/rust/allocator/alias.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.cc +@@ -0,0 +1,22 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.cc ( additionally the APIs ++// were moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#include "build/rust/allocator/alias.h" ++ ++#include "build/rust/allocator/compiler_specific.h" ++ ++namespace build_rust_std { ++namespace debug { ++ ++// This file/function should be excluded from LTO/LTCG to ensure that the ++// compiler can't see this function's implementation when compiling calls to it. ++NOINLINE void Alias(const void* var) {} ++ ++} // namespace debug ++} // namespace build_rust_std diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h new file mode 100644 index 000000000000..6530c6ae8779 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alias.h @@ -0,0 +1,40 @@ +--- build/rust/allocator/alias.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alias.h +@@ -0,0 +1,37 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/debug/alias.h (and then trimmed to just ++// the APIs / macros needed by //build/rust/std; additionally the APIs were ++// moved into the `build_rust_std` namespace). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALIAS_H_ ++#define BUILD_RUST_ALLOCATOR_ALIAS_H_ ++ ++#include <stddef.h> ++ ++namespace build_rust_std { ++namespace debug { ++ ++// Make the optimizer think that |var| is aliased. This can be used to prevent a ++// local variable from being optimized out (which is something that ++// `NO_CODE_FOLDING` macro definition below depends on). See ++// //base/debug/alias.h for more details. ++void Alias(const void* var); ++ ++} // namespace debug ++ ++} // namespace build_rust_std ++ ++// Prevent code folding (where a linker identifies functions that are ++// bit-identical and overlays them, which saves space but it leads to confusing ++// call stacks because multiple symbols are at the same address). See ++// //base/debug/alias.h for more details. ++#define NO_CODE_FOLDING() \ ++ const int line_number = __LINE__; \ ++ build_rust_std::debug::Alias(&line_number) ++ ++#endif // BUILD_RUST_ALLOCATOR_ALIAS_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc new file mode 100644 index 000000000000..048c267abefa --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.cc @@ -0,0 +1,20 @@ +--- build/rust/allocator/alloc_error_handler_impl.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.cc +@@ -0,0 +1,17 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/alloc_error_handler_impl.h" ++ ++#include "build/rust/allocator/alias.h" ++#include "build/rust/allocator/immediate_crash.h" ++ ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl() { ++ NO_CODE_FOLDING(); ++ IMMEDIATE_CRASH(); ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h new file mode 100644 index 000000000000..887ea602b027 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_alloc__error__handler__impl.h @@ -0,0 +1,24 @@ +--- build/rust/allocator/alloc_error_handler_impl.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/alloc_error_handler_impl.h +@@ -0,0 +1,21 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ ++ ++// This header exposes to Rust a C++ implementation of quickly crashing after an ++// allocation error. (The API below is called from `__rust_alloc_error_handler` ++// in `lib.rs`.) ++// ++// TODO(lukasza): Investigate if we can delete this `.h` / `.cc` and just call ++// `std::process::abort()` (or something else?) directly from `.rs`. The main ++// open question is how much we care about `NO_CODE_FOLDING`. ++namespace rust_allocator_internal { ++ ++void alloc_error_handler_impl(); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOC_ERROR_HANDLER_IMPL_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc new file mode 100644 index 000000000000..94e04d7b966a --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.cc @@ -0,0 +1,108 @@ +--- build/rust/allocator/allocator_impls.cc.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.cc +@@ -0,0 +1,105 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#include "build/rust/allocator/allocator_impls.h" ++ ++#ifdef UNSAFE_BUFFERS_BUILD ++// TODO(crbug.com/390223051): Remove C-library calls to fix the errors. ++#pragma allow_unsafe_libc_calls ++#endif ++ ++#include <cstddef> ++#include <cstring> ++ ++#include "build/build_config.h" ++#include "build/rust/allocator/buildflags.h" ++ ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++#include "partition_alloc/partition_alloc_constants.h" // nogncheck ++#include "partition_alloc/shim/allocator_shim.h" // nogncheck ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++#include <cstdlib> ++#endif ++ ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // PartitionAlloc will crash if given an alignment larger than this. ++ if (align > partition_alloc::internal::kMaxSupportedAlignment) { ++ return nullptr; ++ } ++ ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>(allocator_shim::UncheckedAlloc(size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedAlloc(size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_malloc(size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++void dealloc(unsigned char* p, size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ if (align <= alignof(std::max_align_t)) { ++ allocator_shim::UncheckedFree(p); ++ } else { ++ allocator_shim::UncheckedAlignedFree(p); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return _aligned_free(p); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) ++ // We use unchecked allocation paths in PartitionAlloc rather than going ++ // through its shims in `malloc()` etc so that we can support fallible ++ // allocation paths such as Vec::try_reserve without crashing on allocation ++ // failure. ++ if (align <= alignof(std::max_align_t)) { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedRealloc(p, new_size)); ++ } else { ++ return static_cast<unsigned char*>( ++ allocator_shim::UncheckedAlignedRealloc(p, new_size, align)); ++ } ++#elif BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ return static_cast<unsigned char*>(_aligned_realloc(p, new_size, align)); ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++unsigned char* alloc_zeroed(size_t size, size_t align) { ++#if BUILDFLAG(RUST_ALLOCATOR_USES_PARTITION_ALLOC) || \ ++ BUILDFLAG(RUST_ALLOCATOR_USES_ALIGNED_MALLOC) ++ // TODO(danakj): When RUST_ALLOCATOR_USES_PARTITION_ALLOC is true, it's ++ // possible that a partition_alloc::UncheckedAllocZeroed() call would perform ++ // better than partition_alloc::UncheckedAlloc() + memset. But there is no ++ // such API today. See b/342251590. ++ unsigned char* p = alloc(size, align); ++ if (p) { ++ memset(p, 0, size); ++ } ++ return p; ++#else ++#error This configuration is not supported. ++#endif ++} ++ ++} // namespace rust_allocator_internal diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h new file mode 100644 index 000000000000..9249cdc938d2 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls.h @@ -0,0 +1,27 @@ +--- build/rust/allocator/allocator_impls.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls.h +@@ -0,0 +1,24 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++#ifndef BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++#define BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ ++ ++#include <cstddef> ++ ++// This header exposes a C++ allocator (e.g. PartitionAlloc) to Rust. ++// The APIs below are called from `impl GlobalAlloc` in `lib.rs`. ++namespace rust_allocator_internal { ++ ++unsigned char* alloc(size_t size, size_t align); ++void dealloc(unsigned char* p, size_t size, size_t align); ++unsigned char* realloc(unsigned char* p, ++ size_t old_size, ++ size_t align, ++ size_t new_size); ++unsigned char* alloc_zeroed(size_t size, size_t align); ++ ++} // namespace rust_allocator_internal ++ ++#endif // BUILD_RUST_ALLOCATOR_ALLOCATOR_IMPLS_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs new file mode 100644 index 000000000000..8f0baf1576ce --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_allocator__impls__ffi.rs @@ -0,0 +1,22 @@ +--- build/rust/allocator/allocator_impls_ffi.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/allocator_impls_ffi.rs +@@ -0,0 +1,19 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! FFI for `allocator_impls.h` is in a separate `.rs` file/module to ++//! better support conditional compilation (these functions are only ++//! used under `#[cfg(rust_allocator_uses_allocator_impls_h)]`. ++ ++#[cxx::bridge(namespace = "rust_allocator_internal")] ++pub mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/allocator_impls.h"); ++ ++ unsafe fn alloc(size: usize, align: usize) -> *mut u8; ++ unsafe fn dealloc(p: *mut u8, size: usize, align: usize); ++ unsafe fn realloc(p: *mut u8, old_size: usize, align: usize, new_size: usize) -> *mut u8; ++ unsafe fn alloc_zeroed(size: usize, align: usize) -> *mut u8; ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h new file mode 100644 index 000000000000..7feb0c739d79 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_compiler__specific.h @@ -0,0 +1,41 @@ +--- build/rust/allocator/compiler_specific.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/compiler_specific.h +@@ -0,0 +1,38 @@ ++// Copyright 2023 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/compiler_specific.h (and then ++// significantly trimmed to just the APIs / macros needed by //build/rust/std). ++// ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++#define BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ ++ ++#include "build/build_config.h" ++ ++#if defined(COMPILER_MSVC) && !defined(__clang__) ++#error "Only clang-cl is supported on Windows, see https://crbug.com/988071" ++#endif ++ ++#if defined(__has_attribute) ++#define HAS_ATTRIBUTE(x) __has_attribute(x) ++#else ++#define HAS_ATTRIBUTE(x) 0 ++#endif ++ ++// Annotate a function indicating it should not be inlined. ++// Use like: ++// NOINLINE void DoStuff() { ... } ++#if defined(__clang__) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE [[clang::noinline]] ++#elif defined(COMPILER_GCC) && HAS_ATTRIBUTE(noinline) ++#define NOINLINE __attribute__((noinline)) ++#elif defined(COMPILER_MSVC) ++#define NOINLINE __declspec(noinline) ++#else ++#define NOINLINE ++#endif ++ ++#endif // BUILD_RUST_ALLOCATOR_COMPILER_SPECIFIC_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h b/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h new file mode 100644 index 000000000000..7ab0f9d9c34c --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_immediate__crash.h @@ -0,0 +1,174 @@ +--- build/rust/allocator/immediate_crash.h.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/immediate_crash.h +@@ -0,0 +1,171 @@ ++// Copyright 2021 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++// This file has been copied from //base/immediate_crash.h. ++// TODO(crbug.com/40279749): Avoid code duplication / reuse code. ++ ++#ifndef BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++#define BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ ++ ++#include "build/build_config.h" ++ ++// Crashes in the fastest possible way with no attempt at logging. ++// There are several constraints; see http://crbug.com/664209 for more context. ++// ++// - TRAP_SEQUENCE_() must be fatal. It should not be possible to ignore the ++// resulting exception or simply hit 'continue' to skip over it in a debugger. ++// - Different instances of TRAP_SEQUENCE_() must not be folded together, to ++// ensure crash reports are debuggable. Unlike __builtin_trap(), asm volatile ++// blocks will not be folded together. ++// Note: TRAP_SEQUENCE_() previously required an instruction with a unique ++// nonce since unlike clang, GCC folds together identical asm volatile ++// blocks. ++// - TRAP_SEQUENCE_() must produce a signal that is distinct from an invalid ++// memory access. ++// - TRAP_SEQUENCE_() must be treated as a set of noreturn instructions. ++// __builtin_unreachable() is used to provide that hint here. clang also uses ++// this as a heuristic to pack the instructions in the function epilogue to ++// improve code density. ++// ++// Additional properties that are nice to have: ++// - TRAP_SEQUENCE_() should be as compact as possible. ++// - The first instruction of TRAP_SEQUENCE_() should not change, to avoid ++// shifting crash reporting clusters. As a consequence of this, explicit ++// assembly is preferred over intrinsics. ++// Note: this last bullet point may no longer be true, and may be removed in ++// the future. ++ ++// Note: TRAP_SEQUENCE Is currently split into two macro helpers due to the fact ++// that clang emits an actual instruction for __builtin_unreachable() on certain ++// platforms (see https://crbug.com/958675). In addition, the int3/bkpt/brk will ++// be removed in followups, so splitting it up like this now makes it easy to ++// land the followups. ++ ++#if defined(COMPILER_GCC) ++ ++#if BUILDFLAG(IS_NACL) ++ ++// Crash report accuracy is not guaranteed on NaCl. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#elif defined(ARCH_CPU_X86_FAMILY) ++ ++// TODO(crbug.com/40625592): In theory, it should be possible to use just ++// int3. However, there are a number of crashes with SIGILL as the exception ++// code, so it seems likely that there's a signal handler that allows execution ++// to continue after SIGTRAP. ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++ ++#if BUILDFLAG(IS_APPLE) ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Mac. ++#define TRAP_SEQUENCE2_() asm volatile("") ++#else ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++#endif // BUILDFLAG(IS_APPLE) ++ ++#elif defined(ARCH_CPU_ARMEL) ++ ++// bkpt will generate a SIGBUS when running on armv7 and a SIGTRAP when running ++// as a 32 bit userspace app on arm64. There doesn't seem to be any way to ++// cause a SIGTRAP from userspace without using a syscall (which would be a ++// problem for sandboxing). ++// TODO(crbug.com/40625592): Remove bkpt from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("bkpt #0") ++#define TRAP_SEQUENCE2_() asm volatile("udf #0") ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// This will always generate a SIGTRAP on arm64. ++// TODO(crbug.com/40625592): Remove brk from this sequence. ++#define TRAP_SEQUENCE1_() asm volatile("brk #0") ++#define TRAP_SEQUENCE2_() asm volatile("hlt #0") ++ ++#else ++ ++// Crash report accuracy will not be guaranteed on other architectures, but at ++// least this will crash as expected. ++#define TRAP_SEQUENCE1_() __builtin_trap() ++#define TRAP_SEQUENCE2_() asm volatile("") ++ ++#endif // ARCH_CPU_* ++ ++#elif defined(COMPILER_MSVC) ++ ++#if !defined(__clang__) ++ ++// MSVC x64 doesn't support inline asm, so use the MSVC intrinsic. ++#define TRAP_SEQUENCE1_() __debugbreak() ++#define TRAP_SEQUENCE2_() ++ ++#elif defined(ARCH_CPU_ARM64) ++ ++// Windows ARM64 uses "BRK #F000" as its breakpoint instruction, and ++// __debugbreak() generates that in both VC++ and clang. ++#define TRAP_SEQUENCE1_() __debugbreak() ++// Intentionally empty: __builtin_unreachable() is always part of the sequence ++// (see IMMEDIATE_CRASH below) and already emits a ud2 on Win64, ++// https://crbug.com/958373 ++#define TRAP_SEQUENCE2_() __asm volatile("") ++ ++#else ++ ++#define TRAP_SEQUENCE1_() asm volatile("int3") ++#define TRAP_SEQUENCE2_() asm volatile("ud2") ++ ++#endif // __clang__ ++ ++#else ++ ++#error No supported trap sequence! ++ ++#endif // COMPILER_GCC ++ ++#define TRAP_SEQUENCE_() \ ++ do { \ ++ TRAP_SEQUENCE1_(); \ ++ TRAP_SEQUENCE2_(); \ ++ } while (false) ++ ++// CHECK() and the trap sequence can be invoked from a constexpr function. ++// This could make compilation fail on GCC, as it forbids directly using inline ++// asm inside a constexpr function. However, it allows calling a lambda ++// expression including the same asm. ++// The side effect is that the top of the stacktrace will not point to the ++// calling function, but to this anonymous lambda. This is still useful as the ++// full name of the lambda will typically include the name of the function that ++// calls CHECK() and the debugger will still break at the right line of code. ++#if !defined(COMPILER_GCC) || defined(__clang__) ++ ++#define WRAPPED_TRAP_SEQUENCE_() TRAP_SEQUENCE_() ++ ++#else ++ ++#define WRAPPED_TRAP_SEQUENCE_() \ ++ do { \ ++ [] { TRAP_SEQUENCE_(); }(); \ ++ } while (false) ++ ++#endif // !defined(COMPILER_GCC) || defined(__clang__) ++ ++#if defined(__clang__) || defined(COMPILER_GCC) ++ ++// __builtin_unreachable() hints to the compiler that this is noreturn and can ++// be packed in the function epilogue. ++#define IMMEDIATE_CRASH() \ ++ ({ \ ++ WRAPPED_TRAP_SEQUENCE_(); \ ++ __builtin_unreachable(); \ ++ }) ++ ++#else ++ ++// This is supporting non-chromium user of logging.h to build with MSVC, like ++// pdfium. On MSVC there is no __builtin_unreachable(). ++#define IMMEDIATE_CRASH() WRAPPED_TRAP_SEQUENCE_() ++ ++#endif // defined(__clang__) || defined(COMPILER_GCC) ++ ++#endif // BUILD_RUST_ALLOCATOR_IMMEDIATE_CRASH_H_ diff --git a/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs b/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs new file mode 100644 index 000000000000..89fddf278294 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_allocator_lib.rs @@ -0,0 +1,122 @@ +--- build/rust/allocator/lib.rs.orig 2025-05-20 09:16:26 UTC ++++ build/rust/allocator/lib.rs +@@ -0,0 +1,119 @@ ++// Copyright 2025 The Chromium Authors ++// Use of this source code is governed by a BSD-style license that can be ++// found in the LICENSE file. ++ ++//! Define the allocator that Rust code in Chrome should use. ++//! ++//! Any final artifact that depends on this crate, even transitively, will use ++//! the allocator defined here. ++//! ++//! List of known issues: ++//! ++//! 1. We'd like to use PartitionAlloc on Windows, but the stdlib uses Windows ++//! heap functions directly that PartitionAlloc can not intercept. ++//! 2. We'd like `Vec::try_reserve` to fail at runtime on Linux instead of ++//! crashing in malloc() where PartitionAlloc replaces that function. ++ ++// Required to apply weak linkage to symbols. ++// ++// TODO(https://crbug.com/410596442): Stop using unstable features here. ++// https://github.com/rust-lang/rust/issues/29603 tracks stabilization of the `linkage` feature. ++#![feature(linkage)] ++// Required to apply `#[rustc_std_internal_symbol]` to our alloc error handler ++// so the name is correctly mangled as rustc expects. ++// ++// TODO(https://crbug.com/410596442): Stop using internal features here. ++#![allow(internal_features)] ++#![feature(rustc_attrs)] ++ ++// This module is in a separate source file to avoid having to teach `cxxbridge` ++// about conditional compilation. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod allocator_impls_ffi; ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using an allocator from C++. ++#[cfg(rust_allocator_uses_allocator_impls_h)] ++mod cpp_allocator { ++ use super::allocator_impls_ffi::ffi; ++ use std::alloc::{GlobalAlloc, Layout}; ++ ++ struct Allocator; ++ ++ unsafe impl GlobalAlloc for Allocator { ++ unsafe fn alloc(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn dealloc(&self, ptr: *mut u8, layout: Layout) { ++ unsafe { ++ ffi::dealloc(ptr, layout.size(), layout.align()); ++ } ++ } ++ ++ unsafe fn alloc_zeroed(&self, layout: Layout) -> *mut u8 { ++ unsafe { ffi::alloc_zeroed(layout.size(), layout.align()) } ++ } ++ ++ unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 { ++ unsafe { ffi::realloc(ptr, layout.size(), layout.align(), new_size) } ++ } ++ } ++ ++ #[global_allocator] ++ static GLOBAL: Allocator = Allocator; ++} ++ ++/// Module that provides `#[global_allocator]` / `GlobalAlloc` interface for ++/// using the default Rust allocator. ++#[cfg(not(rust_allocator_uses_allocator_impls_h))] ++mod rust_allocator { ++ #[global_allocator] ++ static GLOBAL: std::alloc::System = std::alloc::System; ++} ++ ++/// Module that provides global symbols that are needed both by `cpp_allocator` ++/// and `rust_allocator`. ++/// ++/// When `rustc` drives linking, then it will define the symbols below. But ++/// Chromium only uses `rustc` to link Rust-only executables (e.g. `build.rs` ++/// scripts) and otherwise uses a non-Rust linker. This is why we have to ++/// manually define a few symbols below. We define those symbols ++/// as "weak" symbols, so that Rust-provided symbols "win" in case where Rust ++/// actually does drive the linking. This hack works (not only for Chromium, ++/// but also for google3 and other projects), but isn't officially supported by ++/// `rustc`. ++/// ++/// TODO(https://crbug.com/410596442): Stop using internal features here. ++mod both_allocators { ++ /// As part of rustc's contract for using `#[global_allocator]` without ++ /// rustc-generated shims we must define this symbol, since we are opting in ++ /// to unstable functionality. See https://github.com/rust-lang/rust/issues/123015 ++ #[no_mangle] ++ #[linkage = "weak"] ++ static __rust_no_alloc_shim_is_unstable: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ static __rust_alloc_error_handler_should_panic: u8 = 0; ++ ++ // Mangle the symbol name as rustc expects. ++ #[rustc_std_internal_symbol] ++ #[allow(non_upper_case_globals)] ++ #[linkage = "weak"] ++ fn __rust_alloc_error_handler(_size: usize, _align: usize) { ++ // TODO(lukasza): Investigate if we can just call `std::process::abort()` here. ++ // (Not really _needed_, but it could simplify code a little bit.) ++ unsafe { ffi::alloc_error_handler_impl() } ++ } ++ ++ #[cxx::bridge(namespace = "rust_allocator_internal")] ++ mod ffi { ++ extern "C++" { ++ include!("build/rust/allocator/alloc_error_handler_impl.h"); ++ unsafe fn alloc_error_handler_impl(); ++ } ++ } ++} diff --git a/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni b/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni new file mode 100644 index 000000000000..a1590f727aa3 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_cargo__crate.gni @@ -0,0 +1,25 @@ +--- build/rust/cargo_crate.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/cargo_crate.gni +@@ -259,6 +259,12 @@ template("cargo_crate") { + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true + ++ # Don't depend on the chrome-specific #[global_allocator] crate from ++ # third-party code. This avoids some dependency cycle issues. The allocator ++ # crate will still be used if it exists anywhere in the dependency graph for ++ # a given linked artifact. ++ no_allocator_crate = true ++ + rustc_metadata = _rustc_metadata + + # TODO(crbug.com/40259764): don't default to true. This requires changes to +@@ -482,6 +488,9 @@ template("cargo_crate") { + + # Don't import the `chromium` crate into third-party code. + no_chromium_prelude = true ++ ++ # Build scripts do not need to link to chrome's allocator. ++ no_allocator_crate = true + + # The ${_build_script_name}_output target looks for the exe in this + # location. Due to how the Windows component build works, this has to diff --git a/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni b/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni new file mode 100644 index 000000000000..0dafc3819aa1 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_rust__macro.gni @@ -0,0 +1,12 @@ +--- build/rust/rust_macro.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_macro.gni +@@ -16,6 +16,9 @@ template("rust_macro") { + forward_variables_from(invoker, TESTONLY_AND_VISIBILITY) + proc_macro_configs = invoker.configs + target_type = "rust_proc_macro" ++ ++ # Macros are loaded by rustc and shouldn't use chrome's allocation routines. ++ no_allocator_crate = true + } + } + diff --git a/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni b/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni new file mode 100644 index 000000000000..f4ad6f04fc45 --- /dev/null +++ b/www/ungoogled-chromium/files/patch-build_rust_rust__target.gni @@ -0,0 +1,13 @@ +--- build/rust/rust_target.gni.orig 2025-05-20 09:16:26 UTC ++++ build/rust/rust_target.gni +@@ -339,6 +339,10 @@ template("rust_target") { + _rust_deps += [ "//build/rust/std" ] + } + ++ if (!defined(invoker.no_allocator_crate) || !invoker.no_allocator_crate) { ++ _rust_deps += [ "//build/rust/allocator" ] ++ } ++ + if (_build_unit_tests) { + _unit_test_target = "${_target_name}_unittests" + if (defined(invoker.unit_test_target)) { diff --git a/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn b/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn index 0a5335d58d48..c6c2801bd47d 100644 --- a/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn +++ b/www/ungoogled-chromium/files/patch-build_rust_std_BUILD.gn @@ -1,6 +1,58 @@ ---- build/rust/std/BUILD.gn.orig 2025-04-05 13:54:50 UTC +--- build/rust/std/BUILD.gn.orig 2025-05-20 09:16:26 UTC +++ build/rust/std/BUILD.gn -@@ -89,13 +89,20 @@ if (toolchain_has_rust) { +@@ -15,51 +15,12 @@ + # allocator functions to PartitionAlloc when `use_partition_alloc_as_malloc` is + # true, so that Rust and C++ use the same allocator backend. + +-import("//build/buildflag_header.gni") + import("//build/config/compiler/compiler.gni") + import("//build/config/coverage/coverage.gni") + import("//build/config/rust.gni") + import("//build/config/sanitizers/sanitizers.gni") + +-rust_allocator_uses_partition_alloc = false +-if (build_with_chromium) { +- import("//base/allocator/partition_allocator/partition_alloc.gni") +- rust_allocator_uses_partition_alloc = use_partition_alloc_as_malloc +-} +- +-buildflag_header("buildflags") { +- header = "buildflags.h" +- flags = [ +- "RUST_ALLOCATOR_USES_PARTITION_ALLOC=$rust_allocator_uses_partition_alloc", +- ] +- visibility = [ ":*" ] +-} +- + if (toolchain_has_rust) { +- # If clang performs the link step, we need to provide the allocator symbols +- # that are normally injected by rustc during linking. +- # +- # We also "happen to" use this to redirect allocations to PartitionAlloc, +- # though that would be better done through a #[global_allocator] crate (see +- # above). +- source_set("remap_alloc") { +- public_deps = [] +- if (rust_allocator_uses_partition_alloc) { +- public_deps += [ "//base/allocator/partition_allocator:partition_alloc" ] +- } +- deps = [ ":buildflags" ] +- sources = [ +- # `alias.*`, `compiler_specific.h`, and `immediate_crash.*` have been +- # copied from `//base`. +- # TODO(crbug.com/40279749): Avoid duplication / reuse code. +- "alias.cc", +- "alias.h", +- "compiler_specific.h", +- "immediate_crash.h", +- "remap_alloc.cc", +- ] +- } +- + # List of Rust stdlib rlibs which are present in the official Rust toolchain + # we are using from the Android team. This is usually a version or two behind + # nightly. Generally this matches the toolchain we build ourselves, but if +@@ -89,13 +50,20 @@ if (toolchain_has_rust) { # These are no longer present in the Windows toolchain. stdlib_files += [ "addr2line", @@ -22,7 +74,7 @@ } if (toolchain_for_rust_host_build_tools) { -@@ -115,7 +122,6 @@ if (toolchain_has_rust) { +@@ -115,7 +83,6 @@ if (toolchain_has_rust) { # don't need to pass to the C++ linker because they're used for specialized # purposes. skip_stdlib_files = [ @@ -30,3 +82,25 @@ "rustc_std_workspace_alloc", "rustc_std_workspace_core", "rustc_std_workspace_std", +@@ -269,8 +236,6 @@ if (toolchain_has_rust) { + foreach(libname, stdlib_files + skip_stdlib_files) { + deps += [ "rules:$libname" ] + } +- +- public_deps = [ ":remap_alloc" ] + } + } else { + action("find_stdlib") { +@@ -396,12 +361,6 @@ if (toolchain_has_rust) { + ":stdlib_public_dependent_libs", + ] + deps = [ ":prebuilt_rustc_copy_to_sysroot" ] +- +- # The host builds tools toolchain supports Rust only and does not use +- # the allocator remapping to point it to PartitionAlloc. +- if (!toolchain_for_rust_host_build_tools) { +- deps += [ ":remap_alloc" ] +- } + } + } + } |