[CMAKE/MSVC]
authorAmine Khaldi <amine.khaldi@reactos.org>
Sun, 12 Oct 2014 22:59:32 +0000 (22:59 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Sun, 12 Oct 2014 22:59:32 +0000 (22:59 +0000)
* Introduce support for for MSVC native run-time checks. Set RUNTIME_CHECKS to TRUE to enable it.
* Dedicated to Christoph von Wittich and all ReactOS devs that use MSVC builds ;)
CORE-8626

svn path=/trunk/; revision=64704

reactos/cmake/CMakeMacros.cmake
reactos/cmake/msvc.cmake
reactos/dll/win32/kernel32/CMakeLists.txt
reactos/lib/pseh/i386/seh.s
reactos/lib/sdk/crt/except/i386/seh.s
reactos/lib/sdk/crt/startup/gs_support.c
reactos/lib/sdk/crt/startup/mscmain.c

index 244080a..03e53bd 100644 (file)
@@ -502,6 +502,14 @@ function(add_importlibs _module)
         if("${LIB}" MATCHES "msvcrt")
             add_target_compile_definitions(${_module} _DLL __USE_CRTIMP)
             target_link_libraries(${_module} msvcrtex)
+            if(MSVC)
+                if(RUNTIME_CHECKS)
+                    if(NOT ${_module} STREQUAL "kernel32")
+                        add_target_compile_flags(${_module} "/RTC1")
+                        target_link_libraries(${_module} RunTmChk.lib)
+                    endif()
+                endif()
+            endif()
         endif()
         target_link_libraries(${_module} lib${LIB})
         add_dependencies(${_module} lib${LIB})
index 3b0e1b8..3b57f79 100644 (file)
@@ -82,6 +82,14 @@ if(MSVC_IDE)
     endif()
 endif()
 
+if(NOT DEFINED RUNTIME_CHECKS)
+    set(RUNTIME_CHECKS FALSE)
+endif()
+
+if(RUNTIME_CHECKS)
+    add_definitions(-D__RUNTIME_CHECKS__)
+endif()
+
 set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
 set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
 set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} /MANIFEST:NO /INCREMENTAL:NO /SAFESEH:NO /NODEFAULTLIB /RELEASE")
index 0498290..d4720e3 100644 (file)
@@ -107,6 +107,10 @@ set_subsystem(kernel32 console)
 
 target_link_libraries(kernel32 wine chkstk ${PSEH_LIB})
 
+if(RUNTIME_CHECKS)
+    target_link_libraries(kernel32 RunTmChk.lib)
+endif()
+
 add_importlibs(kernel32 ntdll)
 add_pch(kernel32 k32.h SOURCE)
 add_dependencies(kernel32 psdk errcodes asm)
index 6fde1e1..7c2da45 100644 (file)
@@ -22,9 +22,12 @@ EXTERN _RtlUnwind@16:PROC
 
 /* GLOBALS *******************************************************************/
 
+#ifndef __RUNTIME_CHECKS__
 PUBLIC __global_unwind2
 PUBLIC __local_unwind2
 PUBLIC __abnormal_termination
+#endif
+
 PUBLIC __except_handler2
 PUBLIC __except_handler3
 
index 6fde1e1..98f4b70 100644 (file)
@@ -25,8 +25,11 @@ EXTERN _RtlUnwind@16:PROC
 PUBLIC __global_unwind2
 PUBLIC __local_unwind2
 PUBLIC __abnormal_termination
+
+#if !defined(__RUNTIME_CHECKS__) || (defined(__RUNTIME_CHECKS__) && !defined(_LIBCNT_))
 PUBLIC __except_handler2
 PUBLIC __except_handler3
+#endif
 
 /* FUNCTIONS *****************************************************************/
 
index 1882930..efdfad4 100644 (file)
@@ -102,6 +102,7 @@ __security_init_cookie (void)
 
 __declspec(noreturn) void __cdecl __report_gsfailure (ULONG_PTR);
 
+#ifndef _MSC_VER
 __declspec(noreturn) void __cdecl
 __report_gsfailure (ULONG_PTR StackCookie)
 {
@@ -147,4 +148,4 @@ __report_gsfailure (ULONG_PTR StackCookie)
   TerminateProcess (GetCurrentProcess (), STATUS_STACK_BUFFER_OVERRUN);
   abort();
 }
-
+#endif /* !_MSC_VER */
index 11454db..4eba46f 100644 (file)
@@ -36,6 +36,18 @@ _CRT_INIT0(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpReserved)
     return TRUE;
 }
 
+void Catch_RTC_Failure(int errType, const wchar_t *file, int line, 
+                       const wchar_t *module, const wchar_t *format, ...)
+{
+    /* FIXME: better failure routine */
+    __debugbreak();
+}
+
+void* __cdecl _CRT_RTC_INITW(void *res0, void **res1, int res2, int res3, int res4)
+{
+    return &Catch_RTC_Failure; 
+}
+
 static int initialized = 0;
 
 void