aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / vendor / libc / src / unix / nuttx / mod.rs
| 1 | ///! Definitions for Apache NuttX RTOS. |
| 2 | ///! |
| 3 | ///! Following definitions are based on NuttX 13.0.0. |
| 4 | ///! See https://github.com/apache/nuttx/tree/releases/13.0 for more details. |
| 5 | use crate::prelude::*; |
| 6 | use crate::{ |
| 7 | in6_addr, |
| 8 | in_addr_t, |
| 9 | timespec, |
| 10 | DIR, |
| 11 | }; |
| 12 | |
| 13 | pub type pid_t = c_int; |
| 14 | pub type nlink_t = u16; |
| 15 | pub type ino_t = u16; |
| 16 | pub type blkcnt_t = u64; |
| 17 | pub type blksize_t = i16; |
| 18 | pub type cc_t = u8; |
| 19 | pub type clock_t = i64; |
| 20 | pub type dev_t = i32; |
| 21 | pub type fsblkcnt_t = u64; |
| 22 | pub type locale_t = *mut i8; |
| 23 | pub type mode_t = u32; |
| 24 | pub type nfds_t = u32; |
| 25 | pub type off_t = i64; |
| 26 | pub type pthread_key_t = i32; |
| 27 | pub type pthread_mutexattr_t = u8; |
| 28 | pub type pthread_rwlockattr_t = i32; |
| 29 | pub type pthread_t = i32; |
| 30 | pub type rlim_t = i64; |
| 31 | pub type sa_family_t = u16; |
| 32 | pub type socklen_t = c_uint; |
| 33 | pub type speed_t = usize; |
| 34 | pub type suseconds_t = i32; |
| 35 | pub type tcflag_t = u32; |
| 36 | pub type clockid_t = c_int; |
| 37 | pub type time_t = i64; |
| 38 | |
| 39 | cfg_if! { |
| 40 | if #[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))] { |
| 41 | pub type wchar_t = c_int; |
| 42 | } else if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] { |
| 43 | pub type wchar_t = c_uint; |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | s! { |
| 48 | // sys/stat.h |
| 49 | pub struct stat { |
| 50 | pub st_dev: dev_t, |
| 51 | pub st_ino: ino_t, |
| 52 | pub st_mode: mode_t, |
| 53 | pub st_nlink: nlink_t, |
| 54 | pub st_uid: u32, |
| 55 | pub st_gid: u32, |
| 56 | pub st_rdev: dev_t, |
| 57 | pub st_size: off_t, |
| 58 | pub st_atim: timespec, |
| 59 | pub st_mtim: timespec, |
| 60 | pub st_ctim: timespec, |
| 61 | pub st_blksize: blksize_t, |
| 62 | pub st_blocks: i64, |
| 63 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 64 | } |
| 65 | |
| 66 | // sys/socket.h |
| 67 | pub struct sockaddr { |
| 68 | pub sa_family: sa_family_t, |
| 69 | pub sa_data: [u8; 14], |
| 70 | } |
| 71 | |
| 72 | pub struct msghdr { |
| 73 | pub msg_name: *mut c_void, |
| 74 | pub msg_namelen: socklen_t, |
| 75 | pub msg_iov: *mut crate::iovec, |
| 76 | pub msg_iovlen: c_ulong, |
| 77 | pub msg_control: *mut c_void, |
| 78 | pub msg_controllen: c_ulong, |
| 79 | pub msg_flags: c_int, |
| 80 | } |
| 81 | |
| 82 | // pwd.h |
| 83 | pub struct passwd { |
| 84 | pub pw_name: *const c_char, |
| 85 | pub pw_passwd: *const c_char, |
| 86 | pub pw_uid: u32, |
| 87 | pub pw_gid: u32, |
| 88 | pub pw_gecos: *const c_char, |
| 89 | pub pw_dir: *const c_char, |
| 90 | pub pw_shell: *const c_char, |
| 91 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 92 | } |
| 93 | |
| 94 | pub struct sem_t { |
| 95 | __val: [usize; __SEM_SIZE__], |
| 96 | } |
| 97 | |
| 98 | pub struct pthread_attr_t { |
| 99 | __val: [usize; __PTHREAD_ATTR_SIZE__], |
| 100 | } |
| 101 | |
| 102 | pub struct pthread_mutex_t { |
| 103 | __val: [usize; __PTHREAD_MUTEX_SIZE__], |
| 104 | } |
| 105 | |
| 106 | pub struct pthread_cond_t { |
| 107 | __val: [usize; __PTHREAD_COND_SIZE__], |
| 108 | } |
| 109 | |
| 110 | pub struct pthread_condattr_t { |
| 111 | __val: [usize; __PTHREAD_CONDATTR_SIZE__], |
| 112 | } |
| 113 | |
| 114 | pub struct Dl_info { |
| 115 | pub dli_fname: *const c_char, |
| 116 | pub dli_fbase: *mut c_void, |
| 117 | pub dli_sname: *const c_char, |
| 118 | pub dli_saddr: *mut c_void, |
| 119 | } |
| 120 | |
| 121 | pub struct lconv { |
| 122 | pub decimal_point: *const c_char, |
| 123 | pub thousands_sep: *const c_char, |
| 124 | pub grouping: *const c_char, |
| 125 | pub int_curr_symbol: *const c_char, |
| 126 | pub currency_symbol: *const c_char, |
| 127 | pub mon_decimal_point: *const c_char, |
| 128 | pub mon_thousands_sep: *const c_char, |
| 129 | pub mon_grouping: *const c_char, |
| 130 | pub positive_sign: *const c_char, |
| 131 | pub negative_sign: *const c_char, |
| 132 | pub int_frac_digits: i8, |
| 133 | pub frac_digits: i8, |
| 134 | pub p_cs_precedes: i8, |
| 135 | pub p_sep_by_space: i8, |
| 136 | pub n_cs_precedes: i8, |
| 137 | pub n_sep_by_space: i8, |
| 138 | pub p_sign_posn: i8, |
| 139 | pub n_sign_posn: i8, |
| 140 | pub int_n_cs_precedes: i8, |
| 141 | pub int_n_sep_by_space: i8, |
| 142 | pub int_n_sign_posn: i8, |
| 143 | pub int_p_cs_precedes: i8, |
| 144 | pub int_p_sep_by_space: i8, |
| 145 | pub int_p_sign_posn: i8, |
| 146 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 147 | } |
| 148 | |
| 149 | pub struct tm { |
| 150 | pub tm_sec: i32, |
| 151 | pub tm_min: i32, |
| 152 | pub tm_hour: i32, |
| 153 | pub tm_mday: i32, |
| 154 | pub tm_mon: i32, |
| 155 | pub tm_year: i32, |
| 156 | pub tm_wday: i32, |
| 157 | pub tm_yday: i32, |
| 158 | pub tm_isdst: i32, |
| 159 | pub tm_gmtoff: isize, |
| 160 | pub tm_zone: *const c_char, |
| 161 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 162 | } |
| 163 | |
| 164 | pub struct addrinfo { |
| 165 | pub ai_flags: i32, |
| 166 | pub ai_family: i32, |
| 167 | pub ai_socktype: i32, |
| 168 | pub ai_protocol: i32, |
| 169 | pub ai_addrlen: socklen_t, |
| 170 | pub ai_addr: *mut sockaddr, |
| 171 | pub ai_canonname: *mut c_char, |
| 172 | pub ai_next: *mut addrinfo, |
| 173 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 174 | } |
| 175 | |
| 176 | pub struct pthread_rwlock_t { |
| 177 | __val: [usize; __PTHREAD_RWLOCK_SIZE__], |
| 178 | } |
| 179 | |
| 180 | pub struct statvfs { |
| 181 | pub f_bsize: usize, |
| 182 | pub f_frsize: usize, |
| 183 | pub f_blocks: fsblkcnt_t, |
| 184 | pub f_bfree: fsblkcnt_t, |
| 185 | pub f_bavail: fsblkcnt_t, |
| 186 | pub f_files: fsblkcnt_t, |
| 187 | pub f_ffree: fsblkcnt_t, |
| 188 | pub f_favail: fsblkcnt_t, |
| 189 | pub f_fsid: usize, |
| 190 | pub f_flag: usize, |
| 191 | pub f_namemax: usize, |
| 192 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 193 | } |
| 194 | |
| 195 | pub struct dirent { |
| 196 | pub d_type: u8, |
| 197 | pub d_name: [c_char; __NAME_MAX__ + 1], |
| 198 | } |
| 199 | |
| 200 | pub struct fd_set { |
| 201 | __val: [u32; __FDSET_SIZE__], |
| 202 | } |
| 203 | |
| 204 | pub struct sigset_t { |
| 205 | __val: [u32; __SIGSET_SIZE__], |
| 206 | } |
| 207 | |
| 208 | pub struct sigaction { |
| 209 | pub sa_handler: usize, |
| 210 | pub sa_mask: sigset_t, |
| 211 | pub sa_flags: i32, |
| 212 | pub sa_user: usize, |
| 213 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 214 | } |
| 215 | |
| 216 | pub struct termios { |
| 217 | pub c_iflag: tcflag_t, |
| 218 | pub c_oflag: tcflag_t, |
| 219 | pub c_cflag: tcflag_t, |
| 220 | pub c_lflag: tcflag_t, |
| 221 | pub c_cc: [cc_t; 12], |
| 222 | pub c_speed: speed_t, |
| 223 | __reserved: Padding<[usize; __DEFAULT_RESERVED_SIZE__]>, |
| 224 | } |
| 225 | |
| 226 | // netinet/in.h |
| 227 | pub struct in_addr { |
| 228 | pub s_addr: in_addr_t, |
| 229 | } |
| 230 | |
| 231 | pub struct sockaddr_in { |
| 232 | pub sin_family: sa_family_t, |
| 233 | pub sin_port: crate::in_port_t, |
| 234 | pub sin_addr: crate::in_addr, |
| 235 | pub sin_zero: [u8; 8], |
| 236 | } |
| 237 | |
| 238 | pub struct sockaddr_in6 { |
| 239 | pub sin6_family: sa_family_t, |
| 240 | pub sin6_port: crate::in_port_t, |
| 241 | pub sin6_flowinfo: u32, |
| 242 | pub sin6_addr: crate::in6_addr, |
| 243 | pub sin6_scope_id: u32, |
| 244 | } |
| 245 | |
| 246 | pub struct sockaddr_un { |
| 247 | pub sun_family: sa_family_t, |
| 248 | pub sun_path: [c_char; 108], |
| 249 | } |
| 250 | |
| 251 | pub struct sockaddr_storage { |
| 252 | pub ss_family: sa_family_t, |
| 253 | ss_data: [u32; __SOCKADDR_STORAGE_SIZE__], |
| 254 | } |
| 255 | |
| 256 | pub struct ip_mreq { |
| 257 | pub imr_multiaddr: in_addr, |
| 258 | pub imr_interface: in_addr, |
| 259 | } |
| 260 | |
| 261 | pub struct ip_mreqn { |
| 262 | pub imr_multiaddr: in_addr, |
| 263 | pub imr_address: in_addr, |
| 264 | pub imr_ifindex: c_uint, |
| 265 | } |
| 266 | |
| 267 | pub struct ipv6_mreq { |
| 268 | pub ipv6mr_multiaddr: in6_addr, |
| 269 | pub ipv6mr_interface: u32, |
| 270 | } |
| 271 | |
| 272 | pub struct ip_mreq_source { |
| 273 | pub imr_multiaddr: in_addr, |
| 274 | pub imr_interface: in_addr, |
| 275 | pub imr_sourceaddr: in_addr, |
| 276 | } |
| 277 | } |
| 278 | |
| 279 | // Reserved two pointer size for reserved area for some structures. |
| 280 | // This ensures that the size of these structures is large enough |
| 281 | // if more fields are added in the NuttX side. |
| 282 | // |
| 283 | // These structures are that defined by POSIX but only necessary fields are included, |
| 284 | // for example, struct passwd, https://pubs.opengroup.org/onlinepubs/009695399/basedefs/pwd.h.html, |
| 285 | // POSIX only defines following fields in struct passwd: |
| 286 | // char *pw_name User's login name. |
| 287 | // char *pw_passwd Encrypted password. |
| 288 | // uid_t pw_uid Numerical user ID. |
| 289 | // gid_t pw_gid Numerical group ID. |
| 290 | // char *pw_dir Initial working directory. |
| 291 | // char *pw_shell Program to use as shell. |
| 292 | // Other fields can be different depending on the implementation. |
| 293 | |
| 294 | const __DEFAULT_RESERVED_SIZE__: usize = 2; |
| 295 | |
| 296 | const __SOCKADDR_STORAGE_SIZE__: usize = 36; |
| 297 | const __PTHREAD_ATTR_SIZE__: usize = 5; |
| 298 | const __PTHREAD_MUTEX_SIZE__: usize = 9; |
| 299 | const __PTHREAD_COND_SIZE__: usize = 7; |
| 300 | const __PTHREAD_CONDATTR_SIZE__: usize = 5; |
| 301 | const __PTHREAD_RWLOCK_SIZE__: usize = 17; |
| 302 | const __SEM_SIZE__: usize = 6; |
| 303 | const __NAME_MAX__: usize = 64; |
| 304 | const __FDSET_SIZE__: usize = 10; |
| 305 | const __SIGSET_SIZE__: usize = 8; |
| 306 | |
| 307 | pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { |
| 308 | __val: [0; __PTHREAD_COND_SIZE__], |
| 309 | }; |
| 310 | pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { |
| 311 | __val: [0; __PTHREAD_MUTEX_SIZE__], |
| 312 | }; |
| 313 | |
| 314 | // dlfcn.h |
| 315 | pub const RTLD_DEFAULT: *mut c_void = ptr::null_mut(); |
| 316 | |
| 317 | // stdlib.h |
| 318 | pub const EXIT_SUCCESS: i32 = 0; |
| 319 | pub const EXIT_FAILURE: i32 = 1; |
| 320 | |
| 321 | // time.h |
| 322 | pub const CLOCK_REALTIME: i32 = 0; |
| 323 | pub const CLOCK_MONOTONIC: i32 = 1; |
| 324 | |
| 325 | // errno.h |
| 326 | pub const EPERM: i32 = 1; |
| 327 | pub const ENOENT: i32 = 2; |
| 328 | pub const ESRCH: i32 = 3; |
| 329 | pub const EINTR: i32 = 4; |
| 330 | pub const EIO: i32 = 5; |
| 331 | pub const ENXIO: i32 = 6; |
| 332 | pub const E2BIG: i32 = 7; |
| 333 | pub const ENOEXEC: i32 = 8; |
| 334 | pub const EBADF: i32 = 9; |
| 335 | pub const ECHILD: i32 = 10; |
| 336 | pub const EAGAIN: i32 = 11; |
| 337 | pub const ENOMEM: i32 = 12; |
| 338 | pub const EACCES: i32 = 13; |
| 339 | pub const EFAULT: i32 = 14; |
| 340 | pub const ENOTBLK: i32 = 15; |
| 341 | pub const EBUSY: i32 = 16; |
| 342 | pub const EEXIST: i32 = 17; |
| 343 | pub const EXDEV: i32 = 18; |
| 344 | pub const ENODEV: i32 = 19; |
| 345 | pub const ENOTDIR: i32 = 20; |
| 346 | pub const EISDIR: i32 = 21; |
| 347 | pub const EINVAL: i32 = 22; |
| 348 | pub const ENFILE: i32 = 23; |
| 349 | pub const EMFILE: i32 = 24; |
| 350 | pub const ENOTTY: i32 = 25; |
| 351 | pub const ETXTBSY: i32 = 26; |
| 352 | pub const EFBIG: i32 = 27; |
| 353 | pub const ENOSPC: i32 = 28; |
| 354 | pub const ESPIPE: i32 = 29; |
| 355 | pub const EROFS: i32 = 30; |
| 356 | pub const EMLINK: i32 = 31; |
| 357 | pub const EPIPE: i32 = 32; |
| 358 | pub const EDOM: i32 = 33; |
| 359 | pub const ERANGE: i32 = 34; |
| 360 | pub const EDEADLK: i32 = 35; |
| 361 | pub const ENAMETOOLONG: i32 = 36; |
| 362 | pub const ENOLCK: i32 = 37; |
| 363 | pub const ENOSYS: i32 = 38; |
| 364 | pub const ENOTEMPTY: i32 = 39; |
| 365 | pub const ELOOP: i32 = 40; |
| 366 | pub const EWOULDBLOCK: i32 = EAGAIN; |
| 367 | pub const ENOMSG: i32 = 42; |
| 368 | pub const EIDRM: i32 = 43; |
| 369 | pub const ECHRNG: i32 = 44; |
| 370 | pub const EL2NSYNC: i32 = 45; |
| 371 | pub const EL3HLT: i32 = 46; |
| 372 | pub const EL3RST: i32 = 47; |
| 373 | pub const ELNRNG: i32 = 48; |
| 374 | pub const EUNATCH: i32 = 49; |
| 375 | pub const ENOCSI: i32 = 50; |
| 376 | pub const EL2HLT: i32 = 51; |
| 377 | pub const EBADE: i32 = 52; |
| 378 | pub const EBADR: i32 = 53; |
| 379 | pub const EXFULL: i32 = 54; |
| 380 | pub const ENOANO: i32 = 55; |
| 381 | pub const EBADRQC: i32 = 56; |
| 382 | pub const EBADSLT: i32 = 57; |
| 383 | pub const EDEADLOCK: i32 = EDEADLK; |
| 384 | pub const EBFONT: i32 = 59; |
| 385 | pub const ENOSTR: i32 = 60; |
| 386 | pub const ENODATA: i32 = 61; |
| 387 | pub const ETIME: i32 = 62; |
| 388 | pub const ENOSR: i32 = 63; |
| 389 | pub const ENONET: i32 = 64; |
| 390 | pub const ENOPKG: i32 = 65; |
| 391 | pub const EREMOTE: i32 = 66; |
| 392 | pub const ENOLINK: i32 = 67; |
| 393 | pub const EADV: i32 = 68; |
| 394 | pub const ESRMNT: i32 = 69; |
| 395 | pub const ECOMM: i32 = 70; |
| 396 | pub const EPROTO: i32 = 71; |
| 397 | pub const EMULTIHOP: i32 = 72; |
| 398 | pub const EDOTDOT: i32 = 73; |
| 399 | pub const EBADMSG: i32 = 74; |
| 400 | pub const EOVERFLOW: i32 = 75; |
| 401 | pub const ENOTUNIQ: i32 = 76; |
| 402 | pub const EBADFD: i32 = 77; |
| 403 | pub const EREMCHG: i32 = 78; |
| 404 | pub const ELIBACC: i32 = 79; |
| 405 | pub const ELIBBAD: i32 = 80; |
| 406 | pub const ELIBSCN: i32 = 81; |
| 407 | pub const ELIBMAX: i32 = 82; |
| 408 | pub const ELIBEXEC: i32 = 83; |
| 409 | pub const EILSEQ: i32 = 84; |
| 410 | pub const ERESTART: i32 = 85; |
| 411 | pub const ESTRPIPE: i32 = 86; |
| 412 | pub const EUSERS: i32 = 87; |
| 413 | pub const ENOTSOCK: i32 = 88; |
| 414 | pub const EDESTADDRREQ: i32 = 89; |
| 415 | pub const EMSGSIZE: i32 = 90; |
| 416 | pub const EPROTOTYPE: i32 = 91; |
| 417 | pub const ENOPROTOOPT: i32 = 92; |
| 418 | pub const EPROTONOSUPPORT: i32 = 93; |
| 419 | pub const ESOCKTNOSUPPORT: i32 = 94; |
| 420 | pub const EOPNOTSUPP: i32 = 95; |
| 421 | pub const EPFNOSUPPORT: i32 = 96; |
| 422 | pub const EAFNOSUPPORT: i32 = 97; |
| 423 | pub const EADDRINUSE: i32 = 98; |
| 424 | pub const EADDRNOTAVAIL: i32 = 99; |
| 425 | pub const ENETDOWN: i32 = 100; |
| 426 | pub const ENETUNREACH: i32 = 101; |
| 427 | pub const ENETRESET: i32 = 102; |
| 428 | pub const ECONNABORTED: i32 = 103; |
| 429 | pub const ECONNRESET: i32 = 104; |
| 430 | pub const ENOBUFS: i32 = 105; |
| 431 | pub const EISCONN: i32 = 106; |
| 432 | pub const ENOTCONN: i32 = 107; |
| 433 | pub const ESHUTDOWN: i32 = 108; |
| 434 | pub const ETOOMANYREFS: i32 = 109; |
| 435 | pub const ETIMEDOUT: i32 = 110; |
| 436 | pub const ECONNREFUSED: i32 = 111; |
| 437 | pub const EHOSTDOWN: i32 = 112; |
| 438 | pub const EHOSTUNREACH: i32 = 113; |
| 439 | pub const EALREADY: i32 = 114; |
| 440 | pub const EINPROGRESS: i32 = 115; |
| 441 | pub const ESTALE: i32 = 116; |
| 442 | pub const EUCLEAN: i32 = 117; |
| 443 | pub const ENOTNAM: i32 = 118; |
| 444 | pub const ENAVAIL: i32 = 119; |
| 445 | pub const EISNAM: i32 = 120; |
| 446 | pub const EREMOTEIO: i32 = 121; |
| 447 | pub const EDQUOT: i32 = 122; |
| 448 | pub const ENOMEDIUM: i32 = 123; |
| 449 | pub const EMEDIUMTYPE: i32 = 124; |
| 450 | pub const ECANCELED: i32 = 125; |
| 451 | pub const ENOKEY: i32 = 126; |
| 452 | pub const EKEYEXPIRED: i32 = 127; |
| 453 | pub const EKEYREVOKED: i32 = 128; |
| 454 | pub const EKEYREJECTED: i32 = 129; |
| 455 | pub const EOWNERDEAD: i32 = 130; |
| 456 | pub const ENOTRECOVERABLE: i32 = 131; |
| 457 | pub const ERFKILL: i32 = 132; |
| 458 | pub const EHWPOISON: i32 = 133; |
| 459 | pub const ELBIN: i32 = 134; |
| 460 | pub const EFTYPE: i32 = 135; |
| 461 | pub const ENMFILE: i32 = 136; |
| 462 | pub const EPROCLIM: i32 = 137; |
| 463 | pub const ENOTSUP: i32 = 138; |
| 464 | pub const ENOSHARE: i32 = 139; |
| 465 | pub const ECASECLASH: i32 = 140; |
| 466 | |
| 467 | // fcntl.h |
| 468 | // fcntl() commands |
| 469 | pub const FIOCLEX: i32 = 0x30b; |
| 470 | pub const F_DUPFD_CLOEXEC: i32 = 0x12; |
| 471 | pub const F_GETFD: i32 = 0x1; |
| 472 | pub const F_GETFL: i32 = 0x2; |
| 473 | pub const F_SETFD: i32 = 8; |
| 474 | pub const F_SETFL: i32 = 9; |
| 475 | // open flag settings for open() (and related APIs) |
| 476 | pub const O_RDONLY: i32 = 0x1; |
| 477 | pub const O_WRONLY: i32 = 0x2; |
| 478 | pub const O_RDWR: i32 = 0x3; |
| 479 | pub const O_CREAT: i32 = 0x4; |
| 480 | pub const O_EXCL: i32 = 0x8; |
| 481 | pub const O_NOCTTY: i32 = 0x0; |
| 482 | pub const O_TRUNC: i32 = 0x20; |
| 483 | pub const O_APPEND: i32 = 0x10; |
| 484 | pub const O_NONBLOCK: i32 = 0x40; |
| 485 | pub const O_DSYNC: i32 = 0x80; |
| 486 | pub const O_DIRECT: i32 = 0x200; |
| 487 | pub const O_LARGEFILE: i32 = 0x2000; |
| 488 | pub const O_DIRECTORY: i32 = 0x800; |
| 489 | pub const O_NOFOLLOW: i32 = 0x1000; |
| 490 | pub const O_NOATIME: i32 = 0x40000; |
| 491 | pub const O_CLOEXEC: i32 = 0x400; |
| 492 | pub const O_ACCMODE: i32 = 0x0003; |
| 493 | pub const AT_FDCWD: i32 = -100; |
| 494 | pub const AT_REMOVEDIR: i32 = 0x200; |
| 495 | |
| 496 | // sys/types.h |
| 497 | pub const SEEK_SET: i32 = 0; |
| 498 | pub const SEEK_CUR: i32 = 1; |
| 499 | pub const SEEK_END: i32 = 2; |
| 500 | |
| 501 | // sys/stat.h |
| 502 | pub const S_IFDIR: u32 = 0x4000; |
| 503 | pub const S_IFLNK: u32 = 0xA000; |
| 504 | pub const S_IFREG: u32 = 0x8000; |
| 505 | pub const S_IFMT: u32 = 0xF000; |
| 506 | pub const S_IFIFO: u32 = 0x1000; |
| 507 | pub const S_IFSOCK: u32 = 0xc000; |
| 508 | pub const S_IFBLK: u32 = 0x6000; |
| 509 | pub const S_IFCHR: u32 = 0x2000; |
| 510 | pub const S_IRUSR: u32 = 0x100; |
| 511 | pub const S_IWUSR: u32 = 0x80; |
| 512 | pub const S_IXUSR: u32 = 0x40; |
| 513 | pub const S_IRGRP: u32 = 0x20; |
| 514 | pub const S_IWGRP: u32 = 0x10; |
| 515 | pub const S_IXGRP: u32 = 0x8; |
| 516 | pub const S_IROTH: u32 = 0x004; |
| 517 | pub const S_IWOTH: u32 = 0x002; |
| 518 | pub const S_IXOTH: u32 = 0x001; |
| 519 | |
| 520 | // sys/poll.h |
| 521 | pub const POLLIN: i16 = 0x01; |
| 522 | pub const POLLRDNORM: i16 = 0x01; |
| 523 | pub const POLLRDBAND: i16 = 0x01; |
| 524 | pub const POLLPRI: i16 = 0x02; |
| 525 | pub const POLLOUT: i16 = 0x04; |
| 526 | pub const POLLWRNORM: i16 = 0x04; |
| 527 | pub const POLLWRBAND: i16 = 0x04; |
| 528 | pub const POLLHUP: i16 = 0x10; |
| 529 | pub const POLLRDHUP: i16 = 0x10; |
| 530 | pub const POLLERR: i16 = 0x08; |
| 531 | pub const POLLNVAL: i16 = 0x20; |
| 532 | |
| 533 | // sys/socket.h |
| 534 | // Supported Protocol Families |
| 535 | pub const AF_UNSPEC: i32 = 0; |
| 536 | pub const AF_UNIX: i32 = 1; |
| 537 | pub const AF_INET: i32 = 2; |
| 538 | pub const AF_INET6: i32 = 10; |
| 539 | // The socket created by socket() has the indicated type, which specifies |
| 540 | // the communication semantics. |
| 541 | pub const SOCK_STREAM: i32 = 1; |
| 542 | pub const SOCK_DGRAM: i32 = 2; |
| 543 | pub const SOCK_RAW: i32 = 3; |
| 544 | pub const SOCK_RDM: i32 = 4; |
| 545 | pub const SOCK_SEQPACKET: i32 = 5; |
| 546 | pub const SOCK_CLOEXEC: i32 = 0o02000000; |
| 547 | pub const SOCK_NONBLOCK: i32 = 0o00004000; |
| 548 | // Bits in the FLAGS argument to `send', `recv', et al. These are the bits |
| 549 | // recognized by Linux, not all are supported by NuttX. |
| 550 | pub const MSG_OOB: i32 = 0x000001; |
| 551 | pub const MSG_PEEK: i32 = 0x000002; |
| 552 | pub const MSG_TRUNC: i32 = 0x000020; |
| 553 | pub const MSG_EOR: i32 = 0x000080; |
| 554 | // Protocol levels supported by get/setsockopt(): |
| 555 | pub const SOL_SOCKET: i32 = 1; |
| 556 | // Socket-level options |
| 557 | pub const SO_BROADCAST: i32 = 1; |
| 558 | pub const SO_ERROR: i32 = 4; |
| 559 | pub const SO_KEEPALIVE: i32 = 5; |
| 560 | pub const SO_LINGER: i32 = 6; |
| 561 | pub const SO_OOBINLINE: i32 = 7; |
| 562 | pub const SO_RCVBUF: i32 = 8; |
| 563 | pub const SO_RCVTIMEO: i32 = 10; |
| 564 | pub const SO_REUSEADDR: i32 = 11; |
| 565 | pub const SO_SNDBUF: i32 = 12; |
| 566 | pub const SO_SNDTIMEO: i32 = 14; |
| 567 | pub const SO_TYPE: i32 = 15; |
| 568 | // Protocol-level socket options may begin with this value |
| 569 | pub const __SO_PROTOCOL: i32 = 16; |
| 570 | // Values for the 'how' argument of shutdown() |
| 571 | pub const SHUT_RD: i32 = 1; |
| 572 | pub const SHUT_WR: i32 = 2; |
| 573 | pub const SHUT_RDWR: i32 = 3; |
| 574 | // The maximum backlog queue length |
| 575 | pub const SOMAXCONN: i32 = 8; |
| 576 | |
| 577 | // netinet/tcp.h |
| 578 | pub const TCP_NODELAY: i32 = __SO_PROTOCOL + 0; |
| 579 | pub const TCP_KEEPIDLE: i32 = __SO_PROTOCOL + 1; |
| 580 | pub const TCP_KEEPINTVL: i32 = __SO_PROTOCOL + 2; |
| 581 | pub const TCP_KEEPCNT: i32 = __SO_PROTOCOL + 3; |
| 582 | pub const TCP_MAXSEG: i32 = __SO_PROTOCOL + 4; |
| 583 | |
| 584 | // nuttx/fs/ioctl.h |
| 585 | pub const FIONBIO: i32 = 0x30a; |
| 586 | |
| 587 | // unistd.h |
| 588 | pub const _SC_PAGESIZE: i32 = 0x36; |
| 589 | pub const _SC_THREAD_STACK_MIN: i32 = 0x58; |
| 590 | pub const _SC_GETPW_R_SIZE_MAX: i32 = 0x25; |
| 591 | pub const _SC_HOST_NAME_MAX: i32 = 0x26; |
| 592 | |
| 593 | // sys/eventfd.h |
| 594 | pub const EFD_NONBLOCK: i32 = O_NONBLOCK; |
| 595 | pub const EFD_CLOEXEC: i32 = O_CLOEXEC; |
| 596 | |
| 597 | // signal.h |
| 598 | pub const SIGHUP: c_int = 1; |
| 599 | pub const SIGINT: c_int = 2; |
| 600 | pub const SIGQUIT: c_int = 3; |
| 601 | pub const SIGILL: c_int = 4; |
| 602 | pub const SIGTRAP: c_int = 5; |
| 603 | pub const SIGABRT: c_int = 6; |
| 604 | pub const SIGBUS: c_int = 7; |
| 605 | pub const SIGFPE: c_int = 8; |
| 606 | pub const SIGKILL: c_int = 9; |
| 607 | pub const SIGUSR1: c_int = 10; |
| 608 | pub const SIGSEGV: c_int = 11; |
| 609 | pub const SIGUSR2: c_int = 12; |
| 610 | pub const SIGPIPE: c_int = 13; |
| 611 | pub const SIGALRM: c_int = 14; |
| 612 | pub const SIGTERM: c_int = 15; |
| 613 | pub const SIGSTKFLT: c_int = 16; |
| 614 | pub const SIGCHLD: c_int = 17; |
| 615 | pub const SIGCONT: c_int = 18; |
| 616 | pub const SIGSTOP: c_int = 19; |
| 617 | pub const SIGTSTP: c_int = 20; |
| 618 | pub const SIGTTIN: c_int = 21; |
| 619 | pub const SIGTTOU: c_int = 22; |
| 620 | pub const SIGURG: c_int = 23; |
| 621 | pub const SIGXCPU: c_int = 24; |
| 622 | pub const SIGXFSZ: c_int = 25; |
| 623 | pub const SIGVTALRM: c_int = 26; |
| 624 | pub const SIGPROF: c_int = 27; |
| 625 | pub const SIGWINCH: c_int = 28; |
| 626 | pub const SIGIO: c_int = 29; |
| 627 | pub const SIGPOLL: c_int = SIGIO; |
| 628 | pub const SIGPWR: c_int = 30; |
| 629 | pub const SIGSYS: c_int = 31; |
| 630 | |
| 631 | // pthread.h |
| 632 | pub const PTHREAD_MUTEX_NORMAL: i32 = 0; |
| 633 | |
| 634 | // netinet/in.h |
| 635 | // SOL_IP protocol-level socket options. |
| 636 | pub const IP_MULTICAST_IF: i32 = __SO_PROTOCOL + 1; |
| 637 | pub const IP_MULTICAST_TTL: i32 = __SO_PROTOCOL + 2; |
| 638 | pub const IP_MULTICAST_LOOP: i32 = __SO_PROTOCOL + 3; |
| 639 | pub const IP_ADD_MEMBERSHIP: i32 = __SO_PROTOCOL + 4; |
| 640 | pub const IP_DROP_MEMBERSHIP: i32 = __SO_PROTOCOL + 5; |
| 641 | pub const IP_ADD_SOURCE_MEMBERSHIP: i32 = __SO_PROTOCOL + 8; |
| 642 | pub const IP_DROP_SOURCE_MEMBERSHIP: i32 = __SO_PROTOCOL + 9; |
| 643 | pub const IP_TOS: i32 = __SO_PROTOCOL + 13; |
| 644 | pub const IP_TTL: i32 = __SO_PROTOCOL + 14; |
| 645 | // SOL_IPV6 protocol-level socket options. |
| 646 | pub const IPV6_JOIN_GROUP: i32 = __SO_PROTOCOL + 1; |
| 647 | pub const IPV6_LEAVE_GROUP: i32 = __SO_PROTOCOL + 2; |
| 648 | pub const IPV6_MULTICAST_HOPS: i32 = __SO_PROTOCOL + 3; |
| 649 | pub const IPV6_MULTICAST_IF: i32 = __SO_PROTOCOL + 4; |
| 650 | pub const IPV6_MULTICAST_LOOP: i32 = __SO_PROTOCOL + 5; |
| 651 | pub const IPV6_UNICAST_HOPS: i32 = __SO_PROTOCOL + 6; |
| 652 | pub const IPV6_V6ONLY: i32 = __SO_PROTOCOL + 7; |
| 653 | pub const IPV6_RECVHOPLIMIT: i32 = __SO_PROTOCOL + 11; |
| 654 | |
| 655 | extern "C" { |
| 656 | pub fn __errno() -> *mut c_int; |
| 657 | pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32; |
| 658 | pub fn ioctl(fd: i32, request: i32, ...) -> i32; |
| 659 | pub fn dirfd(dirp: *mut DIR) -> i32; |
| 660 | pub fn recvfrom( |
| 661 | sockfd: i32, |
| 662 | buf: *mut c_void, |
| 663 | len: usize, |
| 664 | flags: i32, |
| 665 | src_addr: *mut sockaddr, |
| 666 | addrlen: *mut socklen_t, |
| 667 | ) -> i32; |
| 668 | |
| 669 | pub fn pthread_create( |
| 670 | thread: *mut pthread_t, |
| 671 | attr: *const pthread_attr_t, |
| 672 | start_routine: extern "C" fn(*mut c_void) -> *mut c_void, |
| 673 | arg: *mut c_void, |
| 674 | ) -> i32; |
| 675 | |
| 676 | pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32; |
| 677 | pub fn futimens(fd: i32, times: *const timespec) -> i32; |
| 678 | pub fn pthread_condattr_setclock(attr: *mut pthread_condattr_t, clock_id: clockid_t) -> i32; |
| 679 | pub fn pthread_setname_np(thread: pthread_t, name: *const c_char) -> i32; |
| 680 | pub fn pthread_getname_np(thread: pthread_t, name: *mut c_char, len: usize) -> i32; |
| 681 | pub fn getrandom(buf: *mut c_void, buflen: usize, flags: u32) -> isize; |
| 682 | pub fn arc4random() -> u32; |
| 683 | pub fn arc4random_buf(bytes: *mut c_void, nbytes: usize); |
| 684 | // string.h |
| 685 | pub fn strerror_r(errnum: c_int, buf: *mut c_char, buflen: size_t) -> c_int; |
| 686 | // sys/socket.h |
| 687 | pub fn accept4( |
| 688 | sockfd: c_int, |
| 689 | addr: *mut sockaddr, |
| 690 | addrlen: *mut socklen_t, |
| 691 | flags: c_int, |
| 692 | ) -> c_int; |
| 693 | pub fn recvmsg(sockfd: c_int, msg: *mut msghdr, flags: c_int) -> ssize_t; |
| 694 | pub fn sendmsg(sockfd: c_int, msg: *const msghdr, flags: c_int) -> ssize_t; |
| 695 | // sys/eventfd.h |
| 696 | pub fn eventfd(count: c_uint, flags: c_int) -> c_int; |
| 697 | // unistd.h |
| 698 | pub fn pipe2(fds: *mut c_int, flags: c_int) -> c_int; |
| 699 | } |