[FEATURE] Duplicate strings through the explicit process heap #10

Open
opened 2026-10-26 11:57:23 +01:00 by erikinkinen · 0 comments
Owner

Problem and motivation

C tools need owned copies of strings that can be released through the process allocator. The existing byte-copy functions do not provide strdup or strndup.

Proposed behavior and scope

Add the two calls to the explicit process-heap runtime, with namespaced Rust declarations and partial C/C++ headers. Copy bytes through the first NUL or the supplied bound, allocate the exact checked extent and append a NUL. Return an independent allocation that the same free can release.

Use the POSIX string-duplication contract. Allocation failure returns NULL and sets the current EriX thread's ENOMEM; successful calls preserve errno.

Authority, security and reliability

Borrow only the caller's valid source bytes and the installed process heap. Do not acquire backing, discover a provider or install host symbols. Preserve the source and existing allocations on failure. Bounded duplication must not read beyond its count or an earlier NUL.

Acceptance criteria

  • Implement complete and bounded duplication over the shared C/Rust heap, with checked size arithmetic and no private length ceiling.
  • Provide explicit and conventional native symbols, documented Rust declarations and C/C++ headers.
  • Add independent byte, bounds, allocation-failure, errno and ownership controls.
  • Exercise both calls in the ordinary native C consumer and document their use.
  • Demonstrate the native workload and warning-free component checks.

Alternatives and tradeoffs

Reuse the process allocator instead of introducing a second string arena. These byte functions need no locale object or implicit environment lookup.

Tracking and rollout

Depends on the process heap. Coordinate native adoption with ordinary C startup and Phase 6.

## Problem and motivation C tools need owned copies of strings that can be released through the process allocator. The existing byte-copy functions do not provide `strdup` or `strndup`. ## Proposed behavior and scope Add the two calls to the explicit process-heap runtime, with namespaced Rust declarations and partial C/C++ headers. Copy bytes through the first NUL or the supplied bound, allocate the exact checked extent and append a NUL. Return an independent allocation that the same `free` can release. Use the [POSIX string-duplication contract](https://pubs.opengroup.org/onlinepubs/9699919799/functions/strdup.html). Allocation failure returns NULL and sets the current EriX thread's ENOMEM; successful calls preserve errno. ## Authority, security and reliability Borrow only the caller's valid source bytes and the installed process heap. Do not acquire backing, discover a provider or install host symbols. Preserve the source and existing allocations on failure. Bounded duplication must not read beyond its count or an earlier NUL. ## Acceptance criteria - [ ] Implement complete and bounded duplication over the shared C/Rust heap, with checked size arithmetic and no private length ceiling. - [ ] Provide explicit and conventional native symbols, documented Rust declarations and C/C++ headers. - [ ] Add independent byte, bounds, allocation-failure, errno and ownership controls. - [ ] Exercise both calls in the ordinary native C consumer and document their use. - [ ] Demonstrate the native workload and warning-free component checks. ## Alternatives and tradeoffs Reuse the process allocator instead of introducing a second string arena. These byte functions need no locale object or implicit environment lookup. ## Tracking and rollout Depends on the [process heap](https://git.erikinkinen.fi/erix/lib-cstd/issues/8). Coordinate native adoption with [ordinary C startup](https://git.erikinkinen.fi/erix/lib-cstd/issues/9) and [Phase 6](https://git.erikinkinen.fi/erix/integration/issues/65).
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#10
No description provided.