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 / unix / linux_like / l4re / uclibc / mod.rs

562 lines · 16140 bytes Raw Blame History
1use crate::off64_t;
2use crate::prelude::*;
3
4pub type shmatt_t = c_ulong;
5pub type regoff_t = c_int;
6pub type rlim_t = c_ulong;
7pub type __rlimit_resource_t = c_int;
8pub type __priority_which_t = c_uint;
9
10pub type _pthread_descr = *mut c_void;
11pub type __pthread_cond_align_t = c_long;
12
13cfg_if! {
14 if #[cfg(doc)] {
15 // Used in `linux::arch` to define ioctl constants.
16 pub(crate) type Ioctl = c_ulong;
17 } else {
18 #[doc(hidden)]
19 pub type Ioctl = c_ulong;
20 }
21}
22
23s! {
24 pub struct cmsghdr {
25 pub cmsg_len: crate::size_t,
26 pub cmsg_level: c_int,
27 pub cmsg_type: c_int,
28 }
29
30 pub struct msghdr {
31 pub msg_name: *mut c_void,
32 pub msg_namelen: crate::socklen_t,
33 pub msg_iov: *mut crate::iovec,
34 #[cfg(target_pointer_width = "32")]
35 pub msg_iovlen: c_int,
36 #[cfg(target_pointer_width = "64")]
37 pub msg_iovlen: crate::size_t,
38 pub msg_control: *mut c_void,
39 #[cfg(target_pointer_width = "32")]
40 pub msg_controllen: crate::socklen_t,
41 #[cfg(target_pointer_width = "64")]
42 pub msg_controllen: crate::size_t,
43 pub msg_flags: c_int,
44 }
45
46 pub struct statfs {
47 pub f_type: fsword_t,
48 pub f_bsize: fsword_t,
49 pub f_blocks: crate::fsblkcnt_t,
50 pub f_bfree: crate::fsblkcnt_t,
51 pub f_bavail: crate::fsblkcnt_t,
52 pub f_files: crate::fsfilcnt_t,
53 pub f_ffree: crate::fsfilcnt_t,
54 pub f_fsid: crate::fsid_t,
55 pub f_namelen: fsword_t,
56 pub f_frsize: fsword_t,
57 pub f_flags: fsword_t,
58 pub f_spare: [fsword_t; 4],
59 }
60
61 pub struct statfs64 {
62 pub f_type: fsword_t,
63 pub f_bsize: fsword_t,
64 pub f_blocks: crate::fsblkcnt64_t,
65 pub f_bfree: crate::fsblkcnt64_t,
66 pub f_bavail: crate::fsblkcnt64_t,
67 pub f_files: crate::fsfilcnt64_t,
68 pub f_ffree: crate::fsfilcnt64_t,
69 pub f_fsid: crate::fsid_t,
70 pub f_namelen: fsword_t,
71 pub f_frsize: fsword_t,
72 pub f_flags: fsword_t,
73 pub f_spare: [fsword_t; 4],
74 }
75
76 pub struct statvfs64 {
77 pub f_bsize: c_ulong,
78 pub f_frsize: c_ulong,
79 pub f_blocks: crate::fsfilcnt64_t,
80 pub f_bfree: crate::fsfilcnt64_t,
81 pub f_bavail: crate::fsfilcnt64_t,
82 pub f_files: crate::fsfilcnt64_t,
83 pub f_ffree: crate::fsfilcnt64_t,
84 pub f_favail: crate::fsfilcnt64_t,
85 pub f_fsid: c_ulong,
86 pub f_flag: c_ulong,
87 pub f_namemax: c_ulong,
88 pub __f_spare: [c_int; 6],
89 }
90
91 pub struct ipc_perm {
92 pub __key: crate::key_t,
93 pub uid: crate::uid_t,
94 pub gid: crate::gid_t,
95 pub cuid: crate::uid_t,
96 pub cgid: crate::gid_t,
97 #[cfg(target_pointer_width = "32")]
98 pub mode: c_ushort,
99 #[cfg(target_pointer_width = "64")]
100 pub mode: c_uint,
101 #[cfg(target_pointer_width = "32")]
102 __pad1: c_ushort,
103 pub __seq: c_ushort,
104 __pad2: c_ushort,
105 __unused1: c_ulong,
106 __unused2: c_ulong,
107 }
108
109 pub struct statvfs {
110 // Different than GNU!
111 pub f_bsize: c_ulong,
112 pub f_frsize: c_ulong,
113 pub f_blocks: crate::fsblkcnt_t,
114 pub f_bfree: crate::fsblkcnt_t,
115 pub f_bavail: crate::fsblkcnt_t,
116 pub f_files: crate::fsfilcnt_t,
117 pub f_ffree: crate::fsfilcnt_t,
118 pub f_favail: crate::fsfilcnt_t,
119 #[cfg(target_endian = "little")]
120 pub f_fsid: c_ulong,
121 #[cfg(target_pointer_width = "32")]
122 __f_unused: c_int,
123 #[cfg(target_endian = "big")]
124 pub f_fsid: c_ulong,
125 pub f_flag: c_ulong,
126 pub f_namemax: c_ulong,
127 __f_spare: [c_int; 6],
128 }
129
130 pub struct sysinfo {
131 pub uptime: c_long,
132 pub loads: [c_ulong; 3],
133 pub totalram: c_ulong,
134 pub freeram: c_ulong,
135 pub sharedram: c_ulong,
136 pub bufferram: c_ulong,
137 pub totalswap: c_ulong,
138 pub freeswap: c_ulong,
139 pub procs: c_ushort,
140 pub pad: c_ushort,
141 pub totalhigh: c_ulong,
142 pub freehigh: c_ulong,
143 pub mem_unit: c_uint,
144 #[cfg(target_pointer_width = "32")]
145 pub _f: [c_char; 8],
146 #[cfg(target_pointer_width = "64")]
147 pub _f: [c_char; 0],
148 }
149
150 pub struct regex_t {
151 __buffer: *mut c_void,
152 __allocated: size_t,
153 __used: size_t,
154 __syntax: c_ulong,
155 __fastmap: *mut c_char,
156 __translate: *mut c_char,
157 __re_nsub: size_t,
158 __bitfield: u8,
159 }
160
161 pub struct rtentry {
162 pub rt_pad1: c_ulong,
163 pub rt_dst: crate::sockaddr,
164 pub rt_gateway: crate::sockaddr,
165 pub rt_genmask: crate::sockaddr,
166 pub rt_flags: c_ushort,
167 pub rt_pad2: c_short,
168 pub rt_pad3: c_ulong,
169 pub rt_tos: c_uchar,
170 pub rt_class: c_uchar,
171 #[cfg(target_pointer_width = "64")]
172 pub rt_pad4: [c_short; 3usize],
173 #[cfg(not(target_pointer_width = "64"))]
174 pub rt_pad4: c_short,
175 pub rt_metric: c_short,
176 pub rt_dev: *mut c_char,
177 pub rt_mtu: c_ulong,
178 pub rt_window: c_ulong,
179 pub rt_irtt: c_ushort,
180 }
181
182 pub struct __exit_status {
183 pub e_termination: c_short,
184 pub e_exit: c_short,
185 }
186
187 pub struct tcp_info {
188 pub tcpi_state: u8,
189 pub tcpi_ca_state: u8,
190 pub tcpi_retransmits: u8,
191 pub tcpi_probes: u8,
192 pub tcpi_backoff: u8,
193 pub tcpi_options: u8,
194 /// This contains the bitfields `tcpi_snd_wscale` and `tcpi_rcv_wscale`.
195 /// Each is 4 bits.
196 pub tcpi_snd_rcv_wscale: u8,
197 pub tcpi_rto: u32,
198 pub tcpi_ato: u32,
199 pub tcpi_snd_mss: u32,
200 pub tcpi_rcv_mss: u32,
201 pub tcpi_unacked: u32,
202 pub tcpi_sacked: u32,
203 pub tcpi_lost: u32,
204 pub tcpi_retrans: u32,
205 pub tcpi_fackets: u32,
206 pub tcpi_last_data_sent: u32,
207 pub tcpi_last_ack_sent: u32,
208 pub tcpi_last_data_recv: u32,
209 pub tcpi_last_ack_recv: u32,
210 pub tcpi_pmtu: u32,
211 pub tcpi_rcv_ssthresh: u32,
212 pub tcpi_rtt: u32,
213 pub tcpi_rttvar: u32,
214 pub tcpi_snd_ssthresh: u32,
215 pub tcpi_snd_cwnd: u32,
216 pub tcpi_advmss: u32,
217 pub tcpi_reordering: u32,
218 pub tcpi_rcv_rtt: u32,
219 pub tcpi_rcv_space: u32,
220 pub tcpi_total_retrans: u32,
221 }
222
223 pub struct __sched_param {
224 __sched_priority: c_int,
225 }
226
227 pub struct _pthread_fastlock {
228 __status: c_long,
229 __spinlock: c_int,
230 }
231
232 pub struct pthread_cond_t {
233 __c_lock: _pthread_fastlock,
234 __c_waiting: _pthread_descr,
235 __padding: [u8; PTHREAD_COND_PADDING_SIZE],
236 __align: __pthread_cond_align_t,
237 }
238
239 pub struct pthread_condattr_t {
240 __dummy: c_int,
241 }
242
243 pub struct pthread_mutex_t {
244 __m_reserved: c_int,
245 __m_count: c_int,
246 __m_owner: _pthread_descr,
247 __m_kind: c_int,
248 __m_lock: _pthread_fastlock,
249 }
250
251 pub struct pthread_mutexattr_t {
252 __mutexkind: c_int,
253 __mutexprotocol: c_int,
254 }
255
256 pub struct pthread_rwlock_t {
257 __rw_lock: _pthread_fastlock,
258 __rw_readers: c_int,
259 __rw_writer: _pthread_descr,
260 __rw_read_waiting: _pthread_descr,
261 __rw_write_waiting: _pthread_descr,
262 __rw_kind: c_int,
263 __rw_pshared: c_int,
264 }
265
266 pub struct pthread_rwlockattr_t {
267 __lockkind: c_int,
268 __pshared: c_int,
269 }
270
271 pub struct pthread_barrier_t {
272 __ba_lock: _pthread_fastlock,
273 __ba_required: c_int,
274 __ba_present: c_int,
275 __ba_waiting: _pthread_descr,
276 }
277
278 pub struct pthread_barrierattr_t {
279 __pshared: c_int,
280 }
281
282 pub struct __mbstate_t {
283 pub __mask: crate::wchar_t,
284 pub __wc: crate::wchar_t,
285 }
286
287 pub struct fpos64_t {
288 pub __pos: crate::off64_t,
289 pub __mbstate: __mbstate_t,
290 pub __mblen_pending: c_int,
291 }
292
293 pub struct shmid_ds {
294 pub shm_perm: crate::ipc_perm,
295 pub shm_segsz: crate::size_t,
296 pub shm_atime: crate::time_t,
297 pub shm_dtime: crate::time_t,
298 pub shm_ctime: crate::time_t,
299 pub shm_cpid: crate::pid_t,
300 pub shm_lpid: crate::pid_t,
301 pub shm_nattch: crate::shmatt_t,
302 __unused4: c_ulong,
303 __unused5: c_ulong,
304 }
305}
306
307impl siginfo_t {
308 pub unsafe fn si_addr(&self) -> *mut c_void {
309 #[repr(C)]
310 struct siginfo_sigfault {
311 _si_signo: c_int,
312 _si_errno: c_int,
313 _si_code: c_int,
314 si_addr: *mut c_void,
315 }
316 (*core::ptr::from_ref(self).cast::<siginfo_sigfault>()).si_addr
317 }
318
319 pub unsafe fn si_value(&self) -> crate::sigval {
320 #[repr(C)]
321 struct siginfo_si_value {
322 _si_signo: c_int,
323 _si_errno: c_int,
324 _si_code: c_int,
325 _si_timerid: c_int,
326 _si_overrun: c_int,
327 si_value: crate::sigval,
328 }
329 (*core::ptr::from_ref(self).cast::<siginfo_si_value>()).si_value
330 }
331}
332
333s_no_extra_traits! {
334 // Internal, for casts to access union fields
335 struct sifields_sigchld {
336 si_pid: crate::pid_t,
337 si_uid: crate::uid_t,
338 si_status: c_int,
339 si_utime: c_long,
340 si_stime: c_long,
341 }
342
343 // Internal, for casts to access union fields
344 union sifields {
345 _align_pointer: *mut c_void,
346 sigchld: sifields_sigchld,
347 }
348
349 // Internal, for casts to access union fields. Note that some variants
350 // of sifields start with a pointer, which makes the alignment of
351 // sifields vary on 32-bit and 64-bit architectures.
352 struct siginfo_f {
353 _siginfo_base: [c_int; 3],
354 sifields: sifields,
355 }
356}
357
358impl siginfo_t {
359 unsafe fn sifields(&self) -> &sifields {
360 &(*core::ptr::from_ref(self).cast::<siginfo_f>()).sifields
361 }
362
363 pub unsafe fn si_pid(&self) -> crate::pid_t {
364 self.sifields().sigchld.si_pid
365 }
366
367 pub unsafe fn si_uid(&self) -> crate::uid_t {
368 self.sifields().sigchld.si_uid
369 }
370
371 pub unsafe fn si_status(&self) -> c_int {
372 self.sifields().sigchld.si_status
373 }
374
375 pub unsafe fn si_utime(&self) -> c_long {
376 self.sifields().sigchld.si_utime
377 }
378
379 pub unsafe fn si_stime(&self) -> c_long {
380 self.sifields().sigchld.si_stime
381 }
382}
383
384pub const MCL_CURRENT: c_int = 0x0001;
385pub const MCL_FUTURE: c_int = 0x0002;
386pub const MCL_ONFAULT: c_int = 0x0004;
387
388pub const SIGEV_THREAD_ID: c_int = 4;
389
390pub const AF_VSOCK: c_int = 40;
391
392pub const POSIX_FADV_DONTNEED: c_int = 4;
393pub const POSIX_FADV_NOREUSE: c_int = 5;
394
395// These are different than GNU!
396pub const LC_CTYPE: c_int = 0;
397pub const LC_NUMERIC: c_int = 1;
398pub const LC_TIME: c_int = 3;
399pub const LC_COLLATE: c_int = 4;
400pub const LC_MONETARY: c_int = 2;
401pub const LC_MESSAGES: c_int = 5;
402pub const LC_ALL: c_int = 6;
403// end different section
404
405// MS_ flags for mount(2)
406pub const MS_RMT_MASK: c_ulong =
407 crate::MS_RDONLY | crate::MS_SYNCHRONOUS | crate::MS_MANDLOCK | crate::MS_I_VERSION;
408
409pub const ENOTSUP: c_int = EOPNOTSUPP;
410
411pub const IPV6_JOIN_GROUP: c_int = 20;
412pub const IPV6_LEAVE_GROUP: c_int = 21;
413
414// Different than Gnu.
415pub const FILENAME_MAX: c_uint = 4095;
416
417pub const PRIO_PROCESS: c_int = 0;
418pub const PRIO_PGRP: c_int = 1;
419pub const PRIO_USER: c_int = 2;
420
421pub const SOMAXCONN: c_int = 128;
422
423pub const ST_RELATIME: c_ulong = 4096;
424
425pub const SO_TIMESTAMP: c_int = 29;
426
427pub const RLIM_INFINITY: crate::rlim_t = !0;
428
429pub const AF_NFC: c_int = PF_NFC;
430pub const BUFSIZ: c_int = 256;
431pub const EDEADLK: c_int = 0x23;
432pub const EDEADLOCK: c_int = EDEADLK;
433pub const EXTA: c_uint = B19200;
434pub const EXTB: c_uint = B38400;
435pub const EXTPROC: crate::tcflag_t = 0o200000;
436pub const FOPEN_MAX: c_int = 16;
437pub const F_GETOWN: c_int = 9;
438pub const F_OFD_GETLK: c_int = 36;
439pub const F_OFD_SETLK: c_int = 37;
440pub const F_OFD_SETLKW: c_int = 38;
441pub const F_RDLCK: c_int = 0;
442pub const F_SETOWN: c_int = 8;
443pub const F_UNLCK: c_int = 2;
444pub const F_WRLCK: c_int = 1;
445pub const IPV6_MULTICAST_ALL: c_int = 29;
446pub const IPV6_ROUTER_ALERT_ISOLATE: c_int = 30;
447pub const MAP_HUGE_SHIFT: c_int = 26;
448pub const MAP_HUGE_MASK: c_int = 0x3f;
449pub const MSG_COPY: c_int = 0o40000;
450pub const NI_MAXHOST: crate::socklen_t = 1025;
451pub const O_TMPFILE: c_int = 0o20000000 | O_DIRECTORY;
452pub const PF_NFC: c_int = 39;
453pub const PF_VSOCK: c_int = 40;
454pub const RTLD_NOLOAD: c_int = 0x00004;
455pub const RUSAGE_THREAD: c_int = 1;
456pub const SHM_EXEC: c_int = 0o100000;
457pub const SOCK_DCCP: c_int = 6;
458pub const SOCK_PACKET: c_int = 10;
459pub const TCP_COOKIE_TRANSACTIONS: c_int = 15;
460pub const UDP_GRO: c_int = 104;
461pub const UDP_SEGMENT: c_int = 103;
462
463pub const PTHREAD_RWLOCK_PREFER_READER_NP: c_int = 0;
464pub const PTHREAD_RWLOCK_PREFER_WRITER_NP: c_int = 1;
465pub const PTHREAD_RWLOCK_PREFER_WRITER_NONRECURSIVE_NP: c_int = 2;
466pub const PTHREAD_RWLOCK_DEFAULT_NP: c_int = PTHREAD_RWLOCK_PREFER_WRITER_NP;
467
468pub const PTHREAD_MUTEX_TIMED_NP: c_int = 0;
469pub const PTHREAD_MUTEX_RECURSIVE_NP: c_int = 1;
470pub const PTHREAD_MUTEX_ERRORCHECK_NP: c_int = 2;
471pub const PTHREAD_MUTEX_ADAPTIVE_NP: c_int = 3;
472
473pub const __LT_SPINLOCK_INIT: c_int = 0;
474
475pub const __LOCK_INITIALIZER: _pthread_fastlock = _pthread_fastlock {
476 __status: 0,
477 __spinlock: __LT_SPINLOCK_INIT,
478};
479
480pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t {
481 __m_reserved: 0,
482 __m_count: 0,
483 __m_owner: ptr::null_mut(),
484 __m_kind: PTHREAD_MUTEX_TIMED_NP,
485 __m_lock: __LOCK_INITIALIZER,
486};
487
488const PTHREAD_COND_PADDING_SIZE: usize = 48
489 - size_of::<_pthread_fastlock>()
490 - size_of::<_pthread_descr>()
491 - size_of::<__pthread_cond_align_t>();
492
493pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t {
494 __c_lock: __LOCK_INITIALIZER,
495 __c_waiting: ptr::null_mut(),
496 __padding: [0; PTHREAD_COND_PADDING_SIZE],
497 __align: 0,
498};
499
500pub const PTHREAD_RWLOCK_INITIALIZER: pthread_rwlock_t = pthread_rwlock_t {
501 __rw_lock: __LOCK_INITIALIZER,
502 __rw_readers: 0,
503 __rw_writer: ptr::null_mut(),
504 __rw_read_waiting: ptr::null_mut(),
505 __rw_write_waiting: ptr::null_mut(),
506 __rw_kind: PTHREAD_RWLOCK_DEFAULT_NP,
507 __rw_pshared: crate::PTHREAD_PROCESS_PRIVATE,
508};
509
510extern "C" {
511 pub fn gettimeofday(tp: *mut crate::timeval, tz: *mut crate::timezone) -> c_int;
512
513 pub fn pthread_rwlockattr_getkind_np(
514 attr: *const crate::pthread_rwlockattr_t,
515 val: *mut c_int,
516 ) -> c_int;
517 pub fn pthread_rwlockattr_setkind_np(
518 attr: *mut crate::pthread_rwlockattr_t,
519 val: c_int,
520 ) -> c_int;
521
522 pub fn openpty(
523 amaster: *mut c_int,
524 aslave: *mut c_int,
525 name: *mut c_char,
526 termp: *mut termios,
527 winp: *mut crate::winsize,
528 ) -> c_int;
529
530 pub fn getnameinfo(
531 sa: *const crate::sockaddr,
532 salen: crate::socklen_t,
533 host: *mut c_char,
534 hostlen: crate::socklen_t,
535 serv: *mut c_char,
536 servlen: crate::socklen_t,
537 flags: c_int,
538 ) -> c_int;
539
540 pub fn pwritev(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t;
541 pub fn preadv(fd: c_int, iov: *const crate::iovec, iovcnt: c_int, offset: off64_t) -> ssize_t;
542
543 pub fn getrlimit64(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit64) -> c_int;
544 pub fn setrlimit64(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit64)
545 -> c_int;
546 pub fn getrlimit(resource: crate::__rlimit_resource_t, rlim: *mut crate::rlimit) -> c_int;
547 pub fn setrlimit(resource: crate::__rlimit_resource_t, rlim: *const crate::rlimit) -> c_int;
548 pub fn getauxval(type_: c_ulong) -> c_ulong;
549
550}
551
552cfg_if! {
553 if #[cfg(target_arch = "x86_64")] {
554 mod x86_64;
555 pub use self::x86_64::*;
556 } else if #[cfg(target_arch = "aarch64")] {
557 mod aarch64;
558 pub use self::aarch64::*;
559 } else {
560 // unsupported target
561 }
562}