Skip to content

rigs: page-3 scratch for the SYS trampolines (#209, #247 item 1) - #257

Merged
JC-000 merged 4 commits into
masterfrom
fix/rig-tools-209-scratch
Sep 29, 2026
Merged

JC-000 merged 4 commits into
masterfrom
fix/rig-tools-209-scratch

Conversation

@JC-000

@JC-000 JC-000 commented Sep 25, 2026 •

Copy link
Copy Markdown
Owner

Fixes #209
Fixes #247 (item 1)

Stack: #254 → #257 → #256. This PR is based on #254's branch, so its diff is only #209. GitHub retargets it to master when #254 merges.

Design

rig_https_local (and the print_body/p384 wrappers that run its main()), rig_https_live and rig_https_bad_finished now allocate their scratch from page 3, $0334-$03FF (204 B), through _memory_policy.build_policy_and_low_ram_arbiter. That window is outside every segment the link lays out, so a CRYPTO_OVERLAY reshuffle can no longer take it away.

  • Allocations are sized to what is written: routine 117 B (measured at address 0, since every operand is absolute), host 32 B (64 on live), path 8 B, and one 3-byte sentinel+progress+carry block. The poll reads that block as one 2-byte read, and three separate allocations had only been adjacent by first-fit luck. After the rebase onto rig_https_local / rig_https_bad_finished start the listener before taking the DeviceLock, so a queued run's ACCEPT_TIMEOUT expires #246 the routine is built only once the lock is held, and it is asserted to match the length allocated before the lock.
  • c64-test-harness withholds its own page-3 writers from the arbiter. The window is allocated raw only against the 5 writers audited as never called from tools/uci, and a test pins that audit. It now ignores a script's own local helper of the same name (rig_close_retry's opcode-emitting jsr). Any new harness page-3 writer makes the allocation fail instead of being overridden.
  • rig_https_live's default SENTINEL_POLL_TIMEOUT goes from 300 to 900 s.

Why page 3 is quiet while the trampoline runs

  • Link. Every memory area in cfg/c64-https-uci*.cfg (re-checked on 8aa1a49) starts at or above $07FF (LOADADDR); the only ones below are ZP_CRYPTO $22-$3F and ZP_WIDE $40-$7F. The one symbol that labels.txt puts in page 3 is cassette_buf = $0334, an equate in libs/nistcurves/src/constants.s. It is absent from build/c64-https.map (the map lists only exports that something imports), and no source in src/ or the two libs references it. Grepping src/, libs/nistcurves/src and libs/x25519/src for $0300-$03FF finds only protocol constants and a comment.
  • KERNAL. Of the KERNAL, our code calls only CHROUT ($FFD2, screen) and GETIN ($FFE4, keyboard); nothing calls SETLFS/OPEN/LOAD. The rig drives BASIC through the keyboard buffer ($0277, $C6) and SYS. $033C-$03FB is the datasette buffer, which only tape I/O uses, and $0334-$033B and $03FC-$03FF are unused by the KERNAL. The window starts just above the $0314-$0333 vectors. RAMTAS clears pages 2-3 at reset, which is why the rigs write their scratch after the load and the BASIC return.
  • Runtime. On hardware the trampoline at $035F/$037F ran the whole handshake and GET and came back to write its sentinel. A page-3 byte overwritten mid-run would have left the sentinel unset or crashed the return.

Red-green

Hardware (U64E 10.43.23.81, fw c47155b7, via DeviceLock), on the stack top 42e32a0 (#256, which contains this PR)

  • rig_https_live on uci-comb PRG ed681de15314565f69325c918e621e6a0bd3ebe8af140d1bc7d9a46160e8315d (BACKEND=uci USE_NISTCURVES_ONCHIP_COMB=1, default target): HTTPS_TARGET=lwn.net gave PASS: HTTP 200, carry 0, tls_reached_connected=CONNECTED, trampoline at $037F, CFIN at 43.7 s.
  • rig_https_local on uci-onchip PRG c698b8c0cc535ec978a7ccaac4efe1627da45fb7a9c11625d41821f86153bf30 (HTTPS_SNI=www.foo.invalid) PASSED with no ACCEPT_TIMEOUT override. Scratch: markers $0334-$0336, host $0337-$0356, path $0357-$035E, trampoline $035F-$03D3.
  • Pre-rebase (cf89a98): rig_https_local and bad-mode rig_https_bad_finished on uci-comb aedf8f5a… both PASSED.

Not proven / out of scope

🤖 Generated with Claude Code

@JC-000
JC-000 force-pushed the fix/rig-tools-209-scratch branch from de0fc6d to 30a075b Compare September 29, 2026 03:08
@JC-000
JC-000 changed the base branch from master to fix/rig-tools-246-234-247 September 29, 2026 03:08
@JC-000
JC-000 marked this pull request as ready for review September 29, 2026 03:09
@JC-000
JC-000 force-pushed the fix/rig-tools-246-234-247 branch from 9bc40d6 to 65c042e Compare September 29, 2026 03:28
@JC-000
JC-000 force-pushed the fix/rig-tools-209-scratch branch from 30a075b to be68373 Compare September 29, 2026 03:28
JC-000 and others added 4 commits September 28, 2026 22:37
#209)

rig_https_local (and the print_body/p384 wrappers that run its main()),
rig_https_live and rig_https_bad_finished carved 387 B of scratch from a
linked-region tail; on uci-comb the CRYPTO_OVERLAY tail is ~110-126 B, so
they died in MemoryArbiter.alloc before touching the device. They now
allocate from $0334-$03FF (_memory_policy.build_policy_and_low_ram_arbiter):
outside every segment the link lays out, so a cfg reshaping CRYPTO_OVERLAY
cannot take it. Sizes are what is written: the routine's measured length
(117 B), host 32 B (64 B on live), path 8 B, and one 3-byte marker block
(the poll already read sentinel+progress as one 2-byte blob, which three
separate allocs only satisfied by first-fit luck; the 16-byte clear that
ran 13 bytes past it is now 3).

c64-test-harness withholds its own page-3 writers from the arbiter; the
window is allocated raw only for the five owners audited as never called
by a tools/uci rig, and any new page-3 writer in the harness refuses the
allocation instead of being overridden.

tools/test_rig_scratch.py (new, in testpaths) runs each rig's main() on a
uci-comb labels fixture up to the DeviceLock; the three allocation cases
fail on master with #209's exact MemoryArbiterError.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
github.com's / is ~576 KB chunked at ~2 KB/s (measured by the uci-socket
lane), so the 300 s default ended every full fetch as a TIMEOUT rather than
a result.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…r rig (#209)

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@JC-000
JC-000 force-pushed the fix/rig-tools-209-scratch branch from be68373 to 8a7eeb1 Compare September 29, 2026 03:37
@JC-000
JC-000 changed the base branch from fix/rig-tools-246-234-247 to master September 29, 2026 03:41
@JC-000
JC-000 merged commit 8a4b673 into master Sep 29, 2026
@JC-000
JC-000 deleted the fix/rig-tools-209-scratch branch October 14, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant