Skip to content

Commit 7845c01

Browse files
committed
collect all Fuchsia bindings into the fuchsia module
The Fuchsia bindings are currently spread out across multiple modules in `sys/pal/unix` leading to unnecessary duplication. This PR moves all of these definitions into `sys::pal::unix::fuchsia` and additionally: * deduplicates the definitions * makes the error names consistent * marks some extern functions as safe * removes unused items (there's no need to maintain these bindings if we're not going to use them) * removes the documentation for the definitions (contributors should always consult the platform documentation, duplicating that here is just an extra maintenance burden)
1 parent 54d024e commit 7845c01

5 files changed

Lines changed: 122 additions & 282 deletions

File tree

Lines changed: 108 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,35 @@
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+
usecrate::ffi::{c_char, c_int, c_void};
56
usecrate::io;
6-
usecrate::mem::MaybeUninit;
7-
usecrate::os::raw::c_char;
87

9-
pubtypezx_handle_t = u32;
10-
pubtypezx_vaddr_t = usize;
11-
pubtypezx_rights_t = u32;
12-
pubtypezx_status_t = i32;
13-
14-
pubconstZX_HANDLE_INVALID:zx_handle_t = 0;
8+
//////////
9+
// Time //
10+
//////////
1511

1612
pubtypezx_time_t = i64;
17-
pubconstZX_TIME_INFINITE:zx_time_t = i64::MAX;
18-
19-
pubtypezx_signals_t = u32;
20-
21-
pubconstZX_OBJECT_SIGNAL_3:zx_signals_t = 1 << 3;
2213

23-
pubconstZX_TASK_TERMINATED:zx_signals_t = ZX_OBJECT_SIGNAL_3;
14+
pubconstZX_TIME_INFINITE:zx_time_t = i64::MAX;
2415

25-
pubconstZX_RIGHT_SAME_RIGHTS:zx_rights_t = 1 << 31;
16+
unsafeextern"C"{
17+
pub safe fnzx_clock_get_monotonic() -> zx_time_t;
18+
}
2619

27-
// The upper four bits gives the minor version.
28-
pubtypezx_object_info_topic_t = u32;
20+
/////////////
21+
// Handles //
22+
/////////////
2923

30-
pubconstZX_INFO_PROCESS:zx_object_info_topic_t = 3 | (1 << 28);
24+
pubtypezx_handle_t = u32;
3125

32-
pubtypezx_info_process_flags_t = u32;
26+
pubconstZX_HANDLE_INVALID:zx_handle_t = 0;
3327

34-
pubfnzx_cvt<T>(t:T) -> io::Result<T>
35-
where
36-
T:TryInto<zx_status_t> + Copy,
37-
{
38-
ifletOk(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+
unsafeextern"C"{
29+
pubfnzx_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`.
4633
pubstructHandle{
4734
raw:zx_handle_t,
4835
}
@@ -65,6 +52,66 @@ impl Drop for Handle {
6552
}
6653
}
6754

55+
///////////
56+
// Futex //
57+
///////////
58+
59+
pubtypezx_futex_t = crate::sync::atomic::Atomic<u32>;
60+
61+
unsafeextern"C"{
62+
pubfnzx_object_wait_one(
63+
handle:zx_handle_t,
64+
signals:zx_signals_t,
65+
timeout:zx_time_t,
66+
pending:*mutzx_signals_t,
67+
) -> zx_status_t;
68+
69+
pubfnzx_futex_wait(
70+
value_ptr:*constzx_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+
pubfnzx_futex_wake(value_ptr:*constzx_futex_t,wake_count:u32) -> zx_status_t;
76+
pubfnzx_futex_wake_single_owner(value_ptr:*constzx_futex_t) -> zx_status_t;
77+
pub safe fnzx_thread_self() -> zx_handle_t;
78+
}
79+
80+
////////////////
81+
// Properties //
82+
////////////////
83+
84+
pubconstZX_PROP_NAME:u32 = 3;
85+
86+
unsafeextern"C"{
87+
pubfnzx_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+
pubtypezx_signals_t = u32;
100+
101+
pubconstZX_OBJECT_SIGNAL_3:zx_signals_t = 1 << 3;
102+
pubconstZX_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+
pubtypezx_object_info_topic_t = u32;
110+
111+
pubconstZX_INFO_PROCESS:zx_object_info_topic_t = 3 | (1 << 28);
112+
113+
pubtypezx_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

78125
unsafeextern"C"{
79-
pubfnzx_job_default() -> zx_handle_t;
80-
81-
pubfnzx_task_kill(handle:zx_handle_t) -> zx_status_t;
82-
83-
pubfnzx_handle_close(handle:zx_handle_t) -> zx_status_t;
84-
85-
pubfnzx_handle_duplicate(
86-
handle:zx_handle_t,
87-
rights:zx_rights_t,
88-
out:*constzx_handle_t,
89-
) -> zx_handle_t;
90-
91-
pubfnzx_object_wait_one(
92-
handle:zx_handle_t,
93-
signals:zx_signals_t,
94-
timeout:zx_time_t,
95-
pending:*mutzx_signals_t,
96-
) -> zx_status_t;
97-
98126
pubfnzx_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)]
110142
pubstructfdio_spawn_action_t{
@@ -130,180 +162,43 @@ unsafe extern "C" {
130162

131163
pubfnfdio_fd_clone(fd:c_int,out_handle:*mutzx_handle_t) -> zx_status_t;
132164
pubfnfdio_fd_create(handle:zx_handle_t,fd:*mutc_int) -> zx_status_t;
165+
166+
pubfnzx_task_kill(handle:zx_handle_t) -> zx_status_t;
133167
}
134168

135169
// fdio_spawn_etc flags
136170

137171
pubconstFDIO_SPAWN_CLONE_JOB:u32 = 0x0001;
138172
pubconstFDIO_SPAWN_CLONE_LDSVC:u32 = 0x0002;
139173
pubconstFDIO_SPAWN_CLONE_NAMESPACE:u32 = 0x0004;
140-
pubconstFDIO_SPAWN_CLONE_STDIO:u32 = 0x0008;
141174
pubconstFDIO_SPAWN_CLONE_ENVIRON:u32 = 0x0010;
142175
pubconstFDIO_SPAWN_CLONE_UTC_CLOCK:u32 = 0x0020;
143-
pubconstFDIO_SPAWN_CLONE_ALL:u32 = 0xFFFF;
144176

145177
// fdio_spawn_etc actions
146178

147-
pubconstFDIO_SPAWN_ACTION_CLONE_FD:u32 = 0x0001;
148179
pubconstFDIO_SPAWN_ACTION_TRANSFER_FD:u32 = 0x0002;
149180

150-
// Errors
151-
152-
#[allow(unused)]
153-
pubconstERR_INTERNAL:zx_status_t = -1;
154-
155-
// ERR_NOT_SUPPORTED: The operation is not implemented, supported,
156-
// or enabled.
157-
#[allow(unused)]
158-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_WRONG_TYPE:zx_status_t = -12;
194-
195-
// ERR_BAD_SYSCALL: The specified syscall number is invalid.
196-
#[allow(unused)]
197-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_PEER_CLOSED:zx_status_t = -24;
241-
242-
// ERR_NOT_FOUND: The requested entity is not found.
243-
#[allow(unused)]
244-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_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-
pubconstERR_IO_DATA_LOSS:zx_status_t = -43;
296-
297-
// Filesystem specific errors
298-
#[allow(unused)]
299-
pubconstERR_BAD_PATH:zx_status_t = -50;
300-
#[allow(unused)]
301-
pubconstERR_NOT_DIR:zx_status_t = -51;
302-
#[allow(unused)]
303-
pubconstERR_NOT_FILE:zx_status_t = -52;
304-
// ERR_FILE_BIG: A file exceeds a filesystem-specific size limit.
305-
#[allow(unused)]
306-
pubconstERR_FILE_BIG:zx_status_t = -53;
307-
// ERR_NO_SPACE: Filesystem or device space is exhausted.
308-
#[allow(unused)]
309-
pubconstERR_NO_SPACE:zx_status_t = -54;
181+
////////////
182+
// Errors //
183+
////////////
184+
185+
pubtypezx_status_t = i32;
186+
187+
pubconstZX_OK:zx_status_t = 0;
188+
pubconstZX_ERR_NOT_SUPPORTED:zx_status_t = -2;
189+
pubconstZX_ERR_INVALID_ARGS:zx_status_t = -10;
190+
pubconstZX_ERR_BAD_HANDLE:zx_status_t = -11;
191+
pubconstZX_ERR_WRONG_TYPE:zx_status_t = -12;
192+
pubconstZX_ERR_BAD_STATE:zx_status_t = -20;
193+
pubconstZX_ERR_TIMED_OUT:zx_status_t = -21;
194+
195+
pubfnzx_cvt<T>(t:T) -> io::Result<T>
196+
where
197+
T:TryInto<zx_status_t> + Copy,
198+
{
199+
ifletOk(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

Comments
 (0)