Files
Ahmed Arif 4c3d15abe6 [CLANG][SDK] Add the llvm-compat runtime shim library (#9094)
llvm-mingw's static runtime (libc++, libmingwex, libc++abi, libunwind)
references symbols the NT 5.2 export surface does not provide. Add a
static library, linked into the Clang runtime chain below
DLL_EXPORT_VERSION 0x601, providing:

- C99 vsnprintf/snprintf on top of _vsnprintf/_vscprintf.
- __imp_* aliases binding dllimport references to the static CRT
  definitions instead of ucrtbase import thunks, which collide with
  them (lld: "<sym> was replaced").
- K32EnumProcessModules, forwarded to psapi's EnumProcessModules.
- The Win7 SRW lock and Vista condition variable surface, bound to the
  RTL implementation linked statically from rtl_vista. Modules get one
  self-contained, consistent synchronization implementation (ReactOS'
  lock layout is not Windows-compatible), no kernel32_vista.dll
  dependency, and stay runnable on any Windows version. Static SRW
  linking suggested by Timo Kreuzer.

Address review feedback on the llvm-compat shims:

sync_static.c now uses the proper SDK/NDK headers with WINAPI/NTAPI, imp_alias.h
moved to sdk/include/reactos and fixes the msvcrtex slot decorations too, and a
new InitOnceExecuteOnce shim lets us drop libkernel32_vista from the interface.
2026-07-29 11:27:59 +00:00

50 lines
1.2 KiB
C

/*
* PROJECT: ReactOS SDK
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: C99 printf-family shims for llvm-mingw runtime libraries
* COPYRIGHT: Copyright 2026 Ahmed Arif <[email protected]>
*/
#include <stdio.h>
#include <stdarg.h>
/* llvm-mingw's libc++ needs the C99 vsnprintf/snprintf contract, which msvcrt's _vsnprintf (aliased onto
* these names by the crt headers) does not follow: undo the mapping and bridge over _vsnprintf/_vscprintf */
#undef vsnprintf
#undef snprintf
int vsnprintf(char *buffer, size_t count, const char *format, va_list argptr)
{
va_list ap;
int result;
va_copy(ap, argptr);
result = _vsnprintf(buffer, count, format, ap);
va_end(ap);
if (result >= 0 && (size_t)result < count)
return result;
/* Truncated: terminate and return the would-be length */
if (count != 0)
buffer[count - 1] = '\0';
va_copy(ap, argptr);
result = _vscprintf(format, ap);
va_end(ap);
return result;
}
int snprintf(char *buffer, size_t count, const char *format, ...)
{
va_list argptr;
int result;
va_start(argptr, format);
result = vsnprintf(buffer, count, format, argptr);
va_end(argptr);
return result;
}