Debian Codegraph @

debian/missing-sources/libc/src/qurt/mod.rs

raw
1 //! Interface to QuRT (Qualcomm Real-Time OS) C library
2
3 use crate::prelude::*;
4
5 // Forward declarations for opaque types
6 #[derive(Debug)]
7 pub enum DIR {}
8 impl Copy for DIR {}
9 impl Clone for DIR {
10 fn clone(&self) -> DIR {
11 *self
12 }
13 }
14
15 // Network types
16 pub type socklen_t = c_uint;
17 pub type in_addr_t = u32;
18
19 // Error type
20 pub type errno_t = c_int;
21
22 // Resource limit type
23 pub type rlim_t = c_ulong;
24
25 // Terminal types
26 pub type speed_t = c_uint;
27 pub type tcflag_t = c_uint;
28
29 // File descriptor set type for select()
30 pub type fd_set = c_ulong;
31
32 // POSIX semaphore types
33 pub type sem_t = c_uint;
34
35 // Message queue types
36 pub type mqd_t = c_int;
37
38 // Additional file system types
39 pub type nfds_t = c_ulong;
40
41 // Architecture-specific modules
42 cfg_if! {
43 if #[cfg(target_arch = "hexagon")] {
44 mod hexagon;
45 pub use self::hexagon::*;
46 } else {
47 // Add other architectures as needed
48 }
49 }
50
51 // Structures based on QuRT headers
52 s! {
53 pub struct sigval {
54 pub sival_int: c_int,
55 pub sival_ptr: *mut c_void,
56 }
57
58 pub struct sigevent {
59 pub sigev_notify: c_int,
60 pub sigev_signo: c_int,
61 pub sigev_value: sigval,
62 pub sigev_notify_function: Option<extern "C" fn(sigval)>,
63 pub sigev_notify_attributes: *mut pthread_attr_t,
64 }
65
66 pub struct siginfo_t {
67 pub si_signo: c_int,
68 pub si_code: c_int,
69 pub si_value: sigval,
70 }
71
72 pub struct sigaction {
73 pub sa_handler: Option<extern "C" fn(c_int)>,
74 pub sa_mask: sigset_t,
75 pub sa_flags: c_int,
76 pub sa_sigaction: Option<extern "C" fn(c_int, *mut siginfo_t, *mut c_void)>,
77 }
78
79 pub struct termios {
80 pub c_iflag: tcflag_t,
81 pub c_oflag: tcflag_t,
82 pub c_cflag: tcflag_t,
83 pub c_lflag: tcflag_t,
84 pub c_cc: [c_uchar; 32],
85 pub c_ispeed: speed_t,
86 pub c_ospeed: speed_t,
87 }
88
89 pub struct dirent {
90 pub d_ino: ino_t,
91 pub d_type: c_uchar,
92 pub d_name: [c_char; 256],
93 }
94
95 pub struct tm {
96 pub tm_sec: c_int,
97 pub tm_min: c_int,
98 pub tm_hour: c_int,
99 pub tm_mday: c_int,
100 pub tm_mon: c_int,
101 pub tm_year: c_int,
102 pub tm_wday: c_int,
103 pub tm_yday: c_int,
104 pub tm_isdst: c_int,
105 }
106
107 pub struct sched_param {
108 pub sched_priority: c_int,
109 }
110
111 pub struct iovec {
112 pub iov_base: *mut c_void,
113 pub iov_len: size_t,
114 }
115
116 pub struct rlimit {
117 pub rlim_cur: rlim_t,
118 pub rlim_max: rlim_t,
119 }
120
121 pub struct rusage {
122 pub ru_utime: timeval,
123 pub ru_stime: timeval,
124 pub ru_maxrss: c_long,
125 pub ru_ixrss: c_long,
126 pub ru_idrss: c_long,
127 pub ru_isrss: c_long,
128 pub ru_minflt: c_long,
129 pub ru_majflt: c_long,
130 pub ru_nswap: c_long,
131 pub ru_inblock: c_long,
132 pub ru_oublock: c_long,
133 pub ru_msgsnd: c_long,
134 pub ru_msgrcv: c_long,
135 pub ru_nsignals: c_long,
136 pub ru_nvcsw: c_long,
137 pub ru_nivcsw: c_long,
138 }
139
140 pub struct flock {
141 pub l_type: c_short,
142 pub l_whence: c_short,
143 pub l_start: off_t,
144 pub l_len: off_t,
145 pub l_pid: pid_t,
146 }
147 }
148
149 // Memory mapping constants (from sys/mman.h)
150 pub const PROT_NONE: c_int = 0x00;
151 pub const PROT_READ: c_int = 0x01;
152 pub const PROT_WRITE: c_int = 0x02;
153 pub const PROT_EXEC: c_int = 0x04;
154
155 pub const MAP_SHARED: c_int = 0x0001;
156 pub const MAP_PRIVATE: c_int = 0x0002;
157 pub const MAP_FIXED: c_int = 0x0010;
158 pub const MAP_ANON: c_int = 0x1000;
159 pub const MAP_ANONYMOUS: c_int = MAP_ANON;
160 pub const MAP_FILE: c_int = 0x0000;
161 pub const MAP_RENAME: c_int = 0x0020;
162 pub const MAP_NORESERVE: c_int = 0x0040;
163 pub const MAP_INHERIT: c_int = 0x0080;
164 pub const MAP_HASSEMAPHORE: c_int = 0x0200;
165 pub const MAP_TRYFIXED: c_int = 0x0400;
166 pub const MAP_WIRED: c_int = 0x0800;
167
168 pub const MAP_FAILED: *mut c_void = !0 as *mut c_void;
169
170 pub const MS_ASYNC: c_int = 0x01;
171 pub const MS_INVALIDATE: c_int = 0x02;
172 pub const MS_SYNC: c_int = 0x04;
173
174 pub const MCL_CURRENT: c_int = 0x01;
175 pub const MCL_FUTURE: c_int = 0x02;
176
177 // Dynamic linking constants (from dlfcn.h)
178 pub const RTLD_LAZY: c_int = 1;
179 pub const RTLD_NOW: c_int = 2;
180 pub const RTLD_GLOBAL: c_int = 0x100;
181 pub const RTLD_LOCAL: c_int = 0x200;
182
183 // Semaphore constants
184 pub const SEM_FAILED: *mut sem_t = 0 as *mut sem_t;
185
186 // Additional constants
187 pub const PTHREAD_NAME_LEN: c_int = 16;
188 pub const PTHREAD_MAX_THREADS: c_uint = 512;
189 pub const PTHREAD_MIN_STACKSIZE: c_int = 512;
190 pub const PTHREAD_MAX_STACKSIZE: c_int = 1048576;
191 pub const PTHREAD_DEFAULT_STACKSIZE: c_int = 16384;
192 pub const PTHREAD_DEFAULT_PRIORITY: c_int = 1;
193 pub const PTHREAD_SPINLOCK_UNLOCKED: c_int = 0;
194 pub const PTHREAD_SPINLOCK_LOCKED: c_int = 1;
195 pub const TIME_CONV_SCLK_FREQ: c_int = 19200000;
196 pub const CLOCK_MONOTONIC_RAW: clockid_t = 4;
197 pub const CLOCK_REALTIME_COARSE: clockid_t = 5;
198 pub const CLOCK_MONOTONIC_COARSE: clockid_t = 6;
199 pub const CLOCK_BOOTTIME: clockid_t = 7;
200 pub const L_tmpnam: c_uint = 260;
201 pub const TMP_MAX: c_uint = 25;
202 pub const FOPEN_MAX: c_uint = 20;
203 pub const AT_FDCWD: c_int = -100;
204 pub const AT_EACCESS: c_int = 0x200;
205 pub const AT_SYMLINK_NOFOLLOW: c_int = 0x100;
206 pub const AT_SYMLINK_FOLLOW: c_int = 0x400;
207 pub const AT_REMOVEDIR: c_int = 0x200;
208 pub const EOK: c_int = 0;
209 pub const POSIX_MSG: c_int = 7;
210 pub const POSIX_NOTIF: c_int = 8;
211 pub const SIGRTMIN: c_int = 10;
212 pub const SIGRTMAX: c_int = 32;
213 pub const SIGEV_NONE: c_int = 0;
214 pub const SIGEV_SIGNAL: c_int = 1;
215 pub const SIGEV_THREAD: c_int = 2;
216 pub const SA_SIGINFO: c_int = 1;
217
218 // Function declarations for QuRT POSIX API
219 extern "C" {
220 // Signal functions
221 pub fn sigwait(set: *const sigset_t, sig: *mut c_int) -> c_int;
222 pub fn _sigaction(sig: c_int, act: *const sigaction, oact: *mut sigaction) -> c_int;
223 pub fn sigtimedwait(
224 set: *const sigset_t,
225 info: *mut siginfo_t,
226 timeout: *const timespec,
227 ) -> c_int;
228
229 // Additional pthread functions
230 pub fn pthread_attr_getstack(
231 attr: *const pthread_attr_t,
232 stackaddr: *mut *mut c_void,
233 stacksize: *mut size_t,
234 ) -> c_int;
235 pub fn pthread_attr_setstack(
236 attr: *mut pthread_attr_t,
237 stackaddr: *mut c_void,
238 stacksize: size_t,
239 ) -> c_int;
240 pub fn pthread_mutexattr_gettype(attr: *const pthread_mutexattr_t, type_: *mut c_int) -> c_int;
241 pub fn pthread_mutexattr_settype(attr: *mut pthread_mutexattr_t, type_: c_int) -> c_int;
242
243 // Additional time functions
244 pub fn clock_getcpuclockid(pid: pid_t, clock_id: *mut clockid_t) -> c_int;
245
246 // POSIX semaphore functions
247 pub fn sem_open(name: *const c_char, oflag: c_int, ...) -> *mut sem_t;
248 pub fn sem_close(sem: *mut sem_t) -> c_int;
249 pub fn sem_unlink(name: *const c_char) -> c_int;
250
251 // Additional stdlib functions
252 pub fn aligned_alloc(alignment: size_t, size: size_t) -> *mut c_void;
253
254 // String functions
255 pub fn strlen(s: *const c_char) -> size_t;
256 pub fn strcpy(dest: *mut c_char, src: *const c_char) -> *mut c_char;
257 pub fn strncpy(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
258 pub fn strcat(dest: *mut c_char, src: *const c_char) -> *mut c_char;
259 pub fn strncat(dest: *mut c_char, src: *const c_char, n: size_t) -> *mut c_char;
260 pub fn strcmp(s1: *const c_char, s2: *const c_char) -> c_int;
261 pub fn strncmp(s1: *const c_char, s2: *const c_char, n: size_t) -> c_int;
262 pub fn strcoll(s1: *const c_char, s2: *const c_char) -> c_int;
263 pub fn strxfrm(dest: *mut c_char, src: *const c_char, n: size_t) -> size_t;
264 pub fn strchr(s: *const c_char, c: c_int) -> *mut c_char;
265 pub fn strrchr(s: *const c_char, c: c_int) -> *mut c_char;
266 pub fn strspn(s: *const c_char, accept: *const c_char) -> size_t;
267 pub fn strcspn(s: *const c_char, reject: *const c_char) -> size_t;
268 pub fn strpbrk(s: *const c_char, accept: *const c_char) -> *mut c_char;
269 pub fn strstr(haystack: *const c_char, needle: *const c_char) -> *mut c_char;
270 pub fn strtok(s: *mut c_char, delim: *const c_char) -> *mut c_char;
271 pub fn strerror(errnum: c_int) -> *mut c_char;
272 pub fn memchr(s: *const c_void, c: c_int, n: size_t) -> *mut c_void;
273 pub fn memcmp(s1: *const c_void, s2: *const c_void, n: size_t) -> c_int;
274 pub fn memcpy(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
275 pub fn memmove(dest: *mut c_void, src: *const c_void, n: size_t) -> *mut c_void;
276 pub fn memset(s: *mut c_void, c: c_int, n: size_t) -> *mut c_void;
277
278 // Additional unistd functions
279 pub fn fork() -> pid_t;
280 pub fn execve(
281 filename: *const c_char,
282 argv: *const *const c_char,
283 envp: *const *const c_char,
284 ) -> c_int;
285
286 // Directory functions
287 pub fn opendir(name: *const c_char) -> *mut DIR;
288 pub fn closedir(dirp: *mut DIR) -> c_int;
289 pub fn readdir(dirp: *mut DIR) -> *mut dirent;
290 pub fn rewinddir(dirp: *mut DIR);
291 pub fn telldir(dirp: *mut DIR) -> c_long;
292 pub fn seekdir(dirp: *mut DIR, loc: c_long);
293
294 // Memory mapping functions
295 pub fn mmap(
296 addr: *mut c_void,
297 len: size_t,
298 prot: c_int,
299 flags: c_int,
300 fd: c_int,
301 offset: off_t,
302 ) -> *mut c_void;
303 pub fn munmap(addr: *mut c_void, len: size_t) -> c_int;
304 pub fn mprotect(addr: *mut c_void, len: size_t, prot: c_int) -> c_int;
305 pub fn mlock(addr: *const c_void, len: size_t) -> c_int;
306 pub fn munlock(addr: *const c_void, len: size_t) -> c_int;
307 pub fn mlockall(flags: c_int) -> c_int;
308 pub fn munlockall() -> c_int;
309 pub fn msync(addr: *mut c_void, len: size_t, flags: c_int) -> c_int;
310
311 // Dynamic linking functions
312 pub fn dlopen(filename: *const c_char, flag: c_int) -> *mut c_void;
313 pub fn dlclose(handle: *mut c_void) -> c_int;
314 pub fn dlsym(handle: *mut c_void, symbol: *const c_char) -> *mut c_void;
315 pub fn dlerror() -> *mut c_char;
316
317 // Character classification functions
318 pub fn isalnum(c: c_int) -> c_int;
319 pub fn isalpha(c: c_int) -> c_int;
320 pub fn iscntrl(c: c_int) -> c_int;
321 pub fn isdigit(c: c_int) -> c_int;
322 pub fn isgraph(c: c_int) -> c_int;
323 pub fn islower(c: c_int) -> c_int;
324 pub fn isprint(c: c_int) -> c_int;
325 pub fn ispunct(c: c_int) -> c_int;
326 pub fn isspace(c: c_int) -> c_int;
327 pub fn isupper(c: c_int) -> c_int;
328 pub fn isxdigit(c: c_int) -> c_int;
329 pub fn tolower(c: c_int) -> c_int;
330 pub fn toupper(c: c_int) -> c_int;
331 }
332
333 // Re-export common prelude items
334 pub use crate::*;