mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-09-02 12:23:31 +00:00
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.
70 lines
2.0 KiB
C
70 lines
2.0 KiB
C
/*
|
|
* PROJECT: ReactOS CRT library
|
|
* LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
|
|
* PURPOSE: rand_s implementation
|
|
* COPYRIGHT: Copyright 2010 Sylvain Petreolle <[email protected]>
|
|
* Copyright 2015 Christoph von Wittich <[email protected]>
|
|
* Copyright 2015 Pierre Schweitzer <[email protected]>
|
|
*/
|
|
|
|
#include <precomp.h>
|
|
|
|
typedef BOOLEAN (WINAPI *PFN_SystemFunction036)(PVOID, ULONG); // RtlGenRandom
|
|
PFN_SystemFunction036 g_pfnSystemFunction036 = NULL;
|
|
|
|
/*********************************************************************
|
|
* rand_s (MSVCRT.@)
|
|
*/
|
|
int CDECL rand_s(unsigned int *pval)
|
|
{
|
|
HINSTANCE hadvapi32;
|
|
|
|
if (!pval)
|
|
{
|
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
*_errno() = EINVAL;
|
|
return EINVAL;
|
|
}
|
|
|
|
*pval = 0;
|
|
|
|
if (g_pfnSystemFunction036 == NULL)
|
|
{
|
|
PFN_SystemFunction036 pSystemFunction036;
|
|
|
|
hadvapi32 = LoadLibraryA("advapi32.dll");
|
|
if (!hadvapi32)
|
|
{
|
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
*_errno() = EINVAL;
|
|
return EINVAL;
|
|
}
|
|
|
|
pSystemFunction036 = (void*)GetProcAddress(hadvapi32, "SystemFunction036");
|
|
if (!pSystemFunction036)
|
|
{
|
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
*_errno() = EINVAL;
|
|
FreeLibrary(hadvapi32);
|
|
return EINVAL;
|
|
}
|
|
|
|
g_pfnSystemFunction036 = pSystemFunction036;
|
|
}
|
|
|
|
if (!g_pfnSystemFunction036(pval, sizeof(*pval)))
|
|
{
|
|
_invalid_parameter(NULL,_CRT_WIDE("rand_s"),_CRT_WIDE(__FILE__),__LINE__, 0);
|
|
*_errno() = EINVAL;
|
|
return EINVAL;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
// Small hack: import slot bound to the static definition, so the GCC and LLVM C++ runtimes can link
|
|
#if defined(__GNUC__) && (DLL_EXPORT_VERSION < 0x600)
|
|
#include <imp_alias.h>
|
|
IMP_ALIAS_CDECL(rand_s);
|
|
#endif
|