From: BobF on

I remember reading http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
a while back


Joseph M. Newcomer wrote:
> C++ in the kernel has serious problems. Not intrinsic problems, but serious problems.
> When I was at a Driver DevCon some years ago, I asked "Isn't it about time we should be
> able to use C++ in the kernel?" and was dragged over to one of the C++ compiler leads. We
> talked (or rather, I listened) for about half an hour to everything that can go wrong in
> the kernel. Only a subset of C++ actually works. His comment was that he could make it
> work in the kernel, but it involved some significant compiler changes (most of them
> #pragmas, and the consequent handling of them). The problem was simply that there was no
> development budget for this. So it wasn't impossible, just a Very Bad Idea. After 30
> minutes of hearing all the things that could go wrong, in great detail, I walked away with
> one bit set: "Don't use C++ in the kernel".
>
> There is an infamous white paper on why C++ in the kernel produces problems. I haven't
> bothered to track it down, but it was someone's analysis of the problems.
>
> The class of drivers known as "multimedia streaming drivers" are written in C++, and the
> paper came from someone's analysis of all the things that had gone wrong once programmers
> outside Microsoft (who didn't have the top-secret internal memos that said what did and
> didn't work) started writing these drivers. Apparently it is a real nightmare. I've
> never even looked at writing them.
>
> That said, I've heard from other sources that the KMDF framework is written in C++, but in
> a very, very carefully selected subset of C++ that is known to work correctly. I have no
> data to confirm or refute this claim, which was made to me by someone outside Microsoft.
>
> Actually, Peter Viscarola (OSR, the premier driver writers in the country, possibly the
> world) once asked "Why can't we write drivers in C#?" in one of his "Peter Pontificates"
> columns in the OSR newsletter. A firestorm erupted, with people claiming that you
> couldn't write efficient code in C#, that C was good enough for their grandpa and, by gum,
> it's good enough for me, and that anyone who didn't want to code in C was clearly
> delusional. But I agree with Peter: kernel code is too important to leave it to C
> programmers.
>
> I just finished a large C project based on the fact that the customer base for the client
> was still programming in C. One of the things I produced was an MFC-compatible wrapper so
> I could write all my code in C++, and not have to write anything in C.
> joe
> On Thu, 21 Jan 2010 16:40:14 +0100, "Giovanni Dicanio"
> <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:
>
>> "Tom Serface" <tom(a)camaswood.com> ha scritto nel messaggio
>> news:uMCoo2qmKHA.5520(a)TK2MSFTNGP06.phx.gbl...
>>
>>> I've never done device drivers, but I bet you could still do them in C++
>>> somehow.
>> http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>>
>> However we can wait for Joe, who teaches device driver courses and has lots
>> of experience in this fascinating field.
>>
>> Giovanni
>>
>>
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
OK, I had not realized that document was public. I knew about it, but my knowledge had
been under NDA. Now that it is public, it summarizes a lot of the issues that were
explained to me. I see that it went public within a few months of my conversation.
joe

On Thu, 21 Jan 2010 11:59:10 -0600, BobF <nothanks(a)no.spam> wrote:

>
>
>I remember reading http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>a while back
>
>
>Joseph M. Newcomer wrote:
>> C++ in the kernel has serious problems. Not intrinsic problems, but serious problems.
>> When I was at a Driver DevCon some years ago, I asked "Isn't it about time we should be
>> able to use C++ in the kernel?" and was dragged over to one of the C++ compiler leads. We
>> talked (or rather, I listened) for about half an hour to everything that can go wrong in
>> the kernel. Only a subset of C++ actually works. His comment was that he could make it
>> work in the kernel, but it involved some significant compiler changes (most of them
>> #pragmas, and the consequent handling of them). The problem was simply that there was no
>> development budget for this. So it wasn't impossible, just a Very Bad Idea. After 30
>> minutes of hearing all the things that could go wrong, in great detail, I walked away with
>> one bit set: "Don't use C++ in the kernel".
>>
>> There is an infamous white paper on why C++ in the kernel produces problems. I haven't
>> bothered to track it down, but it was someone's analysis of the problems.
>>
>> The class of drivers known as "multimedia streaming drivers" are written in C++, and the
>> paper came from someone's analysis of all the things that had gone wrong once programmers
>> outside Microsoft (who didn't have the top-secret internal memos that said what did and
>> didn't work) started writing these drivers. Apparently it is a real nightmare. I've
>> never even looked at writing them.
>>
>> That said, I've heard from other sources that the KMDF framework is written in C++, but in
>> a very, very carefully selected subset of C++ that is known to work correctly. I have no
>> data to confirm or refute this claim, which was made to me by someone outside Microsoft.
>>
>> Actually, Peter Viscarola (OSR, the premier driver writers in the country, possibly the
>> world) once asked "Why can't we write drivers in C#?" in one of his "Peter Pontificates"
>> columns in the OSR newsletter. A firestorm erupted, with people claiming that you
>> couldn't write efficient code in C#, that C was good enough for their grandpa and, by gum,
>> it's good enough for me, and that anyone who didn't want to code in C was clearly
>> delusional. But I agree with Peter: kernel code is too important to leave it to C
>> programmers.
>>
>> I just finished a large C project based on the fact that the customer base for the client
>> was still programming in C. One of the things I produced was an MFC-compatible wrapper so
>> I could write all my code in C++, and not have to write anything in C.
>> joe
>> On Thu, 21 Jan 2010 16:40:14 +0100, "Giovanni Dicanio"
>> <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:
>>
>>> "Tom Serface" <tom(a)camaswood.com> ha scritto nel messaggio
>>> news:uMCoo2qmKHA.5520(a)TK2MSFTNGP06.phx.gbl...
>>>
>>>> I've never done device drivers, but I bet you could still do them in C++
>>>> somehow.
>>> http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>>>
>>> However we can wait for Joe, who teaches device driver courses and has lots
>>> of experience in this fascinating field.
>>>
>>> Giovanni
>>>
>>>
>> Joseph M. Newcomer [MVP]
>> email: newcomer(a)flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: BobF on

All it took was one read through to convince me I didn't want to go there.

Joseph M. Newcomer wrote:
> OK, I had not realized that document was public. I knew about it, but my knowledge had
> been under NDA. Now that it is public, it summarizes a lot of the issues that were
> explained to me. I see that it went public within a few months of my conversation.
> joe
>
> On Thu, 21 Jan 2010 11:59:10 -0600, BobF <nothanks(a)no.spam> wrote:
>
>>
>> I remember reading http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>> a while back
>>
>>
>> Joseph M. Newcomer wrote:
>>> C++ in the kernel has serious problems. Not intrinsic problems, but serious problems.
>>> When I was at a Driver DevCon some years ago, I asked "Isn't it about time we should be
>>> able to use C++ in the kernel?" and was dragged over to one of the C++ compiler leads. We
>>> talked (or rather, I listened) for about half an hour to everything that can go wrong in
>>> the kernel. Only a subset of C++ actually works. His comment was that he could make it
>>> work in the kernel, but it involved some significant compiler changes (most of them
>>> #pragmas, and the consequent handling of them). The problem was simply that there was no
>>> development budget for this. So it wasn't impossible, just a Very Bad Idea. After 30
>>> minutes of hearing all the things that could go wrong, in great detail, I walked away with
>>> one bit set: "Don't use C++ in the kernel".
>>>
>>> There is an infamous white paper on why C++ in the kernel produces problems. I haven't
>>> bothered to track it down, but it was someone's analysis of the problems.
>>>
>>> The class of drivers known as "multimedia streaming drivers" are written in C++, and the
>>> paper came from someone's analysis of all the things that had gone wrong once programmers
>>> outside Microsoft (who didn't have the top-secret internal memos that said what did and
>>> didn't work) started writing these drivers. Apparently it is a real nightmare. I've
>>> never even looked at writing them.
>>>
>>> That said, I've heard from other sources that the KMDF framework is written in C++, but in
>>> a very, very carefully selected subset of C++ that is known to work correctly. I have no
>>> data to confirm or refute this claim, which was made to me by someone outside Microsoft.
>>>
>>> Actually, Peter Viscarola (OSR, the premier driver writers in the country, possibly the
>>> world) once asked "Why can't we write drivers in C#?" in one of his "Peter Pontificates"
>>> columns in the OSR newsletter. A firestorm erupted, with people claiming that you
>>> couldn't write efficient code in C#, that C was good enough for their grandpa and, by gum,
>>> it's good enough for me, and that anyone who didn't want to code in C was clearly
>>> delusional. But I agree with Peter: kernel code is too important to leave it to C
>>> programmers.
>>>
>>> I just finished a large C project based on the fact that the customer base for the client
>>> was still programming in C. One of the things I produced was an MFC-compatible wrapper so
>>> I could write all my code in C++, and not have to write anything in C.
>>> joe
>>> On Thu, 21 Jan 2010 16:40:14 +0100, "Giovanni Dicanio"
>>> <giovanniDOTdicanio(a)REMOVEMEgmail.com> wrote:
>>>
>>>> "Tom Serface" <tom(a)camaswood.com> ha scritto nel messaggio
>>>> news:uMCoo2qmKHA.5520(a)TK2MSFTNGP06.phx.gbl...
>>>>
>>>>> I've never done device drivers, but I bet you could still do them in C++
>>>>> somehow.
>>>> http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
>>>>
>>>> However we can wait for Joe, who teaches device driver courses and has lots
>>>> of experience in this fascinating field.
>>>>
>>>> Giovanni
>>>>
>>>>
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer(a)flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Alexander Grigoriev on

"Joseph M. Newcomer" <newcomer(a)flounder.com> wrote in message
news:ihvgl59d3dbk0vji8g5j6nqbrrepn6mq5t(a)4ax.com...
> C++ in the kernel has serious problems. Not intrinsic problems, but
> serious problems.
> That said, I've heard from other sources that the KMDF framework is
> written in C++, but in
> a very, very carefully selected subset of C++ that is known to work
> correctly. I have no
> data to confirm or refute this claim, which was made to me by someone
> outside Microsoft.
>

If you load KMDF sys to the debugger and print its symbols, you'll see a lot
of C++ qualified names.


From: Pete Delgado on

"BobF" <nothanks(a)no.spam> wrote in message
news:%23uxn%23NsmKHA.2780(a)TK2MSFTNGP05.phx.gbl...
>
> I remember reading http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx
> a while back

Thanks for the link Bob. This thread had made me wonder why it couldn't be
possible to create a template-based framework with the appropriate entry
points pre-defined. The article answers many of my questions and I think I'm
going to re-read it a couple more times because I always seem to miss
important points during the first reading!

PS: If anyone has an original driver development kit for the reference
implementation of the NVIDIA NVTV product, please contact me!

-Pete