1- #![ allow ( non_camel_case_types,  unused ) ]  
1+ #![ expect ( non_camel_case_types) ]  
22
3- use  libc:: { c_int ,  c_void ,   size_t} ; 
3+ use  libc:: size_t; 
44
5+ use  crate :: ffi:: { c_char,  c_int,  c_void} ; 
56use  crate :: io; 
6- use  crate :: mem:: MaybeUninit ; 
7- use  crate :: os:: raw:: c_char; 
87
9- pub  type  zx_handle_t  = u32 ; 
10- pub  type  zx_vaddr_t  = usize ; 
11- pub  type  zx_rights_t  = u32 ; 
12- pub  type  zx_status_t  = i32 ; 
13- 
14- pub  const  ZX_HANDLE_INVALID :  zx_handle_t  = 0 ; 
8+ ////////// 
9+ // Time // 
10+ ////////// 
1511
1612pub  type  zx_time_t  = i64 ; 
17- pub  const  ZX_TIME_INFINITE :  zx_time_t  = i64:: MAX ; 
18- 
19- pub  type  zx_signals_t  = u32 ; 
20- 
21- pub  const  ZX_OBJECT_SIGNAL_3 :  zx_signals_t  = 1  << 3 ; 
2213
23- pub  const  ZX_TASK_TERMINATED :   zx_signals_t  = ZX_OBJECT_SIGNAL_3 ; 
14+ pub  const  ZX_TIME_INFINITE :   zx_time_t  = i64 :: MAX ; 
2415
25- pub  const  ZX_RIGHT_SAME_RIGHTS :  zx_rights_t  = 1  << 31 ; 
16+ unsafe  extern  "C"  { 
17+     pub  safe fn  zx_clock_get_monotonic ( )  -> zx_time_t ; 
18+ } 
2619
27- // The upper four bits gives the minor version. 
28- pub  type  zx_object_info_topic_t  = u32 ; 
20+ ///////////// 
21+ // Handles // 
22+ ///////////// 
2923
30- pub  const   ZX_INFO_PROCESS :   zx_object_info_topic_t  =  3  |  ( 1  <<  28 ) ; 
24+ pub  type   zx_handle_t  =  u32 ; 
3125
32- pub  type   zx_info_process_flags_t  =  u32 ; 
26+ pub  const   ZX_HANDLE_INVALID :   zx_handle_t  =  0 ; 
3327
34- pub  fn  zx_cvt < T > ( t :  T )  -> io:: Result < T > 
35- where 
36-     T :  TryInto < zx_status_t >  + Copy , 
37- { 
38-     if  let  Ok ( status)  = TryInto :: try_into ( t)  { 
39-         if  status < 0  {  Err ( io:: Error :: from_raw_os_error ( status) )  }  else  {  Ok ( t)  } 
40-     }  else  { 
41-         Err ( io:: Error :: last_os_error ( ) ) 
42-     } 
28+ unsafe  extern  "C"  { 
29+     pub  fn  zx_handle_close ( handle :  zx_handle_t )  -> zx_status_t ; 
4330} 
4431
45- // Safe  wrapper around zx_handle_t 
32+ /// A safe  wrapper around ` zx_handle_t`.  
4633pub  struct  Handle  { 
4734    raw :  zx_handle_t , 
4835} 
@@ -65,6 +52,66 @@ impl Drop for Handle {
6552    } 
6653} 
6754
55+ /////////// 
56+ // Futex // 
57+ /////////// 
58+ 
59+ pub  type  zx_futex_t  = crate :: sync:: atomic:: Atomic < u32 > ; 
60+ 
61+ unsafe  extern  "C"  { 
62+     pub  fn  zx_object_wait_one ( 
63+         handle :  zx_handle_t , 
64+         signals :  zx_signals_t , 
65+         timeout :  zx_time_t , 
66+         pending :  * mut  zx_signals_t , 
67+     )  -> zx_status_t ; 
68+ 
69+     pub  fn  zx_futex_wait ( 
70+         value_ptr :  * const  zx_futex_t , 
71+         current_value :  zx_futex_t , 
72+         new_futex_owner :  zx_handle_t , 
73+         deadline :  zx_time_t , 
74+     )  -> zx_status_t ; 
75+     pub  fn  zx_futex_wake ( value_ptr :  * const  zx_futex_t ,  wake_count :  u32 )  -> zx_status_t ; 
76+     pub  fn  zx_futex_wake_single_owner ( value_ptr :  * const  zx_futex_t )  -> zx_status_t ; 
77+     pub  safe fn  zx_thread_self ( )  -> zx_handle_t ; 
78+ } 
79+ 
80+ //////////////// 
81+ // Properties // 
82+ //////////////// 
83+ 
84+ pub  const  ZX_PROP_NAME :  u32  = 3 ; 
85+ 
86+ unsafe  extern  "C"  { 
87+     pub  fn  zx_object_set_property ( 
88+         handle :  zx_handle_t , 
89+         property :  u32 , 
90+         value :  * const  libc:: c_void , 
91+         value_size :  libc:: size_t , 
92+     )  -> zx_status_t ; 
93+ } 
94+ 
95+ ///////////// 
96+ // Signals // 
97+ ///////////// 
98+ 
99+ pub  type  zx_signals_t  = u32 ; 
100+ 
101+ pub  const  ZX_OBJECT_SIGNAL_3 :  zx_signals_t  = 1  << 3 ; 
102+ pub  const  ZX_TASK_TERMINATED :  zx_signals_t  = ZX_OBJECT_SIGNAL_3 ; 
103+ 
104+ ///////////////// 
105+ // Object info // 
106+ ///////////////// 
107+ 
108+ // The upper four bits gives the minor version. 
109+ pub  type  zx_object_info_topic_t  = u32 ; 
110+ 
111+ pub  const  ZX_INFO_PROCESS :  zx_object_info_topic_t  = 3  | ( 1  << 28 ) ; 
112+ 
113+ pub  type  zx_info_process_flags_t  = u32 ; 
114+ 
68115// Returned for topic ZX_INFO_PROCESS 
69116#[ derive( Default ) ]  
70117#[ repr( C ) ]  
@@ -76,25 +123,6 @@ pub struct zx_info_process_t {
76123} 
77124
78125unsafe  extern  "C"  { 
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 ( 
86-         handle :  zx_handle_t , 
87-         rights :  zx_rights_t , 
88-         out :  * const  zx_handle_t , 
89-     )  -> zx_handle_t ; 
90- 
91-     pub  fn  zx_object_wait_one ( 
92-         handle :  zx_handle_t , 
93-         signals :  zx_signals_t , 
94-         timeout :  zx_time_t , 
95-         pending :  * mut  zx_signals_t , 
96-     )  -> zx_status_t ; 
97- 
98126    pub  fn  zx_object_get_info ( 
99127        handle :  zx_handle_t , 
100128        topic :  u32 , 
@@ -105,6 +133,10 @@ unsafe extern "C" {
105133    )  -> zx_status_t ; 
106134} 
107135
136+ /////////////// 
137+ // Processes // 
138+ /////////////// 
139+ 
108140#[ derive( Default ) ]  
109141#[ repr( C ) ]  
110142pub  struct  fdio_spawn_action_t  { 
@@ -130,180 +162,43 @@ unsafe extern "C" {
130162
131163    pub  fn  fdio_fd_clone ( fd :  c_int ,  out_handle :  * mut  zx_handle_t )  -> zx_status_t ; 
132164    pub  fn  fdio_fd_create ( handle :  zx_handle_t ,  fd :  * mut  c_int )  -> zx_status_t ; 
165+ 
166+     pub  fn  zx_task_kill ( handle :  zx_handle_t )  -> zx_status_t ; 
133167} 
134168
135169// fdio_spawn_etc flags 
136170
137171pub  const  FDIO_SPAWN_CLONE_JOB :  u32  = 0x0001 ; 
138172pub  const  FDIO_SPAWN_CLONE_LDSVC :  u32  = 0x0002 ; 
139173pub  const  FDIO_SPAWN_CLONE_NAMESPACE :  u32  = 0x0004 ; 
140- pub  const  FDIO_SPAWN_CLONE_STDIO :  u32  = 0x0008 ; 
141174pub  const  FDIO_SPAWN_CLONE_ENVIRON :  u32  = 0x0010 ; 
142175pub  const  FDIO_SPAWN_CLONE_UTC_CLOCK :  u32  = 0x0020 ; 
143- pub  const  FDIO_SPAWN_CLONE_ALL :  u32  = 0xFFFF ; 
144176
145177// fdio_spawn_etc actions 
146178
147- pub  const  FDIO_SPAWN_ACTION_CLONE_FD :  u32  = 0x0001 ; 
148179pub  const  FDIO_SPAWN_ACTION_TRANSFER_FD :  u32  = 0x0002 ; 
149180
150- // Errors 
151- 
152- #[ allow( unused) ]  
153- pub  const  ERR_INTERNAL :  zx_status_t  = -1 ; 
154- 
155- // ERR_NOT_SUPPORTED: The operation is not implemented, supported, 
156- // or enabled. 
157- #[ allow( unused) ]  
158- pub  const  ERR_NOT_SUPPORTED :  zx_status_t  = -2 ; 
159- 
160- // ERR_NO_RESOURCES: The system was not able to allocate some resource 
161- // needed for the operation. 
162- #[ allow( unused) ]  
163- pub  const  ERR_NO_RESOURCES :  zx_status_t  = -3 ; 
164- 
165- // ERR_NO_MEMORY: The system was not able to allocate memory needed 
166- // for the operation. 
167- #[ allow( unused) ]  
168- pub  const  ERR_NO_MEMORY :  zx_status_t  = -4 ; 
169- 
170- // ERR_CALL_FAILED: The second phase of zx_channel_call(; did not complete 
171- // successfully. 
172- #[ allow( unused) ]  
173- pub  const  ERR_CALL_FAILED :  zx_status_t  = -5 ; 
174- 
175- // ERR_INTERRUPTED_RETRY: The system call was interrupted, but should be 
176- // retried.  This should not be seen outside of the VDSO. 
177- #[ allow( unused) ]  
178- pub  const  ERR_INTERRUPTED_RETRY :  zx_status_t  = -6 ; 
179- 
180- // ======= Parameter errors ======= 
181- // ERR_INVALID_ARGS: an argument is invalid, ex. null pointer 
182- #[ allow( unused) ]  
183- pub  const  ERR_INVALID_ARGS :  zx_status_t  = -10 ; 
184- 
185- // ERR_BAD_HANDLE: A specified handle value does not refer to a handle. 
186- #[ allow( unused) ]  
187- pub  const  ERR_BAD_HANDLE :  zx_status_t  = -11 ; 
188- 
189- // ERR_WRONG_TYPE: The subject of the operation is the wrong type to 
190- // perform the operation. 
191- // Example: Attempting a message_read on a thread handle. 
192- #[ allow( unused) ]  
193- pub  const  ERR_WRONG_TYPE :  zx_status_t  = -12 ; 
194- 
195- // ERR_BAD_SYSCALL: The specified syscall number is invalid. 
196- #[ allow( unused) ]  
197- pub  const  ERR_BAD_SYSCALL :  zx_status_t  = -13 ; 
198- 
199- // ERR_OUT_OF_RANGE: An argument is outside the valid range for this 
200- // operation. 
201- #[ allow( unused) ]  
202- pub  const  ERR_OUT_OF_RANGE :  zx_status_t  = -14 ; 
203- 
204- // ERR_BUFFER_TOO_SMALL: A caller provided buffer is too small for 
205- // this operation. 
206- #[ allow( unused) ]  
207- pub  const  ERR_BUFFER_TOO_SMALL :  zx_status_t  = -15 ; 
208- 
209- // ======= Precondition or state errors ======= 
210- // ERR_BAD_STATE: operation failed because the current state of the 
211- // object does not allow it, or a precondition of the operation is 
212- // not satisfied 
213- #[ allow( unused) ]  
214- pub  const  ERR_BAD_STATE :  zx_status_t  = -20 ; 
215- 
216- // ERR_TIMED_OUT: The time limit for the operation elapsed before 
217- // the operation completed. 
218- #[ allow( unused) ]  
219- pub  const  ERR_TIMED_OUT :  zx_status_t  = -21 ; 
220- 
221- // ERR_SHOULD_WAIT: The operation cannot be performed currently but 
222- // potentially could succeed if the caller waits for a prerequisite 
223- // to be satisfied, for example waiting for a handle to be readable 
224- // or writable. 
225- // Example: Attempting to read from a message pipe that has no 
226- // messages waiting but has an open remote will return ERR_SHOULD_WAIT. 
227- // Attempting to read from a message pipe that has no messages waiting 
228- // and has a closed remote end will return ERR_REMOTE_CLOSED. 
229- #[ allow( unused) ]  
230- pub  const  ERR_SHOULD_WAIT :  zx_status_t  = -22 ; 
231- 
232- // ERR_CANCELED: The in-progress operation (e.g., a wait) has been 
233- // // canceled. 
234- #[ allow( unused) ]  
235- pub  const  ERR_CANCELED :  zx_status_t  = -23 ; 
236- 
237- // ERR_PEER_CLOSED: The operation failed because the remote end 
238- // of the subject of the operation was closed. 
239- #[ allow( unused) ]  
240- pub  const  ERR_PEER_CLOSED :  zx_status_t  = -24 ; 
241- 
242- // ERR_NOT_FOUND: The requested entity is not found. 
243- #[ allow( unused) ]  
244- pub  const  ERR_NOT_FOUND :  zx_status_t  = -25 ; 
245- 
246- // ERR_ALREADY_EXISTS: An object with the specified identifier 
247- // already exists. 
248- // Example: Attempting to create a file when a file already exists 
249- // with that name. 
250- #[ allow( unused) ]  
251- pub  const  ERR_ALREADY_EXISTS :  zx_status_t  = -26 ; 
252- 
253- // ERR_ALREADY_BOUND: The operation failed because the named entity 
254- // is already owned or controlled by another entity. The operation 
255- // could succeed later if the current owner releases the entity. 
256- #[ allow( unused) ]  
257- pub  const  ERR_ALREADY_BOUND :  zx_status_t  = -27 ; 
258- 
259- // ERR_UNAVAILABLE: The subject of the operation is currently unable 
260- // to perform the operation. 
261- // Note: This is used when there's no direct way for the caller to 
262- // observe when the subject will be able to perform the operation 
263- // and should thus retry. 
264- #[ allow( unused) ]  
265- pub  const  ERR_UNAVAILABLE :  zx_status_t  = -28 ; 
266- 
267- // ======= Permission check errors ======= 
268- // ERR_ACCESS_DENIED: The caller did not have permission to perform 
269- // the specified operation. 
270- #[ allow( unused) ]  
271- pub  const  ERR_ACCESS_DENIED :  zx_status_t  = -30 ; 
272- 
273- // ======= Input-output errors ======= 
274- // ERR_IO: Otherwise unspecified error occurred during I/O. 
275- #[ allow( unused) ]  
276- pub  const  ERR_IO :  zx_status_t  = -40 ; 
277- 
278- // ERR_REFUSED: The entity the I/O operation is being performed on 
279- // rejected the operation. 
280- // Example: an I2C device NAK'ing a transaction or a disk controller 
281- // rejecting an invalid command. 
282- #[ allow( unused) ]  
283- pub  const  ERR_IO_REFUSED :  zx_status_t  = -41 ; 
284- 
285- // ERR_IO_DATA_INTEGRITY: The data in the operation failed an integrity 
286- // check and is possibly corrupted. 
287- // Example: CRC or Parity error. 
288- #[ allow( unused) ]  
289- pub  const  ERR_IO_DATA_INTEGRITY :  zx_status_t  = -42 ; 
290- 
291- // ERR_IO_DATA_LOSS: The data in the operation is currently unavailable 
292- // and may be permanently lost. 
293- // Example: A disk block is irrecoverably damaged. 
294- #[ allow( unused) ]  
295- pub  const  ERR_IO_DATA_LOSS :  zx_status_t  = -43 ; 
296- 
297- // Filesystem specific errors 
298- #[ allow( unused) ]  
299- pub  const  ERR_BAD_PATH :  zx_status_t  = -50 ; 
300- #[ allow( unused) ]  
301- pub  const  ERR_NOT_DIR :  zx_status_t  = -51 ; 
302- #[ allow( unused) ]  
303- pub  const  ERR_NOT_FILE :  zx_status_t  = -52 ; 
304- // ERR_FILE_BIG: A file exceeds a filesystem-specific size limit. 
305- #[ allow( unused) ]  
306- pub  const  ERR_FILE_BIG :  zx_status_t  = -53 ; 
307- // ERR_NO_SPACE: Filesystem or device space is exhausted. 
308- #[ allow( unused) ]  
309- pub  const  ERR_NO_SPACE :  zx_status_t  = -54 ; 
181+ //////////// 
182+ // Errors // 
183+ //////////// 
184+ 
185+ pub  type  zx_status_t  = i32 ; 
186+ 
187+ pub  const  ZX_OK :  zx_status_t  = 0 ; 
188+ pub  const  ZX_ERR_NOT_SUPPORTED :  zx_status_t  = -2 ; 
189+ pub  const  ZX_ERR_INVALID_ARGS :  zx_status_t  = -10 ; 
190+ pub  const  ZX_ERR_BAD_HANDLE :  zx_status_t  = -11 ; 
191+ pub  const  ZX_ERR_WRONG_TYPE :  zx_status_t  = -12 ; 
192+ pub  const  ZX_ERR_BAD_STATE :  zx_status_t  = -20 ; 
193+ pub  const  ZX_ERR_TIMED_OUT :  zx_status_t  = -21 ; 
194+ 
195+ pub  fn  zx_cvt < T > ( t :  T )  -> io:: Result < T > 
196+ where 
197+     T :  TryInto < zx_status_t >  + Copy , 
198+ { 
199+     if  let  Ok ( status)  = TryInto :: try_into ( t)  { 
200+         if  status < 0  {  Err ( io:: Error :: from_raw_os_error ( status) )  }  else  {  Ok ( t)  } 
201+     }  else  { 
202+         Err ( io:: Error :: last_os_error ( ) ) 
203+     } 
204+ } 
0 commit comments