Reactos

[VCRUNTIME] Implement _chkesp / _chkesp_failed

+58
+11
sdk/lib/vcruntime/CMakeLists.txt
··· 7 7 8 8 include_directories(inc) 9 9 10 + if(DBG) 11 + add_compile_definitions(_DEBUG) # TODO: define this globally 12 + endif() 13 + 10 14 # Silence GCC/Clang warnings 11 15 if(CMAKE_C_COMPILER_ID STREQUAL "GNU" OR 12 16 CMAKE_C_COMPILER_ID STREQUAL "Clang") ··· 25 29 if(${ARCH} STREQUAL "i386") 26 30 list(APPEND VCRT_COMMON_ASM_SOURCES 27 31 i386/__security_check_cookie.s 32 + i386/_chkesp.s 28 33 ) 29 34 elseif(${ARCH} STREQUAL "amd64") 30 35 list(APPEND VCRT_COMMON_ASM_SOURCES ··· 95 100 __vcrt_init.c 96 101 purecall.cpp 97 102 ) 103 + 104 + if(${ARCH} STREQUAL "i386") 105 + list(APPEND VCRT_RUNTIME_SOURCES 106 + i386/_chkesp_failed.c 107 + ) 108 + endif() 98 109 99 110 # Runtime library (linked into ucrtbase) 100 111 add_library(vcruntime ${VCRT_RUNTIME_SOURCES} $<TARGET_OBJECTS:vcrt_common> $<TARGET_OBJECTS:setjmp>)
+22
sdk/lib/vcruntime/i386/_chkesp.s
··· 1 + /* 2 + * PROJECT: ReactOS vcruntime library 3 + * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 + * PURPOSE: Implementation of _chkesp 5 + * COPYRIGHT: Copyright 2026 Timo Kreuzer <timo.kreuzer@reactos.org> 6 + */ 7 + 8 + #include <asm.inc> 9 + 10 + .code 11 + 12 + EXTERN __chkesp_failed:PROC 13 + 14 + PUBLIC __chkesp 15 + __chkesp: 16 + jnz _failed 17 + ret 18 + 19 + _failed: 20 + jmp __chkesp_failed 21 + 22 + END
+25
sdk/lib/vcruntime/i386/_chkesp_failed.c
··· 1 + /* 2 + * PROJECT: ReactOS vcruntime library 3 + * LICENSE: MIT (https://spdx.org/licenses/MIT) 4 + * PURPOSE: Implementation of _chkesp_failed 5 + * COPYRIGHT: Copyright 2026 Timo Kreuzer <timo.kreuzer@reactos.org> 6 + */ 7 + 8 + #include <crtdbg.h> 9 + 10 + void _chkesp_failed(void) 11 + { 12 + #ifdef _DEBUG 13 + /* Report the error to the user */ 14 + _CrtDbgReport(_CRT_ERROR, 15 + __FILE__, 16 + __LINE__, 17 + "", 18 + "The stack pointer was invalid after a function call. " 19 + "This indicates that a function was called with the " 20 + "wrong parmeters or calling convention.\n" 21 + "Click 'Retry' to debug the application."); 22 + #endif 23 + 24 + __debugbreak(); 25 + }