C++ and WDF

No no no … this is NOT the infamous “Using C++ in the kernel” discussion.
It’s more along the lines of having a WDF project and I want to define my
source files with CPP extensions and extern “C” my include files to derive
the benefit of the C++ compiler. When I do that, I get the compile errors on
“new” and “delete”. Is this possible? The C++ compiler has much tighter type
definitions and I can overload functions, which can be handy at times. There
is NO intention of doing class definitions with WDF, I just want to use the
C++ aspects of the compiler.

So help me, if someone tells me NOT to use class definitions in the kernel,
I’m gonna shave my head and become a southern Baptist monk.


Gary G. Little

Are you getting new & delete being undefined and not found by the
linker? Or are you getting errors by the compiler itself?

You only need to extern “C” your own headers if you need those functions
called by a driver written in C. you can easily just have a cpp file
and an h file w/no extern “C” on it and be just fine. Of course, you
have to extern “C” the #includes of some system headers, but they won’t
be calling new or delete.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Thursday, July 28, 2005 1:58 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] C++ and WDF

No no no … this is NOT the infamous “Using C++ in the kernel”
discussion.
It’s more along the lines of having a WDF project and I want to define
my
source files with CPP extensions and extern “C” my include files to
derive
the benefit of the C++ compiler. When I do that, I get the compile
errors on
“new” and “delete”. Is this possible? The C++ compiler has much tighter
type
definitions and I can overload functions, which can be handy at times.
There
is NO intention of doing class definitions with WDF, I just want to use
the
C++ aspects of the compiler.

So help me, if someone tells me NOT to use class definitions in the
kernel,
I’m gonna shave my head and become a southern Baptist monk.


Gary G. Little


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

Gary G. Little wrote:

No no no … this is NOT the infamous “Using C++ in the kernel” discussion.
It’s more along the lines of having a WDF project and I want to define my
source files with CPP extensions and extern “C” my include files to derive
the benefit of the C++ compiler. When I do that, I get the compile errors on
“new” and “delete”. Is this possible? The C++ compiler has much tighter type
definitions and I can overload functions, which can be handy at times. There
is NO intention of doing class definitions with WDF, I just want to use the
C++ aspects of the compiler.

What kind of compile errors? As long as you have your own definitions
for global operator new and delete that call one of the Ex*Pool family,
it should work fine.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Tim, Doran …

Here are the first few compiler errors from the VS 2005 output using
DDKBUILD:

1>Compiling - oseentry.cpp for i386
1>errors in directory c:\sandbox\opensea\seakernel\ose
1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage specification
contradicts earlier specification for ‘operator delete’
1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage specification
contradicts earlier specification for ‘operator new’
1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C linkage of
overloaded function ‘operator new’ not allowed
1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C linkage of
overloaded function ‘operator delete’ not allowed
1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894: templates cannot be
declared to have ‘C’ linkage
1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894: templates cannot be
declared to have ‘C’ linkage

I have a local header file that includes the DDK and WDF header files. The
include for that file is wrapped with “extern “C” {#include allheaders.h}”
Given what has been said here, that should be done more like:

extern “C”
{
#include <ntddk.h>
#include <<otherddk.h>>
}
#include <wdf.h>
#include <<otherwdf.h>>


The personal opinion of
Gary G. Little

“Tim Roberts” wrote in message news:xxxxx@ntdev…
> Gary G. Little wrote:
>
>>No no no … this is NOT the infamous “Using C++ in the kernel”
>>discussion. It’s more along the lines of having a WDF project and I want
>>to define my source files with CPP extensions and extern “C” my include
>>files to derive the benefit of the C++ compiler. When I do that, I get the
>>compile errors on “new” and “delete”. Is this possible? The C++ compiler
>>has much tighter type definitions and I can overload functions, which can
>>be handy at times. There is NO intention of doing class definitions with
>>WDF, I just want to use the C++ aspects of the compiler.
>>
>
> What kind of compile errors? As long as you have your own definitions for
> global operator new and delete that call one of the Ex*Pool family, it
> should work fine.
>
> –
> Tim Roberts, xxxxx@probo.com
> Providenza & Boekelheide, Inc.
>
></otherwdf.h></wdf.h></otherddk.h></ntddk.h>

For what its worth, I have a .cpp wdf project that declares no classes that
compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project that has lots
of classes (:slight_smile: and see if that falls over and dies with the latest wdf
drop.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Friday, July 29, 2005 2:05 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] C++ and WDF

Tim, Doran …

Here are the first few compiler errors from the VS 2005 output using
DDKBUILD:

1>Compiling - oseentry.cpp for i386
1>errors in directory c:\sandbox\opensea\seakernel\ose
1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
1>specification
contradicts earlier specification for ‘operator delete’
1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
1>specification
contradicts earlier specification for ‘operator new’
1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C
linkage of
overloaded function ‘operator new’ not allowed
1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C
linkage of
overloaded function ‘operator delete’ not allowed
1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
templates cannot
1>be
declared to have ‘C’ linkage
1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
templates cannot
1>be
declared to have ‘C’ linkage

I have a local header file that includes the DDK and WDF
header files. The include for that file is wrapped with
“extern “C” {#include allheaders.h}”
Given what has been said here, that should be done more like:

extern “C”
{
#include <ntddk.h>
> #include <<otherddk.h>>
> }
> #include <wdf.h>
> #include <<otherwdf.h>>
>
> –
> The personal opinion of
> Gary G. Little
>
> “Tim Roberts” wrote in message news:xxxxx@ntdev…
> > Gary G. Little wrote:
> >
> >>No no no … this is NOT the infamous “Using C++ in the kernel”
> >>discussion. It’s more along the lines of having a WDF project and I
> >>want to define my source files with CPP extensions and
> extern “C” my
> >>include files to derive the benefit of the C++ compiler. When I do
> >>that, I get the compile errors on “new” and “delete”. Is this
> >>possible? The C++ compiler has much tighter type
> definitions and I can
> >>overload functions, which can be handy at times. There is
> NO intention
> >>of doing class definitions with WDF, I just want to use the
> C++ aspects of the compiler.
> >>
> >
> > What kind of compile errors? As long as you have your own
> definitions
> > for global operator new and delete that call one of the Ex*Pool
> > family, it should work fine.
> >
> > –
> > Tim Roberts, xxxxx@probo.com
> > Providenza & Boekelheide, Inc.
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
></otherwdf.h></wdf.h></otherddk.h></ntddk.h>

That’s all I want here, just be able to compile a cop source file but
declare no classes. I’m in the process of cutting and pasting header files
in and out of the extern “C” to find a combination that works.


The personal opinion of
Gary G. Little
(whew, so far my coiffure is safe)

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> For what its worth, I have a .cpp wdf project that declares no classes
> that
> compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project that has
> lots
> of classes (:slight_smile: and see if that falls over and dies with the latest wdf
> drop.
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
>> Sent: Friday, July 29, 2005 2:05 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re:[ntdev] C++ and WDF
>>
>> Tim, Doran …
>>
>> Here are the first few compiler errors from the VS 2005 output using
>> DDKBUILD:
>>
>> 1>Compiling - oseentry.cpp for i386
>> 1>errors in directory c:\sandbox\opensea\seakernel\ose
>> 1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator delete’
>> 1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator new’
>> 1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C
>> linkage of
>> overloaded function ‘operator new’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C
>> linkage of
>> overloaded function ‘operator delete’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>>
>> I have a local header file that includes the DDK and WDF
>> header files. The include for that file is wrapped with
>> “extern “C” {#include allheaders.h}”
>> Given what has been said here, that should be done more like:
>>
>> extern “C”
>> {
>> #include <ntddk.h>
>> #include <<otherddk.h>>
>> }
>> #include <wdf.h>
>> #include <<otherwdf.h>>
>>
>> –
>> The personal opinion of
>> Gary G. Little
>>
>> “Tim Roberts” wrote in message news:xxxxx@ntdev…
>> > Gary G. Little wrote:
>> >
>> >>No no no … this is NOT the infamous “Using C++ in the kernel”
>> >>discussion. It’s more along the lines of having a WDF project and I
>> >>want to define my source files with CPP extensions and
>> extern “C” my
>> >>include files to derive the benefit of the C++ compiler. When I do
>> >>that, I get the compile errors on “new” and “delete”. Is this
>> >>possible? The C++ compiler has much tighter type
>> definitions and I can
>> >>overload functions, which can be handy at times. There is
>> NO intention
>> >>of doing class definitions with WDF, I just want to use the
>> C++ aspects of the compiler.
>> >>
>> >
>> > What kind of compile errors? As long as you have your own
>> definitions
>> > for global operator new and delete that call one of the Ex*Pool
>> > family, it should work fine.
>> >
>> > –
>> > Tim Roberts, xxxxx@probo.com
>> > Providenza & Boekelheide, Inc.
>> >
>> >
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as:
>> xxxxx@hollistech.com To unsubscribe send a blank email to
>> xxxxx@lists.osr.com
>>
>
>
></otherwdf.h></wdf.h></otherddk.h></ntddk.h>

A file that contains any C++'isms (new, delete, classes) cannot be
#includeded under the extern “C” directive. So if you are wrapping your
C++ headers in extern “C” #include, that needs to be moved out.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Friday, July 29, 2005 11:51 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] C++ and WDF

That’s all I want here, just be able to compile a cop source file but
declare no classes. I’m in the process of cutting and pasting header
files
in and out of the extern “C” to find a combination that works.


The personal opinion of
Gary G. Little
(whew, so far my coiffure is safe)

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> For what its worth, I have a .cpp wdf project that declares no classes

> that
> compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project that has

> lots
> of classes (:slight_smile: and see if that falls over and dies with the latest
wdf
> drop.
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
>> Sent: Friday, July 29, 2005 2:05 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re:[ntdev] C++ and WDF
>>
>> Tim, Doran …
>>
>> Here are the first few compiler errors from the VS 2005 output using
>> DDKBUILD:
>>
>> 1>Compiling - oseentry.cpp for i386
>> 1>errors in directory c:\sandbox\opensea\seakernel\ose
>> 1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator delete’
>> 1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator new’
>> 1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C
>> linkage of
>> overloaded function ‘operator new’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C
>> linkage of
>> overloaded function ‘operator delete’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>>
>> I have a local header file that includes the DDK and WDF
>> header files. The include for that file is wrapped with
>> “extern “C” {#include allheaders.h}”
>> Given what has been said here, that should be done more like:
>>
>> extern “C”
>> {
>> #include <ntddk.h>
>> #include <<otherddk.h>>
>> }
>> #include <wdf.h>
>> #include <<otherwdf.h>>
>>
>> –
>> The personal opinion of
>> Gary G. Little
>>
>> “Tim Roberts” wrote in message news:xxxxx@ntdev…
>> > Gary G. Little wrote:
>> >
>> >>No no no … this is NOT the infamous “Using C++ in the kernel”
>> >>discussion. It’s more along the lines of having a WDF project and I
>> >>want to define my source files with CPP extensions and
>> extern “C” my
>> >>include files to derive the benefit of the C++ compiler. When I do
>> >>that, I get the compile errors on “new” and “delete”. Is this
>> >>possible? The C++ compiler has much tighter type
>> definitions and I can
>> >>overload functions, which can be handy at times. There is
>> NO intention
>> >>of doing class definitions with WDF, I just want to use the
>> C++ aspects of the compiler.
>> >>
>> >
>> > What kind of compile errors? As long as you have your own
>> definitions
>> > for global operator new and delete that call one of the Ex*Pool
>> > family, it should work fine.
>> >
>> > –
>> > Tim Roberts, xxxxx@probo.com
>> > Providenza & Boekelheide, Inc.
>> >
>> >
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as:
>> xxxxx@hollistech.com To unsubscribe send a blank email to
>> xxxxx@lists.osr.com
>>
>
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</otherwdf.h></wdf.h></otherddk.h></ntddk.h>

Gary,

I once wrote a legacy toy driver in classless C++, that is,
using C++ as a better C, for my OS classes. All it needs as far
as extern “C” is this

extern “C” { #include <ntddk.h> }

and this,

extern “C” NTSTATUS DriverEntry(…) {

Works fine. There might be a couple of other situations where
you may need it in order to plug some callback - maybe - but
otherwise you can probably get away with a lot before you need
to use extern “C” anywhere else. On the other hand, I’m a
minimalist who doesn’t use any API or hook unless I’m really,
really forced to, therefore, I may be avoiding trouble just by
writing my own code instead of trying to reuse someone else’s.

Note that in fact you don’t want to use extern “C” in your own
functions, I may be wrong but I believe that it’s only needed
when you have a symbol that for one reason or another must be
compiled with the C naming convention. That may include some OS
interfaces, but you don’t need it in your own code.

Alberto.

----- Original Message -----
From: “Gary G. Little”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”

Sent: Friday, July 29, 2005 2:50 PM
Subject: Re:[ntdev] C++ and WDF

> That’s all I want here, just be able to compile a cop source
> file but declare no classes. I’m in the process of cutting and
> pasting header files in and out of the extern “C” to find a
> combination that works.
>
> –
> The personal opinion of
> Gary G. Little
> (whew, so far my coiffure is safe)
>
> “Mark Roddy” wrote in message
> news:xxxxx@ntdev…
>> For what its worth, I have a .cpp wdf project that declares
>> no classes that
>> compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project
>> that has lots
>> of classes (:slight_smile: and see if that falls over and dies with the
>> latest wdf
>> drop.
>>
>> =====================
>> Mark Roddy DDK MVP
>> Windows 2003/XP/2000 Consulting
>> Hollis Technology Solutions 603-321-1032
>> www.hollistech.com
>>
>>> -----Original Message-----
>>> From: xxxxx@lists.osr.com
>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary
>>> G. Little
>>> Sent: Friday, July 29, 2005 2:05 PM
>>> To: Windows System Software Devs Interest List
>>> Subject: Re:[ntdev] C++ and WDF
>>>
>>> Tim, Doran …
>>>
>>> Here are the first few compiler errors from the VS 2005
>>> output using
>>> DDKBUILD:
>>>
>>> 1>Compiling - oseentry.cpp for i386
>>> 1>errors in directory c:\sandbox\opensea\seakernel\ose
>>> 1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
>>> 1>specification
>>> contradicts earlier specification for ‘operator delete’
>>> 1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
>>> 1>specification
>>> contradicts earlier specification for ‘operator new’
>>> 1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second
>>> C
>>> linkage of
>>> overloaded function ‘operator new’ not allowed
>>> 1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second
>>> C
>>> linkage of
>>> overloaded function ‘operator delete’ not allowed
>>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
>>> templates cannot
>>> 1>be
>>> declared to have ‘C’ linkage
>>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
>>> templates cannot
>>> 1>be
>>> declared to have ‘C’ linkage
>>>
>>> I have a local header file that includes the DDK and WDF
>>> header files. The include for that file is wrapped with
>>> “extern “C” {#include allheaders.h}”
>>> Given what has been said here, that should be done more
>>> like:
>>>
>>> extern “C”
>>> {
>>> #include <ntddk.h>
>>> #include <<otherddk.h>>
>>> }
>>> #include <wdf.h>
>>> #include <<otherwdf.h>>
>>>
>>> –
>>> The personal opinion of
>>> Gary G. Little
>>>
>>> “Tim Roberts” wrote in message
>>> news:xxxxx@ntdev…
>>> > Gary G. Little wrote:
>>> >
>>> >>No no no … this is NOT the infamous “Using C++ in the
>>> >>kernel”
>>> >>discussion. It’s more along the lines of having a WDF
>>> >>project and I
>>> >>want to define my source files with CPP extensions and
>>> extern “C” my
>>> >>include files to derive the benefit of the C++ compiler.
>>> >>When I do
>>> >>that, I get the compile errors on “new” and “delete”. Is
>>> >>this
>>> >>possible? The C++ compiler has much tighter type
>>> definitions and I can
>>> >>overload functions, which can be handy at times. There is
>>> NO intention
>>> >>of doing class definitions with WDF, I just want to use
>>> >>the
>>> C++ aspects of the compiler.
>>> >>
>>> >
>>> > What kind of compile errors? As long as you have your own
>>> definitions
>>> > for global operator new and delete that call one of the
>>> > Ex*Pool
>>> > family, it should work fine.
>>> >
>>> > –
>>> > Tim Roberts, xxxxx@probo.com
>>> > Providenza & Boekelheide, Inc.
>>> >
>>> >
>>>
>>>
>>>
>>> —
>>> Questions? First check the Kernel Driver FAQ at
>>> http://www.osronline.com/article.cfm?id=256
>>>
>>> You are currently subscribed to ntdev as:
>>> xxxxx@hollistech.com To unsubscribe send a blank email to
>>> xxxxx@lists.osr.com
>>>
>>
>>
>>
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@ieee.org
> To unsubscribe send a blank email to
> xxxxx@lists.osr.com</otherwdf.h></wdf.h></otherddk.h></ntddk.h></ntddk.h>

> using C++ as a better C, for my OS classes. All it needs as far as extern

“C” is this extern “C” { #include <ntddk.h> }
> and this, extern “C” NTSTATUS DriverEntry(…)
… and if you use pragmas to set the function’s pageability, like

#pragma alloc_text(PAGE, StartDevice)

In this case

extern “C” NTSTATUS StartDevice(…);

MUST preceed the pragma. Otherwise you get

error C2128: ‘StartDevice’ : alloc_text/same_seg applicable only to
functions with C linkage

Regards,
Alex Shvedov

----- Original Message -----
From: “Alberto Moreira”
To: “Windows System Software Devs Interest List”
Sent: Saturday, July 30, 2005 5:29 PM
Subject: Re: Re:[ntdev] C++ and WDF

> Gary,
>
> I once wrote a legacy toy driver in classless C++, that is, using C++ as a
> better C, for my OS classes. All it needs as far as extern “C” is this
>
> extern “C” { #include <ntddk.h> }
>
> and this,
>
> extern “C” NTSTATUS DriverEntry(…) {
>
> Works fine. There might be a couple of other situations where you may need
> it in order to plug some callback - maybe - but otherwise you can probably
> get away with a lot before you need to use extern “C” anywhere else. On
> the other hand, I’m a minimalist who doesn’t use any API or hook unless
> I’m really, really forced to, therefore, I may be avoiding trouble just by
> writing my own code instead of trying to reuse someone else’s.
>
> Note that in fact you don’t want to use extern “C” in your own functions,
> I may be wrong but I believe that it’s only needed when you have a symbol
> that for one reason or another must be compiled with the C naming
> convention. That may include some OS interfaces, but you don’t need it in
> your own code.
>
> Alberto.
>
>
>
> ----- Original Message -----
> From: “Gary G. Little”
> Newsgroups: ntdev
> To: “Windows System Software Devs Interest List”
> Sent: Friday, July 29, 2005 2:50 PM
> Subject: Re:[ntdev] C++ and WDF
>
>
>> That’s all I want here, just be able to compile a cop source file but
>> declare no classes. I’m in the process of cutting and pasting header
>> files in and out of the extern “C” to find a combination that works.
>>
>> –
>> The personal opinion of
>> Gary G. Little
>> (whew, so far my coiffure is safe)
>>
>> “Mark Roddy” wrote in message news:xxxxx@ntdev…
>>> For what its worth, I have a .cpp wdf project that declares no classes
>>> that
>>> compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project that has
>>> lots
>>> of classes (:slight_smile: and see if that falls over and dies with the latest wdf
>>> drop.
>>>
>>> =====================
>>> Mark Roddy DDK MVP
>>> Windows 2003/XP/2000 Consulting
>>> Hollis Technology Solutions 603-321-1032
>>> www.hollistech.com
>>>
>>>> -----Original Message-----
>>>> From: xxxxx@lists.osr.com
>>>> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
>>>> Sent: Friday, July 29, 2005 2:05 PM
>>>> To: Windows System Software Devs Interest List
>>>> Subject: Re:[ntdev] C++ and WDF
>>>>
>>>> Tim, Doran …
>>>>
>>>> Here are the first few compiler errors from the VS 2005 output using
>>>> DDKBUILD:
>>>>
>>>> 1>Compiling - oseentry.cpp for i386
>>>> 1>errors in directory c:\sandbox\opensea\seakernel\ose
>>>> 1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
>>>> 1>specification
>>>> contradicts earlier specification for ‘operator delete’
>>>> 1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
>>>> 1>specification
>>>> contradicts earlier specification for ‘operator new’
>>>> 1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C
>>>> linkage of
>>>> overloaded function ‘operator new’ not allowed
>>>> 1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C
>>>> linkage of
>>>> overloaded function ‘operator delete’ not allowed
>>>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
>>>> templates cannot
>>>> 1>be
>>>> declared to have ‘C’ linkage
>>>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
>>>> templates cannot
>>>> 1>be
>>>> declared to have ‘C’ linkage
>>>>
>>>> I have a local header file that includes the DDK and WDF
>>>> header files. The include for that file is wrapped with
>>>> “extern “C” {#include allheaders.h}”
>>>> Given what has been said here, that should be done more like:
>>>>
>>>> extern “C”
>>>> {
>>>> #include <ntddk.h>
>>>> #include <<otherddk.h>>
>>>> }
>>>> #include <wdf.h>
>>>> #include <<otherwdf.h>>
>>>>
>>>> –
>>>> The personal opinion of
>>>> Gary G. Little
>>>>
>>>> “Tim Roberts” wrote in message news:xxxxx@ntdev…
>>>> > Gary G. Little wrote:
>>>> >
>>>> >>No no no … this is NOT the infamous “Using C++ in the kernel”
>>>> >>discussion. It’s more along the lines of having a WDF project and I
>>>> >>want to define my source files with CPP extensions and
>>>> extern “C” my
>>>> >>include files to derive the benefit of the C++ compiler. When I do
>>>> >>that, I get the compile errors on “new” and “delete”. Is this
>>>> >>possible? The C++ compiler has much tighter type
>>>> definitions and I can
>>>> >>overload functions, which can be handy at times. There is
>>>> NO intention
>>>> >>of doing class definitions with WDF, I just want to use the
>>>> C++ aspects of the compiler.
>>>> >>
>>>> >
>>>> > What kind of compile errors? As long as you have your own
>>>> definitions
>>>> > for global operator new and delete that call one of the Ex*Pool
>>>> > family, it should work fine.
>>>> >
>>>> > –
>>>> > Tim Roberts, xxxxx@probo.com
>>>> > Providenza & Boekelheide, Inc.
>>>> >
>>>> >
>>>>
>>>>
>>>>
>>>> —
>>>> Questions? First check the Kernel Driver FAQ at
>>>> http://www.osronline.com/article.cfm?id=256
>>>>
>>>> You are currently subscribed to ntdev as:
>>>> xxxxx@hollistech.com To unsubscribe send a blank email to
>>>> xxxxx@lists.osr.com
>>>>
>>>
>>>
>>>
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as: xxxxx@ieee.org
>> To unsubscribe send a blank email to xxxxx@lists.osr.com
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@bellsouth.net
> To unsubscribe send a blank email to xxxxx@lists.osr.com
></otherwdf.h></wdf.h></otherddk.h></ntddk.h></ntddk.h></ntddk.h>

The problem proved to be a header that was using inheritance in a struct. I
couldn’t compile with that header as either a CPP or C so I pulled it till
the corrected header is put back in to CVS.

The personal opinion of
Gary G. Little

“Doron Holan” wrote in message
news:xxxxx@ntdev…
A file that contains any C++'isms (new, delete, classes) cannot be
#includeded under the extern “C” directive. So if you are wrapping your
C++ headers in extern “C” #include, that needs to be moved out.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
Sent: Friday, July 29, 2005 11:51 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] C++ and WDF

That’s all I want here, just be able to compile a cop source file but
declare no classes. I’m in the process of cutting and pasting header
files
in and out of the extern “C” to find a combination that works.


The personal opinion of
Gary G. Little
(whew, so far my coiffure is safe)

“Mark Roddy” wrote in message news:xxxxx@ntdev…
> For what its worth, I have a .cpp wdf project that declares no classes

> that
> compiles just fine. I’ll resurrect my ‘wdf-rewrapper’ project that has

> lots
> of classes (:slight_smile: and see if that falls over and dies with the latest
wdf
> drop.
>
> =====================
> Mark Roddy DDK MVP
> Windows 2003/XP/2000 Consulting
> Hollis Technology Solutions 603-321-1032
> www.hollistech.com
>
>> -----Original Message-----
>> From: xxxxx@lists.osr.com
>> [mailto:xxxxx@lists.osr.com] On Behalf Of Gary G. Little
>> Sent: Friday, July 29, 2005 2:05 PM
>> To: Windows System Software Devs Interest List
>> Subject: Re:[ntdev] C++ and WDF
>>
>> Tim, Doran …
>>
>> Here are the first few compiler errors from the VS 2005 output using
>> DDKBUILD:
>>
>> 1>Compiling - oseentry.cpp for i386
>> 1>errors in directory c:\sandbox\opensea\seakernel\ose
>> 1>c:\winddk\3790.1830\inc\crt\new(32) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator delete’
>> 1>c:\winddk\3790.1830\inc\crt\new(33) : error C2732: linkage
>> 1>specification
>> contradicts earlier specification for ‘operator new’
>> 1>c:\winddk\3790.1830\inc\crt\new(53) : error C2733: second C
>> linkage of
>> overloaded function ‘operator new’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\new(56) : error C2733: second C
>> linkage of
>> overloaded function ‘operator delete’ not allowed
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(24) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>> 1>c:\winddk\3790.1830\inc\crt\iosfwd(71) : error C2894:
>> templates cannot
>> 1>be
>> declared to have ‘C’ linkage
>>
>> I have a local header file that includes the DDK and WDF
>> header files. The include for that file is wrapped with
>> “extern “C” {#include allheaders.h}”
>> Given what has been said here, that should be done more like:
>>
>> extern “C”
>> {
>> #include <ntddk.h>
>> #include <<otherddk.h>>
>> }
>> #include <wdf.h>
>> #include <<otherwdf.h>>
>>
>> –
>> The personal opinion of
>> Gary G. Little
>>
>> “Tim Roberts” wrote in message news:xxxxx@ntdev…
>> > Gary G. Little wrote:
>> >
>> >>No no no … this is NOT the infamous “Using C++ in the kernel”
>> >>discussion. It’s more along the lines of having a WDF project and I
>> >>want to define my source files with CPP extensions and
>> extern “C” my
>> >>include files to derive the benefit of the C++ compiler. When I do
>> >>that, I get the compile errors on “new” and “delete”. Is this
>> >>possible? The C++ compiler has much tighter type
>> definitions and I can
>> >>overload functions, which can be handy at times. There is
>> NO intention
>> >>of doing class definitions with WDF, I just want to use the
>> C++ aspects of the compiler.
>> >>
>> >
>> > What kind of compile errors? As long as you have your own
>> definitions
>> > for global operator new and delete that call one of the Ex*Pool
>> > family, it should work fine.
>> >
>> > –
>> > Tim Roberts, xxxxx@probo.com
>> > Providenza & Boekelheide, Inc.
>> >
>> >
>>
>>
>>
>> —
>> Questions? First check the Kernel Driver FAQ at
>> http://www.osronline.com/article.cfm?id=256
>>
>> You are currently subscribed to ntdev as:
>> xxxxx@hollistech.com To unsubscribe send a blank email to
>> xxxxx@lists.osr.com
>>
>
>
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com</otherwdf.h></wdf.h></otherddk.h></ntddk.h>

> “Doron Holan” wrote in message
> news:xxxxx@ntdev…
> A file that contains any C++'isms (new, delete, classes) cannot be
> #includeded under the extern “C” directive. So if you are wrapping your
> C++ headers in extern “C” #include, that needs to be moved out.

Hmmm. I see ntdef.h contains a C++ template definition; this would qualify
as a C++'ism in my book.

I also noticed the WPP tracing stuff uses a global constructor if you
#include it in a .cpp file, and Microsoft supplied no run-time code to make
this work (it’s a very small, but very MS specific piece of code).

The last 2 drivers I’ve written contained significant use of C++ features
(multiple inheritance, polymorphism, per class allocator/deallocator, smart
pointers). I have been totally impressed with how useful this can be, and
have had almost zero issues caused by it.

I’m not going to be adopting WDF if it’s incompatible with C++.

Does anybody know of a mailing list/newsgroup about using C++ for driver
development? I know here it’s a religious issue, and would rather have some
constructive conversations and comparison of experiences than debate its
rightness or wrongness.

- Jan

Actually I think the WPP tracing contains a horribly misnamed local variable
‘this’ which breaks any .cpp module using WPP. I’ve reported this twice, but
it seems to re-appear with each wdf release.

One of our rules for developers here is:

If it is worth fixing it is worth fixing at least seven or eight times.

Case in point.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Sunday, July 31, 2005 3:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

> “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> > A file that contains any C++'isms (new, delete, classes) cannot be
> > #includeded under the extern “C” directive. So if you are wrapping
> > your
> > C++ headers in extern “C” #include, that needs to be moved out.
>
> Hmmm. I see ntdef.h contains a C++ template definition; this
> would qualify as a C++'ism in my book.
>
> I also noticed the WPP tracing stuff uses a global
> constructor if you #include it in a .cpp file, and Microsoft
> supplied no run-time code to make this work (it’s a very
> small, but very MS specific piece of code).
>
> The last 2 drivers I’ve written contained significant use of
> C++ features (multiple inheritance, polymorphism, per class
> allocator/deallocator, smart pointers). I have been totally
> impressed with how useful this can be, and have had almost
> zero issues caused by it.
>
> I’m not going to be adopting WDF if it’s incompatible with C++.
>
> Does anybody know of a mailing list/newsgroup about using C++
> for driver development? I know here it’s a religious issue,
> and would rather have some constructive conversations and
> comparison of experiences than debate its rightness or wrongness.
>
> - Jan
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>

For WPP, use the -dll switch in WPP_OPTIONS.

WDF is compatible with C++, no one ever said it was not.

Have you tried to mark any of templated classes as PAGEable? Or
particular member functions as such? I have had zero luck in getting
that to work on a deterministic basis. It would work most of the time,
some other component would change slightly, and then things would break
down. The linker makes no guarantees about the placement of templacized
code and, if it appears multiple times, which section it would be merged
into (ie it is luck of the draw).

I will look at the ntdef.h code, but remember, ntdef.h is shared between
UM and KM components, so the presence of templates does not mean it is
an endorsement for KM.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Sunday, July 31, 2005 12:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

“Doron Holan” wrote in message
> news:xxxxx@ntdev…
> A file that contains any C++'isms (new, delete, classes) cannot be
> #includeded under the extern “C” directive. So if you are wrapping
your
> C++ headers in extern “C” #include, that needs to be moved out.

Hmmm. I see ntdef.h contains a C++ template definition; this would
qualify
as a C++'ism in my book.

I also noticed the WPP tracing stuff uses a global constructor if you
#include it in a .cpp file, and Microsoft supplied no run-time code to
make
this work (it’s a very small, but very MS specific piece of code).

The last 2 drivers I’ve written contained significant use of C++
features
(multiple inheritance, polymorphism, per class allocator/deallocator,
smart
pointers). I have been totally impressed with how useful this can be,
and
have had almost zero issues caused by it.

I’m not going to be adopting WDF if it’s incompatible with C++.

Does anybody know of a mailing list/newsgroup about using C++ for driver
development? I know here it’s a religious issue, and would rather have
some
constructive conversations and comparison of experiences than debate its
rightness or wrongness.

- Jan


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I fixed it again, hopefully this time it sticks :wink:

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Mark Roddy
Sent: Sunday, July 31, 2005 9:03 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

Actually I think the WPP tracing contains a horribly misnamed local
variable
‘this’ which breaks any .cpp module using WPP. I’ve reported this twice,
but
it seems to re-appear with each wdf release.

One of our rules for developers here is:

If it is worth fixing it is worth fixing at least seven or eight times.

Case in point.

=====================
Mark Roddy DDK MVP
Windows 2003/XP/2000 Consulting
Hollis Technology Solutions 603-321-1032
www.hollistech.com

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Sunday, July 31, 2005 3:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

> “Doron Holan” wrote in message
> > news:xxxxx@ntdev…
> > A file that contains any C++'isms (new, delete, classes) cannot be
> > #includeded under the extern “C” directive. So if you are wrapping
> > your
> > C++ headers in extern “C” #include, that needs to be moved out.
>
> Hmmm. I see ntdef.h contains a C++ template definition; this
> would qualify as a C++'ism in my book.
>
> I also noticed the WPP tracing stuff uses a global
> constructor if you #include it in a .cpp file, and Microsoft
> supplied no run-time code to make this work (it’s a very
> small, but very MS specific piece of code).
>
> The last 2 drivers I’ve written contained significant use of
> C++ features (multiple inheritance, polymorphism, per class
> allocator/deallocator, smart pointers). I have been totally
> impressed with how useful this can be, and have had almost
> zero issues caused by it.
>
> I’m not going to be adopting WDF if it’s incompatible with C++.
>
> Does anybody know of a mailing list/newsgroup about using C++
> for driver development? I know here it’s a religious issue,
> and would rather have some constructive conversations and
> comparison of experiences than debate its rightness or wrongness.
>
> - Jan
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
> http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as:
> xxxxx@hollistech.com To unsubscribe send a blank email to
> xxxxx@lists.osr.com
>


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

I looked at the usage of templates in ntdef.h. Looks like it is being
use for some typesafe string structure initialization and array element
counting. There are C equivalents (less typesafe) as well. Didn’t know
that was there…

d

-----Original Message-----
From: Doron Holan
Sent: Sunday, July 31, 2005 8:59 AM
To: ‘Windows System Software Devs Interest List’
Subject: RE: [ntdev] C++ and WDF

For WPP, use the -dll switch in WPP_OPTIONS.

WDF is compatible with C++, no one ever said it was not.

Have you tried to mark any of templated classes as PAGEable? Or
particular member functions as such? I have had zero luck in getting
that to work on a deterministic basis. It would work most of the time,
some other component would change slightly, and then things would break
down. The linker makes no guarantees about the placement of templacized
code and, if it appears multiple times, which section it would be merged
into (ie it is luck of the draw).

I will look at the ntdef.h code, but remember, ntdef.h is shared between
UM and KM components, so the presence of templates does not mean it is
an endorsement for KM.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Sunday, July 31, 2005 12:55 AM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

“Doron Holan” wrote in message
> news:xxxxx@ntdev…
> A file that contains any C++'isms (new, delete, classes) cannot be
> #includeded under the extern “C” directive. So if you are wrapping
your
> C++ headers in extern “C” #include, that needs to be moved out.

Hmmm. I see ntdef.h contains a C++ template definition; this would
qualify
as a C++'ism in my book.

I also noticed the WPP tracing stuff uses a global constructor if you
#include it in a .cpp file, and Microsoft supplied no run-time code to
make
this work (it’s a very small, but very MS specific piece of code).

The last 2 drivers I’ve written contained significant use of C++
features
(multiple inheritance, polymorphism, per class allocator/deallocator,
smart
pointers). I have been totally impressed with how useful this can be,
and
have had almost zero issues caused by it.

I’m not going to be adopting WDF if it’s incompatible with C++.

Does anybody know of a mailing list/newsgroup about using C++ for driver
development? I know here it’s a religious issue, and would rather have
some
constructive conversations and comparison of experiences than debate its
rightness or wrongness.

- Jan


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

> Have you tried to mark any of templated classes as PAGEable? Or

particular member functions as such? I have had zero luck in getting
that to work on a deterministic basis.

I could imagine this is a problem area for some drivers. It’s exactly this
kind of issue I’d love to discuss someplace without the discussion turning
into a religious war. As the last two drivers I’ve written in C++ used tens
of megabytes of non-paged pool, I avoided any issues of controlling code
segment placement by making all code non-pageable. If I were writing a WDM
driver that had to run on very small memory W9x systems, the reduced
flexibility of controlling code placement in C++ might be a serious problem.

Out of curiosity, I looked at a couple drivers on the XP system I’m writing
this message from. The largest driver is the NVidia video driver (.text size
of over 2 Mbytes), and see that less than 2% of the code isn’t resident. The
NTFS driver on the other hand had only 96 kbytes of resident code and over
400 kbytes of paged code. For the TCP.SYS driver, 80% is resident.

I would think some constructive feedback to the DDK compiler group at
Microsoft would be about better control of code segment placement for C++.
Or perhaps it’s a documentation/education issue, and the compiler and linker
already have features that would allow you control.

Controlling the layout of the .SYS file via an external layout file given to
the linker sounds most attractive to me. Sometimes a driver uses platform
neutral code modules which I don’t want to (or can’t) insert MS specific
compiler directives into. In this case, even for a driver totally in C, I
have limited control over code pageability.

  • Jan

If you look at the map you should be able to determine what routines are in
which segment. Sounds like a real pain to double check each one, but low
memory simulation should cause all pagable code out of memory and the blue
screen should give you a hint. I think DriverWorks solved this by always
including a non-paged code directive at the end of each source file. This
forces all added stuff to be put in non-paged memory. This might have
stopped working after VC++ 6.0.

“Jan Bottorff” wrote in message news:xxxxx@ntdev…
>> Have you tried to mark any of templated classes as PAGEable? Or
>> particular member functions as such? I have had zero luck in getting
>> that to work on a deterministic basis.
>
> I could imagine this is a problem area for some drivers. It’s exactly this
> kind of issue I’d love to discuss someplace without the discussion turning
> into a religious war. As the last two drivers I’ve written in C++ used
> tens
> of megabytes of non-paged pool, I avoided any issues of controlling code
> segment placement by making all code non-pageable. If I were writing a WDM
> driver that had to run on very small memory W9x systems, the reduced
> flexibility of controlling code placement in C++ might be a serious
> problem.
>
> Out of curiosity, I looked at a couple drivers on the XP system I’m
> writing
> this message from. The largest driver is the NVidia video driver (.text
> size
> of over 2 Mbytes), and see that less than 2% of the code isn’t resident.
> The
> NTFS driver on the other hand had only 96 kbytes of resident code and over
> 400 kbytes of paged code. For the TCP.SYS driver, 80% is resident.
>
> I would think some constructive feedback to the DDK compiler group at
> Microsoft would be about better control of code segment placement for C++.
> Or perhaps it’s a documentation/education issue, and the compiler and
> linker
> already have features that would allow you control.
>
> Controlling the layout of the .SYS file via an external layout file given
> to
> the linker sounds most attractive to me. Sometimes a driver uses platform
> neutral code modules which I don’t want to (or can’t) insert MS specific
> compiler directives into. In this case, even for a driver totally in C, I
> have limited control over code pageability.
>
> - Jan
>
>
>
>

I found it’s virtually impossible to make templated functions pageable. It’s
not a big problem, as it would be much worse if I couldn’t make them
non-pageable :slight_smile:

Another issue is with inlined functions. The compiler can inline any
function into any one. Say you’ve got non-paged or templated A() that
acquires a spinlock, and paged B(). Now if A is inlined into paged B, you’re
in a trouble. The whole program optimization makes this even worse, as you
don’t get compiler warnings about inlining - the compiler just reuses pieces
of code with jmp’s.

I think microsoft.public.development.device.drives is good enough for the
discussion.

http://www.cristalink.com

“Jan Bottorff” wrote in message news:xxxxx@ntdev…
>> Have you tried to mark any of templated classes as PAGEable? Or
>> particular member functions as such? I have had zero luck in getting
>> that to work on a deterministic basis.
>
> I could imagine this is a problem area for some drivers. It’s exactly this
> kind of issue I’d love to discuss someplace without the discussion turning
> into a religious war. As the last two drivers I’ve written in C++ used
> tens
> of megabytes of non-paged pool, I avoided any issues of controlling code
> segment placement by making all code non-pageable. If I were writing a WDM
> driver that had to run on very small memory W9x systems, the reduced
> flexibility of controlling code placement in C++ might be a serious
> problem.
>
> Out of curiosity, I looked at a couple drivers on the XP system I’m
> writing
> this message from. The largest driver is the NVidia video driver (.text
> size
> of over 2 Mbytes), and see that less than 2% of the code isn’t resident.
> The
> NTFS driver on the other hand had only 96 kbytes of resident code and over
> 400 kbytes of paged code. For the TCP.SYS driver, 80% is resident.
>
> I would think some constructive feedback to the DDK compiler group at
> Microsoft would be about better control of code segment placement for C++.
> Or perhaps it’s a documentation/education issue, and the compiler and
> linker
> already have features that would allow you control.
>
> Controlling the layout of the .SYS file via an external layout file given
> to
> the linker sounds most attractive to me. Sometimes a driver uses platform
> neutral code modules which I don’t want to (or can’t) insert MS specific
> compiler directives into. In this case, even for a driver totally in C, I
> have limited control over code pageability.
>
> - Jan
>
>
>
>

Here’s the thing with the compiler/linker in terms of drivers:

Market share of UM applications which use them: 99%
Market share of KM drivers which use them: 1%

In terms of priorities of new features and priorities, you can see who
wins. With that said, we are getting the compiler folks to listen to
our issues and what we want solved, but it’s a slow process.

D

(looking at the driver via link /dump tells you about code sections but
not about runtime usage. For instance, most of serial.sys is not
pageable, yet the entire drive is paged out if you are not using a COM
port.)

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Jan Bottorff
Sent: Sunday, July 31, 2005 2:30 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] C++ and WDF

Have you tried to mark any of templated classes as PAGEable? Or
particular member functions as such? I have had zero luck in getting
that to work on a deterministic basis.

I could imagine this is a problem area for some drivers. It’s exactly
this
kind of issue I’d love to discuss someplace without the discussion
turning
into a religious war. As the last two drivers I’ve written in C++ used
tens
of megabytes of non-paged pool, I avoided any issues of controlling code
segment placement by making all code non-pageable. If I were writing a
WDM
driver that had to run on very small memory W9x systems, the reduced
flexibility of controlling code placement in C++ might be a serious
problem.

Out of curiosity, I looked at a couple drivers on the XP system I’m
writing
this message from. The largest driver is the NVidia video driver (.text
size
of over 2 Mbytes), and see that less than 2% of the code isn’t resident.
The
NTFS driver on the other hand had only 96 kbytes of resident code and
over
400 kbytes of paged code. For the TCP.SYS driver, 80% is resident.

I would think some constructive feedback to the DDK compiler group at
Microsoft would be about better control of code segment placement for
C++.
Or perhaps it’s a documentation/education issue, and the compiler and
linker
already have features that would allow you control.

Controlling the layout of the .SYS file via an external layout file
given to
the linker sounds most attractive to me. Sometimes a driver uses
platform
neutral code modules which I don’t want to (or can’t) insert MS specific
compiler directives into. In this case, even for a driver totally in C,
I
have limited control over code pageability.

  • Jan

Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

IIRC C++ has a way of saying “please expand these templates just here”.
Then you can use this thing after #pragma code_seg(“PAGE”).

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com

----- Original Message -----
From: “cristalink”
Newsgroups: ntdev
To: “Windows System Software Devs Interest List”
Sent: Monday, August 01, 2005 2:19 AM
Subject: Re:[ntdev] C++ and WDF

> I found it’s virtually impossible to make templated functions pageable. It’s
> not a big problem, as it would be much worse if I couldn’t make them
> non-pageable :slight_smile:
>
> Another issue is with inlined functions. The compiler can inline any
> function into any one. Say you’ve got non-paged or templated A() that
> acquires a spinlock, and paged B(). Now if A is inlined into paged B, you’re
> in a trouble. The whole program optimization makes this even worse, as you
> don’t get compiler warnings about inlining - the compiler just reuses pieces
> of code with jmp’s.
>
> I think microsoft.public.development.device.drives is good enough for the
> discussion.
> –
>
> http://www.cristalink.com
>
>
> “Jan Bottorff” wrote in message news:xxxxx@ntdev…
> >> Have you tried to mark any of templated classes as PAGEable? Or
> >> particular member functions as such? I have had zero luck in getting
> >> that to work on a deterministic basis.
> >
> > I could imagine this is a problem area for some drivers. It’s exactly this
> > kind of issue I’d love to discuss someplace without the discussion turning
> > into a religious war. As the last two drivers I’ve written in C++ used
> > tens
> > of megabytes of non-paged pool, I avoided any issues of controlling code
> > segment placement by making all code non-pageable. If I were writing a WDM
> > driver that had to run on very small memory W9x systems, the reduced
> > flexibility of controlling code placement in C++ might be a serious
> > problem.
> >
> > Out of curiosity, I looked at a couple drivers on the XP system I’m
> > writing
> > this message from. The largest driver is the NVidia video driver (.text
> > size
> > of over 2 Mbytes), and see that less than 2% of the code isn’t resident.
> > The
> > NTFS driver on the other hand had only 96 kbytes of resident code and over
> > 400 kbytes of paged code. For the TCP.SYS driver, 80% is resident.
> >
> > I would think some constructive feedback to the DDK compiler group at
> > Microsoft would be about better control of code segment placement for C++.
> > Or perhaps it’s a documentation/education issue, and the compiler and
> > linker
> > already have features that would allow you control.
> >
> > Controlling the layout of the .SYS file via an external layout file given
> > to
> > the linker sounds most attractive to me. Sometimes a driver uses platform
> > neutral code modules which I don’t want to (or can’t) insert MS specific
> > compiler directives into. In this case, even for a driver totally in C, I
> > have limited control over code pageability.
> >
> > - Jan
> >
> >
> >
> >
>
>
>
> —
> Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256
>
> You are currently subscribed to ntdev as: xxxxx@storagecraft.com
> To unsubscribe send a blank email to xxxxx@lists.osr.com