1 --- src/3rdparty/chromium/content/utility/utility_main.cc.orig	2025-08-15 18:30:00 UTC
2 +++ src/3rdparty/chromium/content/utility/utility_main.cc
3 @@ -38,18 +38,22 @@
4  #include "services/tracing/public/cpp/trace_startup.h"
5  #include "services/video_effects/public/cpp/buildflags.h"
6 
7 -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
8 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
9  #include "base/file_descriptor_store.h"
10  #include "base/files/file_util.h"
11  #include "base/pickle.h"
12  #include "content/child/sandboxed_process_thread_type_handler.h"
13 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD)
14  #include "content/common/gpu_pre_sandbox_hook_linux.h"
15 +#endif
16  #include "content/public/common/content_descriptor_keys.h"
17  #include "content/utility/speech/speech_recognition_sandbox_hook_linux.h"
18  #include "gpu/config/gpu_info_collector.h"
19  #include "media/gpu/sandbox/hardware_video_decoding_sandbox_hook_linux.h"
20  #include "media/gpu/sandbox/hardware_video_encoding_sandbox_hook_linux.h"
21 +#if !BUILDFLAG(IS_BSD)
22  #include "sandbox/policy/linux/sandbox_linux.h"
23 +#endif
24  #include "services/audio/audio_sandbox_hook_linux.h"
25  #include "services/network/network_sandbox_hook_linux.h"
26  #include "services/screen_ai/buildflags/buildflags.h"
27 @@ -68,7 +72,12 @@
28 
29  #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
30 
31 -#if BUILDFLAG(ENABLE_VIDEO_EFFECTS) && BUILDFLAG(IS_LINUX)
32 +#if BUILDFLAG(IS_BSD)
33 +#include "sandbox/policy/sandbox.h"
34 +#include "content/common/gpu_pre_sandbox_hook_bsd.h"
35 +#endif
36 +
37 +#if BUILDFLAG(ENABLE_VIDEO_EFFECTS) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD))
38  #include "services/video_effects/video_effects_sandbox_hook_linux.h"  // nogncheck
39  #endif  // BUILDFLAG(ENABLE_VIDEO_EFFECTS) && BUILDFLAG(IS_LINUX)
40 
41 @@ -103,7 +112,7 @@ sandbox::TargetServices* g_utility_target_services = n
42  sandbox::TargetServices* g_utility_target_services = nullptr;
43  #endif  // BUILDFLAG(IS_WIN)
44 
45 -#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
46 +#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD))
47  #include "components/services/on_device_translation/sandbox_hook.h"
48  #endif  // BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
49 
50 @@ -111,7 +120,7 @@ namespace {
51 
52  namespace {
53 
54 -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
55 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
56  std::vector<std::string> GetNetworkContextsParentDirectories() {
57    base::MemoryMappedFile::Region region;
58    base::ScopedFD read_pipe_fd = base::FileDescriptorStore::GetInstance().TakeFD(
59 @@ -251,7 +260,8 @@ int UtilityMain(MainFunctionParams parameters) {
60    }
61  #endif
62 
63 -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
64 +// XXX BSD
65 +#if (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)) && !BUILDFLAG(IS_BSD)
66    // Thread type delegate of the process should be registered before first
67    // thread type change in ChildProcess constructor. It also needs to be
68    // registered before the process has multiple threads, which may race with
69 @@ -259,7 +269,7 @@ int UtilityMain(MainFunctionParams parameters) {
70    SandboxedProcessThreadTypeHandler::Create();
71  #endif  // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
72 
73 -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
74 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
75    // Initializes the sandbox before any threads are created.
76    // TODO(jorgelo): move this after GTK initialization when we enable a strict
77    // Seccomp-BPF policy.
78 @@ -295,7 +305,7 @@ int UtilityMain(MainFunctionParams parameters) {
79            base::BindOnce(&speech::SpeechRecognitionPreSandboxHook);
80  #endif
81        break;
82 -#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && BUILDFLAG(IS_LINUX)
83 +#if BUILDFLAG(ENABLE_ON_DEVICE_TRANSLATION) && (BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD))
84      case sandbox::mojom::Sandbox::kOnDeviceTranslation:
85        pre_sandbox_hook = base::BindOnce(
86            &on_device_translation::OnDeviceTranslationSandboxHook);
87 @@ -311,13 +321,13 @@ int UtilityMain(MainFunctionParams parameters) {
88  #else
89        NOTREACHED();
90  #endif
91 -#if BUILDFLAG(IS_LINUX)
92 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_BSD)
93      case sandbox::mojom::Sandbox::kVideoEffects:
94        pre_sandbox_hook =
95            base::BindOnce(&video_effects::VideoEffectsPreSandboxHook);
96        break;
97  #endif  // BUILDFLAG(IS_LINUX)
98 -#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
99 +#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS) || BUILDFLAG(IS_BSD)
100      case sandbox::mojom::Sandbox::kHardwareVideoDecoding:
101        pre_sandbox_hook =
102            base::BindOnce(&media::HardwareVideoDecodingPreSandboxHook);
103 @@ -344,6 +354,7 @@ int UtilityMain(MainFunctionParams parameters) {
104      default:
105        break;
106    }
107 +#if !BUILDFLAG(IS_BSD)
108    if (!sandbox::policy::IsUnsandboxedSandboxType(sandbox_type) &&
109        (parameters.zygote_child || !pre_sandbox_hook.is_null())) {
110      sandbox_options.use_amd_specific_policies =
111 @@ -351,6 +362,11 @@ int UtilityMain(MainFunctionParams parameters) {
112      sandbox::policy::Sandbox::Initialize(
113          sandbox_type, std::move(pre_sandbox_hook), sandbox_options);
114    }
115 +#else
116 +  sandbox::policy::Sandbox::Initialize(
117 +      sandbox_type, std::move(pre_sandbox_hook),
118 +      sandbox::policy::SandboxLinux::Options());
119 +#endif
120 
121    // Start the HangWatcher now that the sandbox is engaged, if it hasn't
122    // already been started.
123