1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved. 2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be 3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file. 4*635a8641SAndroid Build Coastguard Worker 5*635a8641SAndroid Build Coastguard Worker // Note: This header should be compilable as C. 6*635a8641SAndroid Build Coastguard Worker 7*635a8641SAndroid Build Coastguard Worker #ifndef MOJO_PUBLIC_C_SYSTEM_THUNKS_H_ 8*635a8641SAndroid Build Coastguard Worker #define MOJO_PUBLIC_C_SYSTEM_THUNKS_H_ 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker #include <stddef.h> 11*635a8641SAndroid Build Coastguard Worker #include <stdint.h> 12*635a8641SAndroid Build Coastguard Worker 13*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/core.h" 14*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/system_export.h" 15*635a8641SAndroid Build Coastguard Worker 16*635a8641SAndroid Build Coastguard Worker // This defines the *stable*, foward-compatible ABI for the Mojo Core C library. 17*635a8641SAndroid Build Coastguard Worker // As such, the following types of changes are DISALLOWED: 18*635a8641SAndroid Build Coastguard Worker // 19*635a8641SAndroid Build Coastguard Worker // - DO NOT delete or re-order any of the fields in this structure 20*635a8641SAndroid Build Coastguard Worker // - DO NOT modify any function signatures defined here 21*635a8641SAndroid Build Coastguard Worker // - DO NOT alter the alignment of the stucture 22*635a8641SAndroid Build Coastguard Worker // 23*635a8641SAndroid Build Coastguard Worker // Some changes are of course permissible: 24*635a8641SAndroid Build Coastguard Worker // 25*635a8641SAndroid Build Coastguard Worker // - DO feel free to rename existing fields if there's a good reason to do so, 26*635a8641SAndroid Build Coastguard Worker // e.g. deprecation of a function for all future applications. 27*635a8641SAndroid Build Coastguard Worker // - DO add new functions to the end of this structure, but ensure that they 28*635a8641SAndroid Build Coastguard Worker // have a signature which lends itself to reasonably extensible behavior 29*635a8641SAndroid Build Coastguard Worker // (e.g. an optional "Options" structure as many functions here have). 30*635a8641SAndroid Build Coastguard Worker // 31*635a8641SAndroid Build Coastguard Worker #pragma pack(push, 8) 32*635a8641SAndroid Build Coastguard Worker struct MojoSystemThunks { 33*635a8641SAndroid Build Coastguard Worker uint32_t size; // Should be set to sizeof(MojoSystemThunks). 34*635a8641SAndroid Build Coastguard Worker 35*635a8641SAndroid Build Coastguard Worker MojoResult (*Initialize)(const struct MojoInitializeOptions* options); 36*635a8641SAndroid Build Coastguard Worker 37*635a8641SAndroid Build Coastguard Worker MojoTimeTicks (*GetTimeTicksNow)(); 38*635a8641SAndroid Build Coastguard Worker 39*635a8641SAndroid Build Coastguard Worker // Generic handle API. 40*635a8641SAndroid Build Coastguard Worker MojoResult (*Close)(MojoHandle handle); 41*635a8641SAndroid Build Coastguard Worker MojoResult (*QueryHandleSignalsState)( 42*635a8641SAndroid Build Coastguard Worker MojoHandle handle, 43*635a8641SAndroid Build Coastguard Worker struct MojoHandleSignalsState* signals_state); 44*635a8641SAndroid Build Coastguard Worker 45*635a8641SAndroid Build Coastguard Worker // Message pipe API. 46*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateMessagePipe)( 47*635a8641SAndroid Build Coastguard Worker const struct MojoCreateMessagePipeOptions* options, 48*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle0, 49*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle1); 50*635a8641SAndroid Build Coastguard Worker MojoResult (*WriteMessage)(MojoHandle message_pipe_handle, 51*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message_handle, 52*635a8641SAndroid Build Coastguard Worker const struct MojoWriteMessageOptions* options); 53*635a8641SAndroid Build Coastguard Worker MojoResult (*ReadMessage)(MojoHandle message_pipe_handle, 54*635a8641SAndroid Build Coastguard Worker const struct MojoReadMessageOptions* options, 55*635a8641SAndroid Build Coastguard Worker MojoMessageHandle* message_handle); 56*635a8641SAndroid Build Coastguard Worker MojoResult (*FuseMessagePipes)( 57*635a8641SAndroid Build Coastguard Worker MojoHandle handle0, 58*635a8641SAndroid Build Coastguard Worker MojoHandle handle1, 59*635a8641SAndroid Build Coastguard Worker const struct MojoFuseMessagePipesOptions* options); 60*635a8641SAndroid Build Coastguard Worker 61*635a8641SAndroid Build Coastguard Worker // Message object API. 62*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateMessage)(const struct MojoCreateMessageOptions* options, 63*635a8641SAndroid Build Coastguard Worker MojoMessageHandle* message); 64*635a8641SAndroid Build Coastguard Worker MojoResult (*DestroyMessage)(MojoMessageHandle message); 65*635a8641SAndroid Build Coastguard Worker MojoResult (*SerializeMessage)( 66*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message, 67*635a8641SAndroid Build Coastguard Worker const struct MojoSerializeMessageOptions* options); 68*635a8641SAndroid Build Coastguard Worker MojoResult (*AppendMessageData)( 69*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message, 70*635a8641SAndroid Build Coastguard Worker uint32_t additional_payload_size, 71*635a8641SAndroid Build Coastguard Worker const MojoHandle* handles, 72*635a8641SAndroid Build Coastguard Worker uint32_t num_handles, 73*635a8641SAndroid Build Coastguard Worker const struct MojoAppendMessageDataOptions* options, 74*635a8641SAndroid Build Coastguard Worker void** buffer, 75*635a8641SAndroid Build Coastguard Worker uint32_t* buffer_size); 76*635a8641SAndroid Build Coastguard Worker MojoResult (*GetMessageData)(MojoMessageHandle message, 77*635a8641SAndroid Build Coastguard Worker const struct MojoGetMessageDataOptions* options, 78*635a8641SAndroid Build Coastguard Worker void** buffer, 79*635a8641SAndroid Build Coastguard Worker uint32_t* num_bytes, 80*635a8641SAndroid Build Coastguard Worker MojoHandle* handles, 81*635a8641SAndroid Build Coastguard Worker uint32_t* num_handles); 82*635a8641SAndroid Build Coastguard Worker MojoResult (*SetMessageContext)( 83*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message, 84*635a8641SAndroid Build Coastguard Worker uintptr_t context, 85*635a8641SAndroid Build Coastguard Worker MojoMessageContextSerializer serializer, 86*635a8641SAndroid Build Coastguard Worker MojoMessageContextDestructor destructor, 87*635a8641SAndroid Build Coastguard Worker const struct MojoSetMessageContextOptions* options); 88*635a8641SAndroid Build Coastguard Worker MojoResult (*GetMessageContext)( 89*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message, 90*635a8641SAndroid Build Coastguard Worker const struct MojoGetMessageContextOptions* options, 91*635a8641SAndroid Build Coastguard Worker uintptr_t* context); 92*635a8641SAndroid Build Coastguard Worker MojoResult (*NotifyBadMessage)( 93*635a8641SAndroid Build Coastguard Worker MojoMessageHandle message, 94*635a8641SAndroid Build Coastguard Worker const char* error, 95*635a8641SAndroid Build Coastguard Worker uint32_t error_num_bytes, 96*635a8641SAndroid Build Coastguard Worker const struct MojoNotifyBadMessageOptions* options); 97*635a8641SAndroid Build Coastguard Worker 98*635a8641SAndroid Build Coastguard Worker // Data pipe API. 99*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateDataPipe)(const struct MojoCreateDataPipeOptions* options, 100*635a8641SAndroid Build Coastguard Worker MojoHandle* data_pipe_producer_handle, 101*635a8641SAndroid Build Coastguard Worker MojoHandle* data_pipe_consumer_handle); 102*635a8641SAndroid Build Coastguard Worker MojoResult (*WriteData)(MojoHandle data_pipe_producer_handle, 103*635a8641SAndroid Build Coastguard Worker const void* elements, 104*635a8641SAndroid Build Coastguard Worker uint32_t* num_elements, 105*635a8641SAndroid Build Coastguard Worker const struct MojoWriteDataOptions* options); 106*635a8641SAndroid Build Coastguard Worker MojoResult (*BeginWriteData)(MojoHandle data_pipe_producer_handle, 107*635a8641SAndroid Build Coastguard Worker const struct MojoBeginWriteDataOptions* options, 108*635a8641SAndroid Build Coastguard Worker void** buffer, 109*635a8641SAndroid Build Coastguard Worker uint32_t* buffer_num_elements); 110*635a8641SAndroid Build Coastguard Worker MojoResult (*EndWriteData)(MojoHandle data_pipe_producer_handle, 111*635a8641SAndroid Build Coastguard Worker uint32_t num_elements_written, 112*635a8641SAndroid Build Coastguard Worker const struct MojoEndWriteDataOptions* options); 113*635a8641SAndroid Build Coastguard Worker MojoResult (*ReadData)(MojoHandle data_pipe_consumer_handle, 114*635a8641SAndroid Build Coastguard Worker const struct MojoReadDataOptions* options, 115*635a8641SAndroid Build Coastguard Worker void* elements, 116*635a8641SAndroid Build Coastguard Worker uint32_t* num_elements); 117*635a8641SAndroid Build Coastguard Worker MojoResult (*BeginReadData)(MojoHandle data_pipe_consumer_handle, 118*635a8641SAndroid Build Coastguard Worker const struct MojoBeginReadDataOptions* options, 119*635a8641SAndroid Build Coastguard Worker const void** buffer, 120*635a8641SAndroid Build Coastguard Worker uint32_t* buffer_num_elements); 121*635a8641SAndroid Build Coastguard Worker MojoResult (*EndReadData)(MojoHandle data_pipe_consumer_handle, 122*635a8641SAndroid Build Coastguard Worker uint32_t num_elements_read, 123*635a8641SAndroid Build Coastguard Worker const struct MojoEndReadDataOptions* options); 124*635a8641SAndroid Build Coastguard Worker 125*635a8641SAndroid Build Coastguard Worker // Shared buffer API. 126*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateSharedBuffer)( 127*635a8641SAndroid Build Coastguard Worker uint64_t num_bytes, 128*635a8641SAndroid Build Coastguard Worker const struct MojoCreateSharedBufferOptions* options, 129*635a8641SAndroid Build Coastguard Worker MojoHandle* shared_buffer_handle); 130*635a8641SAndroid Build Coastguard Worker MojoResult (*DuplicateBufferHandle)( 131*635a8641SAndroid Build Coastguard Worker MojoHandle buffer_handle, 132*635a8641SAndroid Build Coastguard Worker const struct MojoDuplicateBufferHandleOptions* options, 133*635a8641SAndroid Build Coastguard Worker MojoHandle* new_buffer_handle); 134*635a8641SAndroid Build Coastguard Worker MojoResult (*MapBuffer)(MojoHandle buffer_handle, 135*635a8641SAndroid Build Coastguard Worker uint64_t offset, 136*635a8641SAndroid Build Coastguard Worker uint64_t num_bytes, 137*635a8641SAndroid Build Coastguard Worker const struct MojoMapBufferOptions* options, 138*635a8641SAndroid Build Coastguard Worker void** buffer); 139*635a8641SAndroid Build Coastguard Worker MojoResult (*UnmapBuffer)(void* buffer); 140*635a8641SAndroid Build Coastguard Worker MojoResult (*GetBufferInfo)(MojoHandle buffer_handle, 141*635a8641SAndroid Build Coastguard Worker const struct MojoGetBufferInfoOptions* options, 142*635a8641SAndroid Build Coastguard Worker struct MojoSharedBufferInfo* info); 143*635a8641SAndroid Build Coastguard Worker 144*635a8641SAndroid Build Coastguard Worker // Traps API. 145*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateTrap)(MojoTrapEventHandler handler, 146*635a8641SAndroid Build Coastguard Worker const struct MojoCreateTrapOptions* options, 147*635a8641SAndroid Build Coastguard Worker MojoHandle* trap_handle); 148*635a8641SAndroid Build Coastguard Worker MojoResult (*AddTrigger)(MojoHandle trap_handle, 149*635a8641SAndroid Build Coastguard Worker MojoHandle handle, 150*635a8641SAndroid Build Coastguard Worker MojoHandleSignals signals, 151*635a8641SAndroid Build Coastguard Worker MojoTriggerCondition condition, 152*635a8641SAndroid Build Coastguard Worker uintptr_t context, 153*635a8641SAndroid Build Coastguard Worker const struct MojoAddTriggerOptions* options); 154*635a8641SAndroid Build Coastguard Worker MojoResult (*RemoveTrigger)(MojoHandle trap_handle, 155*635a8641SAndroid Build Coastguard Worker uintptr_t context, 156*635a8641SAndroid Build Coastguard Worker const struct MojoRemoveTriggerOptions* options); 157*635a8641SAndroid Build Coastguard Worker MojoResult (*ArmTrap)(MojoHandle trap_handle, 158*635a8641SAndroid Build Coastguard Worker const struct MojoArmTrapOptions* options, 159*635a8641SAndroid Build Coastguard Worker uint32_t* num_blocking_events, 160*635a8641SAndroid Build Coastguard Worker struct MojoTrapEvent* blocking_events); 161*635a8641SAndroid Build Coastguard Worker 162*635a8641SAndroid Build Coastguard Worker // Platform handle API. 163*635a8641SAndroid Build Coastguard Worker MojoResult (*WrapPlatformHandle)( 164*635a8641SAndroid Build Coastguard Worker const struct MojoPlatformHandle* platform_handle, 165*635a8641SAndroid Build Coastguard Worker const struct MojoWrapPlatformHandleOptions* options, 166*635a8641SAndroid Build Coastguard Worker MojoHandle* mojo_handle); 167*635a8641SAndroid Build Coastguard Worker MojoResult (*UnwrapPlatformHandle)( 168*635a8641SAndroid Build Coastguard Worker MojoHandle mojo_handle, 169*635a8641SAndroid Build Coastguard Worker const MojoUnwrapPlatformHandleOptions* options, 170*635a8641SAndroid Build Coastguard Worker struct MojoPlatformHandle* platform_handle); 171*635a8641SAndroid Build Coastguard Worker MojoResult (*WrapPlatformSharedMemoryRegion)( 172*635a8641SAndroid Build Coastguard Worker const struct MojoPlatformHandle* platform_handles, 173*635a8641SAndroid Build Coastguard Worker uint32_t num_platform_handles, 174*635a8641SAndroid Build Coastguard Worker uint64_t num_bytes, 175*635a8641SAndroid Build Coastguard Worker const struct MojoSharedBufferGuid* guid, 176*635a8641SAndroid Build Coastguard Worker MojoPlatformSharedMemoryRegionAccessMode access_mode, 177*635a8641SAndroid Build Coastguard Worker const struct MojoWrapPlatformSharedMemoryRegionOptions* options, 178*635a8641SAndroid Build Coastguard Worker MojoHandle* mojo_handle); 179*635a8641SAndroid Build Coastguard Worker MojoResult (*UnwrapPlatformSharedMemoryRegion)( 180*635a8641SAndroid Build Coastguard Worker MojoHandle mojo_handle, 181*635a8641SAndroid Build Coastguard Worker const struct MojoUnwrapPlatformSharedMemoryRegionOptions* options, 182*635a8641SAndroid Build Coastguard Worker struct MojoPlatformHandle* platform_handles, 183*635a8641SAndroid Build Coastguard Worker uint32_t* num_platform_handles, 184*635a8641SAndroid Build Coastguard Worker uint64_t* num_bytes, 185*635a8641SAndroid Build Coastguard Worker struct MojoSharedBufferGuid* guid, 186*635a8641SAndroid Build Coastguard Worker MojoPlatformSharedMemoryRegionAccessMode* access_mode); 187*635a8641SAndroid Build Coastguard Worker 188*635a8641SAndroid Build Coastguard Worker // Invitation API. 189*635a8641SAndroid Build Coastguard Worker MojoResult (*CreateInvitation)( 190*635a8641SAndroid Build Coastguard Worker const struct MojoCreateInvitationOptions* options, 191*635a8641SAndroid Build Coastguard Worker MojoHandle* invitation_handle); 192*635a8641SAndroid Build Coastguard Worker MojoResult (*AttachMessagePipeToInvitation)( 193*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 194*635a8641SAndroid Build Coastguard Worker const void* name, 195*635a8641SAndroid Build Coastguard Worker uint32_t name_num_bytes, 196*635a8641SAndroid Build Coastguard Worker const MojoAttachMessagePipeToInvitationOptions* options, 197*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle); 198*635a8641SAndroid Build Coastguard Worker MojoResult (*ExtractMessagePipeFromInvitation)( 199*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 200*635a8641SAndroid Build Coastguard Worker const void* name, 201*635a8641SAndroid Build Coastguard Worker uint32_t name_num_bytes, 202*635a8641SAndroid Build Coastguard Worker const MojoExtractMessagePipeFromInvitationOptions* options, 203*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle); 204*635a8641SAndroid Build Coastguard Worker MojoResult (*SendInvitation)( 205*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 206*635a8641SAndroid Build Coastguard Worker const struct MojoPlatformProcessHandle* process_handle, 207*635a8641SAndroid Build Coastguard Worker const struct MojoInvitationTransportEndpoint* transport_endpoint, 208*635a8641SAndroid Build Coastguard Worker MojoProcessErrorHandler error_handler, 209*635a8641SAndroid Build Coastguard Worker uintptr_t error_handler_context, 210*635a8641SAndroid Build Coastguard Worker const struct MojoSendInvitationOptions* options); 211*635a8641SAndroid Build Coastguard Worker MojoResult (*AcceptInvitation)( 212*635a8641SAndroid Build Coastguard Worker const struct MojoInvitationTransportEndpoint* transport_endpoint, 213*635a8641SAndroid Build Coastguard Worker const struct MojoAcceptInvitationOptions* options, 214*635a8641SAndroid Build Coastguard Worker MojoHandle* invitation_handle); 215*635a8641SAndroid Build Coastguard Worker MojoResult (*SetQuota)(MojoHandle handle, 216*635a8641SAndroid Build Coastguard Worker MojoQuotaType type, 217*635a8641SAndroid Build Coastguard Worker uint64_t limit, 218*635a8641SAndroid Build Coastguard Worker const struct MojoSetQuotaOptions* options); 219*635a8641SAndroid Build Coastguard Worker MojoResult (*QueryQuota)(MojoHandle handle, 220*635a8641SAndroid Build Coastguard Worker MojoQuotaType type, 221*635a8641SAndroid Build Coastguard Worker const struct MojoQueryQuotaOptions* options, 222*635a8641SAndroid Build Coastguard Worker uint64_t* limit, 223*635a8641SAndroid Build Coastguard Worker uint64_t* usage); 224*635a8641SAndroid Build Coastguard Worker }; 225*635a8641SAndroid Build Coastguard Worker #pragma pack(pop) 226*635a8641SAndroid Build Coastguard Worker 227*635a8641SAndroid Build Coastguard Worker // A function for setting up the embedder's own system thunks. This should only 228*635a8641SAndroid Build Coastguard Worker // be called by Mojo embedder code. 229*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT void MojoEmbedderSetSystemThunks( 230*635a8641SAndroid Build Coastguard Worker const struct MojoSystemThunks* system_thunks); 231*635a8641SAndroid Build Coastguard Worker 232*635a8641SAndroid Build Coastguard Worker #endif // MOJO_PUBLIC_C_SYSTEM_THUNKS_H_ 233