Skip to content

Commit

Permalink
refactor(env): don't reexport tls functions
Browse files Browse the repository at this point in the history
Signed-off-by: Martin Kröning <martin.kroening@eonerc.rwth-aachen.de>
  • Loading branch information
mkroening committed Aug 30, 2023
1 parent 9888a27 commit ed3d008
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
12 changes: 6 additions & 6 deletions src/arch/aarch64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use crate::arch::aarch64::kernel::CURRENT_STACK_ADDRESS;
use crate::arch::aarch64::mm::paging::{BasePageSize, PageSize, PageTableEntryFlags};
use crate::arch::aarch64::mm::{PhysAddr, VirtAddr};
use crate::scheduler::task::{Task, TaskFrame};
use crate::{env, DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE};
use crate::{kernel, DEFAULT_STACK_SIZE, KERNEL_STACK_SIZE};

#[derive(Debug)]
#[repr(C, packed)]
Expand Down Expand Up @@ -264,21 +264,21 @@ pub struct TaskTLS {

impl TaskTLS {
fn from_environment() -> Option<Box<Self>> {
if env::get_tls_memsz() == 0 {
if kernel::get_tls_memsz() == 0 {
return None;
}

// Get TLS initialization image
let tls_init_image = {
let tls_init_data = env::get_tls_start().as_ptr::<u8>();
let tls_init_len = env::get_tls_filesz();
let tls_init_data = kernel::get_tls_start().as_ptr::<u8>();
let tls_init_len = kernel::get_tls_filesz();

// SAFETY: We will have to trust the environment here.
unsafe { slice::from_raw_parts(tls_init_data, tls_init_len) }
};

let off = core::cmp::max(16, env::get_tls_align()) - 16;
let block_len = env::get_tls_memsz() + off;
let off = core::cmp::max(16, kernel::get_tls_align()) - 16;
let block_len = kernel::get_tls_memsz() + off;
let len = block_len + mem::size_of::<Box<[Dtv; 2]>>();

let layout = Layout::from_size_align(len, 16).unwrap();
Expand Down
12 changes: 6 additions & 6 deletions src/arch/x86_64/kernel/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use crate::arch::x86_64::mm::paging::{
};
use crate::arch::x86_64::mm::{PhysAddr, VirtAddr};
use crate::config::*;
use crate::env;
use crate::kernel;
use crate::scheduler::task::{Task, TaskFrame};

#[repr(C, packed)]
Expand Down Expand Up @@ -241,24 +241,24 @@ impl TaskTLS {
// “ELF Handling For Thread-Local Storage” Section 3.4.6: x86-64 Specific Definitions for Run-Time Handling of TLS
// https://akkadia.org/drepper/tls.pdf

let tls_len = env::get_tls_memsz();
let tls_len = kernel::get_tls_memsz();

if env::get_tls_memsz() == 0 {
if kernel::get_tls_memsz() == 0 {
return None;
}

// Get TLS initialization image
let tls_init_image = {
let tls_init_data = env::get_tls_start().as_ptr::<u8>();
let tls_init_len = env::get_tls_filesz();
let tls_init_data = kernel::get_tls_start().as_ptr::<u8>();
let tls_init_len = kernel::get_tls_filesz();

// SAFETY: We will have to trust the environment here.
unsafe { slice::from_raw_parts(tls_init_data, tls_init_len) }
};

// Allocate TLS block
let mut block = {
let tls_align = env::get_tls_align();
let tls_align = kernel::get_tls_align();

// As described in “ELF Handling For Thread-Local Storage”
let tls_offset = tls_len.align_up(tls_align);
Expand Down
3 changes: 1 addition & 2 deletions src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ use hermit_entry::boot_info::PlatformInfo;
use hermit_sync::OnceCell;

pub use crate::arch::kernel::{
get_base_address, get_cmdline, get_cmdsize, get_image_size, get_ram_address, get_tls_align,
get_tls_filesz, get_tls_memsz, get_tls_start,
get_base_address, get_cmdline, get_cmdsize, get_image_size, get_ram_address,
};
use crate::kernel::boot_info;

Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,8 +316,8 @@ fn boot_processor_main() -> ! {
});
info!(
"TLS starts at {:p} (size {} Bytes)",
env::get_tls_start(),
env::get_tls_memsz()
kernel::get_tls_start(),
kernel::get_tls_memsz()
);
arch::boot_processor_init();
scheduler::add_current_core();
Expand Down

0 comments on commit ed3d008

Please sign in to comment.