Add TLS key support
This commit is contained in:
parent
d7e3c619cd
commit
dceb0768c2
@ -793,6 +793,15 @@ extern "C" fn syscall_handler() {
|
||||
28 => {
|
||||
TASKING.join_thread(usize(regs.rcx));
|
||||
}
|
||||
29 => {
|
||||
retval = u64(TASKING.new_tls_key());
|
||||
}
|
||||
30 => {
|
||||
TASKING.set_tls_key(usize(regs.rcx), regs.rdx)
|
||||
}
|
||||
31 => {
|
||||
retval = TASKING.get_tls_key(usize(regs.rcx));
|
||||
}
|
||||
_ => (),
|
||||
};
|
||||
unsafe { SYSCALL_REGS = regs };
|
||||
|
@ -4,8 +4,7 @@ use crate::{
|
||||
println,
|
||||
virtual_memory::{ASpaceMutex, AddressSpace, PagingError, ACTIVE_SPACE, KERNEL_SPACE},
|
||||
};
|
||||
use alloc::{boxed::Box, collections::VecDeque, vec::Vec};
|
||||
use az::WrappingAs;
|
||||
use alloc::{boxed::Box, collections::VecDeque, vec::Vec, vec};
|
||||
use cast::{u64, usize};
|
||||
use core::{
|
||||
arch::naked_asm,
|
||||
@ -96,6 +95,7 @@ pub struct Process {
|
||||
threads: RwLock<Slab<Thread>>,
|
||||
main_thread: usize,
|
||||
num_threads: usize,
|
||||
num_tls: usize,
|
||||
}
|
||||
|
||||
impl Process {
|
||||
@ -111,6 +111,7 @@ impl Process {
|
||||
threads: RwLock::new(Slab::new()),
|
||||
main_thread: 0,
|
||||
num_threads: 0,
|
||||
num_tls: 0,
|
||||
};
|
||||
let main_thread = proc.new_thread(entry_point, 0)?;
|
||||
proc.main_thread = main_thread;
|
||||
@ -170,6 +171,7 @@ impl Process {
|
||||
),
|
||||
kernel_stack,
|
||||
sleeping: RwLock::new(sleeping),
|
||||
tls_values: Mutex::new(vec![0; self.num_tls]),
|
||||
};
|
||||
let idx = self.threads.write().insert(thread);
|
||||
self.num_threads += 1;
|
||||
@ -187,6 +189,7 @@ pub struct Thread {
|
||||
kernel_stack: Box<[usize], &'static ASpaceMutex>,
|
||||
kernel_esp: *mut usize,
|
||||
kernel_esp_top: VirtAddr,
|
||||
tls_values: Mutex<Vec<u64>>,
|
||||
}
|
||||
|
||||
pub struct IpcMessage {
|
||||
@ -456,7 +459,7 @@ impl Tasking {
|
||||
*thread.sleeping.write() = Some(SleepReason::Exited);
|
||||
});
|
||||
self.current_process(|process| {
|
||||
for (tid, thread) in &*process.threads().read() {
|
||||
for (tid, _) in &*process.threads().read() {
|
||||
self.wake(
|
||||
current_pid,
|
||||
tid,
|
||||
@ -607,6 +610,29 @@ impl Tasking {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_tls_key(&self) -> usize {
|
||||
self.current_process_mut(|process| {
|
||||
let id = process.num_tls;
|
||||
process.num_tls += 1;
|
||||
for (_, thread) in &*process.threads().read() {
|
||||
thread.tls_values.lock().push(0);
|
||||
}
|
||||
id
|
||||
})
|
||||
}
|
||||
|
||||
pub fn set_tls_key(&self, key: usize, val: u64) {
|
||||
self.current_thread(|thread| {
|
||||
thread.tls_values.lock()[key] = val;
|
||||
})
|
||||
}
|
||||
|
||||
pub fn get_tls_key(&self, key: usize) -> u64 {
|
||||
self.current_thread(|thread| {
|
||||
thread.tls_values.lock()[key]
|
||||
})
|
||||
}
|
||||
|
||||
//pub fn print_stats(&self) {
|
||||
// let mut total = KERNEL_SPACE.lock().get_bytes_allocated();
|
||||
// println!(
|
||||
|
Loading…
Reference in New Issue
Block a user