Repository navigation
vm: map every Win32 and Winsock code through MRI's errmap - #982
Merged
Merged
Conversation
tannevaled
added a commit
that referenced
this pull request
Nov 28, 2026
* vm: set the file-size limit in a child, not in the test process TestAFlushPastTheFileSizeLimitRaises lowered RLIMIT_FSIZE to 4 bytes in the test process itself. The limit is per process, so every file written while it held, by the other tests or by the testing package, was refused too: the arm64 lane of #982 failed with "can't write .../testlog.txt: file too large" after every test had passed. The limited flush now runs in a child copy of the test binary, which reports the class it raised on stdout. Negative control: leaving the child's limit unchanged makes the test fail ("fsize: raised " with no class). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: restore RLIMIT_FSIZE in the child before it exits The child printed "fsize: raised Errno::EFBIG" and PASS, then failed writing its own coverage data under -cover ("file too large") and exited with status 2 on the ubuntu and macos lanes. The limit is now restored right after the flush raised, before anything else in the child writes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * test: let the fsize child's coverage reach the profile The EFBIG arm of writeDirty is reached only in the child on macOS (no /dev/full there), and the child was started without -test.gocoverdir, so its counters were dropped and the coverage ratchet failed the macos lane: "internal/vm/io_dirty.go writeDirty 89.5% (was fully covered)". The parent now passes its own -test.gocoverdir on; the testing package merges every counter file in that directory into the profile. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
On Windows a syscall.Errno is the Win32 code itself, and errnoClasses is keyed by the numbers Go gives the POSIX names, so every raiser that looked a failed call's number up directly picked an unrelated class, or none. ERROR_PATH_NOT_FOUND (3) is Go's syscall.ENOTDIR there, so a path through a missing directory read as Errno::ENOTDIR where MRI raises Errno::ENOENT (witnessed on #978's Windows runner, for the flush), and rmdir of a non-empty directory (ERROR_DIR_NOT_EMPTY) fell to Errno::ENOENT. MRI maps the code first, through errmap and rb_w32_map_errno (win32/win32.c:145-300, v4.0.9). errnoOfError now does the same, once, so sysFail, chdir, realpath, pwrite, the flush and the dial error all see MRI's class. errIsErrno falls back on the mapped class, so ERROR_DIR_NOT_EMPTY is ENOTEMPTY for rmdir, and the two direct errors.Is(err, syscall.EINVAL) checks (File.truncate, flock) go through it. The Winsock rows are ported in full (43, where posixErrno held 15), and posixErrno is gone. Eight of their classes have no number in rbgo on any target (ESHUTDOWN, ETOOMANYREFS, EHOSTDOWN, EPFNOSUPPORT, ESOCKTNOSUPPORT, EPROCLIM, EUSERS, EREMOTE); those keep the WSA code and raise SystemCallError, as before. TestWSARowsWithoutAClass pins that list. Everywhere but Windows mapHostErrno is the identity. Fixes #980 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Three tests fed raw syscall.Errno values and read the class raised. On Windows the class now follows rb_w32_map_errno, so: - the "unclaimed errno" pickers in TestRaiseChdirErrFallbacks and TestRaiseDialErrFallbacks chose 1, ERROR_INVALID_FUNCTION, which maps to EINVAL and raises Errno::EINVAL; - TestRealpathSyscallErr fed syscall.ENOTDIR, which is 3 there (ERROR_PATH_NOT_FOUND) and maps to ENOENT, as in MRI. unclaimedHostErrno and hostErrnoFor scan host codes through mapHostErrno, up to 1<<16 since only codes from 10000 up are kept unmapped on Windows. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tannevaled
force-pushed
the
win32-errno-map
branch
from
November 28, 2026 22:50
1a767f2 to
4669ab8
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
On Windows a
syscall.Errnois the Win32 code itself.errnoClassesis keyed by the numbers Go gives the POSIX names, so every raiser that looked a failed call's number up directly picked an unrelated class, or none. Go definessyscall.ENOTDIRasERROR_PATH_NOT_FOUND(3), so a path through a missing directory read asErrno::ENOTDIR.ERROR_DIR_NOT_EMPTYnever matchedENOTEMPTY, soDir.rmdiron a non-empty directory fell toErrno::ENOENT.MRI maps the code first, through
errmapandrb_w32_map_errno(win32/win32.c:145-300, v4.0.9). This PR does the same in one place:errnoOfErrorreturns the mapped number.sysFail,Dir.chdir,File.realpath,IO#pwrite, the flush and the connect error all see MRI's class.raiseFlushErrno longer maps on its own.errIsErrnocompares the mapped number.Dir.rmdir's ENOTEMPTY, and the two directerrors.Is(err, syscall.EINVAL)checks it now replaces (File.truncate,File#flock), see the Win32 codes.errmapare ported in full: 43, whereposixErrnoheld 15.posixErrnois removed.Everywhere but Windows,
mapHostErrnois the identity.What stays a divergence
ESHUTDOWN,ETOOMANYREFS,EHOSTDOWN,EPFNOSUPPORT,ESOCKTNOSUPPORT,EPROCLIM,EUSERSandEREMOTEhave no number in rbgo on any target (errnoUndefinedEverywhere). Those rows keep their WSA code and raiseSystemCallError, as before.TestWSARowsWithoutAClasspins the list, so defining one of the names moves it out.os.MkdirAll,os.ReadDir,filepath.EvalSymlinks) is the number 3, which is indistinguishable fromERROR_PATH_NOT_FOUND, and maps to ENOENT. No raiser takes its error from those three today. The comment onerrnoOfErrorsays so.Measured
rubydiffagainst MRI 4.0.7 (arm64-darwin25). A program coveringDir.chdirthrough a missing directory,Dir.rmdiron a non-empty one, andFile.truncatethrough a missing directory: the two engines agree. MRI printsErrno::ENOENT,Errno::ENOTEMPTY,Errno::ENOENT.TestAFailedCallRaisesMRIsClassOnEveryHostholds that program with MRI's output as its expected value. It runs on every lane. On darwin and Linux it passes with or without the mapping; the Windows lane is the oracle for this PR, since no local run covers Windows.TestMapHostErrnoIsRbW32MapErrno,TestWSARowsWithoutAClass,TestErrnoOfErrorMapsTheWin32Code) check the table againsterrmaprow by row, plus the classerrnoOfErroranderrIsErrnogive a wrapped Win32 error.go test ./internal/vm/ ./cmd/rbgo/ ./passed locally on darwin (internal/vm295 s).buildscan --vetpassed under all 19 CI configurations. AIX and Plan 9, which no lane builds, cross-build.Fixes #980
Refs #978 (merged; it ported the Win32 rows and applied them to the flush alone)
🤖 Generated with Claude Code