Skip to content

Batch: std.ipc shared buffers, -> T! named scalars, std.worker joins its own threads, to_double_raw kept - #3884

Merged
paul-hammant merged 11 commits into
mainfrom
batch/nov27
Nov 28, 2026
Merged

paul-hammant merged 11 commits into
mainfrom
batch/nov27

Conversation

@paul-hammant

Copy link
Copy Markdown
Collaborator

One batch, a commit per change.

std.ipc: shared buffers (2207e87d2). Memory two processes map: shared_buffer(size), shared_buffer_fd, shared_buffer_map(fd, size), shared_buffer_map_readonly, shared_buffer_length, shared_buffer_view (byte[]), shared_buffer_read_view, shared_buffer_free. Linux and FreeBSD/NetBSD: memfd, its size sealed; macOS and OpenBSD: shm_open. Windows: not yet (refused with a reason). No sandbox grant needed: the descriptor is passed like any other over std.ipc.

Open questions, for review:

  1. The wording of the diagnostic when a read-only mapping is written.
  2. Whether to also seal with F_SEAL_FUTURE_WRITE where the kernel has it.
  3. On macOS the size check is page-granular (shm_open rounds up), so a mapping a little over the size but within the page is not refused.

Parse -> T! with a named scalar or a struct (d95ea39df). -> T! was only parsed for built-in scalar spellings.

std.worker: join a job's own thread once it is done, not detach it (d9ba16ffd). test_worker_pool printed PASS and then segfaulted (exit 139) under Wine on main at 6666346. run_detached's thread was detached at launch, and its job counted as done before the thread had freed it and returned, so main could return into process exit with the thread still on its way out. Those threads are now joined once their job is done (at the next launch, and at exit). Under wine 10.0 on Ubuntu 26.04, x86_64, 4 at a time: before, 4 failures in 6,000 runs; after, 0 in 6,000.

fs_open_binary_mode compares the program's stdout, not the compiler's warnings (a6af3448e). The intermittent UCRT64 failure (runs 45703887783, 45554335933): the test captured 2>&1, and on Windows the compiler's warnings end in CRLF, so a lone \r line got past the filter. It now compares stdout alone. The library was byte-exact throughout.

std.string: keep to_double_raw (9234defa9, docs ed80b5773, 7091f4672). 0.948.0 kept to_double, string_try_double and string_get_double under their old names but removed to_double_raw, so code calling it stopped linking (_string_to_double_raw undefined). It is back as a one-line alias of string_to_float_raw (the same 8-byte slot), with the same delete-once-unused TODO. tests/regression/test_string_to_double_raw.ae fails to compile on 0.948.0 and passes here.

Lanes:

  • ae-x64 (Ubuntu 22.04 x86_64, gcc), make ci: 2,400 passed, 1 failed, 20 skipped. The one is cross_emit_lib, whose --emit=staticlib build was still running at the 420 s limit under the full parallel run; alone it passes in 10 s, and it has not failed in CI. Watch it here.
  • ghostbsd (FreeBSD 15.1, native), build + test-ae: 2,387 passed, 0 failed (at 9234defa9; the two commits after are docs only).
  • macOS: check-api-docs, check-docs, check-changelog pass.
  • Wine (cachyos, ubuntu 26.04, wine 10.0): the worker loop above.

🤖 Generated with Claude Code

paul-hammant and others added 8 commits November 26, 2026 23:29
The return-type lookahead after `->` knew a postfix `?` between a type
name and the body (`-> Point? {`) but not a postfix `!`, so a fallible
result whose payload is a scalar spelt as a name (`f32`, `int64`,
`uint8`, `size_t`, `longdouble`, ...) or a struct was read as an
expression body and the `{` after it was a top-level parse error. The
type keywords (`int!`, `float!`, `byte!`) took another branch and
worked.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ipc.shared_buffer(size) makes a zeroed buffer of anonymous memory and
holds its close-on-exec descriptor (shared_buffer_fd), to pass with
ipc.send_fd. The receiver maps it with shared_buffer_map(fd, size), or
shared_buffer_map_readonly; the size is checked against the descriptor
(fstat), and a mismatch, a closed descriptor or one that is not shared
memory is an error. Both sides read and write it through a bounded
byte[] (shared_buffer_view, or the read-only shared_buffer_read_view,
the only view of a read-only mapping), so bulk data stays out of the
channel, which carries only short messages. Each buffer is a handle of
its own, unmapped with shared_buffer_free; nothing is kept in the
module.

- Linux, FreeBSD, NetBSD: memfd_create (MFD_CLOEXEC, and MFD_NOEXEC_SEAL
  on Linux 6.3+), its size sealed (F_SEAL_SHRINK|GROW|SEAL) so no holder
  can shrink it under a mapping. Called through libc, not syscall().
- macOS, OpenBSD, others: shm_open under a random name, O_EXCL, unlinked
  at once; macOS keeps such an object to whole pages, so the size check
  there is to the page. FreeBSD without memfd: SHM_ANON.
- Windows and builds without processes: an "unsupported" error, as for
  descriptor passing.

No grant: the memory reaches no file, socket or program. A child under
sandbox.spawn_socket with no grants maps a passed buffer and makes one of
its own (tests/integration/std_ipc_shared_buffer, Linux).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tests/regression/test_worker_pool.ae printed PASS and then the Wine
process died of SIGSEGV (exit 139) in the Windows-under-Wine job on
main at 6666346, on both attempts. It is a latent race, not the two
commits before it (contrib.xmp is not linked into the test, and the
to_float change only touches parsing): with wine 10.0 on Ubuntu 26.04,
as CI runs it, on real x86_64, the test binary fails about 1 run in
1000-2000 at 4 runs in parallel, 6/6000 and 5/10000.

The cause is run_detached. Its thread was pthread_detach'ed at launch,
and the job counts as retired (g_pending drops) before the thread has
finished with it: it then frees the job, takes g_lock to wake waiters,
returns through the thread trampoline and exits. The test waits for
pending() == 0 and returns from main, so the process exits while that
thread is still on its way out, and Wine crashes on the overlap. A
variant without the run_detached step failed 0/6000; one that sleeps
50 ms before returning, 0/6000; one with only the run_detached step,
1/6000; one without pool_shutdown, 8/6000, so the idle pool threads
are not involved.

Threads std.worker starts outside the pool (run_detached, and run or
submit when the pool cannot start) are now kept joinable on a list
under g_lock. A thread's last act is to set its done flag, so a join on
a done thread is immediate. Done threads are joined at the next launch,
which keeps the list as long as the number of such threads still
running, and at exit from an atexit handler. A thread still inside its
job at exit is not waited for: a detached job may block for good, and
it ends with the process as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…piler's warnings

The Windows UCRT64 job failed this test on main (runs 45703887783 and
45554335933) with two extra blank-looking lines ahead of the expected
output. The test ran `ae run ... 2>&1` and filtered the compiler's
diagnostics back out with grep patterns, and its program had two
unused variables, so a cold compile printed two W1001 warnings. On
Windows aetherc's stderr is a text-mode stream: every diagnostic line
ends in CRLF, so the blank line after each warning arrives as a lone
"\r", which `grep -v '^$'` keeps. The output captured on win11, put
through the test's filter with GNU grep 3.12 (the version on the
runner), gives exactly the CI failure: two "\r" lines, then the
expected five. The program's own stdout is LF (the runtime sets it to
binary). Whether a run shows it depends on the grep: MSYS2's grep 3.0
strips the CR, so the test passed on win11 with the old filter, and
passing CI runs had the same grep 3.12 package, so why some runs
passed is not settled; the test was wrong either way.

The test now captures stdout alone and sends stderr to a file it prints
on a failure, so neither the compiler's line endings nor anything else
it says on stderr (a stray aether.toml above the temp directory was a
second way to break it) reaches the comparison. The two unused
variables are renamed with a leading underscore. The library is
unchanged: fs.open's handles were byte-exact all along.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
0.948.0 kept to_double, string_try_double and string_get_double for the
code still calling them, but dropped to_double_raw, so that code stopped
linking (_string_to_double_raw undefined). It is back as a one-line alias
of string_to_float_raw: the same 8-byte `float` slot, the same 1 or 0,
with the same TODO as the other old names: delete once nothing calls it.

tests/regression/test_string_to_double_raw.ae fails to compile on 0.948.0
and passes here: 0.1 to 64 bits, agreement with to_float_raw on four
values, refusal of three non-numbers.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant

Copy link
Copy Markdown
Collaborator Author

@nicolas-maman @adilalperenciftci three open questions. I’ll merge it if it’s green and we can revisit if needed….

Sae is keeping Ae3d things (that three.js uses from QuickJs) in a separate process with shared memory. That’s not a fixed choice itself. Claude says you’d not want bloat sae’s exe size as many apps are 2d only. I might be misremembering its rationale

paul-hammant and others added 3 commits November 27, 2026 21:43
…ipc: shared buffers on Android

TSan (report_thread_leaks) called the worker's own threads leaked: a job
still running at exit was left joinable, neither joined nor detached. The
atexit handler now joins the finished ones and detaches the rest, which end
with the process as they did when every one was detached at launch.

The Android cross-build failed: bionic has no shm_open. A memfd from API 30,
where bionic gained memfd_create; before it (ANDROID_API 29, the default) a
buffer cannot be made, ENOSYS, while one received is still mapped.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A thread that had finished and was not yet reaped when the process forked
came into the child as a joinable thread nobody joins; a child that exits
without exec (one whose exec failed) then held it, and TSan reported a
thread leak in os_run_stdio's children. A pthread_atfork prepare handler now
takes g_lock and joins every done thread (each join is immediate: a done
thread has only its return left), and a thread marks itself done under
g_lock, so none can finish between those joins and the fork. The child
forgets its copy of the list; the threads in it are not its own, and
detaching them there trips TSan's own registry check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sweep

The ASan leg failed it: the child is an ASan program confined through the
sandbox's preload library, which ASan refuses to start under (its runtime
not first), and the sandbox passes it none of the sweep's ASAN_OPTIONS. The
reason tests/ae_sweep_prune_asan.txt leaves the sandbox tests out; here only
the sandboxed case goes, so the buffer itself is still held to ASan.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@paul-hammant
paul-hammant merged commit 69ae454 into main Nov 28, 2026
54 checks passed
@paul-hammant
paul-hammant deleted the batch/nov27 branch November 28, 2026 03:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant