Make essential changes for publishing OSTD

This commit is contained in:
Jianfeng Jiang
2024-07-01 08:00:09 +00:00
committed by Tate, Hongliang Tian
parent 77b823edc0
commit f86583dbce
64 changed files with 341 additions and 218 deletions

View File

@ -1,6 +1,9 @@
// SPDX-License-Identifier: MPL-2.0
use ostd::cpu::UserContext;
use ostd::{
cpu::{RawGeneralRegs, UserContext},
Pod,
};
use crate::cpu::LinuxAbi;
@ -36,3 +39,64 @@ impl LinuxAbi for UserContext {
self.fsbase()
}
}
/// General-purpose registers.
#[derive(Debug, Clone, Copy, Pod, Default)]
#[repr(C)]
pub struct GpRegs {
pub rax: usize,
pub rbx: usize,
pub rcx: usize,
pub rdx: usize,
pub rsi: usize,
pub rdi: usize,
pub rbp: usize,
pub rsp: usize,
pub r8: usize,
pub r9: usize,
pub r10: usize,
pub r11: usize,
pub r12: usize,
pub r13: usize,
pub r14: usize,
pub r15: usize,
pub rip: usize,
pub rflags: usize,
pub fsbase: usize,
pub gsbase: usize,
}
macro_rules! copy_gp_regs {
($src: ident, $dst: ident) => {
$dst.rax = $src.rax;
$dst.rbx = $src.rax;
$dst.rcx = $src.rcx;
$dst.rdx = $src.rdx;
$dst.rsi = $src.rsi;
$dst.rdi = $src.rdi;
$dst.rbp = $src.rbp;
$dst.rsp = $src.rsp;
$dst.r8 = $src.r8;
$dst.r9 = $src.r9;
$dst.r10 = $src.r10;
$dst.r11 = $src.r11;
$dst.r12 = $src.r12;
$dst.r13 = $src.r13;
$dst.r14 = $src.r14;
$dst.r15 = $src.r15;
$dst.rip = $src.rip;
$dst.rflags = $src.rflags;
$dst.fsbase = $src.fsbase;
$dst.gsbase = $src.gsbase;
};
}
impl GpRegs {
pub fn copy_to_raw(&self, dst: &mut RawGeneralRegs) {
copy_gp_regs!(self, dst);
}
pub fn copy_from_raw(&mut self, src: &RawGeneralRegs) {
copy_gp_regs!(src, self);
}
}

View File

@ -1,6 +1,6 @@
// SPDX-License-Identifier: MPL-2.0
use pod::Pod;
use ostd::Pod;
use super::constants::{EXFAT_FIRST_CLUSTER, EXFAT_RESERVED_CLUSTERS, MEDIA_FAILURE, VOLUME_DIRTY};
use crate::prelude::*;

View File

@ -19,8 +19,8 @@ pub(crate) use log::{debug, error, info, log_enabled, trace, warn};
pub(crate) use ostd::{
mm::{Vaddr, VmReader, VmWriter, PAGE_SIZE},
sync::{Mutex, MutexGuard, RwLock, RwMutex, SpinLock, SpinLockGuard},
Pod,
};
pub(crate) use pod::Pod;
/// return current process
#[macro_export]

View File

@ -6,10 +6,10 @@
use core::mem::{self, size_of};
use aster_util::{read_union_fields, union_read_ptr::UnionReadPtr};
use ostd::cpu::GeneralRegs;
use super::sig_num::SigNum;
use crate::{
arch::cpu::GpRegs,
prelude::*,
process::{Pid, Uid},
};
@ -206,7 +206,7 @@ pub struct mcontext_t {
#[derive(Debug, Clone, Copy, Pod, Default)]
#[repr(C)]
pub struct SignalCpuContext {
pub gp_regs: GeneralRegs,
pub gp_regs: GpRegs,
pub fpregs_on_heap: u64,
pub fpregs: Vaddr, // *mut FpRegs,
}

View File

@ -166,7 +166,11 @@ pub fn handle_user_signal(
uc_sigmask: mask.as_u64(),
..Default::default()
};
ucontext.uc_mcontext.inner.gp_regs = *context.general_regs();
ucontext
.uc_mcontext
.inner
.gp_regs
.copy_from_raw(context.general_regs());
let mut sig_context = posix_thread.sig_context().lock();
if let Some(sig_context_addr) = *sig_context {
ucontext.uc_link = sig_context_addr;

View File

@ -38,7 +38,11 @@ pub fn sys_rt_sigreturn(context: &mut UserContext) -> Result<SyscallReturn> {
} else {
*sig_context = Some(ucontext.uc_link);
};
*context.general_regs_mut() = ucontext.uc_mcontext.inner.gp_regs;
ucontext
.uc_mcontext
.inner
.gp_regs
.copy_to_raw(context.general_regs_mut());
// unblock sig mask
let sig_mask = ucontext.uc_sigmask;
posix_thread.sig_mask().lock().unblock(sig_mask);

View File

@ -23,8 +23,8 @@ use aster_util::coeff::Coeff;
use ostd::{
mm::{Frame, VmIo, PAGE_SIZE},
sync::SpinLock,
Pod,
};
use pod::Pod;
use spin::Once;
use crate::{