Skip to main content

xila_sys/
bindings.rs

1// Generated from the native application ABI. Do not edit.
2
3use core::ffi::{c_char, c_void};
4/// Native application entry points, in slot order. The header precedes slot zero.
5/// Networking slots return Unsupported when the runtime omits networking, and so does
6/// the graphics slot when it omits graphics.
7#[repr(C)]
8pub struct XilaApi {
9    /// Packed major and minor Xila version: `(major << 16) | minor`.
10    pub version: u32,
11    /// Total size in bytes, including this header.
12    pub size: u32,
13    pub directory_open: unsafe extern "C" fn(
14        parent: *const Directory,
15        path: *const c_char,
16        path_length: usize,
17        rights: u32,
18        directory: *mut *mut Directory,
19    ) -> Status,
20    pub directory_close: unsafe extern "C" fn(directory: *mut Directory) -> Status,
21    pub directory_create: unsafe extern "C" fn(
22        directory: *const Directory,
23        path: *const c_char,
24        length: usize,
25    ) -> Status,
26    pub directory_remove: unsafe extern "C" fn(
27        directory: *const Directory,
28        path: *const c_char,
29        length: usize,
30        flags: u32,
31    ) -> Status,
32    pub directory_rename: unsafe extern "C" fn(
33        from: *const Directory,
34        from_path: *const c_char,
35        from_length: usize,
36        to: *const Directory,
37        to_path: *const c_char,
38        to_length: usize,
39    ) -> Status,
40    pub file_open: unsafe extern "C" fn(
41        directory: *const Directory,
42        path: *const c_char,
43        path_length: usize,
44        flags: u32,
45        file: *mut *mut File,
46    ) -> Status,
47    pub file_read: unsafe extern "C" fn(
48        file: *mut File,
49        buffer: *mut c_void,
50        size: usize,
51        count: *mut usize,
52    ) -> Status,
53    pub file_write: unsafe extern "C" fn(
54        file: *mut File,
55        buffer: *const c_void,
56        size: usize,
57        count: *mut usize,
58    ) -> Status,
59    pub file_seek: unsafe extern "C" fn(
60        file: *mut File,
61        offset: i64,
62        whence: u32,
63        position: *mut u64,
64    ) -> Status,
65    pub file_flush: unsafe extern "C" fn(file: *mut File) -> Status,
66    pub file_close: unsafe extern "C" fn(file: *mut File) -> Status,
67    pub file_set_size: unsafe extern "C" fn(file: *mut File, size: u64) -> Status,
68    pub file_get_statistics: unsafe extern "C" fn(
69        file: *mut File,
70        output: *mut Statistics,
71    ) -> Status,
72    pub directory_get_statistics: unsafe extern "C" fn(
73        directory: *const Directory,
74        path: *const c_char,
75        length: usize,
76        flags: u32,
77        output: *mut Statistics,
78    ) -> Status,
79    pub directory_iterator_open: unsafe extern "C" fn(
80        directory: *const Directory,
81        path: *const c_char,
82        length: usize,
83        output: *mut *mut DirectoryIterator,
84    ) -> Status,
85    pub directory_iterator_next: unsafe extern "C" fn(
86        iterator: *mut DirectoryIterator,
87        name_buffer: *mut c_char,
88        capacity: usize,
89        name_length: *mut usize,
90        kind: *mut u32,
91    ) -> Status,
92    pub directory_iterator_rewind: unsafe extern "C" fn(
93        iterator: *mut DirectoryIterator,
94    ) -> Status,
95    pub directory_iterator_close: unsafe extern "C" fn(
96        iterator: *mut DirectoryIterator,
97    ) -> Status,
98    pub time_monotonic: unsafe extern "C" fn(nanoseconds: *mut u64) -> Status,
99    pub time_realtime: unsafe extern "C" fn(nanoseconds: *mut i64) -> Status,
100    pub network_close: unsafe extern "C" fn(network: *mut Network) -> Status,
101    pub tcp_connect: unsafe extern "C" fn(
102        network: *const Network,
103        address: *const NetworkAddress,
104        timeout_ms: u32,
105        connection: *mut *mut Tcp,
106    ) -> Status,
107    pub tcp_listen: unsafe extern "C" fn(
108        network: *const Network,
109        address: *const NetworkAddress,
110        listener: *mut *mut TcpListener,
111    ) -> Status,
112    pub tcp_accept: unsafe extern "C" fn(
113        listener: *mut TcpListener,
114        connection: *mut *mut Tcp,
115    ) -> Status,
116    pub tcp_close: unsafe extern "C" fn(socket: *mut Tcp) -> Status,
117    pub tcp_listener_close: unsafe extern "C" fn(socket: *mut TcpListener) -> Status,
118    pub tcp_shutdown: unsafe extern "C" fn(socket: *mut Tcp, direction: u32) -> Status,
119    pub tcp_send: unsafe extern "C" fn(
120        socket: *mut Tcp,
121        buffer: *const c_void,
122        size: usize,
123        count: *mut usize,
124    ) -> Status,
125    pub tcp_receive: unsafe extern "C" fn(
126        socket: *mut Tcp,
127        buffer: *mut c_void,
128        size: usize,
129        count: *mut usize,
130    ) -> Status,
131    pub tcp_local_address: unsafe extern "C" fn(
132        socket: *const Tcp,
133        address: *mut NetworkAddress,
134    ) -> Status,
135    pub tcp_peer_address: unsafe extern "C" fn(
136        socket: *const Tcp,
137        address: *mut NetworkAddress,
138    ) -> Status,
139    pub udp_bind: unsafe extern "C" fn(
140        network: *const Network,
141        address: *const NetworkAddress,
142        socket: *mut *mut Udp,
143    ) -> Status,
144    pub udp_close: unsafe extern "C" fn(socket: *mut Udp) -> Status,
145    pub udp_send_to: unsafe extern "C" fn(
146        socket: *mut Udp,
147        buffer: *const c_void,
148        size: usize,
149        address: *const NetworkAddress,
150        count: *mut usize,
151    ) -> Status,
152    pub udp_receive_from: unsafe extern "C" fn(
153        socket: *mut Udp,
154        buffer: *mut c_void,
155        size: usize,
156        address: *mut NetworkAddress,
157        count: *mut usize,
158    ) -> Status,
159    pub network_resolve: unsafe extern "C" fn(
160        network: *const Network,
161        host: *const c_char,
162        host_length: usize,
163        family: u32,
164        addresses: *mut NetworkAddress,
165        count: *mut usize,
166    ) -> Status,
167    /// Allocate uninitialized memory aligned to XILA_HEAP_ALIGNMENT.
168    pub heap_allocate: unsafe extern "C" fn(
169        heap: *mut Heap,
170        size: usize,
171        allocation: *mut *mut c_void,
172    ) -> Status,
173    /// Resize an allocation. Zero size frees the block and stores null.
174    pub heap_reallocate: unsafe extern "C" fn(
175        heap: *mut Heap,
176        pointer: *mut c_void,
177        size: usize,
178        allocation: *mut *mut c_void,
179    ) -> Status,
180    /// Release an allocation from this heap. Null succeeds.
181    pub heap_free: unsafe extern "C" fn(heap: *mut Heap, pointer: *mut c_void) -> Status,
182    /// Read a clock's nominal resolution: XILA_CLOCK_MONOTONIC or XILA_CLOCK_REALTIME.
183    /// Returns Unavailable when the host installed no clock.
184    pub time_resolution: unsafe extern "C" fn(
185        clock: u32,
186        nanoseconds: *mut u64,
187    ) -> Status,
188    /// Suspend for at least the given nanoseconds on the executor's clock. A zero wait
189    /// yields once inside a coroutine and returns at once outside one.
190    pub time_sleep: unsafe extern "C" fn(nanoseconds: u64) -> Status,
191    /// Fill a buffer from the host-granted entropy source. Zero size succeeds. The
192    /// buffer contents are unspecified after a failure.
193    pub random_fill: unsafe extern "C" fn(buffer: *mut c_void, size: usize) -> Status,
194    /// Read the process's identifier.
195    pub process_id: unsafe extern "C" fn(
196        process: *const Process,
197        id: *mut u32,
198    ) -> Status,
199    /// Read the identifier of the process that spawned this one, or zero (the root
200    /// task) once that process has exited.
201    pub process_parent_id: unsafe extern "C" fn(
202        process: *const Process,
203        id: *mut u32,
204    ) -> Status,
205    /// End the process with an exit status. Does not return on success; outside a
206    /// native process coroutine it returns Unsupported.
207    pub process_exit: unsafe extern "C" fn(
208        process: *const Process,
209        status: i32,
210    ) -> Status,
211    /// Start an executable below a directory capability as a child process.
212    pub process_spawn: unsafe extern "C" fn(
213        process: *const Process,
214        directory: *const Directory,
215        path: *const c_char,
216        path_length: usize,
217        spawn: *const Spawn,
218        child: *mut *mut Child,
219    ) -> Status,
220    /// Collect a child's exit status. Only the spawning process may wait; flags:
221    /// XILA_WAIT_NO_HANG.
222    pub process_wait: unsafe extern "C" fn(
223        process: *const Process,
224        child: *mut Child,
225        flags: u32,
226        status: *mut i32,
227    ) -> Status,
228    /// Release a child handle. Null succeeds.
229    pub process_child_close: unsafe extern "C" fn(child: *mut Child) -> Status,
230    /// Read an environment variable; BufferTooSmall stores the required length.
231    pub env_get: unsafe extern "C" fn(
232        process: *const Process,
233        name: *const c_char,
234        name_length: usize,
235        buffer: *mut c_char,
236        capacity: usize,
237        value_length: *mut usize,
238    ) -> Status,
239    /// Set an environment variable of this process.
240    pub env_set: unsafe extern "C" fn(
241        process: *const Process,
242        name: *const c_char,
243        name_length: usize,
244        value: *const c_char,
245        value_length: usize,
246    ) -> Status,
247    /// Remove an environment variable of this process. A missing one succeeds.
248    pub env_remove: unsafe extern "C" fn(
249        process: *const Process,
250        name: *const c_char,
251        name_length: usize,
252    ) -> Status,
253    /// Read a counted NAME=VALUE entry by index; NotFound marks the end.
254    pub env_entry: unsafe extern "C" fn(
255        process: *const Process,
256        index: usize,
257        buffer: *mut c_char,
258        capacity: usize,
259        entry_length: *mut usize,
260    ) -> Status,
261    /// Spawn a worker of the current process; stack_size zero chooses the default.
262    pub thread_spawn: unsafe extern "C" fn(
263        process: *const Process,
264        stack_size: usize,
265        entry: ThreadEntry,
266        argument: *mut c_void,
267        thread: *mut usize,
268    ) -> Status,
269    /// Collect the worker result. Only the thread that created it may join.
270    pub thread_join: unsafe extern "C" fn(
271        thread: usize,
272        result: *mut *mut c_void,
273    ) -> Status,
274    pub thread_detach: unsafe extern "C" fn(thread: usize) -> Status,
275    pub thread_yield: unsafe extern "C" fn() -> Status,
276    pub thread_current: unsafe extern "C" fn(thread: *mut usize) -> Status,
277    pub thread_key_create: unsafe extern "C" fn(key: *mut usize) -> Status,
278    pub thread_key_delete: unsafe extern "C" fn(key: usize) -> Status,
279    pub thread_tls_get: unsafe extern "C" fn(
280        key: usize,
281        value: *mut *mut c_void,
282    ) -> Status,
283    pub thread_tls_set: unsafe extern "C" fn(key: usize, value: *mut c_void) -> Status,
284    /// Address of the SDK-reserved libc state, valid until the current thread ends.
285    pub thread_libc: unsafe extern "C" fn(location: *mut *mut ThreadLibc) -> Status,
286    pub mutex_init: unsafe extern "C" fn(mutex: *mut Mutex, flags: u32) -> Status,
287    pub mutex_destroy: unsafe extern "C" fn(mutex: *mut Mutex) -> Status,
288    /// A contended XILA_MUTEX_TRY returns WouldBlock.
289    pub mutex_lock: unsafe extern "C" fn(mutex: *mut Mutex, flags: u32) -> Status,
290    pub mutex_unlock: unsafe extern "C" fn(mutex: *mut Mutex) -> Status,
291    pub condition_init: unsafe extern "C" fn(condition: *mut Condition) -> Status,
292    pub condition_destroy: unsafe extern "C" fn(condition: *mut Condition) -> Status,
293    /// Unlock and sleep atomically, then reacquire before returning. A null deadline
294    /// means infinite; otherwise use absolute nanoseconds on the selected ABI clock.
295    pub condition_wait: unsafe extern "C" fn(
296        condition: *mut Condition,
297        mutex: *mut Mutex,
298        clock: u32,
299        deadline: *const i64,
300    ) -> Status,
301    pub condition_notify: unsafe extern "C" fn(
302        condition: *mut Condition,
303        all: bool,
304    ) -> Status,
305    /// Report whether any worker is live, including the caller if it is a worker.
306    pub thread_has_workers: unsafe extern "C" fn(live: *mut bool) -> Status,
307    /// Begin terminal cleanup. The process driver will only resume the caller.
308    pub thread_stop_others: unsafe extern "C" fn(process: *const Process) -> Status,
309    /// End a worker with a join result. This returns only on failure.
310    pub thread_exit: unsafe extern "C" fn(result: *mut c_void) -> Status,
311    /// Wait for readiness across file, pipe, directory and socket handles.
312    /// timeout_ms is relative; negative means infinite, zero probes once.
313    pub poll_wait: unsafe extern "C" fn(
314        entries: *mut PollEntry,
315        count: usize,
316        timeout_ms: i32,
317        ready_count: *mut usize,
318    ) -> Status,
319    /// Transfer from an explicit offset without changing the shared cursor.
320    pub file_read_at: unsafe extern "C" fn(
321        file: *mut File,
322        buffer: *mut c_void,
323        size: usize,
324        offset: u64,
325        count: *mut usize,
326    ) -> Status,
327    /// Transfer to an explicit offset without changing the shared cursor.
328    pub file_write_at: unsafe extern "C" fn(
329        file: *mut File,
330        buffer: *const c_void,
331        size: usize,
332        offset: u64,
333        count: *mut usize,
334    ) -> Status,
335    /// Return an owned file that shares the original cursor and status flags.
336    pub file_duplicate: unsafe extern "C" fn(
337        file: *const File,
338        output: *mut *mut File,
339    ) -> Status,
340    /// Query queued pipe bytes or get/set file flags using a uint32_t buffer.
341    pub file_control: unsafe extern "C" fn(
342        file: *mut File,
343        command: u32,
344        input: *const c_void,
345        input_size: usize,
346        output: *mut c_void,
347        output_size: usize,
348    ) -> Status,
349    /// Report whether an open file is an interactive terminal.
350    pub file_is_terminal: unsafe extern "C" fn(
351        file: *mut File,
352        terminal: *mut bool,
353    ) -> Status,
354    /// Create the read and write handles of an unnamed pipe.
355    /// The only supported flag is XILA_OPEN_NON_BLOCKING.
356    pub pipe_create: unsafe extern "C" fn(
357        process: *const Process,
358        flags: u32,
359        reader: *mut *mut File,
360        writer: *mut *mut File,
361    ) -> Status,
362    /// Run one graphics call by its ID from `xila/graphics.h`. `arguments` holds
363    /// `argument_count` words (at most seven; null at zero) and `result` receives the
364    /// call's word or 32-bit result. The SDK's generated functions pack the words.
365    pub graphics_call: unsafe extern "C" fn(
366        process: *const Process,
367        function: u32,
368        arguments: *const usize,
369        argument_count: usize,
370        result: *mut c_void,
371    ) -> Status,
372    /// Read a child's process identifier, the value its `process_id` reports.
373    pub process_child_id: unsafe extern "C" fn(
374        child: *const Child,
375        id: *mut u32,
376    ) -> Status,
377}
378pub const XILA_RIGHT_READ: u32 = 1;
379pub const XILA_RIGHT_WRITE: u32 = 2;
380/// Opaque path capability. Native callers must serialize access and preserve ownership.
381#[repr(C)]
382pub struct Directory {
383    _opaque: [u8; 0],
384    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
385}
386/// Allow removing directories as well as files. Removal never follows the final link.
387pub const XILA_REMOVE_DIRECTORY: u32 = 1;
388pub const XILA_OPEN_READ: u32 = 1;
389pub const XILA_OPEN_WRITE: u32 = 2;
390pub const XILA_OPEN_CREATE: u32 = 4;
391pub const XILA_OPEN_EXCLUSIVE: u32 = 8;
392pub const XILA_OPEN_TRUNCATE: u32 = 16;
393pub const XILA_OPEN_APPEND: u32 = 32;
394pub const XILA_OPEN_NON_BLOCKING: u32 = 64;
395pub const XILA_SEEK_START: u32 = 0;
396pub const XILA_SEEK_CURRENT: u32 = 1;
397pub const XILA_SEEK_END: u32 = 2;
398/// Opaque owned file. No handle lookup or buffer allocation is required for I/O.
399#[repr(C)]
400pub struct File {
401    _opaque: [u8; 0],
402    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
403}
404pub const XILA_CONTROL_BYTES_AVAILABLE: u32 = 1;
405pub const XILA_CONTROL_GET_FILE_FLAGS: u32 = 2;
406pub const XILA_CONTROL_SET_FILE_FLAGS: u32 = 3;
407pub const XILA_PIPE_CAPACITY: usize = 512;
408/// Opaque owned listing with at most one pending VFS entry for buffer retries.
409#[repr(C)]
410pub struct DirectoryIterator {
411    _opaque: [u8; 0],
412    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
413}
414pub const XILA_STATISTICS_NO_FOLLOW: u32 = 1;
415pub const XILA_KIND_FILE: u32 = 1;
416pub const XILA_KIND_DIRECTORY: u32 = 2;
417pub const XILA_KIND_BLOCK_DEVICE: u32 = 3;
418pub const XILA_KIND_CHARACTER_DEVICE: u32 = 4;
419pub const XILA_KIND_PIPE: u32 = 5;
420pub const XILA_KIND_SOCKET: u32 = 6;
421pub const XILA_KIND_SYMLINK: u32 = 7;
422/// Versioned output: initialize size to sizeof(XilaStatistics) before each call.
423#[repr(C)]
424#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
425pub struct Statistics {
426    pub size: u32,
427    pub kind: u32,
428    pub permissions: u32,
429    pub owner_user: u32,
430    pub owner_group: u32,
431    pub reserved: u32,
432    pub file_size: u64,
433    pub link_count: u64,
434    pub inode: u64,
435    pub access_nanoseconds: i64,
436    pub modification_nanoseconds: i64,
437    pub status_change_nanoseconds: i64,
438}
439pub const XILA_NETWORK_CONNECT: u32 = 1;
440pub const XILA_NETWORK_LISTEN: u32 = 2;
441pub const XILA_NETWORK_RESOLVE: u32 = 4;
442pub const XILA_ADDRESS_IPV4: u32 = 4;
443pub const XILA_ADDRESS_IPV6: u32 = 6;
444pub const XILA_SHUTDOWN_WRITE: u32 = 1;
445/// Fixed-width address. Bytes are in network order; integer fields are host order.
446/// IPv4 uses the first four bytes and requires the remaining bytes to be zero.
447/// Scope must be zero: Core does not support scoped IPv6 endpoints.
448#[repr(C)]
449#[derive(Debug, Clone, Copy, PartialEq, Eq)]
450pub struct NetworkAddress {
451    pub family: u32,
452    pub bytes: [u8; 16],
453    pub port: u16,
454    pub reserved: u16,
455    pub scope_id: u32,
456}
457/// Host-granted network authority. Future host/port restrictions belong here.
458#[repr(C)]
459pub struct Network {
460    _opaque: [u8; 0],
461    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
462}
463/// Owned TCP connection. Its creation grants bidirectional I/O authority.
464#[repr(C)]
465pub struct Tcp {
466    _opaque: [u8; 0],
467    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
468}
469/// One pending connection, with no additional backlog. Accept replenishes the socket.
470#[repr(C)]
471pub struct TcpListener {
472    _opaque: [u8; 0],
473    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
474}
475/// Owned UDP socket. Sending additionally requires CONNECT on its parent capability.
476#[repr(C)]
477pub struct Udp {
478    _opaque: [u8; 0],
479    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
480}
481pub const XILA_POLL_IGNORE: u32 = 0;
482pub const XILA_POLL_FILE: u32 = 1;
483pub const XILA_POLL_DIRECTORY: u32 = 2;
484pub const XILA_POLL_TCP: u32 = 3;
485pub const XILA_POLL_TCP_LISTENER: u32 = 4;
486pub const XILA_POLL_UDP: u32 = 5;
487pub const XILA_POLL_IN: u16 = 1;
488pub const XILA_POLL_OUT: u16 = 2;
489pub const XILA_POLL_ERR: u16 = 4;
490pub const XILA_POLL_HUP: u16 = 8;
491pub const XILA_POLL_NVAL: u16 = 16;
492/// One poll entry. Only IN and OUT are requested. ERR, HUP and NVAL are
493/// reported regardless of the request. IGNORE entries always return zero.
494/// A null file/directory/socket or unknown kind reports NVAL.
495#[repr(C)]
496pub struct PollEntry {
497    /// Opaque object of the type named by kind.
498    pub handle: *const c_void,
499    pub kind: u32,
500    pub events: u16,
501    pub revents: u16,
502}
503/// `xila_process_wait` flag: return `WouldBlock` instead of waiting for a running child.
504pub const XILA_WAIT_NO_HANG: u32 = 1;
505/// `XilaSpawn.flags`: give the child the right to connect (and to send datagrams).
506/// The value is `XILA_NETWORK_CONNECT`'s.
507pub const XILA_SPAWN_NETWORK_CONNECT: u32 = 1;
508/// `XilaSpawn.flags`: give the child the right to listen and bind. The value is
509/// `XILA_NETWORK_LISTEN`'s.
510pub const XILA_SPAWN_NETWORK_LISTEN: u32 = 2;
511/// `XilaSpawn.flags`: give the child the right to resolve names. The value is
512/// `XILA_NETWORK_RESOLVE`'s.
513pub const XILA_SPAWN_NETWORK_RESOLVE: u32 = 4;
514/// Opaque capability of the running process: its identity, environment, children and
515/// exit. The host grants it through `XilaStartup.process`; the pointer is borrowed for
516/// the entry call and a process must not pass it to another process.
517#[repr(C)]
518pub struct Process {
519    _opaque: [u8; 0],
520    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
521}
522/// A spawned child, owned by the process that spawned it. It holds the child's
523/// exit status until the owner waits for it, so a child that finished and was not
524/// waited for costs one signal slot and no task. `xila_process_child_close`
525/// releases it, waited for or not.
526#[repr(C)]
527pub struct Child {
528    _opaque: [u8; 0],
529    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
530}
531/// Arguments of `xila_process_spawn`. Set `size` to `sizeof(XilaSpawn)`. All
532/// pointers are borrowed for the call.
533#[repr(C)]
534pub struct Spawn {
535    pub size: u32,
536    /// The network rights the child gets (`XILA_SPAWN_NETWORK_*`). Zero gives it no
537    /// network. Each right must be one the parent holds: a child never gets more than
538    /// its parent. Other bits are reserved and must be zero.
539    pub flags: u32,
540    /// Arguments of the child, with no implicit program name. A null array has count zero.
541    pub arguments: *const XilaString,
542    pub argument_count: usize,
543    /// The child's whole environment as `NAME=VALUE` strings, a later entry overriding an
544    /// earlier one. A null array gives the child a copy of the parent's environment
545    /// and requires count zero. An array with count zero gives it an empty one.
546    pub environment: *const XilaString,
547    pub environment_count: usize,
548    /// Streams the child gets as duplicates of these. All three are required.
549    pub standard_input: *const File,
550    pub standard_output: *const File,
551    pub standard_error: *const File,
552    /// Optional home directory capability the child gets a copy of.
553    pub home: *const Directory,
554}
555/// UTF-8 bytes, not NUL-terminated. A null data pointer is valid only at length zero.
556#[repr(C)]
557pub struct XilaString {
558    pub data: *const c_char,
559    pub length: usize,
560}
561/// Host-owned startup data, valid only for the duration of the entry call.
562/// The API is always present. Capability pointers may be null when not granted;
563/// the process capability is null for an application that is not a process, such
564/// as a built-in one linked into the firmware, whose process calls fail with
565/// InvalidArgument. A null argument array has argument_count zero.
566/// Fields are only ever appended: check `size` before reading a field that a
567/// later Xila version added, such as `network`.
568/// Applications must not close, retain or transfer these objects; closing them is
569/// undefined behavior. Objects opened by the application must still be closed.
570#[repr(C)]
571pub struct XilaStartup {
572    pub size: u32,
573    pub api: *const XilaApi,
574    pub heap: *mut Heap,
575    pub arguments: *const XilaString,
576    pub argument_count: usize,
577    pub standard_input: *mut File,
578    pub standard_output: *mut File,
579    pub standard_error: *mut File,
580    pub home: *mut Directory,
581    pub process: *const Process,
582    /// Executable's launch name. Empty for a linked entry without a process.
583    pub program_name: XilaString,
584    /// Network authority granted to the process, with only the rights its launch
585    /// granted explicitly (connect, listen, resolve). Null unless the launch granted at
586    /// least one right and the host has a network stack, so a process has no network by
587    /// default. Appended after `program_name`, so images built before it existed still
588    /// start.
589    pub network: *const Network,
590}
591/// A native worker entry. Null is rejected.
592pub type ThreadEntry = Option<unsafe extern "C" fn(*mut c_void) -> *mut c_void>;
593pub const XILA_THREAD_STACK_MIN: usize = 2048;
594pub const XILA_THREAD_STACK_MAX: usize = 64 * 1024;
595pub const XILA_THREAD_KEYS_MAX: usize = 8;
596pub const XILA_MUTEX_RECURSIVE: u32 = 1;
597pub const XILA_MUTEX_TRY: u32 = 1;
598/// SDK-reserved coroutine-local libc state. Other applications should use TLS keys.
599#[repr(C)]
600pub struct ThreadLibc {
601    pub(crate) error: i32,
602    pub(crate) strtok_next: *mut c_char,
603    pub(crate) random_state: u64,
604}
605/// Process-local mutex. Zero initialize for a plain mutex, or use mutex_init.
606/// Keep its address fixed from first use through destruction. The fields are private
607/// to the host; copying a used mutex or sharing it across processes is invalid.
608#[repr(C)]
609pub struct Mutex {
610    pub(crate) owner: usize,
611    pub(crate) depth: u32,
612    pub(crate) recursive: bool,
613    pub(crate) waiters: *mut c_void,
614}
615impl Mutex {
616    /// Initial storage, before any host operation.
617    pub const ZERO: Self = Self {
618        owner: 0,
619        depth: 0,
620        recursive: false,
621        waiters: core::ptr::null_mut(),
622    };
623}
624/// Process-local condition variable. Zero initialize or use condition_init.
625/// Keep its address fixed from first use through destruction. The fields are private
626/// to the host; copying a used condition or sharing it across processes is invalid.
627#[repr(C)]
628pub struct Condition {
629    pub(crate) waiters: *mut c_void,
630}
631impl Condition {
632    /// Initial storage, before any host operation.
633    pub const ZERO: Self = Self {
634        waiters: core::ptr::null_mut(),
635    };
636}
637/// Monotonic clock identifier for `xila_time_resolution`.
638pub const XILA_CLOCK_MONOTONIC: u32 = 0;
639/// Realtime (Unix UTC) clock identifier for `xila_time_resolution`.
640pub const XILA_CLOCK_REALTIME: u32 = 1;
641/// Alignment guaranteed for every allocation, including zero-length requests.
642#[cfg(target_arch = "arm")]
643pub const XILA_HEAP_ALIGNMENT: usize = 8;
644/// Alignment guaranteed for every allocation, including zero-length requests.
645#[cfg(not(target_arch = "arm"))]
646pub const XILA_HEAP_ALIGNMENT: usize = 16;
647/// Opaque native heap capability. The process owner drops it after all native
648/// execution ends. Keep ownership outside any stack that can be abandoned.
649///
650/// Native applications are trusted, so misuse detection is cheap rather than
651/// hardened. Every block starts with a header whose tag is the heap's key XOR
652/// the block address. Free and resize read the header that would precede the
653/// pointer and reject it as `InvalidArgument` unless it is aligned and its tag
654/// matches: an interior pointer or a double free (including one through a
655/// pointer that a moving resize left stale) is caught, and so is a
656/// foreign-heap pointer unless the two heaps' keys collide, which is
657/// unlikely. Like a C allocator, this reads through the pointer, so it needs
658/// readable memory below it. It cannot detect a freed block whose memory was
659/// reused by a later allocation of this heap, which then identifies the new
660/// block. Metadata lives in the block, so no operation allocates it and a
661/// shrinking resize never fails because of it.
662#[repr(C)]
663pub struct Heap {
664    _opaque: [u8; 0],
665    _marker: core::marker::PhantomData<(*mut u8, core::marker::PhantomPinned)>,
666}
667/// Native status values mirror the unified error kinds one-to-one. Zero is success.
668#[repr(transparent)]
669#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
670pub struct Status(pub u32);
671#[allow(non_upper_case_globals)]
672impl Status {
673    pub const Ok: Self = Self(0);
674    pub const InvalidArgument: Self = Self(0x0101);
675    pub const InvalidData: Self = Self(0x0102);
676    pub const PermissionDenied: Self = Self(0x0103);
677    pub const OperationNotPermitted: Self = Self(0x0104);
678    pub const InputOutput: Self = Self(0x0105);
679    pub const OutOfMemory: Self = Self(0x0106);
680    pub const WouldBlock: Self = Self(0x0107);
681    pub const ResourceBusy: Self = Self(0x0108);
682    pub const Interrupted: Self = Self(0x0109);
683    pub const TimedOut: Self = Self(0x010a);
684    pub const Unsupported: Self = Self(0x010b);
685    pub const Overflow: Self = Self(0x010c);
686    pub const WriteZero: Self = Self(0x010d);
687    pub const NoBuffers: Self = Self(0x010e);
688    pub const NotFound: Self = Self(0x010f);
689    pub const AlreadyExists: Self = Self(0x0110);
690    pub const InvalidFlags: Self = Self(0x0111);
691    pub const InvalidState: Self = Self(0x0112);
692    pub const NotImplemented: Self = Self(0x0113);
693    pub const ExecFormat: Self = Self(0x0114);
694    pub const NoChild: Self = Self(0x0115);
695    pub const ArgumentListTooLong: Self = Self(0x0116);
696    pub const Deadlock: Self = Self(0x0117);
697    pub const BadDescriptor: Self = Self(0x0201);
698    pub const InvalidPath: Self = Self(0x0202);
699    pub const MissingPathComponent: Self = Self(0x0203);
700    pub const MissingFinalEntry: Self = Self(0x0204);
701    pub const NameTooLong: Self = Self(0x0205);
702    pub const SymlinkLoop: Self = Self(0x0206);
703    pub const NotADirectory: Self = Self(0x0207);
704    pub const IsADirectory: Self = Self(0x0208);
705    pub const DirectoryNotEmpty: Self = Self(0x0209);
706    pub const NoSpace: Self = Self(0x020a);
707    pub const FileTooLarge: Self = Self(0x020b);
708    pub const ProcessFileLimit: Self = Self(0x020c);
709    pub const SystemFileLimit: Self = Self(0x020d);
710    pub const CrossDevice: Self = Self(0x020e);
711    pub const PathEscapesRoot: Self = Self(0x020f);
712    pub const CorruptData: Self = Self(0x0210);
713    pub const MissingAttribute: Self = Self(0x0211);
714    pub const StaleHandle: Self = Self(0x0212);
715    pub const ReadOnlyFileSystem: Self = Self(0x0213);
716    pub const InvalidSeek: Self = Self(0x0214);
717    pub const Unavailable: Self = Self(0x0301);
718    pub const NoSuchTask: Self = Self(0x0302);
719    pub const InappropriateIoControl: Self = Self(0x0303);
720    pub const ConnectionRefused: Self = Self(0x0401);
721    pub const ConnectionReset: Self = Self(0x0402);
722    pub const ConnectionAborted: Self = Self(0x0403);
723    pub const NotConnected: Self = Self(0x0404);
724    pub const AlreadyConnected: Self = Self(0x0405);
725    pub const AddressInUse: Self = Self(0x0406);
726    pub const AddressNotAvailable: Self = Self(0x0407);
727    pub const DestinationRequired: Self = Self(0x0408);
728    pub const HostUnreachable: Self = Self(0x0409);
729    pub const NetworkUnreachable: Self = Self(0x040a);
730    pub const NetworkDown: Self = Self(0x040b);
731    pub const BrokenPipe: Self = Self(0x040c);
732    pub const MessageTooLarge: Self = Self(0x040d);
733    pub const DatagramTruncated: Self = Self(0x040e);
734    pub const SocketOperationUnsupported: Self = Self(0x040f);
735    pub const ProtocolUnsupported: Self = Self(0x0410);
736    pub const AddressFamilyUnsupported: Self = Self(0x0411);
737    pub const InProgress: Self = Self(0x0412);
738    pub const AlreadyInProgress: Self = Self(0x0413);
739    pub const ProtocolError: Self = Self(0x0414);
740    pub const NotASocket: Self = Self(0x0415);
741    pub const InvalidDnsName: Self = Self(0x0501);
742    pub const UnsupportedDnsQuery: Self = Self(0x0502);
743    pub const NameNotResolved: Self = Self(0x0503);
744    pub const ResolverTemporaryFailure: Self = Self(0x0504);
745    pub const ResolverFailure: Self = Self(0x0505);
746    pub const End: Self = Self(0x0701);
747    pub const BufferTooSmall: Self = Self(0x0702);
748}
749/// Major version of the Xila release this ABI belongs to. Native images
750/// record `(XILA_VERSION_MAJOR << 16) | XILA_VERSION_MINOR` in their ABI note.
751pub const XILA_VERSION_MAJOR: u32 = 0;
752/// Minor version of the Xila release this ABI belongs to.
753pub const XILA_VERSION_MINOR: u32 = 1;