global variable in functional driver

I want to apply ioctl for reading and writing PCI Card in a functional driver. I have some question:

  1. Since i want to read the PCI configuration file using PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a functional driver? Is there any negative effect to this? Or maybe there are other way to do?
  2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this tool or i should install WDK? And, can we use insdrv and debugview for testing and debuging or any other tool recommend?
    ?
    Regards,
    Sofian

While global variables work fine in a driver for the right things, this is
not one of them. Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them. In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used. Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4376 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

As far as tools for debugging, you probably want to take a look at windbg, which the WIn7 WDK also installs.

You can find the latest (Win7) WDK on msdn.microsoft.com (definitely) and (perhaps still) on connect.microsoft.com.

DDKBUILD is batch file that allows one to easily use VS for editing, but still use the WDK build environment.

Good luck,

mm

thank’s for the advice.
Btw, if i create a functional driver that implement ioctl. How can i debug my program?

— On Fri, 8/28/09, Don Burn wrote:

From: Don Burn
Subject: Re:[ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 8:53 AM

While global variables work fine in a driver for the right things, this is
not one of them.? Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them.? In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used.? Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4376 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

Get Windbg and have either two computers or two virtual machines. Any
other approach to debugging is just a waste of time.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
thank’s for the advice.
Btw, if i create a functional driver that implement ioctl. How can i debug
my program?

— On Fri, 8/28/09, Don Burn wrote:

From: Don Burn
Subject: Re:[ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 8:53 AM

While global variables work fine in a driver for the right things, this is
not one of them. Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them. In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used. Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Information from ESET NOD32 Antivirus, version of virus signature
database 4377 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4377 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

You can use either Visual Studio to debug your program or WinDbg.

—Mark Cariddi
OSR, Open Systems Resources, Inc.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Friday, August 28, 2009 10:13 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] global variable in functional driver

thank’s for the advice.
Btw, if i create a functional driver that implement ioctl. How can i debug my program?

— On Fri, 8/28/09, Don Burn wrote:

From: Don Burn
Subject: Re:[ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 8:53 AM
While global variables work fine in a driver for the right things, this is
not one of them.? Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them.? In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used.? Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4376 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

If i use WinDbg, it means we can use one computer, right? But, it means we have to load the driver first (install the driver)? and how to debug the ioctl code then?

— On Fri, 8/28/09, Mark Cariddi wrote:

From: Mark Cariddi
Subject: RE: [ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 10:16 AM

You can use either Visual Studio to debug your program or WinDbg.

—Mark Cariddi
OSR, Open Systems Resources, Inc.

From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Friday, August 28, 2009 10:13 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] global variable in functional driver

thank’s for the advice.
Btw, if i create a functional driver that implement ioctl. How can i debug my program?

— On Fri, 8/28/09, Don Burn wrote:

From: Don Burn
Subject: Re:[ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 8:53 AM
While global variables work fine in a driver for the right things, this is
not one of them.? Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them.? In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used.? Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4376 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

No WinDBG uses one computer for test and one to run the debugger. On the
debugger system you set a breakpoint at DriverEntry in your driver, this
will be a deferred breakpoint since the driver is not loaded. You then load
the driver on the test machine, and the debugger will stop the system at you
DebugEntry so you can start debugging and allow you to place other
breakpoints as needed.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
If i use WinDbg, it means we can use one computer, right? But, it means we
have to load the driver first (install the driver)? and how to debug the
ioctl code then?

— On Fri, 8/28/09, Mark Cariddi wrote:

From: Mark Cariddi
Subject: RE: [ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 10:16 AM

You can use either Visual Studio to debug your program or WinDbg.

—Mark Cariddi
OSR, Open Systems Resources, Inc.

From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of sahrizal sofian
Sent: Friday, August 28, 2009 10:13 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] global variable in functional driver

thank’s for the advice.
Btw, if i create a functional driver that implement ioctl. How can i debug
my program?

— On Fri, 8/28/09, Don Burn wrote:

From: Don Burn
Subject: Re:[ntdev] global variable in functional driver
To: “Windows System Software Devs Interest List”
Date: Friday, August 28, 2009, 8:53 AM
While global variables work fine in a driver for the right things, this is
not one of them. Your driver may be used for more than one device, but if
you used a global variable you would only have space for one and no way to
destinguish them. In a WDM driver this is stuff that should be in the
device extension, in KMDF it would go in a context of the device object.

For KMDF you want the WDK, and in general the DDK is obsolete and should not
be used. Go with the WDK and get Mark Roddy’s DDKBUILD from
http://www.hollistech.com/ to hide some of the obnoxious behavior introduced
with the release of the Windows 7 WDK.


Don Burn (MVP, Windows DKD)
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

“sahrizal sofian” wrote in message
news:xxxxx@ntdev…
I want to apply ioctl for reading and writing PCI Card in a functional
driver. I have some question:
1. Since i want to read the PCI configuration file using
PCI_BUS_INTERFACE_STANDARD, is it okay to declare a global varible in a
functional driver? Is there any negative effect to this? Or maybe there are
other way to do?
2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this
tool or i should install WDK? And, can we use insdrv and debugview for
testing and debuging or any other tool recommend?

Regards,
Sofian

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature
database 4376 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

— NTDEV is sponsored by OSR For our schedule of WDF, WDM, debugging and
other seminars visit: http://www.osr.com/seminars To unsubscribe, visit the
List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer


NTDEV is sponsored by OSR

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at
http://www.osronline.com/page.cfm?name=ListServer

Information from ESET NOD32 Antivirus, version of virus signature
database 4377 (20090828)


The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Information from ESET NOD32 Antivirus, version of virus signature database 4377 (20090828)

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

No, you need two computers to use windbg for kd. If you’re writing a software only driver, you can use vmware workstation/hyper-v, but that doesn’t sound like the case for you.

Regarding how to debug, you’re at the beginning of a step learning curve, one which you have to climb on your own.

There’s a word document called ‘kernel_debugging_tutorial.doc’ in the root of the windbg installation that describes how to get started. I really don’t know whether it’s good, bad or other, but it’s the only place that I can tell you start.

Good luck,

mm

you do not need to declare global variable. but create PCI_BUS_INTERFACE structure into Device Extension which is non paged memory.and then you can use it whenever you want.

> is it okay to declare a global variable in a functional driver? Is there
any negative effect to this?

One effect is you will get a lot of replies rather critical of your
programming style. MOST uses of global variable in drivers I would be
critical of, although there are a few valid uses like:

  1. global flag for controlling debugging output (useful so you don’t have to
    pass it as a parameter)
  2. roots for global data structures used to share specific data between all
    device instances for a driver (although if you know the driver object you
    can walk the list of all associated devices too)
  3. pointer to the driver object or driver global configuration data
  4. statistical/performance data that applies to ALL instances
  5. data that you will need at driver unload time

Just from a programming idealist viewpoint, ALL globals are bad, but when I
put on my pragmatic cap have to accept there are a few times you have no
other option. I could pretty easily argue there should be at most 1 global
variable, a structure (or perhaps pointer to a structure) named something
like Globals. I’d much rather see code with names like Globals.someVar than
just have code access someVar and let you figure out its global. The
generated code I believe will be identical, since the address is fixed.

Global variables also are real different than static variables, even though
you can usually replace a static with a global, it’s better if you don’t.

Jan

>2. Regarding KDMF. I have installed winddk. Can we build a KDMF with this tool or i should install

WDK?

Yes. WinDDK is obsolete.

If you can afford dropping w2k support, use the Win7 RTM WDK, otherwise, use 6001.18002


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com