1use linux_api::errno::Errno;
2use shadow_shim_helper_rs::syscall_types::ForeignPtr;
34use crate::host::syscall::handler::{SyscallContext, SyscallHandler};
5use crate::host::syscall::types::SyscallError;
67impl SyscallHandler {
8log_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 );
16pub 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> {
23log::trace!("prlimit64 called on pid {pid} for resource {resource}");
2425// 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.
2728if pid == 0 {
29// process is calling prlimit on itself
30Err(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.
35Err(Errno::EOPNOTSUPP.into())
36 }
37 }
38}