Post by eles via Digitalmars-dPost by Piotrek via Digitalmars-dPost by eles via Digitalmars-dShort 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.
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