OLD | NEW |
(Empty) | |
| 1 // Copyright 2013 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 #include "mojo/public/platform/native/system_impl_private_thunks.h" |
| 6 |
| 7 #include <assert.h> |
| 8 |
| 9 #include "mojo/public/platform/native/thunk_export.h" |
| 10 |
| 11 extern "C" { |
| 12 |
| 13 static MojoSystemImplThunksPrivate g_system_impl_thunks = {0}; |
| 14 static MojoExplicitSystemThunksPrivate g_explicit_system_thunks = {0}; |
| 15 |
| 16 MojoSystemImpl MojoSystemImplGetDefaultImpl() { |
| 17 assert(g_system_impl_thunks.GetDefaultSystemImpl); |
| 18 return g_system_impl_thunks.GetDefaultSystemImpl(); |
| 19 } |
| 20 |
| 21 MojoSystemImpl MojoSystemImplCreateImpl() { |
| 22 assert(g_system_impl_thunks.CreateSystemImpl); |
| 23 return g_system_impl_thunks.CreateSystemImpl(); |
| 24 } |
| 25 |
| 26 MojoResult MojoSystemImplTransferHandle(MojoSystemImpl from_system, |
| 27 MojoHandle handle, |
| 28 MojoSystemImpl to_system, |
| 29 MojoHandle* result_handle) { |
| 30 assert(g_system_impl_thunks.TransferHandle); |
| 31 return g_system_impl_thunks.TransferHandle(from_system, handle, to_system, |
| 32 result_handle); |
| 33 } |
| 34 |
| 35 MojoTimeTicks MojoSystemImplGetTimeTicksNow(MojoSystemImpl system) { |
| 36 assert(g_explicit_system_thunks.GetTimeTicksNow); |
| 37 return g_explicit_system_thunks.GetTimeTicksNow(system); |
| 38 } |
| 39 |
| 40 MojoResult MojoSystemImplClose(MojoSystemImpl system, MojoHandle handle) { |
| 41 assert(g_explicit_system_thunks.Close); |
| 42 return g_explicit_system_thunks.Close(system, handle); |
| 43 } |
| 44 |
| 45 MojoResult MojoSystemImplWait(MojoSystemImpl system, |
| 46 MojoHandle handle, |
| 47 MojoHandleSignals signals, |
| 48 MojoDeadline deadline, |
| 49 struct MojoHandleSignalsState* signals_state) { |
| 50 assert(g_explicit_system_thunks.Wait); |
| 51 return g_explicit_system_thunks.Wait(system, handle, signals, deadline, |
| 52 signals_state); |
| 53 } |
| 54 |
| 55 MojoResult MojoSystemImplWaitMany( |
| 56 MojoSystemImpl system, |
| 57 const MojoHandle* handles, |
| 58 const MojoHandleSignals* signals, |
| 59 uint32_t num_handles, |
| 60 MojoDeadline deadline, |
| 61 uint32_t* result_index, |
| 62 struct MojoHandleSignalsState* signals_states) { |
| 63 assert(g_explicit_system_thunks.WaitMany); |
| 64 return g_explicit_system_thunks.WaitMany(system, handles, signals, |
| 65 num_handles, deadline, result_index, |
| 66 signals_states); |
| 67 } |
| 68 |
| 69 MojoResult MojoSystemImplCreateMessagePipe( |
| 70 MojoSystemImpl system, |
| 71 const struct MojoCreateMessagePipeOptions* options, |
| 72 MojoHandle* message_pipe_handle0, |
| 73 MojoHandle* message_pipe_handle1) { |
| 74 assert(g_explicit_system_thunks.CreateMessagePipe); |
| 75 return g_explicit_system_thunks.CreateMessagePipe( |
| 76 system, options, message_pipe_handle0, message_pipe_handle1); |
| 77 } |
| 78 |
| 79 MojoResult MojoSystemImplWriteMessage(MojoSystemImpl system, |
| 80 MojoHandle message_pipe_handle, |
| 81 const void* bytes, |
| 82 uint32_t num_bytes, |
| 83 const MojoHandle* handles, |
| 84 uint32_t num_handles, |
| 85 MojoWriteMessageFlags flags) { |
| 86 assert(g_explicit_system_thunks.WriteMessage); |
| 87 return g_explicit_system_thunks.WriteMessage(system, message_pipe_handle, |
| 88 bytes, num_bytes, handles, |
| 89 num_handles, flags); |
| 90 } |
| 91 |
| 92 MojoResult MojoSystemImplReadMessage(MojoSystemImpl system, |
| 93 MojoHandle message_pipe_handle, |
| 94 void* bytes, |
| 95 uint32_t* num_bytes, |
| 96 MojoHandle* handles, |
| 97 uint32_t* num_handles, |
| 98 MojoReadMessageFlags flags) { |
| 99 assert(g_explicit_system_thunks.ReadMessage); |
| 100 return g_explicit_system_thunks.ReadMessage(system, message_pipe_handle, |
| 101 bytes, num_bytes, handles, |
| 102 num_handles, flags); |
| 103 } |
| 104 |
| 105 MojoResult MojoSystemImplCreateDataPipe( |
| 106 MojoSystemImpl system, |
| 107 const struct MojoCreateDataPipeOptions* options, |
| 108 MojoHandle* data_pipe_producer_handle, |
| 109 MojoHandle* data_pipe_consumer_handle) { |
| 110 assert(g_explicit_system_thunks.CreateDataPipe); |
| 111 return g_explicit_system_thunks.CreateDataPipe( |
| 112 system, options, data_pipe_producer_handle, data_pipe_consumer_handle); |
| 113 } |
| 114 |
| 115 MojoResult MojoSystemImplWriteData(MojoSystemImpl system, |
| 116 MojoHandle data_pipe_producer_handle, |
| 117 const void* elements, |
| 118 uint32_t* num_elements, |
| 119 MojoWriteDataFlags flags) { |
| 120 assert(g_explicit_system_thunks.WriteData); |
| 121 return g_explicit_system_thunks.WriteData(system, data_pipe_producer_handle, |
| 122 elements, num_elements, flags); |
| 123 } |
| 124 |
| 125 MojoResult MojoSystemImplBeginWriteData(MojoSystemImpl system, |
| 126 MojoHandle data_pipe_producer_handle, |
| 127 void** buffer, |
| 128 uint32_t* buffer_num_elements, |
| 129 MojoWriteDataFlags flags) { |
| 130 assert(g_explicit_system_thunks.BeginWriteData); |
| 131 return g_explicit_system_thunks.BeginWriteData( |
| 132 system, data_pipe_producer_handle, buffer, buffer_num_elements, flags); |
| 133 } |
| 134 |
| 135 MojoResult MojoSystemImplEndWriteData(MojoSystemImpl system, |
| 136 MojoHandle data_pipe_producer_handle, |
| 137 uint32_t num_elements_written) { |
| 138 assert(g_explicit_system_thunks.EndWriteData); |
| 139 return g_explicit_system_thunks.EndWriteData( |
| 140 system, data_pipe_producer_handle, num_elements_written); |
| 141 } |
| 142 |
| 143 MojoResult MojoSystemImplReadData(MojoSystemImpl system, |
| 144 MojoHandle data_pipe_consumer_handle, |
| 145 void* elements, |
| 146 uint32_t* num_elements, |
| 147 MojoReadDataFlags flags) { |
| 148 assert(g_explicit_system_thunks.ReadData); |
| 149 return g_explicit_system_thunks.ReadData(system, data_pipe_consumer_handle, |
| 150 elements, num_elements, flags); |
| 151 } |
| 152 |
| 153 MojoResult MojoSystemImplBeginReadData(MojoSystemImpl system, |
| 154 MojoHandle data_pipe_consumer_handle, |
| 155 const void** buffer, |
| 156 uint32_t* buffer_num_elements, |
| 157 MojoReadDataFlags flags) { |
| 158 assert(g_explicit_system_thunks.BeginReadData); |
| 159 return g_explicit_system_thunks.BeginReadData( |
| 160 system, data_pipe_consumer_handle, buffer, buffer_num_elements, flags); |
| 161 } |
| 162 |
| 163 MojoResult MojoSystemImplEndReadData(MojoSystemImpl system, |
| 164 MojoHandle data_pipe_consumer_handle, |
| 165 uint32_t num_elements_read) { |
| 166 assert(g_explicit_system_thunks.EndReadData); |
| 167 return g_explicit_system_thunks.EndReadData(system, data_pipe_consumer_handle, |
| 168 num_elements_read); |
| 169 } |
| 170 |
| 171 MojoResult MojoSystemImplCreateSharedBuffer( |
| 172 MojoSystemImpl system, |
| 173 const struct MojoCreateSharedBufferOptions* options, |
| 174 uint64_t num_bytes, |
| 175 MojoHandle* shared_buffer_handle) { |
| 176 assert(g_explicit_system_thunks.CreateSharedBuffer); |
| 177 return g_explicit_system_thunks.CreateSharedBuffer(system, options, num_bytes, |
| 178 shared_buffer_handle); |
| 179 } |
| 180 |
| 181 MojoResult MojoSystemImplDuplicateBufferHandle( |
| 182 MojoSystemImpl system, |
| 183 MojoHandle buffer_handle, |
| 184 const struct MojoDuplicateBufferHandleOptions* options, |
| 185 MojoHandle* new_buffer_handle) { |
| 186 assert(g_explicit_system_thunks.DuplicateBufferHandle); |
| 187 return g_explicit_system_thunks.DuplicateBufferHandle( |
| 188 system, buffer_handle, options, new_buffer_handle); |
| 189 } |
| 190 |
| 191 MojoResult MojoSystemImplMapBuffer(MojoSystemImpl system, |
| 192 MojoHandle buffer_handle, |
| 193 uint64_t offset, |
| 194 uint64_t num_bytes, |
| 195 void** buffer, |
| 196 MojoMapBufferFlags flags) { |
| 197 assert(g_explicit_system_thunks.MapBuffer); |
| 198 return g_explicit_system_thunks.MapBuffer(system, buffer_handle, offset, |
| 199 num_bytes, buffer, flags); |
| 200 } |
| 201 |
| 202 MojoResult MojoSystemImplUnmapBuffer(MojoSystemImpl system, void* buffer) { |
| 203 assert(g_explicit_system_thunks.UnmapBuffer); |
| 204 return g_explicit_system_thunks.UnmapBuffer(system, buffer); |
| 205 } |
| 206 |
| 207 extern "C" THUNK_EXPORT size_t MojoSetSystemImplThunksPrivate( |
| 208 const MojoSystemImplThunksPrivate* system_thunks) { |
| 209 if (system_thunks->size >= sizeof(g_system_impl_thunks)) |
| 210 g_system_impl_thunks = *system_thunks; |
| 211 return sizeof(g_system_impl_thunks); |
| 212 } |
| 213 |
| 214 extern "C" THUNK_EXPORT size_t MojoSetExplicitSystemThunksPrivate( |
| 215 const MojoExplicitSystemThunksPrivate* system_thunks) { |
| 216 if (system_thunks->size >= sizeof(g_explicit_system_thunks)) |
| 217 g_explicit_system_thunks = *system_thunks; |
| 218 return sizeof(g_explicit_system_thunks); |
| 219 } |
| 220 |
| 221 } // extern "C" |
OLD | NEW |