Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add thread local storage support #3

Open
kammce opened this issue Jun 9, 2024 · 0 comments
Open

Add thread local storage support #3

kammce opened this issue Jun 9, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@kammce
Copy link
Member

kammce commented Jun 9, 2024

Thread local storage is needed for exceptions to work. Technically exceptions can work without TLS but it can be slow and is currently not implemented yet in estell-exceptions.

There may be other useful utilities to supporting Tls as well. Potential it could be used for an io_waiter for task notification, but that wouldn't actually work as the interrupt for a driver could happen anywhere on any thread.

Linker scripts will have a TLS section with symbols for tls_data_begin and end as well as bss begin and end. These sections must be contiguous in the linker script.

The idea is to only utilize a single pointer in the FreeRTOS TCB (thread control block) and have it point to data on the top of thread's stack or allocate the memory using some sort of polymorphic memory allocator just for TLS data.

Or if it is somehow possible to know the absolute size of a TLS section at compile/link time, this would be the most ideal option as it would allow the developers to get the exact size of their TLS vs having to guess and check their values after a build, like is done with thread stack sizes.

This support would also have to hook into and provide __emu_tls clang and gcc functions in order to allow C++'s thread_local variable to actually work. That function should use the FreeRTOS TLS first pointer in the TCB and then return a pointer to the value within the TLS section.

The API for this should be a single function a dev calls at the start of their stack. If and when a C++ thread or a hal::freertos::thread is created it should do this automatically for the user before calling their thread.

@kammce kammce added the enhancement New feature or request label Jun 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: No status
Development

No branches or pull requests

1 participant