From: Damjan Jovanovic Subject: [PATCH] ntdll: implement InterlockedCompareExchange64 within the unix library when needed Message-Id: Date: Thu, 24 Sep 2020 10:54:59 +0200 On 2 May 2020 a series of commits starting with adb45d2294c0b165970a9b7d03713c8bc768ba0a and ending with 7eef40d444b3325f9580ff557afb6bc19c811f5e changed the implementation of the InterlockedCompareExchange64 function to use GCC's builtin __sync_val_compare_and_swap, and fall back to the (kernel32?) InterlockedCompareExchange64 exported function if absent. 0c14b1a962573ee125940f2008c646befe597226 then fixed the problem with ntdll's unix library not linking when GCC lacked the builtin (which both GCC and Clang lack on FreeBSD i386), by (in effect) redefining it as RtlInterlockedCompareExchange64 and linking to ntdll which exports that. Recently 7571fa87df453e404d8b6ca58e2da95340156849 made ntdll's unix library link with -nodefaultlibs, so it cannot import RtlInterlockedCompareExchange64 from ntdll any more, recreating that linking regression when GCC lacks the builtin. This patch implements InterlockedCompareExchange64 within the unix library when it is unavailable from GCC, and gets the unix library to link again. Signed-off-by: Damjan Jovanovic --- dlls/ntdll/Makefile.in | 1 + dlls/ntdll/unix/cmpxchg64.c | 64 +++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) create mode 100644 dlls/ntdll/unix/cmpxchg64.c diff --git a/dlls/ntdll/Makefile.in b/dlls/ntdll/Makefile.in index f39ffb42c6f..341123f7488 100644 --- a/dlls/ntdll/Makefile.in +++ b/dlls/ntdll/Makefile.in @@ -44,6 +44,7 @@ C_SRCS = \ threadpool.c \ time.c \ unix/cdrom.c \ + unix/cmpxchg64.c \ unix/debug.c \ unix/env.c \ unix/file.c \ diff --git a/dlls/ntdll/unix/cmpxchg64.c b/dlls/ntdll/unix/cmpxchg64.c new file mode 100644 index 00000000000..032e32bb4c2 --- /dev/null +++ b/dlls/ntdll/unix/cmpxchg64.c @@ -0,0 +1,64 @@ +/* + * Large integer functions + * + * Copyright 2000 Alexandre Julliard + * Copyright 2003 Thomas Mertes + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#if 0 +#pragma makedep unix +#endif + +#include + +#include "ntstatus.h" +#define WIN32_NO_STATUS +#include "windef.h" +#include "winternl.h" +#include "wine/asm.h" + + +#ifndef _WIN64 + +/************************************************************************* + * RtlInterlockedCompareExchange64 (NTDLL.@) + */ +#ifndef __GCC_HAVE_SYNC_COMPARE_AND_SWAP_8 +__ASM_STDCALL_FUNC(RtlInterlockedCompareExchange64, 20, + "push %ebx\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") + __ASM_CFI(".cfi_rel_offset %ebx,0\n\t") + "push %esi\n\t" + __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t") + __ASM_CFI(".cfi_rel_offset %esi,0\n\t") + "movl 12(%esp),%esi\n\t" + "movl 16(%esp),%ebx\n\t" + "movl 20(%esp),%ecx\n\t" + "movl 24(%esp),%eax\n\t" + "movl 28(%esp),%edx\n\t" + "lock; cmpxchg8b (%esi)\n\t" + "pop %esi\n\t" + __ASM_CFI(".cfi_same_value %esi\n\t") + __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") + "pop %ebx\n\t" + __ASM_CFI(".cfi_same_value %ebx\n\t") + __ASM_CFI(".cfi_adjust_cfa_offset -4\n\t") + "ret $20") +#endif + +#endif /* _WIN64 */ +