diff --git a/CMakeLists.txt b/CMakeLists.txt index aca02c9..eea3cfd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,7 +39,7 @@ else() set(LDK_USE_RAISE_EXCEPTION OFF) set(LDK_USE_RTL_RAISE_EXCEPTION OFF) endif() -CPMAddPackage("gh:ntoskrnl7/Ldk@0.7.1") +CPMAddPackage("gh:ntoskrnl7/Ldk@0.7.2") CPMAddPackage("gh:ntoskrnl7/FindWDK#master") list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake") diff --git a/README.md b/README.md index 0d4d1bc..2767662 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # crtsys -C/C++ Runtime library for system file (Windows Kernel Driver) +**C**/C++ Run**t**ime library for **sys**tem file (Windows Kernel Driver) + +![GitHub](https://img.shields.io/github/license/ntoskrnl7/crtsys) ![GitHub release (latest by date)](https://img.shields.io/github/v/release/ntoskrnl7/crtsys) ![Windows 7+](https://img.shields.io/badge/Windows-7+-red.svg) ![Visual Studio 2017+](https://img.shields.io/badge/Visual%20Studio-2017+-orange.svg) ![CMake 3.14+](https://img.shields.io/badge/CMake-3.14+-yellow.svg) 커널 드라이버에서 C++ 및 STL 기능을 사용할 수 있도록 도와주는 CRT 라이브러리 입니다. @@ -141,13 +143,15 @@ crtsys가 장점은 아래와 같습니다. ### C Standard - [x] math functions - - 직접 구현하기에는 시간이 부족하여 [RetrievAL](https://github.com/SpoilerScriptsGroup/RetrievAL)의 코드를 그대로 사용하였습니다. (SpoilerScriptsGroup 감사합니다! :-)) + - 직접 구현하기에는 시간이 부족하여 아래 프로젝트의 내용을 참고하엿습니다. 감사합니다! :-) + - [RetrievAL](https://github.com/SpoilerScriptsGroup/RetrievAL) + - [musl](https://github.com/bminor/musl) ### NTL (NT Template Library) 커널에서 더 나은 개발 환경을 지원하기 위한 기능을 제공합니다. -- ntl::expand_stack [(tested)](./test/src/ntl_test.cpp#L5) +- ntl::expand_stack [(tested)](./test/src/ntl.cpp#L5) - 스택 크기를 확장하기 위한 함수 - 기본적으로 커널 스택은 사용자 스레드 스택보다 훨씬 작은 크기를 할당받기 때문에 STL 기능을 사용하거나, 특히 throw를 수행할때 사용하는것이 좋습니다. - ntl::status @@ -241,7 +245,7 @@ project(crtsys_test LANGUAGES C) include(cmake/CPM.cmake) set(CRTSYS_NTL_MAIN ON) # use ntl::main -CPMAddPackage("gh:ntoskrnl7/crtsys@0.1.2") +CPMAddPackage("gh:ntoskrnl7/crtsys@0.1.3") include(${crtsys_SOURCE_DIR}/cmake/CrtSys.cmake) # add driver diff --git a/include/_version b/include/_version index dbdacd6..d839ed5 100644 --- a/include/_version +++ b/include/_version @@ -26,6 +26,6 @@ Environment: #define CRTSYS_VERSION_MAJOR 0 #define CRTSYS_VERSION_MINOR 1 -#define CRTSYS_VERSION_PATCH 2 +#define CRTSYS_VERSION_PATCH 3 #endif // _CRTSYS_VERSION_H_ \ No newline at end of file diff --git a/src/custom/crt/misc.c b/src/custom/crt/misc.c index cbe703a..7e12a7f 100644 --- a/src/custom/crt/misc.c +++ b/src/custom/crt/misc.c @@ -12,7 +12,9 @@ void __cdecl _CRT_DEBUGGER_HOOK(int reserved) // -// 10.0.22000.0/km/x86/libcntpr.lib(ieee87.obj) _pxcptinfoptrs +// 10.0.17763.0 +// 10.0.22000.0 +// km\x86\libcntpr.lib(ieee87.obj) // #ifdef _M_IX86 void ** __cdecl __pxcptinfoptrs(void); @@ -20,10 +22,50 @@ void ** __cdecl _pxcptinfoptrs(void) { return __pxcptinfoptrs(); } + +unsigned int __cdecl __get_fpsr_sse2() +{ + KdBreakPoint(); + return 0; +} + +void __cdecl __set_fpsr_sse2(unsigned int _Arg) +{ + _Arg; + KdBreakPoint(); +} + +#include +void __cdecl _setdefaultprecision() +{ + KdBreakPoint(); + _controlfp_s(NULL, _PC_53, _MCW_PC); +} #endif +// +// signbit +// +#include + +_Check_return_ _ACRTIMP int __cdecl _dsign(_In_ double _X) +{ + return _DSIGN_C(_X); +} + +_Check_return_ _ACRTIMP int __cdecl _ldsign(_In_ long double _X) +{ + return _LSIGN_C(_X); +} +_Check_return_ _ACRTIMP int __cdecl _fdsign(_In_ float _X) +{ + return _FSIGN_C(_X); +} + + + // // // diff --git a/src/custom/ucrt/common/internal/winapi_thunks.cpp b/src/custom/ucrt/common/internal/winapi_thunks.cpp index 170d2ed..b392f61 100644 --- a/src/custom/ucrt/common/internal/winapi_thunks.cpp +++ b/src/custom/ucrt/common/internal/winapi_thunks.cpp @@ -1,9 +1,15 @@ #include +extern "C" bool __cdecl __acrt_uninitialize_winapi_thunks(bool const terminating) +{ + UNREFERENCED_PARAMETER(terminating); + return true; +} + extern "C" BOOL WINAPI __acrt_InitializeCriticalSectionEx(LPCRITICAL_SECTION const critical_section, DWORD const spin_count, DWORD const flags) { - flags; + UNREFERENCED_PARAMETER(flags); return InitializeCriticalSectionAndSpinCount(critical_section, spin_count); } @@ -70,7 +76,6 @@ extern "C" int WINAPI __acrt_GetUserDefaultLocaleName( return GetUserDefaultLocaleName(locale_name, locale_name_count); } - extern "C" int WINAPI __acrt_LCIDToLocaleName( LCID const locale, LPWSTR const name, @@ -112,11 +117,6 @@ extern "C" void WINAPI __acrt_RoUninitialize() { } - -// -// -// - extern "C" void __cdecl __acrt_eagerly_load_locale_apis() { } @@ -127,13 +127,6 @@ begin_thread_init_policy __cdecl __acrt_get_begin_thread_init_policy() return begin_thread_init_policy_none; } -extern "C" -process_end_policy __cdecl __acrt_get_process_end_policy(void) -{ - return process_end_policy_exit_process; -} - - extern "C" BOOL WINAPI __acrt_EnumSystemLocalesEx( LOCALE_ENUMPROCEX const enum_proc, DWORD const flags, @@ -144,9 +137,6 @@ extern "C" BOOL WINAPI __acrt_EnumSystemLocalesEx( return EnumSystemLocalesEx(enum_proc, flags, param, reserved); } - - - extern "C" int WINAPI __acrt_GetDateFormatEx( LPCWSTR const locale_name, DWORD const flags, @@ -196,67 +186,75 @@ extern "C" int __cdecl __acrt_LCMapStringA(_locale_t const plocinfo, PCWSTR cons return 0; } -extern "C" bool __cdecl __acrt_can_use_vista_locale_apis() +extern "C" int WINAPI __acrt_MessageBoxA( + HWND const hwnd, + LPCSTR const text, + LPCSTR const caption, + UINT const type + ) { - return true; + KdBreakPoint(); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; + // abort(); // No fallback; callers should check availablility before calling } -extern "C" bool __cdecl __acrt_initialize_winapi_thunks() +extern "C" int WINAPI __acrt_MessageBoxW( + HWND const hwnd, + LPCWSTR const text, + LPCWSTR const caption, + UINT const type + ) { - return true; + KdBreakPoint(); + SetLastError(ERROR_CALL_NOT_IMPLEMENTED); + return 0; + // abort(); // No fallback; callers should check availablility before calling } -extern "C" bool __cdecl __acrt_uninitialize_winapi_thunks(bool const terminating) + +extern "C" bool __cdecl __acrt_can_use_vista_locale_apis() { return true; } -bool __cdecl __acrt_initialize_command_line() + +extern "C" bool __cdecl __acrt_initialize_winapi_thunks() { return true; } -bool __cdecl __acrt_uninitialize_command_line(bool const terminating) + +extern "C" HWND __cdecl __acrt_get_parent_window() { - return true; + return nullptr; } -void __cdecl __acrt_initialize_user_matherr(void* encoded_null) + +extern "C" bool __cdecl __acrt_is_interactive() { + return true; } -extern "C" { - char** __argv = nullptr; // The arguments as narrow strings - wchar_t** __wargv = nullptr; // The arguments as wide strings +extern "C" bool __cdecl __acrt_can_show_message_box() +{ + return false; } // -// :-( +// unexported sources // -extern "C" errno_t __cdecl _configure_narrow_argv(_crt_argv_mode const mode) -{ - return 0; -} - -extern "C" int __cdecl __acrt_show_wide_message_box( - wchar_t const* const text, - wchar_t const* const caption, - unsigned const type - ) +void __cdecl __acrt_initialize_user_matherr(void* encoded_null) { - return 0; } -#include - -#ifdef _M_IX86 -extern "C" unsigned int __cdecl __get_fpsr_sse2() +extern "C" process_end_policy __cdecl __acrt_get_process_end_policy(void) { - return 0; + return process_end_policy_terminate_process; } -extern "C" void __cdecl __set_fpsr_sse2(unsigned int) +extern "C" developer_information_policy __cdecl __acrt_get_developer_information_policy(void) { + return developer_information_policy_none; } -extern "C" void __cdecl _setdefaultprecision() +extern "C" windowing_model_policy __cdecl __acrt_get_windowing_model_policy(void) { - _controlfp_s(NULL, _PC_53, _MCW_PC); -} -#endif \ No newline at end of file + return windowing_model_policy_none; +} \ No newline at end of file diff --git a/src/custom/ucrt/common/startup/argv_parsing.cpp b/src/custom/ucrt/common/startup/argv_parsing.cpp new file mode 100644 index 0000000..a510ae0 --- /dev/null +++ b/src/custom/ucrt/common/startup/argv_parsing.cpp @@ -0,0 +1,10 @@ +#define _CORECRT_BUILD +#define _CRT_GLOBAL_STATE_ISOLATION +#define _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY +#include + +extern "C" errno_t __cdecl _configure_narrow_argv(_crt_argv_mode const mode) +{ + mode; + return 0; +} \ No newline at end of file diff --git a/src/ucrt.props b/src/ucrt.props index 7c9b6e8..ab739e9 100644 --- a/src/ucrt.props +++ b/src/ucrt.props @@ -118,7 +118,19 @@ stdcpp14 Cdecl - + + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + stdcpp14 + Cdecl + + + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + stdcpp14 + Cdecl + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 Cdecl @@ -182,6 +194,18 @@ Cdecl + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + Cdecl + 4189 + + + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + Cdecl + 4189 + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 $(IntDir)ucrt\%(FileName).obj @@ -273,6 +297,12 @@ Cdecl + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + 4245;4838 + Cdecl + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 Cdecl diff --git a/src/ucrt_for_ucxxrt.props b/src/ucrt_for_ucxxrt.props index b9469a9..6f6b122 100644 --- a/src/ucrt_for_ucxxrt.props +++ b/src/ucrt_for_ucxxrt.props @@ -120,6 +120,19 @@ Cdecl + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + stdcpp14 + Cdecl + $(IntDir)\ucrt\%(Directory)%(FileName).obj + + + + %(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931 + stdcpp14 + Cdecl + +