sys_setfsgid.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. use crate::arch::interrupt::TrapFrame;
  2. use crate::arch::syscall::nr::SYS_SETFSGID;
  3. use crate::process::cred::Kgid;
  4. use crate::process::ProcessManager;
  5. use crate::syscall::table::FormattedSyscallParam;
  6. use crate::syscall::table::Syscall;
  7. use alloc::vec::Vec;
  8. use system_error::SystemError;
  9. pub struct SysSetFsgid;
  10. impl SysSetFsgid {
  11. fn fsgid(args: &[usize]) -> usize {
  12. args[0]
  13. }
  14. }
  15. impl Syscall for SysSetFsgid {
  16. fn num_args(&self) -> usize {
  17. 1
  18. }
  19. fn handle(&self, args: &[usize], _frame: &mut TrapFrame) -> Result<usize, SystemError> {
  20. let fsgid = Self::fsgid(args);
  21. let fsgid = Kgid::new(fsgid);
  22. let pcb = ProcessManager::current_pcb();
  23. let mut guard = pcb.cred.lock();
  24. let old_fsgid = guard.fsgid;
  25. if fsgid == guard.gid || fsgid == guard.egid || fsgid == guard.sgid {
  26. guard.setfsgid(fsgid.data());
  27. }
  28. Ok(old_fsgid.data())
  29. }
  30. fn entry_format(&self, args: &[usize]) -> Vec<FormattedSyscallParam> {
  31. vec![FormattedSyscallParam::new(
  32. "fsgid",
  33. format!("{:#x}", Self::fsgid(args)),
  34. )]
  35. }
  36. }
  37. syscall_table_macros::declare_syscall!(SYS_SETFSGID, SysSetFsgid);