[VCRUNTIME] Implement _chkesp / _chkesp_failed

This commit is contained in:
Timo Kreuzer
2026-01-11 15:41:11 +02:00
parent 89506818c4
commit 4c19b94ae9
3 changed files with 58 additions and 0 deletions

View File

@@ -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_OBJECTS:vcrt_common> $<TARGET_OBJECTS:setjmp>)
target_link_libraries(vcruntime ${PSEH_LIB})

View File

@@ -0,0 +1,22 @@
/*
* PROJECT: ReactOS vcruntime library
* LICENSE: MIT (https://spdx.org/licenses/MIT)
* PURPOSE: Implementation of _chkesp
* COPYRIGHT: Copyright 2026 Timo Kreuzer <timo.kreuzer@reactos.org>
*/
#include <asm.inc>
.code
EXTERN __chkesp_failed:PROC
PUBLIC __chkesp
__chkesp:
jnz _failed
ret
_failed:
jmp __chkesp_failed
END

View File

@@ -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 <timo.kreuzer@reactos.org>
*/
#include <crtdbg.h>
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();
}