The thread's CPU: TLS_SLOT_APP

A stub reaches the thread's CPU from TPIDR_EL0 at a fixed offset (NceEnv.tls). On Linux that is static TLS of the executable. Android's runtime is libscarletnx.so, a library the app loads: built for API 21 its TLS is emulated (__emutls_get_address, no offset at all), and from API 29 bionic refuses an initial-exec access in a loaded library. The word the stubs read is bionic's TLS_SLOT_APP (TPIDR_EL0 + 16), which the app owns from Android 10 (API 29). It holds a pointer to the thread's block, so the stubs load twice (NceEnv.indirect) in the same three words, and the outcall's asm does the same (nce_host.c).

TPIDR_EL0 stays the host's while guest code runs. ART's signal handlers, reached through libsigchain, and the runtime's own (the write tracking's SIGSEGV, NCE's kicks and traps) run C code as they do without NCE, with bionic's TLS where they expect it.

Limits:

Before Android 10

What would serve them is Eden's way (src/core/arm/nce/arm_nce.s): TPIDR_EL0 set to the thread's NCE block while guest code runs, and the host's put back on each outcall. It needs no slot, so it works from API 21. The cost:


Made from docs/platforms/nx/nce.md at 69237645142c. GPL-3.0-or-later.