- Can we use cpp to write WDM driver ?
- Posted by Kid on May 30th, 2007
Hi
I found that some WDM audio driver source use cpp files , so can DDK use all
C++ class and library ?
Can we use other languages (like VB C# Java) to develop Microsoft drivers ?
Thank you
- Posted by Don Burn on May 30th, 2007
You can use C++ but there are a lot of restrictions see
http://www.microsoft.com/whdc/driver/kernel/KMcode.mspx. Because of these
restrictions most class libraries and other things do not work. Also, you
have to code your own runtime environment see http://www.hollistech.com/
for a version you can use.
Most people who use C++ in the kernel use it extremely limited mode. I
know of firms that required an assembler code reviiew of all drivers with
C++ to make sure some surprise did not occur using C++. I have also worked
for firms that have it in their coding guidelines that using C++ in the
kernel is grounds for termination or non-payment for a consultant.
You cannot use other languages for in the kernel, just C and limited C++.
Be aware that the audio driver is part of kernel streaming a seperate
subsystem. I have heard people from Microsoft call it "kernel screaming"
due to its unreliability that is blamed on C++.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"Kid" <Kid@discussions.microsoft.com> wrote in message
news:25A7DD01-71F9-4ACA-8D55-F80D84E7B3E4@microsoft.com...
- Posted by Ben Voigt [C++ MVP] on May 30th, 2007
"Don Burn" <burn@stopspam.windrvr.com> wrote in message
news:uBXkkCroHHA.1240@TK2MSFTNGP06.phx.gbl...
I guess you are saying that C++ is usable so long as it is limited to the
parts that are just syntactic sugar (ala cfront)? Of course the standard
C++ runtime library won't work in kernel mode, but then kernel drivers don't
use the CRT either. Exceptions and RTTI rely on support from the runtime
library and thus would probably not work.
- Posted by Don Burn on May 30th, 2007
"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
news:OD1kTqsoHHA.1244@TK2MSFTNGP04.phx.gbl...
is why I referred to the paper, since you can get into serious trouble by
just using C++ without runtimes. I like C++ and was on the standards
committee for the language, but I will not go near it in the kernel.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
- Posted by Alexander Grigoriev on May 30th, 2007
Nevertheless, KMDF inside is written on C++, even though exposing only C
interfaces..
"Don Burn" <burn@stopspam.windrvr.com> wrote in message
news:uzJi7xsoHHA.5084@TK2MSFTNGP02.phx.gbl...
- Posted by Don Burn on May 30th, 2007
Yes KMDF used C++, but extremely limited mainly for virtual functions and
even there some challenges see
http://blogs.msdn.com/doronh/archive...functions.aspx
Trying to claim C++ is ok by the example of KMDF is a gross overstatement,
not only was their use highly constrained, the developers are some of the
sharpest in Microsoft which places them above the average kernel developer.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:%23BMdAAtoHHA.4188@TK2MSFTNGP02.phx.gbl...
- Posted by Ray Trent on May 30th, 2007
Don Burn wrote:
True, but at the risk of restarting the annual C++ flamewar...
What it *does* show is that the best and brightest MS engineers,
including those who know the most about the problems it could cause,
thought hard about it and decided that there were enough *advantages* to
using C++ in a non-trivial way in the kernel that it was worth doing it...
.... Notwithstanding the nightmare that it could cause bluescreens in
*every* KMDF driver if C++ caused a problem in the framework code.
--
Ray
- Posted by Don Burn on May 30th, 2007
Ray,
I would argue it was a trivial way in that they choose to use it for
one feature. I have seen excellent drivers in C++ and total crap drivers
in C, but the OP's level of questions says IMHO that they should not use
C++ until they know a lot more.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"Ray Trent" <rat@nospam.nospam> wrote in message
news:%23LWmFztoHHA.1476@TK2MSFTNGP03.phx.gbl...
- Posted by Doron Holan [MS] on May 31st, 2007
let me tell you, i needed convincing. on the previous project i worked on
before KMDF (bluetooth), the initial stab at it was in C++ with templates
and other c++isms galore. got bit by it in a very hard way. took alot of
convincing and manual rules (on restricting C++ features to use) to convince
me to try again.
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ray Trent" <rat@nospam.nospam> wrote in message
news:%23LWmFztoHHA.1476@TK2MSFTNGP03.phx.gbl...
- Posted by Ben Voigt [C++ MVP] on May 31st, 2007
"Doron Holan [MS]" <doronh@nospam.microsoft.com> wrote in message
news:uDrlbY0oHHA.4428@TK2MSFTNGP06.phx.gbl...
If templates caused a problem, it must have been due to reasoning errors by
the programmers... as far as I can tell templates require absolutely no
runtime support whatsoever, and essentially just expand to C code in a
type-safe way.
- Posted by Don Burn on May 31st, 2007
"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
Go read the paper I referenced. Unless you choose to waste a lot of
kernel space to put everyting non-paged, templates can cause a ton of
problems by instantiating methods in the wrong area.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
- Posted by Alexander Grigoriev on May 31st, 2007
What's a big reason to ever use paged code in a reasonably sized WDM driver?
"Don Burn" <burn@stopspam.windrvr.com> wrote in message
news:uipUJx4oHHA.596@TK2MSFTNGP06.phx.gbl...
- Posted by Don Burn on May 31st, 2007
Well the question was on templates. I find people get surprised how often
templates expand to a large amount of memory. I also, find little reason
to use a template in a stock WDM driver, but if you are doing something
advanced which may take a lot of space, then templates start looking more
interesting, except this is when you will get nailed by paged and non-paged
sections.
Personally, I still am careful to take advantage of paged code where ever
possible. Having the smallest reasonable foot print is just being a good
developer in the Windows kernel, the next driver may need those resources.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
"Alexander Grigoriev" <alegr@earthlink.net> wrote in message
news:eptCMH5oHHA.668@TK2MSFTNGP05.phx.gbl...
- Posted by 440gtx@email.com on May 31st, 2007
The same is true for people who use C in the kernel. Functions like
printf don't work, others like memcpy are frowned upon, using a few K
of stack a no-no, etc.
I sense a little bias here as I doubt these firms scrutinized the
assembly code and terminated consultants who used C with the 2003 DDK
(one of the most prolific in the history of drivers) that produced bad
code for things like interlocks. You talk about needing an assembler
code review and prone to failure...
I was disappointed when I read the blog of the Microsoft developer
being tripped up by C++. It seems simply a case he confused the C#
language with C++. I suspect anyone who has studied more than language
has done that in one form or another so no biggie really.
But I tend to agree with the spirit of the thread, some C++ can be
done effectively, but you better know well what you are doing before
you do anything with C++ in the kernel.
- Posted by Don Burn on May 31st, 2007
<440gtx@email.com> wrote in message
I have consulted for a firm that had in their Statement of Work "The use of
C++ is grounds for non-payment". One of the firms that did assembly review
was parts of Microsoft. The problem with C++ is that it looks like C but
can generate a lot of stuff underneath for you, whereas with C code for the
most part what you see is pretty much what you get.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
- Posted by 440gtx@email.com on May 31st, 2007
30 years ago that is what the assembly guys were saying about C.
- Posted by Don Burn on May 31st, 2007
<440gtx@email.com> wrote in message
news:1180628359.301732.278750@x35g2000prf.googlegr oups.com...
then) was whether you can trust the compiler to generate the correct code
for a mission critical system such as an OS. Actually, some of the
philosophy behind C was to make a simple enough language with out any
implicit runtime to make it easier to be sure the compiler did the correct
thing.
The concern with C++ is that you can have a simple statement that generates
something far from simple. It is true that it is under the developers
control rather than the compiler and that is both the blessing and problem.
This is why some people insist on assembler reviews, since in C a simple
expression has limited possible outcomes, but the same expression in C++
requires verifying all the base classes.
--
Don Burn (MVP, Windows DDK)
Windows 2k/XP/2k3 Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr
Remove StopSpam to reply
- Posted by Doron Holan [MS] on June 1st, 2007
not a true comparison. you are comparing the CRT in C with built in language
features in C++.
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
<440gtx@email.com> wrote in message
news:1180626574.141803.188910@i38g2000prf.googlegr oups.com...
- Posted by Doron Holan [MS] on June 1st, 2007
the issue is not the code that is generated, but *WHERE* the code is
generated. drivers will segment code and data by where it can withstand a
page fault or not. we use #pragmas to set this attribute for code, but
templates do not respect the #pragmas around them b/c they are instantiated
not in the header, but in first usage. furthermore, the linker does alot of
functional folding, so even if you got it right in the lib phase, the linker
can put it in the wrong section.
d
--
Please do not send e-mail directly to this alias. this alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.
"Ben Voigt [C++ MVP]" <rbv@nospam.nospam> wrote in message
news:uFvDXt4oHHA.3736@TK2MSFTNGP03.phx.gbl...
- Posted by 440gtx@email.com on June 1st, 2007
On Jun 1, 8:35 am, "Doron Holan [MS]" <dor...@nospam.microsoft.com>
wrote:
On the contrary, I think it is an excellent comparison. The CRT is
part of the C standard. The standard libraries are part of the C++
standard. Both have limitations in the kernel. When using C in the
kernel one must be aware of limitations in *and* out of the CRT. With
C you do indeed need intimate knowledge of what parts of the language
you can use, and not only that but how to use working parts properly
due to the unique characteristics of the kernel.