OLD | NEW |
(Empty) | |
| 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_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |
| 8 #define MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |
| 9 |
| 10 #include <stddef.h> |
| 11 #include <stdint.h> |
| 12 |
| 13 #include "mojo/public/c/system/core.h" |
| 14 |
| 15 // The embedder needs to bind the basic Mojo Core functions of a DSO to those of |
| 16 // the embedder when loading a DSO that is dependent on mojo_system. |
| 17 // The typical usage would look like: |
| 18 // base::ScopedNativeLibrary app_library( |
| 19 // base::LoadNativeLibrary(app_path_, &error)); |
| 20 // typedef MojoResult (*MojoSetSystemThunksFn)(MojoSystemThunks*); |
| 21 // MojoSetSystemThunksFn mojo_set_system_thunks_fn = |
| 22 // reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( |
| 23 // "MojoSetSystemThunks")); |
| 24 // MojoSystemThunks system_thunks = MojoMakeSystemThunks(); |
| 25 // size_t expected_size = mojo_set_system_thunks_fn(&system_thunks); |
| 26 // if (expected_size > sizeof(MojoSystemThunks)) { |
| 27 // LOG(ERROR) |
| 28 // << "Invalid DSO. Expected MojoSystemThunks size: " |
| 29 // << expected_size; |
| 30 // break; |
| 31 // } |
| 32 |
| 33 // Structure used to bind the basic Mojo Core functions of a DSO to those of |
| 34 // the embedder. |
| 35 // This is the ABI between the embedder and the DSO. It can only have new |
| 36 // functions added to the end. No other changes are supported. |
| 37 #pragma pack(push, 8) |
| 38 struct MojoSystemThunks { |
| 39 size_t size; // Should be set to sizeof(MojoSystemThunks). |
| 40 MojoTimeTicks (*GetTimeTicksNow)(); |
| 41 MojoResult (*Close)(MojoHandle handle); |
| 42 MojoResult (*Wait)(MojoHandle handle, |
| 43 MojoHandleSignals signals, |
| 44 MojoDeadline deadline, |
| 45 struct MojoHandleSignalsState* signals_state); |
| 46 MojoResult (*WaitMany)(const MojoHandle* handles, |
| 47 const MojoHandleSignals* signals, |
| 48 uint32_t num_handles, |
| 49 MojoDeadline deadline, |
| 50 uint32_t* result_index, |
| 51 struct MojoHandleSignalsState* signals_states); |
| 52 MojoResult (*CreateMessagePipe)( |
| 53 const struct MojoCreateMessagePipeOptions* options, |
| 54 MojoHandle* message_pipe_handle0, |
| 55 MojoHandle* message_pipe_handle1); |
| 56 MojoResult (*WriteMessage)(MojoHandle message_pipe_handle, |
| 57 const void* bytes, |
| 58 uint32_t num_bytes, |
| 59 const MojoHandle* handles, |
| 60 uint32_t num_handles, |
| 61 MojoWriteMessageFlags flags); |
| 62 MojoResult (*ReadMessage)(MojoHandle message_pipe_handle, |
| 63 void* bytes, |
| 64 uint32_t* num_bytes, |
| 65 MojoHandle* handles, |
| 66 uint32_t* num_handles, |
| 67 MojoReadMessageFlags flags); |
| 68 MojoResult (*CreateDataPipe)(const struct MojoCreateDataPipeOptions* options, |
| 69 MojoHandle* data_pipe_producer_handle, |
| 70 MojoHandle* data_pipe_consumer_handle); |
| 71 MojoResult (*WriteData)(MojoHandle data_pipe_producer_handle, |
| 72 const void* elements, |
| 73 uint32_t* num_elements, |
| 74 MojoWriteDataFlags flags); |
| 75 MojoResult (*BeginWriteData)(MojoHandle data_pipe_producer_handle, |
| 76 void** buffer, |
| 77 uint32_t* buffer_num_elements, |
| 78 MojoWriteDataFlags flags); |
| 79 MojoResult (*EndWriteData)(MojoHandle data_pipe_producer_handle, |
| 80 uint32_t num_elements_written); |
| 81 MojoResult (*ReadData)(MojoHandle data_pipe_consumer_handle, |
| 82 void* elements, |
| 83 uint32_t* num_elements, |
| 84 MojoReadDataFlags flags); |
| 85 MojoResult (*BeginReadData)(MojoHandle data_pipe_consumer_handle, |
| 86 const void** buffer, |
| 87 uint32_t* buffer_num_elements, |
| 88 MojoReadDataFlags flags); |
| 89 MojoResult (*EndReadData)(MojoHandle data_pipe_consumer_handle, |
| 90 uint32_t num_elements_read); |
| 91 MojoResult (*CreateSharedBuffer)( |
| 92 const struct MojoCreateSharedBufferOptions* options, |
| 93 uint64_t num_bytes, |
| 94 MojoHandle* shared_buffer_handle); |
| 95 MojoResult (*DuplicateBufferHandle)( |
| 96 MojoHandle buffer_handle, |
| 97 const struct MojoDuplicateBufferHandleOptions* options, |
| 98 MojoHandle* new_buffer_handle); |
| 99 MojoResult (*MapBuffer)(MojoHandle buffer_handle, |
| 100 uint64_t offset, |
| 101 uint64_t num_bytes, |
| 102 void** buffer, |
| 103 MojoMapBufferFlags flags); |
| 104 MojoResult (*UnmapBuffer)(void* buffer); |
| 105 |
| 106 MojoResult (*CreateWaitSet)(MojoHandle* wait_set); |
| 107 MojoResult (*AddHandle)(MojoHandle wait_set, |
| 108 MojoHandle handle, |
| 109 MojoHandleSignals signals); |
| 110 MojoResult (*RemoveHandle)(MojoHandle wait_set, |
| 111 MojoHandle handle); |
| 112 MojoResult (*GetReadyHandles)(MojoHandle wait_set, |
| 113 uint32_t* count, |
| 114 MojoHandle* handles, |
| 115 MojoResult* results, |
| 116 struct MojoHandleSignalsState* signals_states); |
| 117 MojoResult (*Watch)(MojoHandle handle, |
| 118 MojoHandleSignals signals, |
| 119 MojoWatchCallback callback, |
| 120 uintptr_t context); |
| 121 MojoResult (*CancelWatch)(MojoHandle handle, uintptr_t context); |
| 122 MojoResult (*FuseMessagePipes)(MojoHandle handle0, MojoHandle handle1); |
| 123 MojoResult (*WriteMessageNew)(MojoHandle message_pipe_handle, |
| 124 MojoMessageHandle message, |
| 125 MojoWriteMessageFlags flags); |
| 126 MojoResult (*ReadMessageNew)(MojoHandle message_pipe_handle, |
| 127 MojoMessageHandle* message, |
| 128 uint32_t* num_bytes, |
| 129 MojoHandle* handles, |
| 130 uint32_t* num_handles, |
| 131 MojoReadMessageFlags flags); |
| 132 MojoResult (*AllocMessage)(uint32_t num_bytes, |
| 133 const MojoHandle* handles, |
| 134 uint32_t num_handles, |
| 135 MojoAllocMessageFlags flags, |
| 136 MojoMessageHandle* message); |
| 137 MojoResult (*FreeMessage)(MojoMessageHandle message); |
| 138 MojoResult (*GetMessageBuffer)(MojoMessageHandle message, void** buffer); |
| 139 MojoResult (*WrapPlatformHandle)( |
| 140 const struct MojoPlatformHandle* platform_handle, |
| 141 MojoHandle* mojo_handle); |
| 142 MojoResult (*UnwrapPlatformHandle)( |
| 143 MojoHandle mojo_handle, |
| 144 struct MojoPlatformHandle* platform_handle); |
| 145 MojoResult (*WrapPlatformSharedBufferHandle)( |
| 146 const struct MojoPlatformHandle* platform_handle, |
| 147 size_t num_bytes, |
| 148 MojoPlatformSharedBufferHandleFlags flags, |
| 149 MojoHandle* mojo_handle); |
| 150 MojoResult (*UnwrapPlatformSharedBufferHandle)( |
| 151 MojoHandle mojo_handle, |
| 152 struct MojoPlatformHandle* platform_handle, |
| 153 size_t* num_bytes, |
| 154 MojoPlatformSharedBufferHandleFlags* flags); |
| 155 }; |
| 156 #pragma pack(pop) |
| 157 |
| 158 |
| 159 #ifdef __cplusplus |
| 160 // Intended to be called from the embedder. Returns a |MojoCore| initialized |
| 161 // to contain pointers to each of the embedder's MojoCore functions. |
| 162 inline MojoSystemThunks MojoMakeSystemThunks() { |
| 163 MojoSystemThunks system_thunks = {sizeof(MojoSystemThunks), |
| 164 MojoGetTimeTicksNow, |
| 165 MojoClose, |
| 166 MojoWait, |
| 167 MojoWaitMany, |
| 168 MojoCreateMessagePipe, |
| 169 MojoWriteMessage, |
| 170 MojoReadMessage, |
| 171 MojoCreateDataPipe, |
| 172 MojoWriteData, |
| 173 MojoBeginWriteData, |
| 174 MojoEndWriteData, |
| 175 MojoReadData, |
| 176 MojoBeginReadData, |
| 177 MojoEndReadData, |
| 178 MojoCreateSharedBuffer, |
| 179 MojoDuplicateBufferHandle, |
| 180 MojoMapBuffer, |
| 181 MojoUnmapBuffer, |
| 182 MojoCreateWaitSet, |
| 183 MojoAddHandle, |
| 184 MojoRemoveHandle, |
| 185 MojoGetReadyHandles, |
| 186 MojoWatch, |
| 187 MojoCancelWatch, |
| 188 MojoFuseMessagePipes, |
| 189 MojoWriteMessageNew, |
| 190 MojoReadMessageNew, |
| 191 MojoAllocMessage, |
| 192 MojoFreeMessage, |
| 193 MojoGetMessageBuffer, |
| 194 MojoWrapPlatformHandle, |
| 195 MojoUnwrapPlatformHandle, |
| 196 MojoWrapPlatformSharedBufferHandle, |
| 197 MojoUnwrapPlatformSharedBufferHandle}; |
| 198 return system_thunks; |
| 199 } |
| 200 #endif |
| 201 |
| 202 |
| 203 // Use this type for the function found by dynamically discovering it in |
| 204 // a DSO linked with mojo_system. For example: |
| 205 // MojoSetSystemThunksFn mojo_set_system_thunks_fn = |
| 206 // reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( |
| 207 // "MojoSetSystemThunks")); |
| 208 // The expected size of |system_thunks} is returned. |
| 209 // The contents of |system_thunks| are copied. |
| 210 typedef size_t (*MojoSetSystemThunksFn)( |
| 211 const struct MojoSystemThunks* system_thunks); |
| 212 |
| 213 #endif // MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ |
OLD | NEW |