Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives #251

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

MikWells
Copy link

@MikWells MikWells commented Feb 12, 2025

…a fixed binary format

The windows_bootstamp clasa uses a simple C style string so that the binary format is the same in debug and release builds

There can be multiple modules which use boost interprocess named objects (e.g. named_recursive_mutex). These modules can be built in release or debug mode and hence the binary format of std::basic_string<> will differ. This results in an access violation if the windows_intermodule_singleton for the windows_bootstamp is created in a module built in release mode, and accessed in a module build in debug mode (or vice-versa). It is not only release versus debug that is an issue. The access violation could also occur if the modules are built with different compilers.

The solution is to create a new windows_intermodule_singleton because we cannot change the format of the existing windows_bootstamp class. The new singleton uses only C functions to allocate and free the the character string. This ensures that the build configuration mode or the compiler do not affect the binary layout of the singleton object.

The new windows_intermodule_singleton has a class name which includes a version number. E.g. windows_bootstamp::version1

If the layout of this class needs to change, then the version number must be incremented. This would then create a new singleton, which is required.

This is likely to resolve #94

…a fixed binary format

The windows_bootstamp clasa uses a simple C style string so that the binary format is the same in debug and release builds

There can be multiple modules which use boost interprocess named objects (e.g. named_recursive_mutex).
These modules can be built in release or debug mode and hence the binary format of std::basic_string<> will differ.
This results in an access violation if the windows_intermodule_singleton for the windows_bootstamp<CharT> is
created in a module built in release mode, and accessed in a module build in debug mode (or vice-versa).
It is not only release versus debug that is an issue. The access violation could also occur if the modules
are built with different compilers.

The solution is to create a new windows_intermodule_singleton because we cannot change the format of the existing windows_bootstamp<CharT> class.
The new singleton uses only C functions to allocate and free the the character string.
This ensures that the build configuration mode or the compiler do not affect the binary layout of the singleton object.

The new windows_intermodule_singleton has a class name which includes a version number. E.g. windows_bootstamp::version1

If the layout of this class needs to change, then the version number must be incremented. This would then create a new singleton, which is required.
@MikWells MikWells changed the title The windows_intermodule_singleton for getting the bootstamp path has … Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Mar 11, 2025
@MikWells MikWells changed the title Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives See also issue #94 Mar 11, 2025
@MikWells MikWells changed the title Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives See also issue #94 Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolve #94 Mar 11, 2025
@MikWells MikWells changed the title Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolve #94 Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolves #94 Mar 11, 2025
@MikWells MikWells changed the title Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolves #94 Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolve #94 Mar 11, 2025
@MikWells MikWells changed the title Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Likely to resolve #94 Fix crashes in Windows if mixing Debug/Release with interprocess synchronization primitives Mar 11, 2025
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.

Boost.Interprocess v1.66 - get_bootstamp segfault with C#
1 participant