[FEATURE] Share an explicit process heap between C and Rust #8

Open
opened 2026-10-26 07:49:49 +01:00 by erikinkinen · 0 comments
Owner

Problem and motivation

Native EriX programs can allocate Rust objects from explicitly supplied regions, but C callers have no matching allocation provider. A process needs one heap shared by C and Rust before larger C libraries and the external toolchain can run.

Proposed behavior and scope

Add an explicitly selected LibCstd heap provider over LibOwnedRegion's existing allocator. Implement malloc, calloc, realloc, free, aligned_alloc and posix_memalign, with namespaced declarations and optional conventional symbols. One process root owns the provider; shared libraries must not acquire separate heaps implicitly.

Add a Posixd native client and Integration fixture that supply a separate RW/NX heap range and genuine initialized thread state. Exercise conventional C calls and Rust allocation against the same allocator, including a native member thread. Preserve existing runtime companion products.

This supplies a fixed, caller-owned process heap. Anonymous mapping growth, general C entry/exit, artifact TLS, a complete sysroot and rebuilding Rust/LLVM inside EriX remain separate requirements.

Authority, security and reliability

Startup installs original exclusive backing once. The process retains its mapping and native thread owners through final execution; freeing a block does not unmap memory or refund a resource grant. Allocation introduces no service sender or capability. Errno uses the actual initialized current thread, with no process-global fallback.

Checked geometry precedes effects. Failed allocation preserves existing blocks; failed realloc preserves the old pointer and contents. A second installation cannot replace the heap. A missing or incompatible startup/provider role refuses before entry. Native uncertainty retains the original owners.

Acceptance criteria

  • Implement the complete allocation family and checked metadata over one existing region allocator, shared with Rust GlobalAlloc.
  • Define zero-size, alignment and overflow behavior; preserve errno on success, free and posix_memalign; preserve the output pointer on posix_memalign failure.
  • Provide explicit process-root symbols and reject missing, duplicate or substituted providers without changing existing companion products.
  • Add the genuine native C/Rust client, separate packaged heap range and initial/member-thread errno and lifetime checks.
  • Cover dirty calloc, moved and in-place realloc, exhaustion/recovery, failed replacement and startup failures; document backing, linker and thread requirements.
  • Demonstrate the native workload in EriX and retain the separate full sysroot and guest toolchain rebuild requirements.

Alternatives and tradeoffs

A second allocator would duplicate the existing region implementation. Implicit access to memory services would broaden every C caller's authority. An explicit fixed region provides useful allocation now while leaving counted growth and release to their own design.

Tracking and rollout

Related: libc scope, runtime companions, region allocator, POSIX runtime and phase 6. Land the provider and its native producer together; select it explicitly before extending consumers.

## Problem and motivation Native EriX programs can allocate Rust objects from explicitly supplied regions, but C callers have no matching allocation provider. A process needs one heap shared by C and Rust before larger C libraries and the external toolchain can run. ## Proposed behavior and scope Add an explicitly selected LibCstd heap provider over LibOwnedRegion's existing allocator. Implement `malloc`, `calloc`, `realloc`, `free`, `aligned_alloc` and `posix_memalign`, with namespaced declarations and optional conventional symbols. One process root owns the provider; shared libraries must not acquire separate heaps implicitly. Add a Posixd native client and Integration fixture that supply a separate RW/NX heap range and genuine initialized thread state. Exercise conventional C calls and Rust allocation against the same allocator, including a native member thread. Preserve existing runtime companion products. This supplies a fixed, caller-owned process heap. Anonymous mapping growth, general C entry/exit, artifact TLS, a complete sysroot and rebuilding Rust/LLVM inside EriX remain separate requirements. ## Authority, security and reliability Startup installs original exclusive backing once. The process retains its mapping and native thread owners through final execution; freeing a block does not unmap memory or refund a resource grant. Allocation introduces no service sender or capability. Errno uses the actual initialized current thread, with no process-global fallback. Checked geometry precedes effects. Failed allocation preserves existing blocks; failed `realloc` preserves the old pointer and contents. A second installation cannot replace the heap. A missing or incompatible startup/provider role refuses before entry. Native uncertainty retains the original owners. ## Acceptance criteria - [ ] Implement the complete allocation family and checked metadata over one existing region allocator, shared with Rust `GlobalAlloc`. - [ ] Define zero-size, alignment and overflow behavior; preserve errno on success, `free` and `posix_memalign`; preserve the output pointer on `posix_memalign` failure. - [ ] Provide explicit process-root symbols and reject missing, duplicate or substituted providers without changing existing companion products. - [ ] Add the genuine native C/Rust client, separate packaged heap range and initial/member-thread errno and lifetime checks. - [ ] Cover dirty `calloc`, moved and in-place `realloc`, exhaustion/recovery, failed replacement and startup failures; document backing, linker and thread requirements. - [ ] Demonstrate the native workload in EriX and retain the separate full sysroot and guest toolchain rebuild requirements. ## Alternatives and tradeoffs A second allocator would duplicate the existing region implementation. Implicit access to memory services would broaden every C caller's authority. An explicit fixed region provides useful allocation now while leaving counted growth and release to their own design. ## Tracking and rollout Related: [libc scope](https://git.erikinkinen.fi/erix/lib-cstd/issues/1), [runtime companions](https://git.erikinkinen.fi/erix/lib-cstd/pulls/3), [region allocator](https://git.erikinkinen.fi/erix/lib-owned-region/issues/3), [POSIX runtime](https://git.erikinkinen.fi/erix/posixd/issues/1) and [phase 6](https://git.erikinkinen.fi/erix/integration/issues/65). Land the provider and its native producer together; select it explicitly before extending consumers.
erikinkinen added this to the Alpha 1 milestone 2026-10-30 09:34:40 +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#8
No description provided.