Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the host
process (WudfHost.exe) throws the exceptions as below. Any suggestions on
how I might debug this better? Any suggestions on using winsock within a
UMDF driver? I’ve been around the block on this one a few times… using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols loaded.

…winsock correctly initialized, bound and connected at this point. Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully

Have you attached a debugger to the service, and enabled first-chance exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m ignorant of how the WudfHost.exe process is created, but I assume it is either directly launched by the Service Control Manager, or is launched indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process, and you’ll need to set up the debugger so that it halts on first-chance exceptions, for the set of exceptions that you’re interested in. I would recommend using the “Image File Execution Options” way to enable automatically launching a process under a debugger. If you search the NTDEV archives, I posted a few long-ish messages on how to do this. Long story short, go to “HKLM\Software\Microsoft\Windows NT\CurrentVersion\Image File Execution Options”, and create a subkey named “WudfHost.exe”. In that subkey, create a REG_SZ value named “Debugger” whose value is something like “c:\dbg\cdb.exe -server tcp:port=4000”. CreateProcess looks for this registry string when it launches a process, and if the “Debugger” value is there, it will concatenate the “Debugger” string with the original command line, and execute that process instead. This allows the debugger to be launched, no matter how the process in question is launched. The only limitation to this technique is that you can only choose which processes to launch under a debugger based on the filename of the executable. So if you need to debug only one instance of foo.exe, you need to choose a different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled. You can do this by modifying the command-line that you pass to cdb.exe. Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace “vcpp” with any other exception, either using the names or hex values of the exceptions. (This is exactly equivalent to “sxe vcpp” from within the debugger. Read the “Controlling Exceptions and Events” page in debugger.chm for more info.) You’ll need to add this before the -server statement.

Next, choose whether you want the process to launch without waiting for you to connect to the debugger and resume, or whether you do want it to wait. If you want it to run without waiting, use “-g”. And similarly, use “-G” to allow the process to exit without the debugger interfering. So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a debugger. If you need help getting this working properly, send me mail off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the host
process (WudfHost.exe) throws the exceptions as below. Any suggestions on
how I might debug this better? Any suggestions on using winsock within a
UMDF driver? I’ve been around the block on this one a few times… using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols loaded.

…winsock correctly initialized, bound and connected at this point. Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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

Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the problem.
I can catch it and view the call stack all the way down to the kernal where
it occurs. I’m assuming that if I use windbg and the symbol server I should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is there
some fundamental threading issue or cs/ds issue that I’m forgetting about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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

Random silly question, you are initializing winsock via WSAStartup
before using it right?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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

>>Random silly question, you are initializing winsock via WSAStartup

>before using it right?

Yes, the winsock code was extracted from a previously running application.
The startup, bind and connect all work flawlessly, its just the send() that
creates the exceptions. In fact send() returns successfully, but it causes
the exceptions elsewhere in WUDFHost.exe.

// Startup socket sub-system.

WSADATA wsaData;

WORD wVersion = MAKEWORD( 2, 0 );

WSAStartup( wVersion, &wsaData );

m_bConnected = FALSE;

int nError;

// Ensure socket is closed

if(m_hSocket != INVALID_SOCKET)

{

closesocket(m_hSocket);

}

// Create a socket

m_hSocket = socket(AF_INET, SOCK_STREAM, 0);

if(m_hSocket == INVALID_SOCKET)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to create socket (%d).\n", nError);

return FALSE;

}

//

// Set socket options

//

int nValue = 1;

if(setsockopt (m_hSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &nValue,
sizeof(nValue)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket options (%d).\n", nError);

return FALSE;

}

//

// Set Packet Size

//

nValue = 1024;

if((setsockopt(m_hSocket, SOL_SOCKET, SO_RCVBUF, (char *) &nValue,
sizeof(nValue)) )

|| (setsockopt(m_hSocket, SOL_SOCKET, SO_SNDBUF, (char *) &nValue,
sizeof(nValue)) ))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket buffer sizes (%d).\n", nError);

return FALSE;

}

//

// Bind Address info to socket

//

SOCKADDR_IN stAddr;

stAddr.sin_family = AF_INET;

stAddr.sin_port = htons(static_cast(m_nPortNumber));

stAddr.sin_addr.s_addr = ADDR_ANY;

if(bind(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to bind socket (%d).\n", nError);

return FALSE;

}

//

// Ready to connect…

stAddr.sin_addr.s_addr = inet_addr(“192.168.100.101”);

int nReturn = connect(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr));

if(nReturn == SOCKET_ERROR)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to connect socket (%d).\n", nError);

return FALSE;

}

// Connected

m_bConnected = TRUE;

return TRUE;

} // Connect()

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Random silly question, you are initializing winsock via WSAStartup
before using it right?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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

Ok, so what are the exceptions? What’s the call stack? It seems relevant.

In the short term, if your app is using TCP, you can use ReadFile / WriteFile instead of recv / send. AFD will translate these into the equivalent of send / recv. Can’t use with UDP, though, in general.

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 3:00 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

>Random silly question, you are initializing winsock via WSAStartup
>before using it right?

Yes, the winsock code was extracted from a previously running application.
The startup, bind and connect all work flawlessly, its just the send() that
creates the exceptions. In fact send() returns successfully, but it causes
the exceptions elsewhere in WUDFHost.exe.

// Startup socket sub-system.

WSADATA wsaData;

WORD wVersion = MAKEWORD( 2, 0 );

WSAStartup( wVersion, &wsaData );

m_bConnected = FALSE;

int nError;

// Ensure socket is closed

if(m_hSocket != INVALID_SOCKET)

{

closesocket(m_hSocket);

}

// Create a socket

m_hSocket = socket(AF_INET, SOCK_STREAM, 0);

if(m_hSocket == INVALID_SOCKET)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to create socket (%d).\n", nError);

return FALSE;

}

//

// Set socket options

//

int nValue = 1;

if(setsockopt (m_hSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &nValue,
sizeof(nValue)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket options (%d).\n", nError);

return FALSE;

}

//

// Set Packet Size

//

nValue = 1024;

if((setsockopt(m_hSocket, SOL_SOCKET, SO_RCVBUF, (char *) &nValue,
sizeof(nValue)) )

|| (setsockopt(m_hSocket, SOL_SOCKET, SO_SNDBUF, (char *) &nValue,
sizeof(nValue)) ))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket buffer sizes (%d).\n", nError);

return FALSE;

}

//

// Bind Address info to socket

//

SOCKADDR_IN stAddr;

stAddr.sin_family = AF_INET;

stAddr.sin_port = htons(static_cast(m_nPortNumber));

stAddr.sin_addr.s_addr = ADDR_ANY;

if(bind(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to bind socket (%d).\n", nError);

return FALSE;

}

//

// Ready to connect…

stAddr.sin_addr.s_addr = inet_addr(“192.168.100.101”);

int nReturn = connect(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr));

if(nReturn == SOCKET_ERROR)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to connect socket (%d).\n", nError);

return FALSE;

}

// Connected

m_bConnected = TRUE;

return TRUE;

} // Connect()

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Random silly question, you are initializing winsock via WSAStartup
before using it right?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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


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

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

So it sounds to me like you’re corrupting memory.

We have some winsock based drivers internally, but we haven’t had time
to create a sample for publishing unfortunately.

I think that getting windbg/cdb hooked up and using the symbol server to
get a real stack trace of the first chance exception would be a first
good bet.

If you comment out the send does the host not become corrupt?

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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

I was able to catch the exception within windbg. The exception doesn’t
happen within the thread calling winsock send(), but rather some other
thread.

I’m not sure if you can deduce much from this… I can’t.

Command window when stepping over winsock send() call…

WUDFEchoDriver!CNetLink::Send+0x24:
008b3c04 6a00 push 0x0
0:002> p
ModLoad: 77fe0000 77ff1000 C:\WINDOWS\System32\Secur32.dll
(670.680): C++ EH exception - code e06d7363 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0071f1dc ebx=0071f34c ecx=00000000 edx=30332f00 esi=0071f26c
edi=0071f26c
eip=7c812a5b esp=0071f1d8 ebp=0071f22c iopl=0 nv up ei pl nz na po
nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000
efl=00000206
kernel32!RaiseException+0x53:
7c812a5b 5e pop esi
*** WARNING: Unable to verify checksum for C:\WINDOWS\System32\winsflt.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for
C:\WINDOWS\System32\winsflt.dll -

----- CALL STACK AFTER EXCEPTION IS CAUGHT -----

kernel32!RaiseException+0x53
WARNING: Stack unwind information not available. Following frames may be
wrong.
winsflt!WSPStartup+0x54899
winsflt!WSPStartup+0xc4f1
winsflt!WSPStartup+0xa3a3
winsflt+0x10a96
ntdll!RtlpFreeToHeapLookaside+0x22
ntdll!RtlFreeHeap+0x1e9
winsflt!WSPStartup+0x55ced
ntdll!RtlFreeHeap+0x647

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
So it sounds to me like you’re corrupting memory.

We have some winsock based drivers internally, but we haven’t had time
to create a sample for publishing unfortunately.

I think that getting windbg/cdb hooked up and using the symbol server to
get a real stack trace of the first chance exception would be a first
good bet.

If you comment out the send does the host not become corrupt?

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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

Thanks for the information. I included some exception information in another
post you can take a look at. I was however a little more interested in your
comment about using WriteFile(). Are you saying I can use the SOCKET handle
with WriteFile(), or, are you saying I need to create a named picpe or
something and then use WriteFile(). I tried the SOCKET handle, and as
expected WriteFile() returned ERROR_INVALID PARAMETER.

If you could explain this a little more, it might help me work around this
send() issue I’m having.

I wasn’t aware I could use
“Arlie Davis” wrote in message
news:xxxxx@ntdev…
Ok, so what are the exceptions? What’s the call stack? It seems relevant.

In the short term, if your app is using TCP, you can use ReadFile /
WriteFile instead of recv / send. AFD will translate these into the
equivalent of send / recv. Can’t use with UDP, though, in general.

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 3:00 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

>>Random silly question, you are initializing winsock via WSAStartup
>>before using it right?

Yes, the winsock code was extracted from a previously running application.
The startup, bind and connect all work flawlessly, its just the send() that
creates the exceptions. In fact send() returns successfully, but it causes
the exceptions elsewhere in WUDFHost.exe.

// Startup socket sub-system.

WSADATA wsaData;

WORD wVersion = MAKEWORD( 2, 0 );

WSAStartup( wVersion, &wsaData );

m_bConnected = FALSE;

int nError;

// Ensure socket is closed

if(m_hSocket != INVALID_SOCKET)

{

closesocket(m_hSocket);

}

// Create a socket

m_hSocket = socket(AF_INET, SOCK_STREAM, 0);

if(m_hSocket == INVALID_SOCKET)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to create socket (%d).\n", nError);

return FALSE;

}

//

// Set socket options

//

int nValue = 1;

if(setsockopt (m_hSocket, SOL_SOCKET, SO_REUSEADDR, (char *) &nValue,
sizeof(nValue)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket options (%d).\n", nError);

return FALSE;

}

//

// Set Packet Size

//

nValue = 1024;

if((setsockopt(m_hSocket, SOL_SOCKET, SO_RCVBUF, (char *) &nValue,
sizeof(nValue)) )

|| (setsockopt(m_hSocket, SOL_SOCKET, SO_SNDBUF, (char *) &nValue,
sizeof(nValue)) ))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to set socket buffer sizes (%d).\n", nError);

return FALSE;

}

//

// Bind Address info to socket

//

SOCKADDR_IN stAddr;

stAddr.sin_family = AF_INET;

stAddr.sin_port = htons(static_cast(m_nPortNumber));

stAddr.sin_addr.s_addr = ADDR_ANY;

if(bind(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr)))

{

nError = WSAGetLastError();

CDebug::error(L"Failed to bind socket (%d).\n", nError);

return FALSE;

}

//

// Ready to connect…

stAddr.sin_addr.s_addr = inet_addr(“192.168.100.101”);

int nReturn = connect(m_hSocket, (SOCKADDR *) &stAddr, sizeof(stAddr));

if(nReturn == SOCKET_ERROR)

{

nError = WSAGetLastError();

CDebug::error(L"Failed to connect socket (%d).\n", nError);

return FALSE;

}

// Connected

m_bConnected = TRUE;

return TRUE;

} // Connect()

“Doron Holan” wrote in message
news:xxxxx@ntdev…
Random silly question, you are initializing winsock via WSAStartup
before using it right?

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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


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

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

Winsflt.dll isn’t a part of the Windows OS. An internet search I did points from several places to a “Puresight Internet content filter” www.puresight.com.

You might also check for any version info of the dll with Explorer to see if that checks out. Not always there, and not always useful, but when it is and has a company name, etc, it does give some warm fuzzies.

Hopefully, that is the source of this binary and someone there can tell you why the exception happened?

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 3:02 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

I was able to catch the exception within windbg. The exception doesn’t
happen within the thread calling winsock send(), but rather some other
thread.

I’m not sure if you can deduce much from this… I can’t.

Command window when stepping over winsock send() call…

WUDFEchoDriver!CNetLink::Send+0x24:
008b3c04 6a00 push 0x0
0:002> p
ModLoad: 77fe0000 77ff1000 C:\WINDOWS\System32\Secur32.dll
(670.680): C++ EH exception - code e06d7363 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0071f1dc ebx=0071f34c ecx=00000000 edx=30332f00 esi=0071f26c
edi=0071f26c
eip=7c812a5b esp=0071f1d8 ebp=0071f22c iopl=0 nv up ei pl nz na po
nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000
efl=00000206
kernel32!RaiseException+0x53:
7c812a5b 5e pop esi
*** WARNING: Unable to verify checksum for C:\WINDOWS\System32\winsflt.dll
*** ERROR: Symbol file could not be found. Defaulted to export symbols for
C:\WINDOWS\System32\winsflt.dll -

----- CALL STACK AFTER EXCEPTION IS CAUGHT -----

kernel32!RaiseException+0x53
WARNING: Stack unwind information not available. Following frames may be
wrong.
winsflt!WSPStartup+0x54899
winsflt!WSPStartup+0xc4f1
winsflt!WSPStartup+0xa3a3
winsflt+0x10a96
ntdll!RtlpFreeToHeapLookaside+0x22
ntdll!RtlFreeHeap+0x1e9
winsflt!WSPStartup+0x55ced
ntdll!RtlFreeHeap+0x647

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
So it sounds to me like you’re corrupting memory.

We have some winsock based drivers internally, but we haven’t had time
to create a sample for publishing unfortunately.

I think that getting windbg/cdb hooked up and using the symbol server to
get a real stack trace of the first chance exception would be a first
good bet.

If you comment out the send does the host not become corrupt?

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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


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

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

Last time I dealt with WinSock internals, WriteFile and ReadFile worked on TCP sockets. This is because socket handles are exposed to user-mode apps as file handles by MSAFD.SYS, which is a sort of proxy for TDI. MSAFD handles IRP_MJ_READ / IRP_MJ_WRITE on TCP/IP sockets, and handles them in the “obvious” way.

Now, I know quite a lot of changes went into the Vista TCP/IP stack, so this may no longer be true. What kernel are you working on? I’m pretty sure this is true for NT4, W2K, and XP. I’m not at work right now, so I can’t verify it, but I can check it out tomorrow. I can’t vouch for Vista – I’m simply ignorant of WinSock / TCP/IP internals on Vista.

In other words, yes, you should be able to cast the SOCKET value to a HANDLE, and then call ReadFile and WriteFile – at least on the kernels that I mentioned. (If this has changed, hoooo boy do I need to catch up on how the WinSock stack has changed on Vista.) Nearly all of the standard WinSock calls boil down to either 1) changes to in-process memory, or 2) DeviceIoControl calls on the file handle exposed by MSAFD.


From: xxxxx@lists.osr.com [xxxxx@lists.osr.com] On Behalf Of Greg Thomson [xxxxx@newageautomation.com]
Sent: Thursday, January 18, 2007 5:52 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Re:Problems using winsock within UMDF driver

Thanks for the information. I included some exception information in another
post you can take a look at. I was however a little more interested in your
comment about using WriteFile(). Are you saying I can use the SOCKET handle
with WriteFile(), or, are you saying I need to create a named picpe or
something and then use WriteFile(). I tried the SOCKET handle, and as
expected WriteFile() returned ERROR_INVALID PARAMETER.

If you could explain this a little more, it might help me work around this
send() issue I’m having.

I wasn’t aware I could use
“Arlie Davis” wrote in message
news:xxxxx@ntdev…
Ok, so what are the exceptions? What’s the call stack? It seems relevant.

In the short term, if your app is using TCP, you can use ReadFile /
WriteFile instead of recv / send. AFD will translate these into the
equivalent of send / recv. Can’t use with UDP, though, in general.

Thanks Bob,

I traced the DLL to my ISP’s firewall/virus protection software… F-Secure
(www.f-secure.com).

I’ll have to do some more investigation to figure out whats going on here.

“Bob Kjelgaard” wrote in message
news:xxxxx@ntdev…
Winsflt.dll isn’t a part of the Windows OS. An internet search I did points
from several places to a “Puresight Internet content filter”
www.puresight.com.

You might also check for any version info of the dll with Explorer to see if
that checks out. Not always there, and not always useful, but when it is
and has a company name, etc, it does give some warm fuzzies.

Hopefully, that is the source of this binary and someone there can tell you
why the exception happened?

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 3:02 PM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

I was able to catch the exception within windbg. The exception doesn’t
happen within the thread calling winsock send(), but rather some other
thread.

I’m not sure if you can deduce much from this… I can’t.

Command window when stepping over winsock send() call…

WUDFEchoDriver!CNetLink::Send+0x24:
008b3c04 6a00 push 0x0
0:002> p
ModLoad: 77fe0000 77ff1000 C:\WINDOWS\System32\Secur32.dll
(670.680): C++ EH exception - code e06d7363 (first chance)
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0071f1dc ebx=0071f34c ecx=00000000 edx=30332f00 esi=0071f26c
edi=0071f26c
eip=7c812a5b esp=0071f1d8 ebp=0071f22c iopl=0 nv up ei pl nz na po
nc
cs=001b ss=0023 ds=0023 es=0023 fs=003b gs=0000
efl=00000206
kernel32!RaiseException+0x53:
7c812a5b 5e pop esi
WARNING: Unable to verify checksum for C:\WINDOWS\System32\winsflt.dll
ERROR: Symbol file could not be found. Defaulted to export symbols for
C:\WINDOWS\System32\winsflt.dll -

----- CALL STACK AFTER EXCEPTION IS CAUGHT -----

kernel32!RaiseException+0x53
WARNING: Stack unwind information not available. Following frames may be
wrong.
winsflt!WSPStartup+0x54899
winsflt!WSPStartup+0xc4f1
winsflt!WSPStartup+0xa3a3
winsflt+0x10a96
ntdll!RtlpFreeToHeapLookaside+0x22
ntdll!RtlFreeHeap+0x1e9
winsflt!WSPStartup+0x55ced
ntdll!RtlFreeHeap+0x647

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
So it sounds to me like you’re corrupting memory.

We have some winsock based drivers internally, but we haven’t had time
to create a sample for publishing unfortunately.

I think that getting windbg/cdb hooked up and using the symbol server to
get a real stack trace of the first chance exception would be a first
good bet.

If you comment out the send does the host not become corrupt?

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 11:05 AM
To: Windows System Software Devs Interest List
Subject: Re:[ntdev] Problems using winsock within UMDF driver

Thanks Peter,

Debugging and catching the first-chance exception isn’t really the
problem.
I can catch it and view the call stack all the way down to the kernal
where
it occurs. I’m assuming that if I use windbg and the symbol server I
should
be able to translate the call-stack into something useful.

My more basic question however is are there any UDMF/winsock samples
around?
Has anyone successfully created a socket within a UMDF driver. And then
finally, because my driver implementation is within a DLL (.SYS) is
there
some fundamental threading issue or cs/ds issue that I’m forgetting
about
when coding up this implementation and making winsock calls (ws2_32.dll)

Sorry, I’m a newbiew to UMDF, but the winsock code I’m using has been
running fine within a Service for a long time now.

Any ideas or suggestions would be greatly appreicated.

Greg,

“Peter Wieland” wrote in message
news:xxxxx@ntdev…
Attaching a debugger the UMDF host process is much easier than this & is
documented in the WDK - see
http://msdn2.microsoft.com/en-us/library/aa510991.aspx. Set the delay
for 30 seconds, enable your device, then run “windbg -pn wudfhost.exe”
and you’ll be attached to the host.

Set your symbol path to include the PDB files for your driver, then set
an unresolved breakpoint (bu) on one of your driver routines (bu
mydriver!myclass::OnDeviceAdd - replace mydriver & myclass with
appropriate names).

‘g’ twice (once because the debugger stops the process when it attaches,
once because UMDF is waiting for a debugger to attach in this case and
it breaks in when it spots one).

Now you’re in your driver code & can set source level breakpoints if you
want.

-p

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Arlie Davis
Sent: Wednesday, January 17, 2007 9:57 PM
To: Windows System Software Devs Interest List
Subject: RE: [ntdev] Problems using winsock within UMDF driver

Have you attached a debugger to the service, and enabled first-chance
exceptions, and had a chance to examine this exception when it occurs?

I realize debugging a service process can be difficult. And I’m
ignorant of how the WudfHost.exe process is created, but I assume it is
either directly launched by the Service Control Manager, or is launched
indirectly by a UMDF service process.

In either case, you’ll need to get a debugger attached to the process,
and you’ll need to set up the debugger so that it halts on first-chance
exceptions, for the set of exceptions that you’re interested in. I
would recommend using the “Image File Execution Options” way to enable
automatically launching a process under a debugger. If you search the
NTDEV archives, I posted a few long-ish messages on how to do this.
Long story short, go to “HKLM\Software\Microsoft\Windows
NT\CurrentVersion\Image File Execution Options”, and create a subkey
named “WudfHost.exe”. In that subkey, create a REG_SZ value named
“Debugger” whose value is something like “c:\dbg\cdb.exe -server
tcp:port=4000”. CreateProcess looks for this registry string when it
launches a process, and if the “Debugger” value is there, it will
concatenate the “Debugger” string with the original command line, and
execute that process instead. This allows the debugger to be launched,
no matter how the process in question is launched. The only limitation
to this technique is that you can only choose which processes to launch
under a debugger based on the filename of the executable. So if you
need to debug only one instance of foo.exe, you need to choose a
different means to debug.

Next, you’ll want to make sure that first-chance exceptions are enabled.
You can do this by modifying the command-line that you pass to cdb.exe.
Add “-xe vcpp” to enable exceptions for the VC++ exception, or replace
“vcpp” with any other exception, either using the names or hex values of
the exceptions. (This is exactly equivalent to “sxe vcpp” from within
the debugger. Read the “Controlling Exceptions and Events” page in
debugger.chm for more info.) You’ll need to add this before the -server
statement.

Next, choose whether you want the process to launch without waiting for
you to connect to the debugger and resume, or whether you do want it to
wait. If you want it to run without waiting, use “-g”. And similarly,
use “-G” to allow the process to exit without the debugger interfering.
So, the full “Debugger” command-line might resemble:

c:\dbg\cdb.exe -server tcp:port=4000 -xe vcpp -g -G

(NB: The order of arguments here is significant. -server must be
first.) Then, start the service, and connect to the debugger:

c:\dbg\windbg -remote tcp:port=4000,server=127.0.0.1

This, or some variant of it, should let you catch the exception under a
debugger. If you need help getting this working properly, send me mail
off-list and I’ll do what I can to help you get set up.

– arlie

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Greg Thomson
Sent: Thursday, January 18, 2007 12:38 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Problems using winsock within UMDF driver

I’m attempting to perform a winsock send() within a UMDF driver and the
host
process (WudfHost.exe) throws the exceptions as below. Any suggestions
on
how I might debug this better? Any suggestions on using winsock within
a
UMDF driver? I’ve been around the block on this one a few times…
using
WSASend() instead of send(), executing winsock code in a separate thread
outside the UMDF callbacks, etc. Everything seems to yield the same
exceptions…

Debug Output… (driver based on echo sample)

SerialHub: CMyQueue::OnWrite

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\winsflt.dll’, Binary was not
built with debug information.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shlwapi.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\shell32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded
‘C:\WINDOWS\WinSxS\x86_Microsoft.Windows.Common-Controls_6595b64144ccf1d
f_6.0.2600.2982_x-ww_ac3f9c03\comctl32.dll’,
No symbols loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\comctl32.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\mswsock.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\hnetcfg.dll’, No symbols
loaded.

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\wshtcpip.dll’, No symbols
loaded.

The thread ‘Win32 Thread’ (0x68c) has exited with code 0 (0x0).

‘WudfHost.exe’: Loaded ‘C:\WINDOWS\system32\secur32.dll’, No symbols
loaded.

…winsock correctly initialized, bound and connected at this point.
Then a
send() is attempted…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

First-chance exception at 0x7c812a5b in WudfHost.exe: Microsoft C++
exception: exception at memory location 0x0071f2ac…

…the send() function sucessfully completes as below, but the host
eventually becomes corrupt…

SerialHub: 7 character(s) sent successfully


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

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


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

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


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

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


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

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