ucxxrt 3.0.4

Suggested Alternatives

Musa.Runtime

There is a newer version of this package available.
See the version list below for details.

Requires NuGet 2.5 or higher.

dotnet add package ucxxrt --version 3.0.4                
NuGet\Install-Package ucxxrt -Version 3.0.4                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ucxxrt" Version="3.0.4">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add ucxxrt --version 3.0.4                
#r "nuget: ucxxrt, 3.0.4"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install ucxxrt as a Cake Addin
#addin nuget:?package=ucxxrt&version=3.0.4

// Install ucxxrt as a Cake Tool
#tool nuget:?package=ucxxrt&version=3.0.4                

Universal C++ RunTime (UCXXRT)

Actions Status LICENSE LICENSE Windows Visual Studio nuget

UserMode support will be removed starting 03/29/2022. The last version to support UserMode is e2f159f8f, UserMode please use VC-LTL5

1. About

ucxxrt is a open source rutime library which based on MSVC.The highlight of this project is that it can be used in kernel-mode drivers.
It gives you the same experience as user-mode application development in C++ when developing kernel-mode drivers.

Before ucxxrt was born,in order to use C++ on kernel-mode drivers, I use (KTL、ustd、...).

But there are several problems,like it isn't support C++ exception and it cost much time on implementing new features which provided by the latest ISO,then ucxxrt was born.

1.1 Principle

  • In kernel-mode driver mode,forced disable kernel-mode flag by using property sheet ,it makes the compiler support C++ exceptions.
  • Implement the exception functions such as throwcatch. Simulated the exception dispatcher in throw.

1.2 Features

  • support x86, x64, ARM(experimental), ARM64(experimental).
  • support new/delete operators.
  • support C++ exception (/EHa, /EHsc).
  • support SAFESEH、GS (Buffer Security Check).
  • support STL (not fully).
  • support static objects.

List of features that are not supported at this time↓

1.3 Example

See project unittest for more Infomation.

void Test$ThrowUnknow()
{
    try
    {
        try
        {
            try
            {
                throw std::wstring();
            }
            catch (int& e)
            {
                ASSERT(false);
                LOG(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "Catch Exception: %d\n", e);
            }
        }
        catch (std::string& e)
        {
            ASSERT(false);
            LOG(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "Catch Exception: %s\n", e.c_str());
        }
    }
    catch (...)
    {
        LOG(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL, "Catch Exception: ...\n");
    }
}

void Test$HashMap()
{
    auto Rand = std::mt19937_64(::rand());
    auto Map = std::unordered_map<uint32_t, std::string>();
    for (auto i = 0u; i < 10; ++i)
    {
        Map[i] = std::to_string(Rand());
    }

    for (const auto& Item : Map)
    {
        LOG(DPFLTR_IHVDRIVER_ID, DPFLTR_ERROR_LEVEL,
            "map[%ld] = %s\n", Item.first, Item.second.c_str());
    }
}

2. How to use

First, rename DriverEntry to DriverMain

2.1 Option 1 (recommend)

Right click on the project and select "Manage NuGet Packages", then search for ucxxrt and choose the version that suits you, and finally click "Install".

nuget

2.2 Option 2

  1. Download the latest package from release and unzip it.

  2. Add the property sheet ucxxrt.props to yor project.

usage

3. How to compile

IDE:Visual Studio 2019 or higher (Compiling for ARM/ARM64 requires Visual Studio 2022)

  • git clone --recurse-submodules https://github.com/MiroKaku/ucxxrt.git
  • Open ucxxrt.sln and compile.

4. Reference and Acknowledgement

Thanks to these excellent projects for help me on developing ucxxrt.

5. List of features that are not supported at this time

  • Thread Local Storage (TLS): thread_local、TlsAlloc ...
  • std::thread
  • std::filesystem
  • std::chrono
  • std::stacktrace_entry
  • std::locale
  • std::stream (std::fstream、std::iostream、std::cin、std::cout、std::cerr)
  • std::mutex、std::shared_mutex
  • std::future
  • std::condition_variable
  • std::latch
  • std::semaphore (std::counting_semaphore、std::binary_semaphore)
  • ...
Product Compatible and additional computed target framework versions.
native native is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

fix: #20, unresolved external symbol 'KeInitializeSpinLock'

feat: Global definition _KERNEL_MODE

fix: #17, Remove PsGetThreadCreateTime

fix: #13, _DEBUG not defined

sync: veil