0

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)?

Xantium
  • 11,201
  • 10
  • 62
  • 89
maidamai
  • 712
  • 9
  • 26
  • Have you done any error checking, that `hMappedFile` and `lpViewOfData` are valid and the functions succeeded? Also, `hMappedFile` or `m_hMappedFile`? Please try to create a proper [mcve] to show us, preferably something which replicates the problem and that we can try out ourselves. – Some programmer dude Jul 19 '19 at 09:00
  • @Someprogrammerdude Yes, its OK.Sorry I can't reproduce the problem, it just happened on one of our test machines, so I suspect the hardware error. – maidamai Jul 19 '19 at 09:00
  • What is the value of `nSharedMemorySize` ? – Michael Chourdakis Jul 19 '19 at 09:02
  • @MichaelChourdakis 256MB – maidamai Jul 19 '19 at 09:04

0 Answers0