I'm trying to understand how the TLS is setup for
the root server on
x64 (to access for example the IPC buffer)
but I'm failing to connect the pieces and how the server is correctly
setting the FS register.
There is detailed documentation for the TLS change on the page for RFC-
In essence, the new TLS model stores the address of the IPC buffer in a
thread-local variable which must be initialised by your process or
threading runtime along with general TLS intialisation.
To assist with this there is a simple sel4runtime library which provides
a minimal C-runtime and tools for initialising TLS.
On x86_64 the TLS register can be set without calling into the kernel by
using the `wrfsbase` instruction or by using the
`sel4runtime_set_tls_base` function from the sel4runtime library.
Now, I'm failing to find in the codebase where
the ELF loader is
actually detecting the TLS segment and the according setup with the
The ELF loader is not responsible for TLS initialisation, the C-runtime
is responsible for configuring TLS of the initial thread.
Never mind, I discovered that I in order to access a
TLS variable you
need to call `seL4_TCB_SetTLSBase` on seL4_CapInitThreadTCB first in
the root server, as I'm trying to work on a bare bone usage of seL4 to
better understand it, this part was not obvious from the existing more
In general I would recommend having the initial thread in a process
initialise its own TLS via the runtime and any new thread configure its
own TLS in the initialisation code before the main function call of that
thread with the `sel4runtime_set_tls_base`. Each new thread will also
need to use `seL4_SetIPCBuffer` to initialise the IPC buffer address in
its TLS before performing any invocations or any other system calls.
Trustworthy Systems, CSIRO's Data61
Level 3, K17 Building
UNSW Gate 14, Barker St
Kensington NSW 2033 Australia