Implement cpu_local with GS and ensure GS points to TSS

This commit is contained in:
Qingsong Chen
2024-09-19 02:11:32 +00:00
committed by Tate, Hongliang Tian
parent 52bde1721e
commit c2f7a10b84
30 changed files with 901 additions and 112 deletions

View File

@ -3,7 +3,7 @@
use ostd::cpu::UserContext;
use super::SyscallReturn;
use crate::{cpu::LinuxAbi, prelude::*};
use crate::prelude::*;
#[allow(non_camel_case_types)]
#[repr(u64)]
@ -18,7 +18,7 @@ pub enum ArchPrctlCode {
pub fn sys_arch_prctl(
code: u64,
addr: u64,
_ctx: &Context,
ctx: &Context,
user_ctx: &mut UserContext,
) -> Result<SyscallReturn> {
let arch_prctl_code = ArchPrctlCode::try_from(code)?;
@ -26,17 +26,24 @@ pub fn sys_arch_prctl(
"arch_prctl_code: {:?}, addr = 0x{:x}",
arch_prctl_code, addr
);
let res = do_arch_prctl(arch_prctl_code, addr, user_ctx).unwrap();
let res = do_arch_prctl(arch_prctl_code, addr, ctx, user_ctx).unwrap();
Ok(SyscallReturn::Return(res as _))
}
pub fn do_arch_prctl(code: ArchPrctlCode, addr: u64, ctx: &mut UserContext) -> Result<u64> {
pub fn do_arch_prctl(
code: ArchPrctlCode,
addr: u64,
ctx: &Context,
user_ctx: &mut UserContext,
) -> Result<u64> {
match code {
ArchPrctlCode::ARCH_SET_FS => {
ctx.set_tls_pointer(addr as usize);
ctx.task.set_tls_pointer(addr as usize);
user_ctx.set_tls_pointer(addr as usize);
user_ctx.activate_tls_pointer();
Ok(0)
}
ArchPrctlCode::ARCH_GET_FS => Ok(ctx.tls_pointer() as u64),
ArchPrctlCode::ARCH_GET_FS => Ok(user_ctx.tls_pointer() as u64),
ArchPrctlCode::ARCH_GET_GS | ArchPrctlCode::ARCH_SET_GS => {
return_errno_with_message!(Errno::EINVAL, "GS cannot be accessed from the user space")
}

View File

@ -5,7 +5,6 @@ use ostd::{cpu::UserContext, user::UserContextApi};
use super::{constants::*, SyscallReturn};
use crate::{
cpu::LinuxAbi,
fs::{
file_table::FileDesc,
fs_resolver::{FsPath, AT_FDCWD},