1 //! Hermit C type definitions 2 3 use crate::prelude::*; 4 5 pub type intmax_t = i64; 6 pub type uintmax_t = u64; 7 pub type intptr_t = isize; 8 pub type uintptr_t = usize; 9 10 pub type size_t = usize; 11 pub type ssize_t = isize; 12 pub type ptrdiff_t = isize; 13 14 pub type clockid_t = i32; 15 pub type in_addr_t = u32; 16 pub type in_port_t = u16; 17 pub type mode_t = u32; 18 pub type nfds_t = usize; 19 pub type pid_t = i32; 20 pub type sa_family_t = u8; 21 pub type socklen_t = u32; 22 pub type time_t = i64; 23 24 s! { 25 pub struct addrinfo { 26 pub ai_flags: i32, 27 pub ai_family: i32, 28 pub ai_socktype: i32, 29 pub ai_protocol: i32, 30 pub ai_addrlen: socklen_t, 31 pub ai_canonname: *mut c_char, 32 pub ai_addr: *mut sockaddr, 33 pub ai_next: *mut addrinfo, 34 } 35 36 pub struct dirent64 { 37 pub d_ino: u64, 38 pub d_off: i64, 39 pub d_reclen: u16, 40 pub d_type: u8, 41 pub d_name: [c_char; 256], 42 } 43 44 #[repr(align(4))] 45 pub struct in6_addr { 46 pub s6_addr: [u8; 16], 47 } 48 49 pub struct in_addr { 50 pub s_addr: in_addr_t, 51 } 52 53 pub struct iovec { 54 iov_base: *mut c_void, 55 iov_len: usize, 56 } 57 58 pub struct pollfd { 59 pub fd: i32, 60 pub events: i16, 61 pub revents: i16, 62 } 63 64 pub struct sockaddr { 65 pub sa_len: u8, 66 pub sa_family: sa_family_t, 67 pub sa_data: [c_char; 14], 68 } 69 70 pub struct sockaddr_in { 71 pub sin_len: u8, 72 pub sin_family: sa_family_t, 73 pub sin_port: in_port_t, 74 pub sin_addr: in_addr, 75 pub sin_zero: [c_char; 8], 76 } 77 78 pub struct sockaddr_in6 { 79 pub sin6_len: u8, 80 pub sin6_family: sa_family_t, 81 pub sin6_port: in_port_t, 82 pub sin6_flowinfo: u32, 83 pub sin6_addr: in6_addr, 84 pub sin6_scope_id: u32, 85 } 86 87 pub struct sockaddr_storage { 88 pub ss_len: u8, 89 pub ss_family: sa_family_t, 90 __ss_pad1: [u8; 6], 91 __ss_align: i64, 92 __ss_pad2: [u8; 112], 93 } 94 95 pub struct stat { 96 pub st_dev: u64, 97 pub st_ino: u64, 98 pub st_nlink: u64, 99 pub st_mode: mode_t, 100 pub st_uid: u32, 101 pub st_gid: u32, 102 pub st_rdev: u64, 103 pub st_size: i64, 104 pub st_blksize: i64, 105 pub st_blocks: i64, 106 pub st_atim: timespec, 107 pub st_mtim: timespec, 108 pub st_ctim: timespec, 109 } 110 111 pub struct timespec { 112 pub tv_sec: time_t, 113 pub tv_nsec: i32, 114 } 115 } 116 117 pub const AF_INET: i32 = 0; 118 pub const AF_INET6: i32 = 1; 119 120 pub const CLOCK_REALTIME: clockid_t = 1; 121 pub const CLOCK_MONOTONIC: clockid_t = 4; 122 123 pub const DT_UNKNOWN: u8 = 0; 124 pub const DT_FIFO: u8 = 1; 125 pub const DT_CHR: u8 = 2; 126 pub const DT_DIR: u8 = 4; 127 pub const DT_BLK: u8 = 6; 128 pub const DT_REG: u8 = 8; 129 pub const DT_LNK: u8 = 10; 130 pub const DT_SOCK: u8 = 12; 131 pub const DT_WHT: u8 = 14; 132 133 pub const EAI_AGAIN: i32 = 2; 134 pub const EAI_BADFLAGS: i32 = 3; 135 pub const EAI_FAIL: i32 = 4; 136 pub const EAI_FAMILY: i32 = 5; 137 pub const EAI_MEMORY: i32 = 6; 138 pub const EAI_NODATA: i32 = 7; 139 pub const EAI_NONAME: i32 = 8; 140 pub const EAI_SERVICE: i32 = 9; 141 pub const EAI_SOCKTYPE: i32 = 10; 142 pub const EAI_SYSTEM: i32 = 11; 143 pub const EAI_OVERFLOW: i32 = 14; 144 145 pub const EFD_SEMAPHORE: i16 = 0o1; 146 pub const EFD_NONBLOCK: i16 = 0o4000; 147 pub const EFD_CLOEXEC: i16 = 0o40000; 148 149 pub const F_DUPFD: i32 = 0; 150 pub const F_GETFD: i32 = 1; 151 pub const F_SETFD: i32 = 2; 152 pub const F_GETFL: i32 = 3; 153 pub const F_SETFL: i32 = 4; 154 155 pub const FD_CLOEXEC: i32 = 1; 156 157 pub const FIONBIO: i32 = 0x8008667e; 158 159 pub const FUTEX_RELATIVE_TIMEOUT: u32 = 1; 160 161 pub const IP_TOS: i32 = 1; 162 pub const IP_TTL: i32 = 2; 163 pub const IP_ADD_MEMBERSHIP: i32 = 3; 164 pub const IP_DROP_MEMBERSHIP: i32 = 4; 165 pub const IP_MULTICAST_TTL: i32 = 5; 166 pub const IP_MULTICAST_LOOP: i32 = 7; 167 168 pub const IPPROTO_IP: i32 = 0; 169 pub const IPPROTO_TCP: i32 = 6; 170 pub const IPPROTO_UDP: i32 = 17; 171 pub const IPPROTO_IPV6: i32 = 41; 172 173 pub const IPV6_ADD_MEMBERSHIP: i32 = 12; 174 pub const IPV6_DROP_MEMBERSHIP: i32 = 13; 175 pub const IPV6_MULTICAST_LOOP: i32 = 19; 176 pub const IPV6_V6ONLY: i32 = 27; 177 178 pub const MSG_PEEK: i32 = 1; 179 180 pub const O_RDONLY: i32 = 0o0; 181 pub const O_WRONLY: i32 = 0o1; 182 pub const O_RDWR: i32 = 0o2; 183 pub const O_CREAT: i32 = 0o100; 184 pub const O_EXCL: i32 = 0o200; 185 pub const O_TRUNC: i32 = 0o1000; 186 pub const O_APPEND: i32 = 0o2000; 187 pub const O_NONBLOCK: i32 = 0o4000; 188 pub const O_DIRECTORY: i32 = 0o200000; 189 190 pub const POLLIN: i16 = 0x1; 191 pub const POLLPRI: i16 = 0x2; 192 pub const POLLOUT: i16 = 0x4; 193 pub const POLLERR: i16 = 0x8; 194 pub const POLLHUP: i16 = 0x10; 195 pub const POLLNVAL: i16 = 0x20; 196 pub const POLLRDNORM: i16 = 0x040; 197 pub const POLLRDBAND: i16 = 0x080; 198 pub const POLLWRNORM: i16 = 0x0100; 199 pub const POLLWRBAND: i16 = 0x0200; 200 pub const POLLRDHUP: i16 = 0x2000; 201 202 pub const S_IRWXU: mode_t = 0o0700; 203 pub const S_IRUSR: mode_t = 0o0400; 204 pub const S_IWUSR: mode_t = 0o0200; 205 pub const S_IXUSR: mode_t = 0o0100; 206 pub const S_IRWXG: mode_t = 0o0070; 207 pub const S_IRGRP: mode_t = 0o0040; 208 pub const S_IWGRP: mode_t = 0o0020; 209 pub const S_IXGRP: mode_t = 0o0010; 210 pub const S_IRWXO: mode_t = 0o0007; 211 pub const S_IROTH: mode_t = 0o0004; 212 pub const S_IWOTH: mode_t = 0o0002; 213 pub const S_IXOTH: mode_t = 0o0001; 214 215 pub const S_IFMT: mode_t = 0o17_0000; 216 pub const S_IFSOCK: mode_t = 0o14_0000; 217 pub const S_IFLNK: mode_t = 0o12_0000; 218 pub const S_IFREG: mode_t = 0o10_0000; 219 pub const S_IFBLK: mode_t = 0o6_0000; 220 pub const S_IFDIR: mode_t = 0o4_0000; 221 pub const S_IFCHR: mode_t = 0o2_0000; 222 pub const S_IFIFO: mode_t = 0o1_0000; 223 224 pub const SHUT_RD: i32 = 0; 225 pub const SHUT_WR: i32 = 1; 226 pub const SHUT_RDWR: i32 = 2; 227 228 pub const SO_REUSEADDR: i32 = 0x0004; 229 pub const SO_KEEPALIVE: i32 = 0x0008; 230 pub const SO_BROADCAST: i32 = 0x0020; 231 pub const SO_LINGER: i32 = 0x0080; 232 pub const SO_SNDBUF: i32 = 0x1001; 233 pub const SO_RCVBUF: i32 = 0x1002; 234 pub const SO_SNDTIMEO: i32 = 0x1005; 235 pub const SO_RCVTIMEO: i32 = 0x1006; 236 pub const SO_ERROR: i32 = 0x1007; 237 238 pub const SOCK_STREAM: i32 = 1; 239 pub const SOCK_DGRAM: i32 = 2; 240 pub const SOCK_NONBLOCK: i32 = 0o4000; 241 pub const SOCK_CLOEXEC: i32 = 0o40000; 242 243 pub const SOL_SOCKET: i32 = 4095; 244 245 pub const STDIN_FILENO: c_int = 0; 246 pub const STDOUT_FILENO: c_int = 1; 247 pub const STDERR_FILENO: c_int = 2; 248 249 pub const TCP_NODELAY: i32 = 1; 250 251 pub const EPERM: i32 = 1; 252 pub const ENOENT: i32 = 2; 253 pub const ESRCH: i32 = 3; 254 pub const EINTR: i32 = 4; 255 pub const EIO: i32 = 5; 256 pub const ENXIO: i32 = 6; 257 pub const E2BIG: i32 = 7; 258 pub const ENOEXEC: i32 = 8; 259 pub const EBADF: i32 = 9; 260 pub const ECHILD: i32 = 10; 261 pub const EAGAIN: i32 = 11; 262 pub const ENOMEM: i32 = 12; 263 pub const EACCES: i32 = 13; 264 pub const EFAULT: i32 = 14; 265 pub const ENOTBLK: i32 = 15; 266 pub const EBUSY: i32 = 16; 267 pub const EEXIST: i32 = 17; 268 pub const EXDEV: i32 = 18; 269 pub const ENODEV: i32 = 19; 270 pub const ENOTDIR: i32 = 20; 271 pub const EISDIR: i32 = 21; 272 pub const EINVAL: i32 = 22; 273 pub const ENFILE: i32 = 23; 274 pub const EMFILE: i32 = 24; 275 pub const ENOTTY: i32 = 25; 276 pub const ETXTBSY: i32 = 26; 277 pub const EFBIG: i32 = 27; 278 pub const ENOSPC: i32 = 28; 279 pub const ESPIPE: i32 = 29; 280 pub const EROFS: i32 = 30; 281 pub const EMLINK: i32 = 31; 282 pub const EPIPE: i32 = 32; 283 pub const EDOM: i32 = 33; 284 pub const ERANGE: i32 = 34; 285 pub const EDEADLK: i32 = 35; 286 pub const ENAMETOOLONG: i32 = 36; 287 pub const ENOLCK: i32 = 37; 288 pub const ENOSYS: i32 = 38; 289 pub const ENOTEMPTY: i32 = 39; 290 pub const ELOOP: i32 = 40; 291 pub const EWOULDBLOCK: i32 = EAGAIN; 292 pub const ENOMSG: i32 = 42; 293 pub const EIDRM: i32 = 43; 294 pub const ECHRNG: i32 = 44; 295 pub const EL2NSYNC: i32 = 45; 296 pub const EL3HLT: i32 = 46; 297 pub const EL3RST: i32 = 47; 298 pub const ELNRNG: i32 = 48; 299 pub const EUNATCH: i32 = 49; 300 pub const ENOCSI: i32 = 50; 301 pub const EL2HLT: i32 = 51; 302 pub const EBADE: i32 = 52; 303 pub const EBADR: i32 = 53; 304 pub const EXFULL: i32 = 54; 305 pub const ENOANO: i32 = 55; 306 pub const EBADRQC: i32 = 56; 307 pub const EBADSLT: i32 = 57; 308 pub const EDEADLOCK: i32 = EDEADLK; 309 pub const EBFONT: i32 = 59; 310 pub const ENOSTR: i32 = 60; 311 pub const ENODATA: i32 = 61; 312 pub const ETIME: i32 = 62; 313 pub const ENOSR: i32 = 63; 314 pub const ENONET: i32 = 64; 315 pub const ENOPKG: i32 = 65; 316 pub const EREMOTE: i32 = 66; 317 pub const ENOLINK: i32 = 67; 318 pub const EADV: i32 = 68; 319 pub const ESRMNT: i32 = 69; 320 pub const ECOMM: i32 = 70; 321 pub const EPROTO: i32 = 71; 322 pub const EMULTIHOP: i32 = 72; 323 pub const EDOTDOT: i32 = 73; 324 pub const EBADMSG: i32 = 74; 325 pub const EOVERFLOW: i32 = 75; 326 pub const ENOTUNIQ: i32 = 76; 327 pub const EBADFD: i32 = 77; 328 pub const EREMCHG: i32 = 78; 329 pub const ELIBACC: i32 = 79; 330 pub const ELIBBAD: i32 = 80; 331 pub const ELIBSCN: i32 = 81; 332 pub const ELIBMAX: i32 = 82; 333 pub const ELIBEXEC: i32 = 83; 334 pub const EILSEQ: i32 = 84; 335 pub const ERESTART: i32 = 85; 336 pub const ESTRPIPE: i32 = 86; 337 pub const EUSERS: i32 = 87; 338 pub const ENOTSOCK: i32 = 88; 339 pub const EDESTADDRREQ: i32 = 89; 340 pub const EMSGSIZE: i32 = 90; 341 pub const EPROTOTYPE: i32 = 91; 342 pub const ENOPROTOOPT: i32 = 92; 343 pub const EPROTONOSUPPORT: i32 = 93; 344 pub const ESOCKTNOSUPPORT: i32 = 94; 345 pub const EOPNOTSUPP: i32 = 95; 346 pub const EPFNOSUPPORT: i32 = 96; 347 pub const EAFNOSUPPORT: i32 = 97; 348 pub const EADDRINUSE: i32 = 98; 349 pub const EADDRNOTAVAIL: i32 = 99; 350 pub const ENETDOWN: i32 = 100; 351 pub const ENETUNREACH: i32 = 101; 352 pub const ENETRESET: i32 = 102; 353 pub const ECONNABORTED: i32 = 103; 354 pub const ECONNRESET: i32 = 104; 355 pub const ENOBUFS: i32 = 105; 356 pub const EISCONN: i32 = 106; 357 pub const ENOTCONN: i32 = 107; 358 pub const ESHUTDOWN: i32 = 108; 359 pub const ETOOMANYREFS: i32 = 109; 360 pub const ETIMEDOUT: i32 = 110; 361 pub const ECONNREFUSED: i32 = 111; 362 pub const EHOSTDOWN: i32 = 112; 363 pub const EHOSTUNREACH: i32 = 113; 364 pub const EALREADY: i32 = 114; 365 pub const EINPROGRESS: i32 = 115; 366 pub const ESTALE: i32 = 116; 367 pub const EUCLEAN: i32 = 117; 368 pub const ENOTNAM: i32 = 118; 369 pub const ENAVAIL: i32 = 119; 370 pub const EISNAM: i32 = 120; 371 pub const EREMOTEIO: i32 = 121; 372 pub const EDQUOT: i32 = 122; 373 pub const ENOMEDIUM: i32 = 123; 374 pub const EMEDIUMTYPE: i32 = 124; 375 pub const ECANCELED: i32 = 125; 376 pub const ENOKEY: i32 = 126; 377 pub const EKEYEXPIRED: i32 = 127; 378 pub const EKEYREVOKED: i32 = 128; 379 pub const EKEYREJECTED: i32 = 129; 380 pub const EOWNERDEAD: i32 = 130; 381 pub const ENOTRECOVERABLE: i32 = 131; 382 pub const ERFKILL: i32 = 132; 383 pub const EHWPOISON: i32 = 133; 384 385 extern "C" { 386 #[link_name = "sys_alloc"] 387 pub fn alloc(size: usize, align: usize) -> *mut u8; 388 389 #[link_name = "sys_alloc_zeroed"] 390 pub fn alloc_zeroed(size: usize, align: usize) -> *mut u8; 391 392 #[link_name = "sys_realloc"] 393 pub fn realloc(ptr: *mut u8, size: usize, align: usize, new_size: usize) -> *mut u8; 394 395 #[link_name = "sys_dealloc"] 396 pub fn dealloc(ptr: *mut u8, size: usize, align: usize); 397 398 #[link_name = "sys_exit"] 399 pub fn exit(status: i32) -> !; 400 401 #[link_name = "sys_abort"] 402 pub fn abort() -> !; 403 404 #[link_name = "sys_errno"] 405 pub fn errno() -> i32; 406 407 #[link_name = "sys_clock_gettime"] 408 pub fn clock_gettime(clockid: clockid_t, tp: *mut timespec) -> i32; 409 410 #[link_name = "sys_nanosleep"] 411 pub fn nanosleep(req: *const timespec) -> i32; 412 413 #[link_name = "sys_available_parallelism"] 414 pub fn available_parallelism() -> usize; 415 416 #[link_name = "sys_futex_wait"] 417 pub fn futex_wait( 418 address: *mut u32, 419 expected: u32, 420 timeout: *const timespec, 421 flags: u32, 422 ) -> i32; 423 424 #[link_name = "sys_futex_wake"] 425 pub fn futex_wake(address: *mut u32, count: i32) -> i32; 426 427 #[link_name = "sys_stat"] 428 pub fn stat(path: *const c_char, stat: *mut stat) -> i32; 429 430 #[link_name = "sys_fstat"] 431 pub fn fstat(fd: i32, stat: *mut stat) -> i32; 432 433 #[link_name = "sys_lstat"] 434 pub fn lstat(path: *const c_char, stat: *mut stat) -> i32; 435 436 #[link_name = "sys_open"] 437 pub fn open(path: *const c_char, flags: i32, mode: mode_t) -> i32; 438 439 #[link_name = "sys_unlink"] 440 pub fn unlink(path: *const c_char) -> i32; 441 442 #[link_name = "sys_mkdir"] 443 pub fn mkdir(path: *const c_char, mode: mode_t) -> i32; 444 445 #[link_name = "sys_rmdir"] 446 pub fn rmdir(path: *const c_char) -> i32; 447 448 #[link_name = "sys_read"] 449 pub fn read(fd: i32, buf: *mut u8, len: usize) -> isize; 450 451 #[link_name = "sys_write"] 452 pub fn write(fd: i32, buf: *const u8, len: usize) -> isize; 453 454 #[link_name = "sys_readv"] 455 pub fn readv(fd: i32, iov: *const iovec, iovcnt: usize) -> isize; 456 457 #[link_name = "sys_writev"] 458 pub fn writev(fd: i32, iov: *const iovec, iovcnt: usize) -> isize; 459 460 #[link_name = "sys_close"] 461 pub fn close(fd: i32) -> i32; 462 463 #[link_name = "sys_dup"] 464 pub fn dup(fd: i32) -> i32; 465 466 #[link_name = "sys_fcntl"] 467 pub fn fcntl(fd: i32, cmd: i32, arg: i32) -> i32; 468 469 #[link_name = "sys_getdents64"] 470 pub fn getdents64(fd: i32, dirp: *mut dirent64, count: usize) -> isize; 471 472 #[link_name = "sys_getaddrinfo"] 473 pub fn getaddrinfo( 474 nodename: *const c_char, 475 servname: *const c_char, 476 hints: *const addrinfo, 477 res: *mut *mut addrinfo, 478 ) -> i32; 479 480 #[link_name = "sys_freeaddrinfo"] 481 pub fn freeaddrinfo(ai: *mut addrinfo); 482 483 #[link_name = "sys_socket"] 484 pub fn socket(domain: i32, ty: i32, protocol: i32) -> i32; 485 486 #[link_name = "sys_bind"] 487 pub fn bind(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32; 488 489 #[link_name = "sys_listen"] 490 pub fn listen(sockfd: i32, backlog: i32) -> i32; 491 492 #[link_name = "sys_accept"] 493 pub fn accept(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32; 494 495 #[link_name = "sys_connect"] 496 pub fn connect(sockfd: i32, addr: *const sockaddr, addrlen: socklen_t) -> i32; 497 498 #[link_name = "sys_recv"] 499 pub fn recv(sockfd: i32, buf: *mut u8, len: usize, flags: i32) -> isize; 500 501 #[link_name = "sys_recvfrom"] 502 pub fn recvfrom( 503 sockfd: i32, 504 buf: *mut c_void, 505 len: usize, 506 flags: i32, 507 addr: *mut sockaddr, 508 addrlen: *mut socklen_t, 509 ) -> isize; 510 511 #[link_name = "sys_send"] 512 pub fn send(sockfd: i32, buf: *const c_void, len: usize, flags: i32) -> isize; 513 514 #[link_name = "sys_sendto"] 515 pub fn sendto( 516 sockfd: i32, 517 buf: *const c_void, 518 len: usize, 519 flags: i32, 520 to: *const sockaddr, 521 tolen: socklen_t, 522 ) -> isize; 523 524 #[link_name = "sys_getpeername"] 525 pub fn getpeername(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32; 526 527 #[link_name = "sys_getsockname"] 528 pub fn getsockname(sockfd: i32, addr: *mut sockaddr, addrlen: *mut socklen_t) -> i32; 529 530 #[link_name = "sys_getsockopt"] 531 pub fn getsockopt( 532 sockfd: i32, 533 level: i32, 534 optname: i32, 535 optval: *mut c_void, 536 optlen: *mut socklen_t, 537 ) -> i32; 538 539 #[link_name = "sys_setsockopt"] 540 pub fn setsockopt( 541 sockfd: i32, 542 level: i32, 543 optname: i32, 544 optval: *const c_void, 545 optlen: socklen_t, 546 ) -> i32; 547 548 #[link_name = "sys_ioctl"] 549 pub fn ioctl(sockfd: i32, cmd: i32, argp: *mut c_void) -> i32; 550 551 #[link_name = "sys_shutdown"] 552 pub fn shutdown(sockfd: i32, how: i32) -> i32; 553 554 #[link_name = "sys_eventfd"] 555 pub fn eventfd(initval: u64, flags: i16) -> i32; 556 557 #[link_name = "sys_poll"] 558 pub fn poll(fds: *mut pollfd, nfds: nfds_t, timeout: i32) -> i32; 559 } 560