| ... | @@ -1 +1,800 @@ | ... | @@ -1 +1,800 @@ |
| 1 | const std = @import("std"); | 1 | const std = @import("std"); |
| | 2 | const sys = std.os.linux; |
| | 3 | const syscall0 = sys.syscall0; |
| | 4 | const syscall1 = sys.syscall1; |
| | 5 | const syscall2 = sys.syscall2; |
| | 6 | const syscall3 = sys.syscall3; |
| | 7 | const syscall4 = sys.syscall4; |
| | 8 | const syscall5 = sys.syscall5; |
| | 9 | const syscall6 = sys.syscall6; |
| | 10 | const errno = @import("errno"); |
| | 11 | |
| | 12 | fn _errno(rc: usize) enum(c_ushort) { ok, _ } { |
| | 13 | const signed: isize = @bitCast(rc); |
| | 14 | const int = if (signed > -4096 and signed < 0) -signed else 0; |
| | 15 | return @enumFromInt(int); |
| | 16 | } |
| | 17 | |
| | 18 | // read |
| | 19 | // ssize_t read(int fd, void buf[.count], size_t count); |
| | 20 | // asmlinkage long sys_read(unsigned int fd, char __user *buf, size_t count); |
| | 21 | pub fn read(fd: c_int, buf: []u8) errno.Error!usize { |
| | 22 | const r = syscall3(.read, fd, buf.ptr, buf.len); |
| | 23 | return switch (_errno(r)) { |
| | 24 | .ok => @intCast(r), |
| | 25 | _ => |c| errno.errorFromInt(c), |
| | 26 | }; |
| | 27 | } |
| | 28 | |
| | 29 | // write |
| | 30 | // ssize_t write(int fd, const void buf[.count], size_t count); |
| | 31 | // asmlinkage long sys_write(unsigned int fd, const char __user *buf, size_t count); |
| | 32 | pub fn write(fd: c_int, buf: []const u8) errno.Error!usize { |
| | 33 | const r = syscall3(.write, fd, buf.ptr, buf.len); |
| | 34 | return switch (_errno(r)) { |
| | 35 | .ok => @intCast(r), |
| | 36 | _ => |c| errno.errorFromInt(c), |
| | 37 | }; |
| | 38 | } |
| | 39 | |
| | 40 | // open |
| | 41 | // int open(const char *pathname, int flags, ... /* mode_t mode */ ); |
| | 42 | |
| | 43 | // close |
| | 44 | // int creat(const char *pathname, mode_t mode); |
| | 45 | |
| | 46 | // stat |
| | 47 | // int stat(const char *restrict pathname, struct stat *restrict statbuf); |
| | 48 | |
| | 49 | // fstat |
| | 50 | // int fstat(int fd, struct stat *statbuf); |
| | 51 | |
| | 52 | // lstat |
| | 53 | // int lstat(const char *restrict pathname, struct stat *restrict statbuf); |
| | 54 | |
| | 55 | // poll |
| | 56 | // int poll(struct pollfd *fds, nfds_t nfds, int timeout); |
| | 57 | |
| | 58 | // lseek |
| | 59 | // off_t lseek(int fd, off_t offset, int whence); |
| | 60 | |
| | 61 | // mmap |
| | 62 | // void *mmap(void addr[.length], size_t length, int prot, int flags, int fd, off_t offset); |
| | 63 | |
| | 64 | // mprotect |
| | 65 | // int mprotect(void addr[.len], size_t len, int prot); |
| | 66 | |
| | 67 | // munmap |
| | 68 | // int munmap(void addr[.length], size_t length); |
| | 69 | |
| | 70 | // brk |
| | 71 | // int brk(void *addr); |
| | 72 | |
| | 73 | // rt_sigaction |
| | 74 | |
| | 75 | // rt_sigprocmask |
| | 76 | |
| | 77 | // rt_sigreturn |
| | 78 | |
| | 79 | // ioctl |
| | 80 | |
| | 81 | // pread64 |
| | 82 | // ssize_t pread(int fd, void buf[.count], size_t count, off_t offset); |
| | 83 | |
| | 84 | // pwrite64 |
| | 85 | // ssize_t pwrite(int fd, const void buf[.count], size_t count, off_t offset); |
| | 86 | |
| | 87 | // readv |
| | 88 | // ssize_t readv(int fd, const struct iovec *iov, int iovcnt); |
| | 89 | |
| | 90 | // writev |
| | 91 | // ssize_t writev(int fd, const struct iovec *iov, int iovcnt); |
| | 92 | |
| | 93 | // access |
| | 94 | // int access(const char *pathname, int mode); |
| | 95 | |
| | 96 | // pipe |
| | 97 | // int pipe(int pipefd[2]); |
| | 98 | |
| | 99 | // select |
| | 100 | // int select(int nfds, fd_set *_Nullable restrict readfds, fd_set *_Nullable restrict writefds, fd_set *_Nullable restrict exceptfds, struct timeval *_Nullable restrict timeout); |
| | 101 | |
| | 102 | // sched_yield |
| | 103 | |
| | 104 | // mremap |
| | 105 | |
| | 106 | // msync |
| | 107 | |
| | 108 | // mincore |
| | 109 | |
| | 110 | // madvise |
| | 111 | |
| | 112 | // shmget |
| | 113 | |
| | 114 | // shmat |
| | 115 | |
| | 116 | // shmctl |
| | 117 | |
| | 118 | // dup |
| | 119 | |
| | 120 | // dup2 |
| | 121 | |
| | 122 | // pause |
| | 123 | |
| | 124 | // nanosleep |
| | 125 | |
| | 126 | // getitimer |
| | 127 | |
| | 128 | // alarm |
| | 129 | |
| | 130 | // setitimer |
| | 131 | |
| | 132 | // getpid |
| | 133 | |
| | 134 | // sendfile |
| | 135 | |
| | 136 | // socket |
| | 137 | |
| | 138 | // connect |
| | 139 | |
| | 140 | // accept |
| | 141 | |
| | 142 | // sendto |
| | 143 | |
| | 144 | // recvfrom |
| | 145 | |
| | 146 | // sendmsg |
| | 147 | |
| | 148 | // recvmsg |
| | 149 | |
| | 150 | // shutdown |
| | 151 | |
| | 152 | // bind |
| | 153 | |
| | 154 | // listen |
| | 155 | |
| | 156 | // getsockname |
| | 157 | |
| | 158 | // getpeername |
| | 159 | |
| | 160 | // socketpair |
| | 161 | |
| | 162 | // setsockopt |
| | 163 | |
| | 164 | // getsockopt |
| | 165 | |
| | 166 | // clone |
| | 167 | |
| | 168 | // fork |
| | 169 | |
| | 170 | // vfork |
| | 171 | |
| | 172 | // execve |
| | 173 | |
| | 174 | // exit |
| | 175 | |
| | 176 | // wait4 |
| | 177 | |
| | 178 | // kill |
| | 179 | |
| | 180 | // uname |
| | 181 | |
| | 182 | // semget |
| | 183 | |
| | 184 | // semop |
| | 185 | |
| | 186 | // semctl |
| | 187 | |
| | 188 | // shmdt |
| | 189 | |
| | 190 | // msgget |
| | 191 | |
| | 192 | // msgsnd |
| | 193 | |
| | 194 | // msgrcv |
| | 195 | |
| | 196 | // msgctl |
| | 197 | |
| | 198 | // fcntl |
| | 199 | |
| | 200 | // flock |
| | 201 | |
| | 202 | // fsync |
| | 203 | |
| | 204 | // fdatasync |
| | 205 | |
| | 206 | // truncate |
| | 207 | |
| | 208 | // ftruncate |
| | 209 | |
| | 210 | // getdents |
| | 211 | |
| | 212 | // getcwd |
| | 213 | |
| | 214 | // chdir |
| | 215 | |
| | 216 | // fchdir |
| | 217 | |
| | 218 | // rename |
| | 219 | |
| | 220 | // mkdir |
| | 221 | |
| | 222 | // rmdir |
| | 223 | |
| | 224 | // creat |
| | 225 | |
| | 226 | // link |
| | 227 | |
| | 228 | // unlink |
| | 229 | |
| | 230 | // symlink |
| | 231 | |
| | 232 | // readlink |
| | 233 | |
| | 234 | // chmod |
| | 235 | |
| | 236 | // fchmod |
| | 237 | |
| | 238 | // chown |
| | 239 | |
| | 240 | // fchown |
| | 241 | |
| | 242 | // lchown |
| | 243 | |
| | 244 | // umask |
| | 245 | |
| | 246 | // gettimeofday |
| | 247 | |
| | 248 | // getrlimit |
| | 249 | |
| | 250 | // getrusage |
| | 251 | |
| | 252 | // sysinfo |
| | 253 | |
| | 254 | // times |
| | 255 | |
| | 256 | // ptrace |
| | 257 | |
| | 258 | // getuid |
| | 259 | |
| | 260 | // syslog |
| | 261 | |
| | 262 | // getgid |
| | 263 | |
| | 264 | // setuid |
| | 265 | |
| | 266 | // setgid |
| | 267 | |
| | 268 | // geteuid |
| | 269 | |
| | 270 | // getegid |
| | 271 | |
| | 272 | // setpgid |
| | 273 | |
| | 274 | // getppid |
| | 275 | |
| | 276 | // getpgrp |
| | 277 | |
| | 278 | // setsid |
| | 279 | |
| | 280 | // setreuid |
| | 281 | |
| | 282 | // setregid |
| | 283 | |
| | 284 | // getgroups |
| | 285 | |
| | 286 | // setgroups |
| | 287 | |
| | 288 | // setresuid |
| | 289 | |
| | 290 | // getresuid |
| | 291 | |
| | 292 | // setresgid |
| | 293 | |
| | 294 | // getresgid |
| | 295 | |
| | 296 | // getpgid |
| | 297 | |
| | 298 | // setfsuid |
| | 299 | |
| | 300 | // setfsgid |
| | 301 | |
| | 302 | // getsid |
| | 303 | |
| | 304 | // capget |
| | 305 | |
| | 306 | // capset |
| | 307 | |
| | 308 | // rt_sigpending |
| | 309 | |
| | 310 | // rt_sigtimedwait |
| | 311 | |
| | 312 | // rt_sigqueueinfo |
| | 313 | |
| | 314 | // rt_sigsuspend |
| | 315 | |
| | 316 | // sigaltstack |
| | 317 | |
| | 318 | // utime |
| | 319 | |
| | 320 | // mknod |
| | 321 | |
| | 322 | // uselib |
| | 323 | |
| | 324 | // personality |
| | 325 | |
| | 326 | // ustat |
| | 327 | |
| | 328 | // statfs |
| | 329 | |
| | 330 | // fstatfs |
| | 331 | |
| | 332 | // sysfs |
| | 333 | |
| | 334 | // getpriority |
| | 335 | |
| | 336 | // setpriority |
| | 337 | |
| | 338 | // sched_setparam |
| | 339 | |
| | 340 | // sched_getparam |
| | 341 | |
| | 342 | // sched_setscheduler |
| | 343 | |
| | 344 | // sched_getscheduler |
| | 345 | |
| | 346 | // sched_get_priority_max |
| | 347 | |
| | 348 | // sched_get_priority_min |
| | 349 | |
| | 350 | // sched_rr_get_interval |
| | 351 | |
| | 352 | // mlock |
| | 353 | |
| | 354 | // munlock |
| | 355 | |
| | 356 | // mlockall |
| | 357 | |
| | 358 | // munlockall |
| | 359 | |
| | 360 | // vhangup |
| | 361 | |
| | 362 | // modify_ldt |
| | 363 | |
| | 364 | // pivot_root |
| | 365 | |
| | 366 | // _sysctl |
| | 367 | |
| | 368 | // prctl |
| | 369 | |
| | 370 | // arch_prctl |
| | 371 | |
| | 372 | // adjtimex |
| | 373 | |
| | 374 | // setrlimit |
| | 375 | |
| | 376 | // chroot |
| | 377 | |
| | 378 | // sync |
| | 379 | |
| | 380 | // acct |
| | 381 | |
| | 382 | // settimeofday |
| | 383 | |
| | 384 | // mount |
| | 385 | |
| | 386 | // umount2 |
| | 387 | |
| | 388 | // swapon |
| | 389 | |
| | 390 | // swapoff |
| | 391 | |
| | 392 | // reboot |
| | 393 | |
| | 394 | // sethostname |
| | 395 | |
| | 396 | // setdomainname |
| | 397 | |
| | 398 | // iopl |
| | 399 | |
| | 400 | // ioperm |
| | 401 | |
| | 402 | // create_module |
| | 403 | |
| | 404 | // init_module |
| | 405 | |
| | 406 | // delete_module |
| | 407 | |
| | 408 | // get_kernel_syms |
| | 409 | |
| | 410 | // query_module |
| | 411 | |
| | 412 | // quotactl |
| | 413 | |
| | 414 | // nfsservctl |
| | 415 | |
| | 416 | // getpmsg |
| | 417 | |
| | 418 | // putpmsg |
| | 419 | |
| | 420 | // afs_syscall |
| | 421 | |
| | 422 | // tuxcall |
| | 423 | |
| | 424 | // security |
| | 425 | |
| | 426 | // gettid |
| | 427 | |
| | 428 | // readahead |
| | 429 | |
| | 430 | // setxattr |
| | 431 | |
| | 432 | // lsetxattr |
| | 433 | |
| | 434 | // fsetxattr |
| | 435 | |
| | 436 | // getxattr |
| | 437 | |
| | 438 | // lgetxattr |
| | 439 | |
| | 440 | // fgetxattr |
| | 441 | |
| | 442 | // listxattr |
| | 443 | |
| | 444 | // llistxattr |
| | 445 | |
| | 446 | // flistxattr |
| | 447 | |
| | 448 | // removexattr |
| | 449 | |
| | 450 | // lremovexattr |
| | 451 | |
| | 452 | // fremovexattr |
| | 453 | |
| | 454 | // tkill |
| | 455 | |
| | 456 | // time |
| | 457 | |
| | 458 | // futex |
| | 459 | |
| | 460 | // sched_setaffinity |
| | 461 | |
| | 462 | // sched_getaffinity |
| | 463 | |
| | 464 | // set_thread_area |
| | 465 | |
| | 466 | // io_setup |
| | 467 | |
| | 468 | // io_destroy |
| | 469 | |
| | 470 | // io_getevents |
| | 471 | |
| | 472 | // io_submit |
| | 473 | |
| | 474 | // io_cancel |
| | 475 | |
| | 476 | // get_thread_area |
| | 477 | |
| | 478 | // lookup_dcookie |
| | 479 | |
| | 480 | // epoll_create |
| | 481 | |
| | 482 | // epoll_ctl_old |
| | 483 | |
| | 484 | // epoll_wait_old |
| | 485 | |
| | 486 | // remap_file_pages |
| | 487 | |
| | 488 | // getdents64 |
| | 489 | |
| | 490 | // set_tid_address |
| | 491 | |
| | 492 | // restart_syscall |
| | 493 | |
| | 494 | // semtimedop |
| | 495 | |
| | 496 | // fadvise64 |
| | 497 | |
| | 498 | // timer_create |
| | 499 | |
| | 500 | // timer_settime |
| | 501 | |
| | 502 | // timer_gettime |
| | 503 | |
| | 504 | // timer_getoverrun |
| | 505 | |
| | 506 | // timer_delete |
| | 507 | |
| | 508 | // clock_settime |
| | 509 | |
| | 510 | // clock_gettime |
| | 511 | |
| | 512 | // clock_getres |
| | 513 | |
| | 514 | // clock_nanosleep |
| | 515 | |
| | 516 | // exit_group |
| | 517 | |
| | 518 | // epoll_wait |
| | 519 | |
| | 520 | // epoll_ctl |
| | 521 | |
| | 522 | // tgkill |
| | 523 | |
| | 524 | // utimes |
| | 525 | |
| | 526 | // vserver |
| | 527 | |
| | 528 | // mbind |
| | 529 | |
| | 530 | // set_mempolicy |
| | 531 | |
| | 532 | // get_mempolicy |
| | 533 | |
| | 534 | // mq_open |
| | 535 | |
| | 536 | // mq_unlink |
| | 537 | |
| | 538 | // mq_timedsend |
| | 539 | |
| | 540 | // mq_timedreceive |
| | 541 | |
| | 542 | // mq_notify |
| | 543 | |
| | 544 | // mq_getsetattr |
| | 545 | |
| | 546 | // kexec_load |
| | 547 | |
| | 548 | // waitid |
| | 549 | |
| | 550 | // add_key |
| | 551 | |
| | 552 | // request_key |
| | 553 | |
| | 554 | // keyctl |
| | 555 | |
| | 556 | // ioprio_set |
| | 557 | |
| | 558 | // ioprio_get |
| | 559 | |
| | 560 | // inotify_init |
| | 561 | |
| | 562 | // inotify_add_watch |
| | 563 | |
| | 564 | // inotify_rm_watch |
| | 565 | |
| | 566 | // migrate_pages |
| | 567 | |
| | 568 | // openat |
| | 569 | // int openat(int dirfd, const char *pathname, int flags, ... /* mode_t mode */ ); |
| | 570 | |
| | 571 | // mkdirat |
| | 572 | |
| | 573 | // mknodat |
| | 574 | |
| | 575 | // fchownat |
| | 576 | |
| | 577 | // futimesat |
| | 578 | |
| | 579 | // fstatat64 |
| | 580 | // int fstatat(int dirfd, const char *restrict pathname, struct stat *restrict statbuf, int flags); |
| | 581 | |
| | 582 | // unlinkat |
| | 583 | |
| | 584 | // renameat |
| | 585 | |
| | 586 | // linkat |
| | 587 | |
| | 588 | // symlinkat |
| | 589 | |
| | 590 | // readlinkat |
| | 591 | |
| | 592 | // fchmodat |
| | 593 | |
| | 594 | // faccessat |
| | 595 | // int faccessat(int dirfd, const char *pathname, int mode, int flags); |
| | 596 | |
| | 597 | // pselect6 |
| | 598 | // int pselect(int nfds, fd_set *_Nullable restrict readfds, fd_set *_Nullable restrict writefds, fd_set *_Nullable restrict exceptfds, const struct timespec *_Nullable restrict timeout, const sigset_t *_Nullable restrict sigmask); |
| | 599 | |
| | 600 | // ppoll |
| | 601 | // int ppoll(struct pollfd *fds, nfds_t nfds, const struct timespec *_Nullable tmo_p, const sigset_t *_Nullable sigmask); |
| | 602 | |
| | 603 | // unshare |
| | 604 | |
| | 605 | // set_robust_list |
| | 606 | |
| | 607 | // get_robust_list |
| | 608 | |
| | 609 | // splice |
| | 610 | |
| | 611 | // tee |
| | 612 | |
| | 613 | // sync_file_range |
| | 614 | |
| | 615 | // vmsplice |
| | 616 | |
| | 617 | // move_pages |
| | 618 | |
| | 619 | // utimensat |
| | 620 | |
| | 621 | // epoll_pwait |
| | 622 | |
| | 623 | // signalfd |
| | 624 | |
| | 625 | // timerfd_create |
| | 626 | |
| | 627 | // eventfd |
| | 628 | |
| | 629 | // fallocate |
| | 630 | |
| | 631 | // timerfd_settime |
| | 632 | |
| | 633 | // timerfd_gettime |
| | 634 | |
| | 635 | // accept4 |
| | 636 | |
| | 637 | // signalfd4 |
| | 638 | |
| | 639 | // eventfd2 |
| | 640 | |
| | 641 | // epoll_create1 |
| | 642 | |
| | 643 | // dup3 |
| | 644 | |
| | 645 | // pipe2 |
| | 646 | // int pipe2(int pipefd[2], int flags); |
| | 647 | |
| | 648 | // inotify_init1 |
| | 649 | |
| | 650 | // preadv |
| | 651 | // ssize_t preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset); |
| | 652 | |
| | 653 | // pwritev |
| | 654 | // ssize_t pwritev(int fd, const struct iovec *iov, int iovcnt, off_t offset); |
| | 655 | |
| | 656 | // rt_tgsigqueueinfo |
| | 657 | |
| | 658 | // perf_event_open |
| | 659 | |
| | 660 | // recvmmsg |
| | 661 | |
| | 662 | // fanotify_init |
| | 663 | |
| | 664 | // fanotify_mark |
| | 665 | |
| | 666 | // prlimit64 |
| | 667 | |
| | 668 | // name_to_handle_at |
| | 669 | |
| | 670 | // open_by_handle_at |
| | 671 | |
| | 672 | // clock_adjtime |
| | 673 | |
| | 674 | // syncfs |
| | 675 | |
| | 676 | // sendmmsg |
| | 677 | |
| | 678 | // setns |
| | 679 | |
| | 680 | // getcpu |
| | 681 | |
| | 682 | // process_vm_readv |
| | 683 | |
| | 684 | // process_vm_writev |
| | 685 | |
| | 686 | // kcmp |
| | 687 | |
| | 688 | // finit_module |
| | 689 | |
| | 690 | // sched_setattr |
| | 691 | |
| | 692 | // sched_getattr |
| | 693 | |
| | 694 | // renameat2 |
| | 695 | |
| | 696 | // seccomp |
| | 697 | |
| | 698 | // getrandom |
| | 699 | |
| | 700 | // memfd_create |
| | 701 | |
| | 702 | // kexec_file_load |
| | 703 | |
| | 704 | // bpf |
| | 705 | |
| | 706 | // execveat |
| | 707 | |
| | 708 | // userfaultfd |
| | 709 | |
| | 710 | // membarrier |
| | 711 | |
| | 712 | // mlock2 |
| | 713 | |
| | 714 | // copy_file_range |
| | 715 | |
| | 716 | // preadv2 |
| | 717 | // ssize_t preadv2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
| | 718 | |
| | 719 | // pwritev2 |
| | 720 | // ssize_t pwritev2(int fd, const struct iovec *iov, int iovcnt, off_t offset, int flags); |
| | 721 | |
| | 722 | // pkey_mprotect |
| | 723 | // int pkey_mprotect(void addr[.len], size_t len, int prot, int pkey); |
| | 724 | |
| | 725 | // pkey_alloc |
| | 726 | |
| | 727 | // pkey_free |
| | 728 | |
| | 729 | // statx |
| | 730 | |
| | 731 | // io_pgetevents |
| | 732 | |
| | 733 | // rseq |
| | 734 | |
| | 735 | // pidfd_send_signal |
| | 736 | |
| | 737 | // io_uring_setup |
| | 738 | |
| | 739 | // io_uring_enter |
| | 740 | |
| | 741 | // io_uring_register |
| | 742 | |
| | 743 | // open_tree |
| | 744 | |
| | 745 | // move_mount |
| | 746 | |
| | 747 | // fsopen |
| | 748 | |
| | 749 | // fsconfig |
| | 750 | |
| | 751 | // fsmount |
| | 752 | |
| | 753 | // fspick |
| | 754 | |
| | 755 | // pidfd_open |
| | 756 | |
| | 757 | // clone3 |
| | 758 | |
| | 759 | // close_range |
| | 760 | |
| | 761 | // openat2 |
| | 762 | // int openat2(int dirfd, const char *pathname, const struct open_how *how, size_t size); |
| | 763 | |
| | 764 | // pidfd_getfd |
| | 765 | |
| | 766 | // faccessat2 |
| | 767 | |
| | 768 | // process_madvise |
| | 769 | |
| | 770 | // epoll_pwait2 |
| | 771 | |
| | 772 | // mount_setattr |
| | 773 | |
| | 774 | // quotactl_fd |
| | 775 | |
| | 776 | // landlock_create_ruleset |
| | 777 | |
| | 778 | // landlock_add_rule |
| | 779 | |
| | 780 | // landlock_restrict_self |
| | 781 | |
| | 782 | // memfd_secret |
| | 783 | |
| | 784 | // process_mrelease |
| | 785 | |
| | 786 | // futex_waitv |
| | 787 | |
| | 788 | // set_mempolicy_home_node |
| | 789 | |
| | 790 | // cachestat |
| | 791 | |
| | 792 | // fchmodat2 |
| | 793 | |
| | 794 | // map_shadow_stack |
| | 795 | |
| | 796 | // futex_wake |
| | 797 | |
| | 798 | // futex_wait |
| | 799 | |
| | 800 | // futex_requeue |