OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 //! This ffi module is used to interact with the | |
6 //! Mojo C bindings API. The structures below are | |
7 //! undocumented because they are pulled exactly | |
8 //! from the header files of the Mojo C bindings | |
9 //! API which can be found in the Mojo repository[1] | |
10 //! under //mojo/public/c/include/mojo/system. Very | |
11 //! clear documentation on these structures and | |
12 //! functions can be found there. It is not worth | |
13 //! elaborating on these all again here. | |
14 //! | |
15 //! [1] https://github.com/domokit/mojo | |
16 | |
17 // This full import is intentional; nearly every type in mojo_types needs to be
used. | |
18 use system::mojo_types::*; | |
19 | |
20 #[allow(bad_style)] | |
21 /// This empty enum is used solely to provide | |
22 /// a notion of void from C. The truth is, the | |
23 /// correct move here is to use the libc Rust | |
24 /// package but, as it turns out, that's the only | |
25 /// part of libc we actually need. Rather than | |
26 /// force ourselves to pull in a dependency, we | |
27 /// instead implement libc's notion of c_void | |
28 /// here. | |
29 pub enum c_void {} | |
30 | |
31 pub mod types { | |
32 //! Defines some C-compatible types for the ffi layer of | |
33 //! the bindings. | |
34 | |
35 pub type MojoCreateSharedBufferOptionsFlags = u32; | |
36 pub type MojoDuplicateBufferHandleOptionsFlags = u32; | |
37 pub type MojoBufferInfoFlags = u32; | |
38 pub type MojoMapBufferFlags = u32; | |
39 pub type MojoCreateDataPipeOptionsFlags = u32; | |
40 pub type MojoWriteDataFlags = u32; | |
41 pub type MojoReadDataFlags = u32; | |
42 pub type MojoHandleSignals = u32; | |
43 pub type MojoCreateMessagePipeOptionsFlags = u32; | |
44 pub type MojoWriteMessageFlags = u32; | |
45 pub type MojoReadMessageFlags = u32; | |
46 pub type MojoCreateWaitSetOptionsFlags = u32; | |
47 pub type MojoWaitSetAddOptionsFlags = u32; | |
48 pub type MojoResultCode = u32; | |
49 } | |
50 | |
51 use system::ffi::types::*; | |
52 | |
53 #[repr(C)] | |
54 pub struct MojoCreateSharedBufferOptions { | |
55 pub struct_size: u32, | |
56 pub flags: MojoCreateSharedBufferOptionsFlags, | |
57 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
58 } | |
59 | |
60 #[repr(C)] | |
61 pub struct MojoDuplicateBufferHandleOptions { | |
62 pub struct_size: u32, | |
63 pub flags: MojoDuplicateBufferHandleOptionsFlags, | |
64 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
65 } | |
66 | |
67 #[repr(C)] | |
68 pub struct MojoBufferInformation { | |
69 pub struct_size: u32, | |
70 pub flags: MojoBufferInfoFlags, | |
71 pub num_bytes: u64, | |
72 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
73 } | |
74 | |
75 #[repr(C)] | |
76 pub struct MojoCreateDataPipeOptions { | |
77 pub struct_size: u32, | |
78 pub flags: MojoCreateDataPipeOptionsFlags, | |
79 pub element_num_bytes: u32, | |
80 pub capacity_num_bytes: u32, | |
81 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
82 } | |
83 | |
84 #[repr(C)] | |
85 pub struct MojoCreateMessagePipeOptions { | |
86 pub struct_size: u32, | |
87 pub flags: MojoCreateMessagePipeOptionsFlags, | |
88 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
89 } | |
90 | |
91 #[repr(C)] | |
92 pub struct MojoCreateWaitSetOptions { | |
93 pub struct_size: u32, | |
94 pub flags: MojoCreateWaitSetOptionsFlags, | |
95 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
96 } | |
97 | |
98 #[repr(C)] | |
99 pub struct MojoWaitSetAddOptions { | |
100 pub struct_size: u32, | |
101 pub flags: MojoWaitSetAddOptionsFlags, | |
102 pub _align: [u64; 0], // Hack to align struct to 8 byte boundary | |
103 } | |
104 | |
105 #[link] | |
106 extern "C" { | |
107 // From //mojo/public/c/include/mojo/system/buffer.h | |
108 pub fn MojoCreateSharedBuffer(options: *const MojoCreateSharedBufferOptions, | |
109 num_bytes: u64, | |
110 shared_buffer_handle: *mut MojoHandle) | |
111 -> MojoResultCode; | |
112 | |
113 pub fn MojoDuplicateBufferHandle(handle: MojoHandle, | |
114 options: *const MojoDuplicateBufferHandleOp
tions, | |
115 new_buffer_handle: *mut MojoHandle) | |
116 -> MojoResultCode; | |
117 | |
118 pub fn MojoGetBufferInformation(buffer_handle: MojoHandle, | |
119 info: *mut MojoBufferInformation, | |
120 info_num_bytes: u32) | |
121 -> MojoResultCode; | |
122 | |
123 pub fn MojoMapBuffer(buffer_handle: MojoHandle, | |
124 offset: u64, | |
125 num_bytes: u64, | |
126 buffer: *mut *mut c_void, | |
127 flags: MojoMapBufferFlags) | |
128 -> MojoResultCode; | |
129 | |
130 pub fn MojoUnmapBuffer(buffer: *const c_void) -> MojoResultCode; | |
131 | |
132 // From //mojo/public/c/include/mojo/system/data_pipe.h | |
133 pub fn MojoCreateDataPipe(options: *const MojoCreateDataPipeOptions, | |
134 data_pipe_producer_handle: *mut MojoHandle, | |
135 data_pipe_consumer_handle: *mut MojoHandle) | |
136 -> MojoResultCode; | |
137 | |
138 pub fn MojoWriteData(data_pipe_producer_handle: MojoHandle, | |
139 elements: *const c_void, | |
140 num_bytes: *mut u32, | |
141 flags: MojoWriteDataFlags) | |
142 -> MojoResultCode; | |
143 | |
144 pub fn MojoBeginWriteData(data_pipe_producer_handle: MojoHandle, | |
145 buffer: *mut *mut c_void, | |
146 buffer_num_bytes: *mut u32, | |
147 flags: MojoWriteDataFlags) | |
148 -> MojoResultCode; | |
149 | |
150 pub fn MojoEndWriteData(data_pipe_producer_handle: MojoHandle, | |
151 num_bytes_written: u32) | |
152 -> MojoResultCode; | |
153 | |
154 pub fn MojoReadData(data_pipe_consumer_handle: MojoHandle, | |
155 elements: *const c_void, | |
156 num_bytes: *mut u32, | |
157 flags: MojoReadDataFlags) | |
158 -> MojoResultCode; | |
159 | |
160 pub fn MojoBeginReadData(data_pipe_consumer_handle: MojoHandle, | |
161 buffer: *mut *mut c_void, | |
162 buffer_num_bytes: *mut u32, | |
163 flags: MojoReadDataFlags) | |
164 -> MojoResultCode; | |
165 | |
166 pub fn MojoEndReadData(data_pipe_consumer_handle: MojoHandle, | |
167 num_bytes_written: u32) | |
168 -> MojoResultCode; | |
169 | |
170 // From //mojo/public/c/include/mojo/system/handle.h | |
171 pub fn MojoClose(handle: MojoHandle) -> MojoResultCode; | |
172 | |
173 // From //mojo/public/c/include/mojo/system/message_pipe.h | |
174 pub fn MojoCreateMessagePipe(options: *const MojoCreateMessagePipeOptions, | |
175 message_pipe_handle0: *mut MojoHandle, | |
176 message_pipe_handle1: *mut MojoHandle) | |
177 -> MojoResultCode; | |
178 | |
179 pub fn MojoWriteMessage(message_pipe_handle: MojoHandle, | |
180 bytes: *const c_void, | |
181 num_bytes: u32, | |
182 handles: *const MojoHandle, | |
183 num_handles: u32, | |
184 flags: MojoWriteMessageFlags) | |
185 -> MojoResultCode; | |
186 | |
187 pub fn MojoReadMessage(message_pipe_handle: MojoHandle, | |
188 bytes: *mut c_void, | |
189 num_bytes: *mut u32, | |
190 handles: *mut MojoHandle, | |
191 num_handles: *mut u32, | |
192 flags: MojoWriteMessageFlags) | |
193 -> MojoResultCode; | |
194 | |
195 // From //mojo/public/c/include/mojo/system/time.h | |
196 pub fn MojoGetTimeTicksNow() -> MojoTimeTicks; | |
197 | |
198 // From //mojo/public/c/include/mojo/system/wait.h | |
199 pub fn MojoWait(handle: MojoHandle, | |
200 signals: HandleSignals, | |
201 deadline: MojoDeadline, | |
202 signals_state: *mut SignalsState) | |
203 -> MojoResultCode; | |
204 | |
205 pub fn MojoWaitMany(handles: *const MojoHandle, | |
206 signals: *const HandleSignals, | |
207 num_handles: u32, | |
208 deadline: MojoDeadline, | |
209 result_index: *mut u32, | |
210 signals_states: *mut SignalsState) | |
211 -> MojoResultCode; | |
212 | |
213 // From //mojo/public/c/include/mojo/system/wait_set.h | |
214 pub fn MojoCreateWaitSet(options: *const MojoCreateWaitSetOptions, | |
215 handle: *mut MojoHandle) | |
216 -> MojoResultCode; | |
217 | |
218 pub fn MojoWaitSetAdd(wait_set_handle: MojoHandle, | |
219 handle: MojoHandle, | |
220 signals: HandleSignals, | |
221 cookie: u64, | |
222 options: *const MojoWaitSetAddOptions) | |
223 -> MojoResultCode; | |
224 | |
225 pub fn MojoWaitSetRemove(wait_set_handle: MojoHandle, cookie: u64) -> MojoRe
sultCode; | |
226 | |
227 pub fn MojoWaitSetWait(wait_set_handle: MojoHandle, | |
228 deadline: MojoDeadline, | |
229 num_results: *mut u32, | |
230 results: *mut WaitSetResult, | |
231 max_results: *mut u32) | |
232 -> MojoResultCode; | |
233 } | |
OLD | NEW |