Skip to content

vm: map every Win32 and Winsock code through MRI's errmap - #982

Merged
tannevaled merged 2 commits into
mainfrom
win32-errno-map
Nov 29, 2026
Merged

tannevaled merged 2 commits into
mainfrom
win32-errno-map

Conversation

@tannevaled

Copy link
Copy Markdown
Contributor

What

On Windows a syscall.Errno is the Win32 code itself. 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. Go defines syscall.ENOTDIR as ERROR_PATH_NOT_FOUND (3), so a path through a missing directory read as Errno::ENOTDIR. ERROR_DIR_NOT_EMPTY never matched ENOTEMPTY, so Dir.rmdir on a non-empty directory fell to Errno::ENOENT.

MRI maps the code first, through errmap and rb_w32_map_errno (win32/win32.c:145-300, v4.0.9). This PR does the same in one place:

  • errnoOfError returns the mapped number. sysFail, Dir.chdir, File.realpath, IO#pwrite, the flush and the connect error all see MRI's class. raiseFlushErr no longer maps on its own.
  • errIsErrno compares the mapped number. Dir.rmdir's ENOTEMPTY, and the two direct errors.Is(err, syscall.EINVAL) checks it now replaces (File.truncate, File#flock), see the Win32 codes.
  • The Winsock rows of errmap are ported in full: 43, where posixErrno held 15. posixErrno is removed.

Everywhere but Windows, mapHostErrno is the identity.

What stays a divergence

  • Eight Winsock classes: ESHUTDOWN, ETOOMANYREFS, EHOSTDOWN, EPFNOSUPPORT, ESOCKTNOSUPPORT, EPROCLIM, EUSERS and EREMOTE have no number in rbgo on any target (errnoUndefinedEverywhere). Those rows keep their WSA code and raise SystemCallError, as before. TestWSARowsWithoutAClass pins the list, so defining one of the names moves it out.
  • ENOTDIR built by Go: on Windows, an ENOTDIR that Go builds itself (os.MkdirAll, os.ReadDir, filepath.EvalSymlinks) is the number 3, which is indistinguishable from ERROR_PATH_NOT_FOUND, and maps to ENOENT. No raiser takes its error from those three today. The comment on errnoOfError says so.

Measured

  • Oracle: rubydiff against MRI 4.0.7 (arm64-darwin25). A program covering Dir.chdir through a missing directory, Dir.rmdir on a non-empty one, and File.truncate through a missing directory: the two engines agree. MRI prints Errno::ENOENT, Errno::ENOTEMPTY, Errno::ENOENT.
  • Tests:
    • TestAFailedCallRaisesMRIsClassOnEveryHost holds 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.
    • The Windows-only tests (TestMapHostErrnoIsRbW32MapErrno, TestWSARowsWithoutAClass, TestErrnoOfErrorMapsTheWin32Code) check the table against errmap row by row, plus the class errnoOfError and errIsErrno give a wrapped Win32 error.
  • Suite: go test ./internal/vm/ ./cmd/rbgo/ ./ passed locally on darwin (internal/vm 295 s).
  • Vet: buildscan --vet passed 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

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>
tannevaled and others added 2 commits November 28, 2026 23:44
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
tannevaled merged commit ed53586 into main Nov 29, 2026
26 checks passed
@tannevaled
tannevaled deleted the win32-errno-map branch November 29, 2026 00:11
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.

Windows: Errno classes come from the raw Win32 code; MRI maps it through rb_w32_map_errno first

1 participant