Module axhal::tls

source ·
Available on crate feature tls only.
Expand description

Thread Local Storage (TLS) support.

TLS layout for x86_64

aligned --> +-------------------------+- static_tls_offset
allocation  |                         | \
            | .tdata                  |  |
| address   |                         |  |
| grow up   + - - - - - - - - - - - - +   > Static TLS block
v           |                         |  |  (length: static_tls_size)
            | .tbss                   |  |
            |                         |  |
            +-------------------------+  |
            | / PADDING / / / / / / / | /
            +-------------------------+
   tls_ptr -+-> self pointer (void *) | \
(tp_offset) |                         |  |
            | Custom TCB format       |   > Thread Control Block (TCB)
            | (might be used          |  |  (length: TCB_SIZE)
            |  by a libC)             |  |
            |                         | /
            +-------------------------+- (total length: tls_area_size)

TLS layout for AArch64 and RISC-V

            +-------------------------+
            |                         | \
            | Custom TCB format       |  |
            | (might be used          |   > Thread Control Block (TCB)
            |  by a libC)             |  |  (length: TCB_SIZE)
            |                         | /
   tls_ptr -+-------------------------+
(tp_offset) | GAP_ABOVE_TP            |
            +-------------------------+- static_tls_offset
            |                         | \
            | .tdata                  |  |
            |                         |  |
            + - - - - - - - - - - - - +   > Static TLS block
            |                         |  |  (length: static_tls_size)
            | .tbss                   |  |
            |                         | /
            +-------------------------+- (total length: tls_area_size)

Reference:

  1. https://github.com/unikraft/unikraft/blob/staging/arch/x86/x86_64/tls.c
  2. https://github.com/unikraft/unikraft/blob/staging/arch/arm/arm64/tls.c

Structs

  • The memory region for thread-local storage.