mirror of
https://github.com/asterinas/asterinas.git
synced 2025-06-24 09:53:24 +00:00
Remove the shim kernel crate
This commit is contained in:
committed by
Tate, Hongliang Tian
parent
d76c7a5b1e
commit
dafd16075f
28
kernel/src/syscall/setgroups.rs
Normal file
28
kernel/src/syscall/setgroups.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// SPDX-License-Identifier: MPL-2.0
|
||||
|
||||
use super::SyscallReturn;
|
||||
use crate::{prelude::*, process::Gid};
|
||||
|
||||
pub fn sys_setgroups(size: usize, group_list_addr: Vaddr, ctx: &Context) -> Result<SyscallReturn> {
|
||||
debug!("size = {}, group_list_addr = 0x{:x}", size, group_list_addr);
|
||||
|
||||
// TODO: check perm: the calling process should have the CAP_SETGID capability
|
||||
|
||||
if size > NGROUPS_MAX {
|
||||
return_errno_with_message!(Errno::EINVAL, "size cannot be greater than NGROUPS_MAX");
|
||||
}
|
||||
|
||||
let mut new_groups = BTreeSet::new();
|
||||
for idx in 0..size {
|
||||
let addr = group_list_addr + idx * core::mem::size_of::<Gid>();
|
||||
let gid = ctx.get_user_space().read_val(addr)?;
|
||||
new_groups.insert(gid);
|
||||
}
|
||||
|
||||
let credentials = ctx.posix_thread.credentials_mut();
|
||||
*credentials.groups_mut() = new_groups;
|
||||
|
||||
Ok(SyscallReturn::Return(0))
|
||||
}
|
||||
|
||||
const NGROUPS_MAX: usize = 65536;
|
Reference in New Issue
Block a user