Expand description
Guest↔host TLS: TPIDR_EL0 + per-thread host snapshot.
Guest code runs with TPIDR → freestanding GUEST_TLS_MAGIC block; every
host entry restores the host TPIDR saved at prepare. Snapshots live in
crate::host_slot and are mirrored into the guest block (A1) so enter can
restore host TPIDR + alt SP without gettid / map locks.
Guest block layout (must match kh-libsystem):
0 magic 8 errno 16 pthread_self 24 host_tpidr 32 alt_top 40 tsd_valsHost owns 24/32; freestanding owns tsd_vals.
Structs§
- Hyper
Enter Ret - Hypercall enter return: alt SP + guest TLS VA for leave (AAPCS64
x0/x1).
Constants§
- GUEST_
TLS_ ALT_ TOP_ OFF - Hypercall alt-stack top mirror (host-owned).
- GUEST_
TLS_ ERRNO_ OFF - Offset of the
errnocell inside the guest TLS block. - GUEST_
TLS_ HOST_ TPIDR_ OFF - Host
TPIDR_EL0mirror (written only by host while host TPIDR is live). - GUEST_
TLS_ MAGIC - Freestanding guest TLS magic (
"KHTLS\x01"). - GUEST_
TLS_ PTHREAD_ OFF - Offset of
pthread_selfpointer storage. - GUEST_
TLS_ SIZE - Size of the guest TLS control block (one page is fine; we use 64 B).
- GUEST_
TLS_ TSD_ VALS_ OFF - Guest-owned per-thread
pthreadTSD array pointer (freestanding).
Functions§
- clear_
guest_ tls_ on_ exit - Restores host TLS and clears the active guest snapshot (worker exit).
- enter_
guest_ tls - Switches
TPIDR_EL0toguest_tpidrand records it in the host slot. - enter_
host_ tls - Safe wrapper used from Rust trap handlers.
- guest_
tpidr - Current guest TPIDR snapshot (0 if none).
- host_
tpidr - Current host TPIDR snapshot (0 if unprepared).
- init_
guest_ tls_ block - Writes magic + errno=0 + optional pthread into a guest TLS block.
- install_
main_ guest_ tls - Allocates the main-thread guest TLS block and records it in
host_slot. - is_
guest_ tls - True when
tpidrlooks like a freestanding guest TLS block. - kh_
tls_ ⚠enter_ host - Safety
- kh_
tls_ ⚠leave_ host - Safety
- leave_
host_ tls - Safe wrapper used from Rust trap handlers (map fallback).
- main_
guest_ tls - Main thread guest TLS VA installed by
install_main_guest_tls. - prepare_
host_ meta - Captures the current (host)
TPIDR_EL0into this thread’s host slot. - publish_
alt_ top_ to_ current_ guest - Update alt_top mirror for the current thread’s guest TLS (host TPIDR live).
- publish_
boundary_ to_ guest_ tls - Write host boundary fields into a freestanding guest TLS block.