1*635a8641SAndroid Build Coastguard Worker // Copyright 2018 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 // This file contains type and function definitions relevant to Mojo invitation 6*635a8641SAndroid Build Coastguard Worker // APIs. 7*635a8641SAndroid Build Coastguard Worker // 8*635a8641SAndroid Build Coastguard Worker // Note: This header should be compilable as C. 9*635a8641SAndroid Build Coastguard Worker 10*635a8641SAndroid Build Coastguard Worker #ifndef MOJO_PUBLIC_C_SYSTEM_INVITATION_H_ 11*635a8641SAndroid Build Coastguard Worker #define MOJO_PUBLIC_C_SYSTEM_INVITATION_H_ 12*635a8641SAndroid Build Coastguard Worker 13*635a8641SAndroid Build Coastguard Worker #include <stdint.h> 14*635a8641SAndroid Build Coastguard Worker 15*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/macros.h" 16*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/platform_handle.h" 17*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/system_export.h" 18*635a8641SAndroid Build Coastguard Worker #include "mojo/public/c/system/types.h" 19*635a8641SAndroid Build Coastguard Worker 20*635a8641SAndroid Build Coastguard Worker // Flags included in |MojoProcessErrorDetails| indicating additional status 21*635a8641SAndroid Build Coastguard Worker // information. 22*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoProcessErrorFlags; 23*635a8641SAndroid Build Coastguard Worker 24*635a8641SAndroid Build Coastguard Worker // No flags. 25*635a8641SAndroid Build Coastguard Worker #define MOJO_PROCESS_ERROR_FLAG_NONE ((MojoProcessErrorFlags)0) 26*635a8641SAndroid Build Coastguard Worker 27*635a8641SAndroid Build Coastguard Worker // If set, the process has been disconnected. No further 28*635a8641SAndroid Build Coastguard Worker // |MojoProcessErrorHandler| invocations occur for it, and any IPC primitives 29*635a8641SAndroid Build Coastguard Worker // (message pipes, data pipes) which were connected to it have been or will 30*635a8641SAndroid Build Coastguard Worker // imminently be disconnected. 31*635a8641SAndroid Build Coastguard Worker #define MOJO_PROCESS_ERROR_FLAG_DISCONNECTED ((MojoProcessErrorFlags)1) 32*635a8641SAndroid Build Coastguard Worker 33*635a8641SAndroid Build Coastguard Worker // Details regarding why an invited process has had its connection to this 34*635a8641SAndroid Build Coastguard Worker // process terminated by the system. See |MojoProcessErrorHandler| and 35*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()|. 36*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoProcessErrorDetails { 37*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 38*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 39*635a8641SAndroid Build Coastguard Worker 40*635a8641SAndroid Build Coastguard Worker // The length of the string pointed to by |error_message| below. 41*635a8641SAndroid Build Coastguard Worker uint32_t error_message_length; 42*635a8641SAndroid Build Coastguard Worker 43*635a8641SAndroid Build Coastguard Worker // An error message corresponding to the reason why the connection was 44*635a8641SAndroid Build Coastguard Worker // terminated. This is an information message which may be useful to 45*635a8641SAndroid Build Coastguard Worker // developers. 46*635a8641SAndroid Build Coastguard Worker MOJO_POINTER_FIELD(const char*, error_message); 47*635a8641SAndroid Build Coastguard Worker 48*635a8641SAndroid Build Coastguard Worker // See |MojoProcessErrorFlags|. 49*635a8641SAndroid Build Coastguard Worker MojoProcessErrorFlags flags; 50*635a8641SAndroid Build Coastguard Worker }; 51*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoProcessErrorDetails) == 24, 52*635a8641SAndroid Build Coastguard Worker "MojoProcessErrorDetails has wrong size."); 53*635a8641SAndroid Build Coastguard Worker 54*635a8641SAndroid Build Coastguard Worker // An opaque process handle value which must be provided when sending an 55*635a8641SAndroid Build Coastguard Worker // invitation to another process via a platform transport. See 56*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()|. 57*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoPlatformProcessHandle { 58*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 59*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 60*635a8641SAndroid Build Coastguard Worker 61*635a8641SAndroid Build Coastguard Worker // The process handle value. For Windows this is a valid process HANDLE value. 62*635a8641SAndroid Build Coastguard Worker // For Fuchsia it must be |zx_handle_t| process handle, and for all other 63*635a8641SAndroid Build Coastguard Worker // POSIX systems, it's a PID. 64*635a8641SAndroid Build Coastguard Worker uint64_t value; 65*635a8641SAndroid Build Coastguard Worker }; 66*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoPlatformProcessHandle) == 16, 67*635a8641SAndroid Build Coastguard Worker "MojoPlatformProcesHandle has wrong size."); 68*635a8641SAndroid Build Coastguard Worker 69*635a8641SAndroid Build Coastguard Worker // Enumeration indicating the type of transport over which an invitation will be 70*635a8641SAndroid Build Coastguard Worker // sent or received. 71*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoInvitationTransportType; 72*635a8641SAndroid Build Coastguard Worker 73*635a8641SAndroid Build Coastguard Worker // The channel transport type embodies common platform-specific OS primitives 74*635a8641SAndroid Build Coastguard Worker // for FIFO message passing: 75*635a8641SAndroid Build Coastguard Worker // - For Windows, this is a named pipe. 76*635a8641SAndroid Build Coastguard Worker // - For Fuchsia, it's a channel. 77*635a8641SAndroid Build Coastguard Worker // - For all other POSIX systems, it's a Unix domain socket pair. 78*635a8641SAndroid Build Coastguard Worker // 79*635a8641SAndroid Build Coastguard Worker // See |MojoInvitationTransportHandle| for details. 80*635a8641SAndroid Build Coastguard Worker #define MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL ((MojoInvitationTransportType)0) 81*635a8641SAndroid Build Coastguard Worker 82*635a8641SAndroid Build Coastguard Worker // Similar to CHANNEL transport, but used for an endpoint which requires an 83*635a8641SAndroid Build Coastguard Worker // additional step to accept an inbound connection. This corresponds to a 84*635a8641SAndroid Build Coastguard Worker // bound listening socket on POSIX, or named pipe server handle on Windows. 85*635a8641SAndroid Build Coastguard Worker // 86*635a8641SAndroid Build Coastguard Worker // The remote endpoint should establish a working connection to the server side 87*635a8641SAndroid Build Coastguard Worker // and wrap the handle to that connection using a CHANNEL transport. 88*635a8641SAndroid Build Coastguard Worker #define MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL_SERVER \ 89*635a8641SAndroid Build Coastguard Worker ((MojoInvitationTransportType)1) 90*635a8641SAndroid Build Coastguard Worker 91*635a8641SAndroid Build Coastguard Worker // A transport endpoint over which an invitation may be sent or received via 92*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()| or |MojoAcceptInvitation()| respectively. 93*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoInvitationTransportEndpoint { 94*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 95*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 96*635a8641SAndroid Build Coastguard Worker 97*635a8641SAndroid Build Coastguard Worker // The type of this transport endpoint. See |MojoInvitationTransportType|. 98*635a8641SAndroid Build Coastguard Worker MojoInvitationTransportType type; 99*635a8641SAndroid Build Coastguard Worker 100*635a8641SAndroid Build Coastguard Worker // The number of platform handles in |platform_handles| below. 101*635a8641SAndroid Build Coastguard Worker uint32_t num_platform_handles; 102*635a8641SAndroid Build Coastguard Worker 103*635a8641SAndroid Build Coastguard Worker // Platform handle(s) corresponding to the system object(s) backing this 104*635a8641SAndroid Build Coastguard Worker // endpoint. The concrete type of the handle(s) depends on |type|. 105*635a8641SAndroid Build Coastguard Worker // 106*635a8641SAndroid Build Coastguard Worker // For |MOJO_INVITATION_TRANSPORT_TYPE_CHANNEL| endpoints: 107*635a8641SAndroid Build Coastguard Worker // - On Windows, this is a single named pipe HANDLE 108*635a8641SAndroid Build Coastguard Worker // - On Fuchsua, this is a single channel Fuchsia handle 109*635a8641SAndroid Build Coastguard Worker // - On other POSIX systems, this is a single Unix domain socket file 110*635a8641SAndroid Build Coastguard Worker // descriptor. 111*635a8641SAndroid Build Coastguard Worker MOJO_POINTER_FIELD(const struct MojoPlatformHandle*, platform_handles); 112*635a8641SAndroid Build Coastguard Worker }; 113*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoInvitationTransportEndpoint) == 24, 114*635a8641SAndroid Build Coastguard Worker "MojoInvitationTransportEndpoint has wrong size."); 115*635a8641SAndroid Build Coastguard Worker 116*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoCreateInvitation()| via |MojoCreateInvitationOptions|. 117*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoCreateInvitationFlags; 118*635a8641SAndroid Build Coastguard Worker 119*635a8641SAndroid Build Coastguard Worker // No flags. Default behavior. 120*635a8641SAndroid Build Coastguard Worker #define MOJO_CREATE_INVITATION_FLAG_NONE ((MojoCreateInvitationFlags)0) 121*635a8641SAndroid Build Coastguard Worker 122*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoCreateInvitation()|. 123*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoCreateInvitationOptions { 124*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 125*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 126*635a8641SAndroid Build Coastguard Worker 127*635a8641SAndroid Build Coastguard Worker // See |MojoCreateInvitationFlags|. 128*635a8641SAndroid Build Coastguard Worker MojoCreateInvitationFlags flags; 129*635a8641SAndroid Build Coastguard Worker }; 130*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoCreateInvitationOptions) == 8, 131*635a8641SAndroid Build Coastguard Worker "MojoCreateInvitationOptions has wrong size"); 132*635a8641SAndroid Build Coastguard Worker 133*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoAttachMessagePipeToInvitation()| via 134*635a8641SAndroid Build Coastguard Worker // |MojoAttachMessagePipeToInvitationOptions|. 135*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoAttachMessagePipeToInvitationFlags; 136*635a8641SAndroid Build Coastguard Worker 137*635a8641SAndroid Build Coastguard Worker // No flags. Default behavior. 138*635a8641SAndroid Build Coastguard Worker #define MOJO_ATTACH_MESSAGE_PIPE_TO_INVITATION_FLAG_NONE \ 139*635a8641SAndroid Build Coastguard Worker ((MojoAttachMessagePipeToInvitationFlags)0) 140*635a8641SAndroid Build Coastguard Worker 141*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoAttachMessagePipeToInvitation()|. 142*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoAttachMessagePipeToInvitationOptions { 143*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 144*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 145*635a8641SAndroid Build Coastguard Worker 146*635a8641SAndroid Build Coastguard Worker // See |MojoAttachMessagePipeToInvitationFlags|. 147*635a8641SAndroid Build Coastguard Worker MojoAttachMessagePipeToInvitationFlags flags; 148*635a8641SAndroid Build Coastguard Worker }; 149*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoAttachMessagePipeToInvitationOptions) == 8, 150*635a8641SAndroid Build Coastguard Worker "MojoAttachMessagePipeToInvitationOptions has wrong size"); 151*635a8641SAndroid Build Coastguard Worker 152*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoExtractMessagePipeFromInvitation()| via 153*635a8641SAndroid Build Coastguard Worker // |MojoExtractMessagePipeFromInvitationOptions|. 154*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoExtractMessagePipeFromInvitationFlags; 155*635a8641SAndroid Build Coastguard Worker 156*635a8641SAndroid Build Coastguard Worker // No flags. Default behavior. 157*635a8641SAndroid Build Coastguard Worker #define MOJO_EXTRACT_MESSAGE_PIPE_FROM_INVITATION_FLAG_NONE \ 158*635a8641SAndroid Build Coastguard Worker ((MojoExtractMessagePipeFromInvitationFlags)0) 159*635a8641SAndroid Build Coastguard Worker 160*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoExtractMessagePipeFromInvitation()|. 161*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoExtractMessagePipeFromInvitationOptions { 162*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 163*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 164*635a8641SAndroid Build Coastguard Worker 165*635a8641SAndroid Build Coastguard Worker // See |MojoExtractMessagePipeFromInvitationFlags|. 166*635a8641SAndroid Build Coastguard Worker MojoExtractMessagePipeFromInvitationFlags flags; 167*635a8641SAndroid Build Coastguard Worker }; 168*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT( 169*635a8641SAndroid Build Coastguard Worker sizeof(MojoExtractMessagePipeFromInvitationOptions) == 8, 170*635a8641SAndroid Build Coastguard Worker "MojoExtractMessagePipeFromInvitationOptions has wrong size"); 171*635a8641SAndroid Build Coastguard Worker 172*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoSendInvitation()| via |MojoSendInvitationOptions|. 173*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoSendInvitationFlags; 174*635a8641SAndroid Build Coastguard Worker 175*635a8641SAndroid Build Coastguard Worker // No flags. Default behavior. 176*635a8641SAndroid Build Coastguard Worker #define MOJO_SEND_INVITATION_FLAG_NONE ((MojoSendInvitationFlags)0) 177*635a8641SAndroid Build Coastguard Worker 178*635a8641SAndroid Build Coastguard Worker // Send an isolated invitation to the receiver. Isolated invitations only 179*635a8641SAndroid Build Coastguard Worker // establish communication between the sender and the receiver. Accepting an 180*635a8641SAndroid Build Coastguard Worker // isolated invitation does not make IPC possible between the sender and any 181*635a8641SAndroid Build Coastguard Worker // other members of the receiver's process graph, nor does it make IPC possible 182*635a8641SAndroid Build Coastguard Worker // between the receiver and any other members of the sender's process graph. 183*635a8641SAndroid Build Coastguard Worker // 184*635a8641SAndroid Build Coastguard Worker // Invitations sent with this flag set must be accepted with the corresponding 185*635a8641SAndroid Build Coastguard Worker // |MOJO_ACCEPT_INVITATION_FLAG_ISOLATED| flag set, and may only have a single 186*635a8641SAndroid Build Coastguard Worker // message pipe attached with a name of exactly four zero-bytes ("\0\0\0\0"). 187*635a8641SAndroid Build Coastguard Worker #define MOJO_SEND_INVITATION_FLAG_ISOLATED ((MojoSendInvitationFlags)1) 188*635a8641SAndroid Build Coastguard Worker 189*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoSendInvitation()|. 190*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoSendInvitationOptions { 191*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 192*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 193*635a8641SAndroid Build Coastguard Worker 194*635a8641SAndroid Build Coastguard Worker // See |MojoSendInvitationFlags|. 195*635a8641SAndroid Build Coastguard Worker MojoSendInvitationFlags flags; 196*635a8641SAndroid Build Coastguard Worker 197*635a8641SAndroid Build Coastguard Worker // If |flags| includes |MOJO_SEND_INVITATION_FLAG_ISOLATED| then these fields 198*635a8641SAndroid Build Coastguard Worker // specify a name identifying the established isolated connection. There are 199*635a8641SAndroid Build Coastguard Worker // no restrictions on the value given. If |isolated_connection_name_length| is 200*635a8641SAndroid Build Coastguard Worker // non-zero, the system ensures that only one isolated process connection can 201*635a8641SAndroid Build Coastguard Worker // exist for the given name at any time. 202*635a8641SAndroid Build Coastguard Worker MOJO_POINTER_FIELD(const char*, isolated_connection_name); 203*635a8641SAndroid Build Coastguard Worker uint32_t isolated_connection_name_length; 204*635a8641SAndroid Build Coastguard Worker }; 205*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoSendInvitationOptions) == 24, 206*635a8641SAndroid Build Coastguard Worker "MojoSendInvitationOptions has wrong size"); 207*635a8641SAndroid Build Coastguard Worker 208*635a8641SAndroid Build Coastguard Worker // Flags passed to |MojoAcceptInvitation()| via |MojoAcceptInvitationOptions|. 209*635a8641SAndroid Build Coastguard Worker typedef uint32_t MojoAcceptInvitationFlags; 210*635a8641SAndroid Build Coastguard Worker 211*635a8641SAndroid Build Coastguard Worker // No flags. Default behavior. 212*635a8641SAndroid Build Coastguard Worker #define MOJO_ACCEPT_INVITATION_FLAG_NONE ((MojoAcceptInvitationFlags)0) 213*635a8641SAndroid Build Coastguard Worker 214*635a8641SAndroid Build Coastguard Worker // Accept an isoalted invitation from the sender. See 215*635a8641SAndroid Build Coastguard Worker // |MOJO_SEND_INVITATION_FLAG_ISOLATED| for details. 216*635a8641SAndroid Build Coastguard Worker #define MOJO_ACCEPT_INVITATION_FLAG_ISOLATED ((MojoAcceptInvitationFlags)1) 217*635a8641SAndroid Build Coastguard Worker 218*635a8641SAndroid Build Coastguard Worker // Options passed to |MojoAcceptInvitation()|. 219*635a8641SAndroid Build Coastguard Worker struct MOJO_ALIGNAS(8) MojoAcceptInvitationOptions { 220*635a8641SAndroid Build Coastguard Worker // The size of this structure, used for versioning. 221*635a8641SAndroid Build Coastguard Worker uint32_t struct_size; 222*635a8641SAndroid Build Coastguard Worker 223*635a8641SAndroid Build Coastguard Worker // See |MojoAcceptInvitationFlags|. 224*635a8641SAndroid Build Coastguard Worker MojoAcceptInvitationFlags flags; 225*635a8641SAndroid Build Coastguard Worker }; 226*635a8641SAndroid Build Coastguard Worker MOJO_STATIC_ASSERT(sizeof(MojoAcceptInvitationOptions) == 8, 227*635a8641SAndroid Build Coastguard Worker "MojoAcceptInvitationOptions has wrong size"); 228*635a8641SAndroid Build Coastguard Worker 229*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus 230*635a8641SAndroid Build Coastguard Worker extern "C" { 231*635a8641SAndroid Build Coastguard Worker #endif 232*635a8641SAndroid Build Coastguard Worker 233*635a8641SAndroid Build Coastguard Worker // A callback which may be invoked by the system when a connection to an invited 234*635a8641SAndroid Build Coastguard Worker // process is terminated due to a communication error (i.e. the invited process 235*635a8641SAndroid Build Coastguard Worker // has sent a message which fails some validation check in the system). See 236*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()|. 237*635a8641SAndroid Build Coastguard Worker // 238*635a8641SAndroid Build Coastguard Worker // |context| is the value of |context| given to |MojoSendInvitation()| when 239*635a8641SAndroid Build Coastguard Worker // inviting the process for whom this callback is being invoked. 240*635a8641SAndroid Build Coastguard Worker typedef void (*MojoProcessErrorHandler)( 241*635a8641SAndroid Build Coastguard Worker uintptr_t context, 242*635a8641SAndroid Build Coastguard Worker const struct MojoProcessErrorDetails* details); 243*635a8641SAndroid Build Coastguard Worker 244*635a8641SAndroid Build Coastguard Worker // Creates a new invitation to be sent to another process. 245*635a8641SAndroid Build Coastguard Worker // 246*635a8641SAndroid Build Coastguard Worker // An invitation is used to invite another process to join this process's 247*635a8641SAndroid Build Coastguard Worker // IPC network. The caller must already be a member of a Mojo network, either 248*635a8641SAndroid Build Coastguard Worker // either by itself having been previously invited, or by being the Mojo broker 249*635a8641SAndroid Build Coastguard Worker // process initialized via the Mojo Core Embedder API. 250*635a8641SAndroid Build Coastguard Worker // 251*635a8641SAndroid Build Coastguard Worker // Invitations can have message pipes attached to them, and these message pipes 252*635a8641SAndroid Build Coastguard Worker // are used to bootstrap Mojo IPC between the inviter and the invitee. See 253*635a8641SAndroid Build Coastguard Worker // |MojoAttachMessagePipeToInvitation()| for attaching message pipes, and 254*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()| for sending an invitation. 255*635a8641SAndroid Build Coastguard Worker // 256*635a8641SAndroid Build Coastguard Worker // |options| controls behavior. May be null for default behavior. 257*635a8641SAndroid Build Coastguard Worker // |invitation_handle| must be the address of storage for a MojoHandle value 258*635a8641SAndroid Build Coastguard Worker // to be output upon success. 259*635a8641SAndroid Build Coastguard Worker // 260*635a8641SAndroid Build Coastguard Worker // NOTE: If discarding an invitation instead of sending it with 261*635a8641SAndroid Build Coastguard Worker // |MojoSendInvitation()|, you must close its handle (i.e. |MojoClose()|) to 262*635a8641SAndroid Build Coastguard Worker // avoid leaking associated system resources. 263*635a8641SAndroid Build Coastguard Worker // 264*635a8641SAndroid Build Coastguard Worker // Returns: 265*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_OK| if the invitation was created successfully. The new 266*635a8641SAndroid Build Coastguard Worker // invitation's handle is stored in |*invitation_handle| before returning. 267*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if |options| was non-null but malformed. 268*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a handle could not be allocated for the 269*635a8641SAndroid Build Coastguard Worker // new invitation. 270*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult 271*635a8641SAndroid Build Coastguard Worker MojoCreateInvitation(const struct MojoCreateInvitationOptions* options, 272*635a8641SAndroid Build Coastguard Worker MojoHandle* invitation_handle); 273*635a8641SAndroid Build Coastguard Worker 274*635a8641SAndroid Build Coastguard Worker // Attaches a message pipe endpoint to an invitation. 275*635a8641SAndroid Build Coastguard Worker // 276*635a8641SAndroid Build Coastguard Worker // This creates a new message pipe which will span the boundary between the 277*635a8641SAndroid Build Coastguard Worker // calling process and the invitation's eventual target process. One end of the 278*635a8641SAndroid Build Coastguard Worker // new pipe is attached to the invitation while the other end is returned to the 279*635a8641SAndroid Build Coastguard Worker // caller. Every attached message pipe has an arbitrary |name| value which 280*635a8641SAndroid Build Coastguard Worker // identifies it within the invitation. 281*635a8641SAndroid Build Coastguard Worker // 282*635a8641SAndroid Build Coastguard Worker // Message pipes can be extracted by the recipient by calling 283*635a8641SAndroid Build Coastguard Worker // |MojoExtractMessagePipeFromInvitation()|. It is up to applications to 284*635a8641SAndroid Build Coastguard Worker // communicate out-of-band or establish a convention for how attached pipes 285*635a8641SAndroid Build Coastguard Worker // are named. 286*635a8641SAndroid Build Coastguard Worker // 287*635a8641SAndroid Build Coastguard Worker // |invitation_handle| is the invitation to which a pipe should be attached. 288*635a8641SAndroid Build Coastguard Worker // |name| is an arbitrary name to give this pipe, required to extract the pipe 289*635a8641SAndroid Build Coastguard Worker // on the receiving end of the invitation. Note that the name is scoped to 290*635a8641SAndroid Build Coastguard Worker // this invitation only, so e.g. multiple invitations may attach pipes with 291*635a8641SAndroid Build Coastguard Worker // the name "foo", but any given invitation may only have a single pipe 292*635a8641SAndroid Build Coastguard Worker // attached with that name. 293*635a8641SAndroid Build Coastguard Worker // |name_num_bytes| is the number of bytes from |name| to use as the name. 294*635a8641SAndroid Build Coastguard Worker // |options| controls behavior. May be null for default behavior. 295*635a8641SAndroid Build Coastguard Worker // |message_pipe_handle| is the address of storage for a MojoHandle value. 296*635a8641SAndroid Build Coastguard Worker // Upon success, the handle of the local endpoint of the new message pipe 297*635a8641SAndroid Build Coastguard Worker // will be stored here. 298*635a8641SAndroid Build Coastguard Worker // 299*635a8641SAndroid Build Coastguard Worker // Returns: 300*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_OK| if the pipe was created and attached successfully. The 301*635a8641SAndroid Build Coastguard Worker // local endpoint of the pipe has its handle stored in 302*635a8641SAndroid Build Coastguard Worker // |*message_pipe_handle| before returning. The other endpoint is attached 303*635a8641SAndroid Build Coastguard Worker // to the invitation. 304*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if |invitation_handle| was not an invitation 305*635a8641SAndroid Build Coastguard Worker // handle, |options| was non-null but malformed, or |message_pipe_handle| 306*635a8641SAndroid Build Coastguard Worker // was null. 307*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_ALREADY_EXISTS| if |name| was already in use for this 308*635a8641SAndroid Build Coastguard Worker // invitation. 309*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a handle could not be allocated for the 310*635a8641SAndroid Build Coastguard Worker // new local message pipe endpoint. 311*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult MojoAttachMessagePipeToInvitation( 312*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 313*635a8641SAndroid Build Coastguard Worker const void* name, 314*635a8641SAndroid Build Coastguard Worker uint32_t name_num_bytes, 315*635a8641SAndroid Build Coastguard Worker const struct MojoAttachMessagePipeToInvitationOptions* options, 316*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle); 317*635a8641SAndroid Build Coastguard Worker 318*635a8641SAndroid Build Coastguard Worker // Extracts a message pipe endpoint from an invitation. 319*635a8641SAndroid Build Coastguard Worker // 320*635a8641SAndroid Build Coastguard Worker // |invitation_handle| is the invitation from which to extract the endpoint. 321*635a8641SAndroid Build Coastguard Worker // |name| is the name of the endpoint within the invitation. This corresponds 322*635a8641SAndroid Build Coastguard Worker // to the name that was given to |MojoAttachMessagePipeToInvitation()| when 323*635a8641SAndroid Build Coastguard Worker // the endpoint was attached. 324*635a8641SAndroid Build Coastguard Worker // |name_num_bytes| is the number of bytes from |name| to use as the name. 325*635a8641SAndroid Build Coastguard Worker // |options| controls behavior. May be null for default behavior. 326*635a8641SAndroid Build Coastguard Worker // |message_pipe_handle| is the address of storage for a MojoHandle value. 327*635a8641SAndroid Build Coastguard Worker // Upon success, the handle of the extracted message pipe endpoint will be 328*635a8641SAndroid Build Coastguard Worker // stored here. 329*635a8641SAndroid Build Coastguard Worker // 330*635a8641SAndroid Build Coastguard Worker // Note that it is possible to extract an endpoint from an invitation even 331*635a8641SAndroid Build Coastguard Worker // before the invitation has been sent to a remote process. If this is done and 332*635a8641SAndroid Build Coastguard Worker // then the invitation is sent, the receiver will not see this endpoint as it 333*635a8641SAndroid Build Coastguard Worker // will no longer be attached. 334*635a8641SAndroid Build Coastguard Worker // 335*635a8641SAndroid Build Coastguard Worker // Returns: 336*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_OK| if a new local message pipe endpoint was successfully 337*635a8641SAndroid Build Coastguard Worker // created and returned in |*message_pipe_handle|. Note that the 338*635a8641SAndroid Build Coastguard Worker // association of this endpoint with an invitation attachment is 339*635a8641SAndroid Build Coastguard Worker // necessarily an asynchronous operation, and it is not known at return 340*635a8641SAndroid Build Coastguard Worker // whether an attachment named |name| actually exists on the invitation. 341*635a8641SAndroid Build Coastguard Worker // As such, the operation may still fail eventually, resuling in a broken 342*635a8641SAndroid Build Coastguard Worker // pipe, i.e. the extracted pipe will signal peer closure. 343*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if |invitation_handle| was not an invitation 344*635a8641SAndroid Build Coastguard Worker // handle, |options| was non-null but malformed, or |message_pipe_handle| 345*635a8641SAndroid Build Coastguard Worker // was null. 346*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_RESOURCE_EXHAUSTED| if a handle could not be allocated for the 347*635a8641SAndroid Build Coastguard Worker // new local message pipe endpoint. 348*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_NOT_FOUND| if it is known at call time that there is no pipe 349*635a8641SAndroid Build Coastguard Worker // named |name| attached to the invitation. This is possible if the 350*635a8641SAndroid Build Coastguard Worker // invtation was created within the calling process by 351*635a8641SAndroid Build Coastguard Worker // |MojoCreateInvitation()|. 352*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult MojoExtractMessagePipeFromInvitation( 353*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 354*635a8641SAndroid Build Coastguard Worker const void* name, 355*635a8641SAndroid Build Coastguard Worker uint32_t name_num_bytes, 356*635a8641SAndroid Build Coastguard Worker const struct MojoExtractMessagePipeFromInvitationOptions* options, 357*635a8641SAndroid Build Coastguard Worker MojoHandle* message_pipe_handle); 358*635a8641SAndroid Build Coastguard Worker 359*635a8641SAndroid Build Coastguard Worker // Sends an invitation on a transport endpoint to bootstrap IPC between the 360*635a8641SAndroid Build Coastguard Worker // calling process and another process. 361*635a8641SAndroid Build Coastguard Worker // 362*635a8641SAndroid Build Coastguard Worker // |invitation_handle| is the handle of the invitation to send. 363*635a8641SAndroid Build Coastguard Worker // |process_handle| is an opaque, platform-specific handle to the remote 364*635a8641SAndroid Build Coastguard Worker // process. See |MojoPlatformProcessHandle|. This is not necessarily 365*635a8641SAndroid Build Coastguard Worker // required to be a valid process handle, but on some platforms (namely 366*635a8641SAndroid Build Coastguard Worker // Windows and Mac) it's important if the invitation target will need to 367*635a8641SAndroid Build Coastguard Worker // send or receive any kind of platform handles (including shared memory) 368*635a8641SAndroid Build Coastguard Worker // over Mojo message pipes. 369*635a8641SAndroid Build Coastguard Worker // |transport_endpoint| is one endpoint of a platform transport primitive, the 370*635a8641SAndroid Build Coastguard Worker // other endpoint of which should be established within the process 371*635a8641SAndroid Build Coastguard Worker // corresponding to |*process_handle|. See |MojoInvitationTransportEndpoint| 372*635a8641SAndroid Build Coastguard Worker // for details. 373*635a8641SAndroid Build Coastguard Worker // |error_handler| is a function to invoke if the connection to the invitee 374*635a8641SAndroid Build Coastguard Worker // encounters any kind of error condition, e.g. a message validation failure 375*635a8641SAndroid Build Coastguard Worker // reported by |MojoNotifyBadMessage()|, or permanent disconnection. See 376*635a8641SAndroid Build Coastguard Worker // |MojoProcessErrorDetails| for more information. 377*635a8641SAndroid Build Coastguard Worker // |error_handler_context| is an arbitrary value to be associated with this 378*635a8641SAndroid Build Coastguard Worker // process invitation. This value is passed as the |context| argument to 379*635a8641SAndroid Build Coastguard Worker // |error_handler| when invoked regarding this invitee. 380*635a8641SAndroid Build Coastguard Worker // |options| controls behavior. May be null for default behavior. 381*635a8641SAndroid Build Coastguard Worker // 382*635a8641SAndroid Build Coastguard Worker // This assumes ownership of any platform handles in |transport_endpoint| if 383*635a8641SAndroid Build Coastguard Worker // and only if returning |MOJO_RESULT_OK|. In that case, |invitation_handle| is 384*635a8641SAndroid Build Coastguard Worker // also invalidated. 385*635a8641SAndroid Build Coastguard Worker // 386*635a8641SAndroid Build Coastguard Worker // NOTE: It's pointless to send an invitation without at least one message pipe 387*635a8641SAndroid Build Coastguard Worker // attached, so it is considered an error to attempt to do so. 388*635a8641SAndroid Build Coastguard Worker // 389*635a8641SAndroid Build Coastguard Worker // Returns: 390*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_OK| if the invitation was successfully sent over the 391*635a8641SAndroid Build Coastguard Worker // transport. |invitation_handle| is implicitly closed. Note that this 392*635a8641SAndroid Build Coastguard Worker // does not guarantee that the invitation has been received by the target 393*635a8641SAndroid Build Coastguard Worker // yet, or that it ever will be (e.g. the target process may terminate 394*635a8641SAndroid Build Coastguard Worker // first or simply fail to accept the invitation). 395*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if |invitation_handle| was not an invitation 396*635a8641SAndroid Build Coastguard Worker // handle, |transport_endpoint| was null or malformed, or |options| was 397*635a8641SAndroid Build Coastguard Worker // non-null but malformed. 398*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_ABORTED| if the system failed to issue any necessary 399*635a8641SAndroid Build Coastguard Worker // communication via |transport_endpoint|, possibly due to a configuration 400*635a8641SAndroid Build Coastguard Worker // issue with the endpoint. The caller may attempt to correct this 401*635a8641SAndroid Build Coastguard Worker // situation and call again. 402*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_FAILED_PRECONDITION| if there were no message pipes attached 403*635a8641SAndroid Build Coastguard Worker // to the invitation. The caller may correct this situation and call 404*635a8641SAndroid Build Coastguard Worker // again. 405*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_UNIMPLEMENTED| if the transport endpoint type is not supported 406*635a8641SAndroid Build Coastguard Worker // by the system's version of Mojo. 407*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult MojoSendInvitation( 408*635a8641SAndroid Build Coastguard Worker MojoHandle invitation_handle, 409*635a8641SAndroid Build Coastguard Worker const struct MojoPlatformProcessHandle* process_handle, 410*635a8641SAndroid Build Coastguard Worker const struct MojoInvitationTransportEndpoint* transport_endpoint, 411*635a8641SAndroid Build Coastguard Worker MojoProcessErrorHandler error_handler, 412*635a8641SAndroid Build Coastguard Worker uintptr_t error_handler_context, 413*635a8641SAndroid Build Coastguard Worker const struct MojoSendInvitationOptions* options); 414*635a8641SAndroid Build Coastguard Worker 415*635a8641SAndroid Build Coastguard Worker // Accepts an invitation from a transport endpoint to complete IPC bootstrapping 416*635a8641SAndroid Build Coastguard Worker // between the calling process and whoever sent the invitation from the other 417*635a8641SAndroid Build Coastguard Worker // end of the transport. 418*635a8641SAndroid Build Coastguard Worker // 419*635a8641SAndroid Build Coastguard Worker // |transport_endpoint| is one endpoint of a platform transport primitive, the 420*635a8641SAndroid Build Coastguard Worker // other endpoint of which should be established within a process 421*635a8641SAndroid Build Coastguard Worker // who has sent or will send an invitation via that endpoint. See 422*635a8641SAndroid Build Coastguard Worker // |MojoInvitationTransportEndpoint| for details. 423*635a8641SAndroid Build Coastguard Worker // |options| controls behavior. May be null for default behavior. 424*635a8641SAndroid Build Coastguard Worker // |invitation_handle| is the address of storage for a MojoHandle value. Upon 425*635a8641SAndroid Build Coastguard Worker // success, the handle of the accepted invitation will be stored here. 426*635a8641SAndroid Build Coastguard Worker // 427*635a8641SAndroid Build Coastguard Worker // Once an invitation is accepted, message pipes endpoints may be extracted from 428*635a8641SAndroid Build Coastguard Worker // it by calling |MojoExtractMessagePipeFromInvitation()|. 429*635a8641SAndroid Build Coastguard Worker // 430*635a8641SAndroid Build Coastguard Worker // Note that it is necessary to eventually close (i.e. |MojoClose()|) any 431*635a8641SAndroid Build Coastguard Worker // accepted invitation handle in order to clean up any associated system 432*635a8641SAndroid Build Coastguard Worker // resources. If an accepted invitation is closed while it still has message 433*635a8641SAndroid Build Coastguard Worker // pipes attached (i.e. not exracted as above), those pipe endpoints are also 434*635a8641SAndroid Build Coastguard Worker // closed. 435*635a8641SAndroid Build Coastguard Worker // 436*635a8641SAndroid Build Coastguard Worker // Returns: 437*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_OK| if the invitation was successfully accepted. The handle 438*635a8641SAndroid Build Coastguard Worker // to the invitation is stored in |*invitation_handle| before returning. 439*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_INVALID_ARGUMENT| if |transport_endpoint| was null or 440*635a8641SAndroid Build Coastguard Worker // malfored, |options| was non-null but malformed, or |invitation_handle| 441*635a8641SAndroid Build Coastguard Worker // was null. 442*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_ABORTED| if the system failed to receive any communication via 443*635a8641SAndroid Build Coastguard Worker // |transport_endpoint|, possibly due to some configuration error. The 444*635a8641SAndroid Build Coastguard Worker // caller may attempt to correct this situation and call again. 445*635a8641SAndroid Build Coastguard Worker // |MOJO_RESULT_UNIMPLEMENTED| if the transport endpoint type is not supported 446*635a8641SAndroid Build Coastguard Worker // by the system's version of Mojo. 447*635a8641SAndroid Build Coastguard Worker MOJO_SYSTEM_EXPORT MojoResult MojoAcceptInvitation( 448*635a8641SAndroid Build Coastguard Worker const struct MojoInvitationTransportEndpoint* transport_endpoint, 449*635a8641SAndroid Build Coastguard Worker const struct MojoAcceptInvitationOptions* options, 450*635a8641SAndroid Build Coastguard Worker MojoHandle* invitation_handle); 451*635a8641SAndroid Build Coastguard Worker 452*635a8641SAndroid Build Coastguard Worker #ifdef __cplusplus 453*635a8641SAndroid Build Coastguard Worker } // extern "C" 454*635a8641SAndroid Build Coastguard Worker #endif 455*635a8641SAndroid Build Coastguard Worker 456*635a8641SAndroid Build Coastguard Worker #endif // MOJO_PUBLIC_C_SYSTEM_INVITATION_H_ 457