DoL 326cf3e0a3
refactor(process): 重构process下的系统调用 (#1184)
* refactor(process):迁移geteuid系统调用

* refactor(process):迁移getegid系统调用

* refactor(process):迁移getgid系统调用

* refactor(process):迁移getpgid系统调用

* refactor(process):迁移getpid系统调用

* refactor(process):迁移getppid系统调用

* refactor(process):迁移getsid系统调用

* refactor(process):迁移gettid系统调用

* refactor(process):迁移getuid系统调用

* refactor(process):迁移set_tid_address系统调用

* refactor(process):迁移setfsgid系统调用

* refactor(process):迁移setfsuid系统调用

* refactor(process):迁移setgid系统调用

* refactor(process):迁移setpgid系统调用

* refactor(process):迁移setresgid系统调用

* refactor(process):迁移setresuid系统调用

* refactor(process):迁移setsid系统调用

* refactor(process):迁移setuid系统调用

* refactor(process):删除部分已迁移的syscall(id相关)的原有部分

* refactor(process):make fmt

* refactor(process):迁移sys_get_rusage系统调用

* refactor(process):迁移exit exit_group 系统调用

* refactor(process):删除重构syscall下的mod中的全架构条件编译

* refactor(process):迁移sys_wait4系统调用

* refactor(process):迁移sys_getrlimit sys_prlimit64 系统调用

* make fmt

* refactor(process):迁移sys_uname系统调用

* fix(ipc):修复rebase时的错误冲突

* refactor(process):修改已迁移的系统调用的handle参数from_user-->frame

* refactor(process):迁移execve系统调用

* refactor(process):迁移clone系统调用

* refactor(process):迁移fork、vfork系统调用

* refactor(process):删除原有syscall文件,将迁移后的文件夹重命名为syscall

* refactor(process):修复条件编译错误
2025-06-04 21:29:51 +08:00

55 lines
1.5 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

use crate::arch::interrupt::TrapFrame;
use crate::arch::syscall::nr::SYS_GETSID;
use crate::process::Pid;
use crate::process::ProcessManager;
use crate::syscall::table::FormattedSyscallParam;
use crate::syscall::table::Syscall;
use alloc::sync::Arc;
use alloc::vec::Vec;
use system_error::SystemError;
pub struct SysGetsid;
impl SysGetsid {
fn pid(args: &[usize]) -> Pid {
Pid::new(args[0])
}
}
impl Syscall for SysGetsid {
fn num_args(&self) -> usize {
1
}
/// # 函数的功能
/// 获取指定进程的会话id
///
/// 若pid为0则返回当前进程的会话id
///
/// 若pid不为0则返回指定进程的会话id
///
/// ## 参数
/// - pid: 指定一个进程号
fn handle(&self, args: &[usize], _frame: &mut TrapFrame) -> Result<usize, SystemError> {
let pid = Self::pid(args);
let session = ProcessManager::current_pcb().session().unwrap();
let sid = session.sid().into();
if pid == Pid(0) {
return Ok(sid);
}
let pcb = ProcessManager::find(pid).ok_or(SystemError::ESRCH)?;
if !Arc::ptr_eq(&session, &pcb.session().unwrap()) {
return Err(SystemError::EPERM);
}
return Ok(sid);
}
fn entry_format(&self, args: &[usize]) -> Vec<FormattedSyscallParam> {
vec![FormattedSyscallParam::new(
"pid",
format!("{:#x}", Self::pid(args).0),
)]
}
}
syscall_table_macros::declare_syscall!(SYS_GETSID, SysGetsid);