#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/core/channel_linux.h"
#include <fcntl.h>
#include <linux/futex.h>
#include <linux/memfd.h>
#include <sys/eventfd.h>
#include <sys/mman.h>
#include <sys/syscall.h>
#include <sys/utsname.h>
#include <unistd.h>
#include <algorithm>
#include <atomic>
#include <cstring>
#include <limits>
#include <memory>
#include "base/bits.h"
#include "base/files/scoped_file.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/location.h"
#include "base/logging.h"
#include "base/memory/page_size.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr_exclusion.h"
#include "base/memory/ref_counted.h"
#include "base/memory/shared_memory_security_policy.h"
#include "base/message_loop/message_pump_for_io.h"
#include "base/metrics/histogram_macros.h"
#include "base/posix/eintr_wrapper.h"
#include "base/system/sys_info.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_runner.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "mojo/buildflags.h"
#include "mojo/core/embedder/features.h"
#if BUILDFLAG(IS_ANDROID)
#include "base/android/build_info.h"
#endif
#ifndef EFD_ZERO_ON_WAKE
#define EFD_ZERO_ON_WAKE …
#endif
namespace mojo {
namespace core {
namespace {
void KernelVersionNumbers(int32_t* major_version,
int32_t* minor_version,
int32_t* bugfix_version) { … }
}
class DataAvailableNotifier { … };
namespace {
constexpr int kMemFDSeals = …;
std::atomic_bool g_params_set{ … };
std::atomic_bool g_use_shared_mem{ … };
std::atomic_bool g_use_zero_on_wake{ … };
std::atomic_uint32_t g_shared_mem_pages{ … };
struct UpgradeOfferMessage { … };
constexpr size_t RoundUpToWordBoundary(size_t size) { … }
base::ScopedFD CreateSealedMemFD(size_t size) { … }
bool ValidateFDIsProperlySealedMemFD(const base::ScopedFD& fd) { … }
class EventFDNotifier : public DataAvailableNotifier,
public base::MessagePumpForIO::FdWatcher { … };
}
class ChannelLinux::SharedBuffer { … };
ChannelLinux::ChannelLinux(
Delegate* delegate,
ConnectionParams connection_params,
HandlePolicy handle_policy,
scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
: … { … }
ChannelLinux::~ChannelLinux() = default;
void ChannelLinux::Write(MessagePtr message) { … }
void ChannelLinux::OfferSharedMemUpgrade() { … }
bool ChannelLinux::OnControlMessage(Message::MessageType message_type,
const void* payload,
size_t payload_size,
std::vector<PlatformHandle> handles) { … }
void ChannelLinux::SharedMemReadReady() { … }
void ChannelLinux::OnWriteError(Error error) { … }
void ChannelLinux::ShutDownOnIOThread() { … }
void ChannelLinux::StartOnIOThread() { … }
void ChannelLinux::OfferSharedMemUpgradeInternal() { … }
bool ChannelLinux::KernelSupportsUpgradeRequirements() { … }
bool ChannelLinux::UpgradesEnabled() { … }
void ChannelLinux::SetSharedMemParameters(bool enabled,
uint32_t num_pages,
bool use_zero_on_wake) { … }
}
}