#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/core/ipcz_driver/data_pipe.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <optional>
#include <tuple>
#include "base/check.h"
#include "base/memory/ref_counted.h"
#include "base/memory/unsafe_shared_memory_region.h"
#include "base/numerics/safe_math.h"
#include "base/synchronization/lock.h"
#include "mojo/core/ipcz_api.h"
#include "mojo/core/ipcz_driver/ring_buffer.h"
#include "third_party/ipcz/include/ipcz/ipcz.h"
namespace mojo::core::ipcz_driver {
namespace {
struct IPCZ_ALIGN(8) DataPipeHeader { … };
static_assert …;
bool SendPeerUpdate(IpczHandle portal, size_t num_bytes) { … }
struct DrainResult { … };
DrainResult DrainPeerUpdates(IpczHandle portal) { … }
}
DataPipe::PortalWrapper::PortalWrapper(ScopedIpczHandle handle)
: … { … }
DataPipe::PortalWrapper::~PortalWrapper() = default;
DataPipe::DataPipe(EndpointType endpoint_type,
const Config& config,
scoped_refptr<SharedBuffer> buffer,
scoped_refptr<SharedBufferMapping> mapping)
: … { … }
DataPipe::~DataPipe() { … }
std::optional<DataPipe::Pair> DataPipe::CreatePair(const Config& config) { … }
bool DataPipe::AdoptPortal(ScopedIpczHandle portal) { … }
scoped_refptr<DataPipe::PortalWrapper> DataPipe::GetPortal() { … }
ScopedIpczHandle DataPipe::TakePortal() { … }
MojoResult DataPipe::WriteData(const void* elements,
uint32_t& num_bytes,
MojoWriteDataFlags flags) { … }
MojoResult DataPipe::BeginWriteData(void*& data,
uint32_t& num_bytes,
MojoBeginWriteDataFlags flags) { … }
MojoResult DataPipe::EndWriteData(size_t num_bytes_produced) { … }
MojoResult DataPipe::ReadData(void* elements,
uint32_t& num_bytes,
MojoReadDataFlags flags) { … }
MojoResult DataPipe::BeginReadData(const void*& buffer,
uint32_t& buffer_num_bytes) { … }
MojoResult DataPipe::EndReadData(size_t num_bytes_consumed) { … }
void DataPipe::Close() { … }
bool DataPipe::IsSerializable() const { … }
bool DataPipe::GetSerializedDimensions(Transport& transmitter,
size_t& num_bytes,
size_t& num_handles) { … }
bool DataPipe::Serialize(Transport& transmitter,
base::span<uint8_t> data,
base::span<PlatformHandle> handles) { … }
scoped_refptr<DataPipe> DataPipe::Deserialize(
base::span<const uint8_t> data,
base::span<PlatformHandle> handles) { … }
bool DataPipe::GetSignals(MojoHandleSignalsState& signals_state) { … }
void DataPipe::FlushUpdatesFromPeer() { … }
bool DataPipe::DeserializeRingBuffer(const RingBuffer::SerializedState& state) { … }
DataPipe::Pair::Pair() = default;
DataPipe::Pair::Pair(const Pair&) = default;
DataPipe::Pair& DataPipe::Pair::operator=(const Pair&) = default;
DataPipe::Pair::~Pair() = default;
}