Commit 4d46202e authored by Yuta Hijikata's avatar Yuta Hijikata Committed by Commit Bot

LaCrOS: Replace defined(OS_CHROMEOS) with BUILDFLAG(IS_CHROMEOS_ASH)

The change is mostly mechanical replacing defined(OS_CHROMEOS) with
BUILDFLAG(IS_CHROMEOS_ASH) and GN variable is_chromeos with is_ash
with some special cases (For those cases please refer to
http://go/lacros-macros).

The patch is made in preparation to switching lacros build from
target_os=linux to target_os=chromeos. This will prevent lacros from
changing behaviour after the switch.

Bug: 1052397
Change-Id: Ifc027928982c4e6e9272e0d149fd19410c5c61de
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2494603
Commit-Queue: Yuta Hijikata <ythjkt@chromium.org>
Reviewed-by: default avatarChris Palmer <palmer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#826719}
parent 1a24cae2
......@@ -95,6 +95,7 @@ if (is_component_build) {
]
deps = [
"//base",
"//build:chromeos_buildflags",
"//media:media_buildflags",
"//sandbox:sandbox_buildflags",
"//sandbox/linux:sandbox",
......
......@@ -110,6 +110,7 @@ source_set("sandbox_linux_unittests_sources") {
":sandbox_linux_test_utils",
"//base",
"//base/third_party/dynamic_annotations",
"//build:chromeos_buildflags",
"//testing/gtest",
]
......@@ -250,6 +251,7 @@ component("seccomp_bpf") {
":sandbox_services",
"//base",
"//base/third_party/dynamic_annotations",
"//build:chromeos_buildflags",
"//sandbox:sandbox_buildflags",
]
......
......@@ -32,6 +32,7 @@
#include "base/system/sys_info.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/bpf_dsl/errorcode.h"
#include "sandbox/linux/bpf_dsl/linux_syscall_ranges.h"
......@@ -2143,7 +2144,7 @@ SANDBOX_TEST(SandboxBPF, Tsync) {
const bool supports_multi_threaded = SandboxBPF::SupportsSeccompSandbox(
SandboxBPF::SeccompLevel::MULTI_THREADED);
// On Chrome OS tsync is mandatory.
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
if (base::SysInfo::IsRunningOnChromeOS()) {
BPF_ASSERT_EQ(true, supports_multi_threaded);
}
......
......@@ -30,6 +30,7 @@
#include "base/posix/eintr_wrapper.h"
#include "base/threading/thread.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
#include "sandbox/linux/seccomp-bpf/bpf_tests.h"
#include "sandbox/linux/seccomp-bpf/sandbox_bpf.h"
......@@ -307,7 +308,7 @@ TEST_BASELINE_SIGSYS(__NR_inotify_init)
TEST_BASELINE_SIGSYS(__NR_vserver)
#endif
#if defined(LIBC_GLIBC) && !defined(OS_CHROMEOS)
#if defined(LIBC_GLIBC) && !BUILDFLAG(IS_CHROMEOS_ASH)
BPF_TEST_C(BaselinePolicy, FutexEINVAL, BaselinePolicy) {
int ops[] = {
FUTEX_CMP_REQUEUE_PI, FUTEX_CMP_REQUEUE_PI_PRIVATE,
......@@ -344,7 +345,7 @@ BPF_DEATH_TEST_C(BaselinePolicy,
syscall(__NR_futex, nullptr, FUTEX_UNLOCK_PI_PRIVATE, 0, nullptr, nullptr, 0);
_exit(1);
}
#endif // defined(LIBC_GLIBC) && !defined(OS_CHROMEOS)
#endif // defined(LIBC_GLIBC) && !BUILDFLAG(IS_CHROMEOS_ASH)
BPF_TEST_C(BaselinePolicy, PrctlDumpable, BaselinePolicy) {
const int is_dumpable = prctl(PR_GET_DUMPABLE, 0, 0, 0, 0);
......
......@@ -23,6 +23,7 @@
#include "base/notreached.h"
#include "base/synchronization/synchronization_buildflags.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/bpf_dsl/seccomp_macros.h"
#include "sandbox/linux/seccomp-bpf-helpers/sigsys_handlers.h"
......@@ -37,8 +38,9 @@
#if !defined(OS_NACL_NONSFI)
#include <sys/ioctl.h>
#include <sys/ptrace.h>
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && !defined(__arm__) && \
!defined(__aarch64__) && !defined(PTRACE_GET_THREAD_AREA)
#if (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) && \
!defined(__arm__) && !defined(__aarch64__) && \
!defined(PTRACE_GET_THREAD_AREA)
// Also include asm/ptrace-abi.h since ptrace.h in older libc (for instance
// the one in Ubuntu 16.04 LTS) is missing PTRACE_GET_THREAD_AREA.
// asm/ptrace-abi.h doesn't exist on arm32 and PTRACE_GET_THREAD_AREA isn't
......@@ -101,7 +103,7 @@ inline bool IsArchitectureMips() {
// to allow those futex(2) calls to fail with EINVAL, instead of crashing the
// process. See crbug.com/598471.
inline bool IsBuggyGlibcSemPost() {
#if defined(LIBC_GLIBC) && !defined(OS_CHROMEOS)
#if defined(LIBC_GLIBC) && !BUILDFLAG(IS_CHROMEOS_ASH)
return true;
#else
return false;
......
......@@ -4,6 +4,7 @@
import("//build/buildflag_header.gni")
import("//build/config/chromecast_build.gni")
import("//build/config/chromeos/ui_mode.gni")
import("//build/config/sanitizers/sanitizers.gni")
import("//testing/test.gni")
......@@ -24,6 +25,7 @@ component("policy") {
deps = [
":sanitizer_buildflags",
"//base",
"//build:chromeos_buildflags",
"//sandbox:common",
]
public_deps = []
......@@ -76,7 +78,7 @@ component("policy") {
"//sandbox/linux:suid_sandbox_client",
]
}
if (is_chromeos) {
if (is_chromeos_ash) {
sources += [
"linux/bpf_ime_policy_linux.cc",
"linux/bpf_ime_policy_linux.h",
......
......@@ -5,6 +5,7 @@
#include "sandbox/policy/features.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
namespace sandbox {
namespace policy {
......@@ -36,7 +37,7 @@ const base::Feature kGpuLPAC{"GpuLPAC", base::FEATURE_ENABLED_BY_DEFAULT};
const base::Feature kXRSandbox{"XRSandbox", base::FEATURE_ENABLED_BY_DEFAULT};
#endif // !defined(OS_ANDROID)
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
// Controls whether the Spectre variant 2 mitigation is enabled. We use a USE
// flag on some Chrome OS boards to disable the mitigation by disabling this
// feature in exchange for system performance.
......@@ -48,7 +49,7 @@ const base::Feature kSpectreVariant2Mitigation{
// enabled.
const base::Feature kForceSpectreVariant2Mitigation{
"ForceSpectreVariant2Mitigation", base::FEATURE_DISABLED_BY_DEFAULT};
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
} // namespace features
} // namespace policy
......
......@@ -10,6 +10,7 @@
#include "base/feature_list.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/policy/export.h"
namespace sandbox {
......@@ -30,11 +31,11 @@ SANDBOX_POLICY_EXPORT extern const base::Feature kGpuLPAC;
SANDBOX_POLICY_EXPORT extern const base::Feature kXRSandbox;
#endif // !defined(OS_ANDROID)
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
SANDBOX_POLICY_EXPORT extern const base::Feature kSpectreVariant2Mitigation;
SANDBOX_POLICY_EXPORT extern const base::Feature
kForceSpectreVariant2Mitigation;
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
} // namespace features
} // namespace policy
......
......@@ -13,6 +13,7 @@
#include "base/compiler_specific.h"
#include "base/macros.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/seccomp-bpf-helpers/syscall_parameters_restrictions.h"
#include "sandbox/linux/seccomp-bpf-helpers/syscall_sets.h"
......@@ -41,10 +42,10 @@ ResultExpr GpuProcessPolicy::EvaluateSyscall(int sysno) const {
switch (sysno) {
case __NR_kcmp:
return Error(ENOSYS);
#if !defined(OS_CHROMEOS)
#if !BUILDFLAG(IS_CHROMEOS_ASH)
case __NR_fallocate:
return Allow();
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
case __NR_fcntl: {
// The Nvidia driver uses flags not in the baseline policy
// fcntl(fd, F_ADD_SEALS, F_SEAL_SEAL | F_SEAL_SHRINK | F_SEAL_GROW)
......@@ -95,7 +96,7 @@ ResultExpr GpuProcessPolicy::EvaluateSyscall(int sysno) const {
if (SyscallSets::IsEventFd(sysno))
return Allow();
#if defined(OS_LINUX) && !defined(OS_CHROMEOS) && defined(USE_X11)
#if (defined(OS_LINUX) || BUILDFLAG(IS_CHROMEOS_LACROS)) && defined(USE_X11)
if (SyscallSets::IsSystemVSharedMemory(sysno))
return Allow();
#endif
......
......@@ -18,6 +18,7 @@
#include "base/macros.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/linux/bpf_dsl/bpf_dsl.h"
#include "sandbox/linux/bpf_dsl/trap_registry.h"
#include "sandbox/policy/sandbox_type.h"
......@@ -52,11 +53,11 @@
#include "sandbox/policy/chromecast_sandbox_allowlist_buildflags.h"
#endif // !defined(OS_NACL_NONSFI)
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "sandbox/policy/features.h"
#include "sandbox/policy/linux/bpf_ime_policy_linux.h"
#include "sandbox/policy/linux/bpf_tts_policy_linux.h"
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
using sandbox::bpf_dsl::Allow;
using sandbox::bpf_dsl::ResultExpr;
......@@ -83,7 +84,7 @@ namespace {
// in its dependencies. Make sure to not link things that are not needed.
#if !defined(IN_NACL_HELPER)
inline bool IsChromeOS() {
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
return true;
#else
return false;
......@@ -182,12 +183,12 @@ std::unique_ptr<BPFBasePolicy> SandboxSeccompBPF::PolicyForSandboxType(
return std::make_unique<SharingServiceProcessPolicy>();
case SandboxType::kSpeechRecognition:
return std::make_unique<SpeechRecognitionProcessPolicy>();
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kIme:
return std::make_unique<ImeProcessPolicy>();
case SandboxType::kTts:
return std::make_unique<TtsProcessPolicy>();
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kZygoteIntermediateSandbox:
case SandboxType::kNoSandbox:
case SandboxType::kVideoCapture:
......@@ -228,10 +229,10 @@ void SandboxSeccompBPF::RunSandboxSanityChecks(
CHECK_EQ(EPERM, errno);
#endif // !defined(NDEBUG)
} break;
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kIme:
case SandboxType::kTts:
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kAudio:
case SandboxType::kSharingService:
case SandboxType::kSpeechRecognition:
......@@ -261,12 +262,12 @@ bool SandboxSeccompBPF::StartSandboxWithExternalPolicy(
SandboxBPF sandbox(std::move(policy));
sandbox.SetProcFd(std::move(proc_fd));
bool enable_ibpb = true;
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
enable_ibpb =
base::FeatureList::IsEnabled(
features::kForceSpectreVariant2Mitigation) ||
base::FeatureList::IsEnabled(features::kSpectreVariant2Mitigation);
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
CHECK(sandbox.StartSandbox(seccomp_level, enable_ibpb));
return true;
}
......
......@@ -10,6 +10,7 @@
#include "base/feature_list.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/policy/features.h"
#include "sandbox/policy/switches.h"
......@@ -57,7 +58,7 @@ bool IsUnsandboxedSandboxType(SandboxType sandbox_type) {
#if defined(OS_MAC)
case SandboxType::kNaClLoader:
#endif
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kIme:
case SandboxType::kTts:
#endif
......@@ -122,10 +123,10 @@ void SetCommandLineFlagsForSandboxType(base::CommandLine* command_line,
case SandboxType::kIconReader:
case SandboxType::kMediaFoundationCdm:
#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kIme:
case SandboxType::kTts:
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if !defined(OS_MAC)
case SandboxType::kSharingService:
#endif
......@@ -246,12 +247,12 @@ std::string StringFromUtilitySandboxType(SandboxType sandbox_type) {
case SandboxType::kMediaFoundationCdm:
return switches::kMediaFoundationCdmSandbox;
#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
case SandboxType::kIme:
return switches::kImeSandbox;
case SandboxType::kTts:
return switches::kTtsSandbox;
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// The following are not utility processes so should not occur.
case SandboxType::kRenderer:
case SandboxType::kGpu:
......@@ -308,12 +309,12 @@ SandboxType UtilitySandboxTypeFromString(const std::string& sandbox_string) {
return SandboxType::kSpeechRecognition;
if (sandbox_string == switches::kVideoCaptureSandbox)
return SandboxType::kVideoCapture;
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
if (sandbox_string == switches::kImeSandbox)
return SandboxType::kIme;
if (sandbox_string == switches::kTtsSandbox)
return SandboxType::kTts;
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
return SandboxType::kUtility;
}
......
......@@ -9,6 +9,7 @@
#include "base/command_line.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/policy/export.h"
namespace sandbox {
......@@ -74,11 +75,11 @@ enum class SandboxType {
// The audio service process.
kAudio,
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
kIme,
// Text-to-speech.
kTts,
#endif // defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
// Indicates that a process is a zygote and will get a real sandbox later.
......
......@@ -5,6 +5,7 @@
#include "sandbox/policy/switches.h"
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#if defined(OS_WIN)
#include "base/command_line.h"
......@@ -41,10 +42,10 @@ const char kIconReaderSandbox[] = "icon_reader";
const char kMediaFoundationCdmSandbox[] = "mf_cdm";
#endif // OS_WIN
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
const char kImeSandbox[] = "ime";
const char kTtsSandbox[] = "tts";
#endif // OS_CHROMEOS
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// Flags owned by the service manager sandbox.
......
......@@ -6,6 +6,7 @@
#define SANDBOX_POLICY_SWITCHES_H_
#include "build/build_config.h"
#include "build/chromeos_buildflags.h"
#include "sandbox/policy/export.h"
namespace sandbox {
......@@ -38,10 +39,10 @@ SANDBOX_POLICY_EXPORT extern const char kIconReaderSandbox[];
SANDBOX_POLICY_EXPORT extern const char kMediaFoundationCdmSandbox[];
#endif // OS_WIN
#if defined(OS_CHROMEOS)
#if BUILDFLAG(IS_CHROMEOS_ASH)
SANDBOX_POLICY_EXPORT extern const char kImeSandbox[];
SANDBOX_POLICY_EXPORT extern const char kTtsSandbox[];
#endif // OS_CHROMEOS
#endif // BUILDFLAG(IS_CHROMEOS_ASH)
// Flags owned by the service manager sandbox.
SANDBOX_POLICY_EXPORT extern const char kAllowNoSandboxJob[];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment