Skip to content

Commit ad50a00

Browse files
committed
[UCRTBASE] Fix broken imports from ntdll
Previously sprintf and _vsnprintf were imported from ntdll. These functions are defined as inline functions in ucrt headers, but linked directly by legacy CRT code.
1 parent c37af4c commit ad50a00

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed

dll/win32/ucrtbase/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11

22
spec2def(ucrtbase.dll ucrtbase.spec ADD_IMPORTLIB)
33

4+
# Hack to replace the old CRT include directory with the UCRT include directory
5+
get_property(INCLUDE_DIRS DIRECTORY . PROPERTY INCLUDE_DIRECTORIES)
6+
list(REMOVE_ITEM INCLUDE_DIRS "${REACTOS_SOURCE_DIR}/sdk/include/crt")
7+
set_property(DIRECTORY . PROPERTY INCLUDE_DIRECTORIES ${INCLUDE_DIRS})
8+
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/ucrt)
9+
10+
remove_definitions(-D_CRT_NON_CONFORMING_SWPRINTFS)
11+
12+
add_compile_definitions(
13+
_UCRT
14+
_CORECRT_BUILD
15+
CRTDLL
16+
)
17+
418
add_library(ucrtbase SHARED
19+
printf.c
520
stubs.c
621
ucrtbase_stubs.c
722
ucrtbase.def

dll/win32/ucrtbase/printf.c

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/*
2+
* PROJECT: ReactOS CRT
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Instantiation of CRT stdio inline functions
5+
* COPYRIGHT: Copyright 2023-2024 Timo Kreuzer <[email protected]>
6+
*/
7+
8+
#define _NO_CRT_STDIO_INLINE
9+
#include <stdio.h>
10+
11+
// These 2 functions are inlined in UCRT headers, but they are referenced by
12+
// external code in the legacy CRT, so we need to provide them as non-inline
13+
// functions here.
14+
15+
_Success_(return >= 0)
16+
_Check_return_opt_
17+
int __CRTDECL sprintf(
18+
_Pre_notnull_ _Always_(_Post_z_) char* const _Buffer,
19+
_In_z_ _Printf_format_string_ char const* const _Format,
20+
...)
21+
{
22+
int _Result;
23+
va_list _ArgList;
24+
25+
__crt_va_start(_ArgList, _Format);
26+
27+
_Result = __stdio_common_vsprintf(
28+
_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION,
29+
_Buffer, (size_t)-1, _Format, NULL, _ArgList);
30+
31+
__crt_va_end(_ArgList);
32+
return _Result < 0 ? -1 : _Result;
33+
}
34+
35+
_Success_(return >= 0)
36+
_Check_return_opt_
37+
int __CRTDECL _vsnprintf(
38+
_Out_writes_opt_(_BufferCount) _Post_maybez_ char* const _Buffer,
39+
_In_ size_t const _BufferCount,
40+
_In_z_ _Printf_format_string_ char const* const _Format,
41+
va_list _ArgList
42+
)
43+
{
44+
int _Result = __stdio_common_vsprintf(
45+
_CRT_INTERNAL_LOCAL_PRINTF_OPTIONS | _CRT_INTERNAL_PRINTF_LEGACY_VSPRINTF_NULL_TERMINATION,
46+
_Buffer, _BufferCount, _Format, NULL, _ArgList);
47+
48+
return _Result < 0 ? -1 : _Result;
49+
}

0 commit comments

Comments
 (0)