Skip to content

Commit

Permalink
TaskTLS: Rework creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mkroening committed Dec 4, 2021
1 parent 932659f commit 11a9160
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
6 changes: 3 additions & 3 deletions src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ pub struct TaskTLS {
}

impl TaskTLS {
pub fn new(tls_size: usize) -> Self {
fn from_environment() -> Self {
Self {
address: VirtAddr::zero(),
}
Expand All @@ -229,7 +229,7 @@ impl Drop for TaskTLS {

impl Clone for TaskTLS {
fn clone(&self) -> Self {
TaskTLS::new(environment::get_tls_memsz())
TaskTLS::from_environment()
}
}

Expand All @@ -244,7 +244,7 @@ extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) {
// Yes, it does, so we have to allocate TLS memory.
// Allocate enough space for the given size and one more variable of type usize, which holds the tls_pointer.
let tls_allocation_size = tls_size + mem::size_of::<usize>();
let tls = TaskTLS::new(tls_allocation_size);
let tls = TaskTLS::from_environment();
// The tls_pointer is the address to the end of the TLS area requested by the task.
let tls_pointer = tls.address + tls_size;
Expand Down
13 changes: 6 additions & 7 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,8 @@ pub struct TaskTLS {
}

impl TaskTLS {
pub fn new(tls_size: usize) -> Self {
fn from_environment() -> Self {
let tls_size = environment::get_tls_memsz();
// determine the size of tdata (tls without tbss)
let tdata_size: usize = environment::get_tls_filesz();
// Yes, it does, so we have to allocate TLS memory.
Expand Down Expand Up @@ -310,7 +311,7 @@ impl Drop for TaskTLS {

impl Clone for TaskTLS {
fn clone(&self) -> Self {
TaskTLS::new(environment::get_tls_memsz())
TaskTLS::from_environment()
}
}

Expand Down Expand Up @@ -347,11 +348,9 @@ extern "C" fn task_entry(func: extern "C" fn(usize), arg: usize) -> ! {

impl TaskFrame for Task {
fn create_stack_frame(&mut self, func: extern "C" fn(usize), arg: usize) {
// Check if the task (process or thread) uses Thread-Local-Storage.
let tls_size = environment::get_tls_memsz();
// check is TLS is already allocated
if self.tls.is_none() && tls_size > 0 {
self.tls = Some(TaskTLS::new(tls_size))
// Check if TLS is allocated already and if the task uses thread-local storage.
if self.tls.is_none() && environment::get_tls_memsz() > 0 {
self.tls = Some(TaskTLS::from_environment());
}

unsafe {
Expand Down

0 comments on commit 11a9160

Please sign in to comment.