[PATCH 0/1] MR9194: ntdll: Use ReadPointerAcquire to get pointer value in RtlRunOnceComplete.
This is needed on architectures with weak memory models like ARM64. Complements !9178 -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9194
From: Jinoh Kang <jinoh.kang.kr(a)gmail.com> This is needed on architectures with weak memory models like ARM64. --- dlls/ntdll/sync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dlls/ntdll/sync.c b/dlls/ntdll/sync.c index 3f8aa0b399d..1bd62612efe 100644 --- a/dlls/ntdll/sync.c +++ b/dlls/ntdll/sync.c @@ -116,7 +116,7 @@ DWORD WINAPI RtlRunOnceComplete( RTL_RUN_ONCE *once, ULONG flags, void *context for (;;) { - ULONG_PTR val = (ULONG_PTR)once->Ptr; + ULONG_PTR val = (ULONG_PTR)ReadPointerAcquire( &once->Ptr ); switch (val & 3) { -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/9194
Thanks a lot! Out of curiosity, maybe this could be a `ReadPointerNoFence`? There are three cases: 1. `STATUS_INVALID_PARAMETER` is returned: this is a programmer error, and no pointer is returned. 2. `InterlockedCompareExchangePointer` is called, which inserts a full memory fence. 3. `STATUS_UNSUCCESSFUL` is returned: the caller should retrieve the value that "won" by calling `RtlRunOnceBeginInitialize` with `RTL_RUN_ONCE_CHECK_ONLY`, which uses acquire semantics. That said, it's _safer_ to ensure acquire semantics in a central place and not in each code branch. So probably this is best for long-term code maintenance? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9194#note_118883
On Fri Oct 17 12:51:04 2025 +0000, Luca Bacci wrote:
Thanks a lot! Out of curiosity, maybe this could be a `ReadPointerNoFence`? There are three cases: 1. `STATUS_INVALID_PARAMETER` is returned: this is a programmer error, and no pointer is returned. 2. `InterlockedCompareExchangePointer` is called, which inserts a full memory fence. 3. `STATUS_UNSUCCESSFUL` is returned: the caller should retrieve the value that "won" by calling `RtlRunOnceBeginInitialize` with `RTL_RUN_ONCE_CHECK_ONLY`, which uses acquire semantics. That said, it's _safer_ to ensure acquire semantics in a central place and not in each code branch. So probably `ReadPointerAcquire` is better for code maintenance in the long term? Thanks for your comment!
Ideally the context should contain sll that is needed, but what if the "won" value is stored somewhere else? -- https://gitlab.winehq.org/wine/wine/-/merge_requests/9194#note_118884
participants (3)
-
Jinoh Kang -
Jinoh Kang (@iamahuman) -
Luca Bacci (@lb90)