]> git.lizzy.rs Git - rust.git/blob - src/libstd/sys/unix/process/zircon.rs
Auto merge of #64819 - Manishearth:clippyup, r=Manishearth
[rust.git] / src / libstd / sys / unix / process / zircon.rs
1 #![allow(non_camel_case_types, unused)]
2
3 use crate::convert::TryInto;
4 use crate::io;
5 use crate::i64;
6 use crate::mem::MaybeUninit;
7 use crate::os::raw::c_char;
8
9 use libc::{c_int, c_void, size_t};
10
11 pub type zx_handle_t = u32;
12 pub type zx_vaddr_t = usize;
13 pub type zx_rights_t = u32;
14 pub type zx_status_t = i32;
15
16 pub const ZX_HANDLE_INVALID: zx_handle_t = 0;
17
18 pub type zx_time_t = i64;
19 pub const ZX_TIME_INFINITE : zx_time_t = i64::MAX;
20
21 pub type zx_signals_t = u32;
22
23 pub const ZX_OBJECT_SIGNAL_3         : zx_signals_t = 1 << 3;
24
25 pub const ZX_TASK_TERMINATED        : zx_signals_t = ZX_OBJECT_SIGNAL_3;
26
27 pub const ZX_RIGHT_SAME_RIGHTS  : zx_rights_t = 1 << 31;
28
29 pub type zx_object_info_topic_t = u32;
30
31 pub const ZX_INFO_PROCESS         : zx_object_info_topic_t = 3;
32
33 pub fn zx_cvt<T>(t: T) -> io::Result<T> where T: TryInto<zx_status_t>+Copy {
34     if let Ok(status) = TryInto::try_into(t) {
35         if status < 0 {
36             Err(io::Error::from_raw_os_error(status))
37         } else {
38             Ok(t)
39         }
40     } else {
41         Err(io::Error::last_os_error())
42     }
43 }
44
45 // Safe wrapper around zx_handle_t
46 pub struct Handle {
47     raw: zx_handle_t,
48 }
49
50 impl Handle {
51     pub fn new(raw: zx_handle_t) -> Handle {
52         Handle {
53             raw,
54         }
55     }
56
57     pub fn raw(&self) -> zx_handle_t {
58         self.raw
59     }
60 }
61
62 impl Drop for Handle {
63     fn drop(&mut self) {
64         unsafe { zx_cvt(zx_handle_close(self.raw)).expect("Failed to close zx_handle_t"); }
65     }
66 }
67
68 // Returned for topic ZX_INFO_PROCESS
69 #[derive(Default)]
70 #[repr(C)]
71 pub struct zx_info_process_t {
72     pub return_code: i64,
73     pub started: bool,
74     pub exited: bool,
75     pub debugger_attached: bool,
76 }
77
78 extern {
79     pub fn zx_job_default() -> zx_handle_t;
80
81     pub fn zx_task_kill(handle: zx_handle_t) -> zx_status_t;
82
83     pub fn zx_handle_close(handle: zx_handle_t) -> zx_status_t;
84
85     pub fn zx_handle_duplicate(handle: zx_handle_t, rights: zx_rights_t,
86                                out: *const zx_handle_t) -> zx_handle_t;
87
88     pub fn zx_object_wait_one(handle: zx_handle_t, signals: zx_signals_t, timeout: zx_time_t,
89                               pending: *mut zx_signals_t) -> zx_status_t;
90
91     pub fn zx_object_get_info(handle: zx_handle_t, topic: u32, buffer: *mut c_void,
92                               buffer_size: size_t, actual_size: *mut size_t,
93                               avail: *mut size_t) -> zx_status_t;
94 }
95
96 #[derive(Default)]
97 #[repr(C)]
98 pub struct fdio_spawn_action_t {
99     pub action: u32,
100     pub reserved0: u32,
101     pub local_fd: i32,
102     pub target_fd: i32,
103     pub reserved1: u64,
104 }
105
106 extern {
107     pub fn fdio_spawn_etc(job: zx_handle_t, flags: u32, path: *const c_char,
108                           argv: *const *const c_char, envp: *const *const c_char,
109                           action_count: size_t, actions: *const fdio_spawn_action_t,
110                           process: *mut zx_handle_t, err_msg: *mut c_char) -> zx_status_t;
111
112     pub fn fdio_fd_clone(fd: c_int, out_handle: *mut zx_handle_t) -> zx_status_t;
113     pub fn fdio_fd_create(handle: zx_handle_t, fd: *mut c_int) -> zx_status_t;
114 }
115
116 // fdio_spawn_etc flags
117
118 pub const FDIO_SPAWN_CLONE_JOB: u32 = 0x0001;
119 pub const FDIO_SPAWN_CLONE_LDSVC: u32 = 0x0002;
120 pub const FDIO_SPAWN_CLONE_NAMESPACE: u32 = 0x0004;
121 pub const FDIO_SPAWN_CLONE_STDIO: u32 = 0x0008;
122 pub const FDIO_SPAWN_CLONE_ENVIRON: u32 = 0x0010;
123 pub const FDIO_SPAWN_CLONE_ALL: u32 = 0xFFFF;
124
125 // fdio_spawn_etc actions
126
127 pub const FDIO_SPAWN_ACTION_CLONE_FD: u32 = 0x0001;
128 pub const FDIO_SPAWN_ACTION_TRANSFER_FD: u32 = 0x0002;
129
130 // Errors
131
132 #[allow(unused)] pub const ERR_INTERNAL: zx_status_t = -1;
133
134 // ERR_NOT_SUPPORTED: The operation is not implemented, supported,
135 // or enabled.
136 #[allow(unused)] pub const ERR_NOT_SUPPORTED: zx_status_t = -2;
137
138 // ERR_NO_RESOURCES: The system was not able to allocate some resource
139 // needed for the operation.
140 #[allow(unused)] pub const ERR_NO_RESOURCES: zx_status_t = -3;
141
142 // ERR_NO_MEMORY: The system was not able to allocate memory needed
143 // for the operation.
144 #[allow(unused)] pub const ERR_NO_MEMORY: zx_status_t = -4;
145
146 // ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete
147 // successfully.
148 #[allow(unused)] pub const ERR_CALL_FAILED: zx_status_t = -5;
149
150 // ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be
151 // retried.  This should not be seen outside of the VDSO.
152 #[allow(unused)] pub const ERR_INTERRUPTED_RETRY: zx_status_t = -6;
153
154 // ======= Parameter errors =======
155 // ERR_INVALID_ARGS: an argument is invalid, ex. null pointer
156 #[allow(unused)] pub const ERR_INVALID_ARGS: zx_status_t = -10;
157
158 // ERR_BAD_HANDLE: A specified handle value does not refer to a handle.
159 #[allow(unused)] pub const ERR_BAD_HANDLE: zx_status_t = -11;
160
161 // ERR_WRONG_TYPE: The subject of the operation is the wrong type to
162 // perform the operation.
163 // Example: Attempting a message_read on a thread handle.
164 #[allow(unused)] pub const ERR_WRONG_TYPE: zx_status_t = -12;
165
166 // ERR_BAD_SYSCALL: The specified syscall number is invalid.
167 #[allow(unused)] pub const ERR_BAD_SYSCALL: zx_status_t = -13;
168
169 // ERR_OUT_OF_RANGE: An argument is outside the valid range for this
170 // operation.
171 #[allow(unused)] pub const ERR_OUT_OF_RANGE: zx_status_t = -14;
172
173 // ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for
174 // this operation.
175 #[allow(unused)] pub const ERR_BUFFER_TOO_SMALL: zx_status_t = -15;
176
177 // ======= Precondition or state errors =======
178 // ERR_BAD_STATE: operation failed because the current state of the
179 // object does not allow it, or a precondition of the operation is
180 // not satisfied
181 #[allow(unused)] pub const ERR_BAD_STATE: zx_status_t = -20;
182
183 // ERR_TIMED_OUT: The time limit for the operation elapsed before
184 // the operation completed.
185 #[allow(unused)] pub const ERR_TIMED_OUT: zx_status_t = -21;
186
187 // ERR_SHOULD_WAIT: The operation cannot be performed currently but
188 // potentially could succeed if the caller waits for a prerequisite
189 // to be satisfied, for example waiting for a handle to be readable
190 // or writable.
191 // Example: Attempting to read from a message pipe that has no
192 // messages waiting but has an open remote will return ERR_SHOULD_WAIT.
193 // Attempting to read from a message pipe that has no messages waiting
194 // and has a closed remote end will return ERR_REMOTE_CLOSED.
195 #[allow(unused)] pub const ERR_SHOULD_WAIT: zx_status_t = -22;
196
197 // ERR_CANCELED: The in-progress operation (e.g., a wait) has been
198 // // canceled.
199 #[allow(unused)] pub const ERR_CANCELED: zx_status_t = -23;
200
201 // ERR_PEER_CLOSED: The operation failed because the remote end
202 // of the subject of the operation was closed.
203 #[allow(unused)] pub const ERR_PEER_CLOSED: zx_status_t = -24;
204
205 // ERR_NOT_FOUND: The requested entity is not found.
206 #[allow(unused)] pub const ERR_NOT_FOUND: zx_status_t = -25;
207
208 // ERR_ALREADY_EXISTS: An object with the specified identifier
209 // already exists.
210 // Example: Attempting to create a file when a file already exists
211 // with that name.
212 #[allow(unused)] pub const ERR_ALREADY_EXISTS: zx_status_t = -26;
213
214 // ERR_ALREADY_BOUND: The operation failed because the named entity
215 // is already owned or controlled by another entity. The operation
216 // could succeed later if the current owner releases the entity.
217 #[allow(unused)] pub const ERR_ALREADY_BOUND: zx_status_t = -27;
218
219 // ERR_UNAVAILABLE: The subject of the operation is currently unable
220 // to perform the operation.
221 // Note: This is used when there's no direct way for the caller to
222 // observe when the subject will be able to perform the operation
223 // and should thus retry.
224 #[allow(unused)] pub const ERR_UNAVAILABLE: zx_status_t = -28;
225
226 // ======= Permission check errors =======
227 // ERR_ACCESS_DENIED: The caller did not have permission to perform
228 // the specified operation.
229 #[allow(unused)] pub const ERR_ACCESS_DENIED: zx_status_t = -30;
230
231 // ======= Input-output errors =======
232 // ERR_IO: Otherwise unspecified error occurred during I/O.
233 #[allow(unused)] pub const ERR_IO: zx_status_t = -40;
234
235 // ERR_REFUSED: The entity the I/O operation is being performed on
236 // rejected the operation.
237 // Example: an I2C device NAK'ing a transaction or a disk controller
238 // rejecting an invalid command.
239 #[allow(unused)] pub const ERR_IO_REFUSED: zx_status_t = -41;
240
241 // ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity
242 // check and is possibly corrupted.
243 // Example: CRC or Parity error.
244 #[allow(unused)] pub const ERR_IO_DATA_INTEGRITY: zx_status_t = -42;
245
246 // ERR_IO_DATA_LOSS: The data in the operation is currently unavailable
247 // and may be permanently lost.
248 // Example: A disk block is irrecoverably damaged.
249 #[allow(unused)] pub const ERR_IO_DATA_LOSS: zx_status_t = -43;
250
251 // Filesystem specific errors
252 #[allow(unused)] pub const ERR_BAD_PATH: zx_status_t = -50;
253 #[allow(unused)] pub const ERR_NOT_DIR: zx_status_t = -51;
254 #[allow(unused)] pub const ERR_NOT_FILE: zx_status_t = -52;
255 // ERR_FILE_BIG: A file exceeds a filesystem-specific size limit.
256 #[allow(unused)] pub const ERR_FILE_BIG: zx_status_t = -53;
257 // ERR_NO_SPACE: Filesystem or device space is exhausted.
258 #[allow(unused)] pub const ERR_NO_SPACE: zx_status_t = -54;