| ... | ... | @@ -0,0 +1,419 @@ |
| 1 | const std = @import("../../index.zig"); |
| 2 | const linux = std.os.linux; |
| 3 | const socklen_t = linux.socklen_t; |
| 4 | const iovec = linux.iovec; |
| 5 | |
| 6 | pub const SYS_io_setup = 0; |
| 7 | pub const SYS_io_destroy = 1; |
| 8 | pub const SYS_io_submit = 2; |
| 9 | pub const SYS_io_cancel = 3; |
| 10 | pub const SYS_io_getevents = 4; |
| 11 | pub const SYS_setxattr = 5; |
| 12 | pub const SYS_lsetxattr = 6; |
| 13 | pub const SYS_fsetxattr = 7; |
| 14 | pub const SYS_getxattr = 8; |
| 15 | pub const SYS_lgetxattr = 9; |
| 16 | pub const SYS_fgetxattr = 10; |
| 17 | pub const SYS_listxattr = 11; |
| 18 | pub const SYS_llistxattr = 12; |
| 19 | pub const SYS_flistxattr = 13; |
| 20 | pub const SYS_removexattr = 14; |
| 21 | pub const SYS_lremovexattr = 15; |
| 22 | pub const SYS_fremovexattr = 16; |
| 23 | pub const SYS_getcwd = 17; |
| 24 | pub const SYS_lookup_dcookie = 18; |
| 25 | pub const SYS_eventfd2 = 19; |
| 26 | pub const SYS_epoll_create1 = 20; |
| 27 | pub const SYS_epoll_ctl = 21; |
| 28 | pub const SYS_epoll_pwait = 22; |
| 29 | pub const SYS_dup = 23; |
| 30 | pub const SYS_dup3 = 24; |
| 31 | pub const SYS_fcntl = 25; |
| 32 | pub const SYS_inotify_init1 = 26; |
| 33 | pub const SYS_inotify_add_watch = 27; |
| 34 | pub const SYS_inotify_rm_watch = 28; |
| 35 | pub const SYS_ioctl = 29; |
| 36 | pub const SYS_ioprio_set = 30; |
| 37 | pub const SYS_ioprio_get = 31; |
| 38 | pub const SYS_flock = 32; |
| 39 | pub const SYS_mknodat = 33; |
| 40 | pub const SYS_mkdirat = 34; |
| 41 | pub const SYS_unlinkat = 35; |
| 42 | pub const SYS_symlinkat = 36; |
| 43 | pub const SYS_linkat = 37; |
| 44 | pub const SYS_renameat = 38; |
| 45 | pub const SYS_umount2 = 39; |
| 46 | pub const SYS_mount = 40; |
| 47 | pub const SYS_pivot_root = 41; |
| 48 | pub const SYS_nfsservctl = 42; |
| 49 | pub const SYS_statfs = 43; |
| 50 | pub const SYS_fstatfs = 44; |
| 51 | pub const SYS_truncate = 45; |
| 52 | pub const SYS_ftruncate = 46; |
| 53 | pub const SYS_fallocate = 47; |
| 54 | pub const SYS_faccessat = 48; |
| 55 | pub const SYS_chdir = 49; |
| 56 | pub const SYS_fchdir = 50; |
| 57 | pub const SYS_chroot = 51; |
| 58 | pub const SYS_fchmod = 52; |
| 59 | pub const SYS_fchmodat = 53; |
| 60 | pub const SYS_fchownat = 54; |
| 61 | pub const SYS_fchown = 55; |
| 62 | pub const SYS_openat = 56; |
| 63 | pub const SYS_close = 57; |
| 64 | pub const SYS_vhangup = 58; |
| 65 | pub const SYS_pipe2 = 59; |
| 66 | pub const SYS_quotactl = 60; |
| 67 | pub const SYS_getdents64 = 61; |
| 68 | pub const SYS_lseek = 62; |
| 69 | pub const SYS_read = 63; |
| 70 | pub const SYS_write = 64; |
| 71 | pub const SYS_readv = 65; |
| 72 | pub const SYS_writev = 66; |
| 73 | pub const SYS_pread64 = 67; |
| 74 | pub const SYS_pwrite64 = 68; |
| 75 | pub const SYS_preadv = 69; |
| 76 | pub const SYS_pwritev = 70; |
| 77 | pub const SYS_pselect6 = 72; |
| 78 | pub const SYS_ppoll = 73; |
| 79 | pub const SYS_signalfd4 = 74; |
| 80 | pub const SYS_vmsplice = 75; |
| 81 | pub const SYS_splice = 76; |
| 82 | pub const SYS_tee = 77; |
| 83 | pub const SYS_readlinkat = 78; |
| 84 | pub const SYS_fstatat = 79; |
| 85 | pub const SYS_fstat = 80; |
| 86 | pub const SYS_sync = 81; |
| 87 | pub const SYS_fsync = 82; |
| 88 | pub const SYS_fdatasync = 83; |
| 89 | pub const SYS_sync_file_range2 = 84; |
| 90 | pub const SYS_sync_file_range = 84; |
| 91 | pub const SYS_timerfd_create = 85; |
| 92 | pub const SYS_timerfd_settime = 86; |
| 93 | pub const SYS_timerfd_gettime = 87; |
| 94 | pub const SYS_utimensat = 88; |
| 95 | pub const SYS_acct = 89; |
| 96 | pub const SYS_capget = 90; |
| 97 | pub const SYS_capset = 91; |
| 98 | pub const SYS_personality = 92; |
| 99 | pub const SYS_exit = 93; |
| 100 | pub const SYS_exit_group = 94; |
| 101 | pub const SYS_waitid = 95; |
| 102 | pub const SYS_set_tid_address = 96; |
| 103 | pub const SYS_unshare = 97; |
| 104 | pub const SYS_futex = 98; |
| 105 | pub const SYS_set_robust_list = 99; |
| 106 | pub const SYS_get_robust_list = 100; |
| 107 | pub const SYS_nanosleep = 101; |
| 108 | pub const SYS_getitimer = 102; |
| 109 | pub const SYS_setitimer = 103; |
| 110 | pub const SYS_kexec_load = 104; |
| 111 | pub const SYS_init_module = 105; |
| 112 | pub const SYS_delete_module = 106; |
| 113 | pub const SYS_timer_create = 107; |
| 114 | pub const SYS_timer_gettime = 108; |
| 115 | pub const SYS_timer_getoverrun = 109; |
| 116 | pub const SYS_timer_settime = 110; |
| 117 | pub const SYS_timer_delete = 111; |
| 118 | pub const SYS_clock_settime = 112; |
| 119 | pub const SYS_clock_gettime = 113; |
| 120 | pub const SYS_clock_getres = 114; |
| 121 | pub const SYS_clock_nanosleep = 115; |
| 122 | pub const SYS_syslog = 116; |
| 123 | pub const SYS_ptrace = 117; |
| 124 | pub const SYS_sched_setparam = 118; |
| 125 | pub const SYS_sched_setscheduler = 119; |
| 126 | pub const SYS_sched_getscheduler = 120; |
| 127 | pub const SYS_sched_getparam = 121; |
| 128 | pub const SYS_sched_setaffinity = 122; |
| 129 | pub const SYS_sched_getaffinity = 123; |
| 130 | pub const SYS_sched_yield = 124; |
| 131 | pub const SYS_sched_get_priority_max = 125; |
| 132 | pub const SYS_sched_get_priority_min = 126; |
| 133 | pub const SYS_sched_rr_get_interval = 127; |
| 134 | pub const SYS_restart_syscall = 128; |
| 135 | pub const SYS_kill = 129; |
| 136 | pub const SYS_tkill = 130; |
| 137 | pub const SYS_tgkill = 131; |
| 138 | pub const SYS_sigaltstack = 132; |
| 139 | pub const SYS_rt_sigsuspend = 133; |
| 140 | pub const SYS_rt_sigaction = 134; |
| 141 | pub const SYS_rt_sigprocmask = 135; |
| 142 | pub const SYS_rt_sigpending = 136; |
| 143 | pub const SYS_rt_sigtimedwait = 137; |
| 144 | pub const SYS_rt_sigqueueinfo = 138; |
| 145 | pub const SYS_rt_sigreturn = 139; |
| 146 | pub const SYS_setpriority = 140; |
| 147 | pub const SYS_getpriority = 141; |
| 148 | pub const SYS_reboot = 142; |
| 149 | pub const SYS_setregid = 143; |
| 150 | pub const SYS_setgid = 144; |
| 151 | pub const SYS_setreuid = 145; |
| 152 | pub const SYS_setuid = 146; |
| 153 | pub const SYS_setresuid = 147; |
| 154 | pub const SYS_getresuid = 148; |
| 155 | pub const SYS_setresgid = 149; |
| 156 | pub const SYS_getresgid = 150; |
| 157 | pub const SYS_setfsuid = 151; |
| 158 | pub const SYS_setfsgid = 152; |
| 159 | pub const SYS_times = 153; |
| 160 | pub const SYS_setpgid = 154; |
| 161 | pub const SYS_getpgid = 155; |
| 162 | pub const SYS_getsid = 156; |
| 163 | pub const SYS_setsid = 157; |
| 164 | pub const SYS_getgroups = 158; |
| 165 | pub const SYS_setgroups = 159; |
| 166 | pub const SYS_uname = 160; |
| 167 | pub const SYS_sethostname = 161; |
| 168 | pub const SYS_setdomainname = 162; |
| 169 | pub const SYS_getrlimit = 163; |
| 170 | pub const SYS_setrlimit = 164; |
| 171 | pub const SYS_getrusage = 165; |
| 172 | pub const SYS_umask = 166; |
| 173 | pub const SYS_prctl = 167; |
| 174 | pub const SYS_getcpu = 168; |
| 175 | pub const SYS_gettimeofday = 169; |
| 176 | pub const SYS_settimeofday = 170; |
| 177 | pub const SYS_adjtimex = 171; |
| 178 | pub const SYS_getpid = 172; |
| 179 | pub const SYS_getppid = 173; |
| 180 | pub const SYS_getuid = 174; |
| 181 | pub const SYS_geteuid = 175; |
| 182 | pub const SYS_getgid = 176; |
| 183 | pub const SYS_getegid = 177; |
| 184 | pub const SYS_gettid = 178; |
| 185 | pub const SYS_sysinfo = 179; |
| 186 | pub const SYS_mq_open = 180; |
| 187 | pub const SYS_mq_unlink = 181; |
| 188 | pub const SYS_mq_timedsend = 182; |
| 189 | pub const SYS_mq_timedreceive = 183; |
| 190 | pub const SYS_mq_notify = 184; |
| 191 | pub const SYS_mq_getsetattr = 185; |
| 192 | pub const SYS_msgget = 186; |
| 193 | pub const SYS_msgctl = 187; |
| 194 | pub const SYS_msgrcv = 188; |
| 195 | pub const SYS_msgsnd = 189; |
| 196 | pub const SYS_semget = 190; |
| 197 | pub const SYS_semctl = 191; |
| 198 | pub const SYS_semtimedop = 192; |
| 199 | pub const SYS_semop = 193; |
| 200 | pub const SYS_shmget = 194; |
| 201 | pub const SYS_shmctl = 195; |
| 202 | pub const SYS_shmat = 196; |
| 203 | pub const SYS_shmdt = 197; |
| 204 | pub const SYS_socket = 198; |
| 205 | pub const SYS_socketpair = 199; |
| 206 | pub const SYS_bind = 200; |
| 207 | pub const SYS_listen = 201; |
| 208 | pub const SYS_accept = 202; |
| 209 | pub const SYS_connect = 203; |
| 210 | pub const SYS_getsockname = 204; |
| 211 | pub const SYS_getpeername = 205; |
| 212 | pub const SYS_sendto = 206; |
| 213 | pub const SYS_recvfrom = 207; |
| 214 | pub const SYS_setsockopt = 208; |
| 215 | pub const SYS_getsockopt = 209; |
| 216 | pub const SYS_shutdown = 210; |
| 217 | pub const SYS_sendmsg = 211; |
| 218 | pub const SYS_recvmsg = 212; |
| 219 | pub const SYS_readahead = 213; |
| 220 | pub const SYS_brk = 214; |
| 221 | pub const SYS_munmap = 215; |
| 222 | pub const SYS_mremap = 216; |
| 223 | pub const SYS_add_key = 217; |
| 224 | pub const SYS_request_key = 218; |
| 225 | pub const SYS_keyctl = 219; |
| 226 | pub const SYS_clone = 220; |
| 227 | pub const SYS_execve = 221; |
| 228 | pub const SYS_mmap = 222; |
| 229 | pub const SYS_fadvise64 = 223; |
| 230 | pub const SYS_swapon = 224; |
| 231 | pub const SYS_swapoff = 225; |
| 232 | pub const SYS_mprotect = 226; |
| 233 | pub const SYS_msync = 227; |
| 234 | pub const SYS_mlock = 228; |
| 235 | pub const SYS_munlock = 229; |
| 236 | pub const SYS_mlockall = 230; |
| 237 | pub const SYS_munlockall = 231; |
| 238 | pub const SYS_mincore = 232; |
| 239 | pub const SYS_madvise = 233; |
| 240 | pub const SYS_remap_file_pages = 234; |
| 241 | pub const SYS_mbind = 235; |
| 242 | pub const SYS_get_mempolicy = 236; |
| 243 | pub const SYS_set_mempolicy = 237; |
| 244 | pub const SYS_migrate_pages = 238; |
| 245 | pub const SYS_move_pages = 239; |
| 246 | pub const SYS_rt_tgsigqueueinfo = 240; |
| 247 | pub const SYS_perf_event_open = 241; |
| 248 | pub const SYS_accept4 = 242; |
| 249 | pub const SYS_recvmmsg = 243; |
| 250 | pub const SYS_arch_specific_syscall = 244; |
| 251 | pub const SYS_wait4 = 260; |
| 252 | pub const SYS_prlimit64 = 261; |
| 253 | pub const SYS_fanotify_init = 262; |
| 254 | pub const SYS_fanotify_mark = 263; |
| 255 | pub const SYS_clock_adjtime = 266; |
| 256 | pub const SYS_syncfs = 267; |
| 257 | pub const SYS_setns = 268; |
| 258 | pub const SYS_sendmmsg = 269; |
| 259 | pub const SYS_process_vm_readv = 270; |
| 260 | pub const SYS_process_vm_writev = 271; |
| 261 | pub const SYS_kcmp = 272; |
| 262 | pub const SYS_finit_module = 273; |
| 263 | pub const SYS_sched_setattr = 274; |
| 264 | pub const SYS_sched_getattr = 275; |
| 265 | pub const SYS_renameat2 = 276; |
| 266 | pub const SYS_seccomp = 277; |
| 267 | pub const SYS_getrandom = 278; |
| 268 | pub const SYS_memfd_create = 279; |
| 269 | pub const SYS_bpf = 280; |
| 270 | pub const SYS_execveat = 281; |
| 271 | pub const SYS_userfaultfd = 282; |
| 272 | pub const SYS_membarrier = 283; |
| 273 | pub const SYS_mlock2 = 284; |
| 274 | pub const SYS_copy_file_range = 285; |
| 275 | pub const SYS_preadv2 = 286; |
| 276 | pub const SYS_pwritev2 = 287; |
| 277 | pub const SYS_pkey_mprotect = 288; |
| 278 | pub const SYS_pkey_alloc = 289; |
| 279 | pub const SYS_pkey_free = 290; |
| 280 | pub const SYS_statx = 291; |
| 281 | pub const SYS_io_pgetevents = 292; |
| 282 | pub const SYS_syscalls = 293; |
| 283 | |
| 284 | pub const VDSO_USEFUL = true; |
| 285 | pub const VDSO_CGT_SYM = "__vdso_clock_gettime"; |
| 286 | pub const VDSO_CGT_VER = "LINUX_2.6"; |
| 287 | pub const VDSO_GETCPU_SYM = "__vdso_getcpu"; |
| 288 | pub const VDSO_GETCPU_VER = "LINUX_2.6"; |
| 289 | |
| 290 | pub fn syscall0(number: usize) usize { |
| 291 | return asm volatile ("svc #0" |
| 292 | : [ret] "={x0}" (-> usize) |
| 293 | : [number] "{x8}" (number) |
| 294 | ); |
| 295 | } |
| 296 | |
| 297 | pub fn syscall1(number: usize, arg1: usize) usize { |
| 298 | return asm volatile ("svc #0" |
| 299 | : [ret] "={x0}" (-> usize) |
| 300 | : [number] "{x8}" (number), |
| 301 | [arg1] "{x0}" (arg1) |
| 302 | ); |
| 303 | } |
| 304 | |
| 305 | pub fn syscall2(number: usize, arg1: usize, arg2: usize) usize { |
| 306 | return asm volatile ("svc #0" |
| 307 | : [ret] "={x0}" (-> usize) |
| 308 | : [number] "{x8}" (number), |
| 309 | [arg1] "{x0}" (arg1), |
| 310 | [arg2] "{x1}" (arg2) |
| 311 | ); |
| 312 | } |
| 313 | |
| 314 | pub fn syscall3(number: usize, arg1: usize, arg2: usize, arg3: usize) usize { |
| 315 | return asm volatile ("svc #0" |
| 316 | : [ret] "={x0}" (-> usize) |
| 317 | : [number] "{x8}" (number), |
| 318 | [arg1] "{x0}" (arg1), |
| 319 | [arg2] "{x1}" (arg2), |
| 320 | [arg3] "{x2}" (arg3) |
| 321 | ); |
| 322 | } |
| 323 | |
| 324 | pub fn syscall4(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize) usize { |
| 325 | return asm volatile ("svc #0" |
| 326 | : [ret] "={x0}" (-> usize) |
| 327 | : [number] "{x8}" (number), |
| 328 | [arg1] "{x0}" (arg1), |
| 329 | [arg2] "{x1}" (arg2), |
| 330 | [arg3] "{x2}" (arg3), |
| 331 | [arg4] "{x3}" (arg4) |
| 332 | ); |
| 333 | } |
| 334 | |
| 335 | pub fn syscall5(number: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) usize { |
| 336 | return asm volatile ("svc #0" |
| 337 | : [ret] "={x0}" (-> usize) |
| 338 | : [number] "{x8}" (number), |
| 339 | [arg1] "{x0}" (arg1), |
| 340 | [arg2] "{x1}" (arg2), |
| 341 | [arg3] "{x2}" (arg3), |
| 342 | [arg4] "{x3}" (arg4), |
| 343 | [arg5] "{x4}" (arg5) |
| 344 | ); |
| 345 | } |
| 346 | |
| 347 | pub fn syscall6( |
| 348 | number: usize, |
| 349 | arg1: usize, |
| 350 | arg2: usize, |
| 351 | arg3: usize, |
| 352 | arg4: usize, |
| 353 | arg5: usize, |
| 354 | arg6: usize, |
| 355 | ) usize { |
| 356 | return asm volatile ("svc #0" |
| 357 | : [ret] "={x0}" (-> usize) |
| 358 | : [number] "{x8}" (number), |
| 359 | [arg1] "{x0}" (arg1), |
| 360 | [arg2] "{x1}" (arg2), |
| 361 | [arg3] "{x2}" (arg3), |
| 362 | [arg4] "{x3}" (arg4), |
| 363 | [arg5] "{x4}" (arg5), |
| 364 | [arg6] "{x5}" (arg6) |
| 365 | ); |
| 366 | } |
| 367 | |
| 368 | /// This matches the libc clone function. |
| 369 | pub extern fn clone(func: extern fn (arg: usize) u8, stack: usize, flags: usize, arg: usize, ptid: *i32, tls: usize, ctid: *i32) usize; |
| 370 | |
| 371 | pub const msghdr = extern struct { |
| 372 | msg_name: *u8, |
| 373 | msg_namelen: socklen_t, |
| 374 | msg_iov: *iovec, |
| 375 | msg_iovlen: i32, |
| 376 | __pad1: i32, |
| 377 | msg_control: *u8, |
| 378 | msg_controllen: socklen_t, |
| 379 | __pad2: socklen_t, |
| 380 | msg_flags: i32, |
| 381 | }; |
| 382 | |
| 383 | /// Renamed to Stat to not conflict with the stat function. |
| 384 | pub const Stat = extern struct { |
| 385 | dev: u64, |
| 386 | ino: u64, |
| 387 | nlink: usize, |
| 388 | |
| 389 | mode: u32, |
| 390 | uid: u32, |
| 391 | gid: u32, |
| 392 | __pad0: u32, |
| 393 | rdev: u64, |
| 394 | size: i64, |
| 395 | blksize: isize, |
| 396 | blocks: i64, |
| 397 | |
| 398 | atim: timespec, |
| 399 | mtim: timespec, |
| 400 | ctim: timespec, |
| 401 | __unused: [3]isize, |
| 402 | }; |
| 403 | |
| 404 | pub const timespec = extern struct { |
| 405 | tv_sec: isize, |
| 406 | tv_nsec: isize, |
| 407 | }; |
| 408 | |
| 409 | pub const timeval = extern struct { |
| 410 | tv_sec: isize, |
| 411 | tv_usec: isize, |
| 412 | }; |
| 413 | |
| 414 | pub const timezone = extern struct { |
| 415 | tz_minuteswest: i32, |
| 416 | tz_dsttime: i32, |
| 417 | }; |
| 418 | |
| 419 | pub const Elf_Symndx = u32; |