C# driver development?

后端 未结 8 1606
星月不相逢
星月不相逢 2020-11-29 05:03

Before I jump headlong into C#...

I\'ve always felt that C, or maybe C++, was best for developing drivers on Windows. I\'m not keen on the idea of developing a driv

相关标签:
8条回答
  • 2020-11-29 05:39

    You can not make kernel-mode device drivers in C# as the runtime can't be safely loaded into ring0 and operate as expected.

    Additionally, C# doesn't create binaries suitable for loading as device drivers, particularly regarding entry points that drivers need to expose. The dependency on the runtime to jump in and analyze and JIT the binary during loading prohibits the direct access the driver subsystem needs to load the binary.

    There is work underway, however, to lift some device drivers into user mode, you can see an interview here with Peter Wieland of the UDMF (User Mode Driver Framework) team.

    User-mode drivers would be much more suited for managed work, but you'll have to google a bit to find out if C# and .NET will be directly supported. All I know is that kernel level drivers are not doable in only C#.

    You can, however, probably make a C/C++ driver, and a C# service (or similar) and have the driver talk to the managed code, if you absolutely have to write a lot of code in C#.

    0 讨论(0)
  • 2020-11-29 05:40

    If I remember it correctly, the Dokan Project is a user-mode file system driver, which also allows .NET code to be executed by a system driver: https://github.com/dokan-dev/dokan-dotnet.

    So, you could develop a C# "driver" (user-mode application really), which is then called/invoked by a C++ kernel-mode driver. The kernel-driver could simply pass everything along without manipulating the data and act as a simple wrapper.
    Needless to mention, that it is very unsafe and you would most likely end with a BSOD (I tried it).


    Mildly related:

    The Cosmos Project is an open-source Operating system, which is developed in C# and runs
    "(kernel) drivers" and user-level applications written completely in C#/F#/VB.NET/...

    Though these are technically kernel-level drivers, the OS is no longer Windows but your own, so I guess that this is not a correct answer ......

    0 讨论(0)
提交回复
热议问题