Windows drivers written in D

Dan Olson via Digitalmars-d digitalmars-d at puremagic.com
Tue Oct 14 01:48:23 PDT 2014


"eles" <eles215 at gzk.dot> writes:

> On Monday, 13 October 2014 at 23:28:05 UTC, Piotrek wrote:
>> On Monday, 13 October 2014 at 21:50:20 UTC, eles wrote:
>>> Short answer is: yes, you cand write, but you cannot compile.
>>
>>
>> Wait, what? Do you mean link or maybe load? I don't write Linux
>> kernel modules, but I bet you can get it working.
>>
>> Check out the "betterC" switch to get away with runtime
>> dependences. There were some post related to minimal executables
>> recently.
>>
>> Piotrek
>
> Yes, I should have a second look at betterC

I have time for D again!  I was able to create a basic OSX kernel
extension in Xcode and then substitude the C code with a .o file
compiled by dmd.  There was no reason it shouldn't work but I wanted to
see it for myself.  This is a long way from a driver that interacts with
hardware, but hey, entertainment on a rainy night.

It started with this tutorial:

https://developer.apple.com/library/mac/documentation/Darwin/Conceptual/KEXTConcept/KEXTConceptKEXT/kext_tutorial.html#//apple_ref/doc/uid/20002365

Then 

$ dmd -release -betterC -c hellokextd.d

add hellokextd.o to the project, removed the C src, rebuild, and
kextutil into the kernel.

>From kernel logs
10/14/14 1:00:09.000 AM kernel[0]: Hello from D sample driver

---- hellokextd.d ----
extern (C):

enum KERN_SUCCESS = 0;
alias kmod_info_t = void;
alias kern_return_t = int;

int printf(const(char)* fmt, ...) nothrow;

// stub out a few unresolved druntime symbols
void _d_arraybounds(string msg, uint line) {}
void _d_assert(string msg, uint line) {}
void _d_unittest(string msg, uint line) {}

kern_return_t MyKext_start(kmod_info_t * ki, void *d)
{
    printf("Hello from D sample driver\n");
    return KERN_SUCCESS;
}

kern_return_t MyKext_stop(kmod_info_t *ki, void *d)
{
    printf("Bye from D sample driver\n");
    return KERN_SUCCESS;
}

-- 
dano


More information about the Digitalmars-d mailing list