Thread View: borland.public.cppbuilder.nativeapi
4 messages
4 total messages
Started by Adam G.
Wed, 30 Apr 2003 22:15
throwing an exception causes crash when exclusive volume locks held.
Author: 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";
}
}
Re: throwing an exception causes crash when exclusive volume locks held.
Author: Remy Lebeau (TeamB)
Date: Wed, 30 Apr 2003 19:36
Date: Wed, 30 Apr 2003 19:36
21 lines
2051 bytes
2051 bytes
"Adam G." <gooch411@hotmail.com> wrote in message news:3eb020e2@newsgroups.borland.com... > 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. 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. Did you verify that your unlock code is correct? 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. Gambit
Re: throwing an exception causes crash when exclusive volume locks held.
Author: Remy Lebeau (TeamB)
Date: Wed, 30 Apr 2003 20:18
Date: Wed, 30 Apr 2003 20:18
17 lines
1580 bytes
1580 bytes
"Adam G." <gooch411@hotmail.com> wrote in message news:3eb02aea@newsgroups.borland.com... > The LockLogicalVolume function in my code was found in > some microsoft newsgroup. <snip> That code shows that both the locking and unlocking functions support both categories. Somewhere along the way, you stripped out the unlock code's ability to support both categories and hard-coded it to one instead. As to why they don't work, I have no clue. I don't do programming as such a low level. Gambit
Re: throwing an exception causes crash when exclusive volume locks held.
Author: Adam G.
Date: Wed, 30 Apr 2003 22:58
Date: Wed, 30 Apr 2003 22:58
122 lines
5233 bytes
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,
®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) )
std::cout << "throwing an exception. why do i crash? :(" << endl;
throw "Test";
}
}
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads