Disable thread-local storage entirely.

This commit is contained in:
4lDO2
2023-07-11 16:18:20 +02:00
parent a78d6e42f8
commit ed2febb289
6 changed files with 5 additions and 79 deletions
-13
View File
@@ -33,19 +33,6 @@ SECTIONS {
. = ALIGN(4K);
}
.tdata ALIGN(4K) : AT(ADDR(.tdata) - KERNEL_OFFSET) {
__bss_end = .;
__tdata_start = .;
*(.tdata*)
. = ALIGN(4K);
__tdata_end = .;
__tbss_start = .;
*(.tbss*)
. += 8;
. = ALIGN(4K);
__tbss_end = .;
}
__end = .;
/DISCARD/ : {
-11
View File
@@ -32,17 +32,6 @@ SECTIONS {
*(.bss*)
}
.tdata ALIGN(4K) : AT(ADDR(.tdata) - KERNEL_OFFSET) {
__bss_end = .;
__tdata_start = .;
*(.tdata*)
__tdata_end = .;
__tbss_start = .;
*(.tbss*)
. = ALIGN(4K);
__tbss_end = .;
}
__end = .;
/DISCARD/ : {
+1 -26
View File
@@ -74,10 +74,9 @@ const BASE_GDT: [GdtEntry; 9] = [
#[repr(C, align(4096))]
pub struct ProcessorControlRegion {
pub tcb_end: usize,
pub self_ref: usize,
pub user_rsp_tmp: usize,
pub tss: TssWrapper,
pub self_ref: usize,
pub gdt: [GdtEntry; 9],
percpu: crate::percpu::PercpuBlock,
}
@@ -138,8 +137,6 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: usize) {
base: pcr.gdt.as_ptr() as *const SegmentDescriptor,
};
pcr.tcb_end = init_percpu();
{
let tss = &pcr.tss.0 as *const _ as usize as u32;
@@ -172,28 +169,6 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: usize) {
};
}
// TODO: Share code with x86. Maybe even with aarch64?
/// Copy tdata, clear tbss, calculate TCB end pointer
#[cold]
unsafe fn init_percpu() -> usize {
use crate::kernel_executable_offsets::*;
let size = __tbss_end() - __tdata_start();
assert_eq!(size % PAGE_SIZE, 0);
let tbss_offset = __tbss_start() - __tdata_start();
let base_frame = crate::memory::allocate_frames(size / PAGE_SIZE).expect("failed to allocate percpu memory");
let base = RmmA::phys_to_virt(base_frame.start_address());
let tls_end = base.data() + size;
core::ptr::copy_nonoverlapping(__tdata_start() as *const u8, base.data() as *mut u8, tbss_offset);
core::ptr::write_bytes((base.data() + tbss_offset) as *mut u8, 0, size - tbss_offset);
tls_end
}
#[derive(Copy, Clone, Debug)]
#[repr(packed)]
pub struct GdtEntry {
+2 -26
View File
@@ -3,7 +3,7 @@
use core::convert::TryInto;
use core::mem;
use crate::paging::{PAGE_SIZE, RmmA, RmmArch};
use crate::paging::{RmmA, RmmArch};
use crate::percpu::PercpuBlock;
use x86::bits64::task::TaskStateSegment;
@@ -74,12 +74,11 @@ const BASE_GDT: [GdtEntry; 8] = [
pub struct ProcessorControlRegion {
// TODO: When both KASLR and KPTI are implemented, the PCR may need to be split into two pages,
// such that "secret" kernel addresses are only stored in the protected half.
pub self_ref: usize,
pub tcb_end: usize,
pub user_rsp_tmp: usize,
// TODO: The I/O permissions bitmap can require more than 8192 bytes of space.
pub tss: TaskStateSegment,
pub self_ref: usize,
// The GDT *must* be stored in the PCR! The paranoid interrupt handler, lacking a reliable way
// to correctly obtain GSBASE, uses SGDT to calculate the PCR offset.
pub gdt: [GdtEntry; 8],
@@ -164,8 +163,6 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: usize) {
base,
};
pcr.tcb_end = init_percpu();
{
pcr.tss.iomap_base = 0xFFFF;
@@ -220,27 +217,6 @@ pub unsafe fn init_paging(stack_offset: usize, cpu_id: usize) {
};
}
/// Copy tdata, clear tbss, calculate TCB end pointer
#[cold]
unsafe fn init_percpu() -> usize {
use crate::kernel_executable_offsets::*;
let size = __tbss_end() - __tdata_start();
assert_eq!(size % PAGE_SIZE, 0);
let tbss_offset = __tbss_start() - __tdata_start();
let base_frame = crate::memory::allocate_frames(size / PAGE_SIZE).expect("failed to allocate percpu memory");
let base = RmmA::phys_to_virt(base_frame.start_address());
let tls_end = base.data() + size;
core::ptr::copy_nonoverlapping(__tdata_start() as *const u8, base.data() as *mut u8, tbss_offset);
core::ptr::write_bytes((base.data() + tbss_offset) as *mut u8, 0, size - tbss_offset);
tls_end
}
#[derive(Copy, Clone, Debug)]
#[repr(packed)]
pub struct GdtEntry {
+1 -1
View File
@@ -282,5 +282,5 @@ macro_rules! linker_offsets(
}
);
pub mod kernel_executable_offsets {
linker_offsets!(__text_start, __text_end, __rodata_start, __rodata_end, __data_start, __data_end, __bss_start, __bss_end, __tdata_start, __tdata_end, __tbss_start, __tbss_end, __usercopy_start, __usercopy_end);
linker_offsets!(__text_start, __text_end, __rodata_start, __rodata_end, __data_start, __data_end, __bss_start, __bss_end, __usercopy_start, __usercopy_end);
}
+1 -2
View File
@@ -23,6 +23,5 @@
"exe-suffix": "",
"has-rpath": false,
"no-default-libraries": true,
"position-independent-executables": false,
"tls-model": "global-dynamic"
"position-independent-executables": false
}