Skip to content

Conversation

@emeryberger
Copy link
Member

Summary

This PR adds Windows platform support to the Mesh allocator. The port includes:

  • Platform abstraction layer (src/platform/) for cross-platform memory operations
  • Modern Windows memory APIs (VirtualAlloc2, MapViewOfFile3) for page-granular meshing on Windows 10 1803+
  • MSVC compiler compatibility - intrinsics for popcnt/ctz/clz, attribute mappings, type definitions
  • Windows threading - TLS via TlsAlloc, background mesh thread using Windows events
  • Vectored Exception Handler for mesh write barriers (replaces Unix signal handlers)
  • CMake build support for Windows (produces mesh.dll and mesh_static.lib)
  • Windows-specific memory stats using GetProcessMemoryInfo
  • Malloc-free debug printf using vendored printf library (safe to use inside allocator)

New Files

  • src/platform/vmem_windows.cc - Modern Windows memory APIs with fallback for older Windows
  • src/platform/exception_handler_windows.cc - VEH for meshing page faults
  • src/runtime_windows.cc - Windows-specific runtime initialization
  • src/memory_stats_windows.cc - RSS measurement via PSAPI
  • src/testing/fragmenter_windows.cc - Windows fragmentation test
  • src/debug_printf.h, printf.c, putchar.c - Malloc-free debug output

Build Instructions

# Configure (from repo root)
cmake -B build-win -DCMAKE_BUILD_TYPE=Release

# Build
cmake --build build-win --config Release

# Test
build-win/bin/Release/fragmenter_test.exe

Requirements

  • Windows 10 version 1803+ for full meshing support (falls back to allocation-only on older Windows)
  • Visual Studio 2019 or later with C++17 support
  • CMake 3.13+

Test plan

  • Basic allocation/deallocation works
  • Thread-local heap operations work
  • Background mesh thread starts and runs
  • mesh.compact mallctl triggers meshing logic
  • Data integrity verified after allocations

🤖 Generated with Claude Code

@emeryberger emeryberger force-pushed the windows_port_test branch 7 times, most recently from c64bc95 to 591577f Compare January 2, 2026 17:37
Add experimental Windows support for the Mesh memory allocator:

Platform abstraction:
- Add Windows implementations for virtual memory operations (VirtualAlloc2, MapViewOfFile3)
- Add vectored exception handler for meshing fault handling
- Add Windows memory stats via GetProcessMemoryInfo
- Abstract file handle type for cross-platform memfd/pagefile support

Compiler compatibility (MSVC):
- Replace GCC builtins with MSVC intrinsics (__popcnt64, _BitScanForward64, etc.)
- Add Windows type definitions (ssize_t, pid_t)
- Handle attribute syntax differences between compilers
- Add pthread compatibility layer using Windows TLS API

Build system:
- Add Windows targets to Bazel BUILD file (mesh.dll, mesh_static_windows)
- Add Windows configuration to CMakeLists.txt
- Link against kernel32, psapi, advapi32

Debug infrastructure:
- Add malloc-free debug printf using vendored printf library
- Guard all debug instrumentation with MESH_DEBUG_VERBOSE

Meshing on Windows requires Windows 10 version 1803+ for page-granular
file mapping. Older versions fall back to allocation-only mode.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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