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