Article View: borland.public.cppbuilder.nativeapi
Article #16704throwing an exception causes crash when exclusive volume locks held.
From: Adam G.
Date: Wed, 30 Apr 2003 22:15
Date: Wed, 30 Apr 2003 22:15
116 lines
4656 bytes
4656 bytes
i have a small program, that acquires a logical volume lock, via vwin32.vxd, on
drive A. it works fine, until i throw an exception. as soon as i throw an
exception while the locks are held.. it crashes.
oddly enough, it has different behaviours depending on the level of lock i have
acquired. at level 1, if i throw an exception, it works ok. if i have a level 2
lock acquired, when i throw an exception it immediatly crashes. at level 3, it
lags a little bit then crashes when i throw an exception. i'm stumped. i can't
figure out why it blows up. the code was compiled with borland C++ 5.5 with
default options, and ran on windows 98se. the error i get is an "illegal
operation" exception code "eefface".
the code compiles, and runs without crashing with devcpp 4.9.5, with default
options. i currently have _no_ idea how to go about resolving this problem,
except for simply using devcpp 4.9.5 (which i'd rather not do)
the code in question follows (it's as small as it can be) -
#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;
inline void ReleaseLock(char drive, HANDLE vwin32)
{
DIOC_REGISTERS regs;
regs.reg_EAX = 0x440D; file://general ioctl
regs.reg_EBX = drive;
regs.reg_ECX = 0x86A; file://unlock logical drive
unsigned long bytesReturned;
DeviceIoControl(vwin32,
VWIN32_DIOC_DOS_IOCTL,
®s,
sizeof(regs),
®s,
sizeof(regs),
&bytesReturned, 0);
}
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,
®s, sizeof(regs), ®s, 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) )
ReleaseLock(1, vwin32);
ReleaseLock(1, vwin32);
ReleaseLock(1, vwin32);
std::cout << "throwing an exception. why do i crash? :(" << endl;
throw "Test";
}
}
Technical Details
Message-ID:
<3eb020e2@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,734a7aac0e382db6,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2003-04-30 12:24:29 PST Reply-To: "Adam G." <gooch411@hotmail.com> From: "Adam G." <gooch411@hotmail.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: throwing an exception causes crash when exclusive volume locks held. Date: Wed, 30 Apr 2003 15:15:45 -0700 Lines: 118 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: 63.214.210.157 Message-ID: <3eb020e2@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1051730146 63.214.210.157 (30 Apr 2003 12:15:46 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-06!sn-xit-08!supernews.com!news-out.visi.com!petbe.visi.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail