Support TLS for MIPS.

master
Yuhao Zhou 6 years ago
parent 2c80f1e46f
commit a9bc66382c

@ -7,6 +7,9 @@ extern crate rcore_user;
use rcore_user::syscall::{sys_arch_prctl, sys_getpid, sys_sleep, sys_vfork};
#[cfg(target_arch = "mips")]
use rcore_user::syscall::sys_set_theaad_area;
fn set_tls(tls: usize, pid: usize) {
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
unsafe {
@ -23,6 +26,8 @@ fn set_tls(tls: usize, pid: usize) {
// set fs base
sys_arch_prctl(0x1002, &DATA[pid] as *const usize as usize);
}
#[cfg(target_arch = "mips")]
sys_set_theaad_area(tls);
}
fn get_tls() -> usize {
@ -39,6 +44,10 @@ fn get_tls() -> usize {
unsafe {
asm!("mov %fs:0, $0" : "=r"(tls) :);
}
#[cfg(target_arch = "mips")]
unsafe {
asm!("rdhwr $0, $$29" : "=r"(tls) :);
}
tls
}

@ -325,6 +325,11 @@ enum SyscallId {
GetPaddr = 998,
}
#[cfg(target_arch = "mips")]
pub fn sys_set_theaad_area(tls: usize) {
sys_call(SyscallId::SetThreadArea, tls, 0, 0, 0, 0, 0);
}
// only for mips N32 abi
// see https://git.linux-mips.org/cgit/ralf/linux.git/tree/arch/mips/include/uapi/asm/unistd.h
#[cfg(target_arch = "mips")]
@ -354,6 +359,7 @@ enum SyscallId {
Chdir = 4012,
GetTime = 4078,
SetPriority = 4097,
SetThreadArea = 4283,
ArchPrctl = -1,
GetDirEntry64 = 4219,
Openat = 4288,
@ -364,7 +370,7 @@ enum SyscallId {
GetPaddr = 998,
}
#[cfg(any(all(target_arch = "x86_64", target_arch = "mips")))]
#[cfg(not(any(target_arch = "x86_64", target_arch = "mips")))]
#[allow(dead_code)]
enum SyscallId {
Read = 63,

Loading…
Cancel
Save