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 extern "C" { | |
12 | |
13 static MojoSystemThunks g_thunks = {0}; | |
14 | |
15 MojoTimeTicks MojoGetTimeTicksNow() { | |
16 assert(g_thunks.GetTimeTicksNow); | |
17 return g_thunks.GetTimeTicksNow(); | |
18 } | |
19 | |
20 MojoResult MojoClose(MojoHandle handle) { | |
21 assert(g_thunks.Close); | |
22 return g_thunks.Close(handle); | |
23 } | |
24 | |
25 MojoResult MojoWait(MojoHandle handle, | |
26 MojoHandleSignals signals, | |
27 MojoDeadline deadline, | |
28 struct MojoHandleSignalsState* signals_state) { | |
29 assert(g_thunks.Wait); | |
30 return g_thunks.Wait(handle, signals, deadline, signals_state); | |
31 } | |
32 | |
33 MojoResult MojoWaitMany(const MojoHandle* handles, | |
34 const MojoHandleSignals* signals, | |
35 uint32_t num_handles, | |
36 MojoDeadline deadline, | |
37 uint32_t* result_index, | |
38 struct MojoHandleSignalsState* signals_states) { | |
39 assert(g_thunks.WaitMany); | |
40 return g_thunks.WaitMany(handles, signals, num_handles, deadline, | |
41 result_index, signals_states); | |
42 } | |
43 | |
44 MojoResult MojoCreateMessagePipe(const MojoCreateMessagePipeOptions* options, | |
45 MojoHandle* message_pipe_handle0, | |
46 MojoHandle* message_pipe_handle1) { | |
47 assert(g_thunks.CreateMessagePipe); | |
48 return g_thunks.CreateMessagePipe(options, message_pipe_handle0, | |
49 message_pipe_handle1); | |
50 } | |
51 | |
52 MojoResult MojoWriteMessage(MojoHandle message_pipe_handle, | |
53 const void* bytes, | |
54 uint32_t num_bytes, | |
55 const MojoHandle* handles, | |
56 uint32_t num_handles, | |
57 MojoWriteMessageFlags flags) { | |
58 assert(g_thunks.WriteMessage); | |
59 return g_thunks.WriteMessage(message_pipe_handle, bytes, num_bytes, handles, | |
60 num_handles, flags); | |
61 } | |
62 | |
63 MojoResult MojoReadMessage(MojoHandle message_pipe_handle, | |
64 void* bytes, | |
65 uint32_t* num_bytes, | |
66 MojoHandle* handles, | |
67 uint32_t* num_handles, | |
68 MojoReadMessageFlags flags) { | |
69 assert(g_thunks.ReadMessage); | |
70 return g_thunks.ReadMessage(message_pipe_handle, bytes, num_bytes, handles, | |
71 num_handles, flags); | |
72 } | |
73 | |
74 MojoResult MojoCreateDataPipe(const MojoCreateDataPipeOptions* options, | |
75 MojoHandle* data_pipe_producer_handle, | |
76 MojoHandle* data_pipe_consumer_handle) { | |
77 assert(g_thunks.CreateDataPipe); | |
78 return g_thunks.CreateDataPipe(options, data_pipe_producer_handle, | |
79 data_pipe_consumer_handle); | |
80 } | |
81 | |
82 MojoResult MojoWriteData(MojoHandle data_pipe_producer_handle, | |
83 const void* elements, | |
84 uint32_t* num_elements, | |
85 MojoWriteDataFlags flags) { | |
86 assert(g_thunks.WriteData); | |
87 return g_thunks.WriteData(data_pipe_producer_handle, elements, num_elements, | |
88 flags); | |
89 } | |
90 | |
91 MojoResult MojoBeginWriteData(MojoHandle data_pipe_producer_handle, | |
92 void** buffer, | |
93 uint32_t* buffer_num_elements, | |
94 MojoWriteDataFlags flags) { | |
95 assert(g_thunks.BeginWriteData); | |
96 return g_thunks.BeginWriteData(data_pipe_producer_handle, buffer, | |
97 buffer_num_elements, flags); | |
98 } | |
99 | |
100 MojoResult MojoEndWriteData(MojoHandle data_pipe_producer_handle, | |
101 uint32_t num_elements_written) { | |
102 assert(g_thunks.EndWriteData); | |
103 return g_thunks.EndWriteData(data_pipe_producer_handle, num_elements_written); | |
104 } | |
105 | |
106 MojoResult MojoReadData(MojoHandle data_pipe_consumer_handle, | |
107 void* elements, | |
108 uint32_t* num_elements, | |
109 MojoReadDataFlags flags) { | |
110 assert(g_thunks.ReadData); | |
111 return g_thunks.ReadData(data_pipe_consumer_handle, elements, num_elements, | |
112 flags); | |
113 } | |
114 | |
115 MojoResult MojoBeginReadData(MojoHandle data_pipe_consumer_handle, | |
116 const void** buffer, | |
117 uint32_t* buffer_num_elements, | |
118 MojoReadDataFlags flags) { | |
119 assert(g_thunks.BeginReadData); | |
120 return g_thunks.BeginReadData(data_pipe_consumer_handle, buffer, | |
121 buffer_num_elements, flags); | |
122 } | |
123 | |
124 MojoResult MojoEndReadData(MojoHandle data_pipe_consumer_handle, | |
125 uint32_t num_elements_read) { | |
126 assert(g_thunks.EndReadData); | |
127 return g_thunks.EndReadData(data_pipe_consumer_handle, num_elements_read); | |
128 } | |
129 | |
130 MojoResult MojoCreateSharedBuffer( | |
131 const struct MojoCreateSharedBufferOptions* options, | |
132 uint64_t num_bytes, | |
133 MojoHandle* shared_buffer_handle) { | |
134 assert(g_thunks.CreateSharedBuffer); | |
135 return g_thunks.CreateSharedBuffer(options, num_bytes, shared_buffer_handle); | |
136 } | |
137 | |
138 MojoResult MojoDuplicateBufferHandle( | |
139 MojoHandle buffer_handle, | |
140 const struct MojoDuplicateBufferHandleOptions* options, | |
141 MojoHandle* new_buffer_handle) { | |
142 assert(g_thunks.DuplicateBufferHandle); | |
143 return g_thunks.DuplicateBufferHandle(buffer_handle, options, | |
144 new_buffer_handle); | |
145 } | |
146 | |
147 MojoResult MojoMapBuffer(MojoHandle buffer_handle, | |
148 uint64_t offset, | |
149 uint64_t num_bytes, | |
150 void** buffer, | |
151 MojoMapBufferFlags flags) { | |
152 assert(g_thunks.MapBuffer); | |
153 return g_thunks.MapBuffer(buffer_handle, offset, num_bytes, buffer, flags); | |
154 } | |
155 | |
156 MojoResult MojoUnmapBuffer(void* buffer) { | |
157 assert(g_thunks.UnmapBuffer); | |
158 return g_thunks.UnmapBuffer(buffer); | |
159 } | |
160 | |
161 extern "C" THUNK_EXPORT size_t MojoSetSystemThunks( | |
162 const MojoSystemThunks* system_thunks) { | |
163 if (system_thunks->size >= sizeof(g_thunks)) | |
164 g_thunks = *system_thunks; | |
165 return sizeof(g_thunks); | |
166 } | |
167 | |
168 } // extern "C" | |
OLD | NEW |