Initialize and retire original per-thread runtime state #85

Open
opened 2026-11-08 12:14:46 +01:00 by erikinkinen · 2 comments
Owner

Problem and motivation

Native threads have original TLS/errno images, but lack private runtime storage for locale selection, default multibyte state, TLS keys and destructor progress. The current 32-byte TCB has no spare field. A process-global table indexed by a thread pointer would not establish original storage ownership or safe reuse.

Proposed behavior and scope

Select an explicit extended thread-runtime profile for both initial and additional threads. Preserve the existing 32-byte prefix and its zero reserved word. The proposed 64-byte TCB adds a runtime version marker, original state pointer, complete state extent and generation/correlation word at offsets 32, 40, 48 and 56.

The original TLS producer allocates and initializes that private state before Start. Native entry borrows the actual mapped storage under the original process/thread lifetime; header values validate correlation, never authenticate or create an owner. Legacy images remain explicitly selected and cannot satisfy the extended runtime.

State includes a typed 16-byte locale cell, separate 32-byte function-specific default conversion states, and thread-specific key/value and destructor progress. Locale starts in global-selection mode; classification reads a copied atomic profile, not an arbitrary locale pointer. Key storage uses the explicitly selected process heap and caller resource policy, with generation-qualified reuse rather than a private key-count ceiling.

Integrate the actual initial/additional entry and returned-callback/self-exit paths. Destructor calls clear the current value first, execute outside locks and mutable state borrows, and permit reentrant key updates. Repeated passes follow the selected POSIX destructor-iteration policy. The process, code and backing owners remain live until actual native retirement; local destructor completion alone cannot authorize reuse.

Affected owners are LibCstd, LibDynlink, Loaderd, Procd, Posixd and Integration. General dynamic module unloading remains its separate lifecycle requirement.

Authority, security and reliability

No provider discovery, host TLS, global errno fallback, pointer-keyed thread table or implicit mapping/execution grant is introduced. The original producer retains writable NX storage and immutable template/module inputs. Runtime callbacks retain their actual code/mapping lifetime premise and are cleanup duties, not portable authority records.

An unreturned callback, failed native exit or uncertain retirement retains original state and first failure. Ordinary work cannot resume, and join/detach cleanup must establish genuine departure before erasure or backing reuse. New profiles must not weaken existing artifact-TLS refusal or legacy image checks.

Acceptance criteria

  • Initialize and bind actual private state for first and additional native threads before execution.
  • Demonstrate distinct errno, locale and conversion state through real compiled native entries.
  • Implement key creation/deletion/get/set with zero initial values, generation reuse and resource-exhaustion refusal.
  • Exercise destructor reinstallation, repeated passes, reentrancy, deleted keys and unreturned callbacks without aliasing or losing cleanup duty.
  • Prove native exit/join/detach retirement precedes state erasure and reuse; reject foreign, legacy, malformed and restored-after-refusal state.
  • Preserve original producer, mapping, caller, older scenario and resource-bound controls; document inline/component/manual contracts and source cohorts.

Alternatives and tradeoffs

Reusing the reserved TCB word would silently change an existing contract. A pointer-indexed global table would add lookup state without original per-thread ownership. A versioned extension gives producers and consumers an explicit compatibility boundary. Exact state layout and consumer slot names will be frozen together before implementation.

Tracking and rollout

Related: libc design, ELF/TLS design. Coordinate locale and multibyte consumers, then publish source-bound producer/runtime branches and a genuine native workload. Parsing, hosted tests and source availability remain separate from guest acceptance.

Semantic reference: POSIX thread-specific key creation. No third-party implementation code is used.

## Problem and motivation Native threads have original TLS/errno images, but lack private runtime storage for locale selection, default multibyte state, TLS keys and destructor progress. The current 32-byte TCB has no spare field. A process-global table indexed by a thread pointer would not establish original storage ownership or safe reuse. ## Proposed behavior and scope Select an explicit extended thread-runtime profile for both initial and additional threads. Preserve the existing 32-byte prefix and its zero reserved word. The proposed 64-byte TCB adds a runtime version marker, original state pointer, complete state extent and generation/correlation word at offsets 32, 40, 48 and 56. The original TLS producer allocates and initializes that private state before Start. Native entry borrows the actual mapped storage under the original process/thread lifetime; header values validate correlation, never authenticate or create an owner. Legacy images remain explicitly selected and cannot satisfy the extended runtime. State includes a typed 16-byte locale cell, separate 32-byte function-specific default conversion states, and thread-specific key/value and destructor progress. Locale starts in global-selection mode; classification reads a copied atomic profile, not an arbitrary locale pointer. Key storage uses the explicitly selected process heap and caller resource policy, with generation-qualified reuse rather than a private key-count ceiling. Integrate the actual initial/additional entry and returned-callback/self-exit paths. Destructor calls clear the current value first, execute outside locks and mutable state borrows, and permit reentrant key updates. Repeated passes follow the selected POSIX destructor-iteration policy. The process, code and backing owners remain live until actual native retirement; local destructor completion alone cannot authorize reuse. Affected owners are LibCstd, LibDynlink, Loaderd, Procd, Posixd and Integration. General dynamic module unloading remains its separate lifecycle requirement. ## Authority, security and reliability No provider discovery, host TLS, global errno fallback, pointer-keyed thread table or implicit mapping/execution grant is introduced. The original producer retains writable NX storage and immutable template/module inputs. Runtime callbacks retain their actual code/mapping lifetime premise and are cleanup duties, not portable authority records. An unreturned callback, failed native exit or uncertain retirement retains original state and first failure. Ordinary work cannot resume, and join/detach cleanup must establish genuine departure before erasure or backing reuse. New profiles must not weaken existing artifact-TLS refusal or legacy image checks. ## Acceptance criteria - [ ] Initialize and bind actual private state for first and additional native threads before execution. - [ ] Demonstrate distinct errno, locale and conversion state through real compiled native entries. - [ ] Implement key creation/deletion/get/set with zero initial values, generation reuse and resource-exhaustion refusal. - [ ] Exercise destructor reinstallation, repeated passes, reentrancy, deleted keys and unreturned callbacks without aliasing or losing cleanup duty. - [ ] Prove native exit/join/detach retirement precedes state erasure and reuse; reject foreign, legacy, malformed and restored-after-refusal state. - [ ] Preserve original producer, mapping, caller, older scenario and resource-bound controls; document inline/component/manual contracts and source cohorts. ## Alternatives and tradeoffs Reusing the reserved TCB word would silently change an existing contract. A pointer-indexed global table would add lookup state without original per-thread ownership. A versioned extension gives producers and consumers an explicit compatibility boundary. Exact state layout and consumer slot names will be frozen together before implementation. ## Tracking and rollout Related: [libc design](https://git.erikinkinen.fi/erix/lib-cstd/issues/1), [ELF/TLS design](https://git.erikinkinen.fi/erix/lib-dynlink/issues/4). Coordinate locale and multibyte consumers, then publish source-bound producer/runtime branches and a genuine native workload. Parsing, hosted tests and source availability remain separate from guest acceptance. Semantic reference: [POSIX thread-specific key creation](https://pubs.opengroup.org/onlinepubs/9799919799/functions/pthread_key_create.html). No third-party implementation code is used.
erikinkinen added this to the Alpha 1 milestone 2026-11-08 12:14:46 +01:00
Author
Owner

The process-heap-backed state and key cleanup implementation is available in #89. Native entry remains incomplete.

To connect both initial and additional producers without linking the C runtime into shared loader code, the versioned byte layout and its initializer will move to a small dependency-free lib-thread-runtime-abi workspace package in LibIPC. LibDynlink and LibCstd will consume that same package. The existing IPC protocol crate will not gain a dependency on LibCstd, and the legacy 32-byte profile remains independently selectable.

The package describes the explicit extended header, private state extent and conversion slots; it grants no memory, thread or callback ownership. Producers must retain actual initialized mappings through native retirement, and the process root must register the actual state before runtime use. Native build/source inventories must include the new package before the extended profile can be selected.

The process-heap-backed state and key cleanup implementation is available in #89. Native entry remains incomplete. To connect both initial and additional producers without linking the C runtime into shared loader code, the versioned byte layout and its initializer will move to a small dependency-free `lib-thread-runtime-abi` workspace package in LibIPC. LibDynlink and LibCstd will consume that same package. The existing IPC protocol crate will not gain a dependency on LibCstd, and the legacy 32-byte profile remains independently selectable. The package describes the explicit extended header, private state extent and conversion slots; it grants no memory, thread or callback ownership. Producers must retain actual initialized mappings through native retirement, and the process root must register the actual state before runtime use. Native build/source inventories must include the new package before the extended profile can be selected.
Author
Owner

Initial producer selection will be explicit: Loaderd’s thread-runtime-state Cargo feature selects the extended image builder; default builds retain the legacy profile. No object name or copied header selects runtime ownership.

The extended image appends a 16-aligned 592-byte state after the original DTV. Deployment sizing therefore needs a real descriptor extension, rather than disguising the state as a larger TCB. ERIXLDCAPLAY0002 keeps its existing 28-word prefix. Feature-off builds remain version 3 with 28 words and TCB32. Feature-on builds use version 4 with 30 words: word 16 is the actual TCB64, word 28 is state alignment 16 and word 29 is state size 592. The Integration capacity calculation must consume those selected fields before native production.

Initial entry registers generation-one storage from the original mapped image. Additional threads allocate real state on the same process heap and retain it before native Start. Genuine native retirement remains required before backing reuse.

Initial producer selection will be explicit: Loaderd’s `thread-runtime-state` Cargo feature selects the extended image builder; default builds retain the legacy profile. No object name or copied header selects runtime ownership. The extended image appends a 16-aligned 592-byte state after the original DTV. Deployment sizing therefore needs a real descriptor extension, rather than disguising the state as a larger TCB. `ERIXLDCAPLAY0002` keeps its existing 28-word prefix. Feature-off builds remain version 3 with 28 words and TCB32. Feature-on builds use version 4 with 30 words: word 16 is the actual TCB64, word 28 is state alignment 16 and word 29 is state size 592. The Integration capacity calculation must consume those selected fields before native production. Initial entry registers generation-one storage from the original mapped image. Additional threads allocate real state on the same process heap and retain it before native Start. Genuine native retirement remains required before backing reuse.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
erix/lib-cstd#85
No description provided.