Skip to content

Commit

Permalink
Merge pull request #6 from ntoskrnl7/features/use_ms_ucrt
Browse files Browse the repository at this point in the history
Features/use windows kit ucrt
  • Loading branch information
ntoskrnl7 authored May 23, 2022
2 parents 2948afd + 3899567 commit 64b4248
Show file tree
Hide file tree
Showing 91 changed files with 2,469 additions and 2,395 deletions.
66 changes: 40 additions & 26 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ cmake_minimum_required(VERSION 3.14)
# INCLUDE_DIRECTORIES $(VC_IncludePath);$(WindowsSDK_IncludePath)
cmake_policy(SET CMP0021 OLD)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake/")
include(pkg-utils)

pkg_get_version(CRTSYS ${CMAKE_CURRENT_SOURCE_DIR}/include/_version VERSION)

project(
crtsys
VERSION 0.1.0
VERSION "${VERSION}"
DESCRIPTION "C Runtime Lbrary for Windows driver file (*.sys)"
HOMEPAGE_URL "https://github.com/ntoskrnl7/crtsys"
LANGUAGES C CXX ASM_MASM
Expand Down Expand Up @@ -34,7 +39,7 @@ else()
set(LDK_USE_RAISE_EXCEPTION OFF)
set(LDK_USE_RTL_RAISE_EXCEPTION OFF)
endif()
CPMAddPackage("gh:ntoskrnl7/Ldk#features/kernel32")
CPMAddPackage("gh:ntoskrnl7/Ldk@0.7.1")

CPMAddPackage("gh:ntoskrnl7/FindWDK#master")
list(APPEND CMAKE_MODULE_PATH "${FindWDK_SOURCE_DIR}/cmake")
Expand All @@ -47,33 +52,53 @@ find_package(WDK REQUIRED)
file(GLOB SOURCE_FILES
src/*.cpp

# common
src/custom/common/*.cpp
src/custom/common/*.c
src/custom/common/*/*.cpp
src/custom/common/*/*.c
# misc
src/custom/misc/*.cpp
src/custom/misc/*.c

# crt
src/custom/crt/*.c
src/custom/crt/fenv/*.c

# ucrt
src/custom/ucrt/common/*.cpp
src/custom/ucrt/common/*/*.cpp

# ucrt
src/custom/ucrt/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/*.cpp
src/custom/ucrt/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/*/*.cpp
)

if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "Win32")
file(GLOB MATH_SOURCE_FILES
src/custom/common/math/*.c
src/custom/crt/math/*.c
)
list(APPEND SOURCE_FILES ${MATH_SOURCE_FILES})
else()
file(GLOB MATH_SOURCE_FILES
src/custom/crt/math/nextafter.c
src/custom/crt/math/fpclassify.c
)
list(APPEND SOURCE_FILES ${MATH_SOURCE_FILES})
endif()

if (UCXXRT_ENABLED)
list(APPEND SOURCE_FILES src/custom/msvc/common/crt/src/stl/winapisupp.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/crt/isa_available_init.c)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/crt/math/ftol3.c)

CPMAddPackage("gh:ntoskrnl7/ucxxrt#master")

file(GLOB_RECURSE UCXXRT_SOURCE_FILES
${ucxxrt_SOURCE_DIR}/src/*.cpp
${ucxxrt_SOURCE_DIR}/vcruntime/*.cpp
${ucxxrt_SOURCE_DIR}/misc/*.cpp
)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/crt.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/locales.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/vcruntime/thread.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/terminate.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/misc/invalid_parameter.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/sys_main.cpp)
list(REMOVE_ITEM UCXXRT_SOURCE_FILES ${ucxxrt_SOURCE_DIR}/src/unittest.cpp)
if("${CMAKE_VS_PLATFORM_NAME}" STREQUAL "x64")
Expand All @@ -90,18 +115,6 @@ if (UCXXRT_ENABLED)
list(APPEND UCXXRT_SOURCE_FILES ${PLATFORM_SOURCE_FILES})

list(APPEND SOURCE_FILES ${UCXXRT_SOURCE_FILES})
list(APPEND SOURCE_FILES src/custom/msvc/common/crt/src/stl/winapisupp.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/common/isa_available_init.c)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/common/errno.c)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/common/math/ftol3.c)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/startup/thread.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/startup/initterm.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/startup/onexit.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/startup/exit.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/startup/argv_parsing.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/heap/malloc.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/misc/terminate.cpp)
list(REMOVE_ITEM SOURCE_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/common/misc/invalid_parameter.cpp)
endif()

wdk_add_library(
Expand All @@ -125,6 +138,7 @@ endif()
target_include_directories(crtsys PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/custom/msvc/${MSVC_TOOLSET_VERSION}/include")
target_include_directories(crtsys PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/custom/msvc/${MSVC_TOOLSET_VERSION}/crt/src/vcruntime")
target_include_directories(crtsys PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/custom/msvc/${MSVC_TOOLSET_VERSION}/crt/src/stl")
target_include_directories(crtsys BEFORE PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src/custom/ucrt/${CMAKE_VS_WINDOWS_TARGET_PLATFORM_VERSION}/inc")

#
# link libraries
Expand All @@ -137,7 +151,7 @@ endif()
#
# Add compile definitions
#
target_compile_definitions(crtsys PUBLIC "_NO_CRT_STDIO_INLINE")
# target_compile_definitions(crtsys PUBLIC "_NO_CRT_STDIO_INLINE")
target_compile_definitions(crtsys PUBLIC "_KERNEL32_")
target_compile_definitions(crtsys PUBLIC "_ITERATOR_DEBUG_LEVEL=0")
if (CRTSYS_USE_LIBCNTPR)
Expand All @@ -156,7 +170,6 @@ endif()
target_compile_definitions(crtsys PUBLIC "_HAS_EXCEPTIONS")
if (UCXXRT_ENABLED)
target_compile_definitions(crtsys PUBLIC "UCXXRT")
target_compile_definitions(crtsys PUBLIC "UCXXRT_X86_NO_THROW_TEST")
target_compile_definitions(crtsys PRIVATE "__KERNEL_MODE")
endif()

Expand Down Expand Up @@ -217,11 +230,12 @@ endif()
#
# set visual studio properties file
#
set(VS_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/src/stl.props")
if (NOT UCXXRT_ENABLED)
list(APPEND VS_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/src/vcruntime.props;${CMAKE_CURRENT_SOURCE_DIR}/src/custom/msvc/crt.props")
if (UCXXRT_ENABLED)
list(APPEND VS_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/src/ucrt_for_ucxxrt.props")
else()
list(APPEND VS_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/src/vcruntime.props;${CMAKE_CURRENT_SOURCE_DIR}/src/custom/msvc/crt.props;${CMAKE_CURRENT_SOURCE_DIR}/src/ucrt.props")
endif()
set_target_properties(crtsys PROPERTIES VS_USER_PROPS "${VS_PROPS}")
set_target_properties(crtsys PROPERTIES VS_USER_PROPS "${CMAKE_CURRENT_SOURCE_DIR}/src/stl.props;${VS_PROPS}")

#
# set library output path (release only)
Expand Down
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,27 +108,27 @@ crtsys가 장점은 아래와 같습니다.
- [Initialization](https://en.cppreference.com/w/cpp/language/initialization)
- [x] [Non-local variables](https://en.cppreference.com/w/cpp/language/initialization#Non-local_variables)
- [x] [Static initialization](https://en.cppreference.com/w/cpp/language/initialization#Static_initialization)
- [x] [Constant initialization](https://en.cppreference.com/w/cpp/language/constant_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L15)
- [x] [Zero initialization](https://en.cppreference.com/w/cpp/language/zero_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L44)
- [x] [Dynamic initialization](https://en.cppreference.com/w/cpp/language/initialization#Dynamic_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L71)
- [x] [Constant initialization](https://en.cppreference.com/w/cpp/language/constant_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L13)
- [x] [Zero initialization](https://en.cppreference.com/w/cpp/language/zero_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L41)
- [x] [Dynamic initialization](https://en.cppreference.com/w/cpp/language/initialization#Dynamic_initialization) [(tested)](./test/src/cpp/lang/initialization.cpp#L65)
- [ ] [Static local variables](https://en.cppreference.com/w/cpp/language/storage_duration#Static_local_variables)
- [ ] thread_local
- [ ] static
- [Exceptions](https://en.cppreference.com/w/cpp/language/exceptions)
- [x] [throw](https://en.cppreference.com/w/cpp/language/throw) [(tested)](./test/src/cpp/lang/exceptions.cpp#L58)
- [x] [try-block](https://en.cppreference.com/w/cpp/language/try_catch) [(tested)](./test/src/cpp/lang/exceptions.cpp#L77)
- [x] [Function-try-block](https://en.cppreference.com/w/cpp/language/function-try-block) [(tested)](./test/src/cpp/lang/exceptions.cpp#L125)
- [x] [throw](https://en.cppreference.com/w/cpp/language/throw) [(tested)](./test/src/cpp/lang/exceptions.cpp#L42)
- [x] [try-block](https://en.cppreference.com/w/cpp/language/try_catch) [(tested)](./test/src/cpp/lang/exceptions.cpp#L60)
- [x] [Function-try-block](https://en.cppreference.com/w/cpp/language/function-try-block) [(tested)](./test/src/cpp/lang/exceptions.cpp#L98)

#### STL

- [x] [std::chrono](https://en.cppreference.com/w/cpp/chrono) [(tested)](./test/src/cpp/stl/chrono.cpp#L15)
- [x] [std::thread](https://en.cppreference.com/w/cpp/thread) [(tested)](./test/src/cpp/stl/thread.cpp#L39)
- [x] [std::condition_variable](https://en.cppreference.com/w/cpp/thread/condition_variable) [(tested)](./test/src/cpp/stl/thread.cpp#L39)
- [x] [std::mutex](https://en.cppreference.com/w/cpp/thread/mutex) [(tested)](./test/src/cpp/stl/thread.cpp#L86)
- [x] [std::shared_mutex](https://en.cppreference.com/w/cpp/thread/shared_mutex) [(tested)](./test/src/cpp/stl/thread.cpp#L135)
- [x] [std::future](https://en.cppreference.com/w/cpp/thread/future) [(tested)](./test/src/cpp/stl/thread.cpp#L164)
- [x] [std::promise](https://en.cppreference.com/w/cpp/thread/promise) [(tested)](./test/src/cpp/stl/thread.cpp#L212)
- [x] [std::packaged_task](https://en.cppreference.com/w/cpp/thread/packaged_task) [(tested)](./test/src/cpp/stl/thread.cpp#L280)
- [x] [std::thread](https://en.cppreference.com/w/cpp/thread) [(tested)](./test/src/cpp/stl/thread.cpp#L35)
- [x] [std::condition_variable](https://en.cppreference.com/w/cpp/thread/condition_variable) [(tested)](./test/src/cpp/stl/thread.cpp#L35)
- [x] [std::mutex](https://en.cppreference.com/w/cpp/thread/mutex) [(tested)](./test/src/cpp/stl/thread.cpp#L81)
- [x] [std::shared_mutex](https://en.cppreference.com/w/cpp/thread/shared_mutex) [(tested)](./test/src/cpp/stl/thread.cpp#L129)
- [x] [std::future](https://en.cppreference.com/w/cpp/thread/future) [(tested)](./test/src/cpp/stl/thread.cpp#L157)
- [x] [std::promise](https://en.cppreference.com/w/cpp/thread/promise) [(tested)](./test/src/cpp/stl/thread.cpp#L203)
- [x] [std::packaged_task](https://en.cppreference.com/w/cpp/thread/packaged_task) [(tested)](./test/src/cpp/stl/thread.cpp#L267)
- [x] [std::cin](https://en.cppreference.com/w/cpp/io/cin)
- [x] [std::clog](https://en.cppreference.com/w/cpp/io/clog)
- [x] [std::cerr](https://en.cppreference.com/w/cpp/io/cerr)
Expand Down Expand Up @@ -241,7 +241,7 @@ project(crtsys_test LANGUAGES C)
include(cmake/CPM.cmake)
set(CRTSYS_NTL_MAIN ON) # use ntl::main
CPMAddPackage("gh:ntoskrnl7/[email protected].0")
CPMAddPackage("gh:ntoskrnl7/[email protected].2")
include(${crtsys_SOURCE_DIR}/cmake/CrtSys.cmake)
# add driver
Expand Down
2 changes: 1 addition & 1 deletion cmake/CrtSys.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function(crtsys_add_driver _target)
"${WDK_ROOT}/Include/${WDK_VERSION}/km/crt"
)

target_compile_definitions(${_target} PRIVATE "_NO_CRT_STDIO_INLINE=0")
# target_compile_definitions(${_target} PRIVATE "_NO_CRT_STDIO_INLINE=0")

if(CRTSYS_NTL_MAIN)
target_compile_definitions(crtsys PUBLIC CRTSYS_USE_NTL_MAIN)
Expand Down
2 changes: 1 addition & 1 deletion include/14.29.30133/stl/mutex
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ public:
#endif // _HAS_CXX17

// FUNCTION TEMPLATE call_once
// #ifdef _M_CEE
#ifdef _M_CEE
#define _WINDOWS_API __stdcall
#define _RENAME_WINDOWS_API(_Api) _Api##_clr
#else // ^^^ _M_CEE // !_M_CEE vvv
Expand Down
31 changes: 31 additions & 0 deletions include/_version
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*++

Copyright (c) CrtSys Authors. All rights reserved.

Module Name:

version.h

Abstract:

This module defines the version preprocessor.

Author:

Jung Kwang Lee ([email protected])

Environment:

Kernel mode

--*/
#pragma once

#ifndef _CRTSYS_VERSION_H_
#define _CRTSYS_VERSION_H_

#define CRTSYS_VERSION_MAJOR 0
#define CRTSYS_VERSION_MINOR 1
#define CRTSYS_VERSION_PATCH 2

#endif // _CRTSYS_VERSION_H_
116 changes: 110 additions & 6 deletions src/crtsys.h
Original file line number Diff line number Diff line change
@@ -1,23 +1,127 @@
// clang-format off

#pragma once

#undef _CTYPE_DISABLE_MACROS
#include <ctype.h>

#include <windows.h>

#pragma warning(disable : 4201)
#include <WinUser.h>

EXTERN_C _ACRTIMP const unsigned short *__cdecl __pctype_func(void);
EXTERN_C _ACRTIMP const wctype_t *__cdecl __pwctype_func(void);

#define WINBASEAPI
EXTERN_C

EXTERN_C_START



// crt/src/stl/xdateord.cpp
WINBASEAPI
int WINAPI GetLocaleInfoEx(_In_opt_ LPCWSTR lpLocaleName, _In_ LCTYPE LCType,
_Out_writes_to_opt_(cchData, return )
LPWSTR lpLCData,
_In_ int cchData);

EXTERN_C


// crt\src\stl\xgetwctype.cpp
WINBASEAPI
BOOL WINAPI GetStringTypeW(_In_ DWORD dwInfoType,
_In_NLS_string_(cchSrc) LPCWCH lpSrcStr,
_In_ int cchSrc, _Out_ LPWORD lpCharType);
_In_ int cchSrc, _Out_ LPWORD lpCharType);



// ucrt/internal/winapi_thunks.cpp
WINBASEAPI
int
WINAPI
GetLocaleInfoW(
_In_ LCID Locale,
_In_ LCTYPE LCType,
_Out_writes_opt_(cchData) LPWSTR lpLCData,
_In_ int cchData);



// ucrt/internal/winapi_thunks.cpp
WINBASEAPI
int
WINAPI
GetDateFormatW(
_In_ LCID Locale,
_In_ DWORD dwFlags,
_In_opt_ CONST SYSTEMTIME* lpDate,
_In_opt_ LPCWSTR lpFormat,
_Out_writes_opt_(cchDate) LPWSTR lpDateStr,
_In_ int cchDate
);



// ucrt/internal/winapi_thunks.cpp
WINBASEAPI
int
WINAPI
GetTimeFormatW(
_In_ LCID Locale,
_In_ DWORD dwFlags,
_In_opt_ CONST SYSTEMTIME* lpTime,
_In_opt_ LPCWSTR lpFormat,
_Out_writes_opt_(cchTime) LPWSTR lpTimeStr,
_In_ int cchTime
);



// ucrt\locale\getqloc_downlevel.cpp
typedef BOOL (CALLBACK* LOCALE_ENUMPROCW)(LPWSTR); // DEPRECATED: please use LOCALE_ENUMPROCEX

WINBASEAPI
BOOL
WINAPI
EnumSystemLocalesW(
_In_ LOCALE_ENUMPROCW lpLocaleEnumProc,
_In_ DWORD dwFlags);



// ucrt/inc/corecrt_internal.h
typedef BOOL (CALLBACK* LOCALE_ENUMPROCEX)(LPWSTR, DWORD, LPARAM);

// ucrt/internal/winapi_thunks.cpp
WINBASEAPI
BOOL
WINAPI
EnumSystemLocalesEx(
_In_ LOCALE_ENUMPROCEX lpLocaleEnumProcEx,
_In_ DWORD dwFlags,
_In_ LPARAM lParam,
_In_opt_ LPVOID lpReserved
);



// ucrt/inc/corecrt_internal.h
WINBASEAPI
BOOL
WINAPI
FindClose(
_Inout_ HANDLE hFindFile
);

// ucrt\inc\corecrt_internal_lowio.h
typedef struct INPUT_RECORD *PINPUT_RECORD;



// ucrt\startup\thread.cpp
WINBASEAPI
DWORD
WINAPI
ResumeThread(
_In_ HANDLE hThread
);

EXTERN_C_END
1 change: 0 additions & 1 deletion src/custom/common/.clang-format

This file was deleted.

Loading

0 comments on commit 64b4248

Please sign in to comment.