Skip to content

Commit

Permalink
Merge pull request #7 from ntoskrnl7/tests/nlohmann-json
Browse files Browse the repository at this point in the history
Add nlohmann::json test.
  • Loading branch information
ntoskrnl7 authored May 27, 2022
2 parents 64b4248 + 5218fd5 commit 98bdf53
Show file tree
Hide file tree
Showing 13 changed files with 248 additions and 62 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 라이브러리 입니다.

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion include/_version
Original file line number Diff line number Diff line change
Expand Up @@ -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_
44 changes: 43 additions & 1 deletion src/custom/crt/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,60 @@ 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);
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 <float.h>
void __cdecl _setdefaultprecision()
{
KdBreakPoint();
_controlfp_s(NULL, _PC_53, _MCW_PC);
}
#endif



//
// signbit
//
#include <math.h>

_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);
}



//
//
//
Expand Down
100 changes: 49 additions & 51 deletions src/custom/ucrt/common/internal/winapi_thunks.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
#include <windows.h>

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);
}

Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -112,11 +117,6 @@ extern "C" void WINAPI __acrt_RoUninitialize()
{
}


//
//
//

extern "C" void __cdecl __acrt_eagerly_load_locale_apis()
{
}
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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 <float.h>

#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
return windowing_model_policy_none;
}
10 changes: 10 additions & 0 deletions src/custom/ucrt/common/startup/argv_parsing.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#define _CORECRT_BUILD
#define _CRT_GLOBAL_STATE_ISOLATION
#define _CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY
#include <corecrt_internal.h>

extern "C" errno_t __cdecl _configure_narrow_argv(_crt_argv_mode const mode)
{
mode;
return 0;
}
32 changes: 31 additions & 1 deletion src/ucrt.props
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,19 @@
<LanguageStandard>stdcpp14</LanguageStandard>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>


<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\startup\assert.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<LanguageStandard>stdcpp14</LanguageStandard>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\startup\argv_data.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<LanguageStandard>stdcpp14</LanguageStandard>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\startup\abort.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<CallingConvention>Cdecl</CallingConvention>
Expand Down Expand Up @@ -182,6 +194,18 @@
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\internal\GetModuleFileNameA.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<CallingConvention>Cdecl</CallingConvention>
<DisableSpecificWarnings>4189</DisableSpecificWarnings>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\internal\OutputDebugStringA.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<CallingConvention>Cdecl</CallingConvention>
<DisableSpecificWarnings>4189</DisableSpecificWarnings>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\internal\per_thread_data.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<ObjectFileName>$(IntDir)ucrt\%(FileName).obj</ObjectFileName>
Expand Down Expand Up @@ -273,6 +297,12 @@
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\misc\crtmbox.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<DisableSpecificWarnings>4245;4838</DisableSpecificWarnings>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>

<ClCompile Include="$(UniversalCRT_SourcePath.Split(%3B)[0])\env\environment_initialization.cpp">
<PreprocessorDefinitions>%(PreprocessorDefinitions);_STL_COMPILER_PREPROCESSOR=0;_CORECRT_BUILD;_CRT_GLOBAL_STATE_ISOLATION;_CRT_DECLARE_GLOBAL_VARIABLES_DIRECTLY;__WARNING_UNUSED_ASSIGNMENT=28931</PreprocessorDefinitions>
<CallingConvention>Cdecl</CallingConvention>
Expand Down
Loading

0 comments on commit 98bdf53

Please sign in to comment.