From 4c19b94ae948a7f6bcc1704dfc01db553f6d845e Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Sun, 11 Jan 2026 15:41:11 +0200 Subject: [PATCH] [VCRUNTIME] Implement _chkesp / _chkesp_failed --- sdk/lib/vcruntime/CMakeLists.txt | 11 +++++++++++ sdk/lib/vcruntime/i386/_chkesp.s | 22 ++++++++++++++++++++++ sdk/lib/vcruntime/i386/_chkesp_failed.c | 25 +++++++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 sdk/lib/vcruntime/i386/_chkesp.s create mode 100644 sdk/lib/vcruntime/i386/_chkesp_failed.c diff --git a/sdk/lib/vcruntime/CMakeLists.txt b/sdk/lib/vcruntime/CMakeLists.txt index 6f2670bf7fc..2829dd9d30a 100644 --- a/sdk/lib/vcruntime/CMakeLists.txt +++ b/sdk/lib/vcruntime/CMakeLists.txt @@ -7,6 +7,10 @@ include_directories(${REACTOS_SOURCE_DIR}/sdk/include/ucrt) include_directories(inc) +if(DBG) + add_compile_definitions(_DEBUG) # TODO: define this globally +endif() + # Silence GCC/Clang warnings if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR CMAKE_C_COMPILER_ID STREQUAL "Clang") @@ -25,6 +29,7 @@ add_compile_definitions( if(${ARCH} STREQUAL "i386") list(APPEND VCRT_COMMON_ASM_SOURCES i386/__security_check_cookie.s + i386/_chkesp.s ) elseif(${ARCH} STREQUAL "amd64") list(APPEND VCRT_COMMON_ASM_SOURCES @@ -96,6 +101,12 @@ list(APPEND VCRT_RUNTIME_SOURCES purecall.cpp ) +if(${ARCH} STREQUAL "i386") + list(APPEND VCRT_RUNTIME_SOURCES + i386/_chkesp_failed.c + ) +endif() + # Runtime library (linked into ucrtbase) add_library(vcruntime ${VCRT_RUNTIME_SOURCES} $ $) target_link_libraries(vcruntime ${PSEH_LIB}) diff --git a/sdk/lib/vcruntime/i386/_chkesp.s b/sdk/lib/vcruntime/i386/_chkesp.s new file mode 100644 index 00000000000..3bb2cba649f --- /dev/null +++ b/sdk/lib/vcruntime/i386/_chkesp.s @@ -0,0 +1,22 @@ +/* + * PROJECT: ReactOS vcruntime library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of _chkesp + * COPYRIGHT: Copyright 2026 Timo Kreuzer + */ + +#include + +.code + +EXTERN __chkesp_failed:PROC + +PUBLIC __chkesp +__chkesp: + jnz _failed + ret + +_failed: + jmp __chkesp_failed + +END diff --git a/sdk/lib/vcruntime/i386/_chkesp_failed.c b/sdk/lib/vcruntime/i386/_chkesp_failed.c new file mode 100644 index 00000000000..74bba82f2b4 --- /dev/null +++ b/sdk/lib/vcruntime/i386/_chkesp_failed.c @@ -0,0 +1,25 @@ +/* + * PROJECT: ReactOS vcruntime library + * LICENSE: MIT (https://spdx.org/licenses/MIT) + * PURPOSE: Implementation of _chkesp_failed + * COPYRIGHT: Copyright 2026 Timo Kreuzer + */ + +#include + +void _chkesp_failed(void) +{ +#ifdef _DEBUG + /* Report the error to the user */ + _CrtDbgReport(_CRT_ERROR, + __FILE__, + __LINE__, + "", + "The stack pointer was invalid after a function call. " + "This indicates that a function was called with the " + "wrong parmeters or calling convention.\n" + "Click 'Retry' to debug the application."); +#endif + + __debugbreak(); +}