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