0

gin: Use BUILDFLAG for OS checking

Use BUILDFLAG(IS_XXX) instead of defined(OS_XXX).

Generated by `os_buildflag_migration.py` (https://crrev.com/c/3311983).

R=thakis@chromium.org

Bug: 1234043
Test: No functionality change
Change-Id: I992993b030d052e6821486adbb7f8653dd363bd8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3373825
Reviewed-by: Nico Weber <thakis@chromium.org>
Commit-Queue: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Cr-Commit-Position: refs/heads/main@{#956756}
This commit is contained in:
Xiaohan Wang
2022-01-08 01:20:46 +00:00
committed by Chromium LUCI CQ
parent 2fdc434c32
commit c696a4748e
9 changed files with 30 additions and 29 deletions

@@ -12,13 +12,13 @@
#include "build/build_config.h" #include "build/build_config.h"
#include "gin/per_isolate_data.h" #include "gin/per_isolate_data.h"
#if defined(OS_POSIX) #if BUILDFLAG(IS_POSIX)
#include <sys/mman.h> #include <sys/mman.h>
#ifndef MAP_ANONYMOUS #ifndef MAP_ANONYMOUS
#define MAP_ANONYMOUS MAP_ANON #define MAP_ANONYMOUS MAP_ANON
#endif #endif
#endif // defined(OS_POSIX) #endif // BUILDFLAG(IS_POSIX)
namespace gin { namespace gin {

@@ -6,7 +6,7 @@
#include "build/build_config.h" #include "build/build_config.h"
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
#include "v8/include/v8-initialization.h" #include "v8/include/v8-initialization.h"
#endif #endif
@@ -21,7 +21,7 @@ void Debug::SetJitCodeEventHandler(v8::JitCodeEventHandler event_handler) {
g_jit_code_event_handler = event_handler; g_jit_code_event_handler = event_handler;
} }
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// static // static
void Debug::SetUnhandledExceptionCallback( void Debug::SetUnhandledExceptionCallback(
v8::UnhandledExceptionCallback callback) { v8::UnhandledExceptionCallback callback) {

@@ -23,7 +23,7 @@ class GIN_EXPORT Debug {
*/ */
static void SetJitCodeEventHandler(v8::JitCodeEventHandler event_handler); static void SetJitCodeEventHandler(v8::JitCodeEventHandler event_handler);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
/* Sets a callback that is invoked for exceptions that arise in V8-generated /* Sets a callback that is invoked for exceptions that arise in V8-generated
* code (jitted code or embedded builtins). * code (jitted code or embedded builtins).
*/ */

@@ -7,12 +7,13 @@
#include "base/path_service.h" #include "base/path_service.h"
#include "base/process/launch.h" #include "base/process/launch.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
base::FilePath GinShellPath() { base::FilePath GinShellPath() {
base::FilePath dir; base::FilePath dir;
base::PathService::Get(base::DIR_EXE, &dir); base::PathService::Get(base::DIR_EXE, &dir);
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
return dir.AppendASCII("gin_shell.exe"); return dir.AppendASCII("gin_shell.exe");
#else #else
return dir.AppendASCII("gin_shell"); return dir.AppendASCII("gin_shell");

@@ -39,9 +39,9 @@
#include "v8/include/v8-snapshot.h" #include "v8/include/v8-snapshot.h"
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
#include "base/android/apk_assets.h" #include "base/android/apk_assets.h"
#elif defined(OS_MAC) #elif BUILDFLAG(IS_MAC)
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#endif #endif
#endif // V8_USE_EXTERNAL_STARTUP_DATA #endif // V8_USE_EXTERNAL_STARTUP_DATA
@@ -75,7 +75,7 @@ void GetMappedFileData(base::MemoryMappedFile* mapped_file,
#if defined(V8_USE_EXTERNAL_STARTUP_DATA) #if defined(V8_USE_EXTERNAL_STARTUP_DATA)
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
const char kV8ContextSnapshotFileName64[] = "v8_context_snapshot_64.bin"; const char kV8ContextSnapshotFileName64[] = "v8_context_snapshot_64.bin";
const char kV8ContextSnapshotFileName32[] = "v8_context_snapshot_32.bin"; const char kV8ContextSnapshotFileName32[] = "v8_context_snapshot_32.bin";
const char kSnapshotFileName64[] = "snapshot_blob_64.bin"; const char kSnapshotFileName64[] = "snapshot_blob_64.bin";
@@ -89,12 +89,12 @@ const char kSnapshotFileName32[] = "snapshot_blob_32.bin";
#define kSnapshotFileName kSnapshotFileName32 #define kSnapshotFileName kSnapshotFileName32
#endif #endif
#else // defined(OS_ANDROID) #else // BUILDFLAG(IS_ANDROID)
#if defined(USE_V8_CONTEXT_SNAPSHOT) #if defined(USE_V8_CONTEXT_SNAPSHOT)
const char kV8ContextSnapshotFileName[] = V8_CONTEXT_SNAPSHOT_FILENAME; const char kV8ContextSnapshotFileName[] = V8_CONTEXT_SNAPSHOT_FILENAME;
#endif #endif
const char kSnapshotFileName[] = "snapshot_blob.bin"; const char kSnapshotFileName[] = "snapshot_blob.bin";
#endif // defined(OS_ANDROID) #endif // BUILDFLAG(IS_ANDROID)
const char* GetSnapshotFileName(const V8SnapshotFileType file_type) { const char* GetSnapshotFileName(const V8SnapshotFileType file_type) {
switch (file_type) { switch (file_type) {
@@ -113,11 +113,11 @@ const char* GetSnapshotFileName(const V8SnapshotFileType file_type) {
} }
void GetV8FilePath(const char* file_name, base::FilePath* path_out) { void GetV8FilePath(const char* file_name, base::FilePath* path_out) {
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
// This is the path within the .apk. // This is the path within the .apk.
*path_out = *path_out =
base::FilePath(FILE_PATH_LITERAL("assets")).AppendASCII(file_name); base::FilePath(FILE_PATH_LITERAL("assets")).AppendASCII(file_name);
#elif defined(OS_MAC) #elif BUILDFLAG(IS_MAC)
base::ScopedCFTypeRef<CFStringRef> bundle_resource( base::ScopedCFTypeRef<CFStringRef> bundle_resource(
base::SysUTF8ToCFStringRef(file_name)); base::SysUTF8ToCFStringRef(file_name));
*path_out = base::mac::PathForFrameworkBundleResource(bundle_resource); *path_out = base::mac::PathForFrameworkBundleResource(bundle_resource);
@@ -158,7 +158,7 @@ base::File OpenV8File(const char* file_name,
base::FilePath path; base::FilePath path;
GetV8FilePath(file_name, &path); GetV8FilePath(file_name, &path);
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
base::File file(base::android::OpenApkAsset(path.value(), region_out)); base::File file(base::android::OpenApkAsset(path.value(), region_out));
OpenV8FileResult result = file.IsValid() ? OpenV8FileResult::OPENED OpenV8FileResult result = file.IsValid() ? OpenV8FileResult::OPENED
: OpenV8FileResult::FAILED_OTHER; : OpenV8FileResult::FAILED_OTHER;
@@ -189,7 +189,7 @@ base::File OpenV8File(const char* file_name,
base::PlatformThread::Sleep(base::Milliseconds(kOpenRetryDelayMillis)); base::PlatformThread::Sleep(base::Milliseconds(kOpenRetryDelayMillis));
} }
} }
#endif // defined(OS_ANDROID) #endif // BUILDFLAG(IS_ANDROID)
UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", result, UMA_HISTOGRAM_ENUMERATION("V8.Initializer.OpenV8File.Result", result,
OpenV8FileResult::MAX_VALUE); OpenV8FileResult::MAX_VALUE);
@@ -428,7 +428,7 @@ void V8Initializer::Initialize(IsolateHolder::ScriptMode mode,
const size_t min_pool_size = const size_t min_pool_size =
base::internal::PartitionAddressSpace::ConfigurablePoolMinSize(); base::internal::PartitionAddressSpace::ConfigurablePoolMinSize();
size_t pool_size = max_pool_size; size_t pool_size = max_pool_size;
#if defined(OS_WIN) #if BUILDFLAG(IS_WIN)
// On Windows prior to 8.1 we allocate a smaller Pool since reserving // On Windows prior to 8.1 we allocate a smaller Pool since reserving
// virtual memory is expensive on these OSes. // virtual memory is expensive on these OSes.
if (base::win::GetVersion() < base::win::Version::WIN8_1) { if (base::win::GetVersion() < base::win::Version::WIN8_1) {
@@ -519,7 +519,7 @@ void V8Initializer::LoadV8SnapshotFromFile(
} }
} }
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
// static // static
base::FilePath V8Initializer::GetSnapshotFilePath( base::FilePath V8Initializer::GetSnapshotFilePath(
bool abi_32_bit, bool abi_32_bit,
@@ -540,7 +540,7 @@ base::FilePath V8Initializer::GetSnapshotFilePath(
GetV8FilePath(filename, &path); GetV8FilePath(filename, &path);
return path; return path;
} }
#endif // defined(OS_ANDROID) #endif // BUILDFLAG(IS_ANDROID)
V8SnapshotFileType GetLoadedSnapshotFileType() { V8SnapshotFileType GetLoadedSnapshotFileType() {
DCHECK(g_snapshot_file_type.has_value()); DCHECK(g_snapshot_file_type.has_value());

@@ -52,7 +52,7 @@ class GIN_EXPORT V8Initializer {
base::MemoryMappedFile::Region* snapshot_file_region, base::MemoryMappedFile::Region* snapshot_file_region,
V8SnapshotFileType snapshot_file_type); V8SnapshotFileType snapshot_file_type);
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
static base::FilePath GetSnapshotFilePath( static base::FilePath GetSnapshotFilePath(
bool abi_32_bit, bool abi_32_bit,
V8SnapshotFileType snapshot_file_type); V8SnapshotFileType snapshot_file_type);

@@ -127,7 +127,7 @@ class TimeClamper {
public: public:
// As site isolation is enabled on desktop platforms, we can safely provide // As site isolation is enabled on desktop platforms, we can safely provide
// more timing resolution. Jittering is still enabled everywhere. // more timing resolution. Jittering is still enabled everywhere.
#if defined(OS_ANDROID) #if BUILDFLAG(IS_ANDROID)
static constexpr double kResolutionSeconds = 100e-6; static constexpr double kResolutionSeconds = 100e-6;
#else #else
static constexpr double kResolutionSeconds = 5e-6; static constexpr double kResolutionSeconds = 5e-6;
@@ -371,7 +371,7 @@ PageAllocator* V8Platform::GetPageAllocator() {
void V8Platform::OnCriticalMemoryPressure() { void V8Platform::OnCriticalMemoryPressure() {
// We only have a reservation on 32-bit Windows systems. // We only have a reservation on 32-bit Windows systems.
// TODO(bbudge) Make the #if's in BlinkInitializer match. // TODO(bbudge) Make the #if's in BlinkInitializer match.
#if defined(OS_WIN) && defined(ARCH_CPU_32_BITS) #if BUILDFLAG(IS_WIN) && defined(ARCH_CPU_32_BITS)
base::ReleaseReservation(); base::ReleaseReservation();
#endif #endif
} }

@@ -3,12 +3,12 @@
// found in the LICENSE file. // found in the LICENSE file.
#include "v8_platform_page_allocator.h" #include "v8_platform_page_allocator.h"
#include "base/allocator/partition_allocator/address_space_randomization.h" #include "base/allocator/partition_allocator/address_space_randomization.h"
#include "base/allocator/partition_allocator/page_allocator_constants.h" #include "base/allocator/partition_allocator/page_allocator_constants.h"
#include "base/allocator/partition_allocator/random.h" #include "base/allocator/partition_allocator/random.h"
#include "base/check_op.h" #include "base/check_op.h"
#include "base/cpu.h" #include "base/cpu.h"
#include "build/build_config.h"
namespace { namespace {
@@ -85,10 +85,10 @@ bool PageAllocator::ReleasePages(void* address,
DCHECK_LT(new_length, length); DCHECK_LT(new_length, length);
uint8_t* release_base = reinterpret_cast<uint8_t*>(address) + new_length; uint8_t* release_base = reinterpret_cast<uint8_t*>(address) + new_length;
size_t release_size = length - new_length; size_t release_size = length - new_length;
#if defined(OS_POSIX) || defined(OS_FUCHSIA) #if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// On POSIX, we can unmap the trailing pages. // On POSIX, we can unmap the trailing pages.
base::FreePages(release_base, release_size); base::FreePages(release_base, release_size);
#elif defined(OS_WIN) #elif BUILDFLAG(IS_WIN)
// On Windows, we can only de-commit the trailing pages. FreePages() will // On Windows, we can only de-commit the trailing pages. FreePages() will
// still free all pages in the region including the released tail, so it's // still free all pages in the region including the released tail, so it's
// safe to just decommit the tail. // safe to just decommit the tail.

@@ -5,7 +5,7 @@
#include "gin/v8_platform_page_allocator.h" #include "gin/v8_platform_page_allocator.h"
#include "base/cpu.h" #include "base/cpu.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h" #include "testing/gtest/include/gtest/gtest.h"
// includes for Branch Target Instruction tests // includes for Branch Target Instruction tests
@@ -14,7 +14,7 @@
#include "base/allocator/partition_allocator/arm_bti_test_functions.h" #include "base/allocator/partition_allocator/arm_bti_test_functions.h"
#include "base/allocator/partition_allocator/page_allocator_constants.h" #include "base/allocator/partition_allocator/page_allocator_constants.h"
#if defined(OS_POSIX) #if BUILDFLAG(IS_POSIX)
#include <signal.h> #include <signal.h>
#include "testing/gtest/include/gtest/gtest-death-test.h" #include "testing/gtest/include/gtest/gtest-death-test.h"
#endif #endif
@@ -98,11 +98,11 @@ TEST(V8PlatformPageAllocatorBTITest, VerifyReadExecutePagesAreProtected) {
// the actual CPU we are running on. The code that were are trying to execute // the actual CPU we are running on. The code that were are trying to execute
// is assembly code and always has BTI enabled. // is assembly code and always has BTI enabled.
if (base::CPU::GetInstanceNoAllocation().has_bti()) { if (base::CPU::GetInstanceNoAllocation().has_bti()) {
#if defined(OS_POSIX) // signal handling is available on POSIX compliant #if BUILDFLAG(IS_POSIX) // signal handling is available on POSIX compliant
// systems only // systems only
EXPECT_EXIT({ bti_invalid_fn(15); }, testing::KilledBySignal(SIGILL), EXPECT_EXIT({ bti_invalid_fn(15); }, testing::KilledBySignal(SIGILL),
""); // Should crash with SIGILL. ""); // Should crash with SIGILL.
#endif // defined(OS_POSIX) #endif // BUILDFLAG(IS_POSIX)
} else { } else {
EXPECT_EQ(bti_invalid_fn(15), 17); EXPECT_EQ(bti_invalid_fn(15), 17);
} }