interplane.Get Omega
Read in your language

aienux

Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.

Brought by drakestapleton

branch main Branches Tags History

aienux / vendor / libc / src / new / qurt / mod.rs

337 lines · 9905 bytes Raw Blame History
1//! QuRT (Qualcomm Real-Time OS) bindings
2//!
3//! QuRT is Qualcomm's real-time operating system for Hexagon DSP architectures.
4//! Headers available via the
5//! Hexagon SDK: https://softwarecenter.qualcomm.com/catalog/item/Hexagon_SDK
6
7use crate::prelude::*;
8
9// Basic C types for QuRT
10pub type intptr_t = isize;
11pub type uintptr_t = usize;
12pub type ptrdiff_t = isize;
13pub type size_t = uintptr_t;
14pub type ssize_t = c_int;
15
16// Process and system types
17pub type pid_t = c_int;
18pub type uid_t = c_uint;
19pub type gid_t = c_uint;
20
21// Time types
22pub type time_t = c_long;
23pub type suseconds_t = c_long;
24pub type useconds_t = c_ulong;
25pub type clockid_t = c_int;
26pub type timer_t = *mut c_void;
27
28// File system types
29pub type dev_t = c_ulonglong;
30pub type ino_t = c_ulonglong;
31pub type mode_t = c_uint;
32pub type nlink_t = c_uint;
33pub type off_t = c_long;
34pub type blkcnt_t = c_long;
35pub type blksize_t = c_long;
36
37// Thread types based on QuRT pthread implementation
38pub type pthread_t = c_uint;
39pub type pthread_key_t = c_int;
40pub type pthread_once_t = c_int;
41pub type pthread_mutex_t = c_uint;
42// QuRT pthread_mutexattr_t is a struct with 4 ints (is_initialized, type, pshared, protocol)
43pub type pthread_mutexattr_t = [c_uint; 4];
44pub type pthread_cond_t = c_uint;
45// QuRT pthread_condattr_t is a struct with 3 ints (is_initialized, pshared, clock_id)
46pub type pthread_condattr_t = [c_uint; 3];
47// pthread_attr_t is defined as a struct in the s! block below
48pub type pthread_rwlock_t = *mut c_void;
49pub type pthread_rwlockattr_t = *mut c_void;
50pub type pthread_spinlock_t = c_uint;
51pub type pthread_barrier_t = c_uint;
52// QuRT pthread_barrierattr_t is a struct with 2 ints (is_initialized, pshared)
53pub type pthread_barrierattr_t = [c_uint; 2];
54
55// Network types
56pub type socklen_t = c_uint;
57pub type sa_family_t = c_ushort;
58pub type in_addr_t = c_uint;
59pub type in_port_t = c_ushort;
60
61// File descriptor types - QuRT defines fd_set as a struct in mqueue.h
62// FD_SETSIZE = 256, NFDBITS = 32, so fds_bits has 8 elements
63
64// Standard C library types
65extern_ty! {
66 pub type FILE;
67}
68pub type fpos_t = c_long;
69pub type clock_t = c_long;
70
71// POSIX semaphore types - QuRT sem_t is a struct with an opaque pointer
72
73// Message queue types
74pub type mqd_t = c_int;
75
76// Additional file system types
77pub type nfds_t = c_ulong;
78
79// Signal types
80pub type sigset_t = c_ulong;
81
82// Variadic argument list type
83pub type va_list = *mut c_char;
84
85// Wide character type (hexagon uses signed wchar_t)
86pub type wchar_t = i32;
87
88// Error type (compatible with std expectations)
89pub type errno_t = c_int;
90
91// Division result types and structures
92s! {
93 pub struct div_t {
94 pub quot: c_int,
95 pub rem: c_int,
96 }
97
98 pub struct ldiv_t {
99 pub quot: c_long,
100 pub rem: c_long,
101 }
102
103 pub struct lldiv_t {
104 pub quot: c_longlong,
105 pub rem: c_longlong,
106 }
107
108 pub struct stat {
109 pub st_dev: dev_t,
110 pub st_ino: ino_t,
111 pub st_mode: mode_t,
112 pub st_nlink: nlink_t,
113 pub st_rdev: dev_t,
114 pub st_size: off_t,
115 pub st_atime: time_t,
116 pub st_mtime: time_t,
117 pub st_ctime: time_t,
118 }
119
120 pub struct tm {
121 pub tm_sec: c_int,
122 pub tm_min: c_int,
123 pub tm_hour: c_int,
124 pub tm_mday: c_int,
125 pub tm_mon: c_int,
126 pub tm_year: c_int,
127 pub tm_wday: c_int,
128 pub tm_yday: c_int,
129 pub tm_isdst: c_int,
130 }
131
132 #[derive(Default)]
133 pub struct timespec {
134 pub tv_sec: time_t,
135 pub tv_nsec: c_long,
136 }
137
138 #[derive(Default)]
139 pub struct timeval {
140 pub tv_sec: time_t,
141 pub tv_usec: suseconds_t,
142 }
143
144 pub struct itimerspec {
145 pub it_interval: timespec,
146 pub it_value: timespec,
147 }
148
149 pub struct dirent {
150 pub d_ino: c_long,
151 pub d_name: [c_char; 255],
152 }
153
154 pub struct DIR {
155 pub index: c_int,
156 pub entry: dirent,
157 }
158
159 // File lock structure (from toolchain generic fcntl.h)
160 pub struct flock {
161 pub l_type: c_short,
162 pub l_whence: c_short,
163 pub l_start: off_t,
164 pub l_len: off_t,
165 pub l_pid: pid_t,
166 }
167
168 // QuRT fd_set from mqueue.h: FD_SETSIZE=256, NFDBITS=32 (sizeof(fd_mask)*8)
169 pub struct fd_set {
170 pub fds_bits: [c_ulong; 8],
171 }
172
173 // QuRT sem_t from semaphore.h: struct with opaque pointer
174 pub struct sem_t {
175 pub opaque: *mut c_uint,
176 }
177
178 // QuRT pthread_attr_t - matches pthread_types.h struct layout
179 pub struct pthread_attr_t {
180 pub stackaddr: *mut c_void,
181 pub internal_stack: c_int,
182 pub stacksize: size_t,
183 pub priority: c_int,
184 pub timetest_id: c_ushort,
185 __bitfield: c_ushort,
186 pub cpumask: cpu_set_t,
187 pub name: [c_char; 16],
188 pub ext_context: c_int,
189 pub detachstate: c_int,
190 }
191}
192
193// Additional pthread constants
194pub const PTHREAD_NAME_LEN: c_int = 16;
195pub const PTHREAD_MAX_THREADS: c_uint = 512;
196pub const PTHREAD_MIN_STACKSIZE: c_int = 512;
197pub const PTHREAD_MAX_STACKSIZE: c_int = 1048576;
198pub const PTHREAD_DEFAULT_STACKSIZE: c_int = 16384;
199pub const PTHREAD_DEFAULT_PRIORITY: c_int = 1;
200pub const PTHREAD_SPINLOCK_UNLOCKED: c_int = 0;
201pub const PTHREAD_SPINLOCK_LOCKED: c_int = 1;
202
203// Additional time constants
204pub const TIME_CONV_SCLK_FREQ: c_int = 19200000;
205pub const CLOCK_MONOTONIC_RAW: clockid_t = 4;
206pub const CLOCK_REALTIME_COARSE: clockid_t = 5;
207pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
208pub const CLOCK_BOOTTIME: clockid_t = 7;
209
210// Stdio constants
211pub const L_tmpnam: c_uint = 260;
212pub const TMP_MAX: c_uint = 25;
213pub const FOPEN_MAX: c_uint = 20;
214
215// Error constants
216pub const EOK: c_int = 0;
217
218// Semaphore constants
219pub const SEM_FAILED: *mut sem_t = ptr::null_mut();
220
221// fd_set constants from mqueue.h
222pub const FD_SETSIZE: c_uint = 256;
223pub const NFDBITS: c_uint = 32;
224
225// Page size constants (hexagon-specific)
226pub const PAGESIZE: size_t = 4096;
227pub const PAGE_SIZE: size_t = 4096;
228
229// Directory entry types (hexagon-specific)
230pub const DT_UNKNOWN: c_uchar = 0;
231pub const DT_FIFO: c_uchar = 1;
232pub const DT_CHR: c_uchar = 2;
233pub const DT_DIR: c_uchar = 4;
234pub const DT_BLK: c_uchar = 6;
235pub const DT_REG: c_uchar = 8;
236pub const DT_LNK: c_uchar = 10;
237pub const DT_SOCK: c_uchar = 12;
238
239// Directory functions (dirent.h)
240extern "C" {
241 pub fn opendir(name: *const c_char) -> *mut DIR;
242 pub fn readdir(dirp: *mut DIR) -> *mut dirent;
243 pub fn closedir(dirp: *mut DIR) -> c_int;
244 pub fn mkdir(path: *const c_char, mode: mode_t) -> c_int;
245}
246
247// Additional time functions
248extern "C" {
249 pub fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int;
250}
251
252// POSIX semaphore functions
253extern "C" {
254 pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
255 pub fn sem_close(sem: *mut sem_t) -> c_int;
256 pub fn sem_unlink(name: *const c_char) -> c_int;
257}
258
259// Additional stdlib functions
260extern "C" {
261 pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
262}
263
264// String functions (string.h)
265extern "C" {
266 pub fn strlen(s: *const c_char) -> size_t;
267 pub fn strcpy(dest: *mut c_char, src: *const c_char) -> *mut c_char;
268 pub fn strncpy(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
269 pub fn strcat(dest: *mut c_char, src: *const c_char) -> *mut c_char;
270 pub fn strncat(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
271 pub fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int;
272 pub fn strncmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int;
273 pub fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int;
274 pub fn strxfrm(dest: *mut c_char, src: *const c_char, n: size_t) -> size_t;
275 pub fn strchr(s: *const c_char, c: c_int) -> *mut c_char;
276 pub fn strrchr(s: *const c_char, c: c_int) -> *mut c_char;
277 pub fn strspn(s: *const c_char, accept: *const c_char) -> size_t;
278 pub fn strcspn(s: *const c_char, reject: *const c_char) -> size_t;
279 pub fn strpbrk(s: *const c_char, accept: *const c_char) -> *mut c_char;
280 pub fn strstr(haystack: *const c_char, needle: *const c_char) -> *mut c_char;
281 pub fn strtok(s: *mut c_char, delim: *const c_char) -> *mut c_char;
282 pub fn strerror(errnum: c_int) -> *mut c_char;
283 pub fn memchr(s: *const c_void, c: c_int, n: size_t) -> *mut c_void;
284 pub fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t) -> c_int;
285 pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
286 pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
287 pub fn memset(s: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
288}
289
290// Character classification functions (ctype.h)
291extern "C" {
292 pub fn isalnum(c: c_int) -> c_int;
293 pub fn isalpha(c: c_int) -> c_int;
294 pub fn iscntrl(c: c_int) -> c_int;
295 pub fn isdigit(c: c_int) -> c_int;
296 pub fn isgraph(c: c_int) -> c_int;
297 pub fn islower(c: c_int) -> c_int;
298 pub fn isprint(c: c_int) -> c_int;
299 pub fn ispunct(c: c_int) -> c_int;
300 pub fn isspace(c: c_int) -> c_int;
301 pub fn isupper(c: c_int) -> c_int;
302 pub fn isxdigit(c: c_int) -> c_int;
303 pub fn tolower(c: c_int) -> c_int;
304 pub fn toupper(c: c_int) -> c_int;
305}
306
307pub(crate) mod dlfcn;
308pub(crate) mod errno;
309pub(crate) mod fcntl;
310pub(crate) mod limits;
311pub(crate) mod mqueue;
312pub(crate) mod pthread;
313pub(crate) mod semaphore;
314pub(crate) mod signal;
315pub(crate) mod stdio;
316pub(crate) mod stdlib;
317pub(crate) mod sys;
318pub(crate) mod time;
319pub(crate) mod unistd;
320
321// Re-export public items from submodules
322pub use dlfcn::*;
323pub use errno::*;
324pub use fcntl::*;
325pub use limits::*;
326pub use mqueue::*;
327pub use pthread::*;
328pub use semaphore::*;
329pub use signal::*;
330pub use stdio::*;
331pub use stdlib::*;
332pub use sys::mman::*;
333pub use sys::sched::*;
334pub use sys::stat::*;
335pub use sys::types::*;
336pub use time::*;
337pub use unistd::*;