I created a shared memory using CreateFileMapping
and get a view using MapViewOfFile
:
HANDLE hMappedFile =
CreateFileMapping(INVALID_HANDLE_VALUE, nullptr, PAGE_READWRITE, 0, DWORD(nSharedMemorySize), L"some-file-identifier")
void* lpViewOfData = MapViewOfFile(m_hMappedFile, FILE_MAP_ALL_ACCESS, 0, 0, 0);
Then I cast lpViewOfData
to unsigned int *
unsigned int *address= reinterpret_cast<unsigned int *>(lpViewOfData)
when writing to the address
, the process crashed
for(size_t i=0; i<len; ++i){ // len is not out-of-rangle
address[i] = i;
}
I dumped the memory with windbg and get some ??
in the shared memory,which means unmapped address according to ?? in memory locations.
000001c7`47bc0ff0 00000b18 00000b1a 00000c79 00000b1a
000001c7`47bc1000 ???????? ???????? ???????? ????????
...// bad
000001c7`47bc1ff0 ???????? ???????? ???????? ????????
000001c7`47bc2000 00000000 00000000 d3304ef3 10f7808e
...
... // good
...
000001c7`47c2eff0 47c2f000 000001c7 00000000 00000000
000001c7`47c2f000 ???????? ???????? ???????? ????????
... // bad
000001c7`47c2fff0 ???????? ???????? ???????? ????????
000001c7`47c30000 00000000 00000000 c5305ef5 0101c17e
As showed above, these ??
regions are exactly 4k
bytes in length.
I want know what's possible reasons to this problem, does this means hard disk error or wrong operations to these memory(other thread freed these region)?