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_thunks.h" | |
6 | |
7 #include <assert.h> | |
8 | |
9 #include "mojo/public/platform/native/thunk_export.h" | |
10 | |
11 static struct MojoSystemThunks g_thunks = {0}; | |
12 | |
13 MojoTimeTicks MojoGetTimeTicksNow() { | |
14 assert(g_thunks.GetTimeTicksNow); | |
15 return g_thunks.GetTimeTicksNow(); | |
16 } | |
17 | |
18 MojoResult MojoClose(MojoHandle handle) { | |
19 assert(g_thunks.Close); | |
20 return g_thunks.Close(handle); | |
21 } | |
22 | |
23 MojoResult MojoGetRights(MojoHandle handle, MojoHandleRights* rights) { | |
24 assert(g_thunks.GetRights); | |
25 return g_thunks.GetRights(handle, rights); | |
26 } | |
27 | |
28 MojoResult MojoReplaceHandleWithReducedRights( | |
29 MojoHandle handle, | |
30 MojoHandleRights rights_to_remove, | |
31 MojoHandle* replacement_handle) { | |
32 assert(g_thunks.ReplaceHandleWithReducedRights); | |
33 return g_thunks.ReplaceHandleWithReducedRights( | |
34 handle, rights_to_remove, replacement_handle); | |
35 } | |
36 | |
37 MojoResult MojoDuplicateHandleWithReducedRights( | |
38 MojoHandle handle, | |
39 MojoHandleRights rights_to_remove, | |
40 MojoHandle* new_handle) { | |
41 assert(g_thunks.DuplicateHandleWithReducedRights); | |
42 return g_thunks.DuplicateHandleWithReducedRights(handle, rights_to_remove, | |
43 new_handle); | |
44 } | |
45 | |
46 MojoResult MojoDuplicateHandle(MojoHandle handle, MojoHandle* new_handle) { | |
47 assert(g_thunks.DuplicateHandle); | |
48 return g_thunks.DuplicateHandle(handle, new_handle); | |
49 } | |
50 | |
51 MojoResult MojoWait(MojoHandle handle, | |
52 MojoHandleSignals signals, | |
53 MojoDeadline deadline, | |
54 struct MojoHandleSignalsState* signals_state) { | |
55 assert(g_thunks.Wait); | |
56 return g_thunks.Wait(handle, signals, deadline, signals_state); | |
57 } | |
58 | |
59 MojoResult MojoWaitMany(const MojoHandle* handles, | |
60 const MojoHandleSignals* signals, | |
61 uint32_t num_handles, | |
62 MojoDeadline deadline, | |
63 uint32_t* result_index, | |
64 struct MojoHandleSignalsState* signals_states) { | |
65 assert(g_thunks.WaitMany); | |
66 return g_thunks.WaitMany(handles, signals, num_handles, deadline, | |
67 result_index, signals_states); | |
68 } | |
69 | |
70 MojoResult MojoCreateMessagePipe( | |
71 const struct MojoCreateMessagePipeOptions* options, | |
72 MojoHandle* message_pipe_handle0, | |
73 MojoHandle* message_pipe_handle1) { | |
74 assert(g_thunks.CreateMessagePipe); | |
75 return g_thunks.CreateMessagePipe(options, message_pipe_handle0, | |
76 message_pipe_handle1); | |
77 } | |
78 | |
79 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, | |
80 const void* bytes, | |
81 uint32_t num_bytes, | |
82 const MojoHandle* handles, | |
83 uint32_t num_handles, | |
84 MojoWriteMessageFlags flags) { | |
85 assert(g_thunks.WriteMessage); | |
86 return g_thunks.WriteMessage(message_pipe_handle, bytes, num_bytes, handles, | |
87 num_handles, flags); | |
88 } | |
89 | |
90 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | |
91 void* bytes, | |
92 uint32_t* num_bytes, | |
93 MojoHandle* handles, | |
94 uint32_t* num_handles, | |
95 MojoReadMessageFlags flags) { | |
96 assert(g_thunks.ReadMessage); | |
97 return g_thunks.ReadMessage(message_pipe_handle, bytes, num_bytes, handles, | |
98 num_handles, flags); | |
99 } | |
100 | |
101 MojoResult MojoCreateDataPipe(const struct MojoCreateDataPipeOptions* options, | |
102 MojoHandle* data_pipe_producer_handle, | |
103 MojoHandle* data_pipe_consumer_handle) { | |
104 assert(g_thunks.CreateDataPipe); | |
105 return g_thunks.CreateDataPipe(options, data_pipe_producer_handle, | |
106 data_pipe_consumer_handle); | |
107 } | |
108 | |
109 MojoResult MojoSetDataPipeProducerOptions( | |
110 MojoHandle data_pipe_producer_handle, | |
111 const struct MojoDataPipeProducerOptions* options) { | |
112 assert(g_thunks.SetDataPipeProducerOptions); | |
113 return g_thunks.SetDataPipeProducerOptions(data_pipe_producer_handle, | |
114 options); | |
115 } | |
116 | |
117 MojoResult MojoGetDataPipeProducerOptions( | |
118 MojoHandle data_pipe_producer_handle, | |
119 struct MojoDataPipeProducerOptions* options, | |
120 uint32_t options_num_bytes) { | |
121 assert(g_thunks.GetDataPipeProducerOptions); | |
122 return g_thunks.GetDataPipeProducerOptions(data_pipe_producer_handle, | |
123 options, options_num_bytes); | |
124 } | |
125 | |
126 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, | |
127 const void* elements, | |
128 uint32_t* num_elements, | |
129 MojoWriteDataFlags flags) { | |
130 assert(g_thunks.WriteData); | |
131 return g_thunks.WriteData(data_pipe_producer_handle, elements, num_elements, | |
132 flags); | |
133 } | |
134 | |
135 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, | |
136 void** buffer, | |
137 uint32_t* buffer_num_elements, | |
138 MojoWriteDataFlags flags) { | |
139 assert(g_thunks.BeginWriteData); | |
140 return g_thunks.BeginWriteData(data_pipe_producer_handle, buffer, | |
141 buffer_num_elements, flags); | |
142 } | |
143 | |
144 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, | |
145 uint32_t num_elements_written) { | |
146 assert(g_thunks.EndWriteData); | |
147 return g_thunks.EndWriteData(data_pipe_producer_handle, num_elements_written); | |
148 } | |
149 | |
150 MojoResult MojoSetDataPipeConsumerOptions( | |
151 MojoHandle data_pipe_consumer_handle, | |
152 const struct MojoDataPipeConsumerOptions* options) { | |
153 assert(g_thunks.SetDataPipeConsumerOptions); | |
154 return g_thunks.SetDataPipeConsumerOptions(data_pipe_consumer_handle, | |
155 options); | |
156 } | |
157 | |
158 MojoResult MojoGetDataPipeConsumerOptions( | |
159 MojoHandle data_pipe_consumer_handle, | |
160 struct MojoDataPipeConsumerOptions* options, | |
161 uint32_t options_num_bytes) { | |
162 assert(g_thunks.GetDataPipeConsumerOptions); | |
163 return g_thunks.GetDataPipeConsumerOptions(data_pipe_consumer_handle, | |
164 options, options_num_bytes); | |
165 } | |
166 | |
167 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, | |
168 void* elements, | |
169 uint32_t* num_elements, | |
170 MojoReadDataFlags flags) { | |
171 assert(g_thunks.ReadData); | |
172 return g_thunks.ReadData(data_pipe_consumer_handle, elements, num_elements, | |
173 flags); | |
174 } | |
175 | |
176 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, | |
177 const void** buffer, | |
178 uint32_t* buffer_num_elements, | |
179 MojoReadDataFlags flags) { | |
180 assert(g_thunks.BeginReadData); | |
181 return g_thunks.BeginReadData(data_pipe_consumer_handle, buffer, | |
182 buffer_num_elements, flags); | |
183 } | |
184 | |
185 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, | |
186 uint32_t num_elements_read) { | |
187 assert(g_thunks.EndReadData); | |
188 return g_thunks.EndReadData(data_pipe_consumer_handle, num_elements_read); | |
189 } | |
190 | |
191 MojoResult MojoCreateSharedBuffer( | |
192 const struct MojoCreateSharedBufferOptions* options, | |
193 uint64_t num_bytes, | |
194 MojoHandle* shared_buffer_handle) { | |
195 assert(g_thunks.CreateSharedBuffer); | |
196 return g_thunks.CreateSharedBuffer(options, num_bytes, shared_buffer_handle); | |
197 } | |
198 | |
199 MojoResult MojoDuplicateBufferHandle( | |
200 MojoHandle buffer_handle, | |
201 const struct MojoDuplicateBufferHandleOptions* options, | |
202 MojoHandle* new_buffer_handle) { | |
203 assert(g_thunks.DuplicateBufferHandle); | |
204 return g_thunks.DuplicateBufferHandle(buffer_handle, options, | |
205 new_buffer_handle); | |
206 } | |
207 | |
208 MojoResult MojoGetBufferInformation(MojoHandle buffer_handle, | |
209 struct MojoBufferInformation* info, | |
210 uint32_t info_num_bytes) { | |
211 assert(g_thunks.GetBufferInformation); | |
212 return g_thunks.GetBufferInformation(buffer_handle, info, info_num_bytes); | |
213 } | |
214 | |
215 MojoResult MojoMapBuffer(MojoHandle buffer_handle, | |
216 uint64_t offset, | |
217 uint64_t num_bytes, | |
218 void** buffer, | |
219 MojoMapBufferFlags flags) { | |
220 assert(g_thunks.MapBuffer); | |
221 return g_thunks.MapBuffer(buffer_handle, offset, num_bytes, buffer, flags); | |
222 } | |
223 | |
224 MojoResult MojoUnmapBuffer(void* buffer) { | |
225 assert(g_thunks.UnmapBuffer); | |
226 return g_thunks.UnmapBuffer(buffer); | |
227 } | |
228 | |
229 MojoResult MojoCreateWaitSet(const struct MojoCreateWaitSetOptions* options, | |
230 MojoHandle* handle) { | |
231 assert(g_thunks.CreateWaitSet); | |
232 return g_thunks.CreateWaitSet(options, handle); | |
233 } | |
234 | |
235 MojoResult MojoWaitSetAdd(MojoHandle wait_set_handle, | |
236 MojoHandle handle, | |
237 MojoHandleSignals signals, | |
238 uint64_t cookie, | |
239 const struct MojoWaitSetAddOptions* options) { | |
240 assert(g_thunks.WaitSetAdd); | |
241 return g_thunks.WaitSetAdd(wait_set_handle, handle, signals, cookie, options); | |
242 } | |
243 | |
244 MojoResult MojoWaitSetRemove(MojoHandle wait_set_handle, uint64_t cookie) { | |
245 assert(g_thunks.WaitSetRemove); | |
246 return g_thunks.WaitSetRemove(wait_set_handle, cookie); | |
247 } | |
248 | |
249 MojoResult MojoWaitSetWait(MojoHandle wait_set_handle, | |
250 MojoDeadline deadline, | |
251 uint32_t* num_results, | |
252 struct MojoWaitSetResult* results, | |
253 uint32_t* max_results) { | |
254 assert(g_thunks.WaitSetWait); | |
255 return g_thunks.WaitSetWait(wait_set_handle, deadline, num_results, results, | |
256 max_results); | |
257 } | |
258 | |
259 THUNK_EXPORT size_t | |
260 MojoSetSystemThunks(const struct MojoSystemThunks* system_thunks) { | |
261 if (system_thunks->size >= sizeof(g_thunks)) | |
262 g_thunks = *system_thunks; | |
263 return sizeof(g_thunks); | |
264 } | |
OLD | NEW |