Skip to content

Add Thread Local Storage (TLS) support #22185

@andrewboie

Description

@andrewboie

Is your enhancement proposal related to a problem? Please describe.
Right now, it is not possible for a user thread to access thread-local data without making a system call. The thread-local data itself is stored in a read/write area in the thread's stack object, but we don't have a way know its address without reading _current->userspace_local_data, which only supervisor mode can do (both knowing the value of _current and reading one of its members)

This is all a gross hack anyway. We want real TLS as GCC understand it.

Solution requirement

support for GCC thread-local storage aka __thread. We know everything at build time, so it's a matter of reserving enough memory in the stack object at thread creation to hold it all, likely using linker variables created directly or indirectly by the compiler.

Implementing this will be architecture-specific, and depend on the type/capabilities of the memory protection hardware, and/or features of the CPU. But it's generally known how to do this, on x86 a special data segment is used, and on other arches a register is reserved for the base of the TLS area.

once in place, get rid of hacks for errno on supported platforms; arch will select some Kconfig if real TLS is supported. At minimum need all userspace platforms to support this.

Further reading:
https://chao-tic.github.io/blog/2018/12/25/tls
https://www.akkadia.org/drepper/tls.pdf
https://www.linuxjournal.com/content/creating-vdso-colonels-other-chicken

Metadata

Metadata

Assignees

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions