Skip to content

Native Windows support with Microsoft Windows Visual Studio (MSVC)#5890

Open
SamuelMarks wants to merge 7 commits into
aws:mainfrom
SamuelMarks:windows
Open

Native Windows support with Microsoft Windows Visual Studio (MSVC)#5890
SamuelMarks wants to merge 7 commits into
aws:mainfrom
SamuelMarks:windows

Conversation

@SamuelMarks

Copy link
Copy Markdown

Goal

Add native Windows support

Why

Windows has many users

How

Shims, mostly.

Callouts

N/A

Testing

It builds! - Can port the test suite too if you want.

Related

Resolve #4018

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Comment thread utils/s2n_safety.h
* Runs _thecleanup function on _thealloc once _thealloc went out of scope
*/
#if defined(_MSC_VER)
#define DEFER_CLEANUP(_thealloc, _thecleanup) _thealloc

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think disable DEFER_CLEANUP on Windows is the right decision. This macros is used to ensure that s2n-tls won't leak memory and all dynamically allocated memory are properly cleaned up.

Disabling DEFER_CLEANUP via zeroes on MSVC removes critical failsafe memory management that handles early returns across the codebase. Instead of forcing upstream macros to compile as C++ RAII or stripping them entirely, we implement a python AST-rewriting pass.

fix_defer_cleanup.py intercepts DEFER_CLEANUP calls during build setup. It copies the source files, parses the variable initialization and cleanup function, and dynamically wraps the remainder of the scope in a native MSVC \__try { ... } __finally { cleanup_fn(&var); }\ block.

CMakeLists.txt is then patched to source these rewritten C files, ensuring perfect runtime safety without modifying any original code.

Includes fix for conditionally compiled DEFER_CLEANUP scopes and vcpkg.json baseline requirement.
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 support (WiP)

2 participants