Skip to content

_Execute_once bug fix. #1356

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

Merged
merged 4 commits into from
Oct 8, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions stl/src/xonce.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
#include "awint.hpp"

_STD_BEGIN

struct _Xfg_trampoline_parameter {
void* _Pv;
_Execute_once_fp_t _Callback;
};

// TRANSITION, ABI
_CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Execute_once(
once_flag& _Flag, _Execute_once_fp_t _Callback, void* _Pv) noexcept { // wrap Win32 InitOnceExecuteOnce()
Expand All @@ -17,13 +23,15 @@ _CRTIMP2_PURE int __CLRCALL_PURE_OR_CDECL _Execute_once(
// we introduce _Xfg_trampoline which has PINIT_ONCE_FN's type signature and
// calls into _Callback as an _Execute_once_fp_t for XFG compatibility.

_Xfg_trampoline_parameter _Trampoline_parameter = {_Pv, _Callback};

PINIT_ONCE_FN _Xfg_trampoline = [](PINIT_ONCE _InitOnce, PVOID _Parameter, PVOID* _Context) {
const auto _Callback = reinterpret_cast<_Execute_once_fp_t>(_Context);
return static_cast<BOOL>(_Callback(_InitOnce, _Parameter, nullptr));
const auto _Trampoline_parameter = static_cast<_Xfg_trampoline_parameter*>(_Parameter);
return static_cast<BOOL>(_Trampoline_parameter->_Callback(_InitOnce, _Trampoline_parameter->_Pv, _Context));
};

return InitOnceExecuteOnce(
reinterpret_cast<PINIT_ONCE>(&_Flag._Opaque), _Xfg_trampoline, _Pv, reinterpret_cast<PVOID*>(_Callback));
reinterpret_cast<PINIT_ONCE>(&_Flag._Opaque), _Xfg_trampoline, &_Trampoline_parameter, nullptr);
}

[[noreturn]] _CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL
Expand Down