shadow_rs/host/syscall/handler/
resource.rs

1use linux_api::errno::Errno;
2use shadow_shim_helper_rs::syscall_types::ForeignPtr;
3
4use crate::host::syscall::handler::{SyscallContext, SyscallHandler};
5use crate::host::syscall::types::SyscallError;
6
7impl SyscallHandler {
8    log_syscall!(
9        prlimit64,
10        /* rv */ std::ffi::c_int,
11        /* pid */ linux_api::posix_types::kernel_pid_t,
12        /* resource */ std::ffi::c_uint,
13        /* new_rlim */ *const std::ffi::c_void,
14        /* old_rlim */ *const std::ffi::c_void,
15    );
16    pub fn prlimit64(
17        _ctx: &mut SyscallContext,
18        pid: linux_api::posix_types::kernel_pid_t,
19        resource: std::ffi::c_uint,
20        _new_rlim: ForeignPtr<()>,
21        _old_rlim: ForeignPtr<()>,
22    ) -> Result<(), SyscallError> {
23        log::trace!("prlimit64 called on pid {pid} for resource {resource}");
24
25        // TODO: For determinism, we may want to enforce static limits for certain resources, like
26        // RLIMIT_NOFILE. Some applications like Tor will change behavior depending on these limits.
27
28        if pid == 0 {
29            // process is calling prlimit on itself
30            Err(SyscallError::Native)
31        } else {
32            // TODO: We do not currently support adjusting other processes limits. To support it, we
33            // just need to find the native pid associated with pid, and call prlimit on the native
34            // pid instead.
35            Err(Errno::EOPNOTSUPP.into())
36        }
37    }
38}