Skip to content

Commit

Permalink
ipc: Use BUILDFLAG for OS checking
Browse files Browse the repository at this point in the history
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: I8e08170879c23cee36f8a5c51a45552396af63f2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3373961
Reviewed-by: Nico Weber <thakis@chromium.org>
Owners-Override: Nico Weber <thakis@chromium.org>
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Cr-Commit-Position: refs/heads/main@{#958148}
  • Loading branch information
xhwang-chromium authored and Chromium LUCI CQ committed Jan 12, 2022
1 parent d8143d7 commit ab909b3
Show file tree
Hide file tree
Showing 25 changed files with 153 additions and 142 deletions.
4 changes: 2 additions & 2 deletions ipc/ipc_channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include "mojo/public/cpp/bindings/scoped_interface_endpoint_handle.h"
#include "mojo/public/cpp/bindings/shared_remote.h"

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
#include <sys/types.h>
#endif

Expand Down Expand Up @@ -236,7 +236,7 @@ class COMPONENT_EXPORT(IPC) Channel : public Sender {
static std::string GenerateUniqueRandomChannelID();
#endif

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
// Sandboxed processes live in a PID namespace, so when sending the IPC hello
// message from client to server we need to send the PID from the global
// PID namespace.
Expand Down
4 changes: 2 additions & 2 deletions ipc/ipc_channel_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace IPC {

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

namespace {
int g_global_pid = 0;
Expand All @@ -26,7 +26,7 @@ int Channel::GetGlobalPid() {
return g_global_pid;
}

#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

// static
std::unique_ptr<Channel> Channel::CreateClient(
Expand Down
8 changes: 4 additions & 4 deletions ipc/ipc_channel_mojo.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ class ThreadSafeChannelProxy : public mojo::ThreadSafeProxy {
};

base::ProcessId GetSelfPID() {
#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
if (int global_pid = Channel::GetGlobalPid())
return global_pid;
#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
#if defined(OS_NACL)
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)
#if BUILDFLAG(IS_NACL)
return -1;
#else
return base::GetCurrentProcId();
#endif // defined(OS_NACL)
#endif // BUILDFLAG(IS_NACL)
}

} // namespace
Expand Down
16 changes: 8 additions & 8 deletions ipc/ipc_channel_mojo_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/abseil-cpp/absl/types/optional.h"

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include "base/file_descriptor_posix.h"
#include "ipc/ipc_platform_file_attachment_posix.h"
#endif
Expand Down Expand Up @@ -415,7 +415,7 @@ class HandleSendingHelper {
GetSendingFileContent());
}

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
static base::FilePath GetSendingFilePath(const base::FilePath& dir_path) {
return dir_path.Append("ListenerThatExpectsFile.txt");
}
Expand Down Expand Up @@ -1486,7 +1486,7 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT_WITH_CUSTOM_FIXTURE(DropAssociatedRequest,
DestroyProxy();
}

#if !defined(OS_APPLE)
#if !BUILDFLAG(IS_APPLE)
// TODO(wez): On Mac we need to set up a MachPortBroker before we can transfer
// Mach ports (which underpin Sharedmemory on Mac) across IPC.

Expand Down Expand Up @@ -1610,9 +1610,9 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(

Close();
}
#endif // !defined(OS_APPLE)
#endif // !BUILDFLAG(IS_APPLE)

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

class ListenerThatExpectsFile : public TestListenerBase {
public:
Expand Down Expand Up @@ -1711,9 +1711,9 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(
Close();
}

#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

#if defined(OS_LINUX) || defined(OS_CHROMEOS)
#if BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

const base::ProcessId kMagicChildId = 54321;

Expand Down Expand Up @@ -1760,6 +1760,6 @@ DEFINE_IPC_CHANNEL_MOJO_TEST_CLIENT(IPCChannelMojoTestVerifyGlobalPidClient) {
Close();
}

#endif // defined(OS_LINUX) || defined(OS_CHROMEOS)
#endif // BUILDFLAG(IS_LINUX) || BUILDFLAG(IS_CHROMEOS)

} // namespace
4 changes: 2 additions & 2 deletions ipc/ipc_channel_proxy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -484,15 +484,15 @@ ChannelProxy::~ChannelProxy() {
void ChannelProxy::Init(const IPC::ChannelHandle& channel_handle,
Channel::Mode mode,
bool create_pipe_now) {
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// When we are creating a server on POSIX, we need its file descriptor
// to be created immediately so that it can be accessed and passed
// to other processes. Forcing it to be created immediately avoids
// race conditions that may otherwise arise.
if (mode & Channel::MODE_SERVER_FLAG) {
create_pipe_now = true;
}
#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
Init(
ChannelFactory::Create(channel_handle, mode, context_->ipc_task_runner()),
create_pipe_now);
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_fuzzing_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TEST(IPCMessageIntegrity, ReadVectorNegativeSize) {
EXPECT_FALSE(ReadParam(&m, &iter, &vec));
}

#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_ReadVectorTooLarge1 DISABLED_ReadVectorTooLarge1
#else
#define MAYBE_ReadVectorTooLarge1 ReadVectorTooLarge1
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_listener.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class COMPONENT_EXPORT(IPC) Listener {
const std::string& interface_name,
mojo::ScopedInterfaceEndpointHandle handle) {}

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// Called on the server side when a channel that listens for connections
// denies an attempt to connect.
virtual void OnChannelDenied() {}
Expand Down
10 changes: 6 additions & 4 deletions ipc/ipc_logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "ipc/ipc_logging.h"

#include "build/build_config.h"

#if BUILDFLAG(IPC_MESSAGE_LOG_ENABLED)
#define IPC_MESSAGE_MACROS_LOG_ENABLED
#endif
Expand All @@ -27,7 +29,7 @@
#include "ipc/ipc_sender.h"
#include "ipc/ipc_sync_message.h"

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
#include <unistd.h>
#endif

Expand All @@ -51,7 +53,7 @@ Logging::Logging()
sender_(nullptr),
main_thread_(base::ThreadTaskRunnerHandle::Get()),
consumer_(nullptr) {
#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
// getenv triggers an unsafe warning. Simply check how big of a buffer
// would be needed to fetch the value to see if the enviornment variable is
// set.
Expand All @@ -64,12 +66,12 @@ Logging::Logging()
if (requiredSize && !strncmp("color", buffer, 6))
enabled_color_ = true;
}
#else // !defined(OS_WIN)
#else // !BUILDFLAG(IS_WIN)
const char* ipc_logging = getenv("CHROME_IPC_LOGGING");
bool logging_env_var_set = (ipc_logging != NULL);
if (ipc_logging && !strcmp(ipc_logging, "color"))
enabled_color_ = true;
#endif //defined(OS_WIN)
#endif // BUILDFLAG(IS_WIN)
if (logging_env_var_set) {
enabled_ = true;
enabled_on_stderr_ = true;
Expand Down
8 changes: 5 additions & 3 deletions ipc/ipc_message.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include "ipc/ipc_message.h"

#include "build/build_config.h"

// ipc_message.h is a widely included header and its size can impact build time.
// Try not to raise this limit unless necessary. See
// https://chromium.googlesource.com/chromium/src/+/HEAD/docs/wmax_tokens.md
Expand All @@ -22,7 +24,7 @@
#include "ipc/ipc_message_attachment.h"
#include "ipc/ipc_message_attachment_set.h"

#if defined(OS_POSIX)
#if BUILDFLAG(IS_POSIX)
#include "base/file_descriptor_posix.h"
#include "ipc/ipc_platform_file_attachment_posix.h"
#endif
Expand Down Expand Up @@ -57,7 +59,7 @@ Message::~Message() = default;
Message::Message() : base::Pickle(sizeof(Header)) {
header()->routing = header()->type = 0;
header()->flags = GetRefNumUpper24();
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
header()->num_fds = 0;
header()->pad = 0;
#endif
Expand All @@ -70,7 +72,7 @@ Message::Message(int32_t routing_id, uint32_t type, PriorityValue priority)
header()->type = type;
DCHECK((priority & 0xffffff00) == 0);
header()->flags = priority | GetRefNumUpper24();
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
header()->num_fds = 0;
header()->pad = 0;
#endif
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message.h
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class IPC_MESSAGE_SUPPORT_EXPORT Message : public base::Pickle {
int32_t routing; // ID of the view that this message is destined for
uint32_t type; // specifies the user-defined message type
uint32_t flags; // specifies control flags for the message
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
uint16_t num_fds; // the number of descriptors included with this message
uint16_t pad; // explicitly initialize this to appease valgrind
#endif
Expand Down
33 changes: 17 additions & 16 deletions ipc/ipc_message_attachment.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,40 @@
#include "base/files/scoped_file.h"
#include "base/logging.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "ipc/ipc_mojo_handle_attachment.h"
#include "mojo/public/cpp/system/platform_handle.h"

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
#include <unistd.h>

#include "base/posix/eintr_wrapper.h"
#include "ipc/ipc_platform_file_attachment_posix.h"
#endif

#if defined(OS_MAC)
#if BUILDFLAG(IS_MAC)
#include "ipc/mach_port_attachment_mac.h"
#endif

#if defined(OS_WIN)
#if BUILDFLAG(IS_WIN)
#include "ipc/handle_attachment_win.h"
#endif

#if defined(OS_FUCHSIA)
#if BUILDFLAG(IS_FUCHSIA)
#include "ipc/handle_attachment_fuchsia.h"
#endif

namespace IPC {

namespace {

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
base::ScopedFD TakeOrDupFile(internal::PlatformFileAttachment* attachment) {
return attachment->Owns()
? base::ScopedFD(attachment->TakePlatformFile())
: base::ScopedFD(HANDLE_EINTR(dup(attachment->file())));
}
#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

} // namespace

Expand All @@ -52,7 +53,7 @@ mojo::ScopedHandle MessageAttachment::TakeMojoHandle() {
case Type::MOJO_HANDLE:
return static_cast<internal::MojoHandleAttachment*>(this)->TakeHandle();

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
case Type::PLATFORM_FILE: {
// We dup() the handles in IPC::Message to transmit.
// IPC::MessageAttachmentSet has intricate lifetime semantics for FDs, so
Expand All @@ -65,9 +66,9 @@ mojo::ScopedHandle MessageAttachment::TakeMojoHandle() {
}
return mojo::WrapPlatformFile(std::move(file));
}
#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

#if defined(OS_MAC)
#if BUILDFLAG(IS_MAC)
case Type::MACH_PORT: {
auto* attachment = static_cast<internal::MachPortAttachmentMac*>(this);
MojoPlatformHandle platform_handle = {
Expand All @@ -81,7 +82,7 @@ mojo::ScopedHandle MessageAttachment::TakeMojoHandle() {
attachment->reset_mach_port_ownership();
return mojo::MakeScopedHandle(mojo::Handle(wrapped_handle));
}
#elif defined(OS_FUCHSIA)
#elif BUILDFLAG(IS_FUCHSIA)
case Type::FUCHSIA_HANDLE: {
auto* attachment = static_cast<internal::HandleAttachmentFuchsia*>(this);
MojoPlatformHandle platform_handle = {
Expand All @@ -94,7 +95,7 @@ mojo::ScopedHandle MessageAttachment::TakeMojoHandle() {
}
return mojo::MakeScopedHandle(mojo::Handle(wrapped_handle));
}
#elif defined(OS_WIN)
#elif BUILDFLAG(IS_WIN)
case Type::WIN_HANDLE:
return mojo::WrapPlatformFile(base::win::ScopedHandle(
static_cast<internal::HandleAttachmentWin*>(this)->Take()));
Expand All @@ -119,31 +120,31 @@ scoped_refptr<MessageAttachment> MessageAttachment::CreateFromMojoHandle(
if (unwrap_result != MOJO_RESULT_OK)
return nullptr;

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
if (type == Type::PLATFORM_FILE) {
base::PlatformFile file = base::kInvalidPlatformFile;
if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FILE_DESCRIPTOR)
file = static_cast<base::PlatformFile>(platform_handle.value);
return new internal::PlatformFileAttachment(file);
}
#endif // defined(OS_POSIX) || defined(OS_FUCHSIA)
#endif // BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)

#if defined(OS_MAC)
#if BUILDFLAG(IS_MAC)
if (type == Type::MACH_PORT) {
mach_port_t mach_port = MACH_PORT_NULL;
if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_MACH_PORT)
mach_port = static_cast<mach_port_t>(platform_handle.value);
return new internal::MachPortAttachmentMac(
mach_port, internal::MachPortAttachmentMac::FROM_WIRE);
}
#elif defined(OS_FUCHSIA)
#elif BUILDFLAG(IS_FUCHSIA)
if (type == Type::FUCHSIA_HANDLE) {
zx::handle zx_handle;
if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_FUCHSIA_HANDLE)
zx_handle.reset(static_cast<zx_handle_t>(platform_handle.value));
return new internal::HandleAttachmentFuchsia(std::move(zx_handle));
}
#elif defined(OS_WIN)
#elif BUILDFLAG(IS_WIN)
if (type == Type::WIN_HANDLE) {
base::PlatformFile platform_file = base::kInvalidPlatformFile;
if (platform_handle.type == MOJO_PLATFORM_HANDLE_TYPE_WINDOWS_HANDLE) {
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message_attachment_set.cc
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ unsigned MessageAttachmentSet::size() const {
bool MessageAttachmentSet::AddAttachment(
scoped_refptr<MessageAttachment> attachment,
size_t* index) {
#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
if (attachment->GetType() == MessageAttachment::Type::PLATFORM_FILE &&
num_descriptors() == kMaxDescriptorsPerMessage) {
DLOG(WARNING) << "Cannot add file descriptor. MessageAttachmentSet full.";
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message_attachment_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class IPC_MESSAGE_SUPPORT_EXPORT MessageAttachmentSet
// auto-close.
void CommitAllDescriptors();

#if defined(OS_POSIX) || defined(OS_FUCHSIA)
#if BUILDFLAG(IS_POSIX) || BUILDFLAG(IS_FUCHSIA)
// This is the maximum number of descriptors per message. We need to know this
// because the control message kernel interface has to be given a buffer which
// is large enough to store all the descriptor numbers. Otherwise the kernel
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message_attachment_set_posix_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ TEST(MessageAttachmentSet, WalkWrongOrder) {
set->CommitAllDescriptors();
}

#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_DontClose DISABLED_DontClose
#else
#define MAYBE_DontClose DontClose
Expand Down
2 changes: 1 addition & 1 deletion ipc/ipc_message_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ TEST_F(IPCMessageParameterTest, EmptyDispatcherWithParam) {
EXPECT_TRUE(called_);
}

#if defined(OS_ANDROID)
#if BUILDFLAG(IS_ANDROID)
#define MAYBE_OneIntegerWithParam DISABLED_OneIntegerWithParam
#else
#define MAYBE_OneIntegerWithParam OneIntegerWithParam
Expand Down
Loading

0 comments on commit ab909b3

Please sign in to comment.