LATX, feat: Add opt-in Guest TLS and explicit libc boundaries - #470
Draft
LaurenIsACoder wants to merge 5 commits into
Draft
LATX, feat: Add opt-in Guest TLS and explicit libc boundaries#470LaurenIsACoder wants to merge 5 commits into
LaurenIsACoder wants to merge 5 commits into
Conversation
Extract CPU clone initialization without changing existing callers or thread policy. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Preserve the existing callback ABI, including float results and Host floating-point register preservation. Add explicit helper-call entry points for subsequent TLS initialization. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Keep common runtime options available in release builds and propagate an explicit -L selection through LAT_LD_PREFIX. A re-executed Guest must use the same loader and libc as its parent. Add test-runtime-prefix-exec to check the exported selection and mapped Guest libc before and after exec. Reverting the runtime-root fix makes the fixture fail; the fixed build passes on LoongArch ABI1. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
Keep Guest TLS management disabled unless LATX_KZT_GUEST_TLS=1 and KZT is effective. Attach native-created threads from an immutable template, initialize Guest TLS from live loader state, and coordinate generation refresh, callback execution, fork and thread exit. Keep existing library registration and disabled-mode loader behavior. Add policy, loader and native-thread callback tests. Initialize the attached TCB thread ID and robust-list fields before calling the Guest loader allocation helper. The debugger regression reaches that helper with TID 0 before the fix and with the real thread ID after it. Opt-in off/on, robust owner death and 64-cycle dynamic loading regressions pass on LoongArch ABI1. Supply the new runtime-gate variables in the standalone TB-flush test fixture so the complete KZT-enabled lat-pr-fast suite links and runs. Co-authored-by: sunguoyun <sunguoyun@loongson.cn> Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
…ries Provide an initially inactive libc boundary broker for errno, h_errno and locale names. Keep Guest thread destruction in the TLS runtime. Consumers explicitly initialize and activate the broker; enabling Guest TLS alone does not enable semantic propagation. Keep private libc pointers within their owning domain. Own locale projections per Guest context, document borrowed handles, and release each projection in its owning libc during context teardown. The two-thread regression fails with the old shared cache and passes with separate contexts, including mutation and release of an owned duplicate. Signed-off-by: Hanlu Li <heuleehanlu@gmail.com>
LaurenIsACoder
force-pushed
the
lauren/kzt-guest-tls
branch
from
September 8, 2026 03:11
af1ed40 to
4d7379d
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary / 变更说明
A native library can call back into x86-64 Guest code from a pthread that never executed the Guest pthread initialization path. Such a thread needs its own Guest CPU, stack, TCB and DTV; copying an ELF TLS image alone does not establish a usable Guest libc thread context.
This draft adds default-off Guest TLS management for native-thread callbacks, followed by a separately activated interface for propagating selected libc state. The five commits are kept in one PR so reviewers can examine the preparation, runtime change and explicit libc interface in order.
Commit guide
2b0e27c77b94d3df926d6b58924b71061743-Lruntime selection throughLAT_LD_PREFIXacross Guestexec, with a focused parent/child regression test.794084bdf99e4d7379d866e4The first four commits form the Guest TLS infrastructure; the fifth layers the libc boundary interface on top. This PR contains only these five commits and has no application-specific native-runtime adapter.
Transient loader-busy handling
A native thread can first call back while the Guest loader is changing its TLS inventory. Attachment previously collapsed a transient
BUSYsnapshot result into a hard failure and returned without executing the callback. Preserve that result before any Guest TLS allocation or helper execution, release the failed attempt's resources and locks, and retry with bounded backoff. Permanent initialization errors still fail immediately; persistent busy does not cause unlimited retries or context allocation.The change belongs to commit 4. It does not implement general recovery from failures after Guest code has started or after a loader mutation has committed.
Activation and ownership
LATX_KZT_GUEST_TLS=1and an effective KZT library group. The default remains off.duplocale()copy before modifying or releasing one. Context teardown releases projections in their owning libc.Details: Guest TLS and explicit libc boundaries.
Validation / 验证
Tested source:
4d7379d866e4197fb439ee142f1ebcedc7b2b2e5, without an application adapter, on a LoongArch ABI1 host with 16 KiB pages, GCC 8.3 and glibc 2.28. Guest fixtures were compiled and linked against a matching x86-64 glibc 2.28 sysroot, then executed on the LoongArch host.Build and fast-suite commands:
Full
lat-pr-fastresult: 27 passed, 0 failed, 0 skipped, 0 timed out.Rebased onto upstream
bfe17ae7c1b5c32e3f519dd52da280b6988ef43dbefore this validation. The no-adapter PR endpoint was independently rebuilt and tested. The optionalkzt-attach-busy.gdbregression passes all three cases: a single busy snapshot is retried and the callback executes; a permanent error remains an error; persistent busy exits within the retry budget.Focused fixtures were executed directly using the separately built Guest/Host artifacts. The native callback invocation uses:
0; native-thread attachment with it set to1kzt-bootstrap-tid.gdb)0; the fixed binary passed all seven observed entries and exited normally.EOWNERDEAD.dlopen/dlclosecycles involving Guest, native-attached and concurrent threads.execThe first four-commit endpoint was also built independently and passed its applicable focused checks. The integration runners are registered with Meson; compiler-dependent runners were not all executed end-to-end on this host, so the direct-fixture results above should not be read as a complete
latx-integrationsuite pass.Draft review points and remaining limits
__res_state()backing storage on attached threads. Resolver APIs are outside the supported attached-thread profile; errno/h_errno propagation is not resolver isolation.Checklist / 检查项
CONTRIBUTING.md. / 我已阅读CONTRIBUTING.md。