| 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 | |
| 12 #include "mojo/public/c/system/core.h" | |
| 13 | |
| 14 // The embedder needs to bind the basic Mojo Core functions of a DSO to those of | |
| 15 // the embedder when loading a DSO that is dependent on mojo_system. | |
| 16 // The typical usage would look like: | |
| 17 // base::ScopedNativeLibrary app_library( | |
| 18 // base::LoadNativeLibrary(app_path_, &error)); | |
| 19 // typedef MojoResult (*MojoSetSystemThunksFn)(MojoSystemThunks*); | |
| 20 // MojoSetSystemThunksFn mojo_set_system_thunks_fn = | |
| 21 // reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( | |
| 22 // "MojoSetSystemThunks")); | |
| 23 // MojoSystemThunks system_thunks = MojoMakeSystemThunks(); | |
| 24 // size_t expected_size = mojo_set_system_thunks_fn(&system_thunks); | |
| 25 // if (expected_size > sizeof(MojoSystemThunks)) { | |
| 26 // LOG(ERROR) | |
| 27 // << "Invalid DSO. Expected MojoSystemThunks size: " | |
| 28 // << expected_size; | |
| 29 // break; | |
| 30 // } | |
| 31 | |
| 32 // Structure used to bind the basic Mojo Core functions of a DSO to those of | |
| 33 // the embedder. | |
| 34 // This is the ABI between the embedder and the DSO. It can only have new | |
| 35 // functions added to the end. No other changes are supported. | |
| 36 #pragma pack(push, 8) | |
| 37 struct MojoSystemThunks { | |
| 38 size_t size; // Should be set to sizeof(MojoSystemThunks). | |
| 39 MojoTimeTicks (*GetTimeTicksNow)(); | |
| 40 MojoResult (*Close)(MojoHandle handle); | |
| 41 MojoResult (*Wait)(MojoHandle handle, | |
| 42 MojoHandleSignals signals, | |
| 43 MojoDeadline deadline, | |
| 44 struct MojoHandleSignalsState* signals_state); | |
| 45 MojoResult (*WaitMany)(const MojoHandle* handles, | |
| 46 const MojoHandleSignals* signals, | |
| 47 uint32_t num_handles, | |
| 48 MojoDeadline deadline, | |
| 49 uint32_t* result_index, | |
| 50 struct MojoHandleSignalsState* signals_states); | |
| 51 MojoResult (*CreateMessagePipe)( | |
| 52 const struct MojoCreateMessagePipeOptions* options, | |
| 53 MojoHandle* message_pipe_handle0, | |
| 54 MojoHandle* message_pipe_handle1); | |
| 55 MojoResult (*WriteMessage)(MojoHandle message_pipe_handle, | |
| 56 const void* bytes, | |
| 57 uint32_t num_bytes, | |
| 58 const MojoHandle* handles, | |
| 59 uint32_t num_handles, | |
| 60 MojoWriteMessageFlags flags); | |
| 61 MojoResult (*ReadMessage)(MojoHandle message_pipe_handle, | |
| 62 void* bytes, | |
| 63 uint32_t* num_bytes, | |
| 64 MojoHandle* handles, | |
| 65 uint32_t* num_handles, | |
| 66 MojoReadMessageFlags flags); | |
| 67 MojoResult (*CreateDataPipe)(const struct MojoCreateDataPipeOptions* options, | |
| 68 MojoHandle* data_pipe_producer_handle, | |
| 69 MojoHandle* data_pipe_consumer_handle); | |
| 70 MojoResult (*WriteData)(MojoHandle data_pipe_producer_handle, | |
| 71 const void* elements, | |
| 72 uint32_t* num_elements, | |
| 73 MojoWriteDataFlags flags); | |
| 74 MojoResult (*BeginWriteData)(MojoHandle data_pipe_producer_handle, | |
| 75 void** buffer, | |
| 76 uint32_t* buffer_num_elements, | |
| 77 MojoWriteDataFlags flags); | |
| 78 MojoResult (*EndWriteData)(MojoHandle data_pipe_producer_handle, | |
| 79 uint32_t num_elements_written); | |
| 80 MojoResult (*ReadData)(MojoHandle data_pipe_consumer_handle, | |
| 81 void* elements, | |
| 82 uint32_t* num_elements, | |
| 83 MojoReadDataFlags flags); | |
| 84 MojoResult (*BeginReadData)(MojoHandle data_pipe_consumer_handle, | |
| 85 const void** buffer, | |
| 86 uint32_t* buffer_num_elements, | |
| 87 MojoReadDataFlags flags); | |
| 88 MojoResult (*EndReadData)(MojoHandle data_pipe_consumer_handle, | |
| 89 uint32_t num_elements_read); | |
| 90 MojoResult (*CreateSharedBuffer)( | |
| 91 const struct MojoCreateSharedBufferOptions* options, | |
| 92 uint64_t num_bytes, | |
| 93 MojoHandle* shared_buffer_handle); | |
| 94 MojoResult (*DuplicateBufferHandle)( | |
| 95 MojoHandle buffer_handle, | |
| 96 const struct MojoDuplicateBufferHandleOptions* options, | |
| 97 MojoHandle* new_buffer_handle); | |
| 98 MojoResult (*MapBuffer)(MojoHandle buffer_handle, | |
| 99 uint64_t offset, | |
| 100 uint64_t num_bytes, | |
| 101 void** buffer, | |
| 102 MojoMapBufferFlags flags); | |
| 103 MojoResult (*UnmapBuffer)(void* buffer); | |
| 104 }; | |
| 105 #pragma pack(pop) | |
| 106 | |
| 107 | |
| 108 #ifdef __cplusplus | |
| 109 // Intended to be called from the embedder. Returns a |MojoCore| initialized | |
| 110 // to contain pointers to each of the embedder's MojoCore functions. | |
| 111 inline MojoSystemThunks MojoMakeSystemThunks() { | |
| 112 MojoSystemThunks system_thunks = {sizeof(MojoSystemThunks), | |
| 113 MojoGetTimeTicksNow, | |
| 114 MojoClose, | |
| 115 MojoWait, | |
| 116 MojoWaitMany, | |
| 117 MojoCreateMessagePipe, | |
| 118 MojoWriteMessage, | |
| 119 MojoReadMessage, | |
| 120 MojoCreateDataPipe, | |
| 121 MojoWriteData, | |
| 122 MojoBeginWriteData, | |
| 123 MojoEndWriteData, | |
| 124 MojoReadData, | |
| 125 MojoBeginReadData, | |
| 126 MojoEndReadData, | |
| 127 MojoCreateSharedBuffer, | |
| 128 MojoDuplicateBufferHandle, | |
| 129 MojoMapBuffer, | |
| 130 MojoUnmapBuffer}; | |
| 131 return system_thunks; | |
| 132 } | |
| 133 #endif | |
| 134 | |
| 135 | |
| 136 // Use this type for the function found by dynamically discovering it in | |
| 137 // a DSO linked with mojo_system. For example: | |
| 138 // MojoSetSystemThunksFn mojo_set_system_thunks_fn = | |
| 139 // reinterpret_cast<MojoSetSystemThunksFn>(app_library.GetFunctionPointer( | |
| 140 // "MojoSetSystemThunks")); | |
| 141 // The expected size of |system_thunks} is returned. | |
| 142 // The contents of |system_thunks| are copied. | |
| 143 typedef size_t (*MojoSetSystemThunksFn)( | |
| 144 const struct MojoSystemThunks* system_thunks); | |
| 145 | |
| 146 #endif // MOJO_PUBLIC_PLATFORM_NATIVE_SYSTEM_THUNKS_H_ | |
| OLD | NEW |