#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/public/cpp/bindings/message.h"
#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <atomic>
#include <string_view>
#include <tuple>
#include <utility>
#include "base/check_op.h"
#include "base/feature_list.h"
#include "base/functional/bind.h"
#include "base/lazy_instance.h"
#include "base/memory/ptr_util.h"
#include "base/numerics/safe_math.h"
#include "base/rand_util.h"
#include "base/ranges/algorithm.h"
#include "base/threading/sequence_local_storage_slot.h"
#include "base/trace_event/trace_event.h"
#include "base/trace_event/trace_id_helper.h"
#include "base/trace_event/typed_macros.h"
#include "mojo/public/cpp/bindings/associated_group_controller.h"
#include "mojo/public/cpp/bindings/lib/array_internal.h"
#include "mojo/public/cpp/bindings/lib/message_fragment.h"
#include "mojo/public/cpp/bindings/lib/unserialized_message_context.h"
namespace mojo {
namespace {
BASE_FEATURE(…);
base::GenericSequenceLocalStorageSlot<internal::MessageDispatchContext*>&
GetSLSMessageDispatchContext() { … }
base::SmallSequenceLocalStorageSlot<internal::MessageDispatchContext*>&
GetSmallSLSMessageDispatchContext() { … }
thread_local base::MetricsSubSampler g_sub_sampler;
void SetMessageDispatchContext(internal::MessageDispatchContext* context) { … }
internal::MessageDispatchContext* GetMessageDispatchContext() { … }
void DoNotifyBadMessage(Message message, std::string_view error) { … }
template <typename HeaderType>
void AllocateHeaderFromBuffer(internal::Buffer* buffer, HeaderType** header) { … }
uint64_t GetTraceId(uint32_t name, uint32_t trace_nonce) { … }
void WriteMessageHeader(uint32_t name,
uint32_t flags,
uint32_t trace_nonce,
size_t payload_interface_id_count,
internal::Buffer* payload_buffer,
int64_t creation_timeticks_us) { … }
void CreateSerializedMessageObject(uint32_t name,
uint32_t flags,
uint32_t trace_nonce,
size_t payload_size,
size_t payload_interface_id_count,
MojoCreateMessageFlags create_message_flags,
std::vector<ScopedHandle>* handles,
ScopedMessageHandle* out_handle,
internal::Buffer* out_buffer,
size_t estimated_payload_size,
int64_t creation_timeticks_us) { … }
void SerializeUnserializedContext(MojoMessageHandle message,
uintptr_t context_value) { … }
void DestroyUnserializedContext(uintptr_t context) { … }
Message CreateUnserializedMessage(
std::unique_ptr<internal::UnserializedMessageContext> context,
MojoCreateMessageFlags create_message_flags) { … }
}
Message::Message() = default;
Message::Message(Message&& other)
: … { … }
Message::Message(std::unique_ptr<internal::UnserializedMessageContext> context,
MojoCreateMessageFlags create_message_flags)
: … { … }
Message::Message(uint32_t name,
uint32_t flags,
size_t payload_size,
size_t payload_interface_id_count,
MojoCreateMessageFlags create_message_flags,
std::vector<ScopedHandle>* handles,
size_t estimated_payload_size) { … }
Message::Message(uint32_t name,
uint32_t flags,
size_t payload_size,
size_t payload_interface_id_count,
std::vector<ScopedHandle>* handles,
size_t estimated_payload_size)
: … { … }
Message::Message(uint32_t name,
uint32_t flags,
MojoCreateMessageFlags create_message_flags,
size_t estimated_payload_size)
: … { … }
Message::Message(uint32_t name, uint32_t flags, size_t estimated_payload_size)
: … { … }
Message::Message(ScopedMessageHandle handle,
const internal::MessageHeaderV1& header)
: … { … }
Message::Message(base::span<const uint8_t> payload,
base::span<ScopedHandle> handles) { … }
Message Message::CreateFromMessageHandle(ScopedMessageHandle* message_handle) { … }
Message::~Message() = default;
Message& Message::operator=(Message&& other) { … }
void Message::Reset() { … }
const uint8_t* Message::payload() const { … }
uint32_t Message::payload_num_bytes() const { … }
uint32_t Message::payload_num_interface_ids() const { … }
const uint32_t* Message::payload_interface_ids() const { … }
ScopedMessageHandle Message::TakeMojoMessage() { … }
void Message::NotifyBadMessage(std::string_view error) { … }
void Message::SerializeHandles(AssociatedGroupController* group_controller) { … }
bool Message::DeserializeAssociatedEndpointHandles(
AssociatedGroupController* group_controller) { … }
void Message::NotifyPeerClosureForSerializedHandles(
AssociatedGroupController* group_controller) { … }
void Message::SerializeIfNecessary() { … }
std::unique_ptr<internal::UnserializedMessageContext>
Message::TakeUnserializedContext(uintptr_t tag) { … }
Message::Message(ScopedMessageHandle message_handle,
std::vector<ScopedHandle> attached_handles,
internal::Buffer payload_buffer,
bool serialized)
: … { … }
uint64_t Message::GetTraceId() const { … }
void Message::WriteIntoTrace(perfetto::TracedValue ctx) const { … }
int64_t Message::creation_timeticks_us() const { … }
bool MessageReceiver::PrefersSerializedMessages() { … }
PassThroughFilter::PassThroughFilter() { … }
PassThroughFilter::~PassThroughFilter() { … }
bool PassThroughFilter::Accept(Message* message) { … }
void ReportBadMessage(std::string_view error) { … }
ReportBadMessageCallback GetBadMessageCallback() { … }
bool IsInMessageDispatch() { … }
namespace internal {
MessageHeaderV2::MessageHeaderV2() = default;
MessageDispatchContext::MessageDispatchContext(Message* message)
: … { … }
MessageDispatchContext::~MessageDispatchContext() { … }
MessageDispatchContext* MessageDispatchContext::current() { … }
ReportBadMessageCallback MessageDispatchContext::GetBadMessageCallback() { … }
}
}