theseus-os / Theseus

Theseus is a modern OS written from scratch in Rust that explores 𝐢𝐧𝐭𝐫𝐚𝐥𝐢𝐧𝐠𝐮𝐚𝐥 𝐝𝐞𝐬𝐢𝐠𝐧: closing the semantic gap between compiler and hardware by maximally leveraging the power of language safety and affine types. Theseus aims to shift OS responsibilities like resource management into the compiler.
https://www.theseus-os.com/
MIT License
2.88k stars 172 forks source link

Add support for thread-local storage #73

Closed kevinaboos closed 2 years ago

kevinaboos commented 6 years ago

Use the FS segment register on x86_64. First start with just storing the current task id there, and then move on towards storing the actual current TaskRef there. This allows us to instantly look up the current task without having to query the TASKLIST, which becomes a bottleneck when there are thousands of Tasks.

Then, after that's working, we can add true support for arbitrary thread-local storage. It could potentially be inside the Task struct, or elsewhere.

Discussion here: https://wiki.osdev.org/Thread_Local_Storage

kevinaboos commented 5 years ago

Commit 5e3ea09 does the first part of this, but doesn't fully implement user/application-defined TLS.

kevinaboos commented 2 years ago

TLS as per the ELF spec and the #[thread_local] attribute is partially supported, but isn't fully working yet when dynamically loading crate object files and assigning offsets to their TLS areas in the global TLS Initializer data image.

kevinaboos commented 2 years ago

The #[thread_local] attribute now fully works. Next up is to add a thread_local!() macro.

kevinaboos commented 2 years ago

The thread_local!() macro for lazy dynamic initialization (and destruction) of TLS objects is finished as of #463.