[FEATURE] Implement the C runtime and libc required by the admitted toolchain #1

Open
opened 2026-09-12 07:56:26 +02:00 by erikinkinen · 8 comments
Owner

Problem and motivation

Compilers and build tools running inside EriX need a C runtime with real startup,
allocation, per-thread errors, stdio and POSIX behavior.

Proposed behavior and scope

Provide libc artifacts, headers, startup objects and the interfaces required by
the selected toolchain. The current byte/string contract covers nineteen
operations, including substring search.
Native memory, initialized-thread support and the
explicit error catalog
have separate source and link contracts. The catalog describes all 40 local/scalar assigned
EriX errors and supports complete copies into caller-owned storage. The separate integer conversion companion
provides four explicit fixed C-locale LP64 calls with full-width limits, exact
end pointers and error-only original thread errno writes. Remaining interfaces
must follow the admitted workload inventory.
The separate character and sorting companions supply fixed C-locale ASCII calls
and allocation-free qsort/bsearch with conventional and prefixed C names.
Their callback and relocation contracts are documented in the matching manual.

Authority, security and reliability

Initialize from validated launch input and use the caller's Posixd route for
mediated operations. Document pointer ownership, overflow, thread state and
fork/exec cleanup. Preserve original owners through partial failure and teardown.
Keep suspected vulnerabilities in the SECURITY.md reporting channel.
Apply security, reliability and performance in that order.

Acceptance criteria

  • Define static/shared libc artifacts, full headers, startup objects,
    symbol versions and the supported C ABI.
  • Implement entry/exit, argc/argv/env, auxiliary data, atexit and initialized
    runtime state without ambient discovery.
  • Complete the required memory/string interfaces and workload coverage.
    • Implement memcpy, memmove, memset and memcmp.
    • Implement strlen, strcmp, strncmp, memchr, strchr and strrchr.
    • Implement strcpy, strncpy, strcat and strncat.
    • Implement strspn, strcspn, strpbrk and strnlen.
    • Implement strstr with independent byte, guard-page, ABI and link controls.
    • Complete the remaining interfaces identified by the workload inventory.
    • Complete actual compatibility-consumer and workload adoption.
  • Implement malloc/calloc/realloc/free and aligned allocation with ownership,
    failure atomicity, zeroing and threaded behavior.
  • Complete per-thread errno and error strings with stable native mappings.
    • Implement the selected fixed C-locale catalog and whole caller-buffer
      copies; complete original ABI/guard/link checks and coherent source,
      Integration and manual/API adoption.
    • Complete native terminal-to-thread errno adapters, required assignments
      and workload mappings, preserving interruption and partial I/O.
    • Complete current/explicit locale error interfaces and mediated diagnostic
      streams with their lifetime and return contracts.
    • Demonstrate independent thread errors and complete native consumer/workload
      behavior through required VM and warning-free CI gates.
  • Implement required stdio, formatting, scanning and conversions, including
    partial I/O, flush, locking, locale, numeric bounds and varargs.
  • Implement file/directory/poll/terminal adapters through Posixd.
  • Implement process/signal/thread adapters and defined fork/exec behavior.
  • Implement required time, locale, multibyte, environment, search, sorting
    and math interfaces.
    • Supply the fourteen fixed C-locale ASCII character calls and their companion contracts.
    • Complete conventional ctype and current-locale interfaces.
    • Implement required multibyte conversion and encoding state.
    • Implement time and sleep through reviewed native mechanisms.
    • Implement caller-owned environment access with defined process behavior.
    • Complete qsort and bsearch with explicit callback and relocation contracts.
    • Complete required math and runtime helpers.
  • Resolve every required extension through the workload inventory, with
    explicit unsupported behavior rather than success-returning stubs.
  • Complete independent C/Rust probes for layout, linking, constructors, TLS,
    allocation, stdio, files, threads, signals and process lifecycle.
  • Complete strict warning-free component/consumer CI, FFI stress coverage,
    documentation and actual guest workloads.

Require formatting, strict Clippy, unit/doctests and warning-denied builds for
affected Rust configurations, plus relevant VM regressions. Keep meaningful
rustdoc and missing_docs enforcement in every crate, update component/manual/API
documents, and keep authored code below 1,000 physical lines.

Alternatives and tradeoffs

Implement the required semantics directly. Stubs would hide missing behavior;
unsupported extensions need an explicit decision and tool configuration or port.

Tracking and rollout

Libc review,
ABI,
Posixd,
Kernel,
manual review,
Integration review,
phase completion.
Both full EriX guest build generations and the external Rust/LLVM rebuild inside
EriX remain required.

The local catalog includes ERANGE=40; existing compatibility 1.25, NBF1 and NJR1 packets retain assignments 1–39. Catalog lookup does not emit those packets or supply native error mapping.

## Problem and motivation Compilers and build tools running inside EriX need a C runtime with real startup, allocation, per-thread errors, stdio and POSIX behavior. ## Proposed behavior and scope Provide libc artifacts, headers, startup objects and the interfaces required by the selected toolchain. The current byte/string contract covers nineteen operations, including [substring search](https://git.erikinkinen.fi/erix/lib-cstd/src/branch/feature/posix-compat/docs/substring-search.md). Native memory, initialized-thread support and the [explicit error catalog](https://git.erikinkinen.fi/erix/lib-cstd/src/branch/feature/posix-compat/docs/error-catalog.md) have separate source and link contracts. The catalog describes all 40 local/scalar assigned EriX errors and supports complete copies into caller-owned storage. The separate [integer conversion companion](https://git.erikinkinen.fi/erix/lib-cstd/src/branch/feature/posix-compat/docs/integer-conversion.md) provides four explicit fixed C-locale LP64 calls with full-width limits, exact end pointers and error-only original thread errno writes. Remaining interfaces must follow the admitted workload inventory. The separate character and sorting companions supply fixed C-locale ASCII calls and allocation-free `qsort`/`bsearch` with conventional and prefixed C names. Their callback and relocation contracts are documented in the matching manual. ## Authority, security and reliability Initialize from validated launch input and use the caller's Posixd route for mediated operations. Document pointer ownership, overflow, thread state and fork/exec cleanup. Preserve original owners through partial failure and teardown. Keep suspected vulnerabilities in the SECURITY.md reporting channel. Apply security, reliability and performance in that order. ## Acceptance criteria - [ ] Define static/shared libc artifacts, full headers, startup objects, symbol versions and the supported C ABI. - [ ] Implement entry/exit, argc/argv/env, auxiliary data, atexit and initialized runtime state without ambient discovery. - [ ] Complete the required memory/string interfaces and workload coverage. - [x] Implement memcpy, memmove, memset and memcmp. - [x] Implement strlen, strcmp, strncmp, memchr, strchr and strrchr. - [x] Implement strcpy, strncpy, strcat and strncat. - [x] Implement strspn, strcspn, strpbrk and strnlen. - [x] Implement strstr with independent byte, guard-page, ABI and link controls. - [ ] Complete the remaining interfaces identified by the workload inventory. - [ ] Complete actual compatibility-consumer and workload adoption. - [ ] Implement malloc/calloc/realloc/free and aligned allocation with ownership, failure atomicity, zeroing and threaded behavior. - [ ] Complete per-thread errno and error strings with stable native mappings. - [x] Implement the selected fixed C-locale catalog and whole caller-buffer copies; complete original ABI/guard/link checks and coherent source, Integration and manual/API adoption. - [ ] Complete native terminal-to-thread errno adapters, required assignments and workload mappings, preserving interruption and partial I/O. - [ ] Complete current/explicit locale error interfaces and mediated diagnostic streams with their lifetime and return contracts. - [ ] Demonstrate independent thread errors and complete native consumer/workload behavior through required VM and warning-free CI gates. - [ ] Implement required stdio, formatting, scanning and conversions, including partial I/O, flush, locking, locale, numeric bounds and varargs. - [ ] Implement file/directory/poll/terminal adapters through Posixd. - [ ] Implement process/signal/thread adapters and defined fork/exec behavior. - [ ] Implement required time, locale, multibyte, environment, search, sorting and math interfaces. - [x] Supply the fourteen fixed C-locale ASCII character calls and their companion contracts. - [ ] Complete conventional ctype and current-locale interfaces. - [ ] Implement required multibyte conversion and encoding state. - [ ] Implement time and sleep through reviewed native mechanisms. - [ ] Implement caller-owned environment access with defined process behavior. - [x] Complete qsort and bsearch with explicit callback and relocation contracts. - [ ] Complete required math and runtime helpers. - [ ] Resolve every required extension through the workload inventory, with explicit unsupported behavior rather than success-returning stubs. - [ ] Complete independent C/Rust probes for layout, linking, constructors, TLS, allocation, stdio, files, threads, signals and process lifecycle. - [ ] Complete strict warning-free component/consumer CI, FFI stress coverage, documentation and actual guest workloads. Require formatting, strict Clippy, unit/doctests and warning-denied builds for affected Rust configurations, plus relevant VM regressions. Keep meaningful rustdoc and `missing_docs` enforcement in every crate, update component/manual/API documents, and keep authored code below 1,000 physical lines. ## Alternatives and tradeoffs Implement the required semantics directly. Stubs would hide missing behavior; unsupported extensions need an explicit decision and tool configuration or port. ## Tracking and rollout [Libc review](https://git.erikinkinen.fi/erix/lib-cstd/pulls/3), [ABI](https://git.erikinkinen.fi/erix/lib-posixabi/issues/1), [Posixd](https://git.erikinkinen.fi/erix/posixd/issues/2), [Kernel](https://git.erikinkinen.fi/erix/kernel/issues/1), [manual review](https://git.erikinkinen.fi/erix/docs/pulls/4), [Integration review](https://git.erikinkinen.fi/erix/integration/pulls/12), [phase completion](https://git.erikinkinen.fi/erix/integration/issues/65). Both full EriX guest build generations and the external Rust/LLVM rebuild inside EriX remain required. The local catalog includes ERANGE=40; existing compatibility 1.25, NBF1 and NJR1 packets retain assignments 1–39. Catalog lookup does not emit those packets or supply native error mapping.
erikinkinen changed title from [FEATURE] [P10] Implement the C runtime and libc required by the admitted toolchain to [FEATURE] Implement the C runtime and libc required by the admitted toolchain 2026-09-12 08:02:05 +02:00
Author
Owner

The signed substring implementation adds strstr to the nineteen byte/string operations. It preserves the first match using constant local storage and leaves input permissions, lifetime and errno unchanged. The manual/API and Integration selection now match the complete body/alias cohort. Full libc, actual compatibility workloads and guest builds remain open. Native CI admission remains tracked in Integration #113.

The [signed substring implementation](https://git.erikinkinen.fi/erix/lib-cstd/commit/4dccc58cecf65f85a12d462cd662f4e3cf4a837c) adds `strstr` to the nineteen byte/string operations. It preserves the first match using constant local storage and leaves input permissions, lifetime and errno unchanged. The [manual/API](https://git.erikinkinen.fi/erix/docs/commit/f3218351ed57a6c61c7ab5d27e1bdf16d1e159a1) and [Integration selection](https://git.erikinkinen.fi/erix/integration/commit/feaea0bed0bc97be79d952920dae8c5c1cc5b990) now match the complete body/alias cohort. Full libc, actual compatibility workloads and guest builds remain open. Native CI admission remains tracked in [Integration #113](https://git.erikinkinen.fi/erix/integration/issues/113).
Author
Owner

The error catalog implementation is signed and pushed. It provides fixed C-locale descriptions and canonical names for all 39 assigned EriX errors, plus complete copies into caller-owned buffers. Unknown signed values and short buffers write nothing; these calls neither consult locale nor change errno. The error companion is separate, and compatibility packaging includes its original immutable data.

Integration and manual/API adoption are underway. Conventional error interfaces, further errno assignments, native mappings and mediated diagnostics remain open. The current CI run still stops at the runner prerequisite before assembly; it does not establish component acceptance.

The [error catalog implementation](https://git.erikinkinen.fi/erix/lib-cstd/commit/1ad230f92074f33a57d75cc2c81795d5d675d6eb) is signed and pushed. It provides fixed C-locale descriptions and canonical names for all 39 assigned EriX errors, plus complete copies into caller-owned buffers. Unknown signed values and short buffers write nothing; these calls neither consult locale nor change errno. The error companion is separate, and compatibility packaging includes its original immutable data. Integration and manual/API adoption are underway. Conventional error interfaces, further errno assignments, native mappings and mediated diagnostics remain open. The [current CI run](https://git.erikinkinen.fi/erix/lib-cstd/actions/runs/48) still stops at the [runner prerequisite](https://git.erikinkinen.fi/erix/integration/issues/113) before assembly; it does not establish component acceptance.
Author
Owner

The fixed C-locale catalog is implemented for all 39 assigned errors, with immutable message/name lookups and whole caller-buffer copies. Integration and the manual now cover the three exported operations. Thread error adapters, locale interfaces and complete native workloads remain open.

The fixed C-locale catalog is implemented for all 39 assigned errors, with immutable message/name lookups and whole caller-buffer copies. Integration and the manual now cover the three exported operations. Thread error adapters, locale interfaces and complete native workloads remain open.
Author
Owner

I propose adding four explicitly fixed-C-locale integer conversions:
erix_c_strtol, erix_c_strtoul, erix_c_strtoll and
erix_c_strtoull. The Rust declarations will use the same original x86_64
LP64/System V bodies. Signed results cover the complete i64 range; unsigned
results cover the complete u64 range. Long and long long share their signed or
unsigned implementation because both are 64 bits on this target.

The grammar follows the C/POSIX locale in
POSIX.1-2024 strtol/strtoll
and
strtoul/strtoull:
the six ASCII whitespace bytes, an optional sign, base zero or bases 2 through
36, and case-insensitive digits. Base zero selects decimal, octal or
hexadecimal. A hexadecimal prefix is consumed only when followed by a
hexadecimal digit. There is no binary-prefix extension. Parsing stops at the
first byte outside the selected digits; overflow still consumes the complete
digit sequence. No input length ceiling, allocation or repeated prefix scan is
introduced.

Successful conversion preserves errno. No conversion returns zero, restores
the original input pointer through a nonnull end pointer and preserves errno;
this chooses the standard's optional no-conversion error behavior explicitly.
An invalid base returns zero and sets the original thread's EINVAL without
reading the input or touching the end pointer. Signed overflow returns the
appropriate limit; unsigned magnitude overflow returns UINT64_MAX. Both set
the assigned local ERANGE40. A representable unsigned magnitude with a minus
sign is negated modulo 2^64. For a valid base, the end pointer reports the complete converted prefix,
including after overflow.

Callers supply readable input, optional writable end-pointer storage and an
already admitted original EriX thread image whenever errno is accessed. End-pointer
storage must be exclusive and disjoint from the input and original thread image;
a returned raw cursor grants no write permission or longer input lifetime. The
invalid-base path requires no input or end-pointer storage because neither is
accessed. The
conversion acquires no mapping, endpoint or storage authority, retains no
pointer, and uses the existing initialized-thread errno accessor with no host
or global fallback. Input bytes, derived pointers, thread state and companion
code keep their existing ownership and lifetime obligations. Local ERANGE40
does not enlarge the older compatibility or thread-result packet domains.

A separate conversion companion will select both original parser and thread
roles explicitly. Compatibility packaging will include those same bodies;
memory-only, thread-only and catalog-only products stay unchanged. Source,
receipt and consumer contracts will distinguish this component. Conventional
strto* names and current/explicit-locale interfaces remain separate until
locale ownership is defined. This slice does not provide stdio, floating-point
conversion or full libc.

Independent literal Rust and freestanding C controls will cover every base,
integer limits, signs, prefix edges, end pointers, long inputs, guarded and
read-only storage, original thread errno isolation and call-state preservation.
Source-role, object, archive, alias, relocation and negative-link controls will
cover the complete producer/consumer graph. Documentation and the manual will
describe the same contracts. Host results will remain distinct from native
EriX execution and the required guest builds.

I propose adding four explicitly fixed-C-locale integer conversions: `erix_c_strtol`, `erix_c_strtoul`, `erix_c_strtoll` and `erix_c_strtoull`. The Rust declarations will use the same original x86_64 LP64/System V bodies. Signed results cover the complete i64 range; unsigned results cover the complete u64 range. Long and long long share their signed or unsigned implementation because both are 64 bits on this target. The grammar follows the C/POSIX locale in [POSIX.1-2024 strtol/strtoll](https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtol.html) and [strtoul/strtoull](https://pubs.opengroup.org/onlinepubs/9799919799/functions/strtoul.html): the six ASCII whitespace bytes, an optional sign, base zero or bases 2 through 36, and case-insensitive digits. Base zero selects decimal, octal or hexadecimal. A hexadecimal prefix is consumed only when followed by a hexadecimal digit. There is no binary-prefix extension. Parsing stops at the first byte outside the selected digits; overflow still consumes the complete digit sequence. No input length ceiling, allocation or repeated prefix scan is introduced. Successful conversion preserves errno. No conversion returns zero, restores the original input pointer through a nonnull end pointer and preserves errno; this chooses the standard's optional no-conversion error behavior explicitly. An invalid base returns zero and sets the original thread's EINVAL without reading the input or touching the end pointer. Signed overflow returns the appropriate limit; unsigned magnitude overflow returns UINT64_MAX. Both set the assigned local ERANGE40. A representable unsigned magnitude with a minus sign is negated modulo 2^64. For a valid base, the end pointer reports the complete converted prefix, including after overflow. Callers supply readable input, optional writable end-pointer storage and an already admitted original EriX thread image whenever errno is accessed. End-pointer storage must be exclusive and disjoint from the input and original thread image; a returned raw cursor grants no write permission or longer input lifetime. The invalid-base path requires no input or end-pointer storage because neither is accessed. The conversion acquires no mapping, endpoint or storage authority, retains no pointer, and uses the existing initialized-thread errno accessor with no host or global fallback. Input bytes, derived pointers, thread state and companion code keep their existing ownership and lifetime obligations. Local ERANGE40 does not enlarge the older compatibility or thread-result packet domains. A separate conversion companion will select both original parser and thread roles explicitly. Compatibility packaging will include those same bodies; memory-only, thread-only and catalog-only products stay unchanged. Source, receipt and consumer contracts will distinguish this component. Conventional `strto*` names and current/explicit-locale interfaces remain separate until locale ownership is defined. This slice does not provide stdio, floating-point conversion or full libc. Independent literal Rust and freestanding C controls will cover every base, integer limits, signs, prefix edges, end pointers, long inputs, guarded and read-only storage, original thread errno isolation and call-state preservation. Source-role, object, archive, alias, relocation and negative-link controls will cover the complete producer/consumer graph. Documentation and the manual will describe the same contracts. Host results will remain distinct from native EriX execution and the required guest builds.
Author
Owner

The fixed catalog now includes ERANGE=40 and its original message, name and complete caller-buffer copy. Earlier entries retain their bytes and unknown inputs still return without access. Integration and manual adoption are continuing; existing packet vocabularies and native mappings remain separate.

The [fixed catalog](https://git.erikinkinen.fi/erix/lib-cstd/src/commit/b9adbd8abbeb18bc016842bfa410c259f88cf4df/docs/error-catalog.md) now includes ERANGE=40 and its original message, name and complete caller-buffer copy. Earlier entries retain their bytes and unknown inputs still return without access. Integration and manual adoption are continuing; existing packet vocabularies and native mappings remain separate.
Author
Owner

b15c0452 adds four explicit fixed C-locale integer conversions over one shared signed/unsigned parser. Base and prefix handling, full-width bounds, overflow endpoints and error-only original thread errno are implemented. The companion selects conversion and thread sources explicitly; compatibility keeps its existing receipt fields. The related GNU archive defect is closed. Integration consumers and generated manual/API references are being updated. Conventional aliases, locale ownership, floating conversion and stdio remain open.

[b15c0452](https://git.erikinkinen.fi/erix/lib-cstd/commit/b15c045255a3030bb9d36e82d9b2a4da2ef2fb4a) adds four explicit fixed C-locale integer conversions over one shared signed/unsigned parser. Base and prefix handling, full-width bounds, overflow endpoints and error-only original thread errno are implemented. The companion selects conversion and thread sources explicitly; compatibility keeps its existing receipt fields. The related [GNU archive defect](https://git.erikinkinen.fi/erix/lib-cstd/issues/6) is closed. Integration consumers and generated manual/API references are being updated. Conventional aliases, locale ownership, floating conversion and stdio remain open.
Author
Owner

The four explicit fixed C-locale LP64 conversions are published in Cstd b15c0452, with matching Integration source selection and manual/API pages. Bases, full-width bounds, overflow and digit endpoints use one parser. Success and no-conversion leave errno unchanged; errors write only the already admitted original thread errno. Locale, floating conversions, stdio and complete libc remain open.

The four explicit fixed C-locale LP64 conversions are published in [Cstd b15c0452](https://git.erikinkinen.fi/erix/lib-cstd/commit/b15c045255a3030bb9d36e82d9b2a4da2ef2fb4a), with matching [Integration source selection](https://git.erikinkinen.fi/erix/integration/commit/a696f3fe9277c0b7c5716080ead84407b4390fbe) and [manual/API pages](https://git.erikinkinen.fi/erix/docs/commit/e66ff4497f2d8237c4152f56a28bdbc6297cfb83). Bases, full-width bounds, overflow and digit endpoints use one parser. Success and no-conversion leave errno unchanged; errors write only the already admitted original thread errno. Locale, floating conversions, stdio and complete libc remain open.
Author
Owner

Signed 7e42dbc7 adds allocation-free qsort and bsearch, with conventional and prefixed C entry points. The caller supplies the array and comparator; the runtime acquires no allocator, locale, thread or service state. The callback and bytewise relocation contracts are documented. Matching manual/API work is underway in Docs PR4.

Signed [7e42dbc7](https://git.erikinkinen.fi/erix/lib-cstd/commit/7e42dbc751f7d99cae6f1d744c71ecc3a8af8bb9) adds allocation-free `qsort` and `bsearch`, with conventional and prefixed C entry points. The caller supplies the array and comparator; the runtime acquires no allocator, locale, thread or service state. The callback and bytewise relocation contracts are documented. Matching manual/API work is underway in [Docs PR4](https://git.erikinkinen.fi/erix/docs/pulls/4).
erikinkinen added this to the Alpha 1 milestone 2026-10-30 09:34:39 +01:00
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#1
No description provided.