1pub mod family;
10
11use ::syscalls::SyscallArgs;
12use ::syscalls::Sysno;
13pub use nix::fcntl::AtFlags;
16pub use nix::fcntl::OFlag;
17use nix::sched::CloneFlags;
19pub use nix::sys::epoll::EpollCreateFlags;
20pub use nix::sys::eventfd::EfdFlags;
21pub use nix::sys::inotify::InitFlags;
22pub use nix::sys::mman::MapFlags;
23pub use nix::sys::mman::ProtFlags;
24pub use nix::sys::signalfd::SfdFlags;
25pub use nix::sys::socket::SockFlag;
26pub use nix::sys::stat::Mode;
27pub use nix::sys::timerfd::TimerFlags;
28pub use nix::sys::wait::WaitPidFlag;
29
30use crate::Addr;
31use crate::AddrMut;
32use crate::args;
33use crate::args::CArrayPtr;
34use crate::args::CStrPtr;
35use crate::args::ClockId;
36use crate::args::CloneArgs;
37use crate::args::FcntlCmd;
38use crate::args::PathPtr;
39use crate::args::StatPtr;
40use crate::args::StatxMask;
41use crate::args::StatxPtr;
42use crate::args::Timespec;
43use crate::args::TimespecMutPtr;
44use crate::args::TimevalMutPtr;
45use crate::args::Timezone;
46use crate::args::ioctl;
47use crate::display::Displayable;
48use crate::raw::FromToRaw;
49
50pub trait SyscallInfo: Displayable + Copy + Send {
52 type Return: Displayable + FromToRaw;
54
55 fn name(&self) -> &'static str;
57
58 fn number(&self) -> Sysno;
60
61 fn into_parts(self) -> (Sysno, SyscallArgs);
63}
64
65#[derive(Debug, Copy, Clone, Eq, PartialEq)]
78pub struct RawSyscall {
79 pub nr: u64,
85
86 pub args: SyscallArgs,
88}
89
90impl RawSyscall {
91 pub fn new(nr: u64, args: SyscallArgs) -> Self {
93 Self { nr, args }
94 }
95}
96
97syscall_list! {
101 #[derive(Debug, Copy, Clone, Eq, PartialEq)]
103 #[allow(missing_docs)]
104 #[non_exhaustive]
105 pub enum Syscall {
106 read => Read,
107 write => Write,
108 #[cfg(not(target_arch = "aarch64"))]
109 open => Open,
110 close => Close,
111 #[cfg(not(target_arch = "aarch64"))]
112 stat => Stat,
113 fstat => Fstat,
114 #[cfg(not(target_arch = "aarch64"))]
115 lstat => Lstat,
116 #[cfg(not(target_arch = "aarch64"))]
117 poll => Poll,
118 lseek => Lseek,
119 mmap => Mmap,
120 mprotect => Mprotect,
121 munmap => Munmap,
122 brk => Brk,
123 rt_sigaction => RtSigaction,
124 rt_sigprocmask => RtSigprocmask,
125 rt_sigreturn => RtSigreturn,
126 ioctl => Ioctl,
127 pread64 => Pread64,
128 pwrite64 => Pwrite64,
129 readv => Readv,
130 writev => Writev,
131 #[cfg(not(target_arch = "aarch64"))]
132 access => Access,
133 #[cfg(not(target_arch = "aarch64"))]
134 pipe => Pipe,
135 #[cfg(not(target_arch = "aarch64"))]
136 select => Select,
137 sched_yield => SchedYield,
138 mremap => Mremap,
139 msync => Msync,
140 mincore => Mincore,
141 madvise => Madvise,
142 shmget => Shmget,
143 shmat => Shmat,
144 shmctl => Shmctl,
145 dup => Dup,
146 #[cfg(not(target_arch = "aarch64"))]
147 dup2 => Dup2,
148 #[cfg(not(target_arch = "aarch64"))]
149 pause => Pause,
150 nanosleep => Nanosleep,
151 getitimer => Getitimer,
152 #[cfg(not(target_arch = "aarch64"))]
153 alarm => Alarm,
154 setitimer => Setitimer,
155 getpid => Getpid,
156 sendfile => Sendfile,
157 socket => Socket,
158 connect => Connect,
159 accept => Accept,
160 sendto => Sendto,
161 recvfrom => Recvfrom,
162 sendmsg => Sendmsg,
163 recvmsg => Recvmsg,
164 shutdown => Shutdown,
165 bind => Bind,
166 listen => Listen,
167 getsockname => Getsockname,
168 getpeername => Getpeername,
169 socketpair => Socketpair,
170 setsockopt => Setsockopt,
171 getsockopt => Getsockopt,
172 clone => Clone,
173 #[cfg(not(target_arch = "aarch64"))]
174 fork => Fork,
175 #[cfg(not(target_arch = "aarch64"))]
176 vfork => Vfork,
177 execve => Execve,
178 exit => Exit,
179 wait4 => Wait4,
180 kill => Kill,
181 uname => Uname,
182 semget => Semget,
183 semop => Semop,
184 semctl => Semctl,
185 shmdt => Shmdt,
186 msgget => Msgget,
187 msgsnd => Msgsnd,
188 msgrcv => Msgrcv,
189 msgctl => Msgctl,
190 fcntl => Fcntl,
191 flock => Flock,
192 fsync => Fsync,
193 fdatasync => Fdatasync,
194 truncate => Truncate,
195 ftruncate => Ftruncate,
196 #[cfg(not(target_arch = "aarch64"))]
197 getdents => Getdents,
198 getcwd => Getcwd,
199 chdir => Chdir,
200 fchdir => Fchdir,
201 #[cfg(not(target_arch = "aarch64"))]
202 rename => Rename,
203 #[cfg(not(target_arch = "aarch64"))]
204 mkdir => Mkdir,
205 #[cfg(not(target_arch = "aarch64"))]
206 rmdir => Rmdir,
207 #[cfg(not(target_arch = "aarch64"))]
208 creat => Creat,
209 #[cfg(not(target_arch = "aarch64"))]
210 link => Link,
211 #[cfg(not(target_arch = "aarch64"))]
212 unlink => Unlink,
213 #[cfg(not(target_arch = "aarch64"))]
214 symlink => Symlink,
215 #[cfg(not(target_arch = "aarch64"))]
216 readlink => Readlink,
217 #[cfg(not(target_arch = "aarch64"))]
218 chmod => Chmod,
219 fchmod => Fchmod,
220 #[cfg(not(target_arch = "aarch64"))]
221 chown => Chown,
222 fchown => Fchown,
223 #[cfg(not(target_arch = "aarch64"))]
224 lchown => Lchown,
225 umask => Umask,
226 gettimeofday => Gettimeofday,
227 getrlimit => Getrlimit,
228 getrusage => Getrusage,
229 sysinfo => Sysinfo,
230 times => Times,
231 ptrace => Ptrace,
232 getuid => Getuid,
233 syslog => Syslog,
234 getgid => Getgid,
235 setuid => Setuid,
236 setgid => Setgid,
237 geteuid => Geteuid,
238 getegid => Getegid,
239 setpgid => Setpgid,
240 getppid => Getppid,
241 #[cfg(not(target_arch = "aarch64"))]
242 getpgrp => Getpgrp,
243 setsid => Setsid,
244 setreuid => Setreuid,
245 setregid => Setregid,
246 getgroups => Getgroups,
247 setgroups => Setgroups,
248 setresuid => Setresuid,
249 getresuid => Getresuid,
250 setresgid => Setresgid,
251 getresgid => Getresgid,
252 getpgid => Getpgid,
253 setfsuid => Setfsuid,
254 setfsgid => Setfsgid,
255 getsid => Getsid,
256 capget => Capget,
257 capset => Capset,
258 rt_sigpending => RtSigpending,
259 rt_sigtimedwait => RtSigtimedwait,
260 rt_sigqueueinfo => RtSigqueueinfo,
261 rt_sigsuspend => RtSigsuspend,
262 sigaltstack => Sigaltstack,
263 #[cfg(not(target_arch = "aarch64"))]
264 utime => Utime,
265 #[cfg(not(target_arch = "aarch64"))]
266 mknod => Mknod,
267 #[cfg(not(target_arch = "aarch64"))]
268 uselib => Uselib,
269 personality => Personality,
270 #[cfg(not(target_arch = "aarch64"))]
271 ustat => Ustat,
272 statfs => Statfs,
273 fstatfs => Fstatfs,
274 #[cfg(not(target_arch = "aarch64"))]
275 sysfs => Sysfs,
276 getpriority => Getpriority,
277 setpriority => Setpriority,
278 sched_setparam => SchedSetparam,
279 sched_getparam => SchedGetparam,
280 sched_setscheduler => SchedSetscheduler,
281 sched_getscheduler => SchedGetscheduler,
282 sched_get_priority_max => SchedGetPriorityMax,
283 sched_get_priority_min => SchedGetPriorityMin,
284 sched_rr_get_interval => SchedRrGetInterval,
285 mlock => Mlock,
286 munlock => Munlock,
287 mlockall => Mlockall,
288 munlockall => Munlockall,
289 vhangup => Vhangup,
290 #[cfg(not(target_arch = "aarch64"))]
291 modify_ldt => ModifyLdt,
292 pivot_root => PivotRoot,
293 #[allow(non_camel_case_types)]
294 #[cfg(not(target_arch = "aarch64"))]
295 _sysctl => _sysctl,
296 prctl => Prctl,
297 #[cfg(not(target_arch = "aarch64"))]
298 arch_prctl => ArchPrctl,
299 adjtimex => Adjtimex,
300 setrlimit => Setrlimit,
301 chroot => Chroot,
302 sync => Sync,
303 acct => Acct,
304 settimeofday => Settimeofday,
305 mount => Mount,
306 umount2 => Umount2,
307 swapon => Swapon,
308 swapoff => Swapoff,
309 reboot => Reboot,
310 sethostname => Sethostname,
311 setdomainname => Setdomainname,
312 #[cfg(not(target_arch = "aarch64"))]
313 iopl => Iopl,
314 #[cfg(not(target_arch = "aarch64"))]
315 ioperm => Ioperm,
316 #[cfg(not(target_arch = "aarch64"))]
317 create_module => CreateModule,
318 init_module => InitModule,
319 delete_module => DeleteModule,
320 #[cfg(not(target_arch = "aarch64"))]
321 get_kernel_syms => GetKernelSyms,
322 #[cfg(not(target_arch = "aarch64"))]
323 query_module => QueryModule,
324 quotactl => Quotactl,
325 nfsservctl => Nfsservctl,
326 #[cfg(not(target_arch = "aarch64"))]
327 getpmsg => Getpmsg,
328 #[cfg(not(target_arch = "aarch64"))]
329 putpmsg => Putpmsg,
330 #[cfg(not(target_arch = "aarch64"))]
331 afs_syscall => AfsSyscall,
332 #[cfg(not(target_arch = "aarch64"))]
333 tuxcall => Tuxcall,
334 #[cfg(not(target_arch = "aarch64"))]
335 security => Security,
336 gettid => Gettid,
337 readahead => Readahead,
338 setxattr => Setxattr,
339 lsetxattr => Lsetxattr,
340 fsetxattr => Fsetxattr,
341 getxattr => Getxattr,
342 lgetxattr => Lgetxattr,
343 fgetxattr => Fgetxattr,
344 listxattr => Listxattr,
345 llistxattr => Llistxattr,
346 flistxattr => Flistxattr,
347 removexattr => Removexattr,
348 lremovexattr => Lremovexattr,
349 fremovexattr => Fremovexattr,
350 tkill => Tkill,
351 #[cfg(not(target_arch = "aarch64"))]
352 time => Time,
353 futex => Futex,
354 sched_setaffinity => SchedSetaffinity,
355 sched_getaffinity => SchedGetaffinity,
356 #[cfg(not(target_arch = "aarch64"))]
357 set_thread_area => SetThreadArea,
358 io_setup => IoSetup,
359 io_destroy => IoDestroy,
360 io_getevents => IoGetevents,
361 io_submit => IoSubmit,
362 io_cancel => IoCancel,
363 #[cfg(not(target_arch = "aarch64"))]
364 get_thread_area => GetThreadArea,
365 lookup_dcookie => LookupDcookie,
366 #[cfg(not(target_arch = "aarch64"))]
367 epoll_create => EpollCreate,
368 #[cfg(not(target_arch = "aarch64"))]
369 epoll_ctl_old => EpollCtlOld,
370 #[cfg(not(target_arch = "aarch64"))]
371 epoll_wait_old => EpollWaitOld,
372 remap_file_pages => RemapFilePages,
373 getdents64 => Getdents64,
374 set_tid_address => SetTidAddress,
375 restart_syscall => RestartSyscall,
376 semtimedop => Semtimedop,
377 fadvise64 => Fadvise64,
378 timer_create => TimerCreate,
379 timer_settime => TimerSettime,
380 timer_gettime => TimerGettime,
381 timer_getoverrun => TimerGetoverrun,
382 timer_delete => TimerDelete,
383 clock_settime => ClockSettime,
384 clock_gettime => ClockGettime,
385 clock_getres => ClockGetres,
386 clock_nanosleep => ClockNanosleep,
387 exit_group => ExitGroup,
388 #[cfg(not(target_arch = "aarch64"))]
389 epoll_wait => EpollWait,
390 epoll_ctl => EpollCtl,
391 tgkill => Tgkill,
392 #[cfg(not(target_arch = "aarch64"))]
393 utimes => Utimes,
394 #[cfg(not(target_arch = "aarch64"))]
395 vserver => Vserver,
396 mbind => Mbind,
397 set_mempolicy => SetMempolicy,
398 get_mempolicy => GetMempolicy,
399 mq_open => MqOpen,
400 mq_unlink => MqUnlink,
401 mq_timedsend => MqTimedsend,
402 mq_timedreceive => MqTimedreceive,
403 mq_notify => MqNotify,
404 mq_getsetattr => MqGetsetattr,
405 kexec_load => KexecLoad,
406 waitid => Waitid,
407 add_key => AddKey,
408 request_key => RequestKey,
409 keyctl => Keyctl,
410 ioprio_set => IoprioSet,
411 ioprio_get => IoprioGet,
412 #[cfg(not(target_arch = "aarch64"))]
413 inotify_init => InotifyInit,
414 inotify_add_watch => InotifyAddWatch,
415 inotify_rm_watch => InotifyRmWatch,
416 migrate_pages => MigratePages,
417 openat => Openat,
418 mkdirat => Mkdirat,
419 mknodat => Mknodat,
420 fchownat => Fchownat,
421 #[cfg(not(target_arch = "aarch64"))]
422 futimesat => Futimesat,
423 #[cfg(target_arch = "x86_64")]
424 newfstatat => Newfstatat,
425 #[cfg(target_arch = "aarch64")]
426 fstatat => Fstatat,
427 unlinkat => Unlinkat,
428 renameat => Renameat,
429 linkat => Linkat,
430 symlinkat => Symlinkat,
431 readlinkat => Readlinkat,
432 fchmodat => Fchmodat,
433 faccessat => Faccessat,
434 pselect6 => Pselect6,
435 ppoll => Ppoll,
436 unshare => Unshare,
437 set_robust_list => SetRobustList,
438 get_robust_list => GetRobustList,
439 splice => Splice,
440 tee => Tee,
441 #[cfg(not(target_arch = "aarch64"))]
442 sync_file_range => SyncFileRange,
443 vmsplice => Vmsplice,
444 move_pages => MovePages,
445 utimensat => Utimensat,
446 epoll_pwait => EpollPwait,
447 #[cfg(not(target_arch = "aarch64"))]
448 signalfd => Signalfd,
449 timerfd_create => TimerfdCreate,
450 #[cfg(not(target_arch = "aarch64"))]
451 eventfd => Eventfd,
452 fallocate => Fallocate,
453 timerfd_settime => TimerfdSettime,
454 timerfd_gettime => TimerfdGettime,
455 accept4 => Accept4,
456 signalfd4 => Signalfd4,
457 eventfd2 => Eventfd2,
458 epoll_create1 => EpollCreate1,
459 dup3 => Dup3,
460 pipe2 => Pipe2,
461 inotify_init1 => InotifyInit1,
462 preadv => Preadv,
463 pwritev => Pwritev,
464 rt_tgsigqueueinfo => RtTgsigqueueinfo,
465 perf_event_open => PerfEventOpen,
466 recvmmsg => Recvmmsg,
467 fanotify_init => FanotifyInit,
468 fanotify_mark => FanotifyMark,
469 prlimit64 => Prlimit64,
470 name_to_handle_at => NameToHandleAt,
471 open_by_handle_at => OpenByHandleAt,
472 clock_adjtime => ClockAdjtime,
473 syncfs => Syncfs,
474 sendmmsg => Sendmmsg,
475 setns => Setns,
476 getcpu => Getcpu,
477 process_vm_readv => ProcessVmReadv,
478 process_vm_writev => ProcessVmWritev,
479 kcmp => Kcmp,
480 finit_module => FinitModule,
481 sched_setattr => SchedSetattr,
482 sched_getattr => SchedGetattr,
483 renameat2 => Renameat2,
484 seccomp => Seccomp,
485 getrandom => Getrandom,
486 memfd_create => MemfdCreate,
487 kexec_file_load => KexecFileLoad,
488 bpf => Bpf,
489 execveat => Execveat,
490 userfaultfd => Userfaultfd,
491 membarrier => Membarrier,
492 mlock2 => Mlock2,
493 copy_file_range => CopyFileRange,
494 preadv2 => Preadv2,
495 pwritev2 => Pwritev2,
496 pkey_mprotect => PkeyMprotect,
497 pkey_alloc => PkeyAlloc,
498 pkey_free => PkeyFree,
499 statx => Statx,
500 io_uring_setup => IoUringSetup,
504 io_uring_enter => IoUringEnter,
505 io_uring_register => IoUringRegister,
506 pidfd_open => PidfdOpen,
513 clone3 => Clone3,
514 openat2 => Openat2,
516 fchmodat2 => Fchmodat2,
526 }
527}
528
529typed_syscall! {
530 pub struct Read {
531 fd: i32,
532 buf: Option<AddrMut<u8>>,
535 len: usize,
536 }
537}
538
539typed_syscall! {
540 pub struct Write {
541 fd: i32,
542 buf: Option<Addr<u8>>,
545 len: usize,
546 }
547}
548
549fn get_mode(flags: OFlag, mode: usize) -> Option<Mode> {
550 if flags.intersects(OFlag::O_CREAT | OFlag::O_TMPFILE) {
551 Some(FromToRaw::from_raw(mode))
552 } else {
553 None
554 }
555}
556
557#[cfg(not(target_arch = "aarch64"))]
559typed_syscall! {
560 pub struct Open -> i32 {
561 path: Option<PathPtr>,
562 flags: OFlag,
563
564 mode?: {
567 fn get(&self) -> Option<Mode> {
568 get_mode(self.flags(), self.raw.arg2)
569 }
570
571 fn set(mut self, v: Option<Mode>) -> Self {
572 self.raw.arg2 = v.into_raw();
573 self
574 }
575 },
576 }
577}
578
579#[cfg(not(target_arch = "aarch64"))]
581impl From<Creat> for Open {
582 fn from(creat: Creat) -> Self {
585 let Creat { mut raw } = creat;
586 raw.arg2 = raw.arg1;
587 raw.arg1 = (libc::O_CREAT | libc::O_WRONLY | libc::O_TRUNC) as usize;
588 Open { raw }
589 }
590}
591
592typed_syscall! {
593 pub struct Close {
594 fd: i32,
595 }
596}
597
598#[cfg(not(target_arch = "aarch64"))]
600typed_syscall! {
601 pub struct Stat {
602 path: Option<PathPtr>,
603 stat: Option<StatPtr>,
604 }
605}
606
607typed_syscall! {
608 pub struct Fstat {
609 fd: i32,
610 stat: Option<StatPtr>,
611 }
612}
613
614#[cfg(not(target_arch = "aarch64"))]
616typed_syscall! {
617 pub struct Lstat {
618 path: Option<PathPtr>,
619 stat: Option<StatPtr>,
620 }
621}
622
623#[cfg(not(target_arch = "aarch64"))]
625typed_syscall! {
626 pub struct Poll {
627 fds: Option<AddrMut<args::PollFd>>,
628 nfds: libc::nfds_t,
629 timeout: libc::c_int,
630 }
631}
632
633typed_syscall! {
634 pub struct Mmap {
635 addr: Option<Addr<libc::c_void>>,
636 len: usize,
637 prot: ProtFlags,
638 flags: MapFlags,
639 fd: i32,
640 offset: libc::off_t,
641 }
642}
643
644typed_syscall! {
645 pub struct Lseek {
646 fd: i32,
647 offset: libc::off_t,
648 whence: args::Whence,
649 }
650}
651
652typed_syscall! {
653 pub struct Mprotect {
654 addr: Option<AddrMut<libc::c_void>>,
655 len: usize,
656 protection: ProtFlags,
657 }
658}
659
660typed_syscall! {
661 pub struct Munmap {
662 addr: Option<Addr<libc::c_void>>,
663 len: usize,
664 }
665}
666
667typed_syscall! {
668 pub struct Brk {
669 addr: Option<AddrMut<libc::c_void>>,
670 }
671}
672
673typed_syscall! {
674 pub struct RtSigaction {
675 signum: i32,
676 action: Option<Addr<libc::sigaction>>,
677 old_action: Option<AddrMut<libc::sigaction>>,
678 sigsetsize: usize,
680 }
681}
682
683typed_syscall! {
684 pub struct RtSigprocmask {
685 how: i32,
686 set: Option<Addr<libc::sigset_t>>,
687 oldset: Option<AddrMut<libc::sigset_t>>,
688 sigsetsize: usize,
690 }
691}
692
693typed_syscall! {
694 pub struct RtSigreturn {
695 }
696}
697
698typed_syscall! {
699 pub struct Ioctl {
700 fd: i32,
701 request: {
702 fn get(&self) -> ioctl::Request {
703 ioctl::Request::from_raw(self.raw.arg1, self.raw.arg2)
704 }
705
706 fn set(mut self, v: ioctl::Request) -> Self {
707 let (request, arg) = v.into_raw();
708 self.raw.arg1 = request;
709 self.raw.arg2 = arg;
710 self
711 }
712 },
713 }
714}
715
716typed_syscall! {
717 pub struct Pread64 {
718 fd: i32,
719 buf: Option<AddrMut<u8>>,
722 len: usize,
723 offset: libc::off_t,
724 }
725}
726
727typed_syscall! {
728 pub struct Pwrite64 {
729 fd: i32,
730 buf: Option<Addr<u8>>,
733 len: usize,
734 offset: libc::off_t,
735 }
736}
737
738typed_syscall! {
739 pub struct Readv {
740 fd: i32,
741 iov: Option<Addr<libc::iovec>>,
742 len: usize,
743 }
744}
745
746typed_syscall! {
747 pub struct Writev {
748 fd: i32,
749 iov: Option<Addr<libc::iovec>>,
750 len: usize,
751 }
752}
753
754#[cfg(not(target_arch = "aarch64"))]
756typed_syscall! {
757 pub struct Access {
758 path: Option<PathPtr>,
759 mode: Mode,
760 }
761}
762
763#[cfg(not(target_arch = "aarch64"))]
765typed_syscall! {
766 pub struct Pipe {
767 pipefd: Option<AddrMut<[i32; 2]>>,
768 }
769}
770
771#[cfg(not(target_arch = "aarch64"))]
773typed_syscall! {
774 pub struct Select {
775 nfds: i32,
776 readfds: Option<AddrMut<libc::fd_set>>,
777 writefds: Option<AddrMut<libc::fd_set>>,
778 exceptfds: Option<AddrMut<libc::fd_set>>,
779 timeout: Option<AddrMut<libc::timeval>>,
780 }
781}
782
783typed_syscall! {
784 pub struct SchedYield {}
785}
786
787typed_syscall! {
788 pub struct Mremap {
789 addr: Option<AddrMut<libc::c_void>>,
790 old_len: usize,
791 new_len: usize,
792 flags: usize,
793 new_addr: Option<AddrMut<libc::c_void>>,
794 }
795}
796
797typed_syscall! {
798 pub struct Msync {
799 addr: Option<AddrMut<libc::c_void>>,
800 len: usize,
801 flags: i32,
802 }
803}
804
805typed_syscall! {
806 pub struct Mincore {
807 addr: Option<AddrMut<libc::c_void>>,
808 len: usize,
809 vec: Option<AddrMut<u8>>,
810 }
811}
812
813typed_syscall! {
814 pub struct Madvise {
815 addr: Option<AddrMut<libc::c_void>>,
816 len: usize,
817 advice: i32,
818 }
819}
820
821typed_syscall! {
822 pub struct Shmget {
823 key: libc::key_t,
824 size: usize,
825 shmflg: i32,
826 }
827}
828
829typed_syscall! {
830 pub struct Shmat {
831 shmid: i32,
832 shmaddr: Option<Addr<libc::c_void>>,
833 shmflg: i32,
834 }
835}
836
837typed_syscall! {
838 pub struct Shmctl {
839 shmid: i32,
840 cmd: i32,
841 buf: Option<AddrMut<libc::shmid_ds>>,
842 }
843}
844
845typed_syscall! {
846 pub struct Dup {
847 oldfd: i32,
848 }
849}
850
851#[cfg(not(target_arch = "aarch64"))]
853typed_syscall! {
854 pub struct Dup2 {
855 oldfd: i32,
856 newfd: i32,
857 }
858}
859
860#[cfg(not(target_arch = "aarch64"))]
862typed_syscall! { pub struct Pause {} }
863
864typed_syscall! {
865 pub struct Nanosleep {
866 req: Option<Addr<Timespec>>,
867 rem: Option<AddrMut<Timespec>>,
868 }
869}
870
871typed_syscall! {
872 pub struct Getitimer {
873 which: i32,
874 value: Option<AddrMut<libc::itimerval>>,
875 }
876}
877
878#[cfg(not(target_arch = "aarch64"))]
880typed_syscall! {
881 pub struct Alarm {
882 seconds: u32,
883 }
884}
885
886typed_syscall! {
887 pub struct Setitimer {
888 which: i32,
889 value: Option<AddrMut<libc::itimerval>>,
890 ovalue: Option<AddrMut<libc::itimerval>>,
891 }
892}
893
894typed_syscall! {
895 pub struct Getpid {}
896}
897
898typed_syscall! {
899 pub struct Sendfile {
900 out_fd: i32,
901 in_fd: i32,
902 offset: Option<AddrMut<libc::loff_t>>,
903 count: usize,
904 }
905}
906
907typed_syscall! {
908 pub struct Socket {
910 family: i32,
911 r#type: i32,
912 protocol: i32,
913 }
914}
915
916typed_syscall! {
917 pub struct Connect {
918 fd: i32,
919 uservaddr: Option<AddrMut<libc::sockaddr>>,
920 addrlen: i32,
921 }
922}
923
924typed_syscall! {
925 pub struct Accept {
926 sockfd: i32,
927 sockaddr: Option<AddrMut<libc::sockaddr>>,
928 addrlen: Option<AddrMut<usize>>,
929 }
930}
931
932typed_syscall! {
933 pub struct Sendto {
934 fd: i32,
935 buf: Option<AddrMut<libc::c_void>>,
936 size: usize,
937 flags: u32,
938 addr: Option<AddrMut<libc::sockaddr>>,
939 addr_len: i32,
940 }
941}
942
943typed_syscall! {
944 pub struct Recvfrom {
945 fd: i32,
946 buf: Option<AddrMut<u8>>,
947 len: usize,
948 flags: i32,
949 addr: Option<AddrMut<libc::sockaddr>>,
950 addr_len: Option<AddrMut<libc::socklen_t>>,
951 }
952}
953
954typed_syscall! {
955 pub struct Sendmsg {
956 fd: i32,
957 msg: Option<Addr<crate::linux_abi::Msghdr>>,
958 flags: i32,
959 }
960}
961
962typed_syscall! {
963 pub struct Recvmsg {
964 sockfd: i32,
965 msg: Option<AddrMut<crate::linux_abi::Msghdr>>,
966 flags: i32,
967 }
968}
969
970typed_syscall! {
971 pub struct Shutdown {
972 fd: i32,
973 how: i32,
974 }
975}
976
977typed_syscall! {
978 pub struct Bind {
979 fd: i32,
980 umyaddr: Option<AddrMut<libc::sockaddr>>,
981 addrlen: i32,
982 }
983}
984
985typed_syscall! {
986 pub struct Listen {
987 fd: i32,
988 backlog: i32,
989 }
990}
991
992typed_syscall! {
993 pub struct Getsockname {
994 fd: i32,
995 usockaddr: Option<AddrMut<libc::sockaddr>>,
996 usockaddr_len: Option<AddrMut<libc::socklen_t>>,
997 }
998}
999
1000typed_syscall! {
1001 pub struct Getpeername {
1002 fd: i32,
1003 usockaddr: Option<AddrMut<libc::sockaddr>>,
1004 usockaddr_len: Option<AddrMut<libc::socklen_t>>,
1005 }
1006}
1007
1008typed_syscall! {
1009 pub struct Socketpair {
1011 family: i32,
1012 r#type: i32,
1013 protocol: i32,
1014 usockvec: Option<AddrMut<[i32; 2]>>,
1015 }
1016}
1017
1018typed_syscall! {
1019 pub struct Setsockopt {
1020 fd: i32,
1021 level: i32,
1022 optname: i32,
1023 optval: Option<Addr<libc::c_void>>,
1024 optlen: libc::socklen_t,
1025 }
1026}
1027
1028typed_syscall! {
1029 pub struct Getsockopt {
1030 fd: i32,
1031 level: i32,
1032 optname: i32,
1033 optval: Option<AddrMut<libc::c_void>>,
1034 optlen: Option<AddrMut<libc::socklen_t>>,
1035 }
1036}
1037
1038#[cfg(target_arch = "x86_64")]
1039typed_syscall! {
1040 pub struct Clone {
1041 flags: CloneFlags,
1042 child_stack: Option<AddrMut<libc::c_void>>,
1043 ptid: Option<AddrMut<libc::pid_t>>,
1044 ctid: Option<AddrMut<libc::pid_t>>,
1045 newtls: u64,
1046 }
1047}
1048
1049#[cfg(any(target_arch = "arm", target_arch = "aarch64", target_arch = "x86"))]
1050typed_syscall! {
1051 pub struct Clone {
1052 flags: CloneFlags,
1053 child_stack: Option<AddrMut<libc::c_void>>,
1054 ptid: Option<AddrMut<libc::pid_t>>,
1055 newtls: u64,
1056 ctid: Option<AddrMut<libc::pid_t>>,
1057 }
1058}
1059
1060#[cfg(not(target_arch = "aarch64"))]
1062impl From<Vfork> for Clone {
1063 fn from(_: Vfork) -> Self {
1068 let raw = SyscallArgs {
1069 arg0: (libc::CLONE_VFORK | libc::CLONE_VM | libc::SIGCHLD) as usize,
1070 arg1: 0,
1071 arg2: 0,
1072 arg3: 0,
1073 arg4: 0,
1074 arg5: 0,
1075 };
1076 Self { raw }
1077 }
1078}
1079
1080#[cfg(not(target_arch = "aarch64"))]
1082impl From<Fork> for Clone {
1083 fn from(_: Fork) -> Self {
1088 let raw = SyscallArgs {
1089 arg0: libc::SIGCHLD as usize,
1090 arg1: 0,
1091 arg2: 0,
1092 arg3: 0,
1093 arg4: 0,
1094 arg5: 0,
1095 };
1096 Self { raw }
1097 }
1098}
1099#[cfg(not(target_arch = "aarch64"))]
1101typed_syscall! {
1102 pub struct Fork {}
1103}
1104#[cfg(not(target_arch = "aarch64"))]
1106typed_syscall! {
1107 pub struct Vfork {}
1108}
1109
1110typed_syscall! {
1111 pub struct Execve {
1112 path: Option<PathPtr>,
1113 argv: Option<CArrayPtr<CStrPtr>>,
1114 envp: Option<CArrayPtr<CStrPtr>>,
1115 }
1116}
1117
1118typed_syscall! {
1119 pub struct Exit {
1120 status: libc::c_int,
1121 }
1122}
1123
1124typed_syscall! {
1125 pub struct Wait4 {
1126 pid: libc::pid_t,
1127 wstatus: Option<AddrMut<libc::c_int>>,
1128 options: WaitPidFlag,
1129 rusage: Option<AddrMut<libc::rusage>>,
1130 }
1131}
1132
1133typed_syscall! {
1134 pub struct Kill {
1135 pid: libc::pid_t,
1136 sig: libc::c_int,
1139 }
1140}
1141
1142typed_syscall! {
1143 pub struct Uname {
1144 buf: Option<AddrMut<libc::utsname>>,
1145 }
1146}
1147
1148typed_syscall! {
1149 pub struct Semget {
1150 key: libc::key_t,
1151 nsems: i32,
1152 semflg: i32,
1153 }
1154}
1155
1156typed_syscall! {
1157 pub struct Semop {
1158 semid: i32,
1159 tsops: Option<AddrMut<libc::sembuf>>,
1160 nsops: usize,
1161 }
1162}
1163
1164typed_syscall! {
1165 pub struct Semctl {
1166 semid: i32,
1167 semnum: i32,
1168 cmd: i32,
1169 arg: u64,
1170 }
1171}
1172
1173typed_syscall! {
1174 pub struct Shmdt {
1175 shmaddr: Option<Addr<libc::c_void>>,
1176 }
1177}
1178
1179typed_syscall! {
1180 pub struct Msgget {
1181 key: libc::key_t,
1182 msgflg: i32,
1183 }
1184}
1185
1186typed_syscall! {
1187 pub struct Msgsnd {
1188 msqid: i32,
1189 msgp: Option<Addr<libc::c_void>>,
1190 msgsz: usize,
1191 msgflg: i32,
1192 }
1193}
1194
1195typed_syscall! {
1196 pub struct Msgrcv {
1197 msqid: i32,
1198 msgp: Option<AddrMut<libc::c_void>>,
1199 msgsz: usize,
1200 msgtyp: libc::c_long,
1201 msgflg: i32,
1202 }
1203}
1204
1205typed_syscall! {
1206 pub struct Msgctl {
1207 msqid: i32,
1208 cmd: i32,
1209 buf: Option<AddrMut<libc::msqid_ds>>,
1210 }
1211}
1212
1213typed_syscall! {
1214 pub struct Fcntl {
1215 fd: i32,
1217
1218 cmd: {
1219 fn get(&self) -> FcntlCmd {
1220 FcntlCmd::from_raw(self.raw.arg1 as libc::c_int, self.raw.arg2)
1221 }
1222
1223 fn set(mut self, v: FcntlCmd) -> Self {
1224 let (cmd, arg) = v.into_raw();
1225 self.raw.arg1 = cmd as usize;
1226 self.raw.arg2 = arg;
1227 self
1228 }
1229 },
1230 }
1231}
1232
1233typed_syscall! {
1234 pub struct Flock {
1235 fd: i32,
1236 operation: i32,
1238 }
1239}
1240
1241typed_syscall! {
1242 pub struct Fsync {
1243 fd: i32,
1244 }
1245}
1246
1247typed_syscall! {
1248 pub struct Fdatasync {
1249 fd: i32,
1250 }
1251}
1252
1253typed_syscall! {
1254 pub struct Truncate {
1255 path: Option<PathPtr>,
1256 length: libc::off_t,
1257 }
1258}
1259
1260typed_syscall! {
1261 pub struct Ftruncate {
1262 fd: i32,
1263 length: libc::off_t,
1264 }
1265}
1266#[cfg(not(target_arch = "aarch64"))]
1268typed_syscall! {
1269 pub struct Getdents {
1270 fd: u32,
1271 dirent: Option<AddrMut<libc::dirent>>,
1272 count: u32,
1273 }
1274}
1275
1276typed_syscall! {
1277 pub struct Getcwd {
1278 buf: Option<AddrMut<libc::c_char>>,
1280 size: usize,
1281 }
1282}
1283
1284typed_syscall! {
1285 pub struct Chdir {
1286 path: Option<PathPtr>,
1287 }
1288}
1289
1290typed_syscall! {
1291 pub struct Fchdir {
1292 fd: i32,
1293 }
1294}
1295#[cfg(not(target_arch = "aarch64"))]
1297typed_syscall! {
1298 pub struct Rename {
1299 oldpath: Option<PathPtr>,
1300 newpath: Option<PathPtr>,
1301 }
1302}
1303#[cfg(not(target_arch = "aarch64"))]
1305typed_syscall! {
1306 pub struct Mkdir {
1307 path: Option<PathPtr>,
1308 mode: Mode,
1309 }
1310}
1311#[cfg(not(target_arch = "aarch64"))]
1313typed_syscall! {
1314 pub struct Rmdir {
1315 path: Option<PathPtr>,
1316 }
1317}
1318#[cfg(not(target_arch = "aarch64"))]
1320typed_syscall! {
1321 pub struct Creat {
1322 path: Option<PathPtr>,
1323 mode: Mode,
1324 }
1325}
1326#[cfg(not(target_arch = "aarch64"))]
1328typed_syscall! {
1329 pub struct Link {
1330 oldpath: Option<PathPtr>,
1331 newpath: Option<PathPtr>,
1332 }
1333}
1334#[cfg(not(target_arch = "aarch64"))]
1336typed_syscall! {
1337 pub struct Unlink {
1338 path: Option<PathPtr>,
1339 }
1340}
1341#[cfg(not(target_arch = "aarch64"))]
1343typed_syscall! {
1344 pub struct Symlink {
1345 target: Option<PathPtr>,
1346 linkpath: Option<PathPtr>,
1347 }
1348}
1349
1350#[cfg(not(target_arch = "aarch64"))]
1352typed_syscall! {
1353 pub struct Readlink {
1354 path: Option<PathPtr>,
1355 buf: Option<AddrMut<libc::c_char>>,
1357 bufsize: usize,
1358 }
1359}
1360
1361#[cfg(not(target_arch = "aarch64"))]
1363typed_syscall! {
1364 pub struct Chmod {
1365 path: Option<PathPtr>,
1366 mode: Mode,
1367 }
1368}
1369
1370typed_syscall! {
1371 pub struct Fchmod {
1372 fd: i32,
1373 mode: Mode,
1374 }
1375}
1376#[cfg(not(target_arch = "aarch64"))]
1378typed_syscall! {
1379 pub struct Chown {
1380 path: Option<PathPtr>,
1381 owner: libc::uid_t,
1382 group: libc::gid_t,
1383 }
1384}
1385
1386typed_syscall! {
1387 pub struct Fchown {
1388 fd: i32,
1389 owner: libc::uid_t,
1390 group: libc::gid_t,
1391 }
1392}
1393#[cfg(not(target_arch = "aarch64"))]
1395typed_syscall! {
1396 pub struct Lchown {
1397 path: Option<PathPtr>,
1398 owner: libc::uid_t,
1399 group: libc::gid_t,
1400 }
1401}
1402
1403typed_syscall! {
1404 pub struct Umask {
1405 mask: Mode,
1406 }
1407}
1408
1409typed_syscall! {
1410 pub struct Gettimeofday {
1411 tv: Option<TimevalMutPtr>,
1412 tz: Option<AddrMut<Timezone>>,
1413 }
1414}
1415
1416typed_syscall! {
1417 pub struct Getrlimit {
1418 resource: i32,
1419 rlim: Option<AddrMut<libc::rlimit>>,
1420 }
1421}
1422
1423typed_syscall! {
1424 pub struct Getrusage {
1425 who: i32,
1426 usage: Option<AddrMut<libc::rusage>>,
1427 }
1428}
1429
1430typed_syscall! {
1431 pub struct Sysinfo {
1432 info: Option<AddrMut<crate::linux_abi::Sysinfo>>,
1433 }
1434}
1435
1436typed_syscall! {
1437 pub struct Times -> libc::clock_t {
1438 buf: Option<AddrMut<libc::tms>>,
1439 }
1440}
1441
1442typed_syscall! {
1443 pub struct Ptrace {
1444 request: u32,
1445 pid: libc::pid_t,
1446 addr: Option<AddrMut<libc::c_void>>,
1447 data: Option<AddrMut<libc::c_void>>,
1448 }
1449}
1450
1451typed_syscall! { pub struct Getuid {} }
1452
1453typed_syscall! {
1454 pub struct Syslog {
1455 priority: i32,
1456 buf: Option<Addr<libc::c_char>>,
1457 len: usize,
1458 }
1459}
1460
1461typed_syscall! { pub struct Getgid {} }
1462typed_syscall! { pub struct Setuid { uid: libc::uid_t, } }
1463typed_syscall! { pub struct Setgid { uid: libc::gid_t, } }
1464typed_syscall! { pub struct Geteuid {} }
1465typed_syscall! { pub struct Getegid {} }
1466typed_syscall! { pub struct Setpgid { pid: libc::pid_t, pgid: libc::pid_t, } }
1467typed_syscall! { pub struct Getppid {} }
1468
1469#[cfg(not(target_arch = "aarch64"))]
1471typed_syscall! { pub struct Getpgrp {} }
1472
1473typed_syscall! { pub struct Setsid {} }
1474typed_syscall! { pub struct Setreuid { ruid: libc::uid_t, euid: libc::uid_t, } }
1475typed_syscall! { pub struct Setregid { rgid: libc::gid_t, egid: libc::gid_t, } }
1476
1477typed_syscall! {
1478 pub struct Getgroups {
1479 size: i32,
1481 list: Option<AddrMut<libc::gid_t>>,
1482 }
1483}
1484
1485typed_syscall! {
1486 pub struct Setgroups {
1487 size: usize,
1489 list: Option<Addr<libc::gid_t>>,
1490 }
1491}
1492
1493typed_syscall! {
1494 pub struct Setresuid {
1495 ruid: libc::uid_t,
1496 euid: libc::uid_t,
1497 suid: libc::uid_t,
1498 }
1499}
1500typed_syscall! {
1501 pub struct Getresuid {
1502 ruid: Option<AddrMut<libc::gid_t>>,
1503 euid: Option<AddrMut<libc::gid_t>>,
1504 suid: Option<AddrMut<libc::gid_t>>,
1505 }
1506}
1507typed_syscall! {
1508 pub struct Setresgid {
1509 rgid: libc::gid_t,
1510 egid: libc::gid_t,
1511 sgid: libc::gid_t,
1512 }
1513}
1514typed_syscall! {
1515 pub struct Getresgid {
1516 rgid: Option<AddrMut<libc::gid_t>>,
1517 egid: Option<AddrMut<libc::gid_t>>,
1518 sgid: Option<AddrMut<libc::gid_t>>,
1519 }
1520}
1521typed_syscall! { pub struct Getpgid {} }
1522typed_syscall! { pub struct Setfsuid {} }
1523typed_syscall! { pub struct Setfsgid {} }
1524typed_syscall! { pub struct Getsid {} }
1525
1526typed_syscall! {
1527 pub struct Capget {
1528 header: Option<AddrMut<libc::c_void>>,
1529 data: Option<AddrMut<libc::c_void>>,
1530 }
1531}
1532
1533typed_syscall! {
1534 pub struct Capset {
1535 header: Option<AddrMut<libc::c_void>>,
1536 data: Option<Addr<libc::c_void>>,
1537 }
1538}
1539
1540typed_syscall! {
1541 pub struct RtSigpending {
1542 set: Option<AddrMut<libc::sigset_t>>,
1543 sigsetsize: usize,
1545 }
1546}
1547
1548typed_syscall! {
1549 pub struct RtSigtimedwait {
1550 set: Option<AddrMut<libc::sigset_t>>,
1551 info: Option<AddrMut<libc::siginfo_t>>,
1552 timeout: Option<Addr<Timespec>>,
1553 sigsetsize: usize,
1555 }
1556}
1557
1558typed_syscall! {
1559 pub struct RtSigqueueinfo {
1560 tgid: libc::pid_t,
1561 sig: i32,
1562 siginfo: Option<AddrMut<libc::siginfo_t>>,
1563 }
1564}
1565
1566typed_syscall! {
1567 pub struct RtSigsuspend {
1568 mask: Option<Addr<libc::sigset_t>>,
1569 sigsetsize: usize,
1571 }
1572}
1573
1574typed_syscall! {
1575 pub struct Sigaltstack {
1576 ss: Option<Addr<libc::stack_t>>,
1577 old_ss: Option<AddrMut<libc::stack_t>>,
1578 }
1579}
1580
1581#[cfg(not(target_arch = "aarch64"))]
1583typed_syscall! {
1584 pub struct Utime {
1585 path: Option<PathPtr>,
1586 times: Option<AddrMut<libc::utimbuf>>,
1587 }
1588}
1589
1590#[cfg(not(target_arch = "aarch64"))]
1592typed_syscall! {
1593 pub struct Mknod {
1594 path: Option<PathPtr>,
1595 mode: Mode,
1596 dev: libc::dev_t,
1597 }
1598}
1599
1600#[cfg(not(target_arch = "aarch64"))]
1602typed_syscall! {
1603 pub struct Uselib {
1604 library: Option<PathPtr>,
1605 }
1606}
1607
1608typed_syscall! {
1609 pub struct Personality {
1610 persona: u64,
1611 }
1612}
1613
1614#[cfg(not(target_arch = "aarch64"))]
1616typed_syscall! {
1617 pub struct Ustat {
1618 dev: libc::dev_t,
1619 ubuf: Option<AddrMut<libc::c_void>>,
1621 }
1622}
1623
1624typed_syscall! {
1625 pub struct Statfs {
1626 path: Option<PathPtr>,
1627 buf: Option<AddrMut<libc::statfs>>,
1628 }
1629}
1630
1631typed_syscall! {
1632 pub struct Fstatfs {
1633 fd: i32,
1634 buf: Option<AddrMut<libc::statfs>>,
1635 }
1636}
1637
1638#[cfg(not(target_arch = "aarch64"))]
1640typed_syscall! {
1641 pub struct Sysfs {
1642 option: i32,
1643 arg1: usize,
1644 arg2: usize,
1645 }
1646}
1647
1648typed_syscall! {
1649 pub struct Getpriority {
1650 which: i32,
1651 who: libc::id_t,
1652 }
1653}
1654
1655typed_syscall! {
1656 pub struct Setpriority {
1657 which: i32,
1658 who: libc::id_t,
1659 prio: i32,
1660 }
1661}
1662
1663typed_syscall! {
1664 pub struct SchedSetparam {
1665 pid: libc::pid_t,
1666 param: Option<Addr<crate::linux_abi::SchedParam>>,
1667 }
1668}
1669
1670typed_syscall! {
1671 pub struct SchedGetparam {
1672 pid: libc::pid_t,
1673 param: Option<AddrMut<crate::linux_abi::SchedParam>>,
1674 }
1675}
1676
1677typed_syscall! {
1678 pub struct SchedSetscheduler {
1679 pid: libc::pid_t,
1680 policy: i32,
1681 param: Option<Addr<crate::linux_abi::SchedParam>>,
1682 }
1683}
1684
1685typed_syscall! {
1686 pub struct SchedGetscheduler {
1687 pid: libc::pid_t,
1688 }
1689}
1690
1691typed_syscall! {
1692 pub struct SchedGetPriorityMax {
1693 policy: i32,
1694 }
1695}
1696
1697typed_syscall! {
1698 pub struct SchedGetPriorityMin {
1699 policy: i32,
1700 }
1701}
1702
1703typed_syscall! {
1704 pub struct SchedRrGetInterval {
1705 pid: libc::pid_t,
1706 tp: Option<AddrMut<Timespec>>,
1707 }
1708}
1709
1710typed_syscall! {
1711 pub struct Mlock {
1712 addr: Option<Addr<libc::c_void>>,
1713 len: usize,
1714 }
1715}
1716
1717typed_syscall! {
1718 pub struct Munlock {
1719 addr: Option<Addr<libc::c_void>>,
1720 len: usize,
1721 }
1722}
1723
1724typed_syscall! {
1725 pub struct Mlockall {
1726 flags: i32,
1727 }
1728}
1729
1730typed_syscall! { pub struct Munlockall {} }
1731
1732typed_syscall! { pub struct Vhangup {} }
1733
1734#[cfg(not(target_arch = "aarch64"))]
1736typed_syscall! {
1737 pub struct ModifyLdt {
1738 func: i32,
1739 ptr: Option<AddrMut<libc::c_void>>,
1740 bytecount: usize,
1741 }
1742}
1743
1744typed_syscall! {
1745 pub struct PivotRoot {
1746 new_root: Option<PathPtr>,
1747 put_old: Option<PathPtr>,
1748 }
1749}
1750
1751#[cfg(not(target_arch = "aarch64"))]
1753typed_syscall! {
1754 #[allow(non_camel_case_types)]
1755 pub struct _sysctl {
1756 args: Option<AddrMut<libc::c_void>>,
1758 }
1759}
1760
1761typed_syscall! {
1762 pub struct Prctl {
1763 option: i32,
1764 arg2: u64,
1765 arg3: u64,
1766 arg4: u64,
1767 arg5: u64,
1768 }
1769}
1770
1771#[cfg(not(target_arch = "aarch64"))]
1773typed_syscall! {
1774 pub struct ArchPrctl {
1775 cmd: {
1776 fn get(&self) -> args::ArchPrctlCmd {
1777 args::ArchPrctlCmd::from_raw(self.raw.arg0 as i32, self.raw.arg1)
1778 }
1779
1780 fn set(mut self, v: args::ArchPrctlCmd) -> Self {
1781 let (cmd, arg) = v.into_raw();
1782 self.raw.arg0 = cmd as usize;
1783 self.raw.arg1 = arg;
1784 self
1785 }
1786 },
1787 }
1788}
1789
1790typed_syscall! {
1791 pub struct Adjtimex {
1792 buf: Option<AddrMut<libc::timex>>,
1793 }
1794}
1795
1796typed_syscall! {
1797 pub struct Setrlimit {
1798 resource: i32,
1799 rlim: Option<Addr<libc::rlimit>>,
1800 }
1801}
1802
1803typed_syscall! {
1804 pub struct Chroot {
1805 path: Option<PathPtr>,
1806 }
1807}
1808
1809typed_syscall! { pub struct Sync {} }
1810
1811typed_syscall! {
1812 pub struct Acct {
1813 filename: Option<PathPtr>,
1814 }
1815}
1816
1817typed_syscall! {
1818 pub struct Settimeofday {
1819 tv: Option<Addr<libc::timeval>>,
1820 tz: Option<Addr<libc::timezone>>,
1821 }
1822}
1823
1824typed_syscall! {
1825 pub struct Mount {
1826 source: Option<PathPtr>,
1827 target: Option<PathPtr>,
1828 filesystemtype: Option<CStrPtr>,
1829 flags: u64,
1830 data: Option<Addr<libc::c_void>>,
1831 }
1832}
1833
1834typed_syscall! {
1835 pub struct Umount2 {
1836 target: Option<PathPtr>,
1837 flags: i32,
1838 }
1839}
1840
1841typed_syscall! {
1842 pub struct Swapon {
1843 path: Option<PathPtr>,
1844 swapflags: i32,
1845 }
1846}
1847
1848typed_syscall! {
1849 pub struct Swapoff {
1850 path: Option<PathPtr>,
1851 }
1852}
1853
1854typed_syscall! {
1855 pub struct Reboot {
1856 magic1: i32,
1857 magic2: i32,
1858 cmd: u32,
1859 arg: Option<AddrMut<libc::c_void>>,
1860 }
1861}
1862
1863typed_syscall! {
1864 pub struct Sethostname {
1865 name: Option<Addr<libc::c_char>>,
1866 len: usize,
1867 }
1868}
1869
1870typed_syscall! {
1871 pub struct Setdomainname {
1872 name: Option<Addr<libc::c_char>>,
1873 len: usize,
1874 }
1875}
1876
1877#[cfg(not(target_arch = "aarch64"))]
1879typed_syscall! {
1880 pub struct Iopl {
1881 level: u32,
1882 }
1883}
1884
1885#[cfg(not(target_arch = "aarch64"))]
1887typed_syscall! {
1888 pub struct Ioperm {
1889 from: u64,
1890 num: u64,
1891 turn_on: i32,
1892 }
1893}
1894
1895#[cfg(not(target_arch = "aarch64"))]
1897typed_syscall! {
1898 pub struct CreateModule {
1900 name: Option<Addr<libc::c_char>>,
1901 len: usize,
1902 }
1903}
1904
1905typed_syscall! {
1906 pub struct InitModule {
1907 module_image: Option<AddrMut<libc::c_void>>,
1908 len: usize,
1909 param_values: Option<CStrPtr>,
1910 }
1911}
1912
1913typed_syscall! {
1914 pub struct DeleteModule {
1915 name: Option<CStrPtr>,
1916 flags: i32,
1917 }
1918}
1919
1920#[cfg(not(target_arch = "aarch64"))]
1922typed_syscall! {
1923 pub struct GetKernelSyms {
1925 table: Option<AddrMut<libc::c_void>>,
1926 }
1927}
1928
1929#[cfg(not(target_arch = "aarch64"))]
1931typed_syscall! {
1932 pub struct QueryModule {
1933 name: Option<CStrPtr>,
1934 which: i32,
1935 buf: Option<AddrMut<libc::c_void>>,
1936 bufsize: usize,
1937 ret: Option<AddrMut<usize>>,
1938 }
1939}
1940
1941typed_syscall! {
1942 pub struct Quotactl {
1943 cmd: i32,
1944 special: Option<CStrPtr>,
1945 id: i32,
1946 addr: Option<AddrMut<libc::c_void>>,
1947 }
1948}
1949
1950typed_syscall! {
1951 pub struct Nfsservctl {
1954 cmd: i32,
1955 argp: Option<AddrMut<libc::c_void>>,
1956 resp: Option<AddrMut<libc::c_void>>,
1957 }
1958}
1959
1960#[cfg(not(target_arch = "aarch64"))]
1962typed_syscall! {
1963 pub struct Getpmsg {}
1965}
1966
1967#[cfg(not(target_arch = "aarch64"))]
1969typed_syscall! {
1970 pub struct Putpmsg {}
1972}
1973
1974#[cfg(not(target_arch = "aarch64"))]
1976typed_syscall! {
1977 pub struct AfsSyscall {}
1979}
1980
1981#[cfg(not(target_arch = "aarch64"))]
1983typed_syscall! {
1984 pub struct Tuxcall {}
1986}
1987
1988#[cfg(not(target_arch = "aarch64"))]
1990typed_syscall! {
1991 pub struct Security {}
1993}
1994
1995typed_syscall! { pub struct Gettid {} }
1996
1997typed_syscall! {
1998 pub struct Readahead {
1999 fd: i32,
2000 offset: libc::loff_t,
2001 count: usize,
2002 }
2003}
2004
2005typed_syscall! {
2006 pub struct Setxattr {
2007 path: Option<PathPtr>,
2008 name: Option<CStrPtr>,
2009 value: Option<Addr<libc::c_void>>,
2010 size: usize,
2011 flags: i32,
2012 }
2013}
2014
2015typed_syscall! {
2016 pub struct Lsetxattr {
2017 path: Option<PathPtr>,
2018 name: Option<CStrPtr>,
2019 value: Option<Addr<libc::c_void>>,
2020 size: usize,
2021 flags: i32,
2022 }
2023}
2024
2025typed_syscall! {
2026 pub struct Fsetxattr {
2027 fd: i32,
2028 name: Option<CStrPtr>,
2029 value: Option<Addr<libc::c_void>>,
2030 size: usize,
2031 flags: i32,
2032 }
2033}
2034
2035typed_syscall! {
2036 pub struct Getxattr {
2037 path: Option<PathPtr>,
2038 name: Option<CStrPtr>,
2039 value: Option<AddrMut<libc::c_void>>,
2040 size: usize,
2041 }
2042}
2043
2044typed_syscall! {
2045 pub struct Lgetxattr {
2046 path: Option<PathPtr>,
2047 name: Option<CStrPtr>,
2048 value: Option<AddrMut<libc::c_void>>,
2049 size: usize,
2050 }
2051}
2052
2053typed_syscall! {
2054 pub struct Fgetxattr {
2055 fd: i32,
2056 name: Option<CStrPtr>,
2057 value: Option<AddrMut<libc::c_void>>,
2058 size: usize,
2059 }
2060}
2061
2062typed_syscall! {
2063 pub struct Listxattr {
2064 path: Option<PathPtr>,
2065 list: Option<AddrMut<libc::c_char>>,
2066 size: usize,
2067 }
2068}
2069
2070typed_syscall! {
2071 pub struct Llistxattr {
2072 path: Option<PathPtr>,
2073 list: Option<AddrMut<libc::c_char>>,
2074 size: usize,
2075 }
2076}
2077
2078typed_syscall! {
2079 pub struct Flistxattr {
2080 fd: i32,
2081 list: Option<AddrMut<libc::c_char>>,
2082 size: usize,
2083 }
2084}
2085
2086typed_syscall! {
2087 pub struct Removexattr {
2088 path: Option<PathPtr>,
2089 name: Option<CStrPtr>,
2090 }
2091}
2092
2093typed_syscall! {
2094 pub struct Lremovexattr {
2095 path: Option<PathPtr>,
2096 name: Option<CStrPtr>,
2097 }
2098}
2099
2100typed_syscall! {
2101 pub struct Fremovexattr {
2102 fd: i32,
2103 name: Option<CStrPtr>,
2104 }
2105}
2106
2107typed_syscall! {
2108 pub struct Tkill {
2109 tid: libc::pid_t,
2110 sig: libc::c_int,
2111 }
2112}
2113
2114#[cfg(not(target_arch = "aarch64"))]
2116typed_syscall! {
2117 pub struct Time {
2118 tloc: Option<AddrMut<i64>>,
2119 }
2120}
2121
2122typed_syscall! {
2123 pub struct Futex {
2125 uaddr: Option<AddrMut<libc::c_int>>,
2126 futex_op: libc::c_int,
2127 val: libc::c_int,
2128 timeout: Option<Addr<Timespec>>,
2129 uaddr2: Option<AddrMut<libc::c_int>>,
2130 val3: libc::c_int,
2131 }
2132}
2133
2134typed_syscall! {
2135 pub struct SchedSetaffinity {
2136 pid: libc::pid_t,
2137 len: u32,
2138 mask: Option<Addr<libc::c_ulong>>,
2139 }
2140}
2141
2142typed_syscall! {
2143 pub struct SchedGetaffinity {
2144 pid: libc::pid_t,
2145 len: u32,
2146 mask: Option<AddrMut<libc::c_ulong>>,
2147 }
2148}
2149
2150#[cfg(not(target_arch = "aarch64"))]
2152typed_syscall! {
2153 pub struct SetThreadArea {
2154 addr: Option<Addr<libc::c_void>>,
2155 }
2156}
2157
2158typed_syscall! {
2159 pub struct IoSetup {
2160 nr_events: u32,
2161 context: Option<AddrMut<libc::c_ulong>>,
2162 }
2163}
2164
2165typed_syscall! {
2166 pub struct IoDestroy {
2167 context: libc::c_ulong,
2168 }
2169}
2170
2171typed_syscall! {
2172 pub struct IoGetevents {
2173 context: libc::c_ulong,
2174 min_nr: libc::c_long,
2175 nr: libc::c_long,
2176 events: Option<AddrMut<libc::c_void>>,
2178 timeout: Option<Addr<Timespec>>,
2179 }
2180}
2181
2182typed_syscall! {
2183 pub struct IoSubmit {
2184 context: libc::c_ulong,
2185 nr: libc::c_long,
2186 iocb: Option<AddrMut<AddrMut<libc::c_void>>>,
2188 }
2189}
2190
2191typed_syscall! {
2192 pub struct IoCancel {
2193 context: libc::c_ulong,
2194 iocb: Option<AddrMut<libc::c_void>>,
2195 result: Option<AddrMut<libc::c_void>>,
2197 }
2198}
2199
2200#[cfg(not(target_arch = "aarch64"))]
2202typed_syscall! {
2203 pub struct GetThreadArea {
2204 addr: Option<AddrMut<libc::c_void>>,
2205 }
2206}
2207
2208typed_syscall! {
2209 pub struct LookupDcookie {
2210 cookie: u64,
2211 buf: Option<AddrMut<libc::c_char>>,
2212 len: usize,
2213 }
2214}
2215
2216#[cfg(not(target_arch = "aarch64"))]
2218typed_syscall! {
2219 pub struct EpollCreate {
2220 size: i32,
2223 }
2224}
2225
2226#[cfg(not(target_arch = "aarch64"))]
2228typed_syscall! {
2229 pub struct EpollCtlOld {}
2231}
2232
2233#[cfg(not(target_arch = "aarch64"))]
2235typed_syscall! {
2236 pub struct EpollWaitOld {}
2238}
2239
2240typed_syscall! {
2241 pub struct RemapFilePages {
2242 addr: Option<AddrMut<libc::c_void>>,
2243 size: u64,
2244 prot: i32,
2245 pgoff: usize,
2246 flags: i32,
2247 }
2248}
2249
2250typed_syscall! {
2251 pub struct Getdents64 {
2252 fd: u32,
2253 dirent: Option<AddrMut<libc::dirent64>>,
2254 count: u32,
2255 }
2256}
2257
2258typed_syscall! {
2259 pub struct SetTidAddress {
2260 tidptr: Option<AddrMut<libc::c_int>>,
2261 }
2262}
2263
2264typed_syscall! { pub struct RestartSyscall { } }
2265
2266typed_syscall! {
2267 pub struct Semtimedop {
2268 semid: i32,
2269 tsops: Option<AddrMut<libc::sembuf>>,
2270 nsops: u32,
2271 timeout: Option<Addr<Timespec>>,
2272 }
2273}
2274
2275typed_syscall! {
2276 pub struct Fadvise64 {
2277 fd: i32,
2278 offset: libc::loff_t,
2279 len: usize,
2280 advice: i32,
2281 }
2282}
2283
2284typed_syscall! {
2285 pub struct TimerCreate {
2286 clockid: ClockId,
2287 sevp: Option<AddrMut<libc::sigevent>>,
2288 timerid: Option<AddrMut<libc::c_int>>,
2289 }
2290}
2291
2292typed_syscall! {
2293 pub struct TimerSettime {
2294 timerid: libc::c_int,
2295 flags: i32,
2296 new_value: Option<Addr<libc::itimerspec>>,
2297 old_value: Option<AddrMut<libc::itimerspec>>,
2298 }
2299}
2300
2301typed_syscall! {
2302 pub struct TimerGettime {
2303 timerid: libc::c_int,
2304 value: Option<AddrMut<libc::itimerspec>>,
2305 }
2306}
2307
2308typed_syscall! {
2309 pub struct TimerGetoverrun {
2310 timerid: libc::c_int,
2311 }
2312}
2313
2314typed_syscall! {
2315 pub struct TimerDelete {
2316 timerid: libc::c_int,
2317 }
2318}
2319
2320typed_syscall! {
2321 pub struct ClockSettime {
2322 clockid: ClockId,
2323 tp: Option<Addr<Timespec>>,
2324 }
2325}
2326
2327typed_syscall! {
2328 pub struct ClockGettime {
2329 clockid: ClockId,
2330 tp: Option<TimespecMutPtr>,
2331 }
2332}
2333
2334typed_syscall! {
2335 pub struct ClockGetres {
2336 clockid: ClockId,
2337 res: Option<AddrMut<Timespec>>,
2338 }
2339}
2340
2341typed_syscall! {
2342 pub struct ClockNanosleep {
2343 clockid: ClockId,
2344 flags: i32,
2345 req: Option<Addr<Timespec>>,
2346 rem: Option<AddrMut<Timespec>>,
2347 }
2348}
2349
2350typed_syscall! {
2351 pub struct ExitGroup {
2352 status: libc::c_int,
2353 }
2354}
2355
2356#[cfg(not(target_arch = "aarch64"))]
2358typed_syscall! {
2359 pub struct EpollWait {
2360 epfd: i32,
2361 events: Option<AddrMut<libc::epoll_event>>,
2362 maxevents: i32,
2363 timeout: i32, }
2365}
2366
2367typed_syscall! {
2368 pub struct EpollCtl {
2369 epfd: i32,
2370 op: i32,
2371 fd: i32,
2372 event: Option<AddrMut<libc::epoll_event>>,
2373 }
2374}
2375
2376typed_syscall! {
2377 pub struct Tgkill {
2378 tgid: libc::pid_t,
2379 tid: libc::pid_t,
2380 sig: libc::c_int,
2381 }
2382}
2383
2384#[cfg(not(target_arch = "aarch64"))]
2386typed_syscall! {
2387 pub struct Utimes {
2388 filename: Option<PathPtr>,
2389 times: Option<Addr<[libc::timeval; 2]>>,
2390 }
2391}
2392
2393#[cfg(not(target_arch = "aarch64"))]
2395typed_syscall! {
2396 pub struct Vserver { }
2398}
2399
2400typed_syscall! {
2401 pub struct Mbind {
2402 addr: Option<AddrMut<libc::c_void>>,
2403 len: u64,
2404 mode: i32,
2405 nodemask: Option<Addr<libc::c_ulong>>,
2406 maxnode: u64,
2407 flags: u32,
2408 }
2409}
2410
2411typed_syscall! {
2412 pub struct SetMempolicy {
2413 mode: i32,
2414 nodemask: Option<Addr<libc::c_ulong>>,
2415 maxnode: u64,
2416 }
2417}
2418
2419typed_syscall! {
2420 pub struct GetMempolicy {
2421 policy: Option<AddrMut<libc::c_int>>,
2422 nodemask: Option<Addr<libc::c_ulong>>,
2423 maxnode: u64,
2424 addr: Option<Addr<libc::c_void>>,
2425 flags: u32,
2426 }
2427}
2428
2429typed_syscall! {
2430 pub struct MqOpen {
2431 name: Option<PathPtr>,
2432 oflag: i32,
2433 mode: libc::mode_t,
2434 attr: Option<AddrMut<libc::mq_attr>>,
2435 }
2436}
2437
2438typed_syscall! {
2439 pub struct MqUnlink {
2440 name: Option<PathPtr>,
2441 }
2442}
2443
2444typed_syscall! {
2445 pub struct MqTimedsend {
2446 mqdes: libc::mqd_t,
2447 msg: Option<Addr<libc::c_char>>,
2448 msg_len: usize,
2449 priority: u32,
2450 timeout: Option<Addr<Timespec>>,
2451 }
2452}
2453
2454typed_syscall! {
2455 pub struct MqTimedreceive {
2456 mqdes: libc::mqd_t,
2457 msg: Option<AddrMut<libc::c_char>>,
2458 msg_len: usize,
2459 priority: u32,
2460 timeout: Option<Addr<Timespec>>,
2461 }
2462}
2463
2464typed_syscall! {
2465 pub struct MqNotify {
2466 mqdes: libc::mqd_t,
2467 sevp: Option<Addr<libc::sigevent>>,
2468 }
2469}
2470
2471typed_syscall! {
2472 pub struct MqGetsetattr {
2473 mqdes: libc::mqd_t,
2474 newattr: Option<Addr<libc::mq_attr>>,
2475 oldattr: Option<AddrMut<libc::mq_attr>>,
2476 }
2477}
2478
2479typed_syscall! {
2480 pub struct KexecLoad {
2481 entry: u64,
2482 nr_segments: u64,
2483 segments: Option<Addr<libc::c_void>>,
2485 flags: u64,
2486 }
2487}
2488
2489typed_syscall! {
2490 pub struct Waitid {
2491 which: i32,
2492 pid: libc::pid_t,
2493 info: Option<AddrMut<libc::siginfo_t>>,
2494 options: i32,
2495 rusage: Option<AddrMut<libc::rusage>>,
2496 }
2497}
2498
2499typed_syscall! {
2500 pub struct AddKey {
2501 key_type: Option<CStrPtr>,
2502 description: Option<CStrPtr>,
2503 payload: Option<Addr<libc::c_void>>,
2504 payload_len: usize,
2505 keyring: libc::c_int,
2506 }
2507}
2508
2509typed_syscall! {
2510 pub struct RequestKey {
2511 key_type: Option<CStrPtr>,
2512 description: Option<CStrPtr>,
2513 callout_info: Option<CStrPtr>,
2514 dest_keyring: libc::c_int,
2515 }
2516}
2517
2518typed_syscall! {
2519 pub struct Keyctl {
2520 option: i32,
2521 arg2: u64,
2522 arg3: u64,
2523 arg4: u64,
2524 arg6: u64,
2525 }
2526}
2527
2528typed_syscall! {
2529 pub struct IoprioSet {
2530 which: i32,
2531 who: i32,
2532 priority: i32,
2533 }
2534}
2535
2536typed_syscall! {
2537 pub struct IoprioGet {
2538 which: i32,
2539 who: i32,
2540 }
2541}
2542
2543#[cfg(not(target_arch = "aarch64"))]
2545typed_syscall! { pub struct InotifyInit {} }
2546
2547typed_syscall! {
2548 pub struct InotifyAddWatch {
2549 fd: i32,
2550 path: Option<PathPtr>,
2551 mask: u32,
2552 }
2553}
2554
2555typed_syscall! {
2556 pub struct InotifyRmWatch {
2557 fd: i32,
2558 wd: i32,
2559 }
2560}
2561
2562typed_syscall! {
2563 pub struct MigratePages {
2564 pid: libc::pid_t,
2565 maxnode: u64,
2566 old_nodes: Option<Addr<libc::c_ulong>>,
2567 new_nodes: Option<Addr<libc::c_ulong>>,
2568 }
2569}
2570
2571typed_syscall! {
2572 pub struct Openat {
2573 dirfd: i32,
2574 path: Option<PathPtr>,
2575 flags: OFlag,
2576
2577 mode?: {
2580 fn get(&self) -> Option<Mode> {
2581 get_mode(self.flags(), self.raw.arg3)
2582 }
2583
2584 fn set(mut self, v: Option<Mode>) -> Self {
2585 self.raw.arg3 = v.into_raw();
2586 self
2587 }
2588 },
2589 }
2590}
2591
2592#[repr(C)]
2595#[derive(Debug, Clone, Copy, Default)]
2596pub struct OpenHow {
2597 pub flags: u64,
2599 pub mode: u64,
2601 pub resolve: u64,
2603}
2604
2605typed_syscall! {
2606 pub struct Openat2 {
2616 dirfd: i32,
2618 path: Option<PathPtr>,
2620 how: Option<Addr<OpenHow>>,
2622 size: usize,
2624 }
2625}
2626
2627#[cfg(not(target_arch = "aarch64"))]
2629impl From<Open> for Openat {
2630 fn from(open: Open) -> Self {
2634 let Open { mut raw } = open;
2635 raw.arg3 = raw.arg2;
2636 raw.arg2 = raw.arg1;
2637 raw.arg1 = raw.arg0;
2638 raw.arg0 = libc::AT_FDCWD as usize;
2639 Openat { raw }
2640 }
2641}
2642
2643#[cfg(not(target_arch = "aarch64"))]
2645impl From<Creat> for Openat {
2646 fn from(creat: Creat) -> Self {
2649 let Creat { mut raw } = creat;
2650 raw.arg3 = raw.arg1;
2651 raw.arg2 = (libc::O_CREAT | libc::O_WRONLY | libc::O_TRUNC) as usize;
2652 raw.arg1 = raw.arg0;
2653 raw.arg0 = libc::AT_FDCWD as usize;
2654 Openat { raw }
2655 }
2656}
2657
2658typed_syscall! {
2659 pub struct Mkdirat {
2660 dirfd: i32,
2661 path: Option<PathPtr>,
2662 mode: Mode,
2663 }
2664}
2665
2666#[cfg(not(target_arch = "aarch64"))]
2668impl From<Mkdir> for Mkdirat {
2669 fn from(syscall: Mkdir) -> Self {
2673 let Mkdir { mut raw } = syscall;
2674 raw.arg2 = raw.arg1;
2675 raw.arg1 = raw.arg0;
2676 raw.arg0 = libc::AT_FDCWD as usize;
2677 Mkdirat { raw }
2678 }
2679}
2680
2681typed_syscall! {
2682 pub struct Mknodat {
2683 dirfd: i32,
2684 path: Option<PathPtr>,
2685 mode: Mode,
2686 dev: libc::dev_t,
2687 }
2688}
2689
2690#[cfg(not(target_arch = "aarch64"))]
2692impl From<Mknod> for Mknodat {
2693 fn from(syscall: Mknod) -> Self {
2697 let Mknod { mut raw } = syscall;
2698 raw.arg3 = raw.arg2;
2699 raw.arg2 = raw.arg1;
2700 raw.arg1 = raw.arg0;
2701 raw.arg0 = libc::AT_FDCWD as usize;
2702 Mknodat { raw }
2703 }
2704}
2705
2706typed_syscall! {
2707 pub struct Fchownat {
2708 dirfd: i32,
2709 path: Option<PathPtr>,
2710 owner: libc::uid_t,
2711 group: libc::gid_t,
2712 flags: AtFlags,
2713 }
2714}
2715
2716#[cfg(not(target_arch = "aarch64"))]
2718typed_syscall! {
2719 pub struct Futimesat {
2720 dirfd: i32,
2721 path: Option<PathPtr>,
2722 utimes: Option<Addr<[libc::timeval; 2]>>,
2723 }
2724}
2725
2726#[cfg(target_arch = "x86_64")]
2728typed_syscall! {
2729 pub struct Newfstatat {
2730 dirfd: i32,
2731 path: Option<PathPtr>,
2732 stat: Option<StatPtr>,
2733 flags: AtFlags,
2734 }
2735}
2736
2737#[cfg(target_arch = "x86_64")]
2740pub type Fstatat = Newfstatat;
2741
2742#[cfg(target_arch = "aarch64")]
2743typed_syscall! {
2744 pub struct Fstatat {
2745 dirfd: i32,
2746 path: Option<PathPtr>,
2747 stat: Option<StatPtr>,
2748 flags: AtFlags,
2749 }
2750}
2751
2752#[cfg(target_arch = "x86_64")]
2754impl From<Stat> for Fstatat {
2755 fn from(stat: Stat) -> Self {
2756 let Stat { mut raw } = stat;
2757 raw.arg3 = 0;
2758 raw.arg2 = raw.arg1;
2759 raw.arg1 = raw.arg0;
2760 raw.arg0 = libc::AT_FDCWD as usize;
2761 Self { raw }
2762 }
2763}
2764
2765#[cfg(target_arch = "x86_64")]
2767impl From<Lstat> for Fstatat {
2768 fn from(lstat: Lstat) -> Self {
2769 let Lstat { mut raw } = lstat;
2770 raw.arg3 = AtFlags::AT_SYMLINK_NOFOLLOW.bits() as usize;
2771 raw.arg2 = raw.arg1;
2772 raw.arg1 = raw.arg0;
2773 raw.arg0 = libc::AT_FDCWD as usize;
2774 Self { raw }
2775 }
2776}
2777
2778typed_syscall! {
2779 pub struct Unlinkat {
2780 dirfd: i32,
2781 path: Option<PathPtr>,
2782 flags: AtFlags,
2783 }
2784}
2785
2786#[cfg(not(target_arch = "aarch64"))]
2788impl From<Unlink> for Unlinkat {
2789 fn from(unlink: Unlink) -> Self {
2790 let Unlink { mut raw } = unlink;
2791 raw.arg2 = 0;
2792 raw.arg1 = raw.arg0;
2793 raw.arg0 = libc::AT_FDCWD as usize;
2794 Unlinkat { raw }
2795 }
2796}
2797
2798#[cfg(not(target_arch = "aarch64"))]
2800impl From<Rmdir> for Unlinkat {
2801 fn from(rmdir: Rmdir) -> Self {
2802 let Rmdir { mut raw } = rmdir;
2803 raw.arg2 = libc::AT_REMOVEDIR as usize;
2804 raw.arg1 = raw.arg0;
2805 raw.arg0 = libc::AT_FDCWD as usize;
2806 Unlinkat { raw }
2807 }
2808}
2809
2810typed_syscall! {
2811 pub struct Renameat {
2812 olddirfd: i32,
2813 oldpath: Option<PathPtr>,
2814 newdirfd: i32,
2815 newpath: Option<PathPtr>,
2816 }
2817}
2818
2819typed_syscall! {
2820 pub struct Linkat {
2821 olddirfd: i32,
2822 oldpath: Option<PathPtr>,
2823 newdirfd: i32,
2824 newpath: Option<PathPtr>,
2825 flags: AtFlags,
2826 }
2827}
2828
2829#[cfg(not(target_arch = "aarch64"))]
2831impl From<Link> for Linkat {
2832 fn from(link: Link) -> Self {
2838 let Link { mut raw } = link;
2839 raw.arg3 = raw.arg1;
2840 raw.arg1 = raw.arg0;
2841 raw.arg0 = libc::AT_FDCWD as usize;
2842 raw.arg2 = libc::AT_FDCWD as usize;
2843 raw.arg4 = 0;
2844 Linkat { raw }
2845 }
2846}
2847
2848typed_syscall! {
2849 pub struct Symlinkat {
2850 target: Option<PathPtr>,
2851 newdirfd: i32,
2852 linkpath: Option<PathPtr>,
2853 }
2854}
2855
2856typed_syscall! {
2857 pub struct Readlinkat {
2858 dirfd: i32,
2859 path: Option<PathPtr>,
2860 buf: Option<AddrMut<libc::c_char>>,
2861 buf_len: usize,
2862 }
2863}
2864
2865typed_syscall! {
2866 pub struct Fchmodat {
2867 dirfd: i32,
2868 path: Option<PathPtr>,
2869 mode: Mode,
2870 }
2871}
2872
2873typed_syscall! {
2874 pub struct Fchmodat2 {
2875 dirfd: i32,
2876 path: Option<PathPtr>,
2877 mode: Mode,
2878 flags: AtFlags,
2879 }
2880}
2881
2882typed_syscall! {
2883 pub struct Faccessat {
2884 dirfd: i32,
2885 path: Option<PathPtr>,
2886 mode: Mode,
2887 flags: AtFlags,
2888 }
2889}
2890
2891typed_syscall! {
2892 pub struct Pselect6 {
2893 nfds: i32,
2894 readfds: Option<AddrMut<libc::fd_set>>,
2895 writefds: Option<AddrMut<libc::fd_set>>,
2896 exceptfds: Option<AddrMut<libc::fd_set>>,
2897 timeout: Option<AddrMut<Timespec>>,
2902 sigmask: Option<Addr<libc::sigset_t>>,
2903 }
2904}
2905
2906typed_syscall! {
2908 pub struct Ppoll {
2909 fds: Option<AddrMut<libc::pollfd>>,
2910 nfds: libc::nfds_t,
2911 timeout: Option<AddrMut<Timespec>>,
2912 sigmask: Option<Addr<libc::sigset_t>>,
2913 sigsetsize: usize,
2914 }
2915}
2916
2917typed_syscall! {
2918 pub struct Unshare {
2919 flags: CloneFlags,
2920 }
2921}
2922
2923typed_syscall! {
2924 pub struct SetRobustList {
2925 head: Option<AddrMut<libc::c_void>>,
2927 len: usize,
2928 }
2929}
2930
2931typed_syscall! {
2932 pub struct GetRobustList {
2933 pid: libc::pid_t,
2934 head_ptr: Option<AddrMut<AddrMut<libc::c_void>>>,
2936 len_ptr: Option<AddrMut<usize>>,
2937 }
2938}
2939
2940typed_syscall! {
2941 pub struct Splice {
2942 fd_in: i32,
2943 off_in: Option<AddrMut<libc::loff_t>>,
2944 fd_out: i32,
2945 off_out: Option<AddrMut<libc::loff_t>>,
2946 len: usize,
2947 flags: u32,
2948 }
2949}
2950
2951typed_syscall! {
2952 pub struct Tee {
2953 fd_in: i32,
2954 fd_out: i32,
2955 len: usize,
2956 flags: u32,
2957 }
2958}
2959
2960#[cfg(not(target_arch = "aarch64"))]
2962typed_syscall! {
2963 pub struct SyncFileRange {
2964 fd: i32,
2965 offset: libc::loff_t,
2966 nbytes: libc::loff_t,
2967 flags: u32,
2968 }
2969}
2970
2971typed_syscall! {
2972 pub struct Vmsplice {
2973 fd: i32,
2974 iov: Option<Addr<libc::iovec>>,
2975 nr_segs: u64,
2976 flags: u32,
2977 }
2978}
2979
2980typed_syscall! {
2981 pub struct MovePages {
2982 pid: libc::pid_t,
2983 nr_pages: u64,
2984 pages: Option<Addr<Addr<libc::c_void>>>,
2985 nodes: Option<Addr<Addr<i32>>>,
2986 status: Option<AddrMut<i32>>,
2987 flags: i32,
2988 }
2989}
2990
2991typed_syscall! {
2992 pub struct Utimensat {
2993 dirfd: i32,
2994 path: Option<PathPtr>,
2995 times: Option<Addr<[Timespec; 2]>>,
2996 flags: i32,
2997 }
2998}
2999
3000typed_syscall! {
3001 pub struct EpollPwait {
3002 epfd: i32,
3003 events: Option<AddrMut<libc::epoll_event>>,
3004 maxevents: i32,
3005 timeout: i32,
3006 sigmask: Option<Addr<libc::sigset_t>>,
3007 sigsetsize: usize,
3008 }
3009}
3010
3011#[cfg(not(target_arch = "aarch64"))]
3013typed_syscall! {
3014 pub struct Signalfd {
3021 fd: i32,
3022 mask: Option<AddrMut<libc::sigset_t>>,
3023 size: usize,
3024 }
3025}
3026
3027typed_syscall! {
3028 pub struct TimerfdCreate {
3029 clockid: ClockId,
3030 flags: TimerFlags,
3031 }
3032}
3033
3034#[cfg(not(target_arch = "aarch64"))]
3036typed_syscall! {
3037 pub struct Eventfd {
3038 count: u32,
3039 }
3040}
3041
3042typed_syscall! {
3043 pub struct Fallocate {
3044 fd: i32,
3045 mode: i32,
3046 offset: libc::loff_t,
3047 len: libc::loff_t,
3048 }
3049}
3050
3051typed_syscall! {
3052 pub struct TimerfdSettime {
3053 fd: i32,
3054 flags: i32,
3055 new_value: Option<Addr<libc::itimerspec>>,
3056 old_value: Option<AddrMut<libc::itimerspec>>,
3057 }
3058}
3059
3060typed_syscall! {
3061 pub struct TimerfdGettime {
3062 fd: i32,
3063 value: Option<AddrMut<libc::itimerspec>>,
3064 }
3065}
3066
3067typed_syscall! {
3068 pub struct Accept4 {
3069 sockfd: i32,
3070 sockaddr: Option<AddrMut<libc::sockaddr>>,
3071 addrlen: Option<AddrMut<usize>>,
3072 flags: SockFlag,
3073 }
3074}
3075
3076impl From<Accept> for Accept4 {
3077 fn from(accept: Accept) -> Self {
3079 let Accept { mut raw } = accept;
3080 raw.arg3 = 0;
3081 Accept4 { raw }
3082 }
3083}
3084
3085typed_syscall! {
3086 pub struct Signalfd4 {
3091 fd: i32,
3092 mask: Option<AddrMut<libc::sigset_t>>,
3093 size: usize,
3094 flags: SfdFlags,
3095 }
3096}
3097
3098#[cfg(not(target_arch = "aarch64"))]
3100impl From<Signalfd> for Signalfd4 {
3101 fn from(signalfd: Signalfd) -> Self {
3102 let Signalfd { mut raw } = signalfd;
3103 raw.arg3 = 0;
3104 Signalfd4 { raw }
3105 }
3106}
3107
3108typed_syscall! {
3109 pub struct Eventfd2 {
3110 count: u32,
3111 flags: EfdFlags,
3112 }
3113}
3114
3115#[cfg(not(target_arch = "aarch64"))]
3117impl From<Eventfd> for Eventfd2 {
3118 fn from(eventfd: Eventfd) -> Self {
3122 let Eventfd { mut raw } = eventfd;
3123 raw.arg1 = 0;
3124 Eventfd2 { raw }
3125 }
3126}
3127
3128typed_syscall! {
3129 pub struct EpollCreate1 {
3130 flags: EpollCreateFlags,
3131 }
3132}
3133
3134#[cfg(not(target_arch = "aarch64"))]
3136impl From<EpollCreate> for EpollCreate1 {
3137 fn from(epoll_create: EpollCreate) -> Self {
3142 let EpollCreate { mut raw } = epoll_create;
3143 raw.arg0 = 0;
3144 EpollCreate1 { raw }
3145 }
3146}
3147
3148typed_syscall! {
3149 pub struct Dup3 {
3150 oldfd: i32,
3151 newfd: i32,
3152 flags: OFlag,
3153 }
3154}
3155
3156typed_syscall! {
3157 pub struct Pipe2 {
3158 pipefd: Option<AddrMut<[i32; 2]>>,
3159 flags: OFlag,
3160 }
3161}
3162
3163#[cfg(not(target_arch = "aarch64"))]
3165impl From<Pipe> for Pipe2 {
3166 fn from(pipe: Pipe) -> Self {
3168 let Pipe { mut raw } = pipe;
3169 raw.arg1 = 0;
3170 Pipe2 { raw }
3171 }
3172}
3173
3174typed_syscall! {
3175 pub struct InotifyInit1 {
3176 flags: InitFlags,
3177 }
3178}
3179
3180#[cfg(not(target_arch = "aarch64"))]
3182impl From<InotifyInit> for InotifyInit1 {
3183 fn from(inotify_init: InotifyInit) -> Self {
3187 let InotifyInit { mut raw } = inotify_init;
3188 raw.arg0 = 0;
3189 InotifyInit1 { raw }
3190 }
3191}
3192
3193typed_syscall! {
3194 pub struct Preadv {
3195 fd: i32,
3196 iov: Option<Addr<libc::iovec>>,
3197 iov_len: usize,
3198 pos_l: u64,
3199 pos_h: u64,
3200 }
3201}
3202
3203typed_syscall! {
3204 pub struct Pwritev {
3205 fd: i32,
3206 iov: Option<Addr<libc::iovec>>,
3207 iov_len: usize,
3208 pos_l: u64,
3209 pos_h: u64,
3210 }
3211}
3212
3213typed_syscall! {
3214 pub struct RtTgsigqueueinfo {
3215 tgid: libc::pid_t,
3216 tid: libc::pid_t,
3217 sig: i32,
3218 siginfo: Option<AddrMut<libc::siginfo_t>>,
3219 }
3220}
3221
3222typed_syscall! {
3223 pub struct PerfEventOpen {
3224 attr: Option<AddrMut<libc::c_void>>,
3226 pid: libc::pid_t,
3227 cpu: i32,
3228 group_fd: i32,
3229 flags: u64,
3230 }
3231}
3232
3233typed_syscall! {
3234 pub struct Recvmmsg {
3235 fd: i32,
3236 mmsg: Option<AddrMut<crate::linux_abi::Mmsghdr>>,
3237 vlen: u32,
3238 flags: u32,
3239 timeout: Option<Addr<Timespec>>,
3240 }
3241}
3242
3243typed_syscall! {
3244 pub struct FanotifyInit {
3245 flags: u32,
3246 event_f_flags: u32,
3247 }
3248}
3249
3250typed_syscall! {
3251 pub struct FanotifyMark {
3252 fanotify_fd: i32,
3253 flags: u32,
3254 mask: u64,
3255 dirfd: i32,
3256 pathname: Option<PathPtr>,
3257 }
3258}
3259
3260typed_syscall! {
3261 pub struct Prlimit64 {
3262 pid: libc::pid_t,
3263 resource: u32,
3264 new_rlim: Option<Addr<libc::rlimit64>>,
3265 old_rlim: Option<AddrMut<libc::rlimit64>>,
3266 }
3267}
3268
3269typed_syscall! {
3270 pub struct NameToHandleAt {
3271 dirfd: i32,
3272 pathname: Option<PathPtr>,
3273 handle: Option<AddrMut<libc::c_void>>,
3275 mount_id: Option<AddrMut<i32>>,
3276 flags: i32,
3277 }
3278}
3279
3280typed_syscall! {
3281 pub struct OpenByHandleAt {
3282 mount_fd: i32,
3283 handle: Option<AddrMut<libc::c_void>>,
3285 flags: i32,
3286 }
3287}
3288
3289typed_syscall! {
3290 pub struct ClockAdjtime {
3291 clockid: ClockId,
3292 buf: Option<AddrMut<libc::timex>>,
3293 }
3294}
3295
3296typed_syscall! {
3297 pub struct Syncfs {
3298 fd: i32,
3299 }
3300}
3301
3302typed_syscall! {
3303 pub struct Sendmmsg {
3304 sockfd: i32,
3305 msgvec: Option<Addr<crate::linux_abi::Msghdr>>,
3306 vlen: u32,
3307 flags: i32,
3308 }
3309}
3310
3311typed_syscall! {
3312 pub struct Setns {
3313 fd: i32,
3314 nstype: CloneFlags,
3315 }
3316}
3317
3318typed_syscall! {
3321 pub struct Getcpu {
3322 cpu: Option<AddrMut<u32>>,
3323 node: Option<AddrMut<u32>>,
3324 }
3325}
3326
3327typed_syscall! {
3328 pub struct ProcessVmReadv {
3329 pid: libc::pid_t,
3330 local_iov: Option<Addr<libc::iovec>>,
3331 local_iov_count: u64,
3332 remote_iov: Option<Addr<libc::iovec>>,
3333 remote_iov_count: u64,
3334 flags: u64,
3335 }
3336}
3337
3338typed_syscall! {
3339 pub struct ProcessVmWritev {
3340 pid: libc::pid_t,
3341 local_iov: Option<Addr<libc::iovec>>,
3342 local_iov_count: u64,
3343 remote_iov: Option<Addr<libc::iovec>>,
3344 remote_iov_count: u64,
3345 flags: u64,
3346 }
3347}
3348
3349typed_syscall! {
3350 pub struct Kcmp {
3351 pid1: libc::pid_t,
3352 pid2: libc::pid_t,
3353 typ: i32,
3354 idx1: u64,
3355 idx2: u64,
3356 }
3357}
3358
3359typed_syscall! {
3360 pub struct FinitModule {
3361 fd: i32,
3362 param_values: Option<CStrPtr>,
3363 flags: i32,
3364 }
3365}
3366
3367typed_syscall! {
3368 pub struct SchedSetattr {
3369 pid: libc::pid_t,
3370 attr: Option<AddrMut<libc::c_void >>,
3371 flags: u32,
3372 }
3373}
3374
3375typed_syscall! {
3376 pub struct SchedGetattr {
3377 pid: libc::pid_t,
3378 attr: Option<AddrMut<libc::c_void>>,
3380 size: u32,
3381 flags: u32,
3382 }
3383}
3384
3385typed_syscall! {
3386 pub struct Renameat2 {
3387 olddirfd: i32,
3388 oldpath: Option<PathPtr>,
3389 newdirfd: i32,
3390 newpath: Option<PathPtr>,
3391 flags: libc::c_uint,
3393 }
3394}
3395
3396#[cfg(not(target_arch = "aarch64"))]
3398impl From<Rename> for Renameat2 {
3399 fn from(rename: Rename) -> Self {
3400 let Rename { mut raw } = rename;
3401 raw.arg4 = 0;
3402 raw.arg3 = raw.arg1;
3403 raw.arg2 = libc::AT_FDCWD as usize;
3404 raw.arg1 = raw.arg0;
3405 raw.arg0 = libc::AT_FDCWD as usize;
3406 Renameat2 { raw }
3407 }
3408}
3409
3410impl From<Renameat> for Renameat2 {
3411 fn from(renameat: Renameat) -> Self {
3412 let Renameat { mut raw } = renameat;
3413 raw.arg4 = 0;
3414 Renameat2 { raw }
3415 }
3416}
3417
3418typed_syscall! {
3419 pub struct Seccomp {
3420 op: u32,
3421 flags: u32,
3422 args: Option<AddrMut<libc::c_void>>,
3423 }
3424}
3425
3426typed_syscall! {
3427 pub struct Getrandom {
3428 buf: Option<AddrMut<u8>>,
3431 buflen: usize,
3432 flags: usize,
3433 }
3434}
3435
3436typed_syscall! {
3437 pub struct MemfdCreate {
3438 name: Option<PathPtr>,
3439 flags: u32,
3440 }
3441}
3442
3443typed_syscall! {
3444 pub struct PidfdOpen {
3445 pid: u32,
3446 flags: u32,
3447 }
3448}
3449
3450typed_syscall! {
3451 pub struct KexecFileLoad {
3452 kernel_fd: i32,
3453 initrd_fd: i32,
3454 cmdline_len: u64,
3455 cmdline: Option<Addr<libc::c_char>>,
3456 flags: u64,
3457 }
3458}
3459
3460typed_syscall! {
3461 pub struct Bpf {
3462 cmd: i32,
3463 attr: Option<AddrMut<libc::c_void >>,
3464 size: u32,
3465 }
3466}
3467
3468typed_syscall! {
3469 pub struct Execveat {
3470 dirfd: i32,
3471 path: Option<PathPtr>,
3472 argv: Option<CArrayPtr<CStrPtr>>,
3473 envp: Option<CArrayPtr<CStrPtr>>,
3474 flags: i32,
3475 }
3476}
3477
3478impl From<Execve> for Execveat {
3479 fn from(execve: Execve) -> Self {
3483 let Execve { mut raw } = execve;
3484 raw.arg4 = 0; raw.arg3 = raw.arg2;
3486 raw.arg2 = raw.arg1;
3487 raw.arg1 = raw.arg0;
3488 raw.arg0 = libc::AT_FDCWD as usize;
3489 Execveat { raw }
3490 }
3491}
3492
3493typed_syscall! {
3494 pub struct Userfaultfd {
3495 flags: i32,
3496 }
3497}
3498
3499typed_syscall! {
3500 pub struct Membarrier {
3501 cmd: i32,
3502 flags: i32,
3503 }
3504}
3505
3506typed_syscall! {
3507 pub struct Mlock2 {
3508 addr: Option<Addr<libc::c_void>>,
3509 len: usize,
3510 flags: i32,
3511 }
3512}
3513
3514typed_syscall! {
3515 pub struct CopyFileRange {
3516 fd_in: i32,
3517 off_in: Option<AddrMut<libc::loff_t>>,
3518 fd_out: i32,
3519 off_out: Option<AddrMut<libc::loff_t>>,
3520 len: usize,
3521 flags: u32,
3522 }
3523}
3524
3525typed_syscall! {
3526 pub struct Preadv2 {
3527 fd: i32,
3528 iov: Option<Addr<libc::iovec>>,
3529 iov_len: u64,
3530 pos_l: u64,
3531 pos_h: u64,
3532 flags: i32,
3533 }
3534}
3535
3536typed_syscall! {
3537 pub struct Pwritev2 {
3538 fd: i32,
3539 iov: Option<Addr<libc::iovec>>,
3540 iov_len: u64,
3541 pos_l: u64,
3542 pos_h: u64,
3543 flags: i32,
3544 }
3545}
3546
3547typed_syscall! {
3548 pub struct PkeyMprotect {
3549 addr: Option<AddrMut<libc::c_void>>,
3550 len: usize,
3551 prot: i32,
3552 pkey: i32,
3553 }
3554}
3555
3556typed_syscall! {
3557 pub struct PkeyAlloc {
3558 flags: u64,
3559 access_rights: u64,
3560 }
3561}
3562
3563typed_syscall! {
3564 pub struct PkeyFree {
3565 pkey: i32,
3566 }
3567}
3568
3569typed_syscall! {
3570 pub struct Statx {
3571 dirfd: i32,
3572 path: Option<PathPtr>,
3573 flags: AtFlags,
3574 mask: StatxMask,
3575 statx: Option<StatxPtr>,
3576 }
3577}
3578
3579typed_syscall! {
3580 pub struct IoUringSetup {
3581 entries: u32,
3582 params: Option<AddrMut<args::IoUringParams>>,
3583 }
3584}
3585
3586typed_syscall! {
3587 pub struct IoUringEnter {
3588 fd: u32,
3589 to_submit: u32,
3590 min_complete: u32,
3591 flags: u32,
3592 sig: Option<Addr<libc::sigset_t>>,
3593 sigsz: usize,
3594 }
3595}
3596
3597typed_syscall! {
3598 pub struct IoUringRegister {
3599 fd: u32,
3600 opcode: u32,
3601 arg: Option<AddrMut<libc::c_void>>,
3602 nr_args: u32,
3603 }
3604}
3605
3606typed_syscall! {
3607 pub struct Clone3 {
3608 args: Option<AddrMut<CloneArgs>>,
3609 size: usize,
3610 }
3611}
3612
3613#[cfg(test)]
3614mod test {
3615 use std::ffi::CString;
3616 use std::path::Path;
3617
3618 use syscalls::SyscallArgs;
3619 use syscalls::Sysno;
3620
3621 use super::*;
3622 use crate::Displayable;
3623 use crate::LocalMemory;
3624 use crate::ReadAddr;
3625
3626 #[test]
3627 fn fchmodat_variants_have_distinct_arities_and_preserve_raw_registers() {
3628 let memory = LocalMemory::new();
3629 let old_raw = SyscallArgs::new(
3630 libc::AT_FDCWD as usize,
3631 0,
3632 0o600,
3633 0xdead_beef,
3634 0xfeed_face,
3635 0xcafe_babe,
3636 );
3637 let old = Syscall::from_raw(Sysno::fchmodat, old_raw);
3638 assert!(matches!(old, Syscall::Fchmodat(_)));
3639 assert_eq!(
3640 format!("{}", old.display(&memory)),
3641 "fchmodat(-100, NULL, Mode(S_IRUSR | S_IWUSR))"
3642 );
3643 let (number, raw) = old.into_parts();
3644 assert_eq!(number, Sysno::fchmodat);
3645 assert_eq!(
3646 [raw.arg0, raw.arg1, raw.arg2, raw.arg3, raw.arg4, raw.arg5],
3647 [
3648 libc::AT_FDCWD as usize,
3649 0,
3650 0o600,
3651 0xdead_beef,
3652 0xfeed_face,
3653 0xcafe_babe,
3654 ]
3655 );
3656
3657 let flags = AtFlags::AT_SYMLINK_NOFOLLOW | AtFlags::AT_EMPTY_PATH;
3658 let new_raw = SyscallArgs::new(
3659 libc::AT_FDCWD as usize,
3660 0,
3661 0o600,
3662 flags.bits() as usize,
3663 0xdead_beef,
3664 0xcafe_babe,
3665 );
3666 let new = Syscall::from_raw(Sysno::fchmodat2, new_raw);
3667 assert!(matches!(new, Syscall::Fchmodat2(_)));
3668 let rendered = format!("{}", new.display(&memory));
3669 assert!(rendered.starts_with("fchmodat2(-100, NULL, Mode(S_IRUSR | S_IWUSR), AtFlags("));
3670 assert!(rendered.contains("AT_SYMLINK_NOFOLLOW"));
3671 assert!(rendered.contains("AT_EMPTY_PATH"));
3672 assert_eq!(rendered.matches(", ").count(), 3);
3673 assert!(!rendered.contains("3735928559"));
3674 assert!(!rendered.contains("3405691582"));
3675 let (number, raw) = new.into_parts();
3676 assert_eq!(number, Sysno::fchmodat2);
3677 assert_eq!(
3678 [raw.arg0, raw.arg1, raw.arg2, raw.arg3, raw.arg4, raw.arg5],
3679 [
3680 libc::AT_FDCWD as usize,
3681 0,
3682 0o600,
3683 flags.bits() as usize,
3684 0xdead_beef,
3685 0xcafe_babe,
3686 ]
3687 );
3688 }
3689
3690 #[test]
3691 fn test_syscall_openat_path() {
3692 assert_eq!(Openat::NAME, "openat");
3693 assert_eq!(Openat::NUMBER, Sysno::openat);
3694
3695 let name = CString::new("/some/file/path").unwrap();
3696
3697 let syscall = Openat::new()
3698 .with_dirfd(-100)
3699 .with_path(PathPtr::from_ptr(name.as_ptr()))
3700 .with_flags(OFlag::O_RDONLY | OFlag::O_APPEND)
3701 .with_mode(Some(Mode::from_bits_truncate(0o644)));
3702
3703 assert_eq!(Openat::from(SyscallArgs::from(syscall)), syscall);
3704
3705 let memory = LocalMemory::new();
3706
3707 assert_eq!(
3708 syscall.path().unwrap().read(&memory).unwrap(),
3709 Path::new("/some/file/path")
3710 );
3711
3712 assert_eq!(
3713 format!("{}", syscall.display(&memory)),
3714 format!(
3715 "openat(-100, {:p} -> \"/some/file/path\", OFlag(O_APPEND))",
3716 name.as_ptr()
3717 )
3718 );
3719 }
3720
3721 #[test]
3722 fn test_ppoll_timeout_is_timespec() {
3723 let timeout = Timespec {
3724 tv_sec: 1,
3725 tv_nsec: 500_000_000,
3726 };
3727 let timeout_addr = AddrMut::from_ptr(&timeout).unwrap();
3728 let syscall = Ppoll::new().with_timeout(Some(timeout_addr));
3729
3730 let decoded = Ppoll::from(SyscallArgs::from(syscall));
3731 let decoded_timeout: Option<AddrMut<Timespec>> = decoded.timeout();
3732 assert_eq!(decoded_timeout, Some(timeout_addr));
3733 }
3734
3735 #[test]
3736 fn test_pselect6_timeout_is_timespec() {
3737 let timeout = Timespec {
3742 tv_sec: 2,
3743 tv_nsec: 250_000_000,
3744 };
3745 let timeout_addr = AddrMut::from_ptr(&timeout).unwrap();
3746 let syscall = Pselect6::new().with_timeout(Some(timeout_addr));
3747
3748 let decoded = Pselect6::from(SyscallArgs::from(syscall));
3749 let decoded_timeout: Option<AddrMut<Timespec>> = decoded.timeout();
3750 assert_eq!(decoded_timeout, Some(timeout_addr));
3751 }
3752
3753 #[test]
3754 fn test_syscall_openat_display() {
3755 assert_eq!(Openat::NAME, "openat");
3756 assert_eq!(Openat::NUMBER, Sysno::openat);
3757
3758 let memory = LocalMemory::new();
3759
3760 assert_eq!(
3761 format!(
3762 "{}",
3763 Openat::new()
3764 .with_dirfd(-100)
3765 .with_path(None)
3766 .with_flags(OFlag::O_APPEND)
3767 .display(&memory)
3768 ),
3769 "openat(-100, NULL, OFlag(O_APPEND))"
3770 );
3771
3772 assert_eq!(
3773 format!(
3774 "{}",
3775 Openat::new()
3776 .with_dirfd(-100)
3777 .with_path(None)
3778 .with_flags(OFlag::O_CREAT)
3779 .with_mode(Some(Mode::from_bits_truncate(0o644)))
3780 .display(&memory)
3781 ),
3782 "openat(-100, NULL, OFlag(O_CREAT), Mode(S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH))"
3783 );
3784
3785 assert_eq!(
3786 format!(
3787 "{}",
3788 Openat::new()
3789 .with_dirfd(-100)
3790 .with_path(None)
3791 .with_flags(OFlag::O_TMPFILE)
3792 .with_mode(Some(Mode::from_bits_truncate(0o600)))
3793 .display(&memory)
3794 ),
3795 "openat(-100, NULL, OFlag(O_DIRECTORY | O_TMPFILE), Mode(S_IRUSR | S_IWUSR))"
3796 );
3797
3798 #[cfg(target_arch = "x86_64")]
3799 assert_eq!(
3800 Openat::new()
3801 .with_dirfd(libc::AT_FDCWD)
3802 .with_path(None)
3803 .with_flags(OFlag::O_CREAT | OFlag::O_WRONLY | OFlag::O_TRUNC)
3804 .with_mode(Some(Mode::from_bits_truncate(0o600))),
3805 Creat::new()
3806 .with_path(None)
3807 .with_mode(Mode::from_bits_truncate(0o600))
3808 .into()
3809 );
3810 }
3811
3812 #[cfg(target_arch = "x86_64")]
3813 #[test]
3814 fn test_syscall_stat() {
3815 let name = CString::new("/dev/null").unwrap();
3816
3817 let stat = nix::sys::stat::stat("/dev/null").unwrap();
3818
3819 let syscall = Stat::new()
3820 .with_path(PathPtr::from_ptr(name.as_ptr()))
3821 .with_stat(StatPtr::from_ptr(&stat as *const libc::stat));
3822
3823 let memory = LocalMemory::new();
3824
3825 assert_eq!(
3826 format!("{}", syscall.display_with_outputs(&memory)),
3827 format!(
3828 "stat({:p} -> \"/dev/null\", {:p} -> {{st_mode=SFlag(S_IFCHR) | 0666, st_size=0, ...}})",
3829 name.as_ptr(),
3830 &stat as *const _
3831 )
3832 );
3833 }
3834
3835 #[test]
3836 fn test_syscall_fcntl() {
3837 let memory = LocalMemory::new();
3838
3839 assert_eq!(
3840 format!(
3841 "{}",
3842 Fcntl::new()
3843 .with_fd(1)
3844 .with_cmd(FcntlCmd::F_DUPFD(2))
3845 .display(&memory)
3846 ),
3847 "fcntl(1, F_DUPFD, 2)"
3848 );
3849 }
3850
3851 #[test]
3854 fn test_syscall_lseek() {
3855 let memory = LocalMemory::new();
3856 let raw = SyscallArgs::new(3, 4096, libc::SEEK_END as usize, 0, 0, 0);
3857 let Syscall::Lseek(call) = Syscall::from_raw(Sysno::lseek, raw) else {
3858 panic!("lseek did not decode to Syscall::Lseek");
3859 };
3860 assert_eq!(call.fd(), 3);
3861 assert_eq!(call.offset(), 4096);
3862 assert_eq!(call.whence(), args::Whence::SEEK_END);
3863 assert_eq!(
3864 format!("{}", call.display(&memory)),
3865 "lseek(3, 4096, SEEK_END)"
3866 );
3867 }
3868
3869 #[cfg(target_arch = "x86_64")]
3870 #[test]
3871 fn test_syscall_pipe2() {
3872 let memory: Option<AddrMut<[i32; 2]>> = AddrMut::from_raw(0x1245);
3873
3874 assert_eq!(
3876 Pipe2::new().with_pipefd(memory),
3877 Pipe::new().with_pipefd(memory).into()
3878 );
3879
3880 assert_ne!(
3881 Pipe2::new()
3882 .with_pipefd(memory)
3883 .with_flags(OFlag::O_CLOEXEC),
3884 Pipe::new().with_pipefd(memory).into()
3885 );
3886 }
3887
3888 #[cfg(target_arch = "x86_64")]
3889 #[test]
3890 fn test_syscall_linkat() {
3891 let foo = CString::new("foo").unwrap();
3892 let bar = CString::new("bar").unwrap();
3893
3894 assert_eq!(
3896 Linkat::new()
3897 .with_olddirfd(libc::AT_FDCWD)
3898 .with_oldpath(PathPtr::from_ptr(foo.as_ptr()))
3899 .with_newdirfd(libc::AT_FDCWD)
3900 .with_newpath(PathPtr::from_ptr(bar.as_ptr()))
3901 .with_flags(AtFlags::empty()),
3902 Link::new()
3903 .with_oldpath(PathPtr::from_ptr(foo.as_ptr()))
3904 .with_newpath(PathPtr::from_ptr(bar.as_ptr()))
3905 .into(),
3906 );
3907 }
3908
3909 #[test]
3910 fn test_syscall_openat2() {
3911 let name = CString::new("/some/file/path").unwrap();
3912
3913 let open_how = OpenHow {
3915 flags: libc::O_RDONLY as u64,
3916 mode: 0o644,
3917 resolve: 0,
3918 };
3919
3920 let syscall = Openat2::new()
3921 .with_dirfd(libc::AT_FDCWD)
3922 .with_path(PathPtr::from_ptr(name.as_ptr()))
3923 .with_how(Addr::from_ptr(&open_how))
3924 .with_size(core::mem::size_of::<OpenHow>());
3925
3926 assert_eq!(Openat2::from(SyscallArgs::from(syscall)), syscall);
3928
3929 let memory = LocalMemory::new();
3930
3931 assert_eq!(
3932 syscall.path().unwrap().read(&memory).unwrap(),
3933 Path::new("/some/file/path")
3934 );
3935
3936 assert_eq!(
3938 format!("{}", syscall.display(&memory)),
3939 format!(
3940 "openat2(-100, {:p} -> \"/some/file/path\", {:p}, 24)",
3941 name.as_ptr(),
3942 &open_how as *const _
3943 )
3944 );
3945 }
3946
3947 #[test]
3948 fn test_syscall_openat2_display() {
3949 let memory = LocalMemory::new();
3950
3951 assert_eq!(
3953 format!(
3954 "{}",
3955 Openat2::new()
3956 .with_dirfd(libc::AT_FDCWD)
3957 .with_path(None)
3958 .with_how(None)
3959 .with_size(24)
3960 .display(&memory)
3961 ),
3962 "openat2(-100, NULL, NULL, 24)"
3963 );
3964 }
3965}