Skip to content
This repository has been archived by the owner on Feb 20, 2021. It is now read-only.

Commit

Permalink
[Fix] Possible AV during background save.
Browse files Browse the repository at this point in the history
This fix is a refinement of a previous fix to avoid a possible AV if the buffer
to write to disk ends exactly at the last byte of a memory page.
  • Loading branch information
enricogior committed Jun 21, 2016
1 parent ffa8eb4 commit fab34af
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/Win32_Interop/Win32_Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,13 @@ namespace Globals
/* This function is used to force the VEH on the entire size of the buffer length,
in the event that the buffer crosses the memory page boundaries */
void EnsureMemoryIsMapped(const void *buffer, size_t size) {
/* Use 'volatile' to make sure the compiler doesn't remove "c = *((char*) (p + offset));" */
volatile char c;
char* p = (char*) buffer;
char* pStart = p - ((size_t) p % Globals::pageSize);
char* pEnd = p + size;
if ((size_t) (pEnd - pStart) > Globals::pageSize) {
size_t offset = 0;
while (offset < size) {
offset += Globals::pageSize;
if (offset > size) {
offset = size;
}
c = *((char*) (p + offset));
}
char* pFirstByte = (char*) buffer;
char* pLastByte = (char*) buffer + size - 1;
char* pFirstPage = pFirstByte - ((size_t) pFirstByte % Globals::pageSize);
char* pLastPage = pLastByte - ((size_t) pLastByte % Globals::pageSize);
// Use 'volatile' to make sure the compiler doesn't remove the memory access
for (volatile char* p = pFirstPage; p <= pLastPage; p += Globals::pageSize) {
volatile char c = *p;
}
}

Expand Down

0 comments on commit fab34af

Please sign in to comment.