🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #16706

Re: throwing an exception causes crash when exclusive volume locks held.

#16706
From: Adam G.
Date: Wed, 30 Apr 2003 22:58
122 lines
5233 bytes
----- Original Message -----
From: Remy Lebeau (TeamB) <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
Sent: Wednesday, April 30, 2003 12:36 PM
Subject: Re: throwing an exception causes crash when exclusive volume locks
held.


> You say that you have the locks held at the time of the exception, but your
> code actually shows that you're trying to release the locks first before
> throwing the exception.

I apologize.  The code I posted was the modified code to verify that it only
crashes while the locks are held.
I will post the correct code at the end of this message.. although, the only
difference is the lack of the ReleaseLock function.

>Did you verify that your unlock code is correct?
as best as i could, yes.  infact, when i release the locks, no crash occurs.

> I'm no expert in low-level device access, but it looks like your locking
> code supports two different device categories while your unlocking code is
> hard-coded to only support one instead.  Microsoft's documentation doesn't
> even mention device catagory 0x48 at all, only 0x08.  Where did you find
> 0x48?  Shouldn't the device category for both locking and unlocking match
> each other?  If 0x48 succeeds, you'll then be unlocking with 0x08 instead of
> 0x48.

The LockLogicalVolume function in my code was found in some microsoft newsgroup
(google link:
http://groups.google.com/groups?q=%22device+category%22+%220x48%22&hl=en&lr=&ie
=UTF-8&selm=BRMn3VnsAHA.53%40cppssbbsa01.microsoft.com&rnum=5).  I just tested
the function with both device category 0x08, and 0x48.  It results in the same
behaviour.  My own function that acquires a logical volume lock only uses
device category 0x08, because as you stated, this is what the documentation
says it must be.  I used the code I found in the newsgroup to see if that
worked, and if it did, then there must obviously be something wrong with my
code... but, both functions result in the same behaviour.


here is the code i meant to post originally <only difference is lack of the
ReleaseLock function>-

#include <windows.h>
#include <iostream>

#pragma pack(push, 1)
struct DIOC_REGISTERS
{
    DWORD   reg_EBX;
    DWORD   reg_EDX;
    DWORD   reg_ECX;
    DWORD   reg_EAX;
    DWORD   reg_EDI;
    DWORD   reg_ESI;
    DWORD   reg_Flags;
};
#pragma pack(pop)

int const VWIN32_DIOC_DOS_IOCTL = 1;      file://int 0x21 0x4400 - 0x4411
functions

using namespace std;


BOOL LockLogicalVolume (HANDLE hVWin32,
                        BYTE   bDriveNum,
                        BYTE   bLockLevel,
                        WORD   wPermissions)
{
   BOOL           fResult;
   DIOC_REGISTERS regs = {0};
   BYTE           bDeviceCat;  // can be either 0x48 or 0x08
   DWORD          cb;

   // Try first with device category 0x48 for FAT32 volumes.  If it doesn't
   // work, we'll try again with device category 0x08.  If that doesn't
   file://work, then the lock failed.

   bDeviceCat = 0x48;

   ATTEMPT_AGAIN:
   // Set up the parameters for the call.
   regs.reg_EAX = 0x440D;
   regs.reg_EBX = MAKEWORD(bDriveNum, bLockLevel);
   regs.reg_ECX = MAKEWORD(0x4A, bDeviceCat);
   regs.reg_EDX = wPermissions;

   fResult = DeviceIoControl (hVWin32, VWIN32_DIOC_DOS_IOCTL,
                              &regs, sizeof(regs), &regs, sizeof(regs),
&cb, 0);

   // See if DeviceIoControl and the lock succeeded
   fResult = fResult && !(regs.reg_Flags & 1);

   // If DeviceIoControl or the lock failed, and device category 0x08 hasn't
   // been tried, retry the operation with device category 0x08.
   if (!fResult && (bDeviceCat != 0x08))
   {
      bDeviceCat = 0x08;
      goto ATTEMPT_AGAIN;
   }

   return fResult;
}


int main()
{
   HANDLE vwin32 = CreateFile("\\\\.\\vwin32", 0, 0, 0, 0,
                               FILE_FLAG_DELETE_ON_CLOSE, 0);

   if(vwin32 && LockLogicalVolume(vwin32, 1, 1, 0x1) &&
      LockLogicalVolume(vwin32, 1, 2, 0x1) &&
      LockLogicalVolume(vwin32, 1, 3, 0x1) )


      std::cout << "throwing an exception.  why do i crash? :(" << endl;
      throw "Test";
   }
}
Technical Details
Message-ID: <3eb02aea@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3eb020e2@newsgroups.borland.com> <3eb0257f$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,734a7aac0e382db6
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-04-30 13:18:45 PST
Reply-To: "Adam G." <gooch411@hotmail.com>
From: "Adam G." <gooch411@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3eb020e2@newsgroups.borland.com> <3eb0257f$1@newsgroups.borland.com>
Subject: Re: throwing an exception causes crash when exclusive volume locks held.
Date: Wed, 30 Apr 2003 15:58:33 -0700
Lines: 127
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.00.2615.200
X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200
NNTP-Posting-Host: 209.246.208.253
Message-ID: <3eb02aea@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1051732714 209.246.208.253 (30 Apr 2003 12:58:34 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail