Porting from XP to 2k, ZwOpenFile/ZwCreatFile causes REBOOT on 2k :( HELP ME!

Porting from XP to 2k, ZwOpenFile/ZwCreatFile causes REBOOT on 2k :( HELP ME!

Post by Greg » Tue, 22 Oct 2002 18:07:26



Hi!

I try to port my WDM XP driver to Win2k and everything works well on 2k too except ZwOpenFile/ZwCreatFile.
I have 128 files in a temp folder which I have to read into the memory. It works 100% on XP. (files are: \WINNT\MYTMP\f0 .... f127)
If I load only one of these files (doesn't matter which one), it works well even on Win2000. ...but if I try to load all of my 128 temp files (in a simple "for" loop) it only works on XP and reboots the machine on 2k.

My driver is an UART (dmus) driver and the temp file loader function is called on UART::NewStream().

This is my code:
(it is called once or even 128 times after each other with the parameter "ix" which is the temp file number (example: ix = 123 -> filename = "f123")

 TP_ex pex;
 UCHAR  a;
 PPt  p;

 HANDLE    hFile;
 NTSTATUS   status;
 OBJECT_ATTRIBUTES attrs;
 IO_STATUS_BLOCK  iostatus;

 //#define PATH  L"\\DosDevices\\E:\\WINNT\\MYTMP\\t"
 #define PATH  L"\\SystemRoot\\MYTMP\\t"            //it doesn't matter which path I use, it still works on XP and crashes on 2k when I load 128 files at once..

 UNICODE_STRING  usPath;
 UNICODE_STRING  usFn;
 UNICODE_STRING      linkDigits;
 WCHAR    linkDigitsBuffer[40];
 WCHAR    pathbuff[255];

 #if (DBG)
  PEXCEPTION_POINTERS Ep;
  _DbgPrintF(DEBUGLVL_TERSE, ("LoadTempFile is running at level=%x", KeGetCurrentIrql()));     // It always reports that it's running at PASSIVE_LEVEL, so it's OK.
 #endif

  RtlInitUnicodeString(&usPath, PATH);

  linkDigits.Length = 0;
  linkDigits.MaximumLength = 40;
  linkDigits.Buffer = linkDigitsBuffer;
  status = RtlIntegerToUnicodeString((ULONG)ix, 10, &linkDigits);
  if (status == STATUS_SUCCESS) {
   usFn.Length = 0;
   usFn.MaximumLength = sizeof(pathbuff);
   usFn.Buffer = pathbuff;
   RtlZeroMemory(usFn.Buffer, usFn.MaximumLength);
   status = RtlAppendUnicodeStringToString(&usFn, &usPath);

   if (status == STATUS_SUCCESS) {
    status = RtlAppendUnicodeStringToString(&usFn, &linkDigits);
    if (status == STATUS_SUCCESS) {
     RtlZeroMemory(&attrs, sizeof(attrs));
     InitializeObjectAttributes(&attrs, &usFn, OBJ_CASE_INSENSITIVE, NULL, NULL);

     //this is the old version:
     //status = ZwOpenFile(&hFile, STANDARD_RIGHTS_READ | FILE_READ_DATA, &attrs, &iostatus, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE);

     //this is the current version, but it still causes system reboot on Win2k loading 128 files...
     status = ZwCreateFile(
        &hFile,
        GENERIC_READ | SYNCHRONIZE,
        &attrs,
        &iostatus,
        0,
        FILE_ATTRIBUTE_NORMAL,
        0,
        FILE_OPEN,
        FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT,
        NULL,
        0
      );

     if (status == STATUS_SUCCESS) {
      RtlZeroMemory(&pex, sizeof(TP_ex));
      status = ZwReadFile(hFile, NULL, NULL, NULL, &iostatus, &pex, sizeof(TP_ex), NULL, NULL);

      .....
      .....
      .....

thanx,
greg1x

 
 
 

Porting from XP to 2k, ZwOpenFile/ZwCreatFile causes REBOOT on 2k :( HELP ME!

Post by Kusha » Wed, 23 Oct 2002 00:10:48


Hi,
Did you check whether this is a problem with IRQL at which this code runs?
(ZwCreateFile, ZwReadFile should be executed at passive level.) you can try
KeGetCurrentIrql to check the Irql.

regards,
Kushal


Hi!

I try to port my WDM XP driver to Win2k and everything works well on 2k too
except ZwOpenFile/ZwCreatFile.
I have 128 files in a temp folder which I have to read into the memory. It
works 100% on XP. (files are: \WINNT\MYTMP\f0 .... f127)
If I load only one of these files (doesn't matter which one), it works well
even on Win2000. ...but if I try to load all of my 128 temp files (in a
simple "for" loop) it only works on XP and reboots the machine on 2k.

My driver is an UART (dmus) driver and the temp file loader function is
called on UART::NewStream().

This is my code:
(it is called once or even 128 times after each other with the parameter
"ix" which is the temp file number (example: ix = 123 -> filename = "f123")

 TP_ex pex;
 UCHAR  a;
 PPt  p;

 HANDLE    hFile;
 NTSTATUS   status;
 OBJECT_ATTRIBUTES attrs;
 IO_STATUS_BLOCK  iostatus;

 //#define PATH  L"\\DosDevices\\E:\\WINNT\\MYTMP\\t"
 #define PATH  L"\\SystemRoot\\MYTMP\\t"            //it doesn't matter
which path I use, it still works on XP and crashes on 2k when I load 128
files at once..

 UNICODE_STRING  usPath;
 UNICODE_STRING  usFn;
 UNICODE_STRING      linkDigits;
 WCHAR    linkDigitsBuffer[40];
 WCHAR    pathbuff[255];

 #if (DBG)
  PEXCEPTION_POINTERS Ep;
  _DbgPrintF(DEBUGLVL_TERSE, ("LoadTempFile is running at level=%x",
KeGetCurrentIrql()));     // It always reports that it's running at
PASSIVE_LEVEL, so it's OK.
 #endif

  RtlInitUnicodeString(&usPath, PATH);

  linkDigits.Length = 0;
  linkDigits.MaximumLength = 40;
  linkDigits.Buffer = linkDigitsBuffer;
  status = RtlIntegerToUnicodeString((ULONG)ix, 10, &linkDigits);
  if (status == STATUS_SUCCESS) {
   usFn.Length = 0;
   usFn.MaximumLength = sizeof(pathbuff);
   usFn.Buffer = pathbuff;
   RtlZeroMemory(usFn.Buffer, usFn.MaximumLength);
   status = RtlAppendUnicodeStringToString(&usFn, &usPath);

   if (status == STATUS_SUCCESS) {
    status = RtlAppendUnicodeStringToString(&usFn, &linkDigits);
    if (status == STATUS_SUCCESS) {
     RtlZeroMemory(&attrs, sizeof(attrs));
     InitializeObjectAttributes(&attrs, &usFn, OBJ_CASE_INSENSITIVE, NULL,
NULL);

     //this is the old version:
     //status = ZwOpenFile(&hFile, STANDARD_RIGHTS_READ | FILE_READ_DATA,
&attrs, &iostatus, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT |
FILE_NON_DIRECTORY_FILE);

     //this is the current version, but it still causes system reboot on
Win2k loading 128 files...
     status = ZwCreateFile(
        &hFile,
        GENERIC_READ | SYNCHRONIZE,
        &attrs,
        &iostatus,
        0,
        FILE_ATTRIBUTE_NORMAL,
        0,
        FILE_OPEN,
        FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_ALERT,
        NULL,
        0
      );

     if (status == STATUS_SUCCESS) {
      RtlZeroMemory(&pex, sizeof(TP_ex));
      status = ZwReadFile(hFile, NULL, NULL, NULL, &iostatus, &pex,
sizeof(TP_ex), NULL, NULL);

      .....
      .....
      .....

thanx,
greg1x

 
 
 

Porting from XP to 2k, ZwOpenFile/ZwCreatFile causes REBOOT on 2k :( HELP ME!

Post by Greg » Wed, 23 Oct 2002 16:22:18


Hi!

Quote:> Did you check whether this is a problem with IRQL at which this code runs?
> (ZwCreateFile, ZwReadFile should be executed at passive level.) you can
try
> KeGetCurrentIrql to check the Irql.

Yes, it always runs at PASSIVE_LEVEL. (and works on XP perfectly)
Any ideas?

greg1x

 
 
 

1. Differences between 2K-Pro, 2K-Server and 2K-Adv Server

I would like to find out if the core OS (kernel, architecture, etc
...) is the same in all 3 versions of the Windows 2000 products?

Windows 2000 Professional
Windows 2000 Server
Windows 2000 Advanced Server

If anyone knows the answer to this question, please respond.

2. Discussion Groups

3. Visio 2K on an Office 2K and XP machine

4. printing/downloading

5. I want to access the parallel port under win 2k/xp

6. Help, finding IC chip !!

7. Porting driver from 2K to XP

8. Integration of Project 2K with MS Office 2K Apps

9. Project 2k kills Office 2k apps: FIX

10. Cant link multiple Excel (2K) worsheets to Visio 2K drawing

11. Help problems under XP/2K

12. Office XP and Visio 2k problems HELP!!!