Debug is Broken, Release is OK. I've got test cases down to failures
on LARGE files in Debug Builds. The reason the large file does not
exist in Release: Debug information is stripped (I'm literally probing
my own EXE).
The original FileMapping code was shamelessly ripped from Matt
Pietrek's 'An In-Depth Look into the Win32 Portable Executable File
Format' (http://msdn.microsoft.com/msdnmag/issues/02/02/PE/). I can't
seem to find what is wrong with the original useage.
I suspect this has to do with the Memory Manager's ability to keep
up... The only thing I tried at this point is ORing in SEC_COMMIT on
CreateFileMapping - with no joy.
Other statistics:
File: C:\...\Debug\CodeDump.exe
Image Base: 00640000
Virtual Address: 000A5000
.text Start: 006E5000
.text Size: 0015D5CE
.text End: 008425CE
Image Base is the pointer returned from MapViewOfFile() - verified.
Virtual Address 000A5000 has been verified using PE Browse
.text Start: 006E5000 has been verified using PE Browse
.text Size: 0015D5CE has been verified using PE Browse
.text End: 008425CE has been verified using PE Browse
The Access Violation occurs within the range of '.text Start'/'.text
End'. Taking from the Output Windows of Visual Studio: First-chance
exception at 0x0053b4f6 in CodeDump.exe: 0xC0000005: Access violation
reading location 0x007d9000.
Any ideas? Below is how I am using CreateFileMapping/MapViewOfFile.
Jeff
/////////////////////////////////////////////////
if( 0 == GetModuleFileName( NULL, szFilename, PATH_SIZE ) )
{
std::cout << _T("Error Retrieving Process Filename") << std::endl;
__leave;
}
/////////////////////////////////////////////////////////////
hFile = CreateFile( szFilename, GENERIC_READ, FILE_SHARE_READ,
NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
if ( hFile == INVALID_HANDLE_VALUE )
{
std::cout << _T("Error - CreateFile()") << std::endl;
__leave;
}
/////////////////////////////////////////////////////////////
hFileMapping = CreateFileMapping(hFile, NULL,
PAGE_READONLY, 0, 0, NULL);
if ( NULL == hFileMapping )
{
std::cout << _T("Error - CreateFileMapping()") << std::endl;
__leave;
}
/////////////////////////////////////////////////////////////
PVOID pMappedFile = NULL;
pMappedFile = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
if ( NULL == pMappedFile )
{
std::cout << _T("Error - MapViewOfFile()") << std::endl;
__leave;
}
> Hi All,
>
>Debug is Broken, Release is OK. I've got test cases down to failures
>on LARGE files in Debug Builds. The reason the large file does not
>exist in Release: Debug information is stripped (I'm literally probing
>my own EXE).
****
I don't have the foggiest notion what you are talking about here. Most debug information
is stored in the .pdb file anyway, with only vestigial symbols in the executable, so there
is no reason you should not be able to study what is going on in the program. See my
essay on Surviving the Release Version.
So can you explain what is really going on here? Is the program reading itself? If so,
it would not be reading from a location in the mapping, and not from some location
nominally in the program?
I'm not sure there is a guarantee that every page in the range of "text" pages needs to
exist. Also, there is not a 1:1 mapping between offsets in the header and offsets in the
executable image. So this whole description is a bit confusing.
*****
>
>The original FileMapping code was shamelessly ripped from Matt
>Pietrek's 'An In-Depth Look into the Win32 Portable Executable File
>Format' (http://msdn.microsoft.com/msdnmag/issues/02/02/PE/). I can't
>seem to find what is wrong with the original useage.
>
>I suspect this has to do with the Memory Manager's ability to keep
>up... The only thing I tried at this point is ORing in SEC_COMMIT on
>CreateFileMapping - with no joy.
****
"Keep up"? What does THAT mean? I wasn't aware that memory managers had to "keep up"
with *anything*.
****
>
>Other statistics:
>File: C:\...\Debug\CodeDump.exe
>
> Image Base: 00640000
> Virtual Address: 000A5000
> .text Start: 006E5000
> .text Size: 0015D5CE
> .text End: 008425CE
>
>Image Base is the pointer returned from MapViewOfFile() - verified.
>Virtual Address 000A5000 has been verified using PE Browse
>.text Start: 006E5000 has been verified using PE Browse
>.text Size: 0015D5CE has been verified using PE Browse
>.text End: 008425CE has been verified using PE Browse
>
>The Access Violation occurs within the range of '.text Start'/'.text
>End'. Taking from the Output Windows of Visual Studio: First-chance
>exception at 0x0053b4f6 in CodeDump.exe: 0xC0000005: Access violation
>reading location 0x007d9000.
*****
So what is the program trying to do? What relation does this hex value have to anything
that has to do with the header of the file? I'm not making a connection here as to what
is going on.
You create a file map. The base of this map is pMappedViewOfFile. You have not shown
what you are trying to access. What line of code is being executed? It looks like you
are trying to read an address which you are assuming is within your program, and not
within the file you are mapping in.
*****
>
>Any ideas? Below is how I am using CreateFileMapping/MapViewOfFile.
>
>Jeff
>
>/////////////////////////////////////////////////
>if( 0 == GetModuleFileName( NULL, szFilename, PATH_SIZE ) )
>{
> std::cout << _T("Error Retrieving Process Filename") << std::endl;
****
If you are not calling ::GetLastError, and preferrably using ::FormatMessage to format the
error message into something readable, you are not producing a good explanation with any
of these error messages
****
> __leave;
>}
>
>/////////////////////////////////////////////////////////////
>hFile = CreateFile( szFilename, GENERIC_READ, FILE_SHARE_READ,
> NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
>
>if ( hFile == INVALID_HANDLE_VALUE )
>{
> std::cout << _T("Error - CreateFile()") << std::endl;
> __leave;
****
And why are you using __leave? This appears to apply only to __try blocks, which are C
Structured Exception Handling (SEH) blocks. SEH is incompatible with C++.
****
>}
>
>/////////////////////////////////////////////////////////////
>hFileMapping = CreateFileMapping(hFile, NULL,
> PAGE_READONLY, 0, 0, NULL);
>if ( NULL == hFileMapping )
>{
> std::cout << _T("Error - CreateFileMapping()") << std::endl;
> __leave;
>}
>
>/////////////////////////////////////////////////////////////
>PVOID pMappedFile = NULL;
>pMappedFile = MapViewOfFile(hFileMapping, FILE_MAP_READ, 0, 0, 0);
>if ( NULL == pMappedFile )
>{
> std::cout << _T("Error - MapViewOfFile()") << std::endl;
> __leave;
>}
Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm