Fix fork-shaped private-file mmap restore; record backing classes and advance apk runtime progress - #98
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 21c7225213
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| }; | ||
| var page = address; | ||
| while (page < address + mapped_length) : (page += frames.PageSize) { | ||
| const leaf = batch26_builder.query(page) catch shutdown(); |
There was a problem hiding this comment.
Back accessible mprotect transitions before querying absent leaves
When a supported MAP_FIXED | MAP_ANONYMOUS PROT_NONE reservation is later changed to readable or writable with mprotect, externalProcessOwnsPage accepts it via the runtime mapping table, but the reservation deliberately has no page-table leaf. This query therefore returns error.InvalidEntry and the catch shuts down the entire VM instead of allocating backing or returning an error to the guest. The same failure occurs when a backed mapping is changed to PROT_NONE and subsequently re-enabled.
AGENTS.md reference: AGENTS.md:L80-L84
Useful? React with 👍 / 👎.
| while (page < page_count) : (page += 1) { | ||
| const virtual = address + page * frames.PageSize; | ||
| if (externalPageOccupied({}, virtual)) _ = batch26_builder.unmapPage(virtual, .page_4k) catch shutdown(); | ||
| _ = batch26_builder.mapPage(virtual, @intFromPtr(&external_prepared_backing[external_next_backing + page]), .page_4k, .{ .read = true, .write = true, .user = true, .accessed = true, .dirty = true }) catch shutdown(); |
There was a problem hiding this comment.
Roll back fixed anonymous mappings when page-table allocation fails
When the bounded page-table frame pool is exhausted during a supported fixed anonymous replacement, this catch shutdown() powers off the whole runtime without a diagnostic or Linux ENOMEM. The mapping table has already been reclassified and earlier pages may already have been installed, so this path also lacks the rollback used by the non-fixed anonymous mapping transaction; prepare/map should remain failure-atomic and return the syscall error instead.
AGENTS.md reference: AGENTS.md:L80-L84
Useful? React with 👍 / 👎.
|
Holding merge on current head
Please repair only these two general semantics on the existing PR branch, add focused regressions for PROT_NONE -> accessible mprotect and mid-map fixed-anonymous failure rollback, rerun the recipe/validation gates and Playable Alpine, then immediately rerun the real apk ladder. Preserve the earned |
Motivation
/sbin/apk --versionlibcrypto ENOMEM and then iterate real QEMU apk pressure causally.Description
BackingClassand per-mappingbacking_start, and new mapping operations:setLastBacking,replaceBackingRange,protectRange,mappingAt, andreplaceBackingRangeinbounded_runtime_mappings.zig.bounded_fork_private_backing.zig, and wire snapshot/restore of the private-file pool and its cursor into the fork (clone) and parent restore (terminate) paths infreestanding_riscv64.zig.backing_startand record private-file backing on commit, and add stage-labeled ENOMEM diagnostics viaexternalMmapNoMemoryinlinux_rv64_file_mmap.zigand caller sites.mprotecthandling and validate that protection changes only apply to pages owned by the process (image/interpreter/break/runtime mappings), preserving physical backing, rejecting W+X, and issuing SFENCE.VMA/FENCE.I infreestanding_riscv64.zig...traversal with bounded buffers and traversal limits inbounded_namespace_lookup.zig.private_file_mapping_pagesincreased (2,048 → 3,072),prepared_table_pagesincreased, and caller-artifact linker transport relocated to avoid overlap.ZIGREF_MMAP_ENOMEM) and richer syscall trace context to help classify the first libcrypto ENOMEM and subsequent blockers.Testing
python3 tools/query-reference.py agent bootstrapandpython3 tools/query-reference.py agent doctor, which passed after creating the Python venv. (PASS)zig build test-recipe-run-hosted-morphic-runtimeandzig build check --summary all, and executedpython3 tools/developer-command.py validate-repositoryandPYTHONDONTWRITEBYTECODE=1 python3 tools/check-command-reference.py --check; these validation steps completed successfully. (PASS)/sbin/apk --version,--help, andapk info. The working loop found and recorded stage-specific failures, implemented bounded repairs, and re-ran until progress./sbin/apk --versionsucceeded (printedapk-tools 2.14.9, compiled for riscv64),--helpwas reached, andapk infowas executed and advanced into dependency loads but then faulted in muslmemset(PC ~0x4004df9a, store to0x8), which is the single next causal blocker to fix. (apk version/help: PASS;apk info: progressed but not fully successful)morphic,second,/,3.22.0,/tmp,hello,hello,still-alive). (PASS)Files changed:
COMMANDS.md,recipes/run-hosted-morphic-runtime/freestanding-riscv64.ld, and multiple sources underrecipes/run-hosted-morphic-runtime/src/includingbounded_fork_private_backing.zig,bounded_namespace_lookup.zig,bounded_runtime_mappings.zig,freestanding_riscv64.zig, andlinux_rv64_file_mmap.zig, and the new reportdocs/reports/AGENTIC_SNOWBALL_BATCH_32U.mddocumenting causal progress and the next blocker.Next action (evidence-backed): diagnose and repair the musl
memsetstore-fault in theapk inforun (store address0x8at PC0x4004df9a), fix the smallest causal producer of that null-derived destination, then rerun the unchangedapk infoand the multi-child restoration ladder immediately.Codex Task