Copy TLS data in sys_fork.

master
Yuhao Zhou 6 years ago
parent dc90cb5a8d
commit 9532311c1e

@ -120,6 +120,7 @@ impl InitStack {
extern "C" {
fn trap_return();
fn _cur_tls();
}
/// Saved registers for kernel context switches.
@ -231,8 +232,9 @@ impl Context {
/// The SATP register will be set to `satp`.
/// All the other registers are same as the original.
pub unsafe fn new_fork(tf: &TrapFrame, kstack_top: usize, satp: usize) -> Self {
let tls = unsafe { *(_cur_tls as *const usize) };
InitStack {
context: ContextData::new(satp, 0),
context: ContextData::new(satp, tls),
tf: {
let mut tf = tf.clone();
// fork function's ret value, the new process is 0

@ -214,7 +214,6 @@ fn reserved_inst(tf: &mut TrapFrame) -> bool {
if opcode == 0b011111 && format == 0b111011 {
// RDHWR
if rd == 29 && sel == 0 {
info!("Read TLS by rdhdr");
extern "C" {
fn _cur_tls();
}
@ -222,7 +221,9 @@ fn reserved_inst(tf: &mut TrapFrame) -> bool {
let tls = unsafe {
*(_cur_tls as *const usize)
};
set_trapframe_register(rt, tls, tf);
info!("Read TLS by rdhdr {:x} to register {:?}", tls, rt);
return true;
} else {
return false;

@ -319,6 +319,7 @@ pub fn syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> isize {
#[cfg(target_arch = "mips")]
fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<SysResult> {
let ret = match id {
SYS_FORK => sys_fork(tf),
SYS_OPEN => sys_open(args[0] as *const u8, args[1], args[2]),
SYS_DUP2 => sys_dup2(args[0], args[1]),
SYS_MMAP2 => sys_mmap(args[0], args[1], args[2], args[3], args[4], args[5] * 4096),
@ -329,6 +330,7 @@ fn mips_syscall(id: usize, args: [usize; 6], tf: &mut TrapFrame) -> Option<SysRe
Ok(0)
}
SYS_SET_THREAD_AREA => {
info!("set_thread_area: tls: 0x{:x}", args[0]);
extern "C" {
fn _cur_tls();
}

Loading…
Cancel
Save