| 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 |
|
| 7 |
use crate::prelude::*; |
| 8 |
|
| 9 |
// Basic C types for QuRT |
| 10 |
pub type intptr_t = isize; |
| 11 |
pub type uintptr_t = usize; |
| 12 |
pub type ptrdiff_t = isize; |
| 13 |
pub type size_t = uintptr_t; |
| 14 |
pub type ssize_t = c_int; |
| 15 |
|
| 16 |
// Process and system types |
| 17 |
pub type pid_t = c_int; |
| 18 |
pub type uid_t = c_uint; |
| 19 |
pub type gid_t = c_uint; |
| 20 |
|
| 21 |
// Time types |
| 22 |
pub type time_t = c_long; |
| 23 |
pub type suseconds_t = c_long; |
| 24 |
pub type useconds_t = c_ulong; |
| 25 |
pub type clockid_t = c_int; |
| 26 |
pub type timer_t = *mut c_void; |
| 27 |
|
| 28 |
// File system types |
| 29 |
pub type dev_t = c_ulonglong; |
| 30 |
pub type ino_t = c_ulonglong; |
| 31 |
pub type mode_t = c_uint; |
| 32 |
pub type nlink_t = c_uint; |
| 33 |
pub type off_t = c_long; |
| 34 |
pub type blkcnt_t = c_long; |
| 35 |
pub type blksize_t = c_long; |
| 36 |
|
| 37 |
// Thread types based on QuRT pthread implementation |
| 38 |
pub type pthread_t = c_uint; |
| 39 |
pub type pthread_key_t = c_int; |
| 40 |
pub type pthread_once_t = c_int; |
| 41 |
pub type pthread_mutex_t = c_uint; |
| 42 |
// QuRT pthread_mutexattr_t is a struct with 4 ints (is_initialized, type, pshared, protocol) |
| 43 |
pub type pthread_mutexattr_t = [c_uint; 4]; |
| 44 |
pub type pthread_cond_t = c_uint; |
| 45 |
// QuRT pthread_condattr_t is a struct with 3 ints (is_initialized, pshared, clock_id) |
| 46 |
pub type pthread_condattr_t = [c_uint; 3]; |
| 47 |
// pthread_attr_t is defined as a struct in the s! block below |
| 48 |
pub type pthread_rwlock_t = *mut c_void; |
| 49 |
pub type pthread_rwlockattr_t = *mut c_void; |
| 50 |
pub type pthread_spinlock_t = c_uint; |
| 51 |
pub type pthread_barrier_t = c_uint; |
| 52 |
// QuRT pthread_barrierattr_t is a struct with 2 ints (is_initialized, pshared) |
| 53 |
pub type pthread_barrierattr_t = [c_uint; 2]; |
| 54 |
|
| 55 |
// Network types |
| 56 |
pub type socklen_t = c_uint; |
| 57 |
pub type sa_family_t = c_ushort; |
| 58 |
pub type in_addr_t = c_uint; |
| 59 |
pub 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 |
| 65 |
extern_ty! { |
| 66 |
pub type FILE; |
| 67 |
} |
| 68 |
pub type fpos_t = c_long; |
| 69 |
pub 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 |
| 74 |
pub type mqd_t = c_int; |
| 75 |
|
| 76 |
// Additional file system types |
| 77 |
pub type nfds_t = c_ulong; |
| 78 |
|
| 79 |
// Signal types |
| 80 |
pub type sigset_t = c_ulong; |
| 81 |
|
| 82 |
// Variadic argument list type |
| 83 |
pub type va_list = *mut c_char; |
| 84 |
|
| 85 |
// Wide character type (hexagon uses signed wchar_t) |
| 86 |
pub type wchar_t = i32; |
| 87 |
|
| 88 |
// Error type (compatible with std expectations) |
| 89 |
pub type errno_t = c_int; |
| 90 |
|
| 91 |
// Division result types and structures |
| 92 |
s! { |
| 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 |
| 194 |
pub const PTHREAD_NAME_LEN: c_int = 16; |
| 195 |
pub const PTHREAD_MAX_THREADS: c_uint = 512; |
| 196 |
pub const PTHREAD_MIN_STACKSIZE: c_int = 512; |
| 197 |
pub const PTHREAD_MAX_STACKSIZE: c_int = 1048576; |
| 198 |
pub const PTHREAD_DEFAULT_STACKSIZE: c_int = 16384; |
| 199 |
pub const PTHREAD_DEFAULT_PRIORITY: c_int = 1; |
| 200 |
pub const PTHREAD_SPINLOCK_UNLOCKED: c_int = 0; |
| 201 |
pub const PTHREAD_SPINLOCK_LOCKED: c_int = 1; |
| 202 |
|
| 203 |
// Additional time constants |
| 204 |
pub const TIME_CONV_SCLK_FREQ: c_int = 19200000; |
| 205 |
pub const CLOCK_MONOTONIC_RAW: clockid_t = 4; |
| 206 |
pub const CLOCK_REALTIME_COARSE: clockid_t = 5; |
| 207 |
pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6; |
| 208 |
pub const CLOCK_BOOTTIME: clockid_t = 7; |
| 209 |
|
| 210 |
// Stdio constants |
| 211 |
pub const L_tmpnam: c_uint = 260; |
| 212 |
pub const TMP_MAX: c_uint = 25; |
| 213 |
pub const FOPEN_MAX: c_uint = 20; |
| 214 |
|
| 215 |
// Error constants |
| 216 |
pub const EOK: c_int = 0; |
| 217 |
|
| 218 |
// Semaphore constants |
| 219 |
pub const SEM_FAILED: *mut sem_t = ptr::null_mut(); |
| 220 |
|
| 221 |
// fd_set constants from mqueue.h |
| 222 |
pub const FD_SETSIZE: c_uint = 256; |
| 223 |
pub const NFDBITS: c_uint = 32; |
| 224 |
|
| 225 |
// Page size constants (hexagon-specific) |
| 226 |
pub const PAGESIZE: size_t = 4096; |
| 227 |
pub const PAGE_SIZE: size_t = 4096; |
| 228 |
|
| 229 |
// Directory entry types (hexagon-specific) |
| 230 |
pub const DT_UNKNOWN: c_uchar = 0; |
| 231 |
pub const DT_FIFO: c_uchar = 1; |
| 232 |
pub const DT_CHR: c_uchar = 2; |
| 233 |
pub const DT_DIR: c_uchar = 4; |
| 234 |
pub const DT_BLK: c_uchar = 6; |
| 235 |
pub const DT_REG: c_uchar = 8; |
| 236 |
pub const DT_LNK: c_uchar = 10; |
| 237 |
pub const DT_SOCK: c_uchar = 12; |
| 238 |
|
| 239 |
// Directory functions (dirent.h) |
| 240 |
extern "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 |
| 248 |
extern "C" { |
| 249 |
pub fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int; |
| 250 |
} |
| 251 |
|
| 252 |
// POSIX semaphore functions |
| 253 |
extern "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 |
| 260 |
extern "C" { |
| 261 |
pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void; |
| 262 |
} |
| 263 |
|
| 264 |
// String functions (string.h) |
| 265 |
extern "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) |
| 291 |
extern "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 |
|
| 307 |
pub(crate) mod dlfcn; |
| 308 |
pub(crate) mod errno; |
| 309 |
pub(crate) mod fcntl; |
| 310 |
pub(crate) mod limits; |
| 311 |
pub(crate) mod mqueue; |
| 312 |
pub(crate) mod pthread; |
| 313 |
pub(crate) mod semaphore; |
| 314 |
pub(crate) mod signal; |
| 315 |
pub(crate) mod stdio; |
| 316 |
pub(crate) mod stdlib; |
| 317 |
pub(crate) mod sys; |
| 318 |
pub(crate) mod time; |
| 319 |
pub(crate) mod unistd; |
| 320 |
|
| 321 |
// Re-export public items from submodules |
| 322 |
pub use dlfcn::*; |
| 323 |
pub use errno::*; |
| 324 |
pub use fcntl::*; |
| 325 |
pub use limits::*; |
| 326 |
pub use mqueue::*; |
| 327 |
pub use pthread::*; |
| 328 |
pub use semaphore::*; |
| 329 |
pub use signal::*; |
| 330 |
pub use stdio::*; |
| 331 |
pub use stdlib::*; |
| 332 |
pub use sys::mman::*; |
| 333 |
pub use sys::sched::*; |
| 334 |
pub use sys::stat::*; |
| 335 |
pub use sys::types::*; |
| 336 |
pub use time::*; |
| 337 |
pub use unistd::*; |