#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/core/core_ipcz.h"
#include <algorithm>
#include <cstddef>
#include <cstdint>
#include <map>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
#include "base/check_op.h"
#include "base/containers/span.h"
#include "base/memory/platform_shared_memory_region.h"
#include "base/memory/ptr_util.h"
#include "base/memory/ref_counted.h"
#include "base/memory/writable_shared_memory_region.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "base/numerics/safe_conversions.h"
#include "base/strings/strcat.h"
#include "base/synchronization/lock.h"
#include "base/time/time.h"
#include "mojo/core/ipcz_api.h"
#include "mojo/core/ipcz_driver/data_pipe.h"
#include "mojo/core/ipcz_driver/invitation.h"
#include "mojo/core/ipcz_driver/mojo_message.h"
#include "mojo/core/ipcz_driver/mojo_trap.h"
#include "mojo/core/ipcz_driver/shared_buffer.h"
#include "mojo/core/ipcz_driver/shared_buffer_mapping.h"
#include "mojo/core/ipcz_driver/wrapped_platform_handle.h"
#include "mojo/public/cpp/platform/platform_handle.h"
#include "third_party/ipcz/include/ipcz/ipcz.h"
namespace mojo::core {
namespace {
class MappingTable { … };
MappingTable& GetMappingTable() { … }
MojoResult GetMojoReadResultForIpczGet(IpczResult result) { … }
MojoResult GetMojoWriteResultForIpczPut(IpczResult result) { … }
extern "C" {
MojoResult MojoInitializeIpcz(const struct MojoInitializeOptions* options) { … }
MojoTimeTicks MojoGetTimeTicksNowIpcz() { … }
MojoResult MojoCloseIpcz(MojoHandle handle) { … }
MojoResult MojoQueryHandleSignalsStateIpcz(
MojoHandle handle,
MojoHandleSignalsState* signals_state) { … }
MojoResult MojoCreateMessagePipeIpcz(
const MojoCreateMessagePipeOptions* options,
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1) { … }
MojoResult MojoWriteMessageIpcz(MojoHandle message_pipe_handle,
MojoMessageHandle message,
const MojoWriteMessageOptions* options) { … }
MojoResult MojoReadMessageIpcz(MojoHandle message_pipe_handle,
const MojoReadMessageOptions* options,
MojoMessageHandle* message) { … }
MojoResult MojoFuseMessagePipesIpcz(
MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options) { … }
MojoResult MojoCreateMessageIpcz(const MojoCreateMessageOptions* options,
MojoMessageHandle* message) { … }
MojoResult MojoDestroyMessageIpcz(MojoMessageHandle message) { … }
MojoResult MojoSerializeMessageIpcz(
MojoMessageHandle message,
const MojoSerializeMessageOptions* options) { … }
MojoResult MojoReserveMessageCapacityIpcz(MojoMessageHandle message,
uint32_t payload_buffer_size,
uint32_t* buffer_size) { … }
MojoResult MojoAppendMessageDataIpcz(
MojoMessageHandle message,
uint32_t additional_payload_size,
const MojoHandle* handles,
uint32_t num_handles,
const MojoAppendMessageDataOptions* options,
void** buffer,
uint32_t* buffer_size) { … }
MojoResult MojoGetMessageDataIpcz(MojoMessageHandle message,
const MojoGetMessageDataOptions* options,
void** buffer,
uint32_t* num_bytes,
MojoHandle* handles,
uint32_t* num_handles) { … }
MojoResult MojoSetMessageContextIpcz(
MojoMessageHandle message_handle,
uintptr_t context,
MojoMessageContextSerializer serializer,
MojoMessageContextDestructor destructor,
const MojoSetMessageContextOptions* options) { … }
MojoResult MojoGetMessageContextIpcz(
MojoMessageHandle message_handle,
const MojoGetMessageContextOptions* options,
uintptr_t* context) { … }
MojoResult MojoNotifyBadMessageIpcz(
MojoMessageHandle message_handle,
const char* error,
uint32_t error_num_bytes,
const MojoNotifyBadMessageOptions* options) { … }
MojoResult MojoCreateDataPipeIpcz(const MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle) { … }
MojoResult MojoWriteDataIpcz(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_bytes,
const MojoWriteDataOptions* options) { … }
MojoResult MojoBeginWriteDataIpcz(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_bytes) { … }
MojoResult MojoEndWriteDataIpcz(MojoHandle data_pipe_producer_handle,
uint32_t num_bytes_produced,
const MojoEndWriteDataOptions* options) { … }
MojoResult MojoReadDataIpcz(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_bytes) { … }
MojoResult MojoBeginReadDataIpcz(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_bytes) { … }
MojoResult MojoEndReadDataIpcz(MojoHandle data_pipe_consumer_handle,
uint32_t num_bytes_consumed,
const MojoEndReadDataOptions* options) { … }
MojoResult MojoCreateSharedBufferIpcz(
uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle) { … }
MojoResult MojoDuplicateBufferHandleIpcz(
MojoHandle buffer_handle,
const MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle) { … }
MojoResult MojoMapBufferIpcz(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
const MojoMapBufferOptions* options,
void** address) { … }
MojoResult MojoUnmapBufferIpcz(void* address) { … }
MojoResult MojoGetBufferInfoIpcz(MojoHandle buffer_handle,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) { … }
MojoResult MojoCreateTrapIpcz(MojoTrapEventHandler handler,
const MojoCreateTrapOptions* options,
MojoHandle* trap_handle) { … }
MojoResult MojoAddTriggerIpcz(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const MojoAddTriggerOptions* options) { … }
MojoResult MojoRemoveTriggerIpcz(MojoHandle trap_handle,
uintptr_t context,
const MojoRemoveTriggerOptions* options) { … }
MojoResult MojoArmTrapIpcz(MojoHandle trap_handle,
const MojoArmTrapOptions* options,
uint32_t* num_blocking_events,
MojoTrapEvent* blocking_events) { … }
MojoResult MojoWrapPlatformHandleIpcz(
const MojoPlatformHandle* platform_handle,
const MojoWrapPlatformHandleOptions* options,
MojoHandle* mojo_handle) { … }
MojoResult MojoUnwrapPlatformHandleIpcz(
MojoHandle mojo_handle,
const MojoUnwrapPlatformHandleOptions* options,
MojoPlatformHandle* platform_handle) { … }
MojoResult MojoWrapPlatformSharedMemoryRegionIpcz(
const MojoPlatformHandle* platform_handles,
uint32_t num_platform_handles,
uint64_t num_bytes,
const MojoSharedBufferGuid* guid,
MojoPlatformSharedMemoryRegionAccessMode access_mode,
const MojoWrapPlatformSharedMemoryRegionOptions* options,
MojoHandle* mojo_handle) { … }
MojoResult MojoUnwrapPlatformSharedMemoryRegionIpcz(
MojoHandle mojo_handle,
const MojoUnwrapPlatformSharedMemoryRegionOptions* options,
MojoPlatformHandle* platform_handles,
uint32_t* num_platform_handles,
uint64_t* num_bytes,
MojoSharedBufferGuid* mojo_guid,
MojoPlatformSharedMemoryRegionAccessMode* access_mode) { … }
MojoResult MojoCreateInvitationIpcz(const MojoCreateInvitationOptions* options,
MojoHandle* invitation_handle) { … }
MojoResult MojoAttachMessagePipeToInvitationIpcz(
MojoHandle invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoAttachMessagePipeToInvitationOptions* options,
MojoHandle* message_pipe_handle) { … }
MojoResult MojoExtractMessagePipeFromInvitationIpcz(
MojoHandle invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoExtractMessagePipeFromInvitationOptions* options,
MojoHandle* message_pipe_handle) { … }
MojoResult MojoSendInvitationIpcz(
MojoHandle invitation_handle,
const MojoPlatformProcessHandle* process_handle,
const MojoInvitationTransportEndpoint* transport_endpoint,
MojoProcessErrorHandler error_handler,
uintptr_t error_handler_context,
const MojoSendInvitationOptions* options) { … }
MojoResult MojoAcceptInvitationIpcz(
const MojoInvitationTransportEndpoint* transport_endpoint,
const MojoAcceptInvitationOptions* options,
MojoHandle* invitation_handle) { … }
MojoResult MojoSetQuotaIpcz(MojoHandle handle,
MojoQuotaType type,
uint64_t limit,
const MojoSetQuotaOptions* options) { … }
MojoResult MojoQueryQuotaIpcz(MojoHandle handle,
MojoQuotaType type,
const MojoQueryQuotaOptions* options,
uint64_t* current_limit,
uint64_t* current_usage) { … }
MojoResult MojoShutdownIpcz(const MojoShutdownOptions* options) { … }
MojoResult MojoSetDefaultProcessErrorHandlerIpcz(
MojoDefaultProcessErrorHandler handler,
const MojoSetDefaultProcessErrorHandlerOptions* options) { … }
}
MojoSystemThunks2 g_mojo_ipcz_thunks = …;
}
const MojoSystemThunks2* GetMojoIpczImpl() { … }
}