#ifdef UNSAFE_BUFFERS_BUILD
#pragma allow_unsafe_buffers
#endif
#include "mojo/public/c/system/thunks.h"
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <optional>
#include <string_view>
#include <vector>
#include "base/check_op.h"
#include "base/compiler_specific.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/no_destructor.h"
#include "base/notreached.h"
#include "build/build_config.h"
#include "mojo/public/c/system/core.h"
#include "mojo/public/c/system/data_pipe.h"
#include "mojo/public/c/system/invitation.h"
#include "mojo/public/c/system/macros.h"
#include "mojo/public/c/system/message_pipe.h"
namespace {
MojoGetSystemThunksFunction;
MojoSystemThunks2 g_thunks;
MojoResult NotImplemented(const char* name) { … }
}
#define INVOKE_THUNK(name, ...) …
extern "C" {
MojoResult MojoInitialize(const struct MojoInitializeOptions* options) { … }
MojoTimeTicks MojoGetTimeTicksNow() { … }
MojoResult MojoClose(MojoHandle handle) { … }
MojoResult MojoQueryHandleSignalsState(
MojoHandle handle,
struct MojoHandleSignalsState* signals_state) { … }
MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options,
MojoHandle* message_pipe_handle0,
MojoHandle* message_pipe_handle1) { … }
MojoResult MojoWriteMessage(MojoHandle message_pipe_handle,
MojoMessageHandle message_handle,
const MojoWriteMessageOptions* options) { … }
MojoResult MojoReadMessage(MojoHandle message_pipe_handle,
const MojoReadMessageOptions* options,
MojoMessageHandle* message_handle) { … }
MojoResult MojoFuseMessagePipes(MojoHandle handle0,
MojoHandle handle1,
const MojoFuseMessagePipesOptions* options) { … }
MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options,
MojoHandle* data_pipe_producer_handle,
MojoHandle* data_pipe_consumer_handle) { … }
MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
const MojoWriteDataOptions* options) { … }
MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_elements) { … }
MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle,
uint32_t num_elements_written,
const MojoEndWriteDataOptions* options) { … }
MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_elements) { … }
MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_elements) { … }
MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle,
uint32_t num_elements_read,
const MojoEndReadDataOptions* options) { … }
MojoResult MojoCreateSharedBuffer(uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle* shared_buffer_handle) { … }
MojoResult MojoDuplicateBufferHandle(
MojoHandle buffer_handle,
const MojoDuplicateBufferHandleOptions* options,
MojoHandle* new_buffer_handle) { … }
MojoResult MojoMapBuffer(MojoHandle buffer_handle,
uint64_t offset,
uint64_t num_bytes,
const MojoMapBufferOptions* options,
void** buffer) { … }
MojoResult MojoUnmapBuffer(void* buffer) { … }
MojoResult MojoGetBufferInfo(MojoHandle buffer_handle,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) { … }
MojoResult MojoCreateTrap(MojoTrapEventHandler handler,
const MojoCreateTrapOptions* options,
MojoHandle* trap_handle) { … }
MojoResult MojoAddTrigger(MojoHandle trap_handle,
MojoHandle handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const MojoAddTriggerOptions* options) { … }
MojoResult MojoRemoveTrigger(MojoHandle trap_handle,
uintptr_t context,
const MojoRemoveTriggerOptions* options) { … }
MojoResult MojoArmTrap(MojoHandle trap_handle,
const MojoArmTrapOptions* options,
uint32_t* num_blocking_events,
MojoTrapEvent* blocking_events) { … }
MojoResult MojoCreateMessage(const MojoCreateMessageOptions* options,
MojoMessageHandle* message) { … }
MojoResult MojoDestroyMessage(MojoMessageHandle message) { … }
MojoResult MojoSerializeMessage(MojoMessageHandle message,
const MojoSerializeMessageOptions* options) { … }
MojoResult MojoReserveMessageCapacity(MojoMessageHandle message,
uint32_t payload_buffer_size,
uint32_t* buffer_size) { … }
MojoResult MojoAppendMessageData(MojoMessageHandle message,
uint32_t payload_size,
const MojoHandle* handles,
uint32_t num_handles,
const MojoAppendMessageDataOptions* options,
void** buffer,
uint32_t* buffer_size) { … }
MojoResult MojoGetMessageData(MojoMessageHandle message,
const MojoGetMessageDataOptions* options,
void** buffer,
uint32_t* num_bytes,
MojoHandle* handles,
uint32_t* num_handles) { … }
MojoResult MojoSetMessageContext(MojoMessageHandle message,
uintptr_t context,
MojoMessageContextSerializer serializer,
MojoMessageContextDestructor destructor,
const MojoSetMessageContextOptions* options) { … }
MojoResult MojoGetMessageContext(MojoMessageHandle message,
const MojoGetMessageContextOptions* options,
uintptr_t* context) { … }
MojoResult MojoNotifyBadMessage(MojoMessageHandle message,
const char* error,
uint32_t error_num_bytes,
const MojoNotifyBadMessageOptions* options) { … }
MojoResult MojoWrapPlatformHandle(const MojoPlatformHandle* platform_handle,
const MojoWrapPlatformHandleOptions* options,
MojoHandle* mojo_handle) { … }
MojoResult MojoUnwrapPlatformHandle(
MojoHandle mojo_handle,
const MojoUnwrapPlatformHandleOptions* options,
MojoPlatformHandle* platform_handle) { … }
MojoResult MojoWrapPlatformSharedMemoryRegion(
const struct 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 MojoUnwrapPlatformSharedMemoryRegion(
MojoHandle mojo_handle,
const MojoUnwrapPlatformSharedMemoryRegionOptions* options,
struct MojoPlatformHandle* platform_handles,
uint32_t* num_platform_handles,
uint64_t* num_bytes,
struct MojoSharedBufferGuid* guid,
MojoPlatformSharedMemoryRegionAccessMode* access_mode) { … }
MojoResult MojoCreateInvitation(const MojoCreateInvitationOptions* options,
MojoHandle* invitation_handle) { … }
MojoResult MojoAttachMessagePipeToInvitation(
MojoHandle invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoAttachMessagePipeToInvitationOptions* options,
MojoHandle* message_pipe_handle) { … }
MojoResult MojoExtractMessagePipeFromInvitation(
MojoHandle invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoExtractMessagePipeFromInvitationOptions* options,
MojoHandle* message_pipe_handle) { … }
MojoResult MojoSendInvitation(
MojoHandle invitation_handle,
const MojoPlatformProcessHandle* process_handle,
const MojoInvitationTransportEndpoint* transport_endpoint,
MojoProcessErrorHandler error_handler,
uintptr_t error_handler_context,
const MojoSendInvitationOptions* options) { … }
MojoResult MojoAcceptInvitation(
const MojoInvitationTransportEndpoint* transport_endpoint,
const MojoAcceptInvitationOptions* options,
MojoHandle* invitation_handle) { … }
MojoResult MojoSetQuota(MojoHandle handle,
MojoQuotaType type,
uint64_t limit,
const MojoSetQuotaOptions* options) { … }
MojoResult MojoQueryQuota(MojoHandle handle,
MojoQuotaType type,
const MojoQueryQuotaOptions* options,
uint64_t* limit,
uint64_t* usage) { … }
MojoResult MojoShutdown(const MojoShutdownOptions* options) { … }
MojoResult MojoSetDefaultProcessErrorHandler(
MojoDefaultProcessErrorHandler handler,
const struct MojoSetDefaultProcessErrorHandlerOptions* options) { … }
MojoResult MojoClose32(MojoHandle32 handle) { … }
MojoResult MojoQueryHandleSignalsState32(
MojoHandle32 handle,
struct MojoHandleSignalsState* signals_state) { … }
MojoResult MojoCreateMessagePipe32(const MojoCreateMessagePipeOptions* options,
MojoHandle32* message_pipe_handle0,
MojoHandle32* message_pipe_handle1) { … }
MojoResult MojoWriteMessage32(MojoHandle32 message_pipe_handle,
MojoMessageHandle message_handle,
const MojoWriteMessageOptions* options) { … }
MojoResult MojoReadMessage32(MojoHandle32 message_pipe_handle,
const MojoReadMessageOptions* options,
MojoMessageHandle* message_handle) { … }
MojoResult MojoFuseMessagePipes32(MojoHandle32 handle0,
MojoHandle32 handle1,
const MojoFuseMessagePipesOptions* options) { … }
MojoResult MojoCreateDataPipe32(const MojoCreateDataPipeOptions* options,
MojoHandle32* data_pipe_producer_handle,
MojoHandle32* data_pipe_consumer_handle) { … }
MojoResult MojoWriteData32(MojoHandle32 data_pipe_producer_handle,
const void* elements,
uint32_t* num_elements,
const MojoWriteDataOptions* options) { … }
MojoResult MojoBeginWriteData32(MojoHandle32 data_pipe_producer_handle,
const MojoBeginWriteDataOptions* options,
void** buffer,
uint32_t* buffer_num_elements) { … }
MojoResult MojoEndWriteData32(MojoHandle32 data_pipe_producer_handle,
uint32_t num_elements_written,
const MojoEndWriteDataOptions* options) { … }
MojoResult MojoReadData32(MojoHandle32 data_pipe_consumer_handle,
const MojoReadDataOptions* options,
void* elements,
uint32_t* num_elements) { … }
MojoResult MojoBeginReadData32(MojoHandle32 data_pipe_consumer_handle,
const MojoBeginReadDataOptions* options,
const void** buffer,
uint32_t* buffer_num_elements) { … }
MojoResult MojoEndReadData32(MojoHandle32 data_pipe_consumer_handle,
uint32_t num_elements_read,
const MojoEndReadDataOptions* options) { … }
MojoResult MojoCreateSharedBuffer32(
uint64_t num_bytes,
const MojoCreateSharedBufferOptions* options,
MojoHandle32* shared_buffer_handle) { … }
MojoResult MojoDuplicateBufferHandle32(
MojoHandle32 buffer_handle,
const MojoDuplicateBufferHandleOptions* options,
MojoHandle32* new_buffer_handle) { … }
MojoResult MojoMapBuffer32(MojoHandle32 buffer_handle,
uint64_t offset,
uint64_t num_bytes,
const MojoMapBufferOptions* options,
void** buffer) { … }
MojoResult MojoGetBufferInfo32(MojoHandle32 buffer_handle,
const MojoGetBufferInfoOptions* options,
MojoSharedBufferInfo* info) { … }
MojoResult MojoCreateTrap32(MojoTrapEventHandler handler,
const MojoCreateTrapOptions* options,
MojoHandle32* trap_handle) { … }
MojoResult MojoAddTrigger32(MojoHandle32 trap_handle,
MojoHandle32 handle,
MojoHandleSignals signals,
MojoTriggerCondition condition,
uintptr_t context,
const MojoAddTriggerOptions* options) { … }
MojoResult MojoRemoveTrigger32(MojoHandle32 trap_handle,
uintptr_t context,
const MojoRemoveTriggerOptions* options) { … }
MojoResult MojoArmTrap32(MojoHandle32 trap_handle,
const MojoArmTrapOptions* options,
uint32_t* num_blocking_events,
MojoTrapEvent* blocking_events) { … }
MojoResult MojoAppendMessageData32(MojoMessageHandle message,
uint32_t payload_size,
const MojoHandle32* handles,
uint32_t num_handles,
const MojoAppendMessageDataOptions* options,
void** buffer,
uint32_t* buffer_size) { … }
MojoResult MojoGetMessageData32(MojoMessageHandle message,
const MojoGetMessageDataOptions* options,
void** buffer,
uint32_t* num_bytes,
MojoHandle32* handles,
uint32_t* num_handles) { … }
MojoResult MojoWrapPlatformHandle32(
const MojoPlatformHandle* platform_handle,
const MojoWrapPlatformHandleOptions* options,
MojoHandle32* mojo_handle) { … }
MojoResult MojoUnwrapPlatformHandle32(
MojoHandle32 mojo_handle,
const MojoUnwrapPlatformHandleOptions* options,
MojoPlatformHandle* platform_handle) { … }
MojoResult MojoWrapPlatformSharedMemoryRegion32(
const struct MojoPlatformHandle* platform_handles,
uint32_t num_platform_handles,
uint64_t num_bytes,
const MojoSharedBufferGuid* guid,
MojoPlatformSharedMemoryRegionAccessMode access_mode,
const MojoWrapPlatformSharedMemoryRegionOptions* options,
MojoHandle32* mojo_handle) { … }
MojoResult MojoUnwrapPlatformSharedMemoryRegion32(
MojoHandle32 mojo_handle,
const MojoUnwrapPlatformSharedMemoryRegionOptions* options,
struct MojoPlatformHandle* platform_handles,
uint32_t* num_platform_handles,
uint64_t* num_bytes,
struct MojoSharedBufferGuid* guid,
MojoPlatformSharedMemoryRegionAccessMode* access_mode) { … }
MojoResult MojoCreateInvitation32(const MojoCreateInvitationOptions* options,
MojoHandle32* invitation_handle) { … }
MojoResult MojoAttachMessagePipeToInvitation32(
MojoHandle32 invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoAttachMessagePipeToInvitationOptions* options,
MojoHandle32* message_pipe_handle) { … }
MojoResult MojoExtractMessagePipeFromInvitation32(
MojoHandle32 invitation_handle,
const void* name,
uint32_t name_num_bytes,
const MojoExtractMessagePipeFromInvitationOptions* options,
MojoHandle32* message_pipe_handle) { … }
MojoResult MojoSendInvitation32(
MojoHandle32 invitation_handle,
const MojoPlatformProcessHandle* process_handle,
const MojoInvitationTransportEndpoint* transport_endpoint,
MojoProcessErrorHandler error_handler,
uintptr_t error_handler_context,
const MojoSendInvitationOptions* options) { … }
MojoResult MojoAcceptInvitation32(
const MojoInvitationTransportEndpoint* transport_endpoint,
const MojoAcceptInvitationOptions* options,
MojoHandle32* invitation_handle) { … }
MojoResult MojoSetQuota32(MojoHandle32 handle,
MojoQuotaType type,
uint64_t limit,
const MojoSetQuotaOptions* options) { … }
MojoResult MojoQueryQuota32(MojoHandle32 handle,
MojoQuotaType type,
const MojoQueryQuotaOptions* options,
uint64_t* limit,
uint64_t* usage) { … }
MojoSystemThunks32 g_thunks_32 = …;
const MojoSystemThunks2* MojoEmbedderGetSystemThunks2() { … }
const MojoSystemThunks32* MojoEmbedderGetSystemThunks32() { … }
void MojoEmbedderSetSystemThunks(const MojoSystemThunks2* thunks) { … }
}