Repository navigation
Add 32-bit Windows (windows/386) support - #27
Merged
Merged
Conversation
syscall.NewCallbackCDecl panics on 386 when a callback argument is wider than uintptr. Since the callbacks are created in package-level variables, any 32-bit program importing go-winfsp crashed at init. Move the seven callbacks taking UINT64 by value (Create, CreateEx, Overwrite, Read, Write, SetBasicInfo, SetFileSize) into a !386 file unchanged, and add 386 variants that receive each 64-bit argument as its two 32-bit cdecl stack slots and recombine them. Refs winfsp#26 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Go aligns 64-bit fields to 4 bytes on 386, while MSVC aligns them to 8, so FileInfo landed at offset 4 instead of 8 and the struct was 100 instead of 104 bytes, garbling every directory entry. Add explicit padding after Size; the layout on 64-bit targets is unchanged. FileSystemAddDirInfo also derived its alignment from Go's Alignof, which is 4 on 386; use FSP_FSCTL_DEFAULT_ALIGNMENT (8) like the C FspFileSystemAddDirInfo. Refs winfsp#26 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Check the sizes and key offsets of the mirrored structs against the static asserts in winfsp/fsctl.h, so a layout mismatch on any architecture is caught without mounting. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The WinFsp installer ships winfsp-x86.dll, and 32-bit test binaries run under WOW64 on windows-latest. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Collaborator
|
Thank you for putting up this PR, I will review when I have spare time. I would also like to see if the examples run on 386 (WOW on Windows 64-bit is okay), it would be better if you have tested them. |
Contributor
Author
|
The passthrough example was already tested, see above description. |
Contributor
Author
|
Here are two additional manual test cases for the examples: SetupRunning examplesmemfsFirst terminal: Second terminal: passthroughFirst terminal: Second terminal: |
3 of 4 tasks
Collaborator
|
Okay, given that the whole PR is ready, and most of the PR looks fine to me, it just need some minor changes:
|
Contributor
Author
|
Fair points - I’ll adjust the PR. |
Contributor
Author
|
Adjusted the structure as per your comment. Also ran the manual tests again - everything worked as expected. |
Collaborator
|
LGTM |
Collaborator
|
Merged and tagged |
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.
Disclaimer: The code and this PR's description was written with support from Claude Opus 5.5 - I reviewed it and tested it to the best of my knowledge.
Fixes #26.
Importing go-winfsp in a 32-bit Windows program (
GOARCH=386) panics during package initialization, beforemain()runs and even if nothing is mounted:dll_windows.goalready pickswinfsp-x86.dllon 386, so 32-bit was meant to be supported. Two problems stood in the way.1. Callbacks with 64-bit arguments
On 386,
syscall.NewCallbackCDeclrefuses arguments wider thanuintptr. Seven callbacks take aUINT64by value:Create,CreateEx,OverwriteAllocationSizeRead,WriteOffsetSetFileSizeNewSizeSetBasicInfoBecause the callbacks are package-level variables, the panic happens at init.
x86 cdecl passes a 64-bit argument as two consecutive 32-bit stack slots, low word first. The seven callback definitions move unchanged into
filesystem_windows_64bits.go(//go:build windows && (amd64 || arm64)). A newfilesystem_windows_386.goreceives each 64-bit argument aslo, hi uint32and recombines them before calling the existingdelegateXhandlers, the same approach cgofuse takes inhost_nocgo_windows.go. The build tag picks the right file at compile time, so 64-bit builds compile the same code as before.2.
FSP_FSCTL_DIR_INFOlayoutGo aligns 64-bit fields to 4 bytes on 386, but MSVC aligns them to 8. The 64-bit fields in
FSP_FSCTL_DIR_INFOinherit that difference:FileInfooffsetNextOffsetoffsetfsctl.h, all archs)This garbled every directory entry.
TestMounton 386 listedg-size-123instead ofreg-size-123, because WinFsp read the name 4 bytes (2 UTF-16 chars) past where Go wrote it.The fix adds explicit
_ [6]bytepadding afterSize. amd64/arm64 already had this implicit padding, so their layout is unchanged.FileSystemAddDirInfotook its alignment fromunsafe.Alignof(FSP_FSCTL_DIR_INFO{}), which is 4 on 386. It now usesFSP_FSCTL_DEFAULT_ALIGNMENT(8), as the CFspFileSystemAddDirInfodoes.The other mirrored structs either contain no 64-bit fields or place them at 8-byte-aligned offsets, so they already match on x86. This covers
FILE_INFO,VOLUME_PARAMS_V0/V1,OPEN_FILE_INFO,NOTIFY_INFO,FSP_FILE_SYSTEMandFSP_FILE_SYSTEM_INTERFACE.Tests and CI
TestStructLayoutchecks sizes and key offsets of the mirrored structs against the static asserts infsctl.h. With the oldDIR_INFOdefinition it fails on 386 (sizeof = 100, want 104).go test -v ./...withGOARCH=386. The WinFsp installer shipswinfsp-x86.dll, and 32-bit test binaries run under WOW64 onwindows-latest.Testing done
On Windows 11 x64 with Go 1.27.1 and WinFsp installed:
go test ./...passes on amd64 and on 386, includingTestMount, which mountsT:.I mounted the 32-bit passthrough example and tested:
Size and data matched the backing file, which covers the high word of the
SetFileSize,WriteandReadarguments.A small probe file system that logs
SetBasicInfoarguments received identical creation, access and write times on 386 and amd64.Create, append, rename and directory listing behave the same on the 32-bit and 64-bit builds.
Not included
FSP_FSCTL_STREAM_INFO's Go mirror doesn't match C on any arch: it has a pointer where C has a flexible array. It's unused, so I left it alone.FSP_FSCTL_VOLUME_INFOis 84 bytes on 386 versus 88 in C, but only in trailing padding. Its size isn't used on the Go side.No public API changes.