Skip to content

refactor(fspy-shm): adopt fspy_nostd on Windows - #666

Merged
wan9chi merged 18 commits into
mainfrom
agent/fspy-shm-windows-nostd
Aug 13, 2026
Merged

refactor(fspy-shm): adopt fspy_nostd on Windows#666
wan9chi merged 18 commits into
mainfrom
agent/fspy-shm-windows-nostd

Conversation

@wan9chi

@wan9chi wan9chi commented Aug 13, 2026

Copy link
Copy Markdown
Member

Motivation

The Windows preload opens and maps shared memory before main and under the loader lock, where Rust std lazy initialization is not a dependable foundation. This moves the Windows implementation onto no-std Win32 calls while preserving the existing fspy_shm API.

It is the Windows counterpart to #664: fspy_nostd provides small safe wrappers where it can enforce path, handle, or mapping ownership. fspy_shm calls DeviceIoControl and SetFileInformationByHandle directly because their buffer contracts and flags are specific to its sparse-file, sizing, and removal policy. The outer OsStr and io::Error conversion remains for the later public API migration.

Move Windows file handles, sparse-file operations, and mapped views behind direct no-std Win32 wrappers. Keep the existing fspy_shm public API while removing its production memmap2 and direct windows-sys use.

Co-authored-by: GPT-5 Codex <codex@openai.com>
@github-actions

github-actions Bot commented Aug 13, 2026

Copy link
Copy Markdown

fspy benchmark

linux

dynamic/launch             change  -0.04%  [ -7.31% ..  +6.59%]  overhead   +49.45%
dynamic/access             change  +0.29%  [-12.79% .. +21.67%]  overhead    +5.02%
dynamic/access-relative    change  +2.12%  [ -2.70% .. +25.11%]  overhead   +48.36%
static/launch              change  -0.09%  [ -7.18% ..  +6.52%]  overhead  +145.25%
static/access              change  +2.26%  [-10.36% .. +15.51%]  overhead  +821.69%
static/access-relative     change  +0.10%  [ -4.88% ..  +3.90%]  overhead +1162.48%

macos

dynamic/launch             change  +0.49%  [ -5.27% ..  +6.37%]  overhead  +238.10%
dynamic/access             change  -0.68%  [-59.33% ..  +5.23%]  overhead    +3.52%
dynamic/access-relative    change  -2.70%  [-44.43% .. +14.99%]  overhead  +244.45%

windows

dynamic/launch             change  +2.44%  [ -3.03% .. +10.52%]  overhead   +31.16%
dynamic/access             change  -0.36%  [ -2.40% ..  +2.78%]  overhead    +1.87%
dynamic/access-relative    change  -0.35%  [ -2.36% ..  +5.45%]  overhead    +2.07%

wan9chi and others added 17 commits August 13, 2026 13:09
Mirror the std remove_file fallback to FileDispositionInfoEx when DeleteFileW is denied, so dropping a shared-memory keeper removes the pathname while existing handles remain usable.

Co-authored-by: GPT-5 Codex <codex@openai.com>
Replace the policy-heavy map_file helper with one-to-one CreateFileMappingW and MapViewOfFile wrappers. Keep MappingView as the owned RAII view and move shared-memory policy into fspy_shm.

Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Co-authored-by: GPT-5 Codex <codex@openai.com>
Address review findings on the no-std adoption:

- Convert long backing paths to verbatim form in copy_path, matching the
  std conversion the raw CreateFileW/DeleteFileW calls no longer get.
- Give every Mapping a duplicated file handle closed only after its view
  unmaps, so the DELETE_ON_CLOSE fallback removal fires once the last
  view is gone on volumes without POSIX delete.
- Open reparse points rather than their targets when creating the
  backing file and in the delete-on-close fallback, as std does.
- Add the checked WideCStr::from_units_with_nul constructor and use it
  instead of a safe wrapper around the unchecked one.
- Export fspy_nostd::{bool_result, last_error} and drop the duplicate in
  fspy_shm.
- Add BorrowedHandle::try_clone_to_owned and reconcile the handle
  sentinel docs with their constructor contracts.
- Model PageProtection as an enum, drop create_file_mapping's unused
  name parameter, and omit the CreateAlways/OpenAlways dispositions
  whose already-existed signal create_file does not surface.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Assume NTFS on Windows 10 1607+, where POSIX delete unlinks a name even
while views of the file remain mapped:

- remove_file now opens the backing file and sets FileDispositionInfoEx
  with POSIX semantics directly, instead of trying DeleteFileW first.
- Drop the DELETE_ON_CLOSE fallback, and with it the duplicated file
  handle each Mapping held only to make that fallback fire after the
  last view unmapped.
- Remove the now-unused fspy_nostd delete_file wrapper,
  FileOptions::DELETE_ON_CLOSE, BorrowedHandle::try_clone_to_owned, and
  the Win32_System_Threading feature.
- Document the platform floor on ShmKeeper.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Replace the hand-rolled `\\?\` prefix logic with omnipath's
to_verbatim, which also normalizes through GetFullPathNameW first and
covers the device-path and drive-relative shapes the local version left
alone. omnipath is dependency-free and maintained by the author of
std's own Windows path handling. The copy_path unit tests are kept and
now pin the integration's behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedcargo/​omnipath@​0.1.610010093100100

View full report

@wan9chi
wan9chi marked this pull request as ready for review August 13, 2026 15:09
@wan9chi
wan9chi merged commit c8bf957 into main Aug 13, 2026
19 checks passed
@wan9chi
wan9chi deleted the agent/fspy-shm-windows-nostd branch August 13, 2026 15:09
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