Hi Alexandre,

> 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-
3.

https://sel4.atlassian.net/browse/RFC-3

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.

https://github.com/seL4/seL4/blob/master/libsel4/include/sel4/functions.h#L28

To assist with this there is a simple sel4runtime library which provides
a minimal C-runtime and tools for initialising TLS.

https://github.com/SEL4PROJ/sel4runtime

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
> TLS register.

The ELF loader is not responsible for TLS initialisation, the C-runtime
is responsible for configuring TLS of the initial thread.

https://bitbucket.ts.data61.csiro.au/projects/SEL4PROJ/repos/sel4runtime/browse/src/env.c#325

> 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
> complex samples!

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.

Cheers,
Curtis Millar

Systems Engineer,
Trustworthy Systems, CSIRO's Data61

curtis.mil...@data61.csiro.au

Data61, CSIRO
Level 3, K17 Building
UNSW Gate 14, Barker St
Kensington NSW 2033 Australia

Attachment: signature.asc
Description: This is a digitally signed message part

_______________________________________________
Devel mailing list
Devel@sel4.systems
https://sel4.systems/lists/listinfo/devel

Reply via email to